blob: c8efdd06e98615112682a920509fcae3a8ac1e1b [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;
54import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070055import android.os.IBinder;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080056import android.os.ICancellationSignal;
tom hsu0b59d292022-09-29 23:49:21 +080057import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070058import android.os.Looper;
59import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070060import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080061import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070062import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070063import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080064import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080065import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070066import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070067import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080068import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070069import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070070import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070071import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070072import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070073import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080074import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070075import android.provider.Telephony;
arunvoddud7401012022-12-15 16:08:12 +000076import android.service.carrier.CarrierIdentifier;
Inseob Kim14bb3d02018-12-13 17:11:34 +090077import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080078import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080079import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070080import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080081import android.telephony.AccessNetworkConstants;
82import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070083import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070084import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080085import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070086import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080087import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070088import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080089import android.telephony.CarrierRestrictionRules;
Hui Wang9b5793a2022-12-05 14:38:06 -060090import android.telephony.CellBroadcastIdRange;
yincheng zhao2737e882019-09-06 17:06:54 -070091import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080092import android.telephony.CellIdentityCdma;
93import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070094import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070095import android.telephony.CellInfoGsm;
96import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070097import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080098import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070099import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700100import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700101import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -0800102import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700103import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -0800104import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -0700105import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800106import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800107import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700108import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800109import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700110import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800111import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800112import android.telephony.SignalStrengthUpdateRequest;
113import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800114import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800115import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800116import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700117import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700118import android.telephony.TelephonyManager;
Jack Yuf5badd92022-12-08 00:50:53 -0800119import android.telephony.TelephonyManager.SimState;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800120import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800121import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800122import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000123import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000124import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000125import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700126import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700127import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800128import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800129import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700130import android.telephony.gba.GbaAuthRequest;
131import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700132import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800133import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000134import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000135import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700136import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000137import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700138import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800139import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700140import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800141import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700142import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000143import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700144import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800145import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800146import android.telephony.ims.stub.ImsRegistrationImplBase;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800147import android.telephony.satellite.ISatelliteDatagramCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800148import android.telephony.satellite.ISatelliteProvisionStateCallback;
149import android.telephony.satellite.ISatelliteStateCallback;
Sarah Chinabf081b2023-03-09 23:00:57 -0800150import android.telephony.satellite.ISatelliteTransmissionUpdateCallback;
Sarah Chin503828c2023-02-01 23:54:20 -0800151import android.telephony.satellite.SatelliteCapabilities;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000152import android.telephony.satellite.SatelliteDatagram;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800153import android.telephony.satellite.SatelliteDatagramCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800154import android.telephony.satellite.SatelliteManager;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800155import android.telephony.satellite.SatelliteProvisionStateCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700156import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800157import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700158import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700159import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800160import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800161
Andrew Lee312e8172014-10-23 17:01:36 -0700162import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800163import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800164import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800165import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800166import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700167import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700168import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700169import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800170import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800171import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700172import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700173import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800174import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700175import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800176import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800177import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800178import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700179import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000180import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700181import com.android.internal.telephony.IIntegerConsumer;
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +0000182import com.android.internal.telephony.ILongConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800183import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700184import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800185import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800186import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800187import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700188import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700189import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700190import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700191import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700192import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800193import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700194import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700195import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700196import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700197import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800198import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800199import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700200import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000201import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700202import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700203import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800204import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800205import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800206import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700207import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000208import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800209import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700210import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800211import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700212import com.android.internal.telephony.imsphone.ImsPhone;
213import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000214import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800215import com.android.internal.telephony.metrics.TelephonyMetrics;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000216import com.android.internal.telephony.satellite.SatelliteController;
Jack Yu285100e2022-12-02 22:48:35 -0800217import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
218import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700219import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700220import com.android.internal.telephony.uicc.IccIoResult;
221import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800222import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700223import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800224import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700225import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000226import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800227import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000228import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800229import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000230import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700231import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700232import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800233import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800234import com.android.phone.callcomposer.CallComposerPictureManager;
235import com.android.phone.callcomposer.CallComposerPictureTransfer;
236import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700237import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700238import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000239import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700240import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800241import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700242import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700243import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800244import com.android.services.telephony.TelecomAccountRegistry;
245import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800246import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800247
Hall Liu82694d52020-12-11 18:22:04 -0800248import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700249import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800250import java.io.IOException;
251import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700252import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700253import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800254import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000255import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800256import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800257import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800258import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800259import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100260import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800261import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700262import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800263import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800264import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700265import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800266import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800267import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800268import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700269
270/**
271 * Implementation of the ITelephony interface.
272 */
Santos Cordon117fee72014-05-16 17:56:12 -0700273public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700274 private static final String LOG_TAG = "PhoneInterfaceManager";
275 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
276 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800277 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700278
279 // Message codes used with mMainThreadHandler
280 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700281 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
282 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700283 private static final int CMD_OPEN_CHANNEL = 9;
284 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
285 private static final int CMD_CLOSE_CHANNEL = 11;
286 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800287 private static final int CMD_NV_READ_ITEM = 13;
288 private static final int EVENT_NV_READ_ITEM_DONE = 14;
289 private static final int CMD_NV_WRITE_ITEM = 15;
290 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
291 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
292 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700293 private static final int CMD_RESET_MODEM_CONFIG = 19;
294 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800295 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
296 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800297 private static final int CMD_SEND_ENVELOPE = 25;
298 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000299 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
300 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700301 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
302 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
303 private static final int CMD_EXCHANGE_SIM_IO = 31;
304 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800305 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
306 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700307 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
308 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700309 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
310 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700311 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
312 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
313 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
314 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700315 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
316 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
317 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
318 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700319 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800320 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
321 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000322 private static final int CMD_SWITCH_SLOTS = 50;
323 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700324 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
325 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
326 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
327 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
328 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
329 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
330 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
331 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700332 private static final int CMD_GET_ALL_CELL_INFO = 60;
333 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
334 private static final int CMD_GET_CELL_LOCATION = 62;
335 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700336 private static final int CMD_MODEM_REBOOT = 64;
337 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700338 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
339 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800340 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
341 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700342 private static final int CMD_GET_MODEM_STATUS = 70;
343 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700344 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
345 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700346 private static final int CMD_ERASE_MODEM_CONFIG = 74;
347 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800348 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
349 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
350 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
351 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800352 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
353 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800354 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800355 private static final int CMD_GET_CALL_FORWARDING = 83;
356 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
357 private static final int CMD_SET_CALL_FORWARDING = 85;
358 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
359 private static final int CMD_GET_CALL_WAITING = 87;
360 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
361 private static final int CMD_SET_CALL_WAITING = 89;
362 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700363 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
364 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
365 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
366 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700367 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
368 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800369 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
370 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800371 private static final int CMD_SET_DATA_THROTTLING = 99;
372 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800373 private static final int CMD_SET_SIM_POWER = 101;
374 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800375 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
376 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
377 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
378 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800379 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
380 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000381 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800382 private static final int CMD_GET_SLICING_CONFIG = 110;
383 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800384 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700385 private static final int CMD_ENABLE_VONR = 113;
386 private static final int EVENT_ENABLE_VONR_DONE = 114;
387 private static final int CMD_IS_VONR_ENABLED = 115;
388 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700389 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
390 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000391
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800392 // Parameters of select command.
393 private static final int SELECT_COMMAND = 0xA4;
394 private static final int SELECT_P1 = 0x04;
395 private static final int SELECT_P2 = 0;
396 private static final int SELECT_P3 = 0x10;
397
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000398 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
399 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
400
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700401 /** The singleton instance. */
402 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800403 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700404
Sarah Chin4beb2b72023-02-14 14:47:54 -0800405 private final PhoneGlobals mApp;
406 private final CallManager mCM;
407 private final ImsResolver mImsResolver;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000408
409 private final SatelliteController mSatelliteController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800410 private final UserManager mUserManager;
411 private final AppOpsManager mAppOps;
412 private final MainThreadHandler mMainThreadHandler;
Jack Yue37dd262022-12-16 11:53:37 -0800413 private final SubscriptionController mSubscriptionController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800414 private final SharedPreferences mTelephonySharedPreferences;
415 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800416 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700417
Peter Wangdafb9ac2020-01-15 14:13:38 -0800418 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800419 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800420 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
421
Sarah Chin4beb2b72023-02-14 14:47:54 -0800422 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800423
Derek Tan97ebb422014-09-05 16:55:38 -0700424 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
425 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800426 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800427 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700428
Michelecea4cf22018-12-21 15:00:11 -0800429 // String to store multi SIM allowed
430 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
431
Derek Tan740e1672017-06-27 14:56:27 -0700432 // The AID of ISD-R.
433 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
434
yinxub1bed742017-04-17 11:45:04 -0700435 private NetworkScanRequestTracker mNetworkScanRequestTracker;
436
David Kelly5e06a7f2018-03-12 14:10:59 +0000437 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
438 private static final int MANUFACTURER_CODE_LENGTH = 8;
439
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800440 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800441 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800442
Sarah Chin2ec39f62022-08-31 17:03:26 -0700443 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
444 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
445
Derek Tan89e89d42014-07-08 17:00:10 -0700446 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700447 * Experiment flag to enable erase modem config on reset network, default value is false
448 */
449 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
450 "reset_network_erase_modem_config_enabled";
451
Rambo Wang0f050d82021-02-12 11:43:36 -0800452 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800453
Gary Jian76280a42022-12-07 16:18:33 +0800454 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
455
sandeepjsb6c87872021-09-27 15:34:44 +0000456 /**
457 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
458 * one ICCID active at the same time.
459 * Apps should use below API signatures if targeting SDK is T and beyond.
460 *
461 * @hide
462 */
463 @ChangeId
464 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
465 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800466
Naina Nallurid63128d2019-09-17 14:10:30 -0700467 /**
Chen Xu540470b2021-12-14 17:15:47 -0800468 * Apps targeting on Android T and beyond will get exception whenever icc close channel
469 * operation fails.
470 */
471 @ChangeId
472 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
473 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
474
475 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700476 * A request object to use for transmitting data to an ICC.
477 */
478 private static final class IccAPDUArgument {
479 public int channel, cla, command, p1, p2, p3;
480 public String data;
481
482 public IccAPDUArgument(int channel, int cla, int command,
483 int p1, int p2, int p3, String data) {
484 this.channel = channel;
485 this.cla = cla;
486 this.command = command;
487 this.p1 = p1;
488 this.p2 = p2;
489 this.p3 = p3;
490 this.data = data;
491 }
492 }
493
494 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700495 * A request object to use for transmitting data to an ICC.
496 */
497 private static final class ManualNetworkSelectionArgument {
498 public OperatorInfo operatorInfo;
499 public boolean persistSelection;
500
501 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
502 this.operatorInfo = operatorInfo;
503 this.persistSelection = persistSelection;
504 }
505 }
506
Sarah Chin71b3a852022-09-28 15:54:19 -0700507 private static final class PurchasePremiumCapabilityArgument {
508 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700509 public @NonNull IIntegerConsumer callback;
510
511 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800512 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700513 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700514 this.callback = callback;
515 }
516 }
517
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700518 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700519 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
520 * request after sending. The main thread will notify the request when it is complete.
521 */
522 private static final class MainThreadRequest {
523 /** The argument to use for the request */
524 public Object argument;
525 /** The result of the request that is run on the main thread */
526 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800527 // The subscriber id that this request applies to. Defaults to
528 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
529 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700530
Nathan Harold92bed182018-10-12 18:16:49 -0700531 // In cases where subId is unavailable, the caller needs to specify the phone.
532 public Phone phone;
533
vagdeviaf9a5b92018-08-15 16:01:53 -0700534 public WorkSource workSource;
535
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700536 public MainThreadRequest(Object argument) {
537 this.argument = argument;
538 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800539
Nathan Harold92bed182018-10-12 18:16:49 -0700540 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
541 this.argument = argument;
542 if (phone != null) {
543 this.phone = phone;
544 }
545 this.workSource = workSource;
546 }
547
vagdeviaf9a5b92018-08-15 16:01:53 -0700548 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800549 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800550 if (subId != null) {
551 this.subId = subId;
552 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700553 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800554 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700555 }
556
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800557 private static final class IncomingThirdPartyCallArgs {
558 public final ComponentName component;
559 public final String callId;
560 public final String callerDisplayName;
561
562 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
563 String callerDisplayName) {
564 this.component = component;
565 this.callId = callId;
566 this.callerDisplayName = callerDisplayName;
567 }
568 }
569
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700570 /**
571 * A handler that processes messages on the main thread in the phone process. Since many
572 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
573 * inbound binder threads to the main thread in the phone process. The Binder thread
574 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
575 * on, which will be notified when the operation completes and will contain the result of the
576 * request.
577 *
578 * <p>If a MainThreadRequest object is provided in the msg.obj field,
579 * note that request.result must be set to something non-null for the calling thread to
580 * unblock.
581 */
582 private final class MainThreadHandler extends Handler {
583 @Override
584 public void handleMessage(Message msg) {
585 MainThreadRequest request;
586 Message onCompleted;
587 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000588 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700589 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800590 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700591
592 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700593 case CMD_HANDLE_USSD_REQUEST: {
594 request = (MainThreadRequest) msg.obj;
595 final Phone phone = getPhoneFromRequest(request);
596 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800597 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700598 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700599
Pengquan Menga1bb6272018-09-06 09:59:22 -0700600 if (!isUssdApiAllowed(request.subId)) {
601 // Carrier does not support use of this API, return failure.
602 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
603 UssdResponse response = new UssdResponse(ussdRequest, null);
604 Bundle returnData = new Bundle();
605 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
606 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700607
Pengquan Menga1bb6272018-09-06 09:59:22 -0700608 request.result = true;
609 notifyRequester(request);
610 return;
611 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700612
Pengquan Menga1bb6272018-09-06 09:59:22 -0700613 try {
614 request.result = phone != null
615 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
616 } catch (CallStateException cse) {
617 request.result = false;
618 }
619 // Wake up the requesting thread
620 notifyRequester(request);
621 break;
pkanwar32d516d2016-10-14 19:37:38 -0700622 }
623
Yorke Lee716f67e2015-06-17 15:39:16 -0700624 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700625 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700626 final Phone phone = getPhoneFromRequest(request);
627 request.result = phone != null ?
628 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
629 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700630 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700631 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700632 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700633 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700634
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700635 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700636 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700637 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000638 uiccPort = getUiccPortFromRequest(request);
639 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700640 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800641 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700642 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700643 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700644 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800645 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000646 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800647 iccArgument.channel, iccArgument.cla, iccArgument.command,
648 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
649 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700650 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700651 break;
652
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700653 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700654 ar = (AsyncResult) msg.obj;
655 request = (MainThreadRequest) ar.userObj;
656 if (ar.exception == null && ar.result != null) {
657 request.result = ar.result;
658 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800659 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700660 if (ar.result == null) {
661 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800662 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800664 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700665 } else {
666 loge("iccTransmitApduLogicalChannel: Unknown exception");
667 }
668 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700669 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700670 break;
671
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700672 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
673 request = (MainThreadRequest) msg.obj;
674 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000675 uiccPort = getUiccPortFromRequest(request);
676 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700677 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800678 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700679 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700680 } else {
681 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800682 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000683 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800684 iccArgument.cla, iccArgument.command, iccArgument.p1,
685 iccArgument.p2,
686 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700687 }
688 break;
689
690 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
691 ar = (AsyncResult) msg.obj;
692 request = (MainThreadRequest) ar.userObj;
693 if (ar.exception == null && ar.result != null) {
694 request.result = ar.result;
695 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800696 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700697 if (ar.result == null) {
698 loge("iccTransmitApduBasicChannel: Empty response");
699 } else if (ar.exception instanceof CommandException) {
700 loge("iccTransmitApduBasicChannel: CommandException: " +
701 ar.exception);
702 } else {
703 loge("iccTransmitApduBasicChannel: Unknown exception");
704 }
705 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700706 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700707 break;
708
709 case CMD_EXCHANGE_SIM_IO:
710 request = (MainThreadRequest) msg.obj;
711 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000712 uiccPort = getUiccPortFromRequest(request);
713 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700714 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800715 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700716 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700717 } else {
718 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
719 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000720 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700721 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
722 iccArgument.data, onCompleted);
723 }
724 break;
725
726 case EVENT_EXCHANGE_SIM_IO_DONE:
727 ar = (AsyncResult) msg.obj;
728 request = (MainThreadRequest) ar.userObj;
729 if (ar.exception == null && ar.result != null) {
730 request.result = ar.result;
731 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800732 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700733 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700734 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700735 break;
736
Derek Tan4d5e5c12014-02-04 11:54:58 -0800737 case CMD_SEND_ENVELOPE:
738 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000739 uiccPort = getUiccPortFromRequest(request);
740 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700741 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800742 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700743 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700744 } else {
745 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800746 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700747 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800748 break;
749
750 case EVENT_SEND_ENVELOPE_DONE:
751 ar = (AsyncResult) msg.obj;
752 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700753 if (ar.exception == null && ar.result != null) {
754 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800755 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800756 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700757 if (ar.result == null) {
758 loge("sendEnvelopeWithStatus: Empty response");
759 } else if (ar.exception instanceof CommandException) {
760 loge("sendEnvelopeWithStatus: CommandException: " +
761 ar.exception);
762 } else {
763 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
764 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800765 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700766 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800767 break;
768
Shishir Agrawal566b7612013-10-28 14:41:00 -0700769 case CMD_OPEN_CHANNEL:
770 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000771 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800772 IccLogicalChannelRequest openChannelRequest =
773 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000774 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700775 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800776 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800777 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700778 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700779 } else {
780 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800781 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
782 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700783 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700784 break;
785
786 case EVENT_OPEN_CHANNEL_DONE:
787 ar = (AsyncResult) msg.obj;
788 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700789 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700790 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700791 int[] result = (int[]) ar.result;
792 int channelId = result[0];
793 byte[] selectResponse = null;
794 if (result.length > 1) {
795 selectResponse = new byte[result.length - 1];
796 for (int i = 1; i < result.length; ++i) {
797 selectResponse[i - 1] = (byte) result[i];
798 }
799 }
800 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800801 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800802
803 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700804 if (uiccPort == null) {
805 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
806 } else {
807 IccLogicalChannelRequest channelRequest =
808 (IccLogicalChannelRequest) request.argument;
809 channelRequest.channel = channelId;
810 uiccPort.onLogicalChannelOpened(channelRequest);
811 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700812 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700813 if (ar.result == null) {
814 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700815 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700816 if (ar.exception != null) {
817 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
818 }
819
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700820 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700821 if (ar.exception instanceof CommandException) {
822 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800823 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700824 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700825 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700826 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700827 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700828 }
829 }
830 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800831 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700832 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700833 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700834 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700835 break;
836
837 case CMD_CLOSE_CHANNEL:
838 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000839 uiccPort = getUiccPortFromRequest(request);
840 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700841 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800842 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800843 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800844 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700845 } else {
846 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000847 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700848 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700849 break;
850
851 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800852 ar = (AsyncResult) msg.obj;
853 request = (MainThreadRequest) ar.userObj;
854 if (ar.exception == null) {
855 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800856 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700857 if (uiccPort == null) {
858 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
859 } else {
860 final int channelId = (Integer) request.argument;
861 uiccPort.onLogicalChannelClosed(channelId);
862 }
Chen Xu540470b2021-12-14 17:15:47 -0800863 } else {
864 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800865 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800866 if (ar.exception instanceof CommandException) {
867 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
868 CommandException.Error error =
869 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800870 if (error == CommandException.Error.INVALID_ARGUMENTS) {
871 // should only throw exceptions from the binder threads.
872 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800873 "iccCloseLogicalChannel: invalid argument ");
874 }
875 } else {
876 loge("iccCloseLogicalChannel: Unknown exception");
877 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800878 request.result = (exception != null) ? exception :
879 new IllegalStateException(
880 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800881 }
882 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800883 break;
884
885 case CMD_NV_READ_ITEM:
886 request = (MainThreadRequest) msg.obj;
887 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800888 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
889 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800890 break;
891
892 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700893 ar = (AsyncResult) msg.obj;
894 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800895 if (ar.exception == null && ar.result != null) {
896 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700897 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800898 request.result = "";
899 if (ar.result == null) {
900 loge("nvReadItem: Empty response");
901 } else if (ar.exception instanceof CommandException) {
902 loge("nvReadItem: CommandException: " +
903 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700904 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800905 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700906 }
907 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700908 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700909 break;
910
Jake Hambye994d462014-02-03 13:10:13 -0800911 case CMD_NV_WRITE_ITEM:
912 request = (MainThreadRequest) msg.obj;
913 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
914 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800915 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700916 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800917 break;
918
919 case EVENT_NV_WRITE_ITEM_DONE:
920 handleNullReturnEvent(msg, "nvWriteItem");
921 break;
922
923 case CMD_NV_WRITE_CDMA_PRL:
924 request = (MainThreadRequest) msg.obj;
925 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800926 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800927 break;
928
929 case EVENT_NV_WRITE_CDMA_PRL_DONE:
930 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
931 break;
932
chen xu6dac5ab2018-10-26 17:39:23 -0700933 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800934 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700935 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800936 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800937 break;
938
chen xu6dac5ab2018-10-26 17:39:23 -0700939 case EVENT_RESET_MODEM_CONFIG_DONE:
940 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800941 break;
942
Sooraj Sasindran37444802020-08-11 10:40:43 -0700943 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
944 request = (MainThreadRequest) msg.obj;
945 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
946 request);
947 Phone phone = getPhoneFromRequest(request);
948 if (phone != null) {
949 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
950 } else {
951 loge("isNRDualConnectivityEnabled: No phone object");
952 request.result = false;
953 notifyRequester(request);
954 }
955 break;
956 }
957
958 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
959 ar = (AsyncResult) msg.obj;
960 request = (MainThreadRequest) ar.userObj;
961 if (ar.exception == null && ar.result != null) {
962 request.result = ar.result;
963 } else {
964 // request.result must be set to something non-null
965 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700966 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700967 request.result = ar.result;
968 } else {
969 request.result = false;
970 }
971 if (ar.result == null) {
972 loge("isNRDualConnectivityEnabled: Empty response");
973 } else if (ar.exception instanceof CommandException) {
974 loge("isNRDualConnectivityEnabled: CommandException: "
975 + ar.exception);
976 } else {
977 loge("isNRDualConnectivityEnabled: Unknown exception");
978 }
979 }
980 notifyRequester(request);
981 break;
982
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700983 case CMD_IS_VONR_ENABLED: {
984 request = (MainThreadRequest) msg.obj;
985 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
986 request);
987 Phone phone = getPhoneFromRequest(request);
988 if (phone != null) {
989 phone.isVoNrEnabled(onCompleted, request.workSource);
990 } else {
991 loge("isVoNrEnabled: No phone object");
992 request.result = false;
993 notifyRequester(request);
994 }
995 break;
996 }
997
998 case EVENT_IS_VONR_ENABLED_DONE:
999 ar = (AsyncResult) msg.obj;
1000 request = (MainThreadRequest) ar.userObj;
1001 if (ar.exception == null && ar.result != null) {
1002 request.result = ar.result;
1003 } else {
1004 // request.result must be set to something non-null
1005 // for the calling thread to unblock
1006 if (ar.result != null) {
1007 request.result = ar.result;
1008 } else {
1009 request.result = false;
1010 }
1011 if (ar.result == null) {
1012 loge("isVoNrEnabled: Empty response");
1013 } else if (ar.exception instanceof CommandException) {
1014 loge("isVoNrEnabled: CommandException: "
1015 + ar.exception);
1016 } else {
1017 loge("isVoNrEnabled: Unknown exception");
1018 }
1019 }
1020 notifyRequester(request);
1021 break;
1022
Sooraj Sasindran37444802020-08-11 10:40:43 -07001023 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1024 request = (MainThreadRequest) msg.obj;
1025 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1026 Phone phone = getPhoneFromRequest(request);
1027 if (phone != null) {
1028 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1029 request.workSource);
1030 } else {
1031 loge("enableNrDualConnectivity: No phone object");
1032 request.result =
1033 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1034 notifyRequester(request);
1035 }
1036 break;
1037 }
1038
1039 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1040 ar = (AsyncResult) msg.obj;
1041 request = (MainThreadRequest) ar.userObj;
1042 if (ar.exception == null) {
1043 request.result =
1044 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1045 } else {
1046 request.result =
1047 TelephonyManager
1048 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1049 if (ar.exception instanceof CommandException) {
1050 CommandException.Error error =
1051 ((CommandException) (ar.exception)).getCommandError();
1052 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1053 request.result =
1054 TelephonyManager
1055 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001056 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1057 request.result =
1058 TelephonyManager
1059 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001060 }
1061 loge("enableNrDualConnectivity" + ": CommandException: "
1062 + ar.exception);
1063 } else {
1064 loge("enableNrDualConnectivity" + ": Unknown exception");
1065 }
1066 }
1067 notifyRequester(request);
1068 break;
1069 }
1070
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001071 case CMD_ENABLE_VONR: {
1072 request = (MainThreadRequest) msg.obj;
1073 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1074 Phone phone = getPhoneFromRequest(request);
1075 if (phone != null) {
1076 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1077 request.workSource);
1078 } else {
1079 loge("setVoNrEnabled: No phone object");
1080 request.result =
1081 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1082 notifyRequester(request);
1083 }
1084 break;
1085 }
1086
1087 case EVENT_ENABLE_VONR_DONE: {
1088 ar = (AsyncResult) msg.obj;
1089 request = (MainThreadRequest) ar.userObj;
1090 if (ar.exception == null) {
1091 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1092 } else {
1093 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1094 if (ar.exception instanceof CommandException) {
1095 CommandException.Error error =
1096 ((CommandException) (ar.exception)).getCommandError();
1097 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1098 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1099 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1100 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1101 } else {
1102 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1103 }
1104 loge("setVoNrEnabled" + ": CommandException: "
1105 + ar.exception);
1106 } else {
1107 loge("setVoNrEnabled" + ": Unknown exception");
1108 }
1109 }
1110 notifyRequester(request);
1111 break;
1112 }
1113
SongFerngWang3ef3e072020-12-21 16:41:52 +08001114 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001115 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001116 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1117 request);
1118 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001119 break;
1120
SongFerngWang3ef3e072020-12-21 16:41:52 +08001121 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001122 ar = (AsyncResult) msg.obj;
1123 request = (MainThreadRequest) ar.userObj;
1124 if (ar.exception == null && ar.result != null) {
1125 request.result = ar.result; // Integer
1126 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301127 // request.result must be set to something non-null
1128 // for the calling thread to unblock
1129 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001130 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001131 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001132 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001133 loge("getAllowedNetworkTypesBitmask: CommandException: "
1134 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001135 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001136 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001137 }
1138 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001139 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001140 break;
1141
SongFerngWang3ef3e072020-12-21 16:41:52 +08001142 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001143 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001144 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1145 request);
1146 Pair<Integer, Long> reasonWithNetworkTypes =
1147 (Pair<Integer, Long>) request.argument;
1148 getPhoneFromRequest(request).setAllowedNetworkTypes(
1149 reasonWithNetworkTypes.first,
1150 reasonWithNetworkTypes.second,
1151 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001152 break;
1153
SongFerngWang3ef3e072020-12-21 16:41:52 +08001154 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1155 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001156 break;
1157
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001158 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1159 request = (MainThreadRequest)msg.obj;
1160 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001161 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001162 break;
1163
1164 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1165 ar = (AsyncResult)msg.obj;
1166 request = (MainThreadRequest)ar.userObj;
1167 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001168 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001169 break;
1170
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001171 case CMD_SET_VOICEMAIL_NUMBER:
1172 request = (MainThreadRequest) msg.obj;
1173 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1174 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001175 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1176 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001177 break;
1178
1179 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1180 handleNullReturnEvent(msg, "setVoicemailNumber");
1181 break;
1182
Stuart Scott54788802015-03-30 13:18:01 -07001183 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1184 request = (MainThreadRequest) msg.obj;
1185 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1186 request);
1187 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1188 break;
1189
1190 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1191 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1192 break;
1193
Shishir Agrawal302c8692015-06-19 13:49:39 -07001194 case CMD_PERFORM_NETWORK_SCAN:
1195 request = (MainThreadRequest) msg.obj;
1196 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1197 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1198 break;
1199
Hall Liu27d24262020-09-18 19:04:59 -07001200 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001201 request = (MainThreadRequest) msg.obj;
1202 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001203 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1204 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1205 request.argument;
1206 int callForwardingReason = args.first;
1207 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001208 break;
Hall Liu27d24262020-09-18 19:04:59 -07001209 }
1210 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001211 ar = (AsyncResult) msg.obj;
1212 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001213 TelephonyManager.CallForwardingInfoCallback callback =
1214 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1215 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001216 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001217 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001218 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1219 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1220 // Service Class is a bit mask per 3gpp 27.007. Search for
1221 // any service for voice call.
1222 if ((callForwardInfo.serviceClass
1223 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001224 callForwardingInfo = new CallForwardingInfo(
1225 callForwardInfo.status
1226 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001227 callForwardInfo.reason,
1228 callForwardInfo.number,
1229 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001230 break;
1231 }
1232 }
1233 // Didn't find a call forward info for voice call.
1234 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001235 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1236 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001237 }
Hall Liu27d24262020-09-18 19:04:59 -07001238 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001239 } else {
1240 if (ar.result == null) {
1241 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1242 }
1243 if (ar.exception != null) {
1244 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1245 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001246 int errorCode = TelephonyManager
1247 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001248 if (ar.exception instanceof CommandException) {
1249 CommandException.Error error =
1250 ((CommandException) (ar.exception)).getCommandError();
1251 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001252 errorCode = TelephonyManager
1253 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001254 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001255 errorCode = TelephonyManager
1256 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001257 }
1258 }
Hall Liu27d24262020-09-18 19:04:59 -07001259 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001260 }
Shuo Qian4a594052020-01-23 11:59:30 -08001261 break;
Hall Liu27d24262020-09-18 19:04:59 -07001262 }
Shuo Qian4a594052020-01-23 11:59:30 -08001263
Hall Liu27d24262020-09-18 19:04:59 -07001264 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001265 request = (MainThreadRequest) msg.obj;
1266 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001267 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001268 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001269 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1270 request.argument).first;
1271 request.phone.setCallForwardingOption(
1272 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001273 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001274 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001275 callForwardingInfoToSet.getReason(),
1276 callForwardingInfoToSet.getNumber(),
1277 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1278 break;
Hall Liu27d24262020-09-18 19:04:59 -07001279 }
Shuo Qian4a594052020-01-23 11:59:30 -08001280
Hall Liu27d24262020-09-18 19:04:59 -07001281 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001282 ar = (AsyncResult) msg.obj;
1283 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001284 Consumer<Integer> callback =
1285 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1286 request.argument).second;
1287 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001288 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001289 int errorCode = TelephonyManager.CallForwardingInfoCallback
1290 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001291 if (ar.exception instanceof CommandException) {
1292 CommandException.Error error =
1293 ((CommandException) (ar.exception)).getCommandError();
1294 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001295 errorCode = TelephonyManager.CallForwardingInfoCallback
1296 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001297 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001298 errorCode = TelephonyManager.CallForwardingInfoCallback
1299 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001300 }
1301 }
1302 callback.accept(errorCode);
1303 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001304 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001305 }
Shuo Qian4a594052020-01-23 11:59:30 -08001306 break;
Hall Liu27d24262020-09-18 19:04:59 -07001307 }
Shuo Qian4a594052020-01-23 11:59:30 -08001308
Hall Liu27d24262020-09-18 19:04:59 -07001309 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001310 request = (MainThreadRequest) msg.obj;
1311 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1312 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1313 break;
Hall Liu27d24262020-09-18 19:04:59 -07001314 }
Shuo Qian4a594052020-01-23 11:59:30 -08001315
Hall Liu27d24262020-09-18 19:04:59 -07001316 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001317 ar = (AsyncResult) msg.obj;
1318 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001319 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001320 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001321 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001322 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001323 // Service Class is a bit mask per 3gpp 27.007.
1324 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001325 if (callForwardResults.length > 1
1326 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001327 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001328 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001329 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1330 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001331 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001332 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001333 }
1334 } else {
1335 if (ar.result == null) {
1336 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1337 }
1338 if (ar.exception != null) {
1339 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1340 }
1341 if (ar.exception instanceof CommandException) {
1342 CommandException.Error error =
1343 ((CommandException) (ar.exception)).getCommandError();
1344 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001345 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001346 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001347 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1348 callWaitingStatus =
1349 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001350 }
1351 }
1352 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001353 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001354 break;
Hall Liu27d24262020-09-18 19:04:59 -07001355 }
Shuo Qian4a594052020-01-23 11:59:30 -08001356
Hall Liu27d24262020-09-18 19:04:59 -07001357 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001358 request = (MainThreadRequest) msg.obj;
1359 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001360 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1361 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001362 break;
Hall Liu27d24262020-09-18 19:04:59 -07001363 }
Shuo Qian4a594052020-01-23 11:59:30 -08001364
Hall Liu27d24262020-09-18 19:04:59 -07001365 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001366 ar = (AsyncResult) msg.obj;
1367 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001368 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1369 Consumer<Integer> callback =
1370 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1371 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001372 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001373 if (ar.exception instanceof CommandException) {
1374 CommandException.Error error =
1375 ((CommandException) (ar.exception)).getCommandError();
1376 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1377 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001378 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1379 callback.accept(
1380 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001381 } else {
1382 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1383 }
1384 } else {
1385 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1386 }
1387 } else {
1388 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1389 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001390 }
Shuo Qian4a594052020-01-23 11:59:30 -08001391 break;
Hall Liu27d24262020-09-18 19:04:59 -07001392 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001393 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1394 ar = (AsyncResult) msg.obj;
1395 request = (MainThreadRequest) ar.userObj;
1396 CellNetworkScanResult cellScanResult;
1397 if (ar.exception == null && ar.result != null) {
1398 cellScanResult = new CellNetworkScanResult(
1399 CellNetworkScanResult.STATUS_SUCCESS,
1400 (List<OperatorInfo>) ar.result);
1401 } else {
1402 if (ar.result == null) {
1403 loge("getCellNetworkScanResults: Empty response");
1404 }
1405 if (ar.exception != null) {
1406 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1407 }
1408 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1409 if (ar.exception instanceof CommandException) {
1410 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001411 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001412 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1413 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1414 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1415 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1416 }
1417 }
1418 cellScanResult = new CellNetworkScanResult(errorCode, null);
1419 }
1420 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001421 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001422 break;
1423
1424 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1425 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001426 ManualNetworkSelectionArgument selArg =
1427 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001428 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1429 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001430 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1431 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001432 break;
1433
1434 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001435 ar = (AsyncResult) msg.obj;
1436 request = (MainThreadRequest) ar.userObj;
1437 if (ar.exception == null) {
1438 request.result = true;
1439 } else {
1440 request.result = false;
1441 loge("setNetworkSelectionModeManual " + ar.exception);
1442 }
1443 notifyRequester(request);
1444 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001445 break;
1446
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001447 case CMD_GET_MODEM_ACTIVITY_INFO:
1448 request = (MainThreadRequest) msg.obj;
1449 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001450 if (defaultPhone != null) {
1451 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001452 } else {
1453 ResultReceiver result = (ResultReceiver) request.argument;
1454 Bundle bundle = new Bundle();
1455 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001456 new ModemActivityInfo(0, 0, 0,
1457 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001458 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001459 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001460 break;
1461
Hall Liud0f208c2020-10-14 16:54:44 -07001462 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001463 ar = (AsyncResult) msg.obj;
1464 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001465 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001466 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001467 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001468 if (mLastModemActivityInfo == null) {
1469 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1470 mLastModemActivitySpecificInfo[0] =
1471 new ActivityStatsTechSpecificInfo(
1472 0,
1473 0,
1474 new int[ModemActivityInfo.getNumTxPowerLevels()],
1475 0);
1476 mLastModemActivityInfo =
1477 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1478 }
1479
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001480 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001481 // Update the last modem activity info and the result of the request.
1482 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1483 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001484 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001485 } else {
1486 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001487 }
Kai Shi917fdc62022-11-28 14:01:02 -08001488 // This is needed to decouple ret from mLastModemActivityInfo
1489 // We don't want to return mLastModemActivityInfo which is updated
1490 // inside mergeModemActivityInfo()
1491 ret = new ModemActivityInfo(
1492 mLastModemActivityInfo.getTimestampMillis(),
1493 mLastModemActivityInfo.getSleepTimeMillis(),
1494 mLastModemActivityInfo.getIdleTimeMillis(),
1495 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001496
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001497 } else {
1498 if (ar.result == null) {
1499 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001500 error = TelephonyManager.ModemActivityInfoException
1501 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001502 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001503 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001504 error = TelephonyManager.ModemActivityInfoException
1505 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001506 } else {
1507 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001508 error = TelephonyManager.ModemActivityInfoException
1509 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001510 }
1511 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001512 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001513 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001514 bundle.putParcelable(
1515 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001516 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001517 } else {
1518 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1519 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001520 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001521 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001522 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001523 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001524
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001525 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001526 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001527 CarrierRestrictionRules argument =
1528 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001529 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001530 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001531 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001532 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001533
1534 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1535 ar = (AsyncResult) msg.obj;
1536 request = (MainThreadRequest) ar.userObj;
1537 if (ar.exception == null && ar.result != null) {
1538 request.result = ar.result;
1539 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001540 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1541 if (ar.exception instanceof CommandException) {
1542 loge("setAllowedCarriers: CommandException: " + ar.exception);
1543 CommandException.Error error =
1544 ((CommandException) (ar.exception)).getCommandError();
1545 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1546 request.result =
1547 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1548 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001549 } else {
1550 loge("setAllowedCarriers: Unknown exception");
1551 }
1552 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001553 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001554 break;
1555
1556 case CMD_GET_ALLOWED_CARRIERS:
1557 request = (MainThreadRequest) msg.obj;
1558 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001559 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001560 break;
1561
1562 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1563 ar = (AsyncResult) msg.obj;
1564 request = (MainThreadRequest) ar.userObj;
1565 if (ar.exception == null && ar.result != null) {
1566 request.result = ar.result;
1567 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001568 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001569 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001570 if (ar.result == null) {
1571 loge("getAllowedCarriers: Empty response");
1572 } else if (ar.exception instanceof CommandException) {
1573 loge("getAllowedCarriers: CommandException: " +
1574 ar.exception);
1575 } else {
1576 loge("getAllowedCarriers: Unknown exception");
1577 }
1578 }
arunvoddud7401012022-12-15 16:08:12 +00001579 if (request.argument != null) {
1580 // This is for the implementation of carrierRestrictionStatus.
1581 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1582 Consumer<Integer> callback = callbackInfo.getConsumer();
1583 int callerCarrierId = callbackInfo.getCarrierId();
1584 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1585 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1586 CarrierRestrictionRules carrierRestrictionRules =
1587 (CarrierRestrictionRules) ar.result;
1588 int carrierId = -1;
1589 try {
1590 CarrierIdentifier carrierIdentifier =
1591 carrierRestrictionRules.getAllowedCarriers().get(0);
1592 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1593 carrierIdentifier);
1594 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1595 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1596 }
1597 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
1598 if (carrierId != -1 && callerCarrierId == carrierId && lockStatus
1599 == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001600 lockStatus = TelephonyManager
1601 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001602 }
1603 } else {
1604 Rlog.e(LOG_TAG,
1605 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1606 }
1607 callback.accept(lockStatus);
1608 } else {
1609 // This is for the implementation of getAllowedCarriers.
1610 notifyRequester(request);
1611 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001612 break;
1613
Nathan Haroldb3014052017-01-25 15:57:32 -08001614 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1615 ar = (AsyncResult) msg.obj;
1616 request = (MainThreadRequest) ar.userObj;
1617 if (ar.exception == null && ar.result != null) {
1618 request.result = ar.result;
1619 } else {
1620 request.result = new IllegalArgumentException(
1621 "Failed to retrieve Forbidden Plmns");
1622 if (ar.result == null) {
1623 loge("getForbiddenPlmns: Empty response");
1624 } else {
1625 loge("getForbiddenPlmns: Unknown exception");
1626 }
1627 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001628 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001629 break;
1630
1631 case CMD_GET_FORBIDDEN_PLMNS:
1632 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001633 uiccPort = getUiccPortFromRequest(request);
1634 if (uiccPort == null) {
1635 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001636 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001637 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001638 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001639 break;
1640 }
1641 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001642 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001643 if (uiccApp == null) {
1644 loge("getForbiddenPlmns() no app with specified type -- "
1645 + appType);
1646 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001647 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001648 break;
1649 } else {
1650 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1651 + " specified type -- " + appType);
1652 }
1653 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1654 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001655 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001656 break;
1657
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001658 case CMD_SWITCH_SLOTS:
1659 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001660 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001661 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001662 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001663 break;
1664
1665 case EVENT_SWITCH_SLOTS_DONE:
1666 ar = (AsyncResult) msg.obj;
1667 request = (MainThreadRequest) ar.userObj;
1668 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001669 notifyRequester(request);
1670 break;
1671 case CMD_GET_NETWORK_SELECTION_MODE:
1672 request = (MainThreadRequest) msg.obj;
1673 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1674 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1675 break;
1676
1677 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1678 ar = (AsyncResult) msg.obj;
1679 request = (MainThreadRequest) ar.userObj;
1680 if (ar.exception != null) {
1681 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1682 } else {
1683 int mode = ((int[]) ar.result)[0];
1684 if (mode == 0) {
1685 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1686 } else {
1687 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1688 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001689 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001690 notifyRequester(request);
1691 break;
1692 case CMD_GET_CDMA_ROAMING_MODE:
1693 request = (MainThreadRequest) msg.obj;
1694 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1695 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1696 break;
1697 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1698 ar = (AsyncResult) msg.obj;
1699 request = (MainThreadRequest) ar.userObj;
1700 if (ar.exception != null) {
1701 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1702 } else {
1703 request.result = ((int[]) ar.result)[0];
1704 }
1705 notifyRequester(request);
1706 break;
1707 case CMD_SET_CDMA_ROAMING_MODE:
1708 request = (MainThreadRequest) msg.obj;
1709 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1710 int mode = (int) request.argument;
1711 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1712 break;
1713 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1714 ar = (AsyncResult) msg.obj;
1715 request = (MainThreadRequest) ar.userObj;
1716 request.result = ar.exception == null;
1717 notifyRequester(request);
1718 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001719 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1720 request = (MainThreadRequest) msg.obj;
1721 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1722 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1723 break;
1724 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1725 ar = (AsyncResult) msg.obj;
1726 request = (MainThreadRequest) ar.userObj;
1727 if (ar.exception != null) {
1728 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1729 } else {
1730 request.result = ((int[]) ar.result)[0];
1731 }
1732 notifyRequester(request);
1733 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001734 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1735 request = (MainThreadRequest) msg.obj;
1736 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1737 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001738 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1739 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001740 break;
1741 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1742 ar = (AsyncResult) msg.obj;
1743 request = (MainThreadRequest) ar.userObj;
1744 request.result = ar.exception == null;
1745 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001746 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001747 case CMD_GET_ALL_CELL_INFO:
1748 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001749 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001750 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001751 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001752 case EVENT_GET_ALL_CELL_INFO_DONE:
1753 ar = (AsyncResult) msg.obj;
1754 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001755 // If a timeout occurs, the response will be null
1756 request.result = (ar.exception == null && ar.result != null)
1757 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001758 synchronized (request) {
1759 request.notifyAll();
1760 }
1761 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001762 case CMD_REQUEST_CELL_INFO_UPDATE:
1763 request = (MainThreadRequest) msg.obj;
1764 request.phone.requestCellInfoUpdate(request.workSource,
1765 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1766 break;
1767 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1768 ar = (AsyncResult) msg.obj;
1769 request = (MainThreadRequest) ar.userObj;
1770 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1771 try {
1772 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001773 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001774 cb.onError(
1775 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1776 ar.exception.getClass().getName(),
1777 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001778 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001779 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001780 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001781 } else {
1782 // use the result as returned
1783 cb.onCellInfo((List<CellInfo>) ar.result);
1784 }
1785 } catch (RemoteException re) {
1786 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1787 }
1788 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001789 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001790 request = (MainThreadRequest) msg.obj;
1791 WorkSource ws = (WorkSource) request.argument;
1792 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001793 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001794 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001795 }
1796 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001797 ar = (AsyncResult) msg.obj;
1798 request = (MainThreadRequest) ar.userObj;
1799 if (ar.exception == null) {
1800 request.result = ar.result;
1801 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001802 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001803 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001804 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001805 }
1806
1807 synchronized (request) {
1808 request.notifyAll();
1809 }
1810 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001811 }
chen xu6dac5ab2018-10-26 17:39:23 -07001812 case CMD_MODEM_REBOOT:
1813 request = (MainThreadRequest) msg.obj;
1814 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001815 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001816 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001817 case EVENT_CMD_MODEM_REBOOT_DONE:
1818 handleNullReturnEvent(msg, "rebootModem");
1819 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001820 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001821 request = (MainThreadRequest) msg.obj;
1822 boolean enable = (boolean) request.argument;
1823 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001824 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001825 PhoneConfigurationManager.getInstance()
1826 .enablePhone(request.phone, enable, onCompleted);
1827 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001828 }
Michele Berionne5e411512020-11-13 02:36:59 +00001829 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001830 ar = (AsyncResult) msg.obj;
1831 request = (MainThreadRequest) ar.userObj;
1832 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001833 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001834 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001835 if ((boolean) request.result) {
1836 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1837 updateModemStateMetrics();
1838 } else {
1839 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1840 + ar.exception);
1841 }
1842 notifyRequester(request);
1843 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001844 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001845 case CMD_GET_MODEM_STATUS:
1846 request = (MainThreadRequest) msg.obj;
1847 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1848 PhoneConfigurationManager.getInstance()
1849 .getPhoneStatusFromModem(request.phone, onCompleted);
1850 break;
1851 case EVENT_GET_MODEM_STATUS_DONE:
1852 ar = (AsyncResult) msg.obj;
1853 request = (MainThreadRequest) ar.userObj;
1854 int id = request.phone.getPhoneId();
1855 if (ar.exception == null && ar.result != null) {
1856 request.result = ar.result;
1857 //update the cache as modem status has changed
1858 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1859 (boolean) request.result);
1860 } else {
1861 // Return true if modem status cannot be retrieved. For most cases,
1862 // modem status is on. And for older version modems, GET_MODEM_STATUS
1863 // and disable modem are not supported. Modem is always on.
1864 // TODO: this should be fixed in R to support a third
1865 // status UNKNOWN b/131631629
1866 request.result = true;
1867 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1868 + ar.exception);
1869 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001870 notifyRequester(request);
1871 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001872 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1873 request = (MainThreadRequest) msg.obj;
1874 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1875 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1876 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1877 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1878 break;
1879 }
1880 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1881 ar = (AsyncResult) msg.obj;
1882 request = (MainThreadRequest) ar.userObj;
1883 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1884 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1885 args.second.accept(ar.exception == null);
1886 notifyRequester(request);
1887 break;
1888 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001889 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1890 request = (MainThreadRequest) msg.obj;
1891 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1892 Phone phone = getPhoneFromRequest(request);
1893 if (phone != null) {
1894 phone.getSystemSelectionChannels(onCompleted);
1895 } else {
1896 loge("getSystemSelectionChannels: No phone object");
1897 request.result = new ArrayList<RadioAccessSpecifier>();
1898 notifyRequester(request);
1899 }
1900 break;
1901 }
1902 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1903 ar = (AsyncResult) msg.obj;
1904 request = (MainThreadRequest) ar.userObj;
1905 if (ar.exception == null && ar.result != null) {
1906 request.result = ar.result;
1907 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001908 request.result = new IllegalStateException(
1909 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001910 if (ar.result == null) {
1911 loge("getSystemSelectionChannels: Empty response");
1912 } else {
1913 loge("getSystemSelectionChannels: Unknown exception");
1914 }
1915 }
1916 notifyRequester(request);
1917 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001918 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1919 ar = (AsyncResult) msg.obj;
1920 request = (MainThreadRequest) ar.userObj;
1921 if (ar.exception == null && ar.result != null) {
1922 request.result = ar.result;
1923 } else {
1924 request.result = -1;
1925 loge("Failed to set Forbidden Plmns");
1926 if (ar.result == null) {
1927 loge("setForbidenPlmns: Empty response");
1928 } else if (ar.exception != null) {
1929 loge("setForbiddenPlmns: Exception: " + ar.exception);
1930 request.result = -1;
1931 } else {
1932 loge("setForbiddenPlmns: Unknown exception");
1933 }
1934 }
1935 notifyRequester(request);
1936 break;
1937 case CMD_SET_FORBIDDEN_PLMNS:
1938 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001939 uiccPort = getUiccPortFromRequest(request);
1940 if (uiccPort == null) {
1941 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001942 request.result = -1;
1943 notifyRequester(request);
1944 break;
1945 }
1946 Pair<Integer, List<String>> setFplmnsArgs =
1947 (Pair<Integer, List<String>>) request.argument;
1948 appType = setFplmnsArgs.first;
1949 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001950 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001951 if (uiccApp == null) {
1952 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1953 request.result = -1;
1954 loge("Failed to get UICC App");
1955 notifyRequester(request);
1956 } else {
1957 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1958 ((SIMRecords) uiccApp.getIccRecords())
1959 .setForbiddenPlmns(onCompleted, fplmns);
1960 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001961 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001962 case CMD_ERASE_MODEM_CONFIG:
1963 request = (MainThreadRequest) msg.obj;
1964 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1965 defaultPhone.eraseModemConfig(onCompleted);
1966 break;
1967 case EVENT_ERASE_MODEM_CONFIG_DONE:
1968 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001969 break;
zoey chene02881a2019-12-30 16:11:23 +08001970
Kai Shif70f46f2021-03-03 13:59:46 -08001971 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1972 request = (MainThreadRequest) msg.obj;
1973 request.result = defaultPhone.eraseDataInSharedPreferences();
1974 notifyRequester(request);
1975 break;
1976
zoey chene02881a2019-12-30 16:11:23 +08001977 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1978 request = (MainThreadRequest) msg.obj;
1979 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1980 Pair<String, String> changed = (Pair<String, String>) request.argument;
1981 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1982 changed.first, changed.second, onCompleted);
1983 break;
1984 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1985 ar = (AsyncResult) msg.obj;
1986 request = (MainThreadRequest) ar.userObj;
1987 if (ar.exception == null) {
1988 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001989 // If the operation is successful, update the PIN storage
1990 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1991 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001992 UiccController.getInstance().getPinStorage()
1993 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001994 } else {
1995 request.result = msg.arg1;
1996 }
1997 notifyRequester(request);
1998 break;
1999
Michele Berionne5e411512020-11-13 02:36:59 +00002000 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002001 request = (MainThreadRequest) msg.obj;
2002 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2003 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2004 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2005 enabled.first, enabled.second, onCompleted);
2006 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002007 }
zoey chene02881a2019-12-30 16:11:23 +08002008 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2009 ar = (AsyncResult) msg.obj;
2010 request = (MainThreadRequest) ar.userObj;
2011 if (ar.exception == null) {
2012 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002013 // If the operation is successful, update the PIN storage
2014 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2015 int phoneId = getPhoneFromRequest(request).getPhoneId();
2016 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002017 UiccController.getInstance().getPinStorage()
2018 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002019 } else {
2020 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2021 }
zoey chene02881a2019-12-30 16:11:23 +08002022 } else {
2023 request.result = msg.arg1;
2024 }
Michele Berionne5e411512020-11-13 02:36:59 +00002025
2026
zoey chene02881a2019-12-30 16:11:23 +08002027 notifyRequester(request);
2028 break;
2029
Peter Wangdafb9ac2020-01-15 14:13:38 -08002030 case MSG_NOTIFY_USER_ACTIVITY:
2031 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002032 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002033 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2034 getDefaultPhone().getContext().sendBroadcastAsUser(
2035 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2036 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002037
2038 case CMD_SET_DATA_THROTTLING: {
2039 request = (MainThreadRequest) msg.obj;
2040 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2041 DataThrottlingRequest dataThrottlingRequest =
2042 (DataThrottlingRequest) request.argument;
2043 Phone phone = getPhoneFromRequest(request);
2044 if (phone != null) {
2045 phone.setDataThrottling(onCompleted,
2046 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2047 dataThrottlingRequest.getCompletionDurationMillis());
2048 } else {
2049 loge("setDataThrottling: No phone object");
2050 request.result =
2051 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2052 notifyRequester(request);
2053 }
2054
2055 break;
2056 }
2057 case EVENT_SET_DATA_THROTTLING_DONE:
2058 ar = (AsyncResult) msg.obj;
2059 request = (MainThreadRequest) ar.userObj;
2060
2061 if (ar.exception == null) {
2062 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2063 } else if (ar.exception instanceof CommandException) {
2064 loge("setDataThrottling: CommandException: " + ar.exception);
2065 CommandException.Error error =
2066 ((CommandException) (ar.exception)).getCommandError();
2067
2068 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2069 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002070 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002071 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2072 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002073 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2074 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002075 } else {
2076 request.result =
2077 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2078 }
2079 } else {
2080 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2081 }
2082 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2083 notifyRequester(request);
2084 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002085
2086 case CMD_SET_SIM_POWER: {
2087 request = (MainThreadRequest) msg.obj;
2088 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2089 request = (MainThreadRequest) msg.obj;
2090 int stateToSet =
2091 ((Pair<Integer, IIntegerConsumer>)
2092 request.argument).first;
2093 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2094 break;
2095 }
2096 case EVENT_SET_SIM_POWER_DONE: {
2097 ar = (AsyncResult) msg.obj;
2098 request = (MainThreadRequest) ar.userObj;
2099 IIntegerConsumer callback =
2100 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2101 if (ar.exception != null) {
2102 loge("setSimPower exception: " + ar.exception);
2103 int errorCode = TelephonyManager.CallForwardingInfoCallback
2104 .RESULT_ERROR_UNKNOWN;
2105 if (ar.exception instanceof CommandException) {
2106 CommandException.Error error =
2107 ((CommandException) (ar.exception)).getCommandError();
2108 if (error == CommandException.Error.SIM_ERR) {
2109 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2110 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2111 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2112 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2113 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2114 } else {
2115 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2116 }
2117 }
2118 try {
2119 callback.accept(errorCode);
2120 } catch (RemoteException e) {
2121 // Ignore if the remote process is no longer available to call back.
2122 Log.w(LOG_TAG, "setSimPower: callback not available.");
2123 }
2124 } else {
2125 try {
2126 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2127 } catch (RemoteException e) {
2128 // Ignore if the remote process is no longer available to call back.
2129 Log.w(LOG_TAG, "setSimPower: callback not available.");
2130 }
2131 }
2132 break;
2133 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002134 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2135 request = (MainThreadRequest) msg.obj;
2136
2137 final Phone phone = getPhoneFromRequest(request);
2138 if (phone == null || phone.getServiceStateTracker() == null) {
2139 request.result = new IllegalStateException("Phone or SST is null");
2140 notifyRequester(request);
2141 break;
2142 }
2143
2144 Pair<Integer, SignalStrengthUpdateRequest> pair =
2145 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2146 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2147 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002148 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002149 request.subId, pair.first /*callingUid*/,
2150 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002151 break;
2152 }
2153 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2154 ar = (AsyncResult) msg.obj;
2155 request = (MainThreadRequest) ar.userObj;
2156 // request.result will be the exception of ar if present, true otherwise.
2157 // Be cautious not to leave result null which will wait() forever
2158 request.result = ar.exception != null ? ar.exception : true;
2159 notifyRequester(request);
2160 break;
2161 }
2162 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2163 request = (MainThreadRequest) msg.obj;
2164
2165 Phone phone = getPhoneFromRequest(request);
2166 if (phone == null || phone.getServiceStateTracker() == null) {
2167 request.result = new IllegalStateException("Phone or SST is null");
2168 notifyRequester(request);
2169 break;
2170 }
2171
2172 Pair<Integer, SignalStrengthUpdateRequest> pair =
2173 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2174 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2175 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002176 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002177 request.subId, pair.first /*callingUid*/,
2178 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002179 break;
2180 }
2181 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2182 ar = (AsyncResult) msg.obj;
2183 request = (MainThreadRequest) ar.userObj;
2184 request.result = ar.exception != null ? ar.exception : true;
2185 notifyRequester(request);
2186 break;
2187 }
Jordan Liu109698e2020-11-24 14:50:34 -08002188
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002189 case CMD_GET_SLICING_CONFIG: {
2190 request = (MainThreadRequest) msg.obj;
2191 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2192 request.phone.getSlicingConfig(onCompleted);
2193 break;
2194 }
2195 case EVENT_GET_SLICING_CONFIG_DONE: {
2196 ar = (AsyncResult) msg.obj;
2197 request = (MainThreadRequest) ar.userObj;
2198 ResultReceiver result = (ResultReceiver) request.argument;
2199
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002200 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002201 Bundle bundle = new Bundle();
2202 int resultCode = 0;
2203 if (ar.exception != null) {
2204 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2205 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002206 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002207 } else if (ar.result == null) {
2208 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002209 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002210 } else {
2211 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002212 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2213 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002214 }
2215
2216 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002217 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002218 }
2219 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2220 result.send(resultCode, bundle);
2221 notifyRequester(request);
2222 break;
2223 }
2224
Sarah Chin71b3a852022-09-28 15:54:19 -07002225 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002226 request = (MainThreadRequest) msg.obj;
2227 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002228 PurchasePremiumCapabilityArgument arg =
2229 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin46355ba2022-11-01 23:51:16 -07002230 SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability(
Sarah Chinb8218c22023-01-04 13:35:29 -08002231 arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002232 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002233 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002234
Sarah Chin71b3a852022-09-28 15:54:19 -07002235 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002236 ar = (AsyncResult) msg.obj;
2237 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002238 PurchasePremiumCapabilityArgument arg =
2239 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002240 try {
2241 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002242 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002243 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002244 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002245 + ", result= "
2246 + TelephonyManager.convertPurchaseResultToString(result));
2247 } catch (RemoteException e) {
2248 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002249 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002250 + " failed: " + e;
2251 if (DBG) log(logStr);
2252 AnomalyReporter.reportAnomaly(
2253 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2254 }
2255 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002256 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002257
Michele Berionne5e411512020-11-13 02:36:59 +00002258 case CMD_PREPARE_UNATTENDED_REBOOT:
2259 request = (MainThreadRequest) msg.obj;
2260 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002261 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002262 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002263 notifyRequester(request);
2264 break;
2265
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002266 default:
2267 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2268 break;
2269 }
2270 }
Jake Hambye994d462014-02-03 13:10:13 -08002271
Pengquan Menga1bb6272018-09-06 09:59:22 -07002272 private void notifyRequester(MainThreadRequest request) {
2273 synchronized (request) {
2274 request.notifyAll();
2275 }
2276 }
2277
Jake Hambye994d462014-02-03 13:10:13 -08002278 private void handleNullReturnEvent(Message msg, String command) {
2279 AsyncResult ar = (AsyncResult) msg.obj;
2280 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2281 if (ar.exception == null) {
2282 request.result = true;
2283 } else {
2284 request.result = false;
2285 if (ar.exception instanceof CommandException) {
2286 loge(command + ": CommandException: " + ar.exception);
2287 } else {
2288 loge(command + ": Unknown exception");
2289 }
2290 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002291 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002292 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002293 }
2294
2295 /**
2296 * Posts the specified command to be executed on the main thread,
2297 * waits for the request to complete, and returns the result.
2298 * @see #sendRequestAsync
2299 */
2300 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002301 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2302 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002303 }
2304
2305 /**
2306 * Posts the specified command to be executed on the main thread,
2307 * waits for the request to complete, and returns the result.
2308 * @see #sendRequestAsync
2309 */
2310 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2311 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002312 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002313 }
2314
2315 /**
2316 * Posts the specified command to be executed on the main thread,
2317 * waits for the request to complete, and returns the result.
2318 * @see #sendRequestAsync
2319 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002320 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002321 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2322 }
2323
2324 /**
2325 * Posts the specified command to be executed on the main thread,
2326 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2327 * if not timeout or null otherwise.
2328 * @see #sendRequestAsync
2329 */
2330 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2331 long timeoutInMs) {
2332 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002333 }
2334
2335 /**
2336 * Posts the specified command to be executed on the main thread,
2337 * waits for the request to complete, and returns the result.
2338 * @see #sendRequestAsync
2339 */
Nathan Harold92bed182018-10-12 18:16:49 -07002340 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002341 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002342 }
2343
2344 /**
2345 * Posts the specified command to be executed on the main thread,
2346 * waits for the request to complete, and returns the result.
2347 * @see #sendRequestAsync
2348 */
2349 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002350 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2351 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002352 }
2353
2354 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002355 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2356 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2357 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002358 * @see #sendRequestAsync
2359 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002360 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2361 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002362 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2363 throw new RuntimeException("This method will deadlock if called from the main thread.");
2364 }
2365
Nathan Harold92bed182018-10-12 18:16:49 -07002366 MainThreadRequest request = null;
2367 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2368 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2369 } else if (phone != null) {
2370 request = new MainThreadRequest(argument, phone, workSource);
2371 } else {
2372 request = new MainThreadRequest(argument, subId, workSource);
2373 }
2374
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002375 Message msg = mMainThreadHandler.obtainMessage(command, request);
2376 msg.sendToTarget();
2377
Rambo Wang0f050d82021-02-12 11:43:36 -08002378
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002379 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002380 if (timeoutInMs >= 0) {
2381 // Wait for at least timeoutInMs before returning null request result
2382 long now = SystemClock.elapsedRealtime();
2383 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002384 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002385 try {
2386 request.wait(deadline - now);
2387 } catch (InterruptedException e) {
2388 // Do nothing, go back and check if request is completed or timeout
2389 } finally {
2390 now = SystemClock.elapsedRealtime();
2391 }
2392 }
2393 } else {
2394 // Wait for the request to complete
2395 while (request.result == null) {
2396 try {
2397 request.wait();
2398 } catch (InterruptedException e) {
2399 // Do nothing, go back and wait until the request is complete
2400 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002401 }
2402 }
2403 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002404 if (request.result == null) {
2405 Log.wtf(LOG_TAG,
2406 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2407 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002408 return request.result;
2409 }
2410
2411 /**
2412 * Asynchronous ("fire and forget") version of sendRequest():
2413 * Posts the specified command to be executed on the main thread, and
2414 * returns immediately.
2415 * @see #sendRequest
2416 */
2417 private void sendRequestAsync(int command) {
2418 mMainThreadHandler.sendEmptyMessage(command);
2419 }
2420
2421 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002422 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002423 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002424 */
2425 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002426 sendRequestAsync(command, argument, null, null);
2427 }
2428
2429 /**
2430 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2431 * @see {@link #sendRequest(int,Object)}
2432 */
2433 private void sendRequestAsync(
2434 int command, Object argument, Phone phone, WorkSource workSource) {
2435 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002436 Message msg = mMainThreadHandler.obtainMessage(command, request);
2437 msg.sendToTarget();
2438 }
2439
2440 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002441 * Initialize the singleton PhoneInterfaceManager instance.
2442 * This is only done once, at startup, from PhoneApp.onCreate().
2443 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002444 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002445 synchronized (PhoneInterfaceManager.class) {
2446 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002447 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002448 } else {
2449 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2450 }
2451 return sInstance;
2452 }
2453 }
2454
2455 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002456 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002457 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002458 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002459 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002460 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002461 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002462 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2463 mMainThreadHandler = new MainThreadHandler();
Jack Yue37dd262022-12-16 11:53:37 -08002464 if (!PhoneFactory.isSubscriptionManagerServiceEnabled()) {
2465 mSubscriptionController = SubscriptionController.getInstance();
2466 } else {
2467 mSubscriptionController = null;
2468 }
Sarah Chin4beb2b72023-02-14 14:47:54 -08002469 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002470 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002471 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002472 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002473 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002474 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002475 publish();
arunvoddud7401012022-12-15 16:08:12 +00002476 CarrierAllowListInfo.loadInstance(mApp);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002477 }
2478
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002479 @VisibleForTesting
2480 public SharedPreferences getSharedPreferences() {
2481 return mTelephonySharedPreferences;
2482 }
2483
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002484 /**
2485 * Get the default phone for this device.
2486 */
2487 @VisibleForTesting
2488 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002489 Phone thePhone = getPhone(getDefaultSubscription());
2490 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2491 }
2492
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002493 private void publish() {
2494 if (DBG) log("publish: " + this);
2495
Peter Wangc035ce42020-01-08 21:00:22 -08002496 TelephonyFrameworkInitializer
2497 .getTelephonyServiceManager()
2498 .getTelephonyServiceRegisterer()
2499 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002500 }
2501
Stuart Scott584921c2015-01-15 17:10:34 -08002502 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002503 if (request.phone != null) {
2504 return request.phone;
2505 } else {
2506 return getPhoneFromSubId(request.subId);
2507 }
2508 }
2509
2510 private Phone getPhoneFromSubId(int subId) {
2511 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2512 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002513 }
2514
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002515 /**
2516 * Get phone object associated with a subscription.
2517 * Return default phone if phone object associated with subscription is null
2518 * @param subId - subscriptionId
2519 * @return phone object associated with a subscription or default phone if null.
2520 */
2521 private Phone getPhoneFromSubIdOrDefault(int subId) {
2522 Phone phone = getPhoneFromSubId(subId);
2523 if (phone == null) {
2524 phone = getDefaultPhone();
2525 }
2526 return phone;
2527 }
2528
Rambo Wange53e07d2022-05-10 13:01:13 -07002529 @Nullable
2530 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002531 Phone phone = getPhoneFromRequest(request);
2532 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002533 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002534 }
2535
Wink Saville36469e72014-06-11 15:17:00 -07002536 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002537 private Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002538 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002539 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002540
Kai Shif70f46f2021-03-03 13:59:46 -08002541 private void sendEraseModemConfig(@NonNull Phone phone) {
2542 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2543 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2544 }
2545
2546 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2547 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2548 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002549 }
2550
Peter Wang44b186e2020-01-13 23:33:09 -08002551 private boolean isImsAvailableOnDevice() {
2552 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2553 if (pm == null) {
2554 // For some reason package manger is not available.. This will fail internally anyway,
2555 // so do not throw error and allow.
2556 return true;
2557 }
2558 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2559 }
2560
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002561 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002562 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002563 }
2564
Wink Savilleb564aae2014-10-23 10:18:09 -07002565 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002566 if (DBG) log("dial: " + number);
2567 // No permission check needed here: This is just a wrapper around the
2568 // ACTION_DIAL intent, which is available to any app since it puts up
2569 // the UI before it does anything.
2570
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002571 final long identity = Binder.clearCallingIdentity();
2572 try {
2573 String url = createTelUrl(number);
2574 if (url == null) {
2575 return;
2576 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002577
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002578 // PENDING: should we just silently fail if phone is offhook or ringing?
2579 PhoneConstants.State state = mCM.getState(subId);
2580 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2581 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2582 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2583 mApp.startActivity(intent);
2584 }
2585 } finally {
2586 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002587 }
2588 }
2589
2590 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002591 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002592 }
2593
Wink Savilleb564aae2014-10-23 10:18:09 -07002594 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002595 if (DBG) log("call: " + number);
2596
2597 // This is just a wrapper around the ACTION_CALL intent, but we still
2598 // need to do a permission check since we're calling startActivity()
2599 // from the context of the phone app.
2600 enforceCallPermission();
2601
Jordan Liu1617b712019-07-10 15:06:26 -07002602 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002603 != AppOpsManager.MODE_ALLOWED) {
2604 return;
2605 }
2606
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002607 final long identity = Binder.clearCallingIdentity();
2608 try {
2609 String url = createTelUrl(number);
2610 if (url == null) {
2611 return;
2612 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002613
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002614 boolean isValid = false;
2615 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2616 if (slist != null) {
2617 for (SubscriptionInfo subInfoRecord : slist) {
2618 if (subInfoRecord.getSubscriptionId() == subId) {
2619 isValid = true;
2620 break;
2621 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002622 }
Wink Saville08874612014-08-31 19:19:58 -07002623 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002624 if (!isValid) {
2625 return;
2626 }
Wink Saville08874612014-08-31 19:19:58 -07002627
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002628 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2629 intent.putExtra(SUBSCRIPTION_KEY, subId);
2630 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2631 mApp.startActivity(intent);
2632 } finally {
2633 Binder.restoreCallingIdentity(identity);
2634 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002635 }
2636
Wink Savilleb564aae2014-10-23 10:18:09 -07002637 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002638 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002639 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2640 }
2641
Wink Savilleb564aae2014-10-23 10:18:09 -07002642 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002643 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002644 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2645 }
2646
Wink Savilleb564aae2014-10-23 10:18:09 -07002647 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002648 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002649
2650 final long identity = Binder.clearCallingIdentity();
2651 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002652 Phone phone = getPhone(subId);
2653 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002654 checkSimPin.start();
2655 return checkSimPin.unlockSim(null, pin);
2656 } finally {
2657 Binder.restoreCallingIdentity(identity);
2658 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002659 }
2660
Wink Savilleb564aae2014-10-23 10:18:09 -07002661 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002662 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002663
2664 final long identity = Binder.clearCallingIdentity();
2665 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002666 Phone phone = getPhone(subId);
2667 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002668 checkSimPuk.start();
2669 return checkSimPuk.unlockSim(puk, pin);
2670 } finally {
2671 Binder.restoreCallingIdentity(identity);
2672 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002673 }
2674
2675 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002676 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002677 * a synchronous one.
2678 */
2679 private static class UnlockSim extends Thread {
2680
2681 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002682 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002683
2684 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002685 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2686 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002687
2688 // For replies from SimCard interface
2689 private Handler mHandler;
2690
2691 // For async handler to identify request type
2692 private static final int SUPPLY_PIN_COMPLETE = 100;
2693
Michele Berionne5e411512020-11-13 02:36:59 +00002694 UnlockSim(int phoneId, IccCard simCard) {
2695 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002696 mSimCard = simCard;
2697 }
2698
2699 @Override
2700 public void run() {
2701 Looper.prepare();
2702 synchronized (UnlockSim.this) {
2703 mHandler = new Handler() {
2704 @Override
2705 public void handleMessage(Message msg) {
2706 AsyncResult ar = (AsyncResult) msg.obj;
2707 switch (msg.what) {
2708 case SUPPLY_PIN_COMPLETE:
2709 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2710 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002711 mRetryCount = msg.arg1;
2712 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002713 CommandException.Error error = null;
2714 if (ar.exception instanceof CommandException) {
2715 error = ((CommandException) (ar.exception))
2716 .getCommandError();
2717 }
2718 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002719 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002720 } else if (error == CommandException.Error.ABORTED) {
2721 /* When UiccCardApp dispose, handle message and return
2722 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002723 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002724 } else {
2725 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2726 }
2727 } else {
2728 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2729 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002730 mDone = true;
2731 UnlockSim.this.notifyAll();
2732 }
2733 break;
2734 }
2735 }
2736 };
2737 UnlockSim.this.notifyAll();
2738 }
2739 Looper.loop();
2740 }
2741
2742 /*
2743 * Use PIN or PUK to unlock SIM card
2744 *
2745 * If PUK is null, unlock SIM card with PIN
2746 *
2747 * If PUK is not null, unlock SIM card with PUK and set PIN code
2748 */
Wink Saville9de0f752013-10-22 19:04:03 -07002749 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002750
2751 while (mHandler == null) {
2752 try {
2753 wait();
2754 } catch (InterruptedException e) {
2755 Thread.currentThread().interrupt();
2756 }
2757 }
2758 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2759
2760 if (puk == null) {
2761 mSimCard.supplyPin(pin, callback);
2762 } else {
2763 mSimCard.supplyPuk(puk, pin, callback);
2764 }
2765
2766 while (!mDone) {
2767 try {
2768 Log.d(LOG_TAG, "wait for done");
2769 wait();
2770 } catch (InterruptedException e) {
2771 // Restore the interrupted status
2772 Thread.currentThread().interrupt();
2773 }
2774 }
2775 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002776 int[] resultArray = new int[2];
2777 resultArray[0] = mResult;
2778 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002779
2780 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002781 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002782 }
2783
Wink Saville9de0f752013-10-22 19:04:03 -07002784 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002785 }
2786 }
2787
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002788 /**
2789 * This method has been removed due to privacy and stability concerns.
2790 */
2791 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002792 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002793 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2794 return;
Wink Saville36469e72014-06-11 15:17:00 -07002795 }
2796
Nathan Harold1f889d82020-06-04 17:05:26 -07002797 @Override
2798 public void updateServiceLocationWithPackageName(String callingPackage) {
2799 mApp.getSystemService(AppOpsManager.class)
2800 .checkPackage(Binder.getCallingUid(), callingPackage);
2801
Nathan Haroldf096d982020-11-18 17:18:06 -08002802 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002803 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2804 // Callers targeting S have no business invoking this method.
2805 return;
2806 }
2807
2808 LocationAccessPolicy.LocationPermissionResult locationResult =
2809 LocationAccessPolicy.checkLocationPermission(mApp,
2810 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2811 .setCallingPackage(callingPackage)
2812 .setCallingFeatureId(null)
2813 .setCallingPid(Binder.getCallingPid())
2814 .setCallingUid(Binder.getCallingUid())
2815 .setMethod("updateServiceLocation")
2816 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2817 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2818 .build());
2819 // Apps that lack location permission have no business calling this method;
2820 // however, because no permission was declared in the public API, denials must
2821 // all be "soft".
2822 switch (locationResult) {
2823 case DENIED_HARD: /* fall through */
2824 case DENIED_SOFT:
2825 return;
2826 }
2827
2828 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002829 final long identity = Binder.clearCallingIdentity();
2830 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002831 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002832 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002833 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002834 }
2835 } finally {
2836 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002837 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002838 }
2839
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002840 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002841 @Override
2842 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002843 return isRadioOnWithFeature(callingPackage, null);
2844 }
2845
2846
2847 @Override
2848 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2849 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2850 callingFeatureId);
2851 }
2852
2853 @Deprecated
2854 @Override
2855 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2856 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002857 }
2858
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002859 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002860 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2861 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002862 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002863 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002864 return false;
2865 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002866
2867 final long identity = Binder.clearCallingIdentity();
2868 try {
2869 return isRadioOnForSubscriber(subId);
2870 } finally {
2871 Binder.restoreCallingIdentity(identity);
2872 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002873 }
2874
2875 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002876 final long identity = Binder.clearCallingIdentity();
2877 try {
2878 final Phone phone = getPhone(subId);
2879 if (phone != null) {
2880 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2881 } else {
2882 return false;
2883 }
2884 } finally {
2885 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002886 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002887 }
2888
2889 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002890 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002891 }
Wink Saville36469e72014-06-11 15:17:00 -07002892
Wink Savilleb564aae2014-10-23 10:18:09 -07002893 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002894 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002895
2896 final long identity = Binder.clearCallingIdentity();
2897 try {
2898 final Phone phone = getPhone(subId);
2899 if (phone != null) {
2900 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2901 }
2902 } finally {
2903 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002904 }
Wink Saville36469e72014-06-11 15:17:00 -07002905 }
2906
2907 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002908 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002909 }
2910
Wink Savilleb564aae2014-10-23 10:18:09 -07002911 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002912 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002913
2914 final long identity = Binder.clearCallingIdentity();
2915 try {
2916 final Phone phone = getPhone(subId);
2917 if (phone == null) {
2918 return false;
2919 }
2920 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2921 toggleRadioOnOffForSubscriber(subId);
2922 }
2923 return true;
2924 } finally {
2925 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002926 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002927 }
Wink Saville36469e72014-06-11 15:17:00 -07002928
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002929 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002930 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002931 /*
2932 * If any of the Radios are available, it will need to be
2933 * shutdown. So return true if any Radio is available.
2934 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002935 final long identity = Binder.clearCallingIdentity();
2936 try {
2937 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2938 Phone phone = PhoneFactory.getPhone(i);
2939 if (phone != null && phone.isRadioAvailable()) return true;
2940 }
2941 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2942 return false;
2943 } finally {
2944 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002945 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002946 }
2947
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002948 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002949 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002950 enforceModifyPermission();
2951
2952 final long identity = Binder.clearCallingIdentity();
2953 try {
2954 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2955 logv("Shutting down Phone " + i);
2956 shutdownRadioUsingPhoneId(i);
2957 }
2958 } finally {
2959 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002960 }
2961 }
2962
2963 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002964 Phone phone = PhoneFactory.getPhone(phoneId);
2965 if (phone != null && phone.isRadioAvailable()) {
2966 phone.shutdownRadio();
2967 }
2968 }
2969
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002970 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002971 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002972
Ling Ma83dc5ea2023-01-12 15:06:04 -08002973 if (!turnOn) {
2974 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
2975 }
2976
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002977 final long identity = Binder.clearCallingIdentity();
2978 try {
2979 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2980 if (defaultPhone != null) {
2981 defaultPhone.setRadioPower(turnOn);
2982 return true;
2983 } else {
2984 loge("There's no default phone.");
2985 return false;
2986 }
2987 } finally {
2988 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002989 }
Wink Saville36469e72014-06-11 15:17:00 -07002990 }
2991
Wink Savilleb564aae2014-10-23 10:18:09 -07002992 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002993 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002994
Ling Ma83dc5ea2023-01-12 15:06:04 -08002995 if (!turnOn) {
2996 log("setRadioPowerForSubscriber off: subId=" + subId
2997 + ",callingPackage=" + getCurrentPackageName());
2998 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002999 final long identity = Binder.clearCallingIdentity();
3000 try {
3001 final Phone phone = getPhone(subId);
3002 if (phone != null) {
3003 phone.setRadioPower(turnOn);
3004 return true;
3005 } else {
3006 return false;
3007 }
3008 } finally {
3009 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003010 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003011 }
3012
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003013 /**
3014 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3015 * no reason to power it off. When any of the voters want to power it off, it will be turned
3016 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3017 * powering it off, and these radio off votes will be cleared.
3018 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3019 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3020 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3021 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3022 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3023 * check its vote.
3024 *
3025 * @param subId The subscription ID.
3026 * @param reason The reason for powering off radio.
3027 * @return true on success and false on failure.
3028 */
3029 public boolean requestRadioPowerOffForReason(int subId,
3030 @TelephonyManager.RadioPowerReason int reason) {
3031 enforceModifyPermission();
3032
Ling Ma83dc5ea2023-01-12 15:06:04 -08003033 log("requestRadioPowerOffForReason: subId=" + subId
3034 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003035 final long identity = Binder.clearCallingIdentity();
3036 try {
3037 final Phone phone = getPhone(subId);
3038 if (phone != null) {
3039 phone.setRadioPowerForReason(false, reason);
3040 return true;
3041 } else {
3042 return false;
3043 }
3044 } finally {
3045 Binder.restoreCallingIdentity(identity);
3046 }
3047 }
3048
3049 /**
3050 * Remove the vote on powering off the radio for a reason, as requested by
3051 * {@link requestRadioPowerOffForReason}.
3052 *
3053 * @param subId The subscription ID.
3054 * @param reason The reason for powering off radio.
3055 * @return true on success and false on failure.
3056 */
3057 public boolean clearRadioPowerOffForReason(int subId,
3058 @TelephonyManager.RadioPowerReason int reason) {
3059 enforceModifyPermission();
3060
3061 final long identity = Binder.clearCallingIdentity();
3062 try {
3063 final Phone phone = getPhone(subId);
3064 if (phone != null) {
3065 phone.setRadioPowerForReason(true, reason);
3066 return true;
3067 } else {
3068 return false;
3069 }
3070 } finally {
3071 Binder.restoreCallingIdentity(identity);
3072 }
3073 }
3074
3075 /**
3076 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3077 *
3078 * @param subId The subscription ID.
3079 * @param callingPackage The package making the call.
3080 * @param callingFeatureId The feature in the package.
3081 * @return List of reasons for powering off radio.
3082 */
3083 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3084 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3085
3086 final long identity = Binder.clearCallingIdentity();
3087 List result = new ArrayList();
3088 try {
3089 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3090 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3091 return result;
3092 }
3093
3094 final Phone phone = getPhone(subId);
3095 if (phone != null) {
3096 result.addAll(phone.getRadioPowerOffReasons());
3097 }
3098 } finally {
3099 Binder.restoreCallingIdentity(identity);
3100 }
3101 return result;
3102 }
3103
Wink Saville36469e72014-06-11 15:17:00 -07003104 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003105 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003106 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003107 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003108
3109 final long identity = Binder.clearCallingIdentity();
3110 try {
Jack Yu285100e2022-12-02 22:48:35 -08003111 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003112 final Phone phone = getPhone(subId);
3113 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003114 phone.getDataSettingsManager().setDataEnabled(
3115 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003116 return true;
3117 } else {
3118 return false;
3119 }
3120 } finally {
3121 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003122 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003123 }
3124
Wink Saville36469e72014-06-11 15:17:00 -07003125 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003126 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003127 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003128 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003129
3130 final long identity = Binder.clearCallingIdentity();
3131 try {
Jack Yu285100e2022-12-02 22:48:35 -08003132 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003133 final Phone phone = getPhone(subId);
3134 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003135 phone.getDataSettingsManager().setDataEnabled(
3136 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003137 return true;
3138 } else {
3139 return false;
3140 }
3141 } finally {
3142 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003143 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003144 }
3145
Sanket Padawe356d7632015-06-22 14:03:32 -07003146 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003147 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003148 final long identity = Binder.clearCallingIdentity();
3149 try {
3150 final Phone phone = getPhone(subId);
3151 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003152 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003153 } else {
3154 return false;
3155 }
3156 } finally {
3157 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003158 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003159 }
3160
3161 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003162 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003163 }
3164
pkanwarae03a6b2016-11-06 20:37:09 -08003165 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003166 enforceCallPermission();
3167
3168 final long identity = Binder.clearCallingIdentity();
3169 try {
3170 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3171 return;
3172 }
3173 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3174 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3175 } finally {
3176 Binder.restoreCallingIdentity(identity);
3177 }
pkanwar32d516d2016-10-14 19:37:38 -07003178 };
3179
Wink Savilleb564aae2014-10-23 10:18:09 -07003180 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003181 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003182
3183 final long identity = Binder.clearCallingIdentity();
3184 try {
3185 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3186 return false;
3187 }
3188 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3189 } finally {
3190 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003191 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003192 }
3193
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003194 /**
3195 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3196 * tag on getCallState Binder call.
3197 */
3198 @Deprecated
3199 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003200 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003201 if (CompatChanges.isChangeEnabled(
3202 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3203 Binder.getCallingUid())) {
3204 // Do not allow this API to be called on API version 31+, it should only be
3205 // called on old apps using this Binder call directly.
3206 throw new SecurityException("This method can only be used for applications "
3207 + "targeting API version 30 or less.");
3208 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003209 final long identity = Binder.clearCallingIdentity();
3210 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003211 Phone phone = getPhone(getDefaultSubscription());
3212 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3213 PhoneConstantConversions.convertCallState(phone.getState());
3214 } finally {
3215 Binder.restoreCallingIdentity(identity);
3216 }
3217 }
3218
3219 @Override
3220 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3221 if (CompatChanges.isChangeEnabled(
3222 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3223 Binder.getCallingUid())) {
3224 // Check READ_PHONE_STATE for API version 31+
3225 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3226 featureId, "getCallStateForSubscription")) {
3227 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3228 + "targeting API level 31+.");
3229 }
3230 }
3231 final long identity = Binder.clearCallingIdentity();
3232 try {
3233 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003234 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3235 PhoneConstantConversions.convertCallState(phone.getState());
3236 } finally {
3237 Binder.restoreCallingIdentity(identity);
3238 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003239 }
3240
Sanket Padawe356d7632015-06-22 14:03:32 -07003241 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003242 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003243 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003244 }
3245
3246 @Override
3247 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003248 final long identity = Binder.clearCallingIdentity();
3249 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003250 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003251 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003252 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003253 } else {
3254 return PhoneConstantConversions.convertDataState(
3255 PhoneConstants.DataState.DISCONNECTED);
3256 }
3257 } finally {
3258 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003259 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003260 }
3261
Sanket Padawe356d7632015-06-22 14:03:32 -07003262 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003263 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003264 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003265 }
3266
3267 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003268 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003269 final long identity = Binder.clearCallingIdentity();
3270 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003271 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003272 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003273 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003274 } else {
3275 return TelephonyManager.DATA_ACTIVITY_NONE;
3276 }
3277 } finally {
3278 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003279 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003280 }
3281
3282 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003283 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003284 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003285 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003286
3287 LocationAccessPolicy.LocationPermissionResult locationResult =
3288 LocationAccessPolicy.checkLocationPermission(mApp,
3289 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3290 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003291 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003292 .setCallingPid(Binder.getCallingPid())
3293 .setCallingUid(Binder.getCallingUid())
3294 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003295 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003296 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3297 .build());
3298 switch (locationResult) {
3299 case DENIED_HARD:
3300 throw new SecurityException("Not allowed to access cell location");
3301 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003302 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3303 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003304 }
3305
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003306 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003307 final long identity = Binder.clearCallingIdentity();
3308 try {
3309 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003310 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003311 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003312 } finally {
3313 Binder.restoreCallingIdentity(identity);
3314 }
Svetoslav64fad262015-04-14 14:35:21 -07003315 }
3316
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003317 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003318 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003319 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3320 // registered cell info, so return a NULL country instead.
3321 final long identity = Binder.clearCallingIdentity();
3322 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003323 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3324 // Get default phone in this case.
3325 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3326 }
Jack Yu285100e2022-12-02 22:48:35 -08003327 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003328 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003329 if (phone == null) return "";
3330 ServiceStateTracker sst = phone.getServiceStateTracker();
3331 if (sst == null) return "";
3332 LocaleTracker lt = sst.getLocaleTracker();
3333 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003334 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003335 } finally {
3336 Binder.restoreCallingIdentity(identity);
3337 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003338 }
3339
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003340 /**
3341 * This method was removed due to potential issues caused by performing partial
3342 * updates of service state, and lack of a credible use case.
3343 *
3344 * This has the ability to break the telephony implementation by disabling notification of
3345 * changes in device connectivity. DO NOT USE THIS!
3346 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003347 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003348 public void enableLocationUpdates() {
3349 mApp.enforceCallingOrSelfPermission(
3350 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003351 }
3352
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003353 /**
3354 * This method was removed due to potential issues caused by performing partial
3355 * updates of service state, and lack of a credible use case.
3356 *
3357 * This has the ability to break the telephony implementation by disabling notification of
3358 * changes in device connectivity. DO NOT USE THIS!
3359 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003360 @Override
3361 public void disableLocationUpdates() {
3362 mApp.enforceCallingOrSelfPermission(
3363 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003364 }
3365
3366 @Override
3367 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003368 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3369 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003370 try {
3371 mApp.getSystemService(AppOpsManager.class)
3372 .checkPackage(Binder.getCallingUid(), callingPackage);
3373 } catch (SecurityException e) {
3374 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3375 throw e;
3376 }
3377
Nathan Haroldf096d982020-11-18 17:18:06 -08003378 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003379 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3380 throw new SecurityException(
3381 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3382 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003383
Jordan Liu1617b712019-07-10 15:06:26 -07003384 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003385 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3386 return null;
3387 }
Svetoslav64fad262015-04-14 14:35:21 -07003388
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003389 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003390
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003391 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003392 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003393
Nathan Haroldf180aac2018-06-01 18:43:55 -07003394 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3395 for (CellInfo ci : info) {
3396 if (ci instanceof CellInfoGsm) {
3397 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3398 } else if (ci instanceof CellInfoWcdma) {
3399 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3400 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003401 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003402 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003403 }
3404
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003405 private List<CellInfo> getCachedCellInfo() {
3406 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3407 for (Phone phone : PhoneFactory.getPhones()) {
3408 List<CellInfo> info = phone.getAllCellInfo();
3409 if (info != null) cellInfos.addAll(info);
3410 }
3411 return cellInfos;
3412 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003413
3414 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003415 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003416 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003417 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003418
3419 LocationAccessPolicy.LocationPermissionResult locationResult =
3420 LocationAccessPolicy.checkLocationPermission(mApp,
3421 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3422 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003423 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003424 .setCallingPid(Binder.getCallingPid())
3425 .setCallingUid(Binder.getCallingUid())
3426 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003427 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003428 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3429 .build());
3430 switch (locationResult) {
3431 case DENIED_HARD:
3432 throw new SecurityException("Not allowed to access cell info");
3433 case DENIED_SOFT:
3434 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003435 }
3436
Nathan Haroldf096d982020-11-18 17:18:06 -08003437 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003438 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3439 return getCachedCellInfo();
3440 }
3441
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003442 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003443 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003444 final long identity = Binder.clearCallingIdentity();
3445 try {
3446 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3447 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003448 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003449 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003450 if (info != null) cellInfos.addAll(info);
3451 }
3452 return cellInfos;
3453 } finally {
3454 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003455 }
3456 }
3457
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003458 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003459 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3460 String callingFeatureId) {
3461 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3462 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003463 }
3464
3465 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003466 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3467 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003468 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003469 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003470 }
3471
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003472 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3473 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003474 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003475 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003476
3477 LocationAccessPolicy.LocationPermissionResult locationResult =
3478 LocationAccessPolicy.checkLocationPermission(mApp,
3479 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3480 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003481 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003482 .setCallingPid(Binder.getCallingPid())
3483 .setCallingUid(Binder.getCallingUid())
3484 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003485 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3486 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003487 .build());
3488 switch (locationResult) {
3489 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003490 if (TelephonyPermissions
3491 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003492 // Safetynet logging for b/154934934
3493 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3494 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003495 throw new SecurityException("Not allowed to access cell info");
3496 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003497 if (TelephonyPermissions
3498 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003499 // Safetynet logging for b/154934934
3500 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3501 }
Nathan Harold5320c422019-05-09 10:26:08 -07003502 try {
3503 cb.onCellInfo(new ArrayList<CellInfo>());
3504 } catch (RemoteException re) {
3505 // Drop without consequences
3506 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003507 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003508 }
3509
Nathan Harolda939a962019-05-09 10:13:47 -07003510
3511 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003512 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3513
3514 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3515 }
3516
3517 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003518 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003519 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003520 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003521
3522 final long identity = Binder.clearCallingIdentity();
3523 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003524 Phone phone = getPhone(subId);
3525 if (phone == null) {
3526 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3527 } else {
3528 phone.setCellInfoListRate(rateInMillis, workSource);
3529 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003530 } finally {
3531 Binder.restoreCallingIdentity(identity);
3532 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003533 }
3534
Shishir Agrawala9f32182016-04-12 12:00:16 -07003535 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003536 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003537 Phone phone = PhoneFactory.getPhone(slotIndex);
3538 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003539 return null;
3540 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003541 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003542 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003543 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003544 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003545 return null;
3546 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003547
3548 final long identity = Binder.clearCallingIdentity();
3549 try {
3550 return phone.getImei();
3551 } finally {
3552 Binder.restoreCallingIdentity(identity);
3553 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003554 }
3555
3556 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003557 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3558 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3559 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3560 callingFeatureId, "getPrimaryImei")) {
3561 throw new SecurityException("Caller does not have permission");
3562 }
3563 final long identity = Binder.clearCallingIdentity();
3564 try {
3565 for (Phone phone : PhoneFactory.getPhones()) {
3566 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3567 return phone.getImei();
3568 }
3569 }
3570 throw new UnsupportedOperationException("Operation not supported");
3571 } finally {
3572 Binder.restoreCallingIdentity(identity);
3573 }
3574 }
3575
3576 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003577 public String getTypeAllocationCodeForSlot(int slotIndex) {
3578 Phone phone = PhoneFactory.getPhone(slotIndex);
3579 String tac = null;
3580 if (phone != null) {
3581 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003582 try {
3583 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3584 } catch (IndexOutOfBoundsException e) {
3585 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3586 return null;
3587 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003588 }
3589 return tac;
3590 }
3591
3592 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003593 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003594 try {
3595 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3596 } catch (SecurityException se) {
3597 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3598 throw new SecurityException("Package " + callingPackage + " does not belong to "
3599 + Binder.getCallingUid());
3600 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003601 Phone phone = PhoneFactory.getPhone(slotIndex);
3602 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003603 return null;
3604 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003605
Jeff Davidson913390f2018-02-23 17:11:49 -08003606 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003607 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003608 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003609 return null;
3610 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003611
3612 final long identity = Binder.clearCallingIdentity();
3613 try {
3614 return phone.getMeid();
3615 } finally {
3616 Binder.restoreCallingIdentity(identity);
3617 }
Jack Yu2af8d712017-03-15 17:14:14 -07003618 }
3619
3620 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003621 public String getManufacturerCodeForSlot(int slotIndex) {
3622 Phone phone = PhoneFactory.getPhone(slotIndex);
3623 String manufacturerCode = null;
3624 if (phone != null) {
3625 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003626 try {
3627 manufacturerCode =
3628 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3629 } catch (IndexOutOfBoundsException e) {
3630 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3631 return null;
3632 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003633 }
3634 return manufacturerCode;
3635 }
3636
3637 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003638 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3639 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003640 Phone phone = PhoneFactory.getPhone(slotIndex);
3641 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003642 return null;
3643 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003644 int subId = phone.getSubId();
3645 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003646 mApp, subId, callingPackage, callingFeatureId,
3647 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003648 return null;
3649 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003650
3651 final long identity = Binder.clearCallingIdentity();
3652 try {
3653 return phone.getDeviceSvn();
3654 } finally {
3655 Binder.restoreCallingIdentity(identity);
3656 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003657 }
3658
fionaxu43304da2017-11-27 22:51:16 -08003659 @Override
3660 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003661 final long identity = Binder.clearCallingIdentity();
3662 try {
3663 final Phone phone = getPhone(subId);
3664 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3665 } finally {
3666 Binder.restoreCallingIdentity(identity);
3667 }
fionaxu43304da2017-11-27 22:51:16 -08003668 }
3669
3670 @Override
3671 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003672 final long identity = Binder.clearCallingIdentity();
3673 try {
3674 final Phone phone = getPhone(subId);
3675 return phone == null ? null : phone.getCarrierName();
3676 } finally {
3677 Binder.restoreCallingIdentity(identity);
3678 }
fionaxu43304da2017-11-27 22:51:16 -08003679 }
3680
calvinpanffe225e2018-11-01 19:43:06 +08003681 @Override
chen xu0026ca62019-03-06 15:28:50 -08003682 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003683 final long identity = Binder.clearCallingIdentity();
3684 try {
3685 final Phone phone = getPhone(subId);
3686 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003687 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003688 } finally {
3689 Binder.restoreCallingIdentity(identity);
3690 }
3691 }
3692
3693 @Override
chen xu0026ca62019-03-06 15:28:50 -08003694 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003695 final long identity = Binder.clearCallingIdentity();
3696 try {
3697 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003698 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003699 } finally {
3700 Binder.restoreCallingIdentity(identity);
3701 }
3702 }
3703
chen xu651eec72018-11-11 19:03:44 -08003704 @Override
chen xu864e11c2018-12-06 22:10:03 -08003705 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3706 if (!isSubscriptionMccMnc) {
3707 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3708 }
chen xu651eec72018-11-11 19:03:44 -08003709 final Phone phone = PhoneFactory.getPhone(slotIndex);
3710 if (phone == null) {
3711 return TelephonyManager.UNKNOWN_CARRIER_ID;
3712 }
3713 final long identity = Binder.clearCallingIdentity();
3714 try {
3715 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3716 } finally {
3717 Binder.restoreCallingIdentity(identity);
3718 }
3719 }
3720
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003721 //
3722 // Internal helper methods.
3723 //
3724
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003725 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003726 * Make sure the caller is the calling package itself
3727 *
3728 * @throws SecurityException if the caller is not the calling package
3729 */
3730 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3731 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003732 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3733 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003734 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003735 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003736 } catch (PackageManager.NameNotFoundException e) {
3737 // packageUid is -1
3738 }
3739 if (packageUid != callingUid) {
3740 throw new SecurityException(message + ": Package " + callingPackage
3741 + " does not belong to " + callingUid);
3742 }
3743 }
3744
3745 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003746 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3747 *
3748 * @throws SecurityException if the caller does not have the required permission
3749 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003750 @VisibleForTesting
3751 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003752 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3753 }
3754
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003755 /**
arunvoddud7401012022-12-15 16:08:12 +00003756 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003757 *
3758 * @throws SecurityException if the caller does not have the required permission
3759 */
3760 @VisibleForTesting
3761 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003762 enforceReadPermission(null);
3763 }
3764
3765 /**
3766 * Make sure the caller has the READ_PHONE_STATE permissions.
3767 *
3768 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3769 */
3770 @VisibleForTesting
3771 public void enforceReadPermission(String msg) {
3772 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003773 }
3774
Shuo Qian3b6ee772019-11-13 17:43:31 -08003775 private void enforceActiveEmergencySessionPermission() {
3776 mApp.enforceCallingOrSelfPermission(
3777 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3778 }
3779
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003780 /**
3781 * Make sure the caller has the CALL_PHONE permission.
3782 *
3783 * @throws SecurityException if the caller does not have the required permission
3784 */
3785 private void enforceCallPermission() {
3786 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3787 }
3788
paulhu5a773602019-08-23 19:17:33 +08003789 private void enforceSettingsPermission() {
3790 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003791 }
3792
Michele Berionne5e411512020-11-13 02:36:59 +00003793 private void enforceRebootPermission() {
3794 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3795 }
3796
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003797 /**
3798 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3799 * @param message - log message to print.
3800 * @throws SecurityException if the caller does not have the required permission
3801 */
3802 private void enforceSatelliteCommunicationPermission(String message) {
3803 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3804 }
3805
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003806 private String createTelUrl(String number) {
3807 if (TextUtils.isEmpty(number)) {
3808 return null;
3809 }
3810
Jake Hambye994d462014-02-03 13:10:13 -08003811 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003812 }
3813
Ihab Awadf9e92732013-12-05 18:02:52 -08003814 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003815 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003816 }
3817
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003818 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003819 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003820 }
3821
Ihab Awadf9e92732013-12-05 18:02:52 -08003822 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003823 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003824 }
3825
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003826 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003827 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003828 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003829 }
3830
Sanket Padawe356d7632015-06-22 14:03:32 -07003831 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003832 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003833 final long identity = Binder.clearCallingIdentity();
3834 try {
3835 final Phone phone = PhoneFactory.getPhone(slotIndex);
3836 if (phone == null) {
3837 return PhoneConstants.PHONE_TYPE_NONE;
3838 } else {
3839 return phone.getPhoneType();
3840 }
3841 } finally {
3842 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003843 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003844 }
3845
3846 /**
3847 * Returns the CDMA ERI icon index to display
3848 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003849 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003850 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3851 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3852 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003853 }
3854
Sanket Padawe356d7632015-06-22 14:03:32 -07003855 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003856 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3857 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003858 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003859 mApp, subId, callingPackage, callingFeatureId,
3860 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003861 return -1;
3862 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003863
3864 final long identity = Binder.clearCallingIdentity();
3865 try {
3866 final Phone phone = getPhone(subId);
3867 if (phone != null) {
3868 return phone.getCdmaEriIconIndex();
3869 } else {
3870 return -1;
3871 }
3872 } finally {
3873 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003874 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003875 }
3876
3877 /**
3878 * Returns the CDMA ERI icon mode,
3879 * 0 - ON
3880 * 1 - FLASHING
3881 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003882 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003883 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3884 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3885 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003886 }
3887
Sanket Padawe356d7632015-06-22 14:03:32 -07003888 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003889 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3890 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003891 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003892 mApp, subId, callingPackage, callingFeatureId,
3893 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003894 return -1;
3895 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003896
3897 final long identity = Binder.clearCallingIdentity();
3898 try {
3899 final Phone phone = getPhone(subId);
3900 if (phone != null) {
3901 return phone.getCdmaEriIconMode();
3902 } else {
3903 return -1;
3904 }
3905 } finally {
3906 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003907 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003908 }
3909
3910 /**
3911 * Returns the CDMA ERI text,
3912 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003913 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003914 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3915 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3916 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003917 }
3918
Sanket Padawe356d7632015-06-22 14:03:32 -07003919 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003920 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3921 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003922 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003923 mApp, subId, callingPackage, callingFeatureId,
3924 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003925 return null;
3926 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003927
3928 final long identity = Binder.clearCallingIdentity();
3929 try {
3930 final Phone phone = getPhone(subId);
3931 if (phone != null) {
3932 return phone.getCdmaEriText();
3933 } else {
3934 return null;
3935 }
3936 } finally {
3937 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003938 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003939 }
3940
3941 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003942 * Returns the CDMA MDN.
3943 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003944 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003945 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003946 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3947 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003948
3949 final long identity = Binder.clearCallingIdentity();
3950 try {
3951 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003952 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003953 return phone.getLine1Number();
3954 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003955 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003956 return null;
3957 }
3958 } finally {
3959 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003960 }
3961 }
3962
3963 /**
3964 * Returns the CDMA MIN.
3965 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003966 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003967 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003968 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3969 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003970
3971 final long identity = Binder.clearCallingIdentity();
3972 try {
3973 final Phone phone = getPhone(subId);
3974 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3975 return phone.getCdmaMin();
3976 } else {
3977 return null;
3978 }
3979 } finally {
3980 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003981 }
3982 }
3983
Hall Liud892bec2018-11-30 14:51:45 -08003984 @Override
3985 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3986 INumberVerificationCallback callback, String callingPackage) {
3987 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3988 != PERMISSION_GRANTED) {
3989 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3990 }
3991 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3992
3993 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3994 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003995 throw new SecurityException("Calling package must be configured in the device config: "
3996 + "calling package: " + callingPackage
3997 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003998 }
3999
4000 if (range == null) {
4001 throw new NullPointerException("Range must be non-null");
4002 }
4003
4004 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004005 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004006
4007 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4008 }
4009
Junda Liuca05d5d2014-08-14 22:36:34 -07004010 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004011 * Returns true if CDMA provisioning needs to run.
4012 */
4013 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004014 final long identity = Binder.clearCallingIdentity();
4015 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004016 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004017 } finally {
4018 Binder.restoreCallingIdentity(identity);
4019 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004020 }
4021
4022 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004023 * Sets the voice mail number of a given subId.
4024 */
4025 @Override
4026 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004027 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4028 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004029
4030 final long identity = Binder.clearCallingIdentity();
4031 try {
4032 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4033 new Pair<String, String>(alphaTag, number), new Integer(subId));
4034 return success;
4035 } finally {
4036 Binder.restoreCallingIdentity(identity);
4037 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004038 }
4039
Ta-wei Yen87c49842016-05-13 21:19:52 -07004040 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004041 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4042 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004043 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4044 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004045 if (!TextUtils.equals(callingPackage, systemDialer)) {
4046 throw new SecurityException("caller must be system dialer");
4047 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004048
4049 final long identity = Binder.clearCallingIdentity();
4050 try {
4051 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4052 if (phoneAccountHandle == null) {
4053 return null;
4054 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004055 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004056 } finally {
4057 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004058 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004059 }
4060
4061 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004062 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4063 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004064 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004065 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004066 mApp, subId, callingPackage, callingFeatureId,
4067 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004068 return null;
4069 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004070
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004071 final long identity = Binder.clearCallingIdentity();
4072 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004073 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004074 } finally {
4075 Binder.restoreCallingIdentity(identity);
4076 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004077 }
4078
4079 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004080 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4081 VisualVoicemailSmsFilterSettings settings) {
4082 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004083
4084 final long identity = Binder.clearCallingIdentity();
4085 try {
4086 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004087 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004088 } finally {
4089 Binder.restoreCallingIdentity(identity);
4090 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004091 }
4092
4093 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004094 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4095 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004096
4097 final long identity = Binder.clearCallingIdentity();
4098 try {
4099 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004100 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004101 } finally {
4102 Binder.restoreCallingIdentity(identity);
4103 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004104 }
4105
4106 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004107 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4108 String callingPackage, int subId) {
4109 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004110
4111 final long identity = Binder.clearCallingIdentity();
4112 try {
4113 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004114 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004115 } finally {
4116 Binder.restoreCallingIdentity(identity);
4117 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004118 }
4119
4120 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004121 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004122 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004123
4124 final long identity = Binder.clearCallingIdentity();
4125 try {
4126 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004127 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004128 } finally {
4129 Binder.restoreCallingIdentity(identity);
4130 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004131 }
4132
4133 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004134 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4135 String callingAttributionTag, int subId, String number, int port, String text,
4136 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004137 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004138 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004139 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07004140 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004141 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4142 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004143 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004144
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004145 /**
fionaxu0152e512016-11-14 13:36:14 -08004146 * Sets the voice activation state of a given subId.
4147 */
4148 @Override
4149 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004150 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4151 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004152
4153 final long identity = Binder.clearCallingIdentity();
4154 try {
4155 final Phone phone = getPhone(subId);
4156 if (phone != null) {
4157 phone.setVoiceActivationState(activationState);
4158 } else {
4159 loge("setVoiceActivationState fails with invalid subId: " + subId);
4160 }
4161 } finally {
4162 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004163 }
4164 }
4165
4166 /**
4167 * Sets the data activation state of a given subId.
4168 */
4169 @Override
4170 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004171 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4172 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004173
4174 final long identity = Binder.clearCallingIdentity();
4175 try {
4176 final Phone phone = getPhone(subId);
4177 if (phone != null) {
4178 phone.setDataActivationState(activationState);
4179 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004180 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004181 }
4182 } finally {
4183 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004184 }
4185 }
4186
4187 /**
4188 * Returns the voice activation state of a given subId.
4189 */
4190 @Override
4191 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004192 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004193
fionaxu0152e512016-11-14 13:36:14 -08004194 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004195 final long identity = Binder.clearCallingIdentity();
4196 try {
4197 if (phone != null) {
4198 return phone.getVoiceActivationState();
4199 } else {
4200 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4201 }
4202 } finally {
4203 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004204 }
4205 }
4206
4207 /**
4208 * Returns the data activation state of a given subId.
4209 */
4210 @Override
4211 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004212 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004213
fionaxu0152e512016-11-14 13:36:14 -08004214 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004215 final long identity = Binder.clearCallingIdentity();
4216 try {
4217 if (phone != null) {
4218 return phone.getDataActivationState();
4219 } else {
4220 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4221 }
4222 } finally {
4223 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004224 }
4225 }
4226
4227 /**
Wink Saville36469e72014-06-11 15:17:00 -07004228 * Returns the unread count of voicemails for a subId
4229 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004230 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004231 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4232 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004233 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004234 mApp, subId, callingPackage, callingFeatureId,
4235 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004236 return 0;
4237 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004238 final long identity = Binder.clearCallingIdentity();
4239 try {
4240 final Phone phone = getPhone(subId);
4241 if (phone != null) {
4242 return phone.getVoiceMessageCount();
4243 } else {
4244 return 0;
4245 }
4246 } finally {
4247 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004248 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004249 }
4250
4251 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004252 * returns true, if the device is in a state where both voice and data
4253 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004254 */
4255 @Override
4256 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004257 final long identity = Binder.clearCallingIdentity();
4258 try {
4259 final Phone phone = getPhone(subId);
4260 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
4261 } finally {
4262 Binder.restoreCallingIdentity(identity);
4263 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004264 }
4265
4266 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004267 * Send the dialer code if called from the current default dialer or the caller has
4268 * carrier privilege.
4269 * @param inputCode The dialer code to send
4270 */
4271 @Override
4272 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004273 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004274 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004275 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4276 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004277 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004278 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004279 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004280 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004281
4282 final long identity = Binder.clearCallingIdentity();
4283 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004284 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004285 } finally {
4286 Binder.restoreCallingIdentity(identity);
4287 }
fionaxu235cc5e2017-03-06 22:25:57 -08004288 }
4289
Pengquan Menga1bb6272018-09-06 09:59:22 -07004290 @Override
4291 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004292 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004293 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4294 mApp, subId, "getNetworkSelectionMode");
shilufc958392020-01-20 11:36:01 -08004295 final long identity = Binder.clearCallingIdentity();
4296 try {
4297 if (!isActiveSubscription(subId)) {
4298 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4299 }
4300 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4301 } finally {
4302 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004303 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004304 }
4305
Brad Ebinger35c841c2018-10-01 10:40:55 -07004306 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004307 public boolean isInEmergencySmsMode() {
4308 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4309 final long identity = Binder.clearCallingIdentity();
4310 try {
4311 for (Phone phone : PhoneFactory.getPhones()) {
4312 if (phone.isInEmergencySmsMode()) {
4313 return true;
4314 }
4315 }
4316 } finally {
4317 Binder.restoreCallingIdentity(identity);
4318 }
4319 return false;
4320 }
4321
shilu366312e2019-12-17 09:28:10 -08004322 /**
4323 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4324 * @param subId The subscription to use to check the configuration.
4325 * @param c The callback that will be used to send the result.
4326 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004327 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004328 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4329 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004330 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004331 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004332
4333 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4334 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4335 "IMS not available on device.");
4336 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004337 final long token = Binder.clearCallingIdentity();
4338 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004339 int slotId = getSlotIndexOrException(subId);
4340 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004341
4342 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4343 if (controller != null) {
4344 ImsManager imsManager = controller.getImsManager(subId);
4345 if (imsManager != null) {
4346 imsManager.addRegistrationCallbackForSubscription(c, subId);
4347 } else {
4348 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4349 }
4350 } else {
4351 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4352 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004353 } catch (ImsException e) {
4354 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004355 } finally {
4356 Binder.restoreCallingIdentity(token);
4357 }
4358 }
4359
shilu366312e2019-12-17 09:28:10 -08004360 /**
4361 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4362 * @param subId The subscription to use to check the configuration.
4363 * @param c The callback that will be used to send the result.
4364 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004365 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004366 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004367 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004368 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004369 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4370 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4371 }
Meng Wangafbc5852019-09-19 17:37:13 -07004372 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004373
Meng Wangafbc5852019-09-19 17:37:13 -07004374 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004375 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4376 if (controller != null) {
4377 ImsManager imsManager = controller.getImsManager(subId);
4378 if (imsManager != null) {
4379 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4380 } else {
4381 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4382 + "is inactive, ignoring unregister.");
4383 // If the ImsManager is not valid, just return, since the callback
4384 // will already have been removed internally.
4385 }
4386 }
Meng Wangafbc5852019-09-19 17:37:13 -07004387 } finally {
4388 Binder.restoreCallingIdentity(token);
4389 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004390 }
4391
Brad Ebingera34a6c22019-10-22 17:36:18 -07004392 /**
4393 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4394 */
4395 @Override
4396 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4397 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4398 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4399 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4400 "IMS not available on device.");
4401 }
4402 final long token = Binder.clearCallingIdentity();
4403 try {
4404 Phone phone = getPhone(subId);
4405 if (phone == null) {
4406 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4407 + subId + "'");
4408 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4409 }
4410 phone.getImsRegistrationState(regState -> {
4411 try {
4412 consumer.accept((regState == null)
4413 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4414 } catch (RemoteException e) {
4415 // Ignore if the remote process is no longer available to call back.
4416 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4417 }
4418 });
4419 } finally {
4420 Binder.restoreCallingIdentity(token);
4421 }
4422 }
4423
4424 /**
4425 * Get the transport type for the IMS service registration state.
4426 */
4427 @Override
4428 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004429 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004430 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004431 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4432 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4433 "IMS not available on device.");
4434 }
4435 final long token = Binder.clearCallingIdentity();
4436 try {
4437 Phone phone = getPhone(subId);
4438 if (phone == null) {
4439 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4440 + subId + "'");
4441 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4442 }
4443 phone.getImsRegistrationTech(regTech -> {
4444 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4445 int regTechConverted = (regTech == null)
4446 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4447 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4448 regTechConverted);
4449 try {
4450 consumer.accept(regTechConverted);
4451 } catch (RemoteException e) {
4452 // Ignore if the remote process is no longer available to call back.
4453 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4454 }
4455 });
4456 } finally {
4457 Binder.restoreCallingIdentity(token);
4458 }
4459 }
4460
shilu366312e2019-12-17 09:28:10 -08004461 /**
4462 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4463 * @param subId The subscription to use to check the configuration.
4464 * @param c The callback that will be used to send the result.
4465 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004466 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004467 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4468 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004469 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004470 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004471 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4472 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4473 "IMS not available on device.");
4474 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004475 final long token = Binder.clearCallingIdentity();
4476 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004477 int slotId = getSlotIndexOrException(subId);
4478 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004479
4480 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4481 if (controller != null) {
4482 ImsManager imsManager = controller.getImsManager(subId);
4483 if (imsManager != null) {
4484 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4485 } else {
4486 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4487 }
4488 } else {
4489 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4490 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004491 } catch (ImsException e) {
4492 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004493 } finally {
4494 Binder.restoreCallingIdentity(token);
4495 }
4496 }
4497
shilu366312e2019-12-17 09:28:10 -08004498 /**
4499 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4500 * @param subId The subscription to use to check the configuration.
4501 * @param c The callback that will be used to send the result.
4502 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004503 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004504 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004505 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004506 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004507 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4508 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4509 }
Meng Wangafbc5852019-09-19 17:37:13 -07004510
4511 final long token = Binder.clearCallingIdentity();
4512 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004513 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4514 if (controller != null) {
4515 ImsManager imsManager = controller.getImsManager(subId);
4516 if (imsManager != null) {
4517 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4518 } else {
4519 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4520 + " is inactive, ignoring unregister.");
4521 // If the ImsManager is not valid, just return, since the callback
4522 // will already have been removed internally.
4523 }
4524 }
Meng Wangafbc5852019-09-19 17:37:13 -07004525 } finally {
4526 Binder.restoreCallingIdentity(token);
4527 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004528 }
4529
4530 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004531 public boolean isCapable(int subId, int capability, int regTech) {
4532 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004533 final long token = Binder.clearCallingIdentity();
4534 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004535 int slotId = getSlotIndexOrException(subId);
4536 verifyImsMmTelConfiguredOrThrow(slotId);
4537 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4538 } catch (com.android.ims.ImsException e) {
4539 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4540 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004541 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004542 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4543 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004544 } finally {
4545 Binder.restoreCallingIdentity(token);
4546 }
4547 }
4548
4549 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004550 public boolean isAvailable(int subId, int capability, int regTech) {
4551 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004552 final long token = Binder.clearCallingIdentity();
4553 try {
4554 Phone phone = getPhone(subId);
4555 if (phone == null) return false;
4556 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004557 } catch (com.android.ims.ImsException e) {
4558 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4559 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004560 } finally {
4561 Binder.restoreCallingIdentity(token);
4562 }
4563 }
4564
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004565 /**
4566 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4567 * subscription.
4568 * @param subId The subscription to use to check the configuration.
4569 * @param callback The callback that will be used to send the result.
4570 * @param capability The MmTelFeature capability that will be used to send the result.
4571 * @param transportType The transport type of the MmTelFeature capability.
4572 */
4573 @Override
4574 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4575 int transportType) {
4576 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004577 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4578 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4579 "IMS not available on device.");
4580 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004581 final long token = Binder.clearCallingIdentity();
4582 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004583 int slotId = getSlotIndex(subId);
4584 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4585 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4586 + subId + "'");
4587 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4588 }
4589 verifyImsMmTelConfiguredOrThrow(slotId);
4590 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4591 transportType, aBoolean -> {
4592 try {
4593 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4594 } catch (RemoteException e) {
4595 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4596 + "running. Ignore");
4597 }
4598 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004599 } catch (ImsException e) {
4600 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004601 } finally {
4602 Binder.restoreCallingIdentity(token);
4603 }
4604 }
4605
shilu366312e2019-12-17 09:28:10 -08004606 /**
4607 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4608 * @param subId The subscription to use to check the configuration.
4609 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004610 @Override
4611 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004612 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004613 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004614
Brad Ebinger35c841c2018-10-01 10:40:55 -07004615 final long token = Binder.clearCallingIdentity();
4616 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004617 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004618 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004619 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004620 } catch (ImsException e) {
4621 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004622 } finally {
4623 Binder.restoreCallingIdentity(token);
4624 }
4625 }
4626
4627 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004628 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004629 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004630 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004631 final long identity = Binder.clearCallingIdentity();
4632 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004633 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004634 // This setting doesn't require an active ImsService connection, so do not verify. The
4635 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004636 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004637 } catch (ImsException e) {
4638 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004639 } finally {
4640 Binder.restoreCallingIdentity(identity);
4641 }
4642 }
4643
shilu366312e2019-12-17 09:28:10 -08004644 /**
4645 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4646 * @param subId The subscription to use to check the configuration.
4647 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004648 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004649 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004650 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004651 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004652 final long identity = Binder.clearCallingIdentity();
4653 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004654 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004655 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004656 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004657 } catch (ImsException e) {
4658 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004659 } finally {
4660 Binder.restoreCallingIdentity(identity);
4661 }
4662 }
4663
4664 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004665 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004666 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004667 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004668 final long identity = Binder.clearCallingIdentity();
4669 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004670 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004671 // This setting doesn't require an active ImsService connection, so do not verify. The
4672 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004673 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004674 } catch (ImsException e) {
4675 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004676 } finally {
4677 Binder.restoreCallingIdentity(identity);
4678 }
4679 }
4680
shilu366312e2019-12-17 09:28:10 -08004681 /**
4682 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4683 * @param subId The subscription to use to check the configuration.
4684 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004685 @Override
4686 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004687 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004688 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004689 final long identity = Binder.clearCallingIdentity();
4690 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004691 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004692 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004693 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004694 } catch (ImsException e) {
4695 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004696 } finally {
4697 Binder.restoreCallingIdentity(identity);
4698 }
4699 }
4700
4701 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004702 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004703 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004704 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004705 final long identity = Binder.clearCallingIdentity();
4706 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004707 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004708 // This setting doesn't require an active ImsService connection, so do not verify. The
4709 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004710 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004711 } catch (ImsException e) {
4712 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004713 } finally {
4714 Binder.restoreCallingIdentity(identity);
4715 }
4716 }
4717
shilu366312e2019-12-17 09:28:10 -08004718 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004719 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4720 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4721 * @param subId The subscription to use to check the configuration.
4722 */
4723 @Override
4724 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004725 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004726 mApp, subId, "isCrossSimCallingEnabledByUser");
4727 final long identity = Binder.clearCallingIdentity();
4728 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004729 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004730 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004731 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004732 } catch (ImsException e) {
4733 throw new ServiceSpecificException(e.getCode());
4734 } finally {
4735 Binder.restoreCallingIdentity(identity);
4736 }
4737 }
4738
4739 /**
4740 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4741 * Requires MODIFY_PHONE_STATE permission.
4742 * @param subId The subscription to use to check the configuration.
4743 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4744 * false otherwise
4745 */
4746 @Override
4747 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4748 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4749 "setCrossSimCallingEnabled");
4750 final long identity = Binder.clearCallingIdentity();
4751 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004752 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004753 // This setting doesn't require an active ImsService connection, so do not verify. The
4754 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004755 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004756 } catch (ImsException e) {
4757 throw new ServiceSpecificException(e.getCode());
4758 } finally {
4759 Binder.restoreCallingIdentity(identity);
4760 }
4761 }
4762
4763 /**
shilu366312e2019-12-17 09:28:10 -08004764 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4765 * @param subId The subscription to use to check the configuration.
4766 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004767 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004768
Brad Ebinger35c841c2018-10-01 10:40:55 -07004769 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004770 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004771 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004772 final long identity = Binder.clearCallingIdentity();
4773 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004774 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004775 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004776 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004777 } catch (ImsException e) {
4778 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004779 } finally {
4780 Binder.restoreCallingIdentity(identity);
4781 }
4782 }
4783
4784 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004785 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004786 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004787 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004788 final long identity = Binder.clearCallingIdentity();
4789 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004790 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004791 // This setting doesn't require an active ImsService connection, so do not verify. The
4792 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004793 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004794 } catch (ImsException e) {
4795 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004796 } finally {
4797 Binder.restoreCallingIdentity(identity);
4798 }
4799 }
4800
4801 @Override
4802 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4803 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4804 "setVoWiFiNonPersistent");
4805 final long identity = Binder.clearCallingIdentity();
4806 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004807 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004808 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004809 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004810 } catch (ImsException e) {
4811 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004812 } finally {
4813 Binder.restoreCallingIdentity(identity);
4814 }
4815 }
4816
shilu366312e2019-12-17 09:28:10 -08004817 /**
4818 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4819 * @param subId The subscription to use to check the configuration.
4820 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004821 @Override
4822 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004823 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004824 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004825 final long identity = Binder.clearCallingIdentity();
4826 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004827 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004828 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004829 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004830 } catch (ImsException e) {
4831 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004832 } finally {
4833 Binder.restoreCallingIdentity(identity);
4834 }
4835 }
4836
4837 @Override
4838 public void setVoWiFiModeSetting(int subId, int mode) {
4839 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4840 "setVoWiFiModeSetting");
4841 final long identity = Binder.clearCallingIdentity();
4842 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004843 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004844 // This setting doesn't require an active ImsService connection, so do not verify. The
4845 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004846 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004847 } catch (ImsException e) {
4848 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004849 } finally {
4850 Binder.restoreCallingIdentity(identity);
4851 }
4852 }
4853
4854 @Override
4855 public int getVoWiFiRoamingModeSetting(int subId) {
4856 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4857 final long identity = Binder.clearCallingIdentity();
4858 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004859 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004860 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004861 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004862 } catch (ImsException e) {
4863 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004864 } finally {
4865 Binder.restoreCallingIdentity(identity);
4866 }
4867 }
4868
4869 @Override
4870 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4871 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4872 "setVoWiFiRoamingModeSetting");
4873 final long identity = Binder.clearCallingIdentity();
4874 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004875 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004876 // This setting doesn't require an active ImsService connection, so do not verify. The
4877 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004878 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004879 } catch (ImsException e) {
4880 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004881 } finally {
4882 Binder.restoreCallingIdentity(identity);
4883 }
4884 }
4885
4886 @Override
4887 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4888 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4889 "setRttCapabilityEnabled");
4890 final long identity = Binder.clearCallingIdentity();
4891 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004892 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004893 // This setting doesn't require an active ImsService connection, so do not verify. The
4894 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004895 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004896 } catch (ImsException e) {
4897 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004898 } finally {
4899 Binder.restoreCallingIdentity(identity);
4900 }
4901 }
4902
shilu366312e2019-12-17 09:28:10 -08004903 /**
4904 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4905 * @param subId The subscription to use to check the configuration.
4906 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004907 @Override
4908 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004909 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004910 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004911 final long identity = Binder.clearCallingIdentity();
4912 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004913 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004914 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004915 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004916 } catch (ImsException e) {
4917 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004918 } finally {
4919 Binder.restoreCallingIdentity(identity);
4920 }
4921 }
4922
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004923 @Override
4924 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4925 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004926
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004927 final long identity = Binder.clearCallingIdentity();
4928 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004929 if (!isImsAvailableOnDevice()) {
4930 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4931 "IMS not available on device.");
4932 }
4933 int slotId = getSlotIndexOrException(subId);
4934 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004935
4936 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4937 if (controller != null) {
4938 ImsManager imsManager = controller.getImsManager(subId);
4939 if (imsManager != null) {
4940 imsManager.addProvisioningCallbackForSubscription(callback, subId);
4941 } else {
4942 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4943 }
4944 } else {
4945 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4946 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004947 } catch (ImsException e) {
4948 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004949 } finally {
4950 Binder.restoreCallingIdentity(identity);
4951 }
4952 }
4953
4954 @Override
4955 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4956 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004957
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004958 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004959 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4960 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4961 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004962 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004963 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4964 if (controller != null) {
4965 ImsManager imsManager = controller.getImsManager(subId);
4966 if (imsManager != null) {
4967 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
4968 } else {
4969 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4970 + " is inactive, ignoring unregister.");
4971 // If the ImsManager is not valid, just return, since the callback will already
4972 // have been removed internally.
4973 }
4974 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004975 } finally {
4976 Binder.restoreCallingIdentity(identity);
4977 }
4978 }
4979
joonhunshincffb7fc2021-11-28 07:32:01 +00004980 @Override
4981 public void registerFeatureProvisioningChangedCallback(int subId,
4982 IFeatureProvisioningCallback callback) {
4983 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4984 mApp, subId, "registerFeatureProvisioningChangedCallback");
4985
4986 final long identity = Binder.clearCallingIdentity();
4987 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4988 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4989 }
4990
joonhunshin91bc1952022-04-29 08:47:15 +00004991 try {
4992 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4993 if (controller == null) {
4994 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4995 "Device does not support IMS");
4996 }
4997 controller.addFeatureProvisioningChangedCallback(subId, callback);
4998 } finally {
4999 Binder.restoreCallingIdentity(identity);
5000 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005001 }
5002
5003 @Override
5004 public void unregisterFeatureProvisioningChangedCallback(int subId,
5005 IFeatureProvisioningCallback callback) {
5006 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5007 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5008
5009 final long identity = Binder.clearCallingIdentity();
5010 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5011 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5012 }
5013
joonhunshin91bc1952022-04-29 08:47:15 +00005014 try {
5015 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5016 if (controller == null) {
5017 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5018 return;
5019 }
5020 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5021 } finally {
5022 Binder.restoreCallingIdentity(identity);
5023 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005024 }
allenwtsu99c623b2020-01-03 18:24:23 +08005025
5026 private void checkModifyPhoneStatePermission(int subId, String message) {
5027 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5028 message);
5029 }
5030
allenwtsu99c623b2020-01-03 18:24:23 +08005031 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005032 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005033 boolean isProvisioned) {
5034 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5035
5036 final long identity = Binder.clearCallingIdentity();
5037 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005038 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5039 if (controller == null) {
5040 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5041 return;
5042 }
5043 controller.setRcsProvisioningStatusForCapability(
5044 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005045 } finally {
5046 Binder.restoreCallingIdentity(identity);
5047 }
allenwtsu99c623b2020-01-03 18:24:23 +08005048 }
5049
5050
5051 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005052 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5053 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5054 mApp, subId, "getRcsProvisioningStatusForCapability");
5055
allenwtsu99c623b2020-01-03 18:24:23 +08005056 final long identity = Binder.clearCallingIdentity();
5057 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005058 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5059 if (controller == null) {
5060 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5061
5062 // device does not support IMS, this method will return true always.
5063 return true;
5064 }
5065 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005066 } finally {
5067 Binder.restoreCallingIdentity(identity);
5068 }
5069 }
5070
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005071 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005072 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5073 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005074 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005075
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005076 final long identity = Binder.clearCallingIdentity();
5077 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005078 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5079 if (controller == null) {
5080 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5081 return;
5082 }
5083 controller.setImsProvisioningStatusForCapability(
5084 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005085 } finally {
5086 Binder.restoreCallingIdentity(identity);
5087 }
5088 }
5089
5090 @Override
5091 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005092 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5093 mApp, subId, "getProvisioningStatusForCapability");
5094
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005095 final long identity = Binder.clearCallingIdentity();
5096 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005097 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5098 if (controller == null) {
5099 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005100
joonhunshin91bc1952022-04-29 08:47:15 +00005101 // device does not support IMS, this method will return true always.
5102 return true;
5103 }
5104 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005105 } finally {
5106 Binder.restoreCallingIdentity(identity);
5107 }
5108 }
5109
5110 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005111 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5112 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5113 mApp, subId, "isProvisioningRequiredForCapability");
5114
5115 final long identity = Binder.clearCallingIdentity();
5116 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005117 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5118 if (controller == null) {
5119 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5120
5121 // device does not support IMS, this method will return false
5122 return false;
5123 }
5124 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005125 } finally {
5126 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005127 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005128 }
5129
5130 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005131 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5132 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5133 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005134
joonhunshincffb7fc2021-11-28 07:32:01 +00005135 final long identity = Binder.clearCallingIdentity();
5136 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005137 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5138 if (controller == null) {
5139 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5140
5141 // device does not support IMS, this method will return false
5142 return false;
5143 }
5144 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005145 } finally {
5146 Binder.restoreCallingIdentity(identity);
5147 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005148 }
5149
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005150 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005151 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005152 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5153 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5154 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005155 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5156 mApp, subId, "getImsProvisioningInt");
5157
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005158 final long identity = Binder.clearCallingIdentity();
5159 try {
5160 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005161 int slotId = getSlotIndex(subId);
5162 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5163 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5164 + subId + "' for key:" + key);
5165 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5166 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005167
joonhunshin91bc1952022-04-29 08:47:15 +00005168 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5169 if (controller == null) {
5170 loge("getImsProvisioningInt: Device does not support IMS");
5171
5172 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5173 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5174 }
5175 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005176 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5177 return retVal;
5178 }
5179
calvinpanb5a34062021-02-08 19:59:36 +08005180 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005181 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005182 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5183 + subId + "' for key:" + key);
5184 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005185 } finally {
5186 Binder.restoreCallingIdentity(identity);
5187 }
5188 }
5189
5190 @Override
5191 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005192 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5193 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5194 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005195 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5196 mApp, subId, "getImsProvisioningString");
5197
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005198 final long identity = Binder.clearCallingIdentity();
5199 try {
5200 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005201 int slotId = getSlotIndex(subId);
5202 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5203 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5204 + subId + "' for key:" + key);
5205 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5206 }
calvinpanb5a34062021-02-08 19:59:36 +08005207 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005208 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005209 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5210 + subId + "' for key:" + key);
5211 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005212 } finally {
5213 Binder.restoreCallingIdentity(identity);
5214 }
5215 }
5216
5217 @Override
5218 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005219 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5220 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5221 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005222 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5223 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005224
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005225 final long identity = Binder.clearCallingIdentity();
5226 try {
5227 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005228 int slotId = getSlotIndex(subId);
5229 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5230 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5231 + subId + "' for key:" + key);
5232 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5233 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005234
joonhunshin91bc1952022-04-29 08:47:15 +00005235 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5236 if (controller == null) {
5237 loge("setImsProvisioningInt: Device does not support IMS");
5238
5239 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5240 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5241 }
5242 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005243 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5244 return retVal;
5245 }
5246
calvinpanb5a34062021-02-08 19:59:36 +08005247 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5248 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005249 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005250 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005251 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005252 } finally {
5253 Binder.restoreCallingIdentity(identity);
5254 }
5255 }
5256
5257 @Override
5258 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005259 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5260 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5261 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005262 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5263 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005264 final long identity = Binder.clearCallingIdentity();
5265 try {
5266 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005267 int slotId = getSlotIndex(subId);
5268 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5269 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5270 + subId + "' for key:" + key);
5271 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5272 }
calvinpanb5a34062021-02-08 19:59:36 +08005273 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5274 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005275 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005276 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005277 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005278 } finally {
5279 Binder.restoreCallingIdentity(identity);
5280 }
5281 }
5282
Brad Ebinger919631e2021-06-02 17:46:35 -07005283 /**
5284 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5285 * for the given slot ID or no ImsResolver instance has been created.
5286 * @param slotId The slot ID that the IMS service is created for.
5287 * @throws ImsException If there is no ImsService configured for this slot.
5288 */
5289 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5290 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5291 ImsFeature.FEATURE_MMTEL)) {
5292 throw new ImsException("This subscription does not support MMTEL over IMS",
5293 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5294 }
5295 }
5296
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005297 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005298 int slotId = SubscriptionManager.getSlotIndex(subId);
5299 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005300 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5301 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005302 }
5303 return slotId;
5304 }
5305
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005306 private int getSlotIndex(int subId) {
5307 int slotId = SubscriptionManager.getSlotIndex(subId);
5308 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5309 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5310 }
5311 return slotId;
5312 }
5313
Wink Saville36469e72014-06-11 15:17:00 -07005314 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005315 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005316 */
5317 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005318 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5319 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005320 try {
5321 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5322 } catch (SecurityException se) {
5323 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5324 throw new SecurityException("Package " + callingPackage + " does not belong to "
5325 + Binder.getCallingUid());
5326 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005327 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005328 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005329 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005330 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005331 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005332 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005333 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005334 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5335 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005336
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005337 final long identity = Binder.clearCallingIdentity();
5338 try {
5339 final Phone phone = getPhone(subId);
5340 if (phone != null) {
5341 return phone.getServiceState().getDataNetworkType();
5342 } else {
5343 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5344 }
5345 } finally {
5346 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005347 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005348 }
5349
5350 /**
5351 * Returns the data network type
5352 */
5353 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005354 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005355 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005356 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005357 }
5358
5359 /**
5360 * Returns the data network type for a subId
5361 */
5362 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005363 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5364 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005365 String functionName = "getDataNetworkTypeForSubscriber";
5366 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5367 mApp, functionName)) {
5368 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5369 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5370 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5371 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005372 }
5373
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005374 final long identity = Binder.clearCallingIdentity();
5375 try {
5376 final Phone phone = getPhone(subId);
5377 if (phone != null) {
5378 return phone.getServiceState().getDataNetworkType();
5379 } else {
5380 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5381 }
5382 } finally {
5383 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005384 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005385 }
5386
5387 /**
Wink Saville36469e72014-06-11 15:17:00 -07005388 * Returns the Voice network type for a subId
5389 */
5390 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005391 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5392 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005393 String functionName = "getVoiceNetworkTypeForSubscriber";
5394 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5395 mApp, functionName)) {
5396 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5397 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5398 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5399 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005400 }
5401
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005402 final long identity = Binder.clearCallingIdentity();
5403 try {
5404 final Phone phone = getPhone(subId);
5405 if (phone != null) {
5406 return phone.getServiceState().getVoiceNetworkType();
5407 } else {
5408 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5409 }
5410 } finally {
5411 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005412 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005413 }
5414
5415 /**
5416 * @return true if a ICC card is present
5417 */
5418 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005419 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005420 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005421 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005422 }
5423
5424 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005425 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005426 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005427 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005428 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005429 final long identity = Binder.clearCallingIdentity();
5430 try {
5431 final Phone phone = PhoneFactory.getPhone(slotIndex);
5432 if (phone != null) {
5433 return phone.getIccCard().hasIccCard();
5434 } else {
5435 return false;
5436 }
5437 } finally {
5438 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005439 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005440 }
5441
5442 /**
5443 * Return if the current radio is LTE on CDMA. This
5444 * is a tri-state return value as for a period of time
5445 * the mode may be unknown.
5446 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005447 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005448 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005449 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005450 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005451 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005452 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5453 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5454 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005455 }
5456
Sanket Padawe356d7632015-06-22 14:03:32 -07005457 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005458 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5459 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005460 try {
5461 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5462 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005463 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5464 }
5465
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005466 final long identity = Binder.clearCallingIdentity();
5467 try {
5468 final Phone phone = getPhone(subId);
5469 if (phone == null) {
5470 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5471 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005472 return TelephonyProperties.lte_on_cdma_device()
5473 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005474 }
5475 } finally {
5476 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005477 }
Wink Saville36469e72014-06-11 15:17:00 -07005478 }
5479
Wink Saville36469e72014-06-11 15:17:00 -07005480 /**
5481 * {@hide}
5482 * Returns Default subId, 0 in the case of single standby.
5483 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005484 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005485 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005486 }
5487
Shishir Agrawala9f32182016-04-12 12:00:16 -07005488 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005489 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005490 }
5491
Wink Savilleb564aae2014-10-23 10:18:09 -07005492 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005493 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005494 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005495
Pengquan Menge92a50d2018-09-21 15:54:48 -07005496 private boolean isActiveSubscription(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08005497 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08005498 return getSubscriptionManagerService().isActiveSubId(subId,
Jack Yu285100e2022-12-02 22:48:35 -08005499 mApp.getOpPackageName(), mApp.getFeatureId());
5500 }
Pengquan Menge92a50d2018-09-21 15:54:48 -07005501 return mSubscriptionController.isActiveSubId(subId);
5502 }
5503
Ihab Awadf2177b72013-11-25 13:33:23 -08005504 /**
5505 * @see android.telephony.TelephonyManager.WifiCallingChoices
5506 */
5507 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005508 final long identity = Binder.clearCallingIdentity();
5509 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005510 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005511 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5512 getWhenToMakeWifiCallsDefaultPreference());
5513 } finally {
5514 Binder.restoreCallingIdentity(identity);
5515 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005516 }
5517
5518 /**
5519 * @see android.telephony.TelephonyManager.WifiCallingChoices
5520 */
5521 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005522 final long identity = Binder.clearCallingIdentity();
5523 try {
5524 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005525 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005526 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5527 } finally {
5528 Binder.restoreCallingIdentity(identity);
5529 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005530 }
5531
Sailesh Nepald1e68152013-12-12 19:08:02 -08005532 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005533 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005534 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005535 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005536
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005537 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5538 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5539 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005540 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005541 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005542 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005543 }
5544 return PhoneFactory.getPhone(phoneId);
5545 }
5546
Shishir Agrawal566b7612013-10-28 14:41:00 -07005547 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005548 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005549 @NonNull IccLogicalChannelRequest request) {
5550 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5551 /*message=*/ "iccOpenLogicalChannel");
5552
5553 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5554 // Verify that the callingPackage in the request belongs to the calling UID
5555 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5556
5557 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005558 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005559
Rambo Wanga1782702021-11-10 20:15:19 -08005560 private Phone getPhoneFromValidIccLogicalChannelRequest(
5561 @NonNull IccLogicalChannelRequest request, String message) {
5562 Phone phone;
5563 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5564 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5565 mApp, request.subId, message);
5566 phone = getPhoneFromSubId(request.subId);
5567 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5568 enforceModifyPermission();
5569 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5570 } else {
5571 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005572 }
Rambo Wanga1782702021-11-10 20:15:19 -08005573 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005574 }
5575
5576 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005577 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005578 final long identity = Binder.clearCallingIdentity();
5579 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005580 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005581 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005582 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5583 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005584 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5585 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005586 loge("The calling package is not allowed to access ISD-R.");
5587 throw new SecurityException(
5588 "The calling package is not allowed to access ISD-R.");
5589 }
Derek Tan740e1672017-06-27 14:56:27 -07005590 }
Derek Tan740e1672017-06-27 14:56:27 -07005591
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005592 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005593 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5594 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005595 return response;
5596 } finally {
5597 Binder.restoreCallingIdentity(identity);
5598 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005599 }
5600
5601 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005602 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5603 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5604 /*message=*/"iccCloseLogicalChannel");
5605
5606 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5607
5608 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005609 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005610
Rambo Wanga1782702021-11-10 20:15:19 -08005611 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5612 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005613 // before this feature is enabled, this API should only return false if
5614 // the operation fails instead of throwing runtime exception for
5615 // backward-compatibility.
5616 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5617 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005618 final long identity = Binder.clearCallingIdentity();
5619 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005620 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005621 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005622 }
Chen Xue9d737e2022-01-01 23:41:31 -08005623 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005624 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005625 Boolean success = false;
5626 if (result instanceof RuntimeException) {
5627 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005628 if (shouldThrowExceptionOnFailure) {
5629 throw (RuntimeException) result;
5630 } else {
5631 return false;
5632 }
Chen Xue9d737e2022-01-01 23:41:31 -08005633 } else if (result instanceof Boolean) {
5634 success = (Boolean) result;
5635 } else {
5636 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5637 }
Rambo Wanga1782702021-11-10 20:15:19 -08005638 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005639 return success;
5640 } finally {
5641 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005642 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005643 }
5644
5645 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005646 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005647 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005648 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5649 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005650 if (DBG) {
5651 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5652 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5653 + p3 + " data=" + data);
5654 }
5655 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5656 command, p1, p2, p3, data);
5657 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005658
Jordan Liu4c733742019-02-28 12:03:40 -08005659 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005660 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005661 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005662 enforceModifyPermission();
5663 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005664 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005665 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5666 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005667 }
5668 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005669 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5670 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005671 }
5672
5673 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5674 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005675 final long identity = Binder.clearCallingIdentity();
5676 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005677 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005678 return "";
5679 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005680
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005681 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005682 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5683 null /* workSource */);
5684 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005685
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005686 // Append the returned status code to the end of the response payload.
5687 String s = Integer.toHexString(
5688 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5689 if (response.payload != null) {
5690 s = IccUtils.bytesToHexString(response.payload) + s;
5691 }
5692 return s;
5693 } finally {
5694 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005695 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005696 }
Jake Hambye994d462014-02-03 13:10:13 -08005697
Evan Charltonc66da362014-05-16 14:06:40 -07005698 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005699 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5700 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005701 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5702 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005703 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005704 if (DBG) {
5705 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5706 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5707 }
5708 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5709 cla, command, p1, p2, p3, data);
5710 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005711
Jordan Liu4c733742019-02-28 12:03:40 -08005712 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005713 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005714 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005715 enforceModifyPermission();
5716 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5717 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005718 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005719 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5720 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005721 }
5722
5723 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005724 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5725 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005726 }
5727
5728 // open APDU basic channel assuming the caller has sufficient permissions
5729 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5730 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005731 final long identity = Binder.clearCallingIdentity();
5732 try {
5733 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5734 && TextUtils.equals(ISDR_AID, data)) {
5735 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005736 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5737 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005738 if (bestComponent == null
5739 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5740 loge("The calling package is not allowed to select ISD-R.");
5741 throw new SecurityException(
5742 "The calling package is not allowed to select ISD-R.");
5743 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005744 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005745
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005746 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005747 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5748 null /* workSource */);
5749 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005750
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005751 // Append the returned status code to the end of the response payload.
5752 String s = Integer.toHexString(
5753 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5754 if (response.payload != null) {
5755 s = IccUtils.bytesToHexString(response.payload) + s;
5756 }
5757 return s;
5758 } finally {
5759 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005760 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005761 }
5762
5763 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005764 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005765 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005766 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5767 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005768
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005769 final long identity = Binder.clearCallingIdentity();
5770 try {
5771 if (DBG) {
5772 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5773 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5774 }
5775
5776 IccIoResult response =
5777 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5778 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5779 subId);
5780
5781 if (DBG) {
5782 log("Exchange SIM_IO [R]" + response);
5783 }
5784
5785 byte[] result = null;
5786 int length = 2;
5787 if (response.payload != null) {
5788 length = 2 + response.payload.length;
5789 result = new byte[length];
5790 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5791 } else {
5792 result = new byte[length];
5793 }
5794
5795 result[length - 1] = (byte) response.sw2;
5796 result[length - 2] = (byte) response.sw1;
5797 return result;
5798 } finally {
5799 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005800 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005801 }
5802
Nathan Haroldb3014052017-01-25 15:57:32 -08005803 /**
5804 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5805 * on a particular subscription
5806 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005807 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5808 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005809 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005810 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005811 return null;
5812 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005813
5814 final long identity = Binder.clearCallingIdentity();
5815 try {
5816 if (appType != TelephonyManager.APPTYPE_USIM
5817 && appType != TelephonyManager.APPTYPE_SIM) {
5818 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5819 return null;
5820 }
5821 Object response = sendRequest(
5822 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5823 if (response instanceof String[]) {
5824 return (String[]) response;
5825 }
yincheng zhao2737e882019-09-06 17:06:54 -07005826 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005827 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005828 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005829 } finally {
5830 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005831 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005832 }
5833
yincheng zhao2737e882019-09-06 17:06:54 -07005834 /**
5835 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5836 * subscription.
5837 *
5838 * @param subId the id of the subscription.
5839 * @param appType the uicc app type, must be USIM or SIM.
5840 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5841 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005842 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005843 * @return number of fplmns that is successfully written to the SIM.
5844 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005845 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5846 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005847 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5848 mApp, subId, "setForbiddenPlmns");
5849
yincheng zhao2737e882019-09-06 17:06:54 -07005850 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5851 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5852 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5853 }
5854 if (fplmns == null) {
5855 throw new IllegalArgumentException("Fplmn List provided is null");
5856 }
5857 for (String fplmn : fplmns) {
5858 if (!CellIdentity.isValidPlmn(fplmn)) {
5859 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5860 }
5861 }
5862 final long identity = Binder.clearCallingIdentity();
5863 try {
5864 Object response = sendRequest(
5865 CMD_SET_FORBIDDEN_PLMNS,
5866 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5867 subId);
5868 return (int) response;
5869 } finally {
5870 Binder.restoreCallingIdentity(identity);
5871 }
5872 }
5873
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005874 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005875 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005876 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5877 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005878
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005879 final long identity = Binder.clearCallingIdentity();
5880 try {
5881 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5882 if (response.payload == null) {
5883 return "";
5884 }
Evan Charltonc66da362014-05-16 14:06:40 -07005885
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005886 // Append the returned status code to the end of the response payload.
5887 String s = Integer.toHexString(
5888 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5889 s = IccUtils.bytesToHexString(response.payload) + s;
5890 return s;
5891 } finally {
5892 Binder.restoreCallingIdentity(identity);
5893 }
Evan Charltonc66da362014-05-16 14:06:40 -07005894 }
5895
Jake Hambye994d462014-02-03 13:10:13 -08005896 /**
5897 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5898 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5899 *
5900 * @param itemID the ID of the item to read
5901 * @return the NV item as a String, or null on error.
5902 */
5903 @Override
5904 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005905 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005906 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5907 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005908
5909 final long identity = Binder.clearCallingIdentity();
5910 try {
5911 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005912 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005913 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5914 return value;
5915 } finally {
5916 Binder.restoreCallingIdentity(identity);
5917 }
Jake Hambye994d462014-02-03 13:10:13 -08005918 }
5919
5920 /**
5921 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5922 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5923 *
5924 * @param itemID the ID of the item to read
5925 * @param itemValue the value to write, as a String
5926 * @return true on success; false on any failure
5927 */
5928 @Override
5929 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005930 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005931 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5932 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005933
5934 final long identity = Binder.clearCallingIdentity();
5935 try {
5936 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5937 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005938 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005939 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5940 return success;
5941 } finally {
5942 Binder.restoreCallingIdentity(identity);
5943 }
Jake Hambye994d462014-02-03 13:10:13 -08005944 }
5945
5946 /**
5947 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5948 * Used for device configuration by some CDMA operators.
5949 *
5950 * @param preferredRoamingList byte array containing the new PRL
5951 * @return true on success; false on any failure
5952 */
5953 @Override
5954 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005955 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5956 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005957
5958 final long identity = Binder.clearCallingIdentity();
5959 try {
5960 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5961 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5962 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5963 return success;
5964 } finally {
5965 Binder.restoreCallingIdentity(identity);
5966 }
Jake Hambye994d462014-02-03 13:10:13 -08005967 }
5968
5969 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005970 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005971 * Used for device configuration by some CDMA operators.
5972 *
chen xu6dac5ab2018-10-26 17:39:23 -07005973 * @param slotIndex - device slot.
5974 *
Jake Hambye994d462014-02-03 13:10:13 -08005975 * @return true on success; false on any failure
5976 */
5977 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005978 public boolean resetModemConfig(int slotIndex) {
5979 Phone phone = PhoneFactory.getPhone(slotIndex);
5980 if (phone != null) {
5981 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5982 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005983
chen xu6dac5ab2018-10-26 17:39:23 -07005984 final long identity = Binder.clearCallingIdentity();
5985 try {
5986 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5987 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5988 return success;
5989 } finally {
5990 Binder.restoreCallingIdentity(identity);
5991 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005992 }
chen xu6dac5ab2018-10-26 17:39:23 -07005993 return false;
5994 }
5995
5996 /**
5997 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5998 *
5999 * @param slotIndex - device slot.
6000 *
6001 * @return true on success; false on any failure
6002 */
6003 @Override
6004 public boolean rebootModem(int slotIndex) {
6005 Phone phone = PhoneFactory.getPhone(slotIndex);
6006 if (phone != null) {
6007 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6008 mApp, phone.getSubId(), "rebootModem");
6009
6010 final long identity = Binder.clearCallingIdentity();
6011 try {
6012 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6013 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6014 return success;
6015 } finally {
6016 Binder.restoreCallingIdentity(identity);
6017 }
6018 }
6019 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006020 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006021
Brad Ebinger51f743a2017-01-23 13:50:20 -08006022 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006023 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6024 * {@link #disableIms(int)}.
6025 * @param slotIndex device slot.
6026 */
6027 public void resetIms(int slotIndex) {
6028 enforceModifyPermission();
6029
6030 final long identity = Binder.clearCallingIdentity();
6031 try {
6032 if (mImsResolver == null) {
6033 // may happen if the does not support IMS.
6034 return;
6035 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006036 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006037 } finally {
6038 Binder.restoreCallingIdentity(identity);
6039 }
6040 }
6041
6042 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006043 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6044 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006045 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006046 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006047 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006048
6049 final long identity = Binder.clearCallingIdentity();
6050 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006051 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006052 // may happen if the device does not support IMS.
6053 return;
6054 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006055 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006056 } finally {
6057 Binder.restoreCallingIdentity(identity);
6058 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006059 }
6060
6061 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006062 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6063 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006064 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006065 public void disableIms(int slotId) {
6066 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006067
6068 final long identity = Binder.clearCallingIdentity();
6069 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006070 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006071 // may happen if the device does not support IMS.
6072 return;
6073 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006074 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006075 } finally {
6076 Binder.restoreCallingIdentity(identity);
6077 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006078 }
6079
6080 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006081 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6082 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006083 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006084 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006085 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006086 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006087
6088 final long identity = Binder.clearCallingIdentity();
6089 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006090 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006091 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6092 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006093 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006094 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006095 } finally {
6096 Binder.restoreCallingIdentity(identity);
6097 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006098 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006099 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006100 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6101 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006102 @Override
6103 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006104 enforceModifyPermission();
6105
6106 final long identity = Binder.clearCallingIdentity();
6107 try {
6108 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006109 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006110 } finally {
6111 Binder.restoreCallingIdentity(identity);
6112 }
6113 }
6114
6115 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006116 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006117 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006118 */
6119 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6120 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006121
6122 final long identity = Binder.clearCallingIdentity();
6123 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006124 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006125 // may happen if the device does not support IMS.
6126 return null;
6127 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006128 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006129 } finally {
6130 Binder.restoreCallingIdentity(identity);
6131 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006132 }
6133
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006134 /**
6135 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006136 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006137 */
6138 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6139 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006140
6141 final long identity = Binder.clearCallingIdentity();
6142 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006143 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006144 // may happen if the device does not support IMS.
6145 return null;
6146 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006147 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006148 } finally {
6149 Binder.restoreCallingIdentity(identity);
6150 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006151 }
6152
Brad Ebinger884c07b2018-02-15 16:17:40 -08006153 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006154 * Sets the ImsService Package Name that Telephony will bind to.
6155 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006156 * @param slotIndex the slot ID that the ImsService should bind for.
6157 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006158 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006159 * @param featureTypes An integer array of feature types associated with a packageName.
6160 * @param packageName The name of the package that the current configuration will be replaced
6161 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006162 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006163 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006164 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6165 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006166 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006167 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006168 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006169
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006170 final long identity = Binder.clearCallingIdentity();
6171 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006172 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006173 // may happen if the device does not support IMS.
6174 return false;
6175 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006176 Map<Integer, String> featureConfig = new HashMap<>();
6177 for (int featureType : featureTypes) {
6178 featureConfig.put(featureType, packageName);
6179 }
6180 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6181 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006182 } finally {
6183 Binder.restoreCallingIdentity(identity);
6184 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006185 }
6186
6187 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006188 * Clears any carrier ImsService overrides for the slot index specified that were previously
6189 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6190 *
6191 * This should only be used for testing.
6192 *
6193 * @param slotIndex the slot ID that the ImsService should bind for.
6194 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6195 */
6196 @Override
6197 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006198 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6199 "clearCarrierImsServiceOverride");
6200 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006201 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006202
6203 final long identity = Binder.clearCallingIdentity();
6204 try {
6205 if (mImsResolver == null) {
6206 // may happen if the device does not support IMS.
6207 return false;
6208 }
6209 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6210 } finally {
6211 Binder.restoreCallingIdentity(identity);
6212 }
6213 }
6214
6215 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006216 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006217 *
6218 * @param slotId The slot that the ImsService is associated with.
6219 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6220 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006221 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006222 * @return the package name of the ImsService configuration.
6223 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006224 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6225 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006226 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006227 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6228 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006229
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006230 final long identity = Binder.clearCallingIdentity();
6231 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006232 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006233 // may happen if the device does not support IMS.
6234 return "";
6235 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006236 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006237 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6238 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006239 } finally {
6240 Binder.restoreCallingIdentity(identity);
6241 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006242 }
6243
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006244 /**
6245 * Get the MmTelFeature state associated with the requested subscription id.
6246 * @param subId The subscription that the MmTelFeature is associated with.
6247 * @param callback A callback with an integer containing the
6248 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6249 */
6250 @Override
6251 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6252 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006253 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6254 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6255 "IMS not available on device.");
6256 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006257 final long token = Binder.clearCallingIdentity();
6258 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006259 int slotId = getSlotIndex(subId);
6260 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6261 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6262 + subId + "'");
6263 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6264 }
6265 verifyImsMmTelConfiguredOrThrow(slotId);
6266 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6267 try {
6268 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6269 } catch (RemoteException e) {
6270 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6271 + "Ignore");
6272 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006273 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006274 } catch (ImsException e) {
6275 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006276 } finally {
6277 Binder.restoreCallingIdentity(token);
6278 }
6279 }
6280
Daniel Brightbb5840b2021-01-12 15:48:18 -08006281 /**
6282 * Sets the ims registration state on all valid {@link Phone}s.
6283 */
6284 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006285 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006286
6287 final long identity = Binder.clearCallingIdentity();
6288 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006289 // NOTE: Before S, this method only set the default phone.
6290 for (final Phone phone : PhoneFactory.getPhones()) {
6291 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6292 phone.setImsRegistrationState(registered);
6293 }
6294 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006295 } finally {
6296 Binder.restoreCallingIdentity(identity);
6297 }
Wink Saville36469e72014-06-11 15:17:00 -07006298 }
6299
6300 /**
Stuart Scott54788802015-03-30 13:18:01 -07006301 * Set the network selection mode to automatic.
6302 *
6303 */
6304 @Override
6305 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006306 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6307 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006308
6309 final long identity = Binder.clearCallingIdentity();
6310 try {
shilufc958392020-01-20 11:36:01 -08006311 if (!isActiveSubscription(subId)) {
6312 return;
6313 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006314 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006315 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6316 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006317 } finally {
6318 Binder.restoreCallingIdentity(identity);
6319 }
Stuart Scott54788802015-03-30 13:18:01 -07006320 }
6321
Jack Yud10cdd42020-09-28 20:28:01 -07006322 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006323 * Ask the radio to connect to the input network and change selection mode to manual.
6324 *
6325 * @param subId the id of the subscription.
6326 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6327 * the operator to attach to.
6328 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6329 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6330 * normal network selection next time.
6331 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006332 */
6333 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006334 public boolean setNetworkSelectionModeManual(
6335 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006336 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6337 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006338
Jack Yu285100e2022-12-02 22:48:35 -08006339 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006340 if (!isActiveSubscription(subId)) {
6341 return false;
6342 }
6343
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006344 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006345 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006346 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006347 if (DBG) {
6348 log("setNetworkSelectionModeManual: subId: " + subId
6349 + " operator: " + operatorInfo);
6350 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006351 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6352 } finally {
6353 Binder.restoreCallingIdentity(identity);
6354 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006355 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006356 /**
shilu84f6e8b2019-12-19 13:58:01 -08006357 * Get the manual network selection
6358 *
6359 * @param subId the id of the subscription.
6360 *
6361 * @return the previously saved user selected PLMN
6362 */
6363 @Override
6364 public String getManualNetworkSelectionPlmn(int subId) {
6365 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006366 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6367 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006368
6369 final long identity = Binder.clearCallingIdentity();
6370 try {
6371 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006372 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006373 }
6374
6375 final Phone phone = getPhone(subId);
6376 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006377 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006378 }
6379 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6380 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006381 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006382 } finally {
6383 Binder.restoreCallingIdentity(identity);
6384 }
6385 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006386
6387 /**
6388 * Scans for available networks.
6389 */
6390 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006391 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6392 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006393 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6394 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006395 LocationAccessPolicy.LocationPermissionResult locationResult =
6396 LocationAccessPolicy.checkLocationPermission(mApp,
6397 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6398 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006399 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006400 .setCallingPid(Binder.getCallingPid())
6401 .setCallingUid(Binder.getCallingUid())
6402 .setMethod("getCellNetworkScanResults")
6403 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006404 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6405 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006406 .build());
6407 switch (locationResult) {
6408 case DENIED_HARD:
6409 throw new SecurityException("Not allowed to access scan results -- location");
6410 case DENIED_SOFT:
6411 return null;
6412 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006413
Pengquan Menga1bb6272018-09-06 09:59:22 -07006414 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006415 try {
6416 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006417 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006418 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006419 } finally {
6420 Binder.restoreCallingIdentity(identity);
6421 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006422 }
6423
6424 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006425 * Get the call forwarding info, given the call forwarding reason.
6426 */
6427 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006428 public void getCallForwarding(int subId, int callForwardingReason,
6429 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006430 enforceReadPrivilegedPermission("getCallForwarding");
6431 long identity = Binder.clearCallingIdentity();
6432 try {
6433 if (DBG) {
6434 log("getCallForwarding: subId " + subId
6435 + " callForwardingReason" + callForwardingReason);
6436 }
Hall Liu27d24262020-09-18 19:04:59 -07006437
6438 Phone phone = getPhone(subId);
6439 if (phone == null) {
6440 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006441 callback.onError(
6442 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006443 } catch (RemoteException e) {
6444 // ignore
6445 }
6446 return;
6447 }
6448
6449 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6450 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6451 @Override
6452 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6453 try {
6454 callback.onCallForwardingInfoAvailable(info);
6455 } catch (RemoteException e) {
6456 // ignore
6457 }
6458 }
6459
6460 @Override
6461 public void onError(int error) {
6462 try {
6463 callback.onError(error);
6464 } catch (RemoteException e) {
6465 // ignore
6466 }
6467 }
6468 });
6469 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006470 } finally {
6471 Binder.restoreCallingIdentity(identity);
6472 }
6473 }
6474
6475 /**
6476 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6477 * reason, the number to forward, and the timeout before the forwarding is attempted.
6478 */
6479 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006480 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6481 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006482 enforceModifyPermission();
6483 long identity = Binder.clearCallingIdentity();
6484 try {
6485 if (DBG) {
6486 log("setCallForwarding: subId " + subId
6487 + " callForwardingInfo" + callForwardingInfo);
6488 }
Hall Liu27d24262020-09-18 19:04:59 -07006489
6490 Phone phone = getPhone(subId);
6491 if (phone == null) {
6492 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006493 callback.accept(
6494 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006495 } catch (RemoteException e) {
6496 // ignore
6497 }
6498 return;
6499 }
6500
6501 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6502 FunctionalUtils.ignoreRemoteException(callback::accept));
6503
6504 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006505 } finally {
6506 Binder.restoreCallingIdentity(identity);
6507 }
6508 }
6509
6510 /**
Hall Liu27d24262020-09-18 19:04:59 -07006511 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006512 */
6513 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006514 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006515 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006516 long identity = Binder.clearCallingIdentity();
6517 try {
Hall Liu27d24262020-09-18 19:04:59 -07006518 Phone phone = getPhone(subId);
6519 if (phone == null) {
6520 try {
6521 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6522 } catch (RemoteException e) {
6523 // ignore
6524 }
6525 return;
6526 }
SongFerngWang0e767992021-03-31 22:08:45 +08006527 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6528 PersistableBundle c = configManager.getConfigForSubId(subId);
6529 boolean requireUssd = c.getBoolean(
6530 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006531
Shuo Qian4a594052020-01-23 11:59:30 -08006532 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006533 if (requireUssd) {
6534 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6535 getSubscriptionCarrierId(subId));
6536 String newUssdCommand = "";
6537 try {
6538 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006539 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006540 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6541 } catch (NullPointerException e) {
6542 loge("Failed to generate USSD number" + e);
6543 }
6544 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6545 mMainThreadHandler, callback, carrierXmlParser,
6546 CarrierXmlParser.SsEntry.SSAction.QUERY);
6547 final String ussdCommand = newUssdCommand;
6548 Executors.newSingleThreadExecutor().execute(() -> {
6549 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6550 });
6551 } else {
6552 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6553 callback::accept);
6554 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6555 }
Shuo Qian4a594052020-01-23 11:59:30 -08006556 } finally {
6557 Binder.restoreCallingIdentity(identity);
6558 }
6559 }
6560
6561 /**
Hall Liu27d24262020-09-18 19:04:59 -07006562 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006563 */
6564 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006565 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006566 enforceModifyPermission();
6567 long identity = Binder.clearCallingIdentity();
6568 try {
Hall Liu27d24262020-09-18 19:04:59 -07006569 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6570
6571 Phone phone = getPhone(subId);
6572 if (phone == null) {
6573 try {
6574 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6575 } catch (RemoteException e) {
6576 // ignore
6577 }
6578 return;
6579 }
6580
SongFerngWang0e767992021-03-31 22:08:45 +08006581 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6582 PersistableBundle c = configManager.getConfigForSubId(subId);
6583 boolean requireUssd = c.getBoolean(
6584 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006585
SongFerngWang0e767992021-03-31 22:08:45 +08006586 if (DBG) log("getCallWaitingStatus: subId " + subId);
6587 if (requireUssd) {
6588 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6589 getSubscriptionCarrierId(subId));
6590 CarrierXmlParser.SsEntry.SSAction ssAction =
6591 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6592 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6593 String newUssdCommand = "";
6594 try {
6595 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006596 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006597 .makeCommand(ssAction, null);
6598 } catch (NullPointerException e) {
6599 loge("Failed to generate USSD number" + e);
6600 }
6601 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6602 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6603 final String ussdCommand = newUssdCommand;
6604 Executors.newSingleThreadExecutor().execute(() -> {
6605 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6606 });
6607 } else {
6608 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6609 FunctionalUtils.ignoreRemoteException(callback::accept));
6610
6611 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6612 }
Shuo Qian4a594052020-01-23 11:59:30 -08006613 } finally {
6614 Binder.restoreCallingIdentity(identity);
6615 }
6616 }
6617
6618 /**
yinxub1bed742017-04-17 11:45:04 -07006619 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006620 *
yinxub1bed742017-04-17 11:45:04 -07006621 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006622 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6623 * location related information which will be sent if the caller already possess
6624 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006625 * @param request contains the radio access networks with bands/channels to scan
6626 * @param messenger callback messenger for scan results or errors
6627 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006628 * @return the id of the requested scan which can be used to stop the scan.
6629 */
6630 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006631 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6632 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006633 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006634 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6635 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006636 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006637 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6638 if (!renounceFineLocationAccess) {
6639 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006640 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6641 .setCallingPackage(callingPackage)
6642 .setCallingFeatureId(callingFeatureId)
6643 .setCallingPid(Binder.getCallingPid())
6644 .setCallingUid(Binder.getCallingUid())
6645 .setMethod("requestNetworkScan")
6646 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6647 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6648 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6649 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006650 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006651 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006652 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6653 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006654 if (e != null) {
6655 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6656 throw e;
6657 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006658 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006659 return TelephonyScanManager.INVALID_SCAN_ID;
6660 }
6661 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006662 }
Hall Liu912dfd32019-04-25 14:02:26 -07006663 int callingUid = Binder.getCallingUid();
6664 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006665 final long identity = Binder.clearCallingIdentity();
6666 try {
6667 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006668 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006669 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006670 } finally {
6671 Binder.restoreCallingIdentity(identity);
6672 }
yinxu504e1392017-04-12 16:03:22 -07006673 }
6674
Hall Liub2ac8ef2019-02-28 15:56:23 -08006675 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006676 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00006677 boolean hasCarrierPriv;
6678 final long identity = Binder.clearCallingIdentity();
6679 try {
6680 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6681 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6682 } finally {
6683 Binder.restoreCallingIdentity(identity);
6684 }
Hall Liu558027f2019-05-15 19:14:05 -07006685 boolean hasNetworkScanPermission =
6686 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006687 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07006688
6689 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6690 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6691 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006692 }
6693
6694 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6695 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006696 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6697 return new SecurityException("Specific channels must not be"
6698 + " scanned without location access.");
6699 }
6700 }
6701 }
6702
Hall Liub2ac8ef2019-02-28 15:56:23 -08006703 return null;
6704 }
6705
yinxu504e1392017-04-12 16:03:22 -07006706 /**
6707 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006708 *
6709 * @param subId id of the subscription
6710 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006711 */
6712 @Override
6713 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006714 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6715 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006716
Hall Liu912dfd32019-04-25 14:02:26 -07006717 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006718 final long identity = Binder.clearCallingIdentity();
6719 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006720 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006721 } finally {
6722 Binder.restoreCallingIdentity(identity);
6723 }
yinxu504e1392017-04-12 16:03:22 -07006724 }
6725
6726 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006727 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006728 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006729 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006730 */
6731 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006732 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006733 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006734 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006735 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006736
6737 final long identity = Binder.clearCallingIdentity();
6738 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006739 if (DBG) log("getAllowedNetworkTypesBitmask");
6740 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6741 int networkTypesBitmask = (result != null ? result[0] : -1);
6742 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6743 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006744 } finally {
6745 Binder.restoreCallingIdentity(identity);
6746 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006747 }
6748
6749 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006750 * Get the allowed network types for certain reason.
6751 *
6752 * @param subId the id of the subscription.
6753 * @param reason the reason the allowed network type change is taking place
6754 * @return the allowed network types.
6755 */
6756 @Override
6757 public long getAllowedNetworkTypesForReason(int subId,
6758 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006759 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006760 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006761 final long identity = Binder.clearCallingIdentity();
6762 try {
Jack Yu7247ac82023-03-02 23:52:10 -08006763 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006764 } finally {
6765 Binder.restoreCallingIdentity(identity);
6766 }
6767 }
6768
6769 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006770 * Enable/Disable E-UTRA-NR Dual Connectivity
6771 * @param subId subscription id of the sim card
6772 * @param nrDualConnectivityState expected NR dual connectivity state
6773 * This can be passed following states
6774 * <ol>
6775 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6776 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6777 * <li>Disable NR dual connectivity and force secondary cell to be released
6778 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6779 * </ol>
6780 * @return operation result.
6781 */
6782 @Override
6783 public int setNrDualConnectivityState(int subId,
6784 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6785 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6786 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006787 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006788 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6789 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6790 }
6791
Sooraj Sasindran37444802020-08-11 10:40:43 -07006792 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6793 final long identity = Binder.clearCallingIdentity();
6794 try {
6795 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6796 nrDualConnectivityState, subId,
6797 workSource);
6798 if (DBG) log("enableNRDualConnectivity result: " + result);
6799 return result;
6800 } finally {
6801 Binder.restoreCallingIdentity(identity);
6802 }
6803 }
6804
6805 /**
6806 * Is E-UTRA-NR Dual Connectivity enabled
6807 * @return true if dual connectivity is enabled else false
6808 */
6809 @Override
6810 public boolean isNrDualConnectivityEnabled(int subId) {
6811 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006812 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006813 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006814 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006815 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6816 return false;
6817 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006818 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6819 final long identity = Binder.clearCallingIdentity();
6820 try {
6821 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6822 null, subId, workSource);
6823 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6824 return isEnabled;
6825 } finally {
6826 Binder.restoreCallingIdentity(identity);
6827 }
6828 }
6829
6830 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006831 * Set the allowed network types of the device and
6832 * provide the reason triggering the allowed network change.
6833 *
6834 * @param subId the id of the subscription.
6835 * @param reason the reason the allowed network type change is taking place
6836 * @param allowedNetworkTypes the allowed network types.
6837 * @return true on success; false on any failure.
6838 */
6839 @Override
6840 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006841 @TelephonyManager.AllowedNetworkTypesReason int reason,
6842 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006843 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6844 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006845 // If the caller only has carrier privileges, then they should not be able to override
6846 // any network types which were set for security reasons.
6847 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6848 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00006849 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006850 throw new SecurityException(
6851 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00006852 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006853 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006854 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006855 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08006856 return false;
6857 }
6858 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6859 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006860 return false;
6861 }
6862
Jack Yu5b494332023-01-23 18:18:04 +00006863 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
6864 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006865
Jack Yue37dd262022-12-16 11:53:37 -08006866 Phone phone = getPhone(subId);
6867 if (phone == null) {
6868 return false;
6869 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006870
Jack Yue37dd262022-12-16 11:53:37 -08006871 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006872 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006873 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006874 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006875
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006876 final long identity = Binder.clearCallingIdentity();
6877 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006878 Boolean success = (Boolean) sendRequest(
6879 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6880 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6881
6882 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6883 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006884 } finally {
6885 Binder.restoreCallingIdentity(identity);
6886 }
6887 }
6888
6889 /**
Miaoa84611c2019-03-15 09:21:10 +08006890 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006891 *
Miaoa84611c2019-03-15 09:21:10 +08006892 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006893 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006894 * @hide
6895 */
6896 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006897 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006898 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006899 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006900 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006901 try {
Miaoa84611c2019-03-15 09:21:10 +08006902 if (phone != null) {
6903 return phone.hasMatchedTetherApnSetting();
6904 } else {
6905 return false;
6906 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006907 } finally {
6908 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006909 }
Junda Liu475951f2014-11-07 16:45:03 -08006910 }
6911
6912 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006913 * Get the user enabled state of Mobile Data.
6914 *
6915 * TODO: remove and use isUserDataEnabled.
6916 * This can't be removed now because some vendor codes
6917 * calls through ITelephony directly while they should
6918 * use TelephonyManager.
6919 *
6920 * @return true on enabled
6921 */
6922 @Override
6923 public boolean getDataEnabled(int subId) {
6924 return isUserDataEnabled(subId);
6925 }
6926
6927 /**
6928 * Get whether mobile data is enabled per user setting.
6929 *
6930 * There are other factors deciding whether mobile data is actually enabled, but they are
6931 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006932 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006933 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6934 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006935 *
6936 * @return {@code true} if data is enabled else {@code false}
6937 */
6938 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006939 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006940 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006941 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006942 try {
6943 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6944 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006945 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006946 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6947 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006948 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006949 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006950 mApp, subId, functionName);
6951
Robert Greenwalt646120a2014-05-23 11:54:03 -07006952 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006953
6954 final long identity = Binder.clearCallingIdentity();
6955 try {
Jack Yu285100e2022-12-02 22:48:35 -08006956 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006957 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6958 Phone phone = PhoneFactory.getPhone(phoneId);
6959 if (phone != null) {
6960 boolean retVal = phone.isUserDataEnabled();
6961 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6962 return retVal;
6963 } else {
6964 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6965 return false;
6966 }
6967 } finally {
6968 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006969 }
6970 }
6971
6972 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006973 * Checks if the device is capable of mobile data by considering whether whether the
6974 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6975 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006976 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006977 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006978 */
6979 @Override
6980 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006981 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006982 try {
6983 try {
6984 mApp.enforceCallingOrSelfPermission(
6985 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006986 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006987 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006988 try {
6989 mApp.enforceCallingOrSelfPermission(
6990 android.Manifest.permission.READ_PHONE_STATE,
6991 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006992 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006993 mApp.enforceCallingOrSelfPermission(
6994 permission.READ_BASIC_PHONE_STATE, functionName);
6995 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006996 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006997 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006998 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006999 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007000
7001 final long identity = Binder.clearCallingIdentity();
7002 try {
Jack Yu285100e2022-12-02 22:48:35 -08007003 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007004 Phone phone = PhoneFactory.getPhone(phoneId);
7005 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007006 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007007 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007008 return retVal;
7009 } else {
7010 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7011 return false;
7012 }
7013 } finally {
7014 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007015 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007016 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007017
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007018 /**
7019 * Check if data is enabled for a specific reason
7020 * @param subId Subscription index
7021 * @param reason the reason the data enable change is taking place
7022 * @return {@code true} if the overall data is enabled; {@code false} if not.
7023 */
7024 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007025 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007026 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007027 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007028 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007029 try {
7030 mApp.enforceCallingOrSelfPermission(
7031 android.Manifest.permission.ACCESS_NETWORK_STATE,
7032 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007033 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007034 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7035 functionName);
7036 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007037 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007038 try {
7039 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007040 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007041 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007042 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007043 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007044 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007045 }
7046
7047
7048 final long identity = Binder.clearCallingIdentity();
7049 try {
Jack Yu285100e2022-12-02 22:48:35 -08007050 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007051 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007052 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007053 + " reason=" + reason);
7054 }
7055 Phone phone = PhoneFactory.getPhone(phoneId);
7056 if (phone != null) {
7057 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007058 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007059 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007060 return retVal;
7061 } else {
7062 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007063 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007064 + subId + " retVal=false");
7065 }
7066 return false;
7067 }
7068 } finally {
7069 Binder.restoreCallingIdentity(identity);
7070 }
7071 }
7072
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007073 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007074 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007075 // No permission needed; this only lets the caller inspect their own status.
7076 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007077 }
Junda Liu29340342014-07-10 15:23:27 -07007078
7079 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007080 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007081 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007082 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7083 }
7084
7085 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7086 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007087 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007088 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007089 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7090 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007091 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7092 if (cpt == null) {
7093 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007094 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7095 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007096 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007097 }
7098
7099 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007100 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007101 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07007102 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007103 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007104 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007105 Phone phone = getPhone(subId);
7106 if (phone == null) {
7107 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7108 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7109 }
7110 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7111 if (cpt == null) {
7112 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007113 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7114 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007115 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007116 }
7117
7118 @Override
7119 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007120 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08007121 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7122 }
7123
7124 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007125 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007126 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007127 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007128 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007129 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7130 Phone phone = PhoneFactory.getPhone(phoneId);
7131 if (phone == null) {
7132 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007133 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007134 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7135 if (cpt == null) {
7136 continue;
7137 }
7138 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007139 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7140 break;
7141 }
7142 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007143 return result;
Junda Liu29340342014-07-10 15:23:27 -07007144 }
Derek Tan89e89d42014-07-08 17:00:10 -07007145
7146 @Override
Junda Liue64de782015-04-16 17:19:16 -07007147 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007148 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00007149 Phone phone = PhoneFactory.getPhone(phoneId);
7150 if (phone == null) {
7151 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007152 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007153 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7154 if (cpt == null) {
7155 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007156 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007157 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007158 }
7159
Amith Yamasani6e118872016-02-19 12:53:51 -08007160 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007161 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007162 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007163 Phone phone = PhoneFactory.getPhone(phoneId);
7164 if (phone == null) {
7165 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007166 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007167 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7168 if (cpt == null) {
7169 return Collections.emptyList();
7170 }
7171 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007172 }
7173
chen xuf7e9fe82019-05-09 19:31:02 -07007174 @Override
7175 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007176 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007177 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007178 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007179 try {
7180 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7181 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7182 }
7183 } finally {
7184 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007185 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007186 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007187 }
7188
Rambo Wang6812ffb2022-03-15 16:54:17 -07007189 @Override
7190 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7191 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7192
7193 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7194 if (phone == null) {
7195 return null;
7196 }
7197 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7198 if (cpt == null) {
7199 return null;
7200 }
7201 return cpt.getCarrierServicePackageName();
7202 }
7203
Wink Savilleb564aae2014-10-23 10:18:09 -07007204 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007205 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007206 UiccPort port = phone == null ? null : phone.getUiccPort();
7207 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007208 return null;
7209 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007210 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007211 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007212 return null;
7213 }
7214 return iccId;
7215 }
7216
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007217 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007218 public void setCallComposerStatus(int subId, int status) {
7219 enforceModifyPermission();
7220
7221 final long identity = Binder.clearCallingIdentity();
7222 try {
7223 Phone phone = getPhone(subId);
7224 if (phone != null) {
7225 Phone defaultPhone = phone.getImsPhone();
7226 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7227 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7228 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007229 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7230 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007231 }
7232 }
Shuo Qian284ae752020-12-22 19:10:14 -08007233 } catch (ImsException e) {
7234 throw new ServiceSpecificException(e.getCode());
7235 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007236 Binder.restoreCallingIdentity(identity);
7237 }
7238 }
7239
7240 @Override
7241 public int getCallComposerStatus(int subId) {
7242 enforceReadPrivilegedPermission("getCallComposerStatus");
7243
7244 final long identity = Binder.clearCallingIdentity();
7245 try {
7246 Phone phone = getPhone(subId);
7247 if (phone != null) {
7248 Phone defaultPhone = phone.getImsPhone();
7249 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7250 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7251 return imsPhone.getCallComposerStatus();
7252 }
7253 }
7254 } finally {
7255 Binder.restoreCallingIdentity(identity);
7256 }
7257 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7258 }
7259
7260 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007261 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7262 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007263 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007264 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007265
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007266 final long identity = Binder.clearCallingIdentity();
7267 try {
7268 final String iccId = getIccId(subId);
7269 final Phone phone = getPhone(subId);
7270 if (phone == null) {
7271 return false;
7272 }
7273 final String subscriberId = phone.getSubscriberId();
7274
7275 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007276 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007277 + subscriberId + " to " + number);
7278 }
7279
7280 if (TextUtils.isEmpty(iccId)) {
7281 return false;
7282 }
7283
7284 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7285
7286 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7287 if (alphaTag == null) {
7288 editor.remove(alphaTagPrefKey);
7289 } else {
7290 editor.putString(alphaTagPrefKey, alphaTag);
7291 }
7292
7293 // Record both the line number and IMSI for this ICCID, since we need to
7294 // track all merged IMSIs based on line number
7295 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7296 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7297 if (number == null) {
7298 editor.remove(numberPrefKey);
7299 editor.remove(subscriberPrefKey);
7300 } else {
7301 editor.putString(numberPrefKey, number);
7302 editor.putString(subscriberPrefKey, subscriberId);
7303 }
7304
7305 editor.commit();
7306 return true;
7307 } finally {
7308 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007309 }
Derek Tan7226c842014-07-02 17:42:23 -07007310 }
7311
7312 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007313 public String getLine1NumberForDisplay(int subId, String callingPackage,
7314 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007315 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007316 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007317 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007318 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007319 return null;
7320 }
Derek Tan97ebb422014-09-05 16:55:38 -07007321
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007322 final long identity = Binder.clearCallingIdentity();
7323 try {
7324 String iccId = getIccId(subId);
7325 if (iccId != null) {
7326 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7327 if (DBG_MERGE) {
7328 log("getLine1NumberForDisplay returning "
7329 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7330 }
7331 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007332 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007333 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7334 return null;
7335 } finally {
7336 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007337 }
Derek Tan7226c842014-07-02 17:42:23 -07007338 }
7339
7340 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007341 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7342 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007343 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007344 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007345 return null;
7346 }
Derek Tan97ebb422014-09-05 16:55:38 -07007347
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007348 final long identity = Binder.clearCallingIdentity();
7349 try {
7350 String iccId = getIccId(subId);
7351 if (iccId != null) {
7352 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7353 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7354 }
7355 return null;
7356 } finally {
7357 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007358 }
Derek Tan7226c842014-07-02 17:42:23 -07007359 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007360
7361 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007362 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7363 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007364 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7365 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007366 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007367 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007368 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007369 return null;
7370 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007371
Jordan Liub49b04b2019-05-06 14:45:15 -07007372 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7373 // the process, where TelephonyManager was instantiated.
7374 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007375 final long identity = Binder.clearCallingIdentity();
7376 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007377 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007378 final TelephonyManager tele = TelephonyManager.from(context);
7379 final SubscriptionManager sub = SubscriptionManager.from(context);
7380
7381 // Figure out what subscribers are currently active
7382 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007383
Jordan Liub49b04b2019-05-06 14:45:15 -07007384 // Only consider subs which match the current subId
7385 // This logic can be simplified. See b/131189269 for progress.
7386 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007387 activeSubscriberIds.add(tele.getSubscriberId(subId));
7388 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007389
7390 // First pass, find a number override for an active subscriber
7391 String mergeNumber = null;
7392 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7393 for (String key : prefs.keySet()) {
7394 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7395 final String subscriberId = (String) prefs.get(key);
7396 if (activeSubscriberIds.contains(subscriberId)) {
7397 final String iccId = key.substring(
7398 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7399 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7400 mergeNumber = (String) prefs.get(numberKey);
7401 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007402 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007403 + " for active subscriber " + subscriberId);
7404 }
7405 if (!TextUtils.isEmpty(mergeNumber)) {
7406 break;
7407 }
7408 }
7409 }
7410 }
7411
7412 // Shortcut when no active merged subscribers
7413 if (TextUtils.isEmpty(mergeNumber)) {
7414 return null;
7415 }
7416
7417 // Second pass, find all subscribers under that line override
7418 final ArraySet<String> result = new ArraySet<>();
7419 for (String key : prefs.keySet()) {
7420 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7421 final String number = (String) prefs.get(key);
7422 if (mergeNumber.equals(number)) {
7423 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7424 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7425 final String subscriberId = (String) prefs.get(subscriberKey);
7426 if (!TextUtils.isEmpty(subscriberId)) {
7427 result.add(subscriberId);
7428 }
7429 }
7430 }
7431 }
7432
7433 final String[] resultArray = result.toArray(new String[result.size()]);
7434 Arrays.sort(resultArray);
7435 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007436 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007437 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7438 }
7439 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007440 } finally {
7441 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007442 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007443 }
7444
7445 @Override
zoey chen38003472019-12-13 17:16:31 +08007446 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7447 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007448
7449 final long identity = Binder.clearCallingIdentity();
7450 try {
7451 final TelephonyManager telephonyManager = mApp.getSystemService(
7452 TelephonyManager.class);
7453 String subscriberId = telephonyManager.getSubscriberId(subId);
7454 if (subscriberId == null) {
7455 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007456 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007457 + subId);
7458 }
7459 return null;
7460 }
7461
Jack Yu285100e2022-12-02 22:48:35 -08007462 ParcelUuid groupUuid;
7463 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08007464 final SubscriptionInfo info = getSubscriptionManagerService()
Jack Yu285100e2022-12-02 22:48:35 -08007465 .getSubscriptionInfo(subId);
7466 groupUuid = info.getGroupUuid();
7467 } else {
7468 final SubscriptionInfo info = mSubscriptionController
7469 .getSubscriptionInfo(subId);
7470 groupUuid = info.getGroupUuid();
7471 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007472 // If it doesn't belong to any group, return just subscriberId of itself.
7473 if (groupUuid == null) {
7474 return new String[]{subscriberId};
7475 }
7476
7477 // Get all subscriberIds from the group.
7478 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu285100e2022-12-02 22:48:35 -08007479 List<SubscriptionInfo> groupInfos;
7480 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08007481 groupInfos = getSubscriptionManagerService()
Jack Yu285100e2022-12-02 22:48:35 -08007482 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7483 mApp.getAttributionTag());
7484 } else {
7485 groupInfos = mSubscriptionController
7486 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7487 mApp.getAttributionTag());
7488 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007489 for (SubscriptionInfo subInfo : groupInfos) {
7490 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7491 if (subscriberId != null) {
7492 mergedSubscriberIds.add(subscriberId);
7493 }
7494 }
7495
7496 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7497 } finally {
7498 Binder.restoreCallingIdentity(identity);
7499
7500 }
7501 }
7502
7503 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007504 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007505 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007506 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007507
7508 final long identity = Binder.clearCallingIdentity();
7509 try {
7510 final Phone phone = getPhone(subId);
7511 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7512 } finally {
7513 Binder.restoreCallingIdentity(identity);
7514 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007515 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007516
7517 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007518 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007519 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7520 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007521 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7522 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007523
7524 final long identity = Binder.clearCallingIdentity();
7525 try {
7526 final Phone phone = getPhone(subId);
7527 if (phone == null) {
7528 return false;
7529 }
7530 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7531 cdmaNonRoamingList);
7532 } finally {
7533 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007534 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007535 }
7536
7537 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007538 @Deprecated
7539 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7540 enforceModifyPermission();
7541
7542 int returnValue = 0;
7543 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007544 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007545 if(result.exception == null) {
7546 if (result.result != null) {
7547 byte[] responseData = (byte[])(result.result);
7548 if(responseData.length > oemResp.length) {
7549 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7550 responseData.length + "bytes. Buffer Size is " +
7551 oemResp.length + "bytes.");
7552 }
7553 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7554 returnValue = responseData.length;
7555 }
7556 } else {
7557 CommandException ex = (CommandException) result.exception;
7558 returnValue = ex.getCommandError().ordinal();
7559 if(returnValue > 0) returnValue *= -1;
7560 }
7561 } catch (RuntimeException e) {
7562 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7563 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7564 if(returnValue > 0) returnValue *= -1;
7565 }
7566
7567 return returnValue;
7568 }
7569
7570 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007571 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007572 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007573 try {
7574 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007575 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007576 mApp, phone.getSubId(), "getRadioAccessFamily");
7577 } catch (SecurityException e) {
7578 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7579 throw e;
7580 }
chen xub97461a2018-10-26 14:17:57 -07007581 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007582 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007583 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007584 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007585 final long identity = Binder.clearCallingIdentity();
7586 try {
chen xub97461a2018-10-26 14:17:57 -07007587 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007588 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007589 mApp, phone.getSubId(), "getRadioAccessFamily");
7590 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007591 } finally {
7592 Binder.restoreCallingIdentity(identity);
7593 }
chen xub97461a2018-10-26 14:17:57 -07007594 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007595 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007596
7597 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007598 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007599 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007600 try {
7601 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7602 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007603 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007604 }
7605 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007606 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007607 }
7608 RoleManager rm = mApp.getSystemService(RoleManager.class);
7609 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7610 if (!dialerRoleHolders.contains(callingPackage)) {
7611 throw new SecurityException("App must be the dialer role holder to"
7612 + " upload a call composer pic");
7613 }
7614
7615 Executors.newSingleThreadExecutor().execute(() -> {
7616 ByteArrayOutputStream output = new ByteArrayOutputStream(
7617 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7618 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7619 boolean readUntilEnd = false;
7620 int totalBytesRead = 0;
7621 byte[] buffer = new byte[16 * 1024];
7622 while (true) {
7623 int numRead;
7624 try {
7625 numRead = input.read(buffer);
7626 } catch (IOException e) {
7627 try {
7628 fd.checkError();
7629 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7630 null);
7631 } catch (IOException e1) {
7632 // This means that the other side closed explicitly with an error. If this
7633 // happens, log and ignore.
7634 loge("Remote end of call composer picture pipe closed: " + e1);
7635 }
7636 break;
7637 }
7638 if (numRead == -1) {
7639 readUntilEnd = true;
7640 break;
7641 }
7642 totalBytesRead += numRead;
7643 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7644 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7645 try {
7646 input.close();
7647 } catch (IOException e) {
7648 // ignore
7649 }
7650 break;
7651 }
7652 output.write(buffer, 0, numRead);
7653 }
7654 // Generally, the remote end will close the file descriptors. The only case where we
7655 // close is above, where the picture size is too big.
7656
7657 try {
7658 fd.checkError();
7659 } catch (IOException e) {
7660 loge("Remote end for call composer closed with an error: " + e);
7661 return;
7662 }
7663
Hall Liuaa4211e2021-01-20 15:43:39 -08007664 if (!readUntilEnd) {
7665 loge("Did not finish reading entire image; aborting");
7666 return;
7667 }
Hall Liu82694d52020-12-11 18:22:04 -08007668
Hall Liuaa4211e2021-01-20 15:43:39 -08007669 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7670 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7671 new CallComposerPictureTransfer.Factory() {},
7672 imageData,
7673 (result) -> {
7674 if (result.first != null) {
7675 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7676 Bundle outputResult = new Bundle();
7677 outputResult.putParcelable(
7678 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7679 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7680 outputResult);
7681 } else {
7682 callback.send(result.second, null);
7683 }
7684 }
7685 );
Hall Liu82694d52020-12-11 18:22:04 -08007686 });
7687 }
7688
7689 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007690 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007691 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007692 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007693
7694 final long identity = Binder.clearCallingIdentity();
7695 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007696 ImsManager.getInstance(defaultPhone.getContext(),
7697 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007698 } finally {
7699 Binder.restoreCallingIdentity(identity);
7700 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007701 }
7702
7703 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007704 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007705 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007706 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7707 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007708 return false;
7709 }
Svet Ganovb320e182015-04-16 12:30:10 -07007710
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007711 final long identity = Binder.clearCallingIdentity();
7712 try {
7713 // Check the user preference and the system-level IMS setting. Even if the user has
7714 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7715 // In the long run, we may instead need to check if there exists a connection service
7716 // which can support video calling.
7717 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007718 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007719 return imsManager.isVtEnabledByPlatform()
7720 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7721 && imsManager.isVtEnabledByUser();
7722 } finally {
7723 Binder.restoreCallingIdentity(identity);
7724 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007725 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007726
Andrew Leea1239f22015-03-02 17:44:07 -08007727 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007728 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7729 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007730 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007731 mApp, subId, callingPackage, callingFeatureId,
7732 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007733 return false;
7734 }
7735
7736 final long identity = Binder.clearCallingIdentity();
7737 try {
7738 CarrierConfigManager configManager =
7739 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007740 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007741 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7742 } finally {
7743 Binder.restoreCallingIdentity(identity);
7744 }
Andrew Leea1239f22015-03-02 17:44:07 -08007745 }
7746
7747 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007748 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007749 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007750 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007751 return false;
7752 }
7753
7754 final long identity = Binder.clearCallingIdentity();
7755 try {
7756 CarrierConfigManager configManager =
7757 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007758 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007759 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7760 } finally {
7761 Binder.restoreCallingIdentity(identity);
7762 }
Andrew Leea1239f22015-03-02 17:44:07 -08007763 }
7764
Andrew Lee9431b832015-03-09 18:46:45 -07007765 @Override
7766 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007767 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007768 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007769 }
7770
7771 @Override
7772 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007773 final long identity = Binder.clearCallingIdentity();
7774 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007775 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007776 } finally {
7777 Binder.restoreCallingIdentity(identity);
7778 }
Andrew Lee9431b832015-03-09 18:46:45 -07007779 }
7780
Hall Liuf6668912018-10-31 17:05:23 -07007781 /**
7782 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7783 * support for the feature and device firmware support.
7784 *
7785 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7786 */
7787 @Override
7788 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007789 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007790 final Phone phone = getPhone(subscriptionId);
7791 if (phone == null) {
7792 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7793 return false;
7794 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007795 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007796 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007797 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7798 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007799 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007800 return isCarrierSupported && isDeviceSupported;
7801 } finally {
7802 Binder.restoreCallingIdentity(identity);
7803 }
Hall Liu98187582018-01-22 19:15:32 -08007804 }
7805
Hall Liuf6668912018-10-31 17:05:23 -07007806 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007807 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7808 * RTT setting, will return true if the device and carrier both support RTT.
7809 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007810 */
7811 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007812 final long identity = Binder.clearCallingIdentity();
7813 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007814 boolean isRttSupported = isRttSupported(subscriptionId);
7815 boolean isUserRttSettingOn = Settings.Secure.getInt(
7816 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7817 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7818 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7819 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007820 } finally {
7821 Binder.restoreCallingIdentity(identity);
7822 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007823 }
7824
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007825 @Deprecated
7826 @Override
7827 public String getDeviceId(String callingPackage) {
7828 return getDeviceIdWithFeature(callingPackage, null);
7829 }
7830
Sanket Padawe7310cc72015-01-14 09:53:20 -08007831 /**
7832 * Returns the unique device ID of phone, for example, the IMEI for
7833 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7834 *
7835 * <p>Requires Permission:
7836 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7837 */
7838 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007839 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007840 try {
7841 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7842 } catch (SecurityException se) {
7843 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7844 throw new SecurityException("Package " + callingPackage + " does not belong to "
7845 + Binder.getCallingUid());
7846 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007847 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007848 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007849 return null;
7850 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007851 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007852 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007853 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007854 return null;
7855 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007856
7857 final long identity = Binder.clearCallingIdentity();
7858 try {
7859 return phone.getDeviceId();
7860 } finally {
7861 Binder.restoreCallingIdentity(identity);
7862 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007863 }
7864
Ping Sunc67b7c22016-03-02 19:16:45 +08007865 /**
7866 * {@hide}
7867 * Returns the IMS Registration Status on a particular subid
7868 *
7869 * @param subId
7870 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007871 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007872 Phone phone = getPhone(subId);
7873 if (phone != null) {
7874 return phone.isImsRegistered();
7875 } else {
7876 return false;
7877 }
7878 }
7879
Santos Cordon7a1885b2015-02-03 11:15:19 -08007880 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007881 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007882 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007883 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007884 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007885 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7886 }
7887 final long identity = Binder.clearCallingIdentity();
7888 try {
7889 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7890 } finally {
7891 Binder.restoreCallingIdentity(identity);
7892 }
7893 }
7894
7895 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007896 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007897 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007898 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007899 mApp,
7900 subscriptionId,
7901 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
7902 + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007903 final long identity = Binder.clearCallingIdentity();
7904 try {
7905 Phone phone = getPhone(subscriptionId);
7906 if (phone == null) {
7907 return null;
7908 }
7909 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7910 } finally {
7911 Binder.restoreCallingIdentity(identity);
7912 }
7913 }
7914
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007915 /**
7916 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007917 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007918 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007919 final long identity = Binder.clearCallingIdentity();
7920 try {
7921 Phone phone = getPhone(subId);
7922 if (phone != null) {
7923 return phone.isWifiCallingEnabled();
7924 } else {
7925 return false;
7926 }
7927 } finally {
7928 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007929 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007930 }
7931
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007932 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007933 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007934 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007935 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007936 final long identity = Binder.clearCallingIdentity();
7937 try {
7938 Phone phone = getPhone(subId);
7939 if (phone != null) {
7940 return phone.isVideoEnabled();
7941 } else {
7942 return false;
7943 }
7944 } finally {
7945 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007946 }
7947 }
7948
7949 /**
7950 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7951 * defined in {@link ImsRegistrationImplBase}.
7952 */
7953 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007954 final long identity = Binder.clearCallingIdentity();
7955 try {
7956 Phone phone = getPhone(subId);
7957 if (phone != null) {
7958 return phone.getImsRegistrationTech();
7959 } else {
7960 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7961 }
7962 } finally {
7963 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007964 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007965 }
7966
Stuart Scott8eef64f2015-04-08 15:13:54 -07007967 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007968 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007969 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007970 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7971 return;
7972 }
Kai Shif70f46f2021-03-03 13:59:46 -08007973 Phone defaultPhone = getDefaultPhone();
7974 if (defaultPhone != null) {
7975 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7976 mApp, getDefaultPhone().getSubId(), "factoryReset");
7977 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007978 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007979
Svet Ganovcc087f82015-05-12 20:35:54 -07007980 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007981 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7982 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007983 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007984 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007985 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007986 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007987 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007988 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007989 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007990 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007991 // There has been issues when Sms raw table somehow stores orphan
7992 // fragments. They lead to garbled message when new fragments come
7993 // in and combined with those stale ones. In case this happens again,
7994 // user can reset all network settings which will clean up this table.
7995 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007996 // Clean up IMS settings as well here.
7997 int slotId = getSlotIndex(subId);
7998 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7999 ImsManager.getInstance(mApp, slotId).factoryReset();
8000 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008001
Kai Shif70f46f2021-03-03 13:59:46 -08008002 if (defaultPhone == null) {
8003 return;
8004 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008005 // Erase modem config if erase modem on network setting is enabled.
8006 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8007 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8008 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008009 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008010 }
Kai Shif70f46f2021-03-03 13:59:46 -08008011
8012 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008013 } finally {
8014 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008015 }
8016 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008017
SongFerngWangfd89b102021-05-27 22:44:54 +08008018 @VisibleForTesting
8019 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8020 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8021 return;
8022 }
8023 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8024 RILConstants.PREFERRED_NETWORK_MODE);
8025 SubscriptionManager.setSubscriptionProperty(subId,
8026 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8027 "user=" + defaultNetworkType);
8028 phone.loadAllowedNetworksFromSubscriptionDatabase();
8029 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8030 defaultNetworkType, null);
8031 }
8032
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008033 private void cleanUpSmsRawTable(Context context) {
8034 ContentResolver resolver = context.getContentResolver();
8035 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8036 resolver.delete(uri, null, null);
8037 }
8038
Narayan Kamath1c496c22015-04-16 14:40:19 +01008039 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008040 public String getSimLocaleForSubscriber(int subId) {
8041 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
8042 final Phone phone = getPhone(subId);
8043 if (phone == null) {
8044 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008045 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008046 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008047 final long identity = Binder.clearCallingIdentity();
8048 try {
Jack Yu285100e2022-12-02 22:48:35 -08008049 SubscriptionInfo info;
8050 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008051 info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
Jack Yu285100e2022-12-02 22:48:35 -08008052 phone.getContext().getOpPackageName(),
8053 phone.getContext().getAttributionTag());
8054 if (info == null) {
8055 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8056 return null;
8057 }
8058 } else {
8059 info = mSubscriptionController.getActiveSubscriptionInfo(subId,
8060 phone.getContext().getOpPackageName(),
8061 phone.getContext().getAttributionTag());
8062 if (info == null) {
8063 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8064 return null;
8065 }
chen xu6291c472019-02-04 12:55:53 -08008066 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008067 // Try and fetch the locale from the carrier properties or from the SIM language
8068 // preferences (EF-PL and EF-LI)...
8069 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008070 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008071 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8072 if (localeFromDefaultSim != null) {
8073 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8074 if (DBG) log("Using locale from subId: " + subId + " locale: "
8075 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008076 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008077 } else {
8078 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008079 }
8080 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008081
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008082 // The SIM language preferences only store a language (e.g. fr = French), not an
8083 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8084 // the SIM and carrier preferences does not include a country we add the country
8085 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008086 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008087 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008088 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008089 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008090 }
8091
8092 if (DBG) log("No locale found - returning null");
8093 return null;
8094 } finally {
8095 Binder.restoreCallingIdentity(identity);
8096 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008097 }
8098
tom hsu0b59d292022-09-29 23:49:21 +08008099 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008100 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008101 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008102 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008103 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008104 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8105 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008106 Locale.forLanguageTag(localeTag).getCountry())) {
8107 return localeTag;
8108 }
8109 }
8110 return inputLocale.toLanguageTag();
8111 }
8112
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008113 /**
8114 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8115 */
8116 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu285100e2022-12-02 22:48:35 -08008117 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008118 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Jack Yu285100e2022-12-02 22:48:35 -08008119 mApp.getOpPackageName(), mApp.getAttributionTag());
8120 }
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008121 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08008122 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01008123 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008124
Gary Jian3aa9a762022-01-24 16:41:19 +08008125 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8126 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008127
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008128 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008129 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8130 * representing the state of the modem.
8131 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008132 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8133 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008134 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008135 */
8136 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008137 public void requestModemActivityInfo(ResultReceiver result) {
8138 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008139 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008140
8141 final long identity = Binder.clearCallingIdentity();
8142 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008143 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008144 } finally {
8145 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008146 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008147 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008148
Gary Jian76280a42022-12-07 16:18:33 +08008149 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008150 // less than total activity duration.
8151 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8152 if (info == null) {
8153 return false;
8154 }
8155 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008156 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008157 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8158
Hall Liu49656c02020-10-09 19:00:11 -07008159 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8160
Siddharth Rayb8114062018-06-17 15:02:38 -07008161 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008162 && (info.getSleepTimeMillis() <= activityDurationMs)
8163 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008164 }
8165
Gary Jian3aa9a762022-01-24 16:41:19 +08008166 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8167 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8168 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8169 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8170
8171 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8172 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8173 }
8174
8175 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8176 mLastModemActivityInfo.setReceiveTimeMillis(
8177 rat,
8178 freq,
8179 info.getReceiveTimeMillis(rat, freq)
8180 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8181 }
8182
8183 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8184 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8185 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8186 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8187
8188 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8189 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8190 }
8191 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8192 mLastModemActivityInfo.setReceiveTimeMillis(
8193 rat,
8194 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8195 }
8196
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008197 /**
8198 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8199 * @param info recent ModemActivityInfo
8200 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008201 private void mergeModemActivityInfo(ModemActivityInfo info) {
8202 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008203 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008204 boolean matched;
8205 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8206 matched = false;
8207 int rat = info.getSpecificInfoRat(i);
8208 int freq = info.getSpecificInfoFrequencyRange(i);
8209 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8210 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8211 //if it already exists
8212 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8213 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8214 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8215 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8216 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8217 updateLastModemActivityInfo(info, rat, freq);
8218 matched = true;
8219 }
8220 } else {
8221 updateLastModemActivityInfo(info, rat);
8222 matched = true;
8223 }
8224 }
8225 }
8226
8227 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008228 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008229 new ActivityStatsTechSpecificInfo(
8230 rat,
8231 freq,
8232 info.getTransmitTimeMillis(rat, freq),
8233 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008234 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008235 }
8236 }
8237 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8238 mLastModemActivitySpecificInfo =
8239 new ActivityStatsTechSpecificInfo[merged.size()];
8240 merged.toArray(mLastModemActivitySpecificInfo);
8241
8242 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8243 mLastModemActivityInfo.setSleepTimeMillis(
8244 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008245 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008246 mLastModemActivityInfo.setIdleTimeMillis(
8247 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008248 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008249
8250 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008251 new ModemActivityInfo(
8252 mLastModemActivityInfo.getTimestampMillis(),
8253 mLastModemActivityInfo.getSleepTimeMillis(),
8254 mLastModemActivityInfo.getIdleTimeMillis(),
8255 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008256 }
8257
8258 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8259 ActivityStatsTechSpecificInfo[] info) {
8260 int infoSize = info.length;
8261 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8262 for (int i = 0; i < infoSize; i++) {
8263 ret[i] = new ActivityStatsTechSpecificInfo(
8264 info[i].getRat(), info[i].getFrequencyRange(),
8265 info[i].getTransmitTimeMillis(),
8266 (int) info[i].getReceiveTimeMillis());
8267 }
8268 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008269 }
8270
Jack Yu85bd38a2015-11-09 11:34:32 -08008271 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008272 * Returns the service state information on specified subscription.
8273 */
8274 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008275 public ServiceState getServiceStateForSubscriber(int subId,
8276 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8277 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008278 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008279 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008280 return null;
8281 }
8282
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008283 boolean hasFinePermission = false;
8284 boolean hasCoarsePermission = false;
8285 if (!renounceFineLocationAccess) {
8286 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8287 LocationAccessPolicy.checkLocationPermission(mApp,
8288 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8289 .setCallingPackage(callingPackage)
8290 .setCallingFeatureId(callingFeatureId)
8291 .setCallingPid(Binder.getCallingPid())
8292 .setCallingUid(Binder.getCallingUid())
8293 .setMethod("getServiceStateForSubscriber")
8294 .setLogAsInfo(true)
8295 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8296 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8297 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8298 .build());
8299 hasFinePermission =
8300 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8301 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008302
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008303 if (!renounceCoarseLocationAccess) {
8304 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8305 LocationAccessPolicy.checkLocationPermission(mApp,
8306 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8307 .setCallingPackage(callingPackage)
8308 .setCallingFeatureId(callingFeatureId)
8309 .setCallingPid(Binder.getCallingPid())
8310 .setCallingUid(Binder.getCallingUid())
8311 .setMethod("getServiceStateForSubscriber")
8312 .setLogAsInfo(true)
8313 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8314 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8315 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8316 .build());
8317 hasCoarsePermission =
8318 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8319 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008320
Jack Yu479f40e2020-10-27 21:29:25 -07008321 final Phone phone = getPhone(subId);
8322 if (phone == null) {
8323 return null;
8324 }
8325
Jordan Liu0f2bc442020-11-18 16:47:37 -08008326 final long identity = Binder.clearCallingIdentity();
8327
Jack Yu479f40e2020-10-27 21:29:25 -07008328 boolean isCallingPackageDataService = phone.getDataServicePackages()
8329 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008330 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008331 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu285100e2022-12-02 22:48:35 -08008332 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008333 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
Jack Yu285100e2022-12-02 22:48:35 -08008334 .getSubscriptionInfoInternal(subId);
8335 if (subInfo == null || !subInfo.isActive()) {
8336 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8337 + "subId=" + subId);
8338 return null;
8339 }
8340 } else {
8341 if (!mSubscriptionController.isActiveSubId(subId, callingPackage,
8342 callingFeatureId)) {
8343 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8344 + "subId=" + subId);
8345 return null;
8346 }
Jordan Liuc437b192020-08-17 10:59:12 -07008347 }
8348
Hall Liuf19c44f2018-11-27 14:38:17 -08008349 ServiceState ss = phone.getServiceState();
8350
8351 // Scrub out the location info in ServiceState depending on what level of access
8352 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008353 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008354 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8355 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008356 } finally {
8357 Binder.restoreCallingIdentity(identity);
8358 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008359 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008360
8361 /**
8362 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8363 *
8364 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8365 * voicemail ringtone.
8366 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8367 * PhoneAccount.
8368 */
8369 @Override
8370 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008371 final long identity = Binder.clearCallingIdentity();
8372 try {
8373 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8374 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008375 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008376 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008377
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008378 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8379 } finally {
8380 Binder.restoreCallingIdentity(identity);
8381 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008382 }
8383
8384 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008385 * Sets the per-account voicemail ringtone.
8386 *
8387 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8388 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8389 *
8390 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8391 * voicemail ringtone.
8392 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8393 * PhoneAccount.
8394 */
8395 @Override
8396 public void setVoicemailRingtoneUri(String callingPackage,
8397 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008398 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008399 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008400 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8401 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008402 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8403 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8404 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008405 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008406
8407 final long identity = Binder.clearCallingIdentity();
8408 try {
8409 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8410 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008411 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008412 }
8413 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8414 } finally {
8415 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008416 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008417 }
8418
8419 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008420 * Returns whether vibration is set for voicemail notification in Phone settings.
8421 *
8422 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8423 * voicemail vibration setting.
8424 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8425 */
8426 @Override
8427 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008428 final long identity = Binder.clearCallingIdentity();
8429 try {
8430 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8431 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008432 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008433 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008434
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008435 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8436 } finally {
8437 Binder.restoreCallingIdentity(identity);
8438 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008439 }
8440
Youhan Wange64578a2016-05-02 15:32:42 -07008441 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008442 * Sets the per-account voicemail vibration.
8443 *
8444 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8445 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8446 *
8447 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8448 * voicemail vibration setting.
8449 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8450 * specific PhoneAccount.
8451 */
8452 @Override
8453 public void setVoicemailVibrationEnabled(String callingPackage,
8454 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008455 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008456 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008457 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8458 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008459 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8460 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8461 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008462 }
8463
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008464 final long identity = Binder.clearCallingIdentity();
8465 try {
8466 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8467 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008468 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008469 }
8470 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8471 } finally {
8472 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008473 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008474 }
8475
8476 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008477 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8478 *
8479 * @throws SecurityException if the caller does not have the required permission
8480 */
arunvoddud7401012022-12-15 16:08:12 +00008481 @VisibleForTesting
8482 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008483 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008484 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008485 }
8486
8487 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008488 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8489 * permission.
8490 *
8491 * @throws SecurityException if the caller does not have the required permission
8492 */
8493 private void enforceSendSmsPermission() {
8494 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8495 }
8496
8497 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00008498 * Make sure either called from same process as self (phone) or IPC caller has interact across
8499 * users permission.
8500 *
8501 * @throws SecurityException if the caller does not have the required permission
8502 */
8503 private void enforceInteractAcrossUsersPermission(String message) {
8504 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
8505 }
8506
8507 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008508 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008509 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008510 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008511 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008512 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008513 final long identity = Binder.clearCallingIdentity();
8514 try {
8515 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008516 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008517 if (componentName == null) {
8518 throw new SecurityException(
8519 "Caller not current active visual voicemail package[null]");
8520 }
8521 String vvmPackage = componentName.getPackageName();
8522 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008523 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008524 }
8525 } finally {
8526 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008527 }
8528 }
8529
8530 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008531 * Return the application ID for the app type.
8532 *
8533 * @param subId the subscription ID that this request applies to.
8534 * @param appType the uicc app type.
8535 * @return Application ID for specificied app type, or null if no uicc.
8536 */
8537 @Override
8538 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008539 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008540 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008541
8542 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008543 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008544 if (phone == null) {
8545 return null;
8546 }
8547 String aid = null;
8548 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008549 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008550 .getApplicationByType(appType).getAid();
8551 } catch (Exception e) {
8552 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8553 }
8554 return aid;
8555 } finally {
8556 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008557 }
Youhan Wange64578a2016-05-02 15:32:42 -07008558 }
8559
Youhan Wang4001d252016-05-11 10:29:41 -07008560 /**
8561 * Return the Electronic Serial Number.
8562 *
8563 * @param subId the subscription ID that this request applies to.
8564 * @return ESN or null if error.
8565 */
8566 @Override
8567 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008568 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008569 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008570
8571 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008572 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008573 if (phone == null) {
8574 return null;
8575 }
8576 String esn = null;
8577 try {
8578 esn = phone.getEsn();
8579 } catch (Exception e) {
8580 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8581 }
8582 return esn;
8583 } finally {
8584 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008585 }
Youhan Wang4001d252016-05-11 10:29:41 -07008586 }
8587
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008588 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008589 * Return the Preferred Roaming List Version.
8590 *
8591 * @param subId the subscription ID that this request applies to.
8592 * @return PRLVersion or null if error.
8593 */
8594 @Override
8595 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008596 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008597 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008598
8599 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008600 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008601 if (phone == null) {
8602 return null;
8603 }
8604 String cdmaPrlVersion = null;
8605 try {
8606 cdmaPrlVersion = phone.getCdmaPrlVersion();
8607 } catch (Exception e) {
8608 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8609 }
8610 return cdmaPrlVersion;
8611 } finally {
8612 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008613 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008614 }
8615
8616 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008617 * Get snapshot of Telephony histograms
8618 * @return List of Telephony histograms
8619 * @hide
8620 */
8621 @Override
8622 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008623 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8624 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008625
8626 final long identity = Binder.clearCallingIdentity();
8627 try {
8628 return RIL.getTelephonyRILTimingHistograms();
8629 } finally {
8630 Binder.restoreCallingIdentity(identity);
8631 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008632 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008633
8634 /**
8635 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008636 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8637 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008638 * Require system privileges. In the future we may add this to carrier APIs.
8639 *
Michele Berionne482f8202018-11-27 18:57:59 -08008640 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008641 */
8642 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008643 @TelephonyManager.SetCarrierRestrictionResult
8644 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008645 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008646 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008647
Michele Berionne482f8202018-11-27 18:57:59 -08008648 if (carrierRestrictionRules == null) {
8649 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008650 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008651
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008652 final long identity = Binder.clearCallingIdentity();
8653 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008654 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008655 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008656 } finally {
8657 Binder.restoreCallingIdentity(identity);
8658 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008659 }
8660
8661 /**
8662 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008663 * Get the allowed carrier list and the excluded carrier list, including the priority between
8664 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008665 * Require system privileges. In the future we may add this to carrier APIs.
8666 *
Michele Berionne482f8202018-11-27 18:57:59 -08008667 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008668 */
8669 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008670 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008671 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008672 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008673
8674 final long identity = Binder.clearCallingIdentity();
8675 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008676 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8677 if (response instanceof CarrierRestrictionRules) {
8678 return (CarrierRestrictionRules) response;
8679 }
8680 // Response is an Exception of some kind,
8681 // which is signalled to the user as a NULL retval
8682 return null;
8683 } catch (Exception e) {
8684 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8685 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008686 } finally {
8687 Binder.restoreCallingIdentity(identity);
8688 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008689 }
8690
fionaxu59545b42016-05-25 15:53:37 -07008691 /**
arunvoddud7401012022-12-15 16:08:12 +00008692 * Fetches the carrier restriction status of the device and sends the status to the caller
8693 * through the callback.
8694 *
8695 * @param callback The callback that will be used to send the result.
8696 * @throws SecurityException if the caller does not have the required permission/privileges or
8697 * the caller is not allowlisted.
8698 */
8699 @Override
8700 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
8701 enforceReadPermission("getCarrierRestrictionStatus");
8702 int carrierId = validateCallerAndGetCarrierId(packageName);
8703 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
8704 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
8705 throw new SecurityException("Not an authorized caller");
8706 }
8707 final long identity = Binder.clearCallingIdentity();
8708 try {
8709 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
8710 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
8711 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
8712 } finally {
8713 Binder.restoreCallingIdentity(identity);
8714 }
8715 }
8716
8717 @VisibleForTesting
8718 public int validateCallerAndGetCarrierId(String packageName) {
8719 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
8720 return allowListInfo.validateCallerAndGetCarrierId(packageName);
8721 }
8722
8723 /**
fionaxu59545b42016-05-25 15:53:37 -07008724 * Action set from carrier signalling broadcast receivers to enable/disable radio
8725 * @param subId the subscription ID that this action applies to.
8726 * @param enabled control enable or disable radio.
8727 * {@hide}
8728 */
8729 @Override
8730 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8731 enforceModifyPermission();
8732 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008733
8734 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008735 if (phone == null) {
8736 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8737 return;
8738 }
8739 try {
8740 phone.carrierActionSetRadioEnabled(enabled);
8741 } catch (Exception e) {
8742 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008743 } finally {
8744 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008745 }
8746 }
8747
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008748 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008749 * Enable or disable Voice over NR (VoNR)
8750 * @param subId the subscription ID that this action applies to.
8751 * @param enabled enable or disable VoNR.
8752 * @return operation result.
8753 */
8754 @Override
8755 public int setVoNrEnabled(int subId, boolean enabled) {
8756 enforceModifyPermission();
8757 final Phone phone = getPhone(subId);
8758
8759 final long identity = Binder.clearCallingIdentity();
8760 if (phone == null) {
8761 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8762 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8763 }
8764
8765 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8766 try {
8767 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8768 workSource);
8769 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008770
8771 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8772 if (DBG) {
8773 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8774 }
8775 SubscriptionManager.setSubscriptionProperty(
8776 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8777 (enabled ? "1" : "0"));
8778 }
8779
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008780 return result;
8781 } finally {
8782 Binder.restoreCallingIdentity(identity);
8783 }
8784 }
8785
8786 /**
8787 * Is voice over NR enabled
8788 * @return true if VoNR is enabled else false
8789 */
8790 @Override
8791 public boolean isVoNrEnabled(int subId) {
8792 enforceReadPrivilegedPermission("isVoNrEnabled");
8793 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8794 final long identity = Binder.clearCallingIdentity();
8795 try {
8796 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8797 null, subId, workSource);
8798 if (DBG) log("isVoNrEnabled: " + isEnabled);
8799 return isEnabled;
8800 } finally {
8801 Binder.restoreCallingIdentity(identity);
8802 }
8803 }
8804
8805 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008806 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8807 * network status based on which carrier apps could apply actions accordingly,
8808 * enable/disable default url handler for example.
8809 *
8810 * @param subId the subscription ID that this action applies to.
8811 * @param report control start/stop reporting the default network status.
8812 * {@hide}
8813 */
8814 @Override
8815 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8816 enforceModifyPermission();
8817 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008818
8819 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008820 if (phone == null) {
8821 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8822 return;
8823 }
8824 try {
8825 phone.carrierActionReportDefaultNetworkStatus(report);
8826 } catch (Exception e) {
8827 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008828 } finally {
8829 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008830 }
8831 }
8832
8833 /**
fionaxud9622282017-07-17 17:51:30 -07008834 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8835 * @param subId the subscription ID that this action applies to.
8836 * {@hide}
8837 */
8838 @Override
8839 public void carrierActionResetAll(int subId) {
8840 enforceModifyPermission();
8841 final Phone phone = getPhone(subId);
8842 if (phone == null) {
8843 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8844 return;
8845 }
8846 try {
8847 phone.carrierActionResetAll();
8848 } catch (Exception e) {
8849 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8850 }
8851 }
8852
8853 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008854 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8855 * bug report is being generated.
8856 */
8857 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008858 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008859 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8860 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008861 writer.println("Permission Denial: can't dump Phone from pid="
8862 + Binder.getCallingPid()
8863 + ", uid=" + Binder.getCallingUid()
8864 + "without permission "
8865 + android.Manifest.permission.DUMP);
8866 return;
8867 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008868 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008869 }
Jack Yueb89b242016-06-22 13:27:47 -07008870
Brad Ebingerdac2f002018-04-03 15:17:52 -07008871 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008872 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8873 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8874 @NonNull String[] args) {
8875 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8876 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008877 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008878 }
8879
Jack Yueb89b242016-06-22 13:27:47 -07008880 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008881 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008882 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008883 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008884 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008885 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008886 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008887 */
8888 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008889 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008890 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008891 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8892 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8893 try {
8894 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008895 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008896 } catch (SecurityException se) {
8897 enforceModifyPermission();
8898 }
8899 } else {
8900 enforceModifyPermission();
8901 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008902
8903 final long identity = Binder.clearCallingIdentity();
8904 try {
8905 Phone phone = getPhone(subId);
8906 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008907 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8908 phone.carrierActionSetMeteredApnsEnabled(enabled);
8909 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008910 phone.getDataSettingsManager().setDataEnabled(
8911 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008912 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008913 }
8914 } finally {
8915 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008916 }
8917 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008918
8919 /**
8920 * Get Client request stats
8921 * @return List of Client Request Stats
8922 * @hide
8923 */
8924 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008925 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8926 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008927 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008928 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008929 return null;
8930 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008931 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008932
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008933 final long identity = Binder.clearCallingIdentity();
8934 try {
8935 if (phone != null) {
8936 return phone.getClientRequestStats();
8937 }
8938
8939 return null;
8940 } finally {
8941 Binder.restoreCallingIdentity(identity);
8942 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008943 }
8944
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008945 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008946 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008947 if (uid == Process.ROOT_UID && packageName == null) {
8948 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8949 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8950 // exception. ROOT_UID seems not to have a valid package name returned by
8951 // PackageManager, so just fake it here to avoid issues when running telephony shell
8952 // commands that plumb through the RIL as root, like so:
8953 // $ adb root
8954 // $ adb shell cmd phone ...
8955 packageName = "root";
8956 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008957 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008958 }
Jack Yueb4124c2017-02-16 15:32:43 -08008959
8960 /**
Grace Chen70990072017-03-24 17:21:30 -07008961 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008962 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008963 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008964 * @param state State of SIM (power down, power up, pass through)
8965 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8966 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8967 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008968 *
8969 **/
8970 @Override
Grace Chen70990072017-03-24 17:21:30 -07008971 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008972 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008973 Phone phone = PhoneFactory.getPhone(slotIndex);
8974
vagdeviaf9a5b92018-08-15 16:01:53 -07008975 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8976
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008977 final long identity = Binder.clearCallingIdentity();
8978 try {
8979 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008980 phone.setSimPowerState(state, null, workSource);
8981 }
8982 } finally {
8983 Binder.restoreCallingIdentity(identity);
8984 }
8985 }
8986
8987 /**
8988 * Set SIM card power state.
8989 *
8990 * @param slotIndex SIM slot id.
8991 * @param state State of SIM (power down, power up, pass through)
8992 * @param callback callback to trigger after success or failure
8993 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8994 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8995 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8996 *
8997 **/
8998 @Override
8999 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9000 IIntegerConsumer callback) {
9001 enforceModifyPermission();
9002 Phone phone = PhoneFactory.getPhone(slotIndex);
9003
9004 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9005
9006 final long identity = Binder.clearCallingIdentity();
9007 try {
9008 if (phone != null) {
9009 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9010 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009011 }
9012 } finally {
9013 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009014 }
9015 }
Shuo Qiandd210312017-04-12 22:11:33 +00009016
Tyler Gunn65d45c22017-06-05 11:22:26 -07009017 private boolean isUssdApiAllowed(int subId) {
9018 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009019 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009020 if (configManager == null) {
9021 return false;
9022 }
9023 PersistableBundle pb = configManager.getConfigForSubId(subId);
9024 if (pb == null) {
9025 return false;
9026 }
9027 return pb.getBoolean(
9028 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9029 }
9030
Shuo Qiandd210312017-04-12 22:11:33 +00009031 /**
9032 * Check if phone is in emergency callback mode
9033 * @return true if phone is in emergency callback mode
9034 * @param subId sub id
9035 */
goneil9c5f4872017-12-05 14:07:56 -08009036 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009037 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009038 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00009039 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009040
9041 final long identity = Binder.clearCallingIdentity();
9042 try {
9043 if (phone != null) {
9044 return phone.isInEcm();
9045 } else {
9046 return false;
9047 }
9048 } finally {
9049 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009050 }
9051 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009052
9053 /**
9054 * Get the current signal strength information for the given subscription.
9055 * Because this information is not updated when the device is in a low power state
9056 * it should not be relied-upon to be current.
9057 * @param subId Subscription index
9058 * @return the most recent cached signal strength info from the modem
9059 */
9060 @Override
9061 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009062 final long identity = Binder.clearCallingIdentity();
9063 try {
9064 Phone p = getPhone(subId);
9065 if (p == null) {
9066 return null;
9067 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009068
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009069 return p.getSignalStrength();
9070 } finally {
9071 Binder.restoreCallingIdentity(identity);
9072 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009073 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009074
Pengquan Meng77b7f132018-08-22 14:49:57 -07009075 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009076 * Get the current modem radio state for the given slot.
9077 * @param slotIndex slot index.
9078 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009079 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009080 * @return the current radio power state from the modem
9081 */
9082 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009083 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009084 Phone phone = PhoneFactory.getPhone(slotIndex);
9085 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009086 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9087 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009088 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9089 }
9090
9091 final long identity = Binder.clearCallingIdentity();
9092 try {
9093 return phone.getRadioPowerState();
9094 } finally {
9095 Binder.restoreCallingIdentity(identity);
9096 }
9097 }
9098 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9099 }
9100
9101 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009102 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9103 *
9104 * <p>Requires one of the following permissions:
9105 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009106 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009107 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9108 * privileges.
9109 *
9110 * @param subId subscription id
9111 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9112 * {@code false}.
9113 */
9114 @Override
9115 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009116 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009117 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009118 try {
9119 mApp.enforceCallingOrSelfPermission(
9120 android.Manifest.permission.ACCESS_NETWORK_STATE,
9121 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009122 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009123 mApp.enforceCallingOrSelfPermission(
9124 permission.READ_BASIC_PHONE_STATE, functionName);
9125 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009126 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009127 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009128 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009129 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009130
Pengquan Menga1bb6272018-09-06 09:59:22 -07009131 boolean isEnabled = false;
9132 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009133 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009134 Phone phone = getPhone(subId);
9135 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009136 } finally {
9137 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009138 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009139 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009140 }
9141
9142
9143 /**
9144 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9145 *
9146 * <p> Requires permission:
9147 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9148 * privileges.
9149 *
9150 * @param subId subscription id
9151 * @param isEnabled {@code true} means enable, {@code false} means disable.
9152 */
9153 @Override
9154 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009155 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9156 mApp, subId, "setDataRoamingEnabled");
9157
Pengquan Menga1bb6272018-09-06 09:59:22 -07009158 final long identity = Binder.clearCallingIdentity();
9159 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009160 Phone phone = getPhone(subId);
9161 if (phone != null) {
9162 phone.setDataRoamingEnabled(isEnabled);
9163 }
9164 } finally {
9165 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009166 }
9167 }
9168
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009169 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009170 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009171 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009172 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009173 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009174
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009175 boolean isAllowed = true;
9176 final long identity = Binder.clearCallingIdentity();
9177 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009178 Phone phone = getPhone(subId);
9179 if (phone != null) {
9180 isAllowed = phone.isCspPlmnEnabled();
9181 }
9182 } finally {
9183 Binder.restoreCallingIdentity(identity);
9184 }
9185 return isAllowed;
9186 }
9187
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009188 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9189 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009190 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009191 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009192 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009193 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9194 if (phone == null) {
9195 return false;
9196 }
9197 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9198 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9199 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009200 }
9201
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009202 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009203 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009204 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009205 mApp.getSystemService(AppOpsManager.class)
9206 .checkPackage(Binder.getCallingUid(), callingPackage);
9207
Jordan Liu1e142fc2019-04-22 15:10:43 -07009208 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009209 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009210 try {
9211 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009212 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009213 } catch (SecurityException e) {
9214 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9215 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009216 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009217 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009218 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009219 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009220 }
sandeepjsb6c87872021-09-27 15:34:44 +00009221 // checking compatibility, if calling app's target SDK is T and beyond.
9222 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9223 Binder.getCallingUid())) {
9224 isIccIdAccessRestricted = true;
9225 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009226 final long identity = Binder.clearCallingIdentity();
9227 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009228 UiccController uiccController = UiccController.getInstance();
9229 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009230 if (hasReadPermission) {
9231 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009232 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009233
9234 // Remove private info if the caller doesn't have access
9235 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9236 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009237 //setting the value after compatibility check
9238 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009239 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9240 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009241 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009242 if (card == null) {
9243 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009244 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009245 continue;
9246 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009247 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9248 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009249 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009250 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009251 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009252 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9253 for (UiccPortInfo portInfo : portInfos) {
9254 UiccPort port = uiccController.getUiccPortForSlot(
9255 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9256 if (port == null) {
9257 // assume no access if port is null
9258 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9259 continue;
9260 }
9261 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9262 uiccPortInfos.add(portInfo);
9263 } else {
9264 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9265 }
9266 }
9267 filteredInfos.add(new UiccCardInfo(
9268 cardInfo.isEuicc(),
9269 cardInfo.getCardId(),
9270 null,
9271 cardInfo.getPhysicalSlotIndex(),
9272 cardInfo.isRemovable(),
9273 cardInfo.isMultipleEnabledProfilesSupported(),
9274 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009275 }
9276 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009277 } finally {
9278 Binder.restoreCallingIdentity(identity);
9279 }
9280 }
9281
sandeepjsb6c87872021-09-27 15:34:44 +00009282 /**
9283 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9284 * generally private and require carrier privileges to view.
9285 *
9286 * @hide
9287 */
9288 @NonNull
9289 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9290 List<UiccPortInfo> portinfo = new ArrayList<>();
9291 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9292 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9293 }
9294 return new UiccCardInfo(
9295 cardInfo.isEuicc(),
9296 cardInfo.getCardId(),
9297 null,
9298 cardInfo.getPhysicalSlotIndex(),
9299 cardInfo.isRemovable(),
9300 cardInfo.isMultipleEnabledProfilesSupported(),
9301 portinfo
9302 );
9303 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009304
sandeepjsb6c87872021-09-27 15:34:44 +00009305 /**
9306 * @hide
9307 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9308 * These values are generally private and require carrier privileges to view.
9309 */
9310 @NonNull
9311 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9312 return new UiccPortInfo(
9313 UiccPortInfo.ICCID_REDACTED,
9314 portInfo.getPortIndex(),
9315 portInfo.getLogicalSlotIndex(),
9316 portInfo.isActive()
9317 );
9318 }
9319 @Override
9320 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009321 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009322 mApp.getSystemService(AppOpsManager.class)
9323 .checkPackage(Binder.getCallingUid(), callingPackage);
9324
sandeepjsb6c87872021-09-27 15:34:44 +00009325 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009326
Aman Guptaf3c90b32022-03-17 04:54:16 +00009327 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9328 // we are reading iccId which is PII data.
9329 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009330
9331 // checking compatibility, if calling app's target SDK is T and beyond.
9332 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9333 Binder.getCallingUid())) {
9334 isLogicalSlotAccessRestricted = true;
9335 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009336 final long identity = Binder.clearCallingIdentity();
9337 try {
9338 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009339 if (slots == null || slots.length == 0) {
9340 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009341 return null;
9342 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009343 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9344 for (int i = 0; i < slots.length; i++) {
9345 UiccSlot slot = slots[i];
9346 if (slot == null) {
9347 continue;
9348 }
9349
Jordan Liu7be7e652019-05-06 18:55:02 +00009350 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009351 UiccCard card = slot.getUiccCard();
9352 if (card != null) {
9353 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009354 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009355 cardId = slot.getEid();
9356 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009357 // If cardId is null, use iccId of default port as cardId.
9358 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009359 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009360 }
9361
Jordan Liu857451f2019-05-09 16:35:35 -07009362 if (cardId != null) {
9363 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9364 // if cardId is an EID, it's all digits so this is fine
9365 cardId = IccUtils.stripTrailingFs(cardId);
9366 }
9367
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009368 int cardState = 0;
9369 switch (slot.getCardState()) {
9370 case CARDSTATE_ABSENT:
9371 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9372 break;
9373 case CARDSTATE_PRESENT:
9374 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9375 break;
9376 case CARDSTATE_ERROR:
9377 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9378 break;
9379 case CARDSTATE_RESTRICTED:
9380 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9381 break;
9382 default:
9383 break;
9384
9385 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009386 List<UiccPortInfo> portInfos = new ArrayList<>();
9387 int[] portIndexes = slot.getPortList();
9388 for (int portIdx : portIndexes) {
9389 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009390 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009391 portInfos.add(new UiccPortInfo(iccId, portIdx,
9392 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009393 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009394 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009395 slot.isEuicc(),
9396 cardId,
9397 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009398 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009399 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009400 //setting the value after compatibility check
9401 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009402 }
9403 return infos;
9404 } finally {
9405 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009406 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009407 }
9408
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009409 /* Returns null if doesn't have read permission or carrier privilege access. */
9410 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9411 boolean hasReadPermission) {
9412 String iccId = slot.getIccId(portIndex);
9413 if (hasReadPermission) { // if has read permission
9414 return iccId;
9415 } else {
9416 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9417 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9418 // if no read permission, checking carrier privilege access
9419 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9420 return iccId;
9421 }
9422 }
9423 }
9424 // No read permission or carrier privilege access.
9425 return UiccPortInfo.ICCID_REDACTED;
9426 }
9427
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009428 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009429 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009430 public boolean switchSlots(int[] physicalSlots) {
9431 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009432
9433 final long identity = Binder.clearCallingIdentity();
9434 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009435 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9436 for (int i = 0; i < physicalSlots.length; i++) {
9437 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9438 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9439 physicalSlots[i], i));
9440 }
9441 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009442 } finally {
9443 Binder.restoreCallingIdentity(identity);
9444 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009445 }
Jack Yu4c988042018-02-27 15:30:01 -08009446
9447 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009448 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9449 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9450 enforceModifyPermission();
9451
9452 final long identity = Binder.clearCallingIdentity();
9453 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009454 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009455 } finally {
9456 Binder.restoreCallingIdentity(identity);
9457 }
9458 }
9459
9460 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009461 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009462 final long identity = Binder.clearCallingIdentity();
9463 try {
9464 return UiccController.getInstance().getCardIdForDefaultEuicc();
9465 } finally {
9466 Binder.restoreCallingIdentity(identity);
9467 }
9468 }
9469
Pengquan Meng85728fb2018-03-12 16:31:21 -07009470 /**
goneil47ffb6e2018-04-06 15:40:58 -07009471 * A test API to reload the UICC profile.
9472 *
9473 * <p>Requires that the calling app has permission
9474 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9475 * @hide
9476 */
9477 @Override
9478 public void refreshUiccProfile(int subId) {
9479 enforceModifyPermission();
9480
9481 final long identity = Binder.clearCallingIdentity();
9482 try {
9483 Phone phone = getPhone(subId);
9484 if (phone == null) {
9485 return;
9486 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009487 UiccPort uiccPort = phone.getUiccPort();
9488 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009489 return;
9490 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009491 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009492 if (uiccProfile == null) {
9493 return;
9494 }
9495 uiccProfile.refresh();
9496 } finally {
9497 Binder.restoreCallingIdentity(identity);
9498 }
9499 }
9500
9501 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009502 * Returns false if the mobile data is disabled by default, otherwise return true.
9503 */
9504 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009505 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009506 }
9507
9508 /**
9509 * Returns true if the data roaming is enabled by default, i.e the system property
9510 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9511 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9512 */
9513 private boolean getDefaultDataRoamingEnabled(int subId) {
9514 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009515 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009516 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009517 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9518 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9519 return isDataRoamingEnabled;
9520 }
9521
9522 /**
9523 * Returns the default network type for the given {@code subId}, if the default network type is
9524 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9525 */
9526 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009527 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -08009528 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +09009529 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9530 return list.get(phoneId);
9531 }
9532 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009533 }
fionaxua13278b2018-03-21 00:08:13 -07009534
9535 @Override
9536 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009537 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009538 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009539
9540 final long identity = Binder.clearCallingIdentity();
9541 try {
9542 final Phone phone = getPhone(subId);
9543 if (phone == null) {
9544 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9545 return;
9546 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009547 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9548 if (cpt != null) {
9549 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9550 }
9551 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009552 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9553 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009554 if (carrierPrivilegeRules == null) {
9555 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9556 } else {
9557 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9558 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009559 } finally {
9560 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009561 }
fionaxua13278b2018-03-21 00:08:13 -07009562 }
9563
9564 @Override
Benedict Wong66477622023-02-03 23:30:57 +00009565 public void setCarrierServicePackageOverride(
9566 int subId, String carrierServicePackage, String callingPackage) {
9567 TelephonyPermissions.enforceShellOnly(
9568 Binder.getCallingUid(), "setCarrierServicePackageOverride");
9569
9570 // Verify that the callingPackage belongs to the calling UID
9571 mApp.getSystemService(AppOpsManager.class)
9572 .checkPackage(Binder.getCallingUid(), callingPackage);
9573
9574 final long identity = Binder.clearCallingIdentity();
9575 try {
9576 final Phone phone = getPhone(subId);
9577 if (phone == null || phone.getSubId() != subId) {
9578 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
9579 throw new IllegalArgumentException("No phone for subid");
9580 }
9581 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9582 if (cpt == null) {
9583 loge("setCarrierServicePackageOverride failed with no CPT for phone");
9584 throw new IllegalStateException("No CPT for phone");
9585 }
9586 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
9587 } finally {
9588 Binder.restoreCallingIdentity(identity);
9589 }
9590 }
9591
9592 @Override
fionaxua13278b2018-03-21 00:08:13 -07009593 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009594 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009595
9596 final long identity = Binder.clearCallingIdentity();
9597 try {
9598 final Phone phone = getPhone(subId);
9599 if (phone == null) {
9600 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9601 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9602 }
9603 return phone.getCarrierIdListVersion();
9604 } finally {
9605 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009606 }
fionaxua13278b2018-03-21 00:08:13 -07009607 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009608
9609 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009610 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9611 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009612 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009613 mApp, subId, callingPackage, callingFeatureId,
9614 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009615 return -1;
9616 }
9617
9618 final long identity = Binder.clearCallingIdentity();
9619 try {
9620 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9621 } finally {
9622 Binder.restoreCallingIdentity(identity);
9623 }
9624 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009625
9626 @Override
9627 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009628 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009629 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009630 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -07009631
9632 final long identity = Binder.clearCallingIdentity();
9633 try {
9634 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9635 } finally {
9636 Binder.restoreCallingIdentity(identity);
9637 }
9638 }
9639
9640 @Override
9641 public boolean setCdmaRoamingMode(int subId, int mode) {
9642 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9643 mApp, subId, "setCdmaRoamingMode");
9644
9645 final long identity = Binder.clearCallingIdentity();
9646 try {
9647 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9648 } finally {
9649 Binder.restoreCallingIdentity(identity);
9650 }
9651 }
9652
9653 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009654 public int getCdmaSubscriptionMode(int subId) {
9655 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009656 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009657 mApp, subId, "getCdmaSubscriptionMode");
9658
9659 final long identity = Binder.clearCallingIdentity();
9660 try {
9661 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9662 } finally {
9663 Binder.restoreCallingIdentity(identity);
9664 }
9665 }
9666
9667 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009668 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9669 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9670 mApp, subId, "setCdmaSubscriptionMode");
9671
9672 final long identity = Binder.clearCallingIdentity();
9673 try {
9674 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9675 } finally {
9676 Binder.restoreCallingIdentity(identity);
9677 }
9678 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009679
sqianc5eccab2018-10-19 18:46:41 -07009680 @Override
sqian8c685422019-02-22 15:55:18 -08009681 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009682 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009683 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009684 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9685 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009686 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9687 }
9688 final long identity = Binder.clearCallingIdentity();
9689 try {
sqian854d44b2018-12-12 16:48:18 -08009690 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9691 for (Phone phone: PhoneFactory.getPhones()) {
9692 if (phone.getEmergencyNumberTracker() != null
9693 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9694 emergencyNumberListInternal.put(
9695 phone.getSubId(),
9696 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9697 }
sqian11b7a0e2018-12-05 18:48:28 -08009698 }
sqian854d44b2018-12-12 16:48:18 -08009699 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009700 } finally {
9701 Binder.restoreCallingIdentity(identity);
9702 }
sqianc5eccab2018-10-19 18:46:41 -07009703 }
9704
9705 @Override
sqian8c685422019-02-22 15:55:18 -08009706 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009707 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009708 if (!exactMatch) {
9709 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009710 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009711 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009712 }
9713 final long identity = Binder.clearCallingIdentity();
9714 try {
sqian854d44b2018-12-12 16:48:18 -08009715 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009716 //Note: we ignore passed in param exactMatch. We can remove it once
9717 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009718 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009719 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009720 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009721 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009722 }
sqian11b7a0e2018-12-05 18:48:28 -08009723 }
9724 return false;
9725 } finally {
9726 Binder.restoreCallingIdentity(identity);
9727 }
9728 }
9729
sqianf4ca7ed2019-01-15 18:32:07 -08009730 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009731 * Start emergency callback mode for GsmCdmaPhone for testing.
9732 */
9733 @Override
9734 public void startEmergencyCallbackMode() {
9735 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9736 "startEmergencyCallbackMode");
9737 enforceModifyPermission();
9738 final long identity = Binder.clearCallingIdentity();
9739 try {
9740 for (Phone phone : PhoneFactory.getPhones()) {
9741 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9742 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9743 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9744 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9745 gsmCdmaPhone.obtainMessage(
9746 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9747 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9748 }
9749 }
9750 } finally {
9751 Binder.restoreCallingIdentity(identity);
9752 }
9753 }
9754
9755 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009756 * Update emergency number list for test mode.
9757 */
9758 @Override
9759 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9760 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9761 "updateEmergencyNumberListTestMode");
9762
9763 final long identity = Binder.clearCallingIdentity();
9764 try {
9765 for (Phone phone: PhoneFactory.getPhones()) {
9766 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9767 if (tracker != null) {
9768 tracker.executeEmergencyNumberTestModeCommand(action, num);
9769 }
9770 }
9771 } finally {
9772 Binder.restoreCallingIdentity(identity);
9773 }
9774 }
9775
9776 /**
9777 * Get the full emergency number list for test mode.
9778 */
9779 @Override
9780 public List<String> getEmergencyNumberListTestMode() {
9781 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9782 "getEmergencyNumberListTestMode");
9783
9784 final long identity = Binder.clearCallingIdentity();
9785 try {
9786 Set<String> emergencyNumbers = new HashSet<>();
9787 for (Phone phone: PhoneFactory.getPhones()) {
9788 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9789 if (tracker != null) {
9790 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9791 emergencyNumbers.add(num.getNumber());
9792 }
9793 }
9794 }
9795 return new ArrayList<>(emergencyNumbers);
9796 } finally {
9797 Binder.restoreCallingIdentity(identity);
9798 }
9799 }
9800
chen xud6b45bd2018-10-30 22:27:10 -07009801 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009802 public int getEmergencyNumberDbVersion(int subId) {
9803 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9804
9805 final long identity = Binder.clearCallingIdentity();
9806 try {
9807 final Phone phone = getPhone(subId);
9808 if (phone == null) {
9809 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9810 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9811 }
9812 return phone.getEmergencyNumberDbVersion();
9813 } finally {
9814 Binder.restoreCallingIdentity(identity);
9815 }
9816 }
9817
9818 @Override
9819 public void notifyOtaEmergencyNumberDbInstalled() {
9820 enforceModifyPermission();
9821
9822 final long identity = Binder.clearCallingIdentity();
9823 try {
9824 for (Phone phone: PhoneFactory.getPhones()) {
9825 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9826 if (tracker != null) {
9827 tracker.updateOtaEmergencyNumberDatabase();
9828 }
9829 }
9830 } finally {
9831 Binder.restoreCallingIdentity(identity);
9832 }
9833 }
9834
9835 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009836 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009837 enforceActiveEmergencySessionPermission();
9838
9839 final long identity = Binder.clearCallingIdentity();
9840 try {
9841 for (Phone phone: PhoneFactory.getPhones()) {
9842 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9843 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009844 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9845 }
9846 }
9847 } finally {
9848 Binder.restoreCallingIdentity(identity);
9849 }
9850 }
9851
9852 @Override
9853 public void resetOtaEmergencyNumberDbFilePath() {
9854 enforceActiveEmergencySessionPermission();
9855
9856 final long identity = Binder.clearCallingIdentity();
9857 try {
9858 for (Phone phone: PhoneFactory.getPhones()) {
9859 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9860 if (tracker != null) {
9861 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009862 }
9863 }
9864 } finally {
9865 Binder.restoreCallingIdentity(identity);
9866 }
9867 }
9868
9869 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009870 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9871 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9872 Phone phone = getPhone(subId);
9873 if (phone == null) {
9874 return null;
9875 }
9876 final long identity = Binder.clearCallingIdentity();
9877 try {
9878 UiccProfile profile = UiccController.getInstance()
9879 .getUiccProfileForPhone(phone.getPhoneId());
9880 if (profile != null) {
9881 return profile.getCertsFromCarrierPrivilegeAccessRules();
9882 }
9883 } finally {
9884 Binder.restoreCallingIdentity(identity);
9885 }
9886 return null;
9887 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009888
9889 /**
9890 * Enable or disable a modem stack.
9891 */
9892 @Override
9893 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9894 enforceModifyPermission();
9895
9896 final long identity = Binder.clearCallingIdentity();
9897 try {
9898 Phone phone = PhoneFactory.getPhone(slotIndex);
9899 if (phone == null) {
9900 return false;
9901 } else {
9902 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9903 }
9904 } finally {
9905 Binder.restoreCallingIdentity(identity);
9906 }
9907 }
Michelecea4cf22018-12-21 15:00:11 -08009908
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009909 /**
9910 * Whether a modem stack is enabled or not.
9911 */
9912 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009913 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9914 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009915 Phone phone = PhoneFactory.getPhone(slotIndex);
9916 if (phone == null) return false;
9917
9918 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009919 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9920 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009921 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9922 }
9923
9924 final long identity = Binder.clearCallingIdentity();
9925 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009926 try {
9927 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9928 } catch (NoSuchElementException ex) {
9929 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9930 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009931 } finally {
9932 Binder.restoreCallingIdentity(identity);
9933 }
9934 }
9935
Michelecea4cf22018-12-21 15:00:11 -08009936 @Override
Michele0ea7d782019-03-19 14:58:42 -07009937 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009938 enforceModifyPermission();
9939
9940 final long identity = Binder.clearCallingIdentity();
9941 try {
9942 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009943 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009944 .commit();
9945 } finally {
9946 Binder.restoreCallingIdentity(identity);
9947 }
9948 }
9949
9950 @Override
Michele0ea7d782019-03-19 14:58:42 -07009951 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009952 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009953 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009954 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9955 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009956 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009957 }
Michelecea4cf22018-12-21 15:00:11 -08009958
9959 final long identity = Binder.clearCallingIdentity();
9960 try {
Michele0ea7d782019-03-19 14:58:42 -07009961 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009962 } finally {
9963 Binder.restoreCallingIdentity(identity);
9964 }
9965 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009966
Michele0ea7d782019-03-19 14:58:42 -07009967 @TelephonyManager.IsMultiSimSupportedResult
9968 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009969 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9970 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9971 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009972 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9973 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009974 }
9975 // Check if the hardware supports multisim functionality. If usage of multisim is not
9976 // supported by the modem, indicate that it is restricted.
9977 PhoneCapability staticCapability =
9978 mPhoneConfigurationManager.getStaticPhoneCapability();
9979 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009980 loge("isMultiSimSupportedInternal: no static configuration available");
9981 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009982 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009983 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009984 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9985 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009986 }
9987 // Check if support of multiple SIMs is restricted by carrier
9988 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009989 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009990 }
9991
Michele0ea7d782019-03-19 14:58:42 -07009992 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009993 }
9994
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009995 /**
9996 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009997 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9998 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9999 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010000 * @param numOfSims number of active sims we want to switch to
10001 */
10002 @Override
10003 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010004 if (numOfSims == 1) {
10005 enforceModifyPermission();
10006 } else {
10007 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10008 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10009 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010010 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010011
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010012 try {
Michele30b57b22019-03-01 12:01:14 -080010013 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010014 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010015 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10016 return;
10017 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010018 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10019 } finally {
10020 Binder.restoreCallingIdentity(identity);
10021 }
10022 }
10023
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010024 @Override
10025 public boolean isApplicationOnUicc(int subId, int appType) {
10026 enforceReadPrivilegedPermission("isApplicationOnUicc");
10027 Phone phone = getPhone(subId);
10028 if (phone == null) {
10029 return false;
10030 }
10031 final long identity = Binder.clearCallingIdentity();
10032 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010033 UiccPort uiccPort = phone.getUiccPort();
10034 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010035 return false;
10036 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010037 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010038 if (uiccProfile == null) {
10039 return false;
10040 }
10041 if (TelephonyManager.APPTYPE_SIM <= appType
10042 && appType <= TelephonyManager.APPTYPE_ISIM) {
10043 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10044 }
10045 return false;
10046 } finally {
10047 Binder.restoreCallingIdentity(identity);
10048 }
10049 }
10050
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010051 /**
chen xub4baa772019-04-03 10:23:41 -070010052 * Get whether making changes to modem configurations will trigger reboot.
10053 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010054 */
10055 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010056 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10057 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010058 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010059 mApp, subId, callingPackage, callingFeatureId,
10060 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010061 return false;
10062 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010063 final long identity = Binder.clearCallingIdentity();
10064 try {
10065 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10066 } finally {
10067 Binder.restoreCallingIdentity(identity);
10068 }
10069 }
10070
Nathan Harold29f5f052019-02-15 13:41:57 -080010071 private void updateModemStateMetrics() {
10072 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10073 // TODO: check the state for each modem if the api is ready.
10074 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10075 }
10076
Pengquan Meng3889a572019-01-23 11:16:29 -080010077 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010078 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010079 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010080 // Verify that the callingPackage belongs to the calling UID
10081 mApp.getSystemService(AppOpsManager.class)
10082 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -080010083 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010084 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010085 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010086 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10087 if (slotInfos != null) {
10088 for (int i = 0; i < slotInfos.length; i++) {
10089 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10090 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10091 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10092 portInfo.getLogicalSlotIndex()));
10093 }
10094 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010095 }
10096 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010097 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010098 } finally {
10099 Binder.restoreCallingIdentity(identity);
10100 }
10101 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010102
10103 /**
10104 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010105 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010106 */
jimsunf9ec1622022-09-13 21:18:43 +080010107 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010108 @Override
10109 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010110 return getHalVersion(HAL_SERVICE_RADIO);
10111 }
10112
10113 /**
10114 * Get the HAL Version of a specific service
10115 */
10116 @Override
10117 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010118 Phone phone = getDefaultPhone();
10119 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010120 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010121 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10122 return hv.major * 100 + hv.minor;
10123 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010124
10125 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010126 * Get the current calling package name.
10127 * @return the current calling package name
10128 */
10129 @Override
10130 public String getCurrentPackageName() {
10131 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
10132 }
10133
10134 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010135 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10136 * corresponding network requests on a subId.
10137 *
10138 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010139 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010140 * 2) APN is un-metered for this subscription, or
10141 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010142 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010143 *
10144 * @return whether data is allowed for a apn type.
10145 *
10146 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010147 */
10148 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010149 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010150 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10151 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010152
10153 // Now that all security checks passes, perform the operation as ourselves.
10154 final long identity = Binder.clearCallingIdentity();
10155 try {
10156 Phone phone = getPhone(subId);
10157 if (phone == null) return false;
10158
Jack Yu27422a52022-03-21 10:38:05 -070010159 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010160 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010161 isMetered = phone.getDataNetworkController().getDataConfigManager()
10162 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10163 phone.getServiceState().getDataRoaming());
10164 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010165 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010166 } finally {
10167 Binder.restoreCallingIdentity(identity);
10168 }
10169 }
10170
10171 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010172 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010173 enforceReadPrivilegedPermission("isApnMetered");
10174
10175 // Now that all security checks passes, perform the operation as ourselves.
10176 final long identity = Binder.clearCallingIdentity();
10177 try {
10178 Phone phone = getPhone(subId);
10179 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010180 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10181 DataUtils.apnTypeToNetworkCapability(apnType),
10182 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010183 } finally {
10184 Binder.restoreCallingIdentity(identity);
10185 }
10186 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010187
10188 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010189 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10190 int subscriptionId, IBooleanConsumer resultCallback) {
10191 enforceModifyPermission();
10192 long token = Binder.clearCallingIdentity();
10193 try {
10194 Phone phone = getPhone(subscriptionId);
10195 if (phone == null) {
10196 try {
10197 if (resultCallback != null) {
10198 resultCallback.accept(false);
10199 }
10200 } catch (RemoteException e) {
10201 // ignore
10202 }
10203 return;
10204 }
10205 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10206 Pair.create(specifiers, (x) -> {
10207 try {
10208 if (resultCallback != null) {
10209 resultCallback.accept(x);
10210 }
10211 } catch (RemoteException e) {
10212 // ignore
10213 }
10214 });
10215 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10216 } finally {
10217 Binder.restoreCallingIdentity(token);
10218 }
10219 }
10220
10221 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010222 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10223 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010224 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010225 mApp, subId, "getSystemSelectionChannels");
10226 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10227 final long identity = Binder.clearCallingIdentity();
10228 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010229 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10230 if (result instanceof IllegalStateException) {
10231 throw (IllegalStateException) result;
10232 }
10233 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010234 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10235 return specifiers;
10236 } finally {
10237 Binder.restoreCallingIdentity(identity);
10238 }
10239 }
10240
10241 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010242 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010243 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010244 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010245 }
10246
10247 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010248 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10249 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010250 if (callingPackage == null) {
10251 callingPackage = getCurrentPackageName();
10252 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010253 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10254 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010255 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10256 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010257 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10258 }
10259 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10260 Intent intent = new Intent();
10261 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10262 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10263 // Bring up choose default SMS subscription dialog right now
10264 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10265 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10266 mApp.startActivity(intent);
10267 }
chen xud5ca2d52019-05-28 15:20:57 -070010268
10269 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010270 public void showSwitchToManagedProfileDialog() {
10271 enforceModifyPermission();
10272
10273 Intent intent = new Intent();
10274 intent.setClass(mApp, ErrorDialogActivity.class);
10275 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10276 mApp.startActivity(intent);
10277 }
10278
10279 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010280 public String getMmsUAProfUrl(int subId) {
10281 //TODO investigate if this API should require proper permission check in R b/133791609
10282 final long identity = Binder.clearCallingIdentity();
10283 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010284 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10285 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10286 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10287 return carrierUAProfUrl;
10288 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010289 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10290 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010291 } finally {
10292 Binder.restoreCallingIdentity(identity);
10293 }
10294 }
10295
10296 @Override
10297 public String getMmsUserAgent(int subId) {
10298 //TODO investigate if this API should require proper permission check in R b/133791609
10299 final long identity = Binder.clearCallingIdentity();
10300 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010301 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10302 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10303 if (!TextUtils.isEmpty(carrierUserAgent)) {
10304 return carrierUserAgent;
10305 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010306 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10307 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010308 } finally {
10309 Binder.restoreCallingIdentity(identity);
10310 }
10311 }
Jack Yub07d4972019-05-28 16:12:25 -070010312
10313 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010314 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10315 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010316
Jack Yub07d4972019-05-28 16:12:25 -070010317 final long identity = Binder.clearCallingIdentity();
10318 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010319 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010320 if (phone == null) return false;
10321
Ling Maf188d502022-09-16 15:22:36 -070010322 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010323 } finally {
10324 Binder.restoreCallingIdentity(identity);
10325 }
10326 }
10327
10328 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010329 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010330 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010331 enforceModifyPermission();
10332
changbettyd5c246e2019-12-24 15:40:37 +080010333 final long identity = Binder.clearCallingIdentity();
10334 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010335 Phone phone = getPhone(subscriptionId);
10336 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010337
Ling Maf188d502022-09-16 15:22:36 -070010338 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010339 } finally {
10340 Binder.restoreCallingIdentity(identity);
10341 }
10342 }
10343
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010344 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010345 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010346 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10347 * otherwise.
10348 */
10349 @Override
10350 public void setCepEnabled(boolean isCepEnabled) {
10351 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10352
10353 final long identity = Binder.clearCallingIdentity();
10354 try {
10355 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10356 for (Phone phone : PhoneFactory.getPhones()) {
10357 Phone defaultPhone = phone.getImsPhone();
10358 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10359 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10360 ImsPhoneCallTracker imsPhoneCallTracker =
10361 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10362 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10363 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10364 + imsPhone.getMsisdn());
10365 }
10366 }
10367 } finally {
10368 Binder.restoreCallingIdentity(identity);
10369 }
10370 }
allenwtsu46dcc572020-01-08 18:24:03 +080010371
10372 /**
10373 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10374 *
10375 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10376 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10377 * before being read.
10378 */
10379 @Override
10380 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10381 isCompressed) {
10382 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10383 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010384 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10385 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10386 }
10387 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010388 // ProvisioningManager can not handle ServiceSpecificException.
10389 // Throw the IllegalStateException and annotate ProvisioningManager.
10390 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010391 }
10392
10393 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010394 try {
Hui Wang761a6682020-10-31 05:12:53 +000010395 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10396 } finally {
10397 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010398 }
10399 }
zoey chene02881a2019-12-30 16:11:23 +080010400
10401 @Override
10402 public boolean isIccLockEnabled(int subId) {
10403 enforceReadPrivilegedPermission("isIccLockEnabled");
10404
10405 // Now that all security checks passes, perform the operation as ourselves.
10406 final long identity = Binder.clearCallingIdentity();
10407 try {
10408 Phone phone = getPhone(subId);
10409 if (phone != null && phone.getIccCard() != null) {
10410 return phone.getIccCard().getIccLockEnabled();
10411 } else {
10412 return false;
10413 }
10414 } finally {
10415 Binder.restoreCallingIdentity(identity);
10416 }
10417 }
10418
10419 /**
10420 * Set the ICC pin lock enabled or disabled.
10421 *
10422 * @return an integer representing the status of IccLock enabled or disabled in the following
10423 * three cases:
10424 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10425 * successfully.
10426 * - Positive number and zero for remaining password attempts.
10427 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10428 *
10429 */
10430 @Override
10431 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10432 enforceModifyPermission();
10433
10434 Phone phone = getPhone(subId);
10435 if (phone == null) {
10436 return 0;
10437 }
10438 // Now that all security checks passes, perform the operation as ourselves.
10439 final long identity = Binder.clearCallingIdentity();
10440 try {
10441 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10442 new Pair<Boolean, String>(enabled, password), phone, null);
10443 return attemptsRemaining;
10444
10445 } catch (Exception e) {
10446 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10447 } finally {
10448 Binder.restoreCallingIdentity(identity);
10449 }
10450 return 0;
10451 }
10452
10453 /**
10454 * Change the ICC password used in ICC pin lock.
10455 *
10456 * @return an integer representing the status of IccLock changed in the following three cases:
10457 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10458 * - Positive number and zero for remaining password attempts.
10459 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10460 *
10461 */
10462 @Override
10463 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10464 enforceModifyPermission();
10465
10466 Phone phone = getPhone(subId);
10467 if (phone == null) {
10468 return 0;
10469 }
10470 // Now that all security checks passes, perform the operation as ourselves.
10471 final long identity = Binder.clearCallingIdentity();
10472 try {
10473 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10474 new Pair<String, String>(oldPassword, newPassword), phone, null);
10475 return attemptsRemaining;
10476
10477 } catch (Exception e) {
10478 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10479 } finally {
10480 Binder.restoreCallingIdentity(identity);
10481 }
10482 return 0;
10483 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010484
10485 /**
10486 * Request for receiving user activity notification
10487 */
10488 @Override
10489 public void requestUserActivityNotification() {
10490 if (!mNotifyUserActivity.get()
10491 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10492 mNotifyUserActivity.set(true);
10493 }
10494 }
10495
10496 /**
10497 * Called when userActivity is signalled in the power manager.
10498 * This is safe to call from any thread, with any window manager locks held or not.
10499 */
10500 @Override
10501 public void userActivity() {
10502 // ***************************************
10503 // * Inherited from PhoneWindowManager *
10504 // ***************************************
10505 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10506 // WITH ITS LOCKS HELD.
10507 //
10508 // This code must be VERY careful about the locks
10509 // it acquires.
10510 // In fact, the current code acquires way too many,
10511 // and probably has lurking deadlocks.
10512
10513 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10514 throw new SecurityException("Only the OS may call notifyUserActivity()");
10515 }
10516
10517 if (mNotifyUserActivity.getAndSet(false)) {
10518 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10519 USER_ACTIVITY_NOTIFICATION_DELAY);
10520 }
10521 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010522
10523 @Override
10524 public boolean canConnectTo5GInDsdsMode() {
10525 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10526 }
Jack Yud10cdd42020-09-28 20:28:01 -070010527
10528 @Override
10529 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10530 String callingFeatureId) {
10531 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10532 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10533 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10534 }
10535
10536 Phone phone = getPhone(subId);
10537 if (phone == null) {
10538 throw new RuntimeException("phone is not available");
10539 }
10540 // Now that all security checks passes, perform the operation as ourselves.
10541 final long identity = Binder.clearCallingIdentity();
10542 try {
10543 return phone.getEquivalentHomePlmns();
10544 } finally {
10545 Binder.restoreCallingIdentity(identity);
10546 }
10547 }
Daniel Bright59e67312020-11-13 11:49:37 -080010548
10549 @Override
10550 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010551 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10552 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010553 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010554 if (radioInterfaceCapabilities == null) {
10555 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010556 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010557 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010558 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010559
Hui Wang641e81c2020-10-12 12:14:23 -070010560 @Override
10561 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10562 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010563 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10564 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10565 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10566 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10567 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010568 if (DBG) {
10569 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10570 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10571 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10572 }
10573
10574 if (!SubscriptionManager.isValidSubscriptionId(subId)
10575 || appType < TelephonyManager.APPTYPE_UNKNOWN
10576 || appType > TelephonyManager.APPTYPE_ISIM
10577 || nafUrl == null || securityProtocol == null || callback == null) {
10578 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10579 if (callback != null) {
10580 try {
10581 callback.onAuthenticationFailure(
10582 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10583 } catch (RemoteException exception) {
10584 log("Fail to notify onAuthenticationFailure due to " + exception);
10585 }
10586 return;
10587 }
10588 }
10589
10590 final long token = Binder.clearCallingIdentity();
10591 try {
10592 getGbaManager(subId).bootstrapAuthenticationRequest(
10593 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010594 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070010595 } finally {
10596 Binder.restoreCallingIdentity(token);
10597 }
10598 }
10599
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010600 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010601 * Attempts to set the radio power state for all phones for thermal reason.
10602 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010603 * requested radio power state will actually be set. See {@link
10604 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10605 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010606 * @param enable {@code true} if trying to turn radio on.
10607 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10608 * false}.
10609 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010610 private boolean setRadioPowerForThermal(boolean enable) {
10611 boolean isPhoneAvailable = false;
10612 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10613 Phone phone = PhoneFactory.getPhone(i);
10614 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010615 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010616 isPhoneAvailable = true;
10617 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010618 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010619
10620 // return true if successfully informed the phone object about the thermal radio power
10621 // request.
10622 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010623 }
10624
10625 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010626 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010627 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10628 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10629 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10630 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10631 throw new IllegalArgumentException("modem does not support data throttling");
10632 }
10633
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010634 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10635 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010636 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010637 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10638 }
10639
Sarah Chinecc78c42022-03-31 21:16:48 -070010640 setDataEnabledForReason(
10641 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010642
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010643 if (isDataThrottlingSupported) {
10644 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010645 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010646 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10647 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10648 } else if (thermalMitigationResult
10649 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010650 log("Modem likely does not support data throttling on secondary carrier. Data " +
10651 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10652 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010653 }
10654 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010655 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010656
10657 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010658 }
10659
Jack Nudelman644b91a2021-03-12 14:09:48 -080010660 private static List<String> getThermalMitigationAllowlist(Context context) {
10661 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10662 for (String pckg : context.getResources()
10663 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10664 sThermalMitigationAllowlistedPackages.add(pckg);
10665 }
10666 }
10667
10668 return sThermalMitigationAllowlistedPackages;
10669 }
10670
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010671 private boolean isAnyPhoneInEmergencyState() {
10672 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10673 if (tm.isInEmergencyCall()) {
10674 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10675 return true;
10676 }
10677 for (Phone phone : PhoneFactory.getPhones()) {
10678 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10679 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010680 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10681 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010682 return true;
10683 }
10684 }
10685
10686 return false;
10687 }
10688
Jack Nudelman644b91a2021-03-12 14:09:48 -080010689 /**
10690 * Used by shell commands to add an authorized package name for thermal mitigation.
10691 * @param packageName name of package to be allowlisted
10692 * @param context
10693 */
10694 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10695 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10696 sThermalMitigationAllowlistedPackages.add(packageName);
10697 }
10698
10699 /**
10700 * Used by shell commands to remove an authorized package name for thermal mitigation.
10701 * @param packageName name of package to remove from allowlist
10702 * @param context
10703 */
10704 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10705 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10706 sThermalMitigationAllowlistedPackages.remove(packageName);
10707 }
10708
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010709 /**
10710 * Thermal mitigation request to control functionalities at modem.
10711 *
10712 * @param subId the id of the subscription.
10713 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010714 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010715 *
10716 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10717 */
10718 @Override
10719 @ThermalMitigationResult
10720 public int sendThermalMitigationRequest(
10721 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010722 ThermalMitigationRequest thermalMitigationRequest,
10723 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010724 enforceModifyPermission();
10725
Jack Nudelman644b91a2021-03-12 14:09:48 -080010726 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10727 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10728 .contains(callingPackage)) {
10729 throw new SecurityException("Calling package must be configured in the device config. "
10730 + "calling package: " + callingPackage);
10731 }
10732
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010733 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10734 final long identity = Binder.clearCallingIdentity();
10735
10736 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10737 try {
10738 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10739 switch (thermalMitigationAction) {
10740 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10741 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010742 handleDataThrottlingRequest(subId,
10743 thermalMitigationRequest.getDataThrottlingRequest(),
10744 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010745 break;
10746 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10747 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10748 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10749 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10750 }
10751
10752 // Ensure that radio is on. If not able to power on due to phone being
10753 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010754 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010755 thermalMitigationResult =
10756 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10757 break;
10758 }
10759
10760 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010761 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010762 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10763 break;
10764 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10765 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10766 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10767 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10768 }
10769
10770 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10771 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010772 Phone phone = getPhone(subId);
10773 if (phone == null) {
10774 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010775 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010776 break;
10777 }
10778
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010779 TelephonyConnectionService service =
10780 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010781 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010782 Log.e(LOG_TAG, "An emergency call is pending");
10783 thermalMitigationResult =
10784 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10785 break;
10786 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010787 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010788 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010789 break;
10790 }
10791 } else {
10792 thermalMitigationResult =
10793 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10794 break;
10795 }
10796
10797 // Turn radio off. If not able to power off due to phone being unavailable,
10798 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010799 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010800 thermalMitigationResult =
10801 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10802 break;
10803 }
10804 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010805 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010806 break;
10807 default:
10808 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10809 + "not exist. Requested action: " + thermalMitigationAction);
10810 }
10811 } catch (IllegalArgumentException e) {
10812 throw e;
10813 } catch (Exception e) {
10814 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10815 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10816 } finally {
10817 Binder.restoreCallingIdentity(identity);
10818 }
10819
10820 if (DBG) {
10821 log("thermalMitigationRequest returning with thermalMitigationResult: "
10822 + thermalMitigationResult);
10823 }
10824
10825 return thermalMitigationResult;
10826 }
Hui Wang641e81c2020-10-12 12:14:23 -070010827
10828 /**
10829 * Set the GbaService Package Name that Telephony will bind to.
10830 *
10831 * @param subId The sim that the GbaService is associated with.
10832 * @param packageName The name of the package to be replaced with.
10833 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10834 */
10835 @Override
10836 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10837 enforceModifyPermission();
10838
10839 final long identity = Binder.clearCallingIdentity();
10840 try {
10841 return getGbaManager(subId).overrideServicePackage(packageName);
10842 } finally {
10843 Binder.restoreCallingIdentity(identity);
10844 }
10845 }
10846
10847 /**
10848 * Return the package name of the currently bound GbaService.
10849 *
10850 * @param subId The sim that the GbaService is associated with.
10851 * @return the package name of the GbaService configuration, null if GBA is not supported.
10852 */
10853 @Override
10854 public String getBoundGbaService(int subId) {
10855 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10856
10857 final long identity = Binder.clearCallingIdentity();
10858 try {
10859 return getGbaManager(subId).getServicePackage();
10860 } finally {
10861 Binder.restoreCallingIdentity(identity);
10862 }
10863 }
10864
10865 /**
10866 * Set the release time for telephony to unbind GbaService.
10867 *
10868 * @param subId The sim that the GbaService is associated with.
10869 * @param interval The release time to unbind GbaService by millisecond.
10870 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10871 */
10872 @Override
10873 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10874 enforceModifyPermission();
10875
10876 final long identity = Binder.clearCallingIdentity();
10877 try {
10878 return getGbaManager(subId).overrideReleaseTime(interval);
10879 } finally {
10880 Binder.restoreCallingIdentity(identity);
10881 }
10882 }
10883
10884 /**
10885 * Return the release time for telephony to unbind GbaService.
10886 *
10887 * @param subId The sim that the GbaService is associated with.
10888 * @return The release time to unbind GbaService by millisecond.
10889 */
10890 @Override
10891 public int getGbaReleaseTime(int subId) {
10892 enforceReadPrivilegedPermission("getGbaReleaseTime");
10893
10894 final long identity = Binder.clearCallingIdentity();
10895 try {
10896 return getGbaManager(subId).getReleaseTime();
10897 } finally {
10898 Binder.restoreCallingIdentity(identity);
10899 }
10900 }
10901
10902 private GbaManager getGbaManager(int subId) {
10903 GbaManager instance = GbaManager.getInstance(subId);
10904 if (instance == null) {
10905 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10906 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10907 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10908 }
10909 return instance;
10910 }
Hui Wang761a6682020-10-31 05:12:53 +000010911
10912 /**
10913 * indicate whether the device and the carrier can support
10914 * RCS VoLTE single registration.
10915 */
10916 @Override
10917 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010918 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10919 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10920 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10921 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010922
10923 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10924 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10925 }
10926
10927 final long identity = Binder.clearCallingIdentity();
10928 try {
10929 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10930 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010931 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10932 if (isCapable != null) {
10933 return isCapable;
10934 }
Hui Wang761a6682020-10-31 05:12:53 +000010935 }
Hui Wang67af90e2021-06-04 16:57:15 -070010936 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10937 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010938 } finally {
10939 Binder.restoreCallingIdentity(identity);
10940 }
10941 }
10942
10943 /**
10944 * Register RCS provisioning callback.
10945 */
10946 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010947 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010948 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010949 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010950 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010951 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10952 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010953
10954 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10955 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10956 }
10957 if (!isImsAvailableOnDevice()) {
10958 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10959 "IMS not available on device.");
10960 }
10961
10962 final long identity = Binder.clearCallingIdentity();
10963 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010964 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010965 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010966 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10967 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010968 }
Hui Wang761a6682020-10-31 05:12:53 +000010969 } finally {
10970 Binder.restoreCallingIdentity(identity);
10971 }
10972 }
10973
10974 /**
10975 * Unregister RCS provisioning callback.
10976 */
10977 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010978 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010979 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010980 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010981 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010982 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10983 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010984
10985 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10986 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10987 }
10988 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010989 // operation failed silently
10990 Rlog.w(LOG_TAG, "IMS not available on device.");
10991 return;
Hui Wang761a6682020-10-31 05:12:53 +000010992 }
10993
10994 final long identity = Binder.clearCallingIdentity();
10995 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010996 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010997 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010998 } finally {
10999 Binder.restoreCallingIdentity(identity);
11000 }
11001 }
11002
11003 /**
11004 * trigger RCS reconfiguration.
11005 */
11006 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011007 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11008 "triggerRcsReconfiguration",
11009 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011010
11011 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11012 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11013 }
11014 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000011015 // ProvisioningManager can not handle ServiceSpecificException.
11016 // Throw the IllegalStateException and annotate ProvisioningManager.
11017 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000011018 }
11019
11020 final long identity = Binder.clearCallingIdentity();
11021 try {
11022 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11023 } finally {
11024 Binder.restoreCallingIdentity(identity);
11025 }
11026 }
11027
11028 /**
11029 * Provide the client configuration parameters of the RCS application.
11030 */
11031 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011032 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11033 "setRcsClientConfiguration",
11034 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011035
11036 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11037 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11038 }
11039 if (!isImsAvailableOnDevice()) {
11040 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11041 "IMS not available on device.");
11042 }
11043
11044 final long identity = Binder.clearCallingIdentity();
11045
11046 try {
11047 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11048 if (configBinder == null) {
11049 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011050 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11051 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011052 } else {
11053 configBinder.setRcsClientConfiguration(rcc);
11054 }
joonhunshin3e154242021-09-17 06:33:39 +000011055
11056 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11057 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011058 } catch (RemoteException e) {
11059 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011060 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11061 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011062 } finally {
11063 Binder.restoreCallingIdentity(identity);
11064 }
11065 }
11066
11067 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011068 * Enables or disables the test mode for RCS VoLTE single registration.
11069 */
11070 @Override
11071 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11072 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11073 "setRcsSingleRegistrationTestModeEnabled");
11074
11075 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11076 }
11077
11078 /**
11079 * Gets the test mode for RCS VoLTE single registration.
11080 */
11081 @Override
11082 public boolean getRcsSingleRegistrationTestModeEnabled() {
11083 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11084 "getRcsSingleRegistrationTestModeEnabled");
11085
11086 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11087 }
11088
11089 /**
Hui Wang761a6682020-10-31 05:12:53 +000011090 * Overrides the config of RCS VoLTE single registration enabled for the device.
11091 */
11092 @Override
11093 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11094 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11095 "setDeviceSingleRegistrationEnabledOverride");
11096 enforceModifyPermission();
11097
11098 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11099 : Boolean.parseBoolean(enabledStr);
11100 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011101 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011102 }
11103
11104 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011105 * Sends a device to device communication message. Only usable via shell.
11106 * @param message message to send.
11107 * @param value message value.
11108 */
11109 @Override
11110 public void sendDeviceToDeviceMessage(int message, int value) {
11111 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011112 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011113 enforceModifyPermission();
11114
11115 final long identity = Binder.clearCallingIdentity();
11116 try {
11117 TelephonyConnectionService service =
11118 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11119 if (service == null) {
11120 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11121 return;
11122 }
11123 service.sendTestDeviceToDeviceMessage(message, value);
11124 } finally {
11125 Binder.restoreCallingIdentity(identity);
11126 }
11127 }
11128
Tyler Gunnbabbda02021-02-10 11:05:02 -080011129 /**
11130 * Sets the specified device to device transport active.
11131 * @param transport The transport to set active.
11132 */
11133 @Override
11134 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11135 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11136 "setActiveDeviceToDeviceTransport");
11137 enforceModifyPermission();
11138
11139 final long identity = Binder.clearCallingIdentity();
11140 try {
11141 TelephonyConnectionService service =
11142 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11143 if (service == null) {
11144 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11145 return;
11146 }
11147 service.setActiveDeviceToDeviceTransport(transport);
11148 } finally {
11149 Binder.restoreCallingIdentity(identity);
11150 }
11151 }
Tyler Gunn92479152021-01-20 16:30:10 -080011152
Tyler Gunnd4339262021-05-03 14:46:49 -070011153 @Override
11154 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11155 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11156 "setDeviceToDeviceForceEnabled");
11157
11158 final long identity = Binder.clearCallingIdentity();
11159 try {
11160 Arrays.stream(PhoneFactory.getPhones()).forEach(
11161 p -> {
11162 Phone thePhone = p.getImsPhone();
11163 if (thePhone != null && thePhone instanceof ImsPhone) {
11164 ImsPhone imsPhone = (ImsPhone) thePhone;
11165 CallTracker tracker = imsPhone.getCallTracker();
11166 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11167 ImsPhoneCallTracker imsPhoneCallTracker =
11168 (ImsPhoneCallTracker) tracker;
11169 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11170 }
11171 }
11172 }
11173 );
11174 } finally {
11175 Binder.restoreCallingIdentity(identity);
11176 }
11177 }
11178
Tyler Gunn92479152021-01-20 16:30:10 -080011179 /**
Hui Wang761a6682020-10-31 05:12:53 +000011180 * Gets the config of RCS VoLTE single registration enabled for the device.
11181 */
11182 @Override
11183 public boolean getDeviceSingleRegistrationEnabled() {
11184 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11185 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11186 }
11187
11188 /**
11189 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11190 */
11191 @Override
11192 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11193 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11194 "setCarrierSingleRegistrationEnabledOverride");
11195 enforceModifyPermission();
11196
11197 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11198 : Boolean.parseBoolean(enabledStr);
11199 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11200 subId, enabled);
11201 }
11202
11203 /**
11204 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11205 */
11206 @Override
11207 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11208 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11209 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11210 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011211
11212 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011213 * Overrides the ims feature validation result
11214 */
11215 @Override
11216 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11217 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11218 "setImsFeatureValidationOverride");
11219
11220 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11221 : Boolean.parseBoolean(enabledStr);
11222 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11223 subId, enabled);
11224 }
11225
11226 /**
11227 * Gets the ims feature validation override value
11228 */
11229 @Override
11230 public boolean getImsFeatureValidationOverride(int subId) {
11231 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11232 "getImsFeatureValidationOverride");
11233 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11234 }
11235
11236 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011237 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11238 * their mobile plan.
11239 */
11240 @Override
11241 public String getMobileProvisioningUrl() {
11242 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11243 final long identity = Binder.clearCallingIdentity();
11244 try {
11245 return getDefaultPhone().getMobileProvisioningUrl();
11246 } finally {
11247 Binder.restoreCallingIdentity(identity);
11248 }
11249 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011250
James.cf Linbcdf8b32021-01-14 16:44:13 +080011251 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011252 * Get the EAB contact from the EAB database.
11253 */
11254 @Override
11255 public String getContactFromEab(String contact) {
11256 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11257 enforceModifyPermission();
11258 final long identity = Binder.clearCallingIdentity();
11259 try {
11260 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11261 } finally {
11262 Binder.restoreCallingIdentity(identity);
11263 }
11264 }
11265
11266 /**
Calvin Pana1434322021-07-01 19:27:01 +080011267 * Get the EAB capability from the EAB database.
11268 */
11269 @Override
11270 public String getCapabilityFromEab(String contact) {
11271 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11272 enforceModifyPermission();
11273 final long identity = Binder.clearCallingIdentity();
11274 try {
11275 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11276 } finally {
11277 Binder.restoreCallingIdentity(identity);
11278 }
11279 }
11280
11281 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011282 * Remove the EAB contacts from the EAB database.
11283 */
11284 @Override
11285 public int removeContactFromEab(int subId, String contacts) {
11286 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11287 enforceModifyPermission();
11288 final long identity = Binder.clearCallingIdentity();
11289 try {
11290 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11291 } finally {
11292 Binder.restoreCallingIdentity(identity);
11293 }
11294 }
11295
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011296 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011297 public boolean getDeviceUceEnabled() {
11298 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11299 final long identity = Binder.clearCallingIdentity();
11300 try {
11301 return mApp.getDeviceUceEnabled();
11302 } finally {
11303 Binder.restoreCallingIdentity(identity);
11304 }
11305 }
11306
11307 @Override
11308 public void setDeviceUceEnabled(boolean isEnabled) {
11309 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11310 final long identity = Binder.clearCallingIdentity();
11311 try {
11312 mApp.setDeviceUceEnabled(isEnabled);
11313 } finally {
11314 Binder.restoreCallingIdentity(identity);
11315 }
11316 }
11317
Brad Ebinger14d467f2021-02-12 06:18:28 +000011318 /**
11319 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11320 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11321 */
11322 // Used for SHELL command only right now.
11323 @Override
11324 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11325 List<String> featureTags) {
11326 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11327 "addUceRegistrationOverrideShell");
11328 final long identity = Binder.clearCallingIdentity();
11329 try {
11330 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11331 new ArraySet<>(featureTags));
11332 } catch (ImsException e) {
11333 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11334 } finally {
11335 Binder.restoreCallingIdentity(identity);
11336 }
11337 }
11338
11339 /**
11340 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11341 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11342 */
11343 // Used for SHELL command only right now.
11344 @Override
11345 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11346 List<String> featureTags) {
11347 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11348 "removeUceRegistrationOverrideShell");
11349 final long identity = Binder.clearCallingIdentity();
11350 try {
11351 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11352 new ArraySet<>(featureTags));
11353 } catch (ImsException e) {
11354 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11355 } finally {
11356 Binder.restoreCallingIdentity(identity);
11357 }
11358 }
11359
11360 /**
11361 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11362 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11363 */
11364 // Used for SHELL command only right now.
11365 @Override
11366 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11367 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11368 "clearUceRegistrationOverrideShell");
11369 final long identity = Binder.clearCallingIdentity();
11370 try {
11371 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11372 } catch (ImsException e) {
11373 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11374 } finally {
11375 Binder.restoreCallingIdentity(identity);
11376 }
11377 }
11378
11379 /**
11380 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11381 */
11382 // Used for SHELL command only right now.
11383 @Override
11384 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11385 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11386 "getLatestRcsContactUceCapabilityShell");
11387 final long identity = Binder.clearCallingIdentity();
11388 try {
11389 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11390 } catch (ImsException e) {
11391 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11392 } finally {
11393 Binder.restoreCallingIdentity(identity);
11394 }
11395 }
11396
11397 /**
11398 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11399 * device does not have an active PUBLISH.
11400 */
11401 // Used for SHELL command only right now.
11402 @Override
11403 public String getLastUcePidfXmlShell(int subId) {
11404 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11405 final long identity = Binder.clearCallingIdentity();
11406 try {
11407 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11408 } catch (ImsException e) {
11409 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11410 } finally {
11411 Binder.restoreCallingIdentity(identity);
11412 }
11413 }
11414
James.cf Line8713a42021-04-29 16:04:26 +080011415 /**
11416 * Remove UCE requests cannot be sent to the network status.
11417 */
11418 // Used for SHELL command only right now.
11419 @Override
11420 public boolean removeUceRequestDisallowedStatus(int subId) {
11421 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11422 final long identity = Binder.clearCallingIdentity();
11423 try {
11424 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11425 } catch (ImsException e) {
11426 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11427 } finally {
11428 Binder.restoreCallingIdentity(identity);
11429 }
11430 }
11431
James.cf Lin18bb9002021-05-25 01:37:38 +080011432 /**
11433 * Remove UCE requests cannot be sent to the network status.
11434 */
11435 // Used for SHELL command only.
11436 @Override
11437 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11438 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11439 final long identity = Binder.clearCallingIdentity();
11440 try {
11441 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11442 } catch (ImsException e) {
11443 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11444 } finally {
11445 Binder.restoreCallingIdentity(identity);
11446 }
11447 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011448
James.cf Lin4b784aa2021-01-31 03:25:15 +080011449 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011450 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11451 String callingPackage) {
11452 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11453 mApp, subId, "setSignalStrengthUpdateRequest");
11454
11455 final int callingUid = Binder.getCallingUid();
11456 // Verify that tha callingPackage belongs to the calling UID
11457 mApp.getSystemService(AppOpsManager.class)
11458 .checkPackage(callingUid, callingPackage);
11459
Rambo Wang3607f502021-02-01 21:51:40 -080011460 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011461
11462 final long identity = Binder.clearCallingIdentity();
11463 try {
11464 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11465 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11466
11467 if (result instanceof IllegalStateException) {
11468 throw (IllegalStateException) result;
11469 }
11470 } finally {
11471 Binder.restoreCallingIdentity(identity);
11472 }
11473 }
11474
11475 @Override
11476 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11477 String callingPackage) {
11478 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11479 mApp, subId, "clearSignalStrengthUpdateRequest");
11480
11481 final int callingUid = Binder.getCallingUid();
11482 // Verify that tha callingPackage belongs to the calling UID
11483 mApp.getSystemService(AppOpsManager.class)
11484 .checkPackage(callingUid, callingPackage);
11485
11486 final long identity = Binder.clearCallingIdentity();
11487 try {
11488 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11489 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11490
11491 if (result instanceof IllegalStateException) {
11492 throw (IllegalStateException) result;
11493 }
11494 } finally {
11495 Binder.restoreCallingIdentity(identity);
11496 }
11497 }
11498
Rambo Wang3607f502021-02-01 21:51:40 -080011499 private static void validateSignalStrengthUpdateRequest(Context context,
11500 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011501 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11502 // phone/system process do not have further restriction on request
11503 return;
11504 }
11505
11506 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011507 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011508 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011509 context.enforceCallingOrSelfPermission(
11510 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11511 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011512 }
11513
11514 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000011515 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011516 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011517 || info.isEnabled()) {
11518 throw new IllegalArgumentException(
11519 "Only system can set hide fields in SignalThresholdInfo");
11520 }
11521
11522 // Thresholds length for each RAN need in range. This has been validated in
11523 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11524 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11525 final int[] thresholds = info.getThresholds();
11526 Objects.requireNonNull(thresholds);
11527 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11528 || thresholds.length
11529 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11530 throw new IllegalArgumentException(
11531 "thresholds length is out of range: " + thresholds.length);
11532 }
11533 }
11534 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011535
11536 /**
11537 * Gets the current phone capability.
11538 *
11539 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11540 * @return the PhoneCapability which describes the data connection capability of modem.
11541 * It's used to evaluate possible phone config change, for example from single
11542 * SIM device to multi-SIM device.
11543 */
11544 @Override
11545 public PhoneCapability getPhoneCapability() {
11546 enforceReadPrivilegedPermission("getPhoneCapability");
11547 final long identity = Binder.clearCallingIdentity();
11548 try {
11549 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11550 } finally {
11551 Binder.restoreCallingIdentity(identity);
11552 }
11553 }
Michele Berionne5e411512020-11-13 02:36:59 +000011554
11555 /**
11556 * Prepare TelephonyManager for an unattended reboot. The reboot is
11557 * required to be done shortly after the API is invoked.
11558 */
11559 @Override
11560 @TelephonyManager.PrepareUnattendedRebootResult
11561 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011562 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011563 enforceRebootPermission();
11564
11565 final long identity = Binder.clearCallingIdentity();
11566 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011567 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011568 } finally {
11569 Binder.restoreCallingIdentity(identity);
11570 }
11571 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011572
11573 /**
11574 * Request to get the current slicing configuration including URSP rules and
11575 * NSSAIs (configured, allowed and rejected).
11576 *
11577 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11578 */
11579 @Override
11580 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011581 TelephonyPermissions
11582 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11583 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011584
11585 final long identity = Binder.clearCallingIdentity();
11586 try {
11587 Phone phone = getDefaultPhone();
11588 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11589 } finally {
11590 Binder.restoreCallingIdentity(identity);
11591 }
11592 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011593
11594 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011595 * Check whether the given premium capability is available for purchase from the carrier.
11596 *
11597 * @param capability The premium capability to check.
11598 * @param subId The subId to check the premium capability for.
11599 *
11600 * @return Whether the given premium capability is available to purchase.
11601 */
11602 @Override
11603 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11604 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11605 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11606 log("Premium capability "
11607 + TelephonyManager.convertPremiumCapabilityToString(capability)
11608 + " is not available for purchase due to missing permissions.");
11609 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11610 + "permission READ_BASIC_PHONE_STATE.");
11611 }
11612
11613 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080011614 if (phone == null) {
11615 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
11616 return false;
11617 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070011618 final long identity = Binder.clearCallingIdentity();
11619 try {
Sarah Chin46355ba2022-11-01 23:51:16 -070011620 return SlicePurchaseController.getInstance(phone)
Sarah Chin2ec39f62022-08-31 17:03:26 -070011621 .isPremiumCapabilityAvailableForPurchase(capability);
11622 } finally {
11623 Binder.restoreCallingIdentity(identity);
11624 }
11625 }
11626
11627 /**
11628 * Purchase the given premium capability from the carrier.
11629 *
11630 * @param capability The premium capability to purchase.
11631 * @param callback The result of the purchase request.
11632 * @param subId The subId to purchase the premium capability for.
11633 */
11634 @Override
11635 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11636 log("purchasePremiumCapability: capability="
11637 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11638 + getCurrentPackageName());
11639
11640 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11641 mApp, "purchasePremiumCapability")) {
11642 log("purchasePremiumCapability "
11643 + TelephonyManager.convertPremiumCapabilityToString(capability)
11644 + " failed due to missing permissions.");
11645 throw new SecurityException("purchasePremiumCapability requires permission "
11646 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080011647 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
11648 mApp, "purchasePremiumCapability")) {
11649 log("purchasePremiumCapability "
11650 + TelephonyManager.convertPremiumCapabilityToString(capability)
11651 + " failed due to missing permissions.");
11652 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070011653 }
11654
11655 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080011656 if (phone == null) {
11657 try {
11658 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
11659 callback.accept(result);
11660 loge("purchasePremiumCapability: phone is null, subId=" + subId);
11661 } catch (RemoteException e) {
11662 String logStr = "Purchase premium capability "
11663 + TelephonyManager.convertPremiumCapabilityToString(capability)
11664 + " failed due to RemoteException handling null phone: " + e;
11665 if (DBG) log(logStr);
11666 AnomalyReporter.reportAnomaly(
11667 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11668 }
11669 return;
11670 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011671
11672 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070011673 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011674 callingProcess = mApp.getPackageManager().getApplicationInfo(
11675 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070011676 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011677 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070011678 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011679
11680 boolean isVisible = false;
11681 ActivityManager am = mApp.getSystemService(ActivityManager.class);
11682 if (am != null) {
11683 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
11684 if (processes != null) {
11685 for (ActivityManager.RunningAppProcessInfo process : processes) {
11686 log("purchasePremiumCapability: process " + process.processName
11687 + "has importance " + process.importance);
11688 if (process.processName.equals(callingProcess) && process.importance
11689 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
11690 isVisible = true;
11691 break;
11692 }
11693 }
11694 }
11695 }
11696
11697 if (!isVisible) {
11698 try {
11699 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
11700 callback.accept(result);
11701 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
11702 } catch (RemoteException e) {
11703 String logStr = "Purchase premium capability "
11704 + TelephonyManager.convertPremiumCapabilityToString(capability)
11705 + " failed due to RemoteException handling background application: " + e;
11706 if (DBG) log(logStr);
11707 AnomalyReporter.reportAnomaly(
11708 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11709 }
11710 return;
11711 }
11712
Sarah Chin71b3a852022-09-28 15:54:19 -070011713 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080011714 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011715 }
11716
11717 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011718 * Register an IMS connection state callback
11719 */
11720 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011721 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11722 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011723 if (feature == ImsFeature.FEATURE_MMTEL) {
11724 // ImsMmTelManager
11725 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11726 TelephonyPermissions
11727 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11728 mApp, subId, "registerImsStateCallback");
11729 } else if (feature == ImsFeature.FEATURE_RCS) {
11730 // ImsRcsManager or SipDelegateManager
11731 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11732 Binder.getCallingUid(), "registerImsStateCallback",
11733 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11734 Manifest.permission.READ_PRECISE_PHONE_STATE,
11735 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11736 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11737 }
11738
11739 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11740 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11741 "IMS not available on device.");
11742 }
11743
11744 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11745 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11746 }
11747
11748 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11749 if (controller == null) {
11750 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11751 "IMS not available on device.");
11752 }
11753
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011754 if (callingPackage == null) {
11755 callingPackage = getCurrentPackageName();
11756 }
11757
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011758 final long token = Binder.clearCallingIdentity();
11759 try {
11760 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011761 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011762 } catch (ImsException e) {
11763 throw new ServiceSpecificException(e.getCode());
11764 } finally {
11765 Binder.restoreCallingIdentity(token);
11766 }
11767 }
11768
11769 /**
11770 * Unregister an IMS connection state callback
11771 */
11772 @Override
11773 public void unregisterImsStateCallback(IImsStateCallback cb) {
11774 final long token = Binder.clearCallingIdentity();
11775 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11776 if (controller == null) {
11777 return;
11778 }
11779 try {
11780 controller.unregisterImsStateCallback(cb);
11781 } finally {
11782 Binder.restoreCallingIdentity(token);
11783 }
11784 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011785
11786 /**
11787 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11788 *
11789 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11790 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11791 * SecurityException.
11792 * If there is current registered network this value will be same as the registered cell
11793 * identity. If the device goes out of service the previous cell identity is cached and
11794 * will be returned. If the cache age of the Cell identity is more than 24 hours
11795 * it will be cleared and null will be returned.
11796 *
11797 */
11798 @Override
11799 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11800 String callingFeatureId) {
11801 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11802 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11803 LocationAccessPolicy.checkLocationPermission(mApp,
11804 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11805 .setCallingPackage(callingPackage)
11806 .setCallingFeatureId(callingFeatureId)
11807 .setCallingPid(Binder.getCallingPid())
11808 .setCallingUid(Binder.getCallingUid())
11809 .setMethod("getLastKnownCellIdentity")
11810 .setLogAsInfo(true)
11811 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11812 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11813 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11814 .build());
11815
11816 boolean hasFinePermission =
11817 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11818 if (!hasFinePermission
11819 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11820 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011821 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011822 }
11823
11824 final long identity = Binder.clearCallingIdentity();
11825 try {
11826 Phone phone = getPhone(subId);
11827 if (phone == null) return null;
11828 ServiceStateTracker sst = phone.getServiceStateTracker();
11829 if (sst == null) return null;
11830 return sst.getLastKnownCellIdentity();
11831 } finally {
11832 Binder.restoreCallingIdentity(identity);
11833 }
11834 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011835
jimsun3b9ccac2021-10-26 15:01:23 +080011836 /**
11837 * Sets the modem service class Name that Telephony will bind to.
11838 *
11839 * @param serviceName The class name of the modem service.
11840 * @return true if the operation is succeed, otherwise false.
11841 */
11842 public boolean setModemService(String serviceName) {
11843 Log.d(LOG_TAG, "setModemService - " + serviceName);
11844 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11845 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011846 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11847 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080011848 return mPhoneConfigurationManager.setModemService(serviceName);
11849 }
11850
11851 /**
11852 * Return the class name of the currently bounded modem service.
11853 *
11854 * @return the class name of the modem service.
11855 */
11856 public String getModemService() {
11857 String result;
11858 Log.d(LOG_TAG, "getModemService");
11859 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11860 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011861 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080011862 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11863 "getModemService");
11864 result = mPhoneConfigurationManager.getModemService();
11865 Log.d(LOG_TAG, "result = " + result);
11866 return result;
11867 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011868
11869 @Override
11870 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11871 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11872 mApp.enforceCallingOrSelfPermission(
11873 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11874 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11875
11876 final long identity = Binder.clearCallingIdentity();
11877 try {
11878 Phone phone = getPhone(subId);
11879 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080011880 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
11881 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011882 phone.setVoiceServiceStateOverride(hasService);
11883 } finally {
11884 Binder.restoreCallingIdentity(identity);
11885 }
11886 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011887
11888 /**
11889 * set removable eSIM as default eUICC.
11890 *
11891 * @hide
11892 */
11893 @Override
11894 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11895 enforceModifyPermission();
11896 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11897
11898 final long identity = Binder.clearCallingIdentity();
11899 try {
11900 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11901 } finally {
11902 Binder.restoreCallingIdentity(identity);
11903 }
11904 }
11905
11906 /**
11907 * Returns whether the removable eSIM is default eUICC or not.
11908 *
11909 * @hide
11910 */
11911 @Override
11912 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11913 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11914 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11915
11916 final long identity = Binder.clearCallingIdentity();
11917 try {
11918 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11919 } finally {
11920 Binder.restoreCallingIdentity(identity);
11921 }
11922 }
11923
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011924 /**
11925 * Get the component name of the default app to direct respond-via-message intent for the
11926 * user associated with this subscription, update the cache if there is no respond-via-message
11927 * application currently configured for this user.
11928 * @return component name of the app and class to direct Respond Via Message intent to, or
11929 * {@code null} if the functionality is not supported.
11930 * @hide
11931 */
11932 @Override
11933 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
11934 boolean updateIfNeeded) {
11935 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011936
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000011937 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
11938
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011939 UserHandle userHandle = null;
11940 final long identity = Binder.clearCallingIdentity();
11941 try {
11942 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
11943 } finally {
11944 Binder.restoreCallingIdentity(identity);
11945 }
11946 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
11947 updateIfNeeded, userHandle);
11948 }
Jack Yuf5badd92022-12-08 00:50:53 -080011949
11950 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011951 * Set whether the device is able to connect with null ciphering or integrity
11952 * algorithms. This is a global setting and will apply to all active subscriptions
11953 * and all new subscriptions after this.
11954 *
11955 * @param enabled when true, null cipher and integrity algorithms are allowed.
11956 * @hide
11957 */
11958 @Override
11959 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
11960 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
11961 enforceModifyPermission();
11962 checkForNullCipherAndIntegritySupport();
11963
11964 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
11965 // for listening to these preference changes and applying them immediately.
11966 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
11967 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
11968 editor.apply();
11969
11970 for (Phone phone: PhoneFactory.getPhones()) {
11971 phone.handleNullCipherEnabledChange();
11972 }
11973 }
11974
11975
11976 /**
11977 * Get whether the device is able to connect with null ciphering or integrity
11978 * algorithms. Note that this retrieves the phone-global preference and not
11979 * the state of the radio.
11980 *
11981 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
11982 * @throws UnsupportedOperationException if the device does not support the minimum HAL
11983 * version for this feature.
11984 * @hide
11985 */
11986 @Override
11987 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
11988 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
11989 enforceReadPermission();
11990 checkForNullCipherAndIntegritySupport();
11991 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
11992 }
11993
11994 private void checkForNullCipherAndIntegritySupport() {
11995 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
11996 throw new UnsupportedOperationException(
11997 "Null cipher and integrity operations require HAL 2.1 or above");
11998 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000011999 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12000 throw new UnsupportedOperationException(
12001 "Null cipher and integrity operations unsupported by modem");
12002 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012003 }
12004
12005 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012006 * Get the SIM state for the slot index.
12007 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12008 *
12009 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12010 */
12011 @Override
12012 @SimState
12013 public int getSimStateForSlotIndex(int slotIndex) {
12014 IccCardConstants.State simState;
12015 if (slotIndex < 0) {
12016 simState = IccCardConstants.State.UNKNOWN;
12017 } else {
12018 Phone phone = null;
12019 try {
12020 phone = PhoneFactory.getPhone(slotIndex);
12021 } catch (IllegalStateException e) {
12022 // ignore
12023 }
12024 if (phone == null) {
12025 simState = IccCardConstants.State.UNKNOWN;
12026 } else {
12027 IccCard icc = phone.getIccCard();
12028 if (icc == null) {
12029 simState = IccCardConstants.State.UNKNOWN;
12030 } else {
12031 simState = icc.getState();
12032 }
12033 }
12034 }
12035 return simState.ordinal();
12036 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012037
12038 /**
12039 * Get current cell broadcast ranges.
12040 */
12041 @Override
12042 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12043 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12044 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12045 "getCellBroadcastIdRanges");
12046 final long identity = Binder.clearCallingIdentity();
12047 try {
12048 return getPhone(subId).getCellBroadcastIdRanges();
12049 } finally {
12050 Binder.restoreCallingIdentity(identity);
12051 }
12052 }
12053
12054 /**
12055 * Set reception of cell broadcast messages with the list of the given ranges
12056 *
12057 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12058 */
12059 @Override
12060 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12061 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12062 @Nullable IIntegerConsumer callback) {
12063 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12064 "setCellBroadcastIdRanges");
12065 final long identity = Binder.clearCallingIdentity();
12066 try {
12067 Phone phone = getPhoneFromSubId(subId);
12068 if (DBG) {
12069 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12070 }
12071 phone.setCellBroadcastIdRanges(ranges, result -> {
12072 if (callback != null) {
12073 try {
12074 callback.accept(result);
12075 } catch (RemoteException e) {
12076 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12077 }
12078 }
12079 });
12080 } finally {
12081 Binder.restoreCallingIdentity(identity);
12082 }
12083 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012084
12085 /**
12086 * Returns whether the device supports the domain selection service.
12087 *
12088 * @return {@code true} if the device supports the domain selection service.
12089 */
12090 @Override
12091 public boolean isDomainSelectionSupported() {
12092 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12093 "isDomainSelectionSupported");
12094
12095 final long identity = Binder.clearCallingIdentity();
12096 try {
12097 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12098 } finally {
12099 Binder.restoreCallingIdentity(identity);
12100 }
12101 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012102
12103 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012104 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
12105 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
12106 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080012107 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012108 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080012109 * @param enableSatellite {@code true} to enable the satellite modem and
12110 * {@code false} to disable.
12111 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
12112 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080012113 *
12114 * @throws SecurityException if the caller doesn't have the required permission.
12115 */
12116 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012117 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
12118 @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012119 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Sarah Chinabf081b2023-03-09 23:00:57 -080012120 mSatelliteController.requestSatelliteEnabled(subId, enableSatellite, enableDemoMode,
12121 callback);
Sarah Chin503828c2023-02-01 23:54:20 -080012122 }
12123
12124 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012125 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080012126 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012127 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012128 * @param result The result receiver that returns whether the satellite modem is enabled
12129 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012130 *
12131 * @throws SecurityException if the caller doesn't have the required permission.
12132 */
12133 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012134 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
12135 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012136 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012137 }
12138
12139 /**
Sarah Chin43457982023-02-15 17:50:38 -080012140 * Request to get whether the satellite service demo mode is enabled.
12141 *
12142 * @param subId The subId of the subscription to check whether the satellite demo mode
12143 * is enabled for.
12144 * @param result The result receiver that returns whether the satellite demo mode is enabled
12145 * if the request is successful or an error code if the request failed.
12146 *
12147 * @throws SecurityException if the caller doesn't have the required permission.
12148 */
12149 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012150 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
12151 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
12152 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080012153 }
12154
12155 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012156 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080012157 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012158 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012159 * @param result The result receiver that returns whether the satellite service is supported on
12160 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012161 */
12162 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012163 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012164 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012165 }
12166
12167 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012168 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080012169 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012170 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012171 * @param result The result receiver that returns the {@link SatelliteCapabilities}
12172 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012173 *
12174 * @throws SecurityException if the caller doesn't have required permission.
12175 */
12176 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012177 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
12178 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012179 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012180 }
12181
12182 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012183 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080012184 * This can be called by the pointing UI when the user starts pointing to the satellite.
12185 * Modem should continue to report the pointing input as the device or satellite moves.
12186 *
Sarah Chinabf081b2023-03-09 23:00:57 -080012187 * @param subId The subId of the subscription to start satellite transmission updates for.
12188 * @param resultCallback The callback to get the result of the request.
12189 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080012190 *
12191 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012192 */
12193 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012194 public void startSatelliteTransmissionUpdates(int subId,
12195 @NonNull IIntegerConsumer resultCallback,
12196 @NonNull ISatelliteTransmissionUpdateCallback callback) {
12197 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
12198 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080012199 }
12200
12201 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012202 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080012203 * This can be called by the pointing UI when the user stops pointing to the satellite.
12204 *
Sarah Chinabf081b2023-03-09 23:00:57 -080012205 * @param subId The subId of the subscription to stop satellite transmission updates for.
12206 * @param resultCallback The callback to get the result of the request.
12207 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
12208 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080012209 *
12210 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012211 */
12212 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012213 public void stopSatelliteTransmissionUpdates(int subId,
12214 @NonNull IIntegerConsumer resultCallback,
12215 @NonNull ISatelliteTransmissionUpdateCallback callback) {
12216 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
12217 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012218 }
12219
12220 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012221 * Register the subscription with a satellite provider.
12222 * This is needed to register the subscription if the provider allows dynamic registration.
12223 *
12224 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012225 * @param token The token to be used as a unique identifier for provisioning with satellite
12226 * gateway.
Sarah Chinabf081b2023-03-09 23:00:57 -080012227 * @param regionId The region ID for the device's current location.
12228 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080012229 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012230 * @return The signal transport used by the caller to cancel the provision request,
12231 * or {@code null} if the request failed.
12232 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012233 * @throws SecurityException if the caller doesn't have the required permission.
12234 */
12235 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012236 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Sarah Chinabf081b2023-03-09 23:00:57 -080012237 @NonNull String token, @NonNull String regionId, @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012238 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Sarah Chinabf081b2023-03-09 23:00:57 -080012239 return mSatelliteController.provisionSatelliteService(subId, token, regionId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012240 }
12241
12242 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012243 * Unregister the device/subscription with the satellite provider.
12244 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012245 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012246 * should report as deprovisioned.
12247 *
12248 * @param subId The subId of the subscription to be deprovisioned.
12249 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080012250 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012251 *
12252 * @throws SecurityException if the caller doesn't have the required permission.
12253 */
12254 @Override
12255 public void deprovisionSatelliteService(int subId,
12256 @NonNull String token, @NonNull IIntegerConsumer callback) {
12257 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012258 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012259 }
12260
12261 /**
Sarah Chin43457982023-02-15 17:50:38 -080012262 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012263 *
Sarah Chin43457982023-02-15 17:50:38 -080012264 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012265 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012266 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012267 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
12268 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012269 * @throws SecurityException if the caller doesn't have the required permission.
12270 */
12271 @Override
Sarah Chindf715ec2023-02-13 13:46:24 -080012272 @SatelliteManager.SatelliteError public int registerForSatelliteProvisionStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012273 @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012274 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012275 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012276 }
12277
12278 /**
Sarah Chin43457982023-02-15 17:50:38 -080012279 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012280 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012281 *
Sarah Chin43457982023-02-15 17:50:38 -080012282 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012283 * @param callback The callback that was passed to
12284 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012285 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012286 * @throws SecurityException if the caller doesn't have the required permission.
12287 */
12288 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012289 public void unregisterForSatelliteProvisionStateChanged(
12290 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012291 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012292 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012293 }
12294
12295 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012296 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012297 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012298 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012299 * @param result The result receiver that returns whether the device is provisioned with a
12300 * satellite provider if the request is successful or an error code if the
12301 * request failed.
12302 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012303 * @throws SecurityException if the caller doesn't have the required permission.
12304 */
12305 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012306 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
12307 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012308 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012309 }
12310
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012311 /**
Sarah Chin43457982023-02-15 17:50:38 -080012312 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012313 *
Sarah Chin43457982023-02-15 17:50:38 -080012314 * @param subId The subId of the subscription to register for satellite modem state changed.
12315 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080012316 *
12317 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
12318 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012319 * @throws SecurityException if the caller doesn't have the required permission.
12320 */
12321 @Override
Sarah Chin43457982023-02-15 17:50:38 -080012322 @SatelliteManager.SatelliteError public int registerForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012323 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080012324 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012325 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012326 }
12327
12328 /**
Sarah Chin43457982023-02-15 17:50:38 -080012329 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012330 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012331 *
Sarah Chin43457982023-02-15 17:50:38 -080012332 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080012333 * @param callback The callback that was passed to
Sarah Chin43457982023-02-15 17:50:38 -080012334 * {@link #registerForSatelliteModemStateChanged(int, ISatelliteStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012335 *
12336 * @throws SecurityException if the caller doesn't have the required permission.
12337 */
12338 @Override
Sarah Chin43457982023-02-15 17:50:38 -080012339 public void unregisterForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012340 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080012341 enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012342 mSatelliteController.unregisterForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012343 }
12344
12345 /**
12346 * Register to receive incoming datagrams over satellite.
12347 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012348 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080012349 * @param callback The callback to handle incoming datagrams over satellite.
12350 *
12351 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
12352 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012353 * @throws SecurityException if the caller doesn't have the required permission.
12354 */
12355 @Override
Sarah Chindf715ec2023-02-13 13:46:24 -080012356 @SatelliteManager.SatelliteError public int registerForSatelliteDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012357 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012358 enforceSatelliteCommunicationPermission("registerForSatelliteDatagram");
Sarah Chinabf081b2023-03-09 23:00:57 -080012359 return mSatelliteController.registerForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012360 }
12361
12362 /**
12363 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012364 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012365 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012366 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
12367 * @param callback The callback that was passed to
Sarah Chinabf081b2023-03-09 23:00:57 -080012368 * {@link #registerForSatelliteDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012369 *
12370 * @throws SecurityException if the caller doesn't have the required permission.
12371 */
12372 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012373 public void unregisterForSatelliteDatagram(int subId,
12374 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012375 enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012376 mSatelliteController.unregisterForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012377 }
12378
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012379 /**
12380 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080012381 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012382 * This method requests modem to check if there are any pending datagrams to be received over
12383 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000012384 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int,
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012385 * ILongConsumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080012386 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012387 * @param subId The subId of the subscription used for receiving datagrams.
12388 * @param callback The callback to get {@link SatelliteManager.SatelliteError} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080012389 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012390 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012391 */
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012392 @Override
12393 public void pollPendingSatelliteDatagrams(int subId, IIntegerConsumer callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012394 enforceSatelliteCommunicationPermission("pollPendingSatelliteDatagrams");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012395 mSatelliteController.pollPendingSatelliteDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012396 }
12397
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012398 /**
12399 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080012400 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000012401 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
12402 * input to this method. Datagram received here will be passed down to modem without any
12403 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080012404 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012405 * @param subId The subId of the subscription to send satellite datagrams for.
12406 * @param datagramType datagram type indicating whether the datagram is of type
12407 * SOS_SMS or LOCATION_SHARING.
12408 * @param datagram encoded gateway datagram which is encrypted by the caller.
12409 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000012410 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
12411 * full screen mode.
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012412 * @param callback The callback to get {@link SatelliteManager.SatelliteError} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012413 *
12414 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012415 */
12416 @Override
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012417 public void sendSatelliteDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
12418 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
12419 @NonNull IIntegerConsumer callback) {
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012420 enforceSatelliteCommunicationPermission("sendSatelliteDatagram");
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012421 mSatelliteController.sendSatelliteDatagram(subId, datagramType, datagram,
12422 needFullScreenPointingUI, callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012423 }
12424
Sarah Chindf715ec2023-02-13 13:46:24 -080012425 /**
12426 * Request to get whether satellite communication is allowed for the current location.
12427 *
12428 * @param subId The subId of the subscription to check whether satellite communication is
12429 * allowed for the current location for.
12430 * @param result The result receiver that returns whether satellite communication is allowed
12431 * for the current location if the request is successful or an error code
12432 * if the request failed.
12433 *
12434 * @throws SecurityException if the caller doesn't have the required permission.
12435 */
12436 @Override
12437 public void requestIsSatelliteCommunicationAllowedForCurrentLocation(int subId,
12438 @NonNull ResultReceiver result) {
12439 enforceSatelliteCommunicationPermission(
12440 "requestIsSatelliteCommunicationAllowedForCurrentLocation");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012441 mSatelliteController.requestIsSatelliteCommunicationAllowedForCurrentLocation(subId,
12442 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080012443 }
12444
12445 /**
Sarah Chin5f57c582023-02-14 04:16:10 -080012446 * Request to get the time after which the satellite will be visible
Sarah Chindf715ec2023-02-13 13:46:24 -080012447 *
Sarah Chin5f57c582023-02-14 04:16:10 -080012448 * @param subId The subId to get the time after which the satellite will be visible for.
12449 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080012450 * be visible if the request is successful or an error code if the request failed.
12451 *
12452 * @throws SecurityException if the caller doesn't have the required permission.
12453 */
12454 @Override
12455 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
12456 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012457 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012458 }
12459
12460 private Phone getPhoneOrDefault(int subId, String caller) {
12461 Phone phone = getPhone(subId);
12462 if (phone == null) {
12463 loge(caller + " called with invalid subId: " + subId
12464 + ". Retrying with default phone.");
12465 phone = getDefaultPhone();
12466 if (phone == null) {
12467 loge(caller + " failed with no phone object.");
12468 }
12469 }
12470 return phone;
12471 }
12472
12473 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000012474 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
12475 *
12476 * <p>This method behaves in one of the following ways:
12477 * <ul>
12478 * <li>return true : if the calling package has the appop permission {@link
12479 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
12480 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
12481 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
12482 * Owner device identifier access check, or the calling package has carrier privileges</>
12483 * <li>throw SecurityException: if the caller does not meet any of the requirements.
12484 * </ul>
12485 */
12486 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
12487 String callingPackage, @Nullable String callingFeatureId, String message) {
12488 for (Phone phone : PhoneFactory.getPhones()) {
12489 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
12490 phone.getSubId(), callingPackage, callingFeatureId, message)) {
12491 return true;
12492 }
12493 }
12494 return false;
12495 }
arunvoddud7401012022-12-15 16:08:12 +000012496
12497 /**
Jack Yufa8ed012023-02-11 15:42:28 -080012498 * @return The subscription manager service instance.
12499 */
12500 public SubscriptionManagerService getSubscriptionManagerService() {
12501 return SubscriptionManagerService.getInstance();
12502 }
12503
12504 /**
arunvoddud7401012022-12-15 16:08:12 +000012505 * Class binds the consumer[callback] and carrierId.
12506 */
12507 private static class CallerCallbackInfo {
12508 private final Consumer<Integer> mConsumer;
12509 private final int mCarrierId;
12510
12511 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
12512 mConsumer = consumer;
12513 mCarrierId = carrierId;
12514 }
12515
12516 public Consumer<Integer> getConsumer() {
12517 return mConsumer;
12518 }
12519
12520 public int getCarrierId() {
12521 return mCarrierId;
12522 }
12523 }
Jack Yufa8ed012023-02-11 15:42:28 -080012524}