blob: de6c625bf81e7fba841e5e22fba419f9c95e7f56 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
Gil Cukierman1c0eb932022-12-06 22:28:24 +000020import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK;
jimsunf9ec1622022-09-13 21:18:43 +080021import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO;
Hall Liud892bec2018-11-30 14:51:45 -080022
Shuo Qianccbaf742021-02-22 18:32:21 -080023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
24import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070025import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070026import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000027import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070028
Brad Ebinger34c09a52021-02-17 23:23:21 +000029import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080030import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080031import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070032import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000033import android.annotation.RequiresPermission;
Sarah Chin532d6bb2022-12-28 22:50:43 -080034import android.app.ActivityManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080036import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070037import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000038import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080039import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000040import android.compat.annotation.ChangeId;
41import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070042import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070043import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.content.Context;
45import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070046import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070047import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070048import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049import android.net.Uri;
50import android.os.AsyncResult;
51import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080052import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.os.Bundle;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080054import android.os.CancellationSignal;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070056import android.os.IBinder;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080057import android.os.ICancellationSignal;
tom hsu0b59d292022-09-29 23:49:21 +080058import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070059import android.os.Looper;
60import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070061import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080062import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070063import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070064import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080065import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080066import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070067import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070068import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080069import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070070import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070071import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070072import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070073import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070074import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080075import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070076import android.provider.Telephony;
arunvoddud7401012022-12-15 16:08:12 +000077import android.service.carrier.CarrierIdentifier;
Inseob Kim14bb3d02018-12-13 17:11:34 +090078import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080079import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080080import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070081import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080082import android.telephony.AccessNetworkConstants;
83import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070084import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070085import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080086import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070087import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080088import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070089import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080090import android.telephony.CarrierRestrictionRules;
Hui Wang9b5793a2022-12-05 14:38:06 -060091import android.telephony.CellBroadcastIdRange;
yincheng zhao2737e882019-09-06 17:06:54 -070092import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080093import android.telephony.CellIdentityCdma;
94import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070096import android.telephony.CellInfoGsm;
97import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070098import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080099import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -0700100import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700101import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700102import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -0800103import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700104import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -0800105import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -0700106import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800107import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800108import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700109import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800110import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700111import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800112import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800113import android.telephony.SignalStrengthUpdateRequest;
114import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800115import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800116import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800117import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700118import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700119import android.telephony.TelephonyManager;
Jack Yuf5badd92022-12-08 00:50:53 -0800120import android.telephony.TelephonyManager.SimState;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800121import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800122import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800123import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000124import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000125import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000126import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700127import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700128import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800129import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800130import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700131import android.telephony.gba.GbaAuthRequest;
132import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700133import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800134import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000135import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000136import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700137import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000138import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700139import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800140import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700141import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800142import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700143import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000144import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700145import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800146import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800147import android.telephony.ims.stub.ImsRegistrationImplBase;
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800148import android.telephony.satellite.ISatelliteStateListener;
Sarah Chineccfbd12023-01-20 19:00:35 -0800149import android.telephony.satellite.PointingInfo;
Aishwarya Mallampati224317a2023-02-13 22:09:30 +0000150import android.telephony.satellite.SatelliteCallback;
Sarah Chin503828c2023-02-01 23:54:20 -0800151import android.telephony.satellite.SatelliteCapabilities;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000152import android.telephony.satellite.SatelliteDatagram;
Sarah Chineccfbd12023-01-20 19:00:35 -0800153import android.telephony.satellite.SatelliteManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700154import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800155import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700156import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700157import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800158import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800159
Andrew Lee312e8172014-10-23 17:01:36 -0700160import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800161import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800162import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800163import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800164import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700165import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700166import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700167import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800168import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800169import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700170import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700171import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800172import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700173import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800174import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800175import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800176import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700177import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000178import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700179import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800180import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700181import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800182import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800183import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800184import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700185import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700186import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700187import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700188import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700189import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800190import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700191import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700192import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700193import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700194import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800195import com.android.internal.telephony.RILConstants;
Sarah Chineccfbd12023-01-20 19:00:35 -0800196import com.android.internal.telephony.RILUtils;
Daniel Bright94f43662021-03-01 14:43:40 -0800197import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700198import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000199import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700200import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700201import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800202import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800203import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800204import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700205import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000206import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800207import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700208import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800209import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700210import com.android.internal.telephony.imsphone.ImsPhone;
211import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000212import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800213import com.android.internal.telephony.metrics.TelephonyMetrics;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800214import com.android.internal.telephony.satellite.SatelliteServiceController;
Jack Yu285100e2022-12-02 22:48:35 -0800215import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
216import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700217import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700218import com.android.internal.telephony.uicc.IccIoResult;
219import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800220import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700221import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800222import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700223import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000224import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800225import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000226import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800227import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000228import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700229import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700230import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800231import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800232import com.android.phone.callcomposer.CallComposerPictureManager;
233import com.android.phone.callcomposer.CallComposerPictureTransfer;
234import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700235import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700236import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000237import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700238import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800239import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700240import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700241import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800242import com.android.services.telephony.TelecomAccountRegistry;
243import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800244import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800245
Hall Liu82694d52020-12-11 18:22:04 -0800246import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700247import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800248import java.io.IOException;
249import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700250import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700251import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800252import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000253import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800254import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800255import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800256import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800257import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100258import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800259import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700260import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800261import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800262import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700263import java.util.UUID;
Sarah Chineccfbd12023-01-20 19:00:35 -0800264import java.util.concurrent.ConcurrentHashMap;
Hall Liu82694d52020-12-11 18:22:04 -0800265import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800266import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800267import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700268
269/**
270 * Implementation of the ITelephony interface.
271 */
Santos Cordon117fee72014-05-16 17:56:12 -0700272public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700273 private static final String LOG_TAG = "PhoneInterfaceManager";
274 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
275 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800276 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700277
278 // Message codes used with mMainThreadHandler
279 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700280 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
281 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700282 private static final int CMD_OPEN_CHANNEL = 9;
283 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
284 private static final int CMD_CLOSE_CHANNEL = 11;
285 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800286 private static final int CMD_NV_READ_ITEM = 13;
287 private static final int EVENT_NV_READ_ITEM_DONE = 14;
288 private static final int CMD_NV_WRITE_ITEM = 15;
289 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
290 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
291 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700292 private static final int CMD_RESET_MODEM_CONFIG = 19;
293 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800294 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
295 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800296 private static final int CMD_SEND_ENVELOPE = 25;
297 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000298 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
299 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700300 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
301 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
302 private static final int CMD_EXCHANGE_SIM_IO = 31;
303 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800304 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
305 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700306 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
307 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700308 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
309 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700310 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
311 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
312 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
313 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700314 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
315 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
316 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
317 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700318 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800319 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
320 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000321 private static final int CMD_SWITCH_SLOTS = 50;
322 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700323 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
324 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
325 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
326 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
327 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
328 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
329 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
330 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700331 private static final int CMD_GET_ALL_CELL_INFO = 60;
332 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
333 private static final int CMD_GET_CELL_LOCATION = 62;
334 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700335 private static final int CMD_MODEM_REBOOT = 64;
336 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700337 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
338 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800339 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
340 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700341 private static final int CMD_GET_MODEM_STATUS = 70;
342 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700343 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
344 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700345 private static final int CMD_ERASE_MODEM_CONFIG = 74;
346 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800347 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
348 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
349 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
350 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800351 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
352 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800353 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800354 private static final int CMD_GET_CALL_FORWARDING = 83;
355 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
356 private static final int CMD_SET_CALL_FORWARDING = 85;
357 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
358 private static final int CMD_GET_CALL_WAITING = 87;
359 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
360 private static final int CMD_SET_CALL_WAITING = 89;
361 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700362 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
363 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
364 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
365 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700366 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
367 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800368 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
369 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800370 private static final int CMD_SET_DATA_THROTTLING = 99;
371 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800372 private static final int CMD_SET_SIM_POWER = 101;
373 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800374 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
375 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
376 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
377 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800378 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
379 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000380 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800381 private static final int CMD_GET_SLICING_CONFIG = 110;
382 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800383 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700384 private static final int CMD_ENABLE_VONR = 113;
385 private static final int EVENT_ENABLE_VONR_DONE = 114;
386 private static final int CMD_IS_VONR_ENABLED = 115;
387 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700388 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
389 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Sarah Chineccfbd12023-01-20 19:00:35 -0800390 private static final int CMD_START_SATELLITE_POSITION_UPDATES = 119;
391 private static final int EVENT_START_SATELLITE_POSITION_UPDATES_DONE = 120;
392 private static final int CMD_STOP_SATELLITE_POSITION_UPDATES = 121;
393 private static final int EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE = 122;
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +0000394 private static final int CMD_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG = 123;
395 private static final int EVENT_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG_DONE = 124;
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800396 private static final int CMD_PROVISION_SATELLITE_SERVICE = 125;
397 private static final int EVENT_PROVISION_SATELLITE_SERVICE_DONE = 126;
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -0800398 private static final int CMD_DEPROVISION_SATELLITE_SERVICE = 127;
399 private static final int EVENT_DEPROVISION_SATELLITE_SERVICE_DONE = 128;
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800400 private static final int CMD_SET_SATELLITE_ENABLED = 129;
401 private static final int EVENT_SET_SATELLITE_ENABLED_DONE = 130;
402 private static final int CMD_IS_SATELLITE_ENABLED = 131;
403 private static final int EVENT_IS_SATELLITE_ENABLED_DONE = 132;
404 private static final int CMD_IS_SATELLITE_SUPPORTED = 133;
405 private static final int EVENT_IS_SATELLITE_SUPPORTED_DONE = 134;
406 private static final int CMD_GET_SATELLITE_CAPABILITIES = 135;
407 private static final int EVENT_GET_SATELLITE_CAPABILITIES_DONE = 136;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000408 private static final int CMD_POLL_PENDING_SATELLITE_DATAGRAMS = 137;
409 private static final int EVENT_POLL_PENDING_SATELLITE_DATAGRAMS_DONE = 138;
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +0000410 private static final int CMD_SEND_SATELLITE_DATAGRAM = 139;
411 private static final int EVENT_SEND_SATELLITE_DATAGRAM_DONE = 140;
Sarah Chindf715ec2023-02-13 13:46:24 -0800412 private static final int CMD_IS_SATELLITE_COMMUNICATION_ALLOWED = 141;
413 private static final int EVENT_IS_SATELLITE_COMMUNICATION_ALLOWED_DONE = 142;
414 private static final int CMD_GET_TIME_SATELLITE_NEXT_VISIBLE = 143;
415 private static final int EVENT_GET_TIME_SATELLITE_NEXT_VISIBLE_DONE = 144;
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800416 // Parameters of select command.
417 private static final int SELECT_COMMAND = 0xA4;
418 private static final int SELECT_P1 = 0x04;
419 private static final int SELECT_P2 = 0;
420 private static final int SELECT_P3 = 0x10;
421
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000422 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
423 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
424
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700425 /** The singleton instance. */
426 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800427 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700428
Sarah Chin4beb2b72023-02-14 14:47:54 -0800429 private final PhoneGlobals mApp;
430 private final CallManager mCM;
431 private final ImsResolver mImsResolver;
432 private final SatelliteServiceController mSatelliteServiceController;
433 private final UserManager mUserManager;
434 private final AppOpsManager mAppOps;
435 private final MainThreadHandler mMainThreadHandler;
Jack Yue37dd262022-12-16 11:53:37 -0800436 private final SubscriptionController mSubscriptionController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800437 private final SharedPreferences mTelephonySharedPreferences;
438 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800439 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700440
Peter Wangdafb9ac2020-01-15 14:13:38 -0800441 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800442 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800443 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
444
Sarah Chin4beb2b72023-02-14 14:47:54 -0800445 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800446
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800447 /**
448 * Map key: subId, value: callback to get error code of the provision request.
449 */
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800450 private final ConcurrentHashMap<Integer, Consumer<Integer>> mSatelliteProvisionCallbacks =
Sarah Chineccfbd12023-01-20 19:00:35 -0800451 new ConcurrentHashMap<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800452 /**
453 * Map key: subId, value: SatellitePositionUpdateHandler to notify registrants.
454 */
455 private final ConcurrentHashMap<IBinder, SatellitePositionUpdateHandler>
456 mSatellitePositionUpdateHandlers = new ConcurrentHashMap<>();
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800457 /**
458 * Map key: subId, value: SatelliteProvisionStateChangedHandler to notify registrants.
459 */
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800460 private final ConcurrentHashMap<Integer, SatelliteProvisionStateChangedHandler>
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800461 mSatelliteProvisionStateChangedHandlers = new ConcurrentHashMap<>();
462
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800463 private Boolean mIsSatelliteSupported = null;
464 private final Object mIsSatelliteSupportedLock = new Object();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800465 private final ResultReceiver mSatelliteSupportedReceiver;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800466 /**
467 * {@code true} to use the vendor satellite service and {@code false} to use the HAL.
468 */
469 private final boolean mIsSatelliteServiceSupported = false;
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800470
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000471 /**
472 * Map key: subId, value: SatelliteStateChangeHandler to notify registrants.
473 */
474 private ConcurrentHashMap<Integer, SatelliteStateListenerHandler>
475 mSatelliteStateListenerHandlers = new ConcurrentHashMap<>();
476
477 /**
478 * Map key: subId, value: SatelliteDatagramListenerHandler to notify registrants.
479 */
480 private ConcurrentHashMap<Integer, SatelliteDatagramListenerHandler>
481 mSatelliteDatagramListenerHandlers = new ConcurrentHashMap<>();
482
Derek Tan97ebb422014-09-05 16:55:38 -0700483 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
484 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800485 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800486 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700487
Michelecea4cf22018-12-21 15:00:11 -0800488 // String to store multi SIM allowed
489 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
490
Derek Tan740e1672017-06-27 14:56:27 -0700491 // The AID of ISD-R.
492 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
493
yinxub1bed742017-04-17 11:45:04 -0700494 private NetworkScanRequestTracker mNetworkScanRequestTracker;
495
David Kelly5e06a7f2018-03-12 14:10:59 +0000496 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
497 private static final int MANUFACTURER_CODE_LENGTH = 8;
498
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800499 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800500 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800501
Sarah Chin2ec39f62022-08-31 17:03:26 -0700502 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
503 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
504
Derek Tan89e89d42014-07-08 17:00:10 -0700505 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700506 * Experiment flag to enable erase modem config on reset network, default value is false
507 */
508 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
509 "reset_network_erase_modem_config_enabled";
510
Rambo Wang0f050d82021-02-12 11:43:36 -0800511 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800512
Gary Jian76280a42022-12-07 16:18:33 +0800513 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
514
sandeepjsb6c87872021-09-27 15:34:44 +0000515 /**
516 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
517 * one ICCID active at the same time.
518 * Apps should use below API signatures if targeting SDK is T and beyond.
519 *
520 * @hide
521 */
522 @ChangeId
523 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
524 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800525
Naina Nallurid63128d2019-09-17 14:10:30 -0700526 /**
Chen Xu540470b2021-12-14 17:15:47 -0800527 * Apps targeting on Android T and beyond will get exception whenever icc close channel
528 * operation fails.
529 */
530 @ChangeId
531 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
532 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
533
534 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700535 * A request object to use for transmitting data to an ICC.
536 */
537 private static final class IccAPDUArgument {
538 public int channel, cla, command, p1, p2, p3;
539 public String data;
540
541 public IccAPDUArgument(int channel, int cla, int command,
542 int p1, int p2, int p3, String data) {
543 this.channel = channel;
544 this.cla = cla;
545 this.command = command;
546 this.p1 = p1;
547 this.p2 = p2;
548 this.p3 = p3;
549 this.data = data;
550 }
551 }
552
553 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700554 * A request object to use for transmitting data to an ICC.
555 */
556 private static final class ManualNetworkSelectionArgument {
557 public OperatorInfo operatorInfo;
558 public boolean persistSelection;
559
560 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
561 this.operatorInfo = operatorInfo;
562 this.persistSelection = persistSelection;
563 }
564 }
565
Sarah Chin71b3a852022-09-28 15:54:19 -0700566 private static final class PurchasePremiumCapabilityArgument {
567 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700568 public @NonNull IIntegerConsumer callback;
569
570 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800571 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700572 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700573 this.callback = callback;
574 }
575 }
576
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800577 private static final class ProvisionSatelliteServiceArgument {
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800578 public @NonNull String token;
579 public @NonNull Consumer<Integer> callback;
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800580 public int subId;
581
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800582 ProvisionSatelliteServiceArgument(String token, Consumer<Integer> callback, int subId) {
583 this.token = token;
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800584 this.callback = callback;
585 this.subId = subId;
586 }
587 }
588
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +0000589 private static final class SendSatelliteDatagramArgument {
590 public @SatelliteManager.DatagramType int datagramType;
591 public @NonNull SatelliteDatagram datagram;
592 public @NonNull Consumer<Integer> callback;
593
594 SendSatelliteDatagramArgument(@SatelliteManager.DatagramType int datagramType,
595 SatelliteDatagram datagram, Consumer<Integer> callback) {
596 this.datagramType = datagramType;
597 this.datagram = datagram;
598 this.callback = callback;
599 }
600 }
601
Sarah Chineccfbd12023-01-20 19:00:35 -0800602 private static final class SatellitePositionUpdateHandler extends Handler {
603 public static final int EVENT_POSITION_UPDATE = 1;
604 public static final int EVENT_MESSAGE_TRANSFER_STATE_UPDATE = 2;
605
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800606 private final ISatelliteStateListener mCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800607
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800608 SatellitePositionUpdateHandler(ISatelliteStateListener callback, Looper looper) {
Sarah Chineccfbd12023-01-20 19:00:35 -0800609 super(looper);
610 mCallback = callback;
611 }
612
613 @Override
614 public void handleMessage(@NonNull Message msg) {
615 switch (msg.what) {
616 case EVENT_POSITION_UPDATE: {
617 AsyncResult ar = (AsyncResult) msg.obj;
618 PointingInfo pointingInfo = (PointingInfo) ar.result;
619 try {
620 mCallback.onSatellitePositionUpdate(pointingInfo);
621 } catch (RemoteException e) {
622 loge("EVENT_POSITION_UPDATE RemoteException: " + e);
623 }
624 break;
625 }
626 case EVENT_MESSAGE_TRANSFER_STATE_UPDATE: {
627 AsyncResult ar = (AsyncResult) msg.obj;
628 int state = (int) ar.result;
629 try {
Sarah Chindf715ec2023-02-13 13:46:24 -0800630 // TODO: get correct responses back from indication
631 mCallback.onMessageTransferStateUpdate(state, 0, 0, 0);
Sarah Chineccfbd12023-01-20 19:00:35 -0800632 } catch (RemoteException e) {
633 loge("EVENT_MESSAGE_TRANSFER_STATE_UPDATE RemoteException: " + e);
634 }
635 break;
636 }
637 default:
638 loge("SatellitePositionUpdateHandler unknown event: " + msg.what);
639 }
640 }
641 }
642
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800643 private static final class SatelliteProvisionStateChangedHandler extends Handler {
644 public static final int EVENT_PROVISION_STATE_CHANGED = 1;
645
646 private ConcurrentHashMap<IBinder, ISatelliteStateListener> mListeners;
647 private final int mSubId;
648
649 SatelliteProvisionStateChangedHandler(Looper looper, int subId) {
650 super(looper);
651 mListeners = new ConcurrentHashMap<>();
652 mSubId = subId;
653 }
654
655 public void addListener(ISatelliteStateListener listener) {
656 mListeners.put(listener.asBinder(), listener);
657 }
658
659 public boolean removeListener(ISatelliteStateListener listener) {
660 return (mListeners.remove(listener.asBinder()) != null);
661 }
662
663 @Override
664 public void handleMessage(@NonNull Message msg) {
665 switch (msg.what) {
666 case EVENT_PROVISION_STATE_CHANGED: {
667 AsyncResult ar = (AsyncResult) msg.obj;
668 boolean provisioned = (boolean) ar.userObj;
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800669 log("Received EVENT_PROVISION_STATE_CHANGED for subId=" + mSubId
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800670 + ", provisioned=" + provisioned);
671 mListeners.values().forEach(listener -> {
672 try {
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -0800673 listener.onSatelliteProvisionStateChanged(provisioned);
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800674 } catch (RemoteException e) {
675 log("EVENT_PROVISION_STATE_CHANGED RemoteException: " + e);
676 }
677 });
678
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800679 setSatelliteProvisioned(provisioned);
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800680 /**
681 * TODO: Take bugreport if provisioned is true and user did not initiate the
682 * provision procedure for the corresponding subscription.
683 */
684 break;
685 }
686 default:
687 loge("SatelliteProvisionStateChangedHandler unknown event: " + msg.what);
688 }
689 }
690
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800691 private void setSatelliteProvisioned(boolean isProvisioned) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800692 if (mSubId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
693 SubscriptionManager.setSubscriptionProperty(
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800694 mSubId, SubscriptionManager.SATELLITE_ENABLED, isProvisioned ? "1" : "0");
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800695 } else {
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800696 //TODO (b/267826133): set via SatelliteController.
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800697 }
698 }
699 }
700
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000701 private static final class SatelliteStateListenerHandler extends Handler {
702 public static final int EVENT_SATELLITE_MODEM_STATE_CHANGE = 1;
Aishwarya Mallampati224317a2023-02-13 22:09:30 +0000703 public static final int EVENT_PENDING_DATAGRAM_COUNT = 2;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000704
705 private ConcurrentHashMap<IBinder, ISatelliteStateListener> mListeners;
706 private final int mSubId;
707
708 SatelliteStateListenerHandler(Looper looper, int subId) {
709 super(looper);
710 mSubId = subId;
711 mListeners = new ConcurrentHashMap<>();
712 }
713
714 public void addListener(ISatelliteStateListener listener) {
715 mListeners.put(listener.asBinder(), listener);
716 }
717
718 public boolean removeListener(ISatelliteStateListener listener) {
719 return (mListeners.remove(listener.asBinder()) != null);
720 }
721
722 @Override
723 public void handleMessage(@NonNull Message msg) {
724 switch (msg.what) {
725 case EVENT_SATELLITE_MODEM_STATE_CHANGE : {
726 AsyncResult ar = (AsyncResult) msg.obj;
727 int state = (int) ar.result;
728 log("Received EVENT_SATELLITE_MODEM_STATE_CHANGE for subId=" + mSubId
729 + ", state=" + state);
730 mListeners.values().forEach(listener -> {
731 try {
732 listener.onSatelliteModemStateChange(state);
733 } catch (RemoteException e) {
734 log("EVENT_SATELLITE_MODEM_STATE_CHANGE RemoteException: " + e);
735 }
736 });
737 break;
738 }
Aishwarya Mallampati224317a2023-02-13 22:09:30 +0000739 case EVENT_PENDING_DATAGRAM_COUNT: {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000740 AsyncResult ar = (AsyncResult) msg.obj;
741 int count = (int) ar.result;
Aishwarya Mallampati224317a2023-02-13 22:09:30 +0000742 log("Received EVENT_PENDING_DATAGRAM_COUNT for subId=" + mSubId
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000743 + ", count=" + count);
744 mListeners.values().forEach(listener -> {
745 try {
Aishwarya Mallampati224317a2023-02-13 22:09:30 +0000746 listener.onPendingDatagramCount(count);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000747 } catch (RemoteException e) {
Aishwarya Mallampati224317a2023-02-13 22:09:30 +0000748 log("EVENT_PENDING_DATAGRAM_COUNT RemoteException: " + e);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000749 }
750 });
751 break;
752 }
753 default:
754 loge("SatelliteStateListenerHandler unknown event: " + msg.what);
755 }
756 }
757 }
758
759 private static final class SatelliteDatagramListenerHandler extends Handler {
760 public static final int EVENT_SATELLITE_DATAGRAMS_RECEIVED = 1;
761
762 private ConcurrentHashMap<IBinder, ISatelliteStateListener> mListeners;
763 private final int mSubId;
764
765 SatelliteDatagramListenerHandler(Looper looper, int subId) {
766 super(looper);
767 mSubId = subId;
768 mListeners = new ConcurrentHashMap<>();
769 }
770
771 public void addListener(ISatelliteStateListener listener) {
772 mListeners.put(listener.asBinder(), listener);
773 }
774
775 public boolean removeListener(ISatelliteStateListener listener) {
776 return (mListeners.remove(listener.asBinder()) != null);
777 }
778
779 @Override
780 public void handleMessage(@NonNull Message msg) {
781 switch (msg.what) {
782 case EVENT_SATELLITE_DATAGRAMS_RECEIVED : {
783 AsyncResult ar = (AsyncResult) msg.obj;
784 byte[][] datagrams = (byte[][]) ar.result;
785 SatelliteDatagram[] satelliteDatagramArray =
786 convertToSatelliteDatagramArray(datagrams);
787
788 log("Received EVENT_SATELLITE_DATAGRAMS_RECEIVED for subId=" + mSubId);
789 mListeners.values().forEach(listener -> {
790 try {
791 listener.onSatelliteDatagrams(satelliteDatagramArray);
792 } catch (RemoteException e) {
793 log("EVENT_SATELLITE_DATAGRAMS_RECEIVED RemoteException: " + e);
794 }
795 });
796 break;
797 }
798 default:
799 loge("SatelliteDatagramListenerHandler unknown event: " + msg.what);
800 }
801 }
802 }
803
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700804 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700805 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
806 * request after sending. The main thread will notify the request when it is complete.
807 */
808 private static final class MainThreadRequest {
809 /** The argument to use for the request */
810 public Object argument;
811 /** The result of the request that is run on the main thread */
812 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800813 // The subscriber id that this request applies to. Defaults to
814 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
815 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700816
Nathan Harold92bed182018-10-12 18:16:49 -0700817 // In cases where subId is unavailable, the caller needs to specify the phone.
818 public Phone phone;
819
vagdeviaf9a5b92018-08-15 16:01:53 -0700820 public WorkSource workSource;
821
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700822 public MainThreadRequest(Object argument) {
823 this.argument = argument;
824 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800825
Nathan Harold92bed182018-10-12 18:16:49 -0700826 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
827 this.argument = argument;
828 if (phone != null) {
829 this.phone = phone;
830 }
831 this.workSource = workSource;
832 }
833
vagdeviaf9a5b92018-08-15 16:01:53 -0700834 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800835 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800836 if (subId != null) {
837 this.subId = subId;
838 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700839 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800840 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700841 }
842
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800843 private static final class IncomingThirdPartyCallArgs {
844 public final ComponentName component;
845 public final String callId;
846 public final String callerDisplayName;
847
848 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
849 String callerDisplayName) {
850 this.component = component;
851 this.callId = callId;
852 this.callerDisplayName = callerDisplayName;
853 }
854 }
855
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700856 /**
857 * A handler that processes messages on the main thread in the phone process. Since many
858 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
859 * inbound binder threads to the main thread in the phone process. The Binder thread
860 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
861 * on, which will be notified when the operation completes and will contain the result of the
862 * request.
863 *
864 * <p>If a MainThreadRequest object is provided in the msg.obj field,
865 * note that request.result must be set to something non-null for the calling thread to
866 * unblock.
867 */
868 private final class MainThreadHandler extends Handler {
869 @Override
870 public void handleMessage(Message msg) {
871 MainThreadRequest request;
872 Message onCompleted;
873 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000874 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700875 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800876 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700877
878 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700879 case CMD_HANDLE_USSD_REQUEST: {
880 request = (MainThreadRequest) msg.obj;
881 final Phone phone = getPhoneFromRequest(request);
882 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800883 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700884 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700885
Pengquan Menga1bb6272018-09-06 09:59:22 -0700886 if (!isUssdApiAllowed(request.subId)) {
887 // Carrier does not support use of this API, return failure.
888 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
889 UssdResponse response = new UssdResponse(ussdRequest, null);
890 Bundle returnData = new Bundle();
891 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
892 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700893
Pengquan Menga1bb6272018-09-06 09:59:22 -0700894 request.result = true;
895 notifyRequester(request);
896 return;
897 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700898
Pengquan Menga1bb6272018-09-06 09:59:22 -0700899 try {
900 request.result = phone != null
901 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
902 } catch (CallStateException cse) {
903 request.result = false;
904 }
905 // Wake up the requesting thread
906 notifyRequester(request);
907 break;
pkanwar32d516d2016-10-14 19:37:38 -0700908 }
909
Yorke Lee716f67e2015-06-17 15:39:16 -0700910 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700911 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700912 final Phone phone = getPhoneFromRequest(request);
913 request.result = phone != null ?
914 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
915 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700916 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700917 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700918 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700919 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700920
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700921 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700922 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700923 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000924 uiccPort = getUiccPortFromRequest(request);
925 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700926 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800927 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700928 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700929 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700930 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800931 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000932 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800933 iccArgument.channel, iccArgument.cla, iccArgument.command,
934 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
935 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700936 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700937 break;
938
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700939 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700940 ar = (AsyncResult) msg.obj;
941 request = (MainThreadRequest) ar.userObj;
942 if (ar.exception == null && ar.result != null) {
943 request.result = ar.result;
944 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800945 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700946 if (ar.result == null) {
947 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800948 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700949 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800950 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700951 } else {
952 loge("iccTransmitApduLogicalChannel: Unknown exception");
953 }
954 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700955 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700956 break;
957
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700958 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
959 request = (MainThreadRequest) msg.obj;
960 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000961 uiccPort = getUiccPortFromRequest(request);
962 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700963 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800964 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700965 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700966 } else {
967 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800968 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000969 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800970 iccArgument.cla, iccArgument.command, iccArgument.p1,
971 iccArgument.p2,
972 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700973 }
974 break;
975
976 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
977 ar = (AsyncResult) msg.obj;
978 request = (MainThreadRequest) ar.userObj;
979 if (ar.exception == null && ar.result != null) {
980 request.result = ar.result;
981 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800982 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700983 if (ar.result == null) {
984 loge("iccTransmitApduBasicChannel: Empty response");
985 } else if (ar.exception instanceof CommandException) {
986 loge("iccTransmitApduBasicChannel: CommandException: " +
987 ar.exception);
988 } else {
989 loge("iccTransmitApduBasicChannel: Unknown exception");
990 }
991 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700992 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700993 break;
994
995 case CMD_EXCHANGE_SIM_IO:
996 request = (MainThreadRequest) msg.obj;
997 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000998 uiccPort = getUiccPortFromRequest(request);
999 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001000 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -08001001 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001002 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001003 } else {
1004 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
1005 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001006 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001007 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
1008 iccArgument.data, onCompleted);
1009 }
1010 break;
1011
1012 case EVENT_EXCHANGE_SIM_IO_DONE:
1013 ar = (AsyncResult) msg.obj;
1014 request = (MainThreadRequest) ar.userObj;
1015 if (ar.exception == null && ar.result != null) {
1016 request.result = ar.result;
1017 } else {
Chen Xue9d737e2022-01-01 23:41:31 -08001018 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001019 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001020 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001021 break;
1022
Derek Tan4d5e5c12014-02-04 11:54:58 -08001023 case CMD_SEND_ENVELOPE:
1024 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001025 uiccPort = getUiccPortFromRequest(request);
1026 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001027 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -08001028 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001029 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001030 } else {
1031 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -08001032 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001033 }
Derek Tan4d5e5c12014-02-04 11:54:58 -08001034 break;
1035
1036 case EVENT_SEND_ENVELOPE_DONE:
1037 ar = (AsyncResult) msg.obj;
1038 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -07001039 if (ar.exception == null && ar.result != null) {
1040 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -08001041 } else {
Chen Xue9d737e2022-01-01 23:41:31 -08001042 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -07001043 if (ar.result == null) {
1044 loge("sendEnvelopeWithStatus: Empty response");
1045 } else if (ar.exception instanceof CommandException) {
1046 loge("sendEnvelopeWithStatus: CommandException: " +
1047 ar.exception);
1048 } else {
1049 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
1050 }
Derek Tan4d5e5c12014-02-04 11:54:58 -08001051 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001052 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -08001053 break;
1054
Shishir Agrawal566b7612013-10-28 14:41:00 -07001055 case CMD_OPEN_CHANNEL:
1056 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001057 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -08001058 IccLogicalChannelRequest openChannelRequest =
1059 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001060 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001061 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -08001062 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -08001063 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001064 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001065 } else {
1066 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -08001067 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
1068 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001069 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07001070 break;
1071
1072 case EVENT_OPEN_CHANNEL_DONE:
1073 ar = (AsyncResult) msg.obj;
1074 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001075 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -07001076 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001077 int[] result = (int[]) ar.result;
1078 int channelId = result[0];
1079 byte[] selectResponse = null;
1080 if (result.length > 1) {
1081 selectResponse = new byte[result.length - 1];
1082 for (int i = 1; i < result.length; ++i) {
1083 selectResponse[i - 1] = (byte) result[i];
1084 }
1085 }
1086 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -08001087 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -08001088
1089 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -07001090 if (uiccPort == null) {
1091 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
1092 } else {
1093 IccLogicalChannelRequest channelRequest =
1094 (IccLogicalChannelRequest) request.argument;
1095 channelRequest.channel = channelId;
1096 uiccPort.onLogicalChannelOpened(channelRequest);
1097 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07001098 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -07001099 if (ar.result == null) {
1100 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -07001101 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001102 if (ar.exception != null) {
1103 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
1104 }
1105
Shishir Agrawal527e8bf2014-08-25 08:54:56 -07001106 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -07001107 if (ar.exception instanceof CommandException) {
1108 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -08001109 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -07001110 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -07001111 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -07001112 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -07001113 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001114 }
1115 }
1116 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -08001117 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001118 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -07001119 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001120 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001121 break;
1122
1123 case CMD_CLOSE_CHANNEL:
1124 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001125 uiccPort = getUiccPortFromRequest(request);
1126 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001127 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -08001128 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001129 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -08001130 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001131 } else {
1132 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001133 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001134 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07001135 break;
1136
1137 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -08001138 ar = (AsyncResult) msg.obj;
1139 request = (MainThreadRequest) ar.userObj;
1140 if (ar.exception == null) {
1141 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -08001142 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -07001143 if (uiccPort == null) {
1144 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
1145 } else {
1146 final int channelId = (Integer) request.argument;
1147 uiccPort.onLogicalChannelClosed(channelId);
1148 }
Chen Xu540470b2021-12-14 17:15:47 -08001149 } else {
1150 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -08001151 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -08001152 if (ar.exception instanceof CommandException) {
1153 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
1154 CommandException.Error error =
1155 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -08001156 if (error == CommandException.Error.INVALID_ARGUMENTS) {
1157 // should only throw exceptions from the binder threads.
1158 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -08001159 "iccCloseLogicalChannel: invalid argument ");
1160 }
1161 } else {
1162 loge("iccCloseLogicalChannel: Unknown exception");
1163 }
Chen Xua8f0dff2022-02-12 00:34:15 -08001164 request.result = (exception != null) ? exception :
1165 new IllegalStateException(
1166 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -08001167 }
1168 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001169 break;
1170
1171 case CMD_NV_READ_ITEM:
1172 request = (MainThreadRequest) msg.obj;
1173 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001174 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
1175 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -08001176 break;
1177
1178 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -07001179 ar = (AsyncResult) msg.obj;
1180 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -08001181 if (ar.exception == null && ar.result != null) {
1182 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -07001183 } else {
Jake Hambye994d462014-02-03 13:10:13 -08001184 request.result = "";
1185 if (ar.result == null) {
1186 loge("nvReadItem: Empty response");
1187 } else if (ar.exception instanceof CommandException) {
1188 loge("nvReadItem: CommandException: " +
1189 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001190 } else {
Jake Hambye994d462014-02-03 13:10:13 -08001191 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -07001192 }
1193 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001194 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001195 break;
1196
Jake Hambye994d462014-02-03 13:10:13 -08001197 case CMD_NV_WRITE_ITEM:
1198 request = (MainThreadRequest) msg.obj;
1199 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
1200 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001201 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -07001202 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -08001203 break;
1204
1205 case EVENT_NV_WRITE_ITEM_DONE:
1206 handleNullReturnEvent(msg, "nvWriteItem");
1207 break;
1208
1209 case CMD_NV_WRITE_CDMA_PRL:
1210 request = (MainThreadRequest) msg.obj;
1211 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001212 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -08001213 break;
1214
1215 case EVENT_NV_WRITE_CDMA_PRL_DONE:
1216 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
1217 break;
1218
chen xu6dac5ab2018-10-26 17:39:23 -07001219 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -08001220 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -07001221 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001222 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -08001223 break;
1224
chen xu6dac5ab2018-10-26 17:39:23 -07001225 case EVENT_RESET_MODEM_CONFIG_DONE:
1226 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -08001227 break;
1228
Sooraj Sasindran37444802020-08-11 10:40:43 -07001229 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
1230 request = (MainThreadRequest) msg.obj;
1231 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
1232 request);
1233 Phone phone = getPhoneFromRequest(request);
1234 if (phone != null) {
1235 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
1236 } else {
1237 loge("isNRDualConnectivityEnabled: No phone object");
1238 request.result = false;
1239 notifyRequester(request);
1240 }
1241 break;
1242 }
1243
1244 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
1245 ar = (AsyncResult) msg.obj;
1246 request = (MainThreadRequest) ar.userObj;
1247 if (ar.exception == null && ar.result != null) {
1248 request.result = ar.result;
1249 } else {
1250 // request.result must be set to something non-null
1251 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001252 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -07001253 request.result = ar.result;
1254 } else {
1255 request.result = false;
1256 }
1257 if (ar.result == null) {
1258 loge("isNRDualConnectivityEnabled: Empty response");
1259 } else if (ar.exception instanceof CommandException) {
1260 loge("isNRDualConnectivityEnabled: CommandException: "
1261 + ar.exception);
1262 } else {
1263 loge("isNRDualConnectivityEnabled: Unknown exception");
1264 }
1265 }
1266 notifyRequester(request);
1267 break;
1268
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001269 case CMD_IS_VONR_ENABLED: {
1270 request = (MainThreadRequest) msg.obj;
1271 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
1272 request);
1273 Phone phone = getPhoneFromRequest(request);
1274 if (phone != null) {
1275 phone.isVoNrEnabled(onCompleted, request.workSource);
1276 } else {
1277 loge("isVoNrEnabled: No phone object");
1278 request.result = false;
1279 notifyRequester(request);
1280 }
1281 break;
1282 }
1283
1284 case EVENT_IS_VONR_ENABLED_DONE:
1285 ar = (AsyncResult) msg.obj;
1286 request = (MainThreadRequest) ar.userObj;
1287 if (ar.exception == null && ar.result != null) {
1288 request.result = ar.result;
1289 } else {
1290 // request.result must be set to something non-null
1291 // for the calling thread to unblock
1292 if (ar.result != null) {
1293 request.result = ar.result;
1294 } else {
1295 request.result = false;
1296 }
1297 if (ar.result == null) {
1298 loge("isVoNrEnabled: Empty response");
1299 } else if (ar.exception instanceof CommandException) {
1300 loge("isVoNrEnabled: CommandException: "
1301 + ar.exception);
1302 } else {
1303 loge("isVoNrEnabled: Unknown exception");
1304 }
1305 }
1306 notifyRequester(request);
1307 break;
1308
Sooraj Sasindran37444802020-08-11 10:40:43 -07001309 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1310 request = (MainThreadRequest) msg.obj;
1311 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1312 Phone phone = getPhoneFromRequest(request);
1313 if (phone != null) {
1314 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1315 request.workSource);
1316 } else {
1317 loge("enableNrDualConnectivity: No phone object");
1318 request.result =
1319 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1320 notifyRequester(request);
1321 }
1322 break;
1323 }
1324
1325 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1326 ar = (AsyncResult) msg.obj;
1327 request = (MainThreadRequest) ar.userObj;
1328 if (ar.exception == null) {
1329 request.result =
1330 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1331 } else {
1332 request.result =
1333 TelephonyManager
1334 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1335 if (ar.exception instanceof CommandException) {
1336 CommandException.Error error =
1337 ((CommandException) (ar.exception)).getCommandError();
1338 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1339 request.result =
1340 TelephonyManager
1341 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001342 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1343 request.result =
1344 TelephonyManager
1345 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001346 }
1347 loge("enableNrDualConnectivity" + ": CommandException: "
1348 + ar.exception);
1349 } else {
1350 loge("enableNrDualConnectivity" + ": Unknown exception");
1351 }
1352 }
1353 notifyRequester(request);
1354 break;
1355 }
1356
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001357 case CMD_ENABLE_VONR: {
1358 request = (MainThreadRequest) msg.obj;
1359 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1360 Phone phone = getPhoneFromRequest(request);
1361 if (phone != null) {
1362 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1363 request.workSource);
1364 } else {
1365 loge("setVoNrEnabled: No phone object");
1366 request.result =
1367 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1368 notifyRequester(request);
1369 }
1370 break;
1371 }
1372
1373 case EVENT_ENABLE_VONR_DONE: {
1374 ar = (AsyncResult) msg.obj;
1375 request = (MainThreadRequest) ar.userObj;
1376 if (ar.exception == null) {
1377 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1378 } else {
1379 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1380 if (ar.exception instanceof CommandException) {
1381 CommandException.Error error =
1382 ((CommandException) (ar.exception)).getCommandError();
1383 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1384 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1385 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1386 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1387 } else {
1388 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1389 }
1390 loge("setVoNrEnabled" + ": CommandException: "
1391 + ar.exception);
1392 } else {
1393 loge("setVoNrEnabled" + ": Unknown exception");
1394 }
1395 }
1396 notifyRequester(request);
1397 break;
1398 }
1399
SongFerngWang3ef3e072020-12-21 16:41:52 +08001400 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001401 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001402 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1403 request);
1404 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001405 break;
1406
SongFerngWang3ef3e072020-12-21 16:41:52 +08001407 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001408 ar = (AsyncResult) msg.obj;
1409 request = (MainThreadRequest) ar.userObj;
1410 if (ar.exception == null && ar.result != null) {
1411 request.result = ar.result; // Integer
1412 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301413 // request.result must be set to something non-null
1414 // for the calling thread to unblock
1415 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001416 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001417 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001418 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001419 loge("getAllowedNetworkTypesBitmask: CommandException: "
1420 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001421 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001422 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001423 }
1424 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001425 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001426 break;
1427
SongFerngWang3ef3e072020-12-21 16:41:52 +08001428 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001429 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001430 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1431 request);
1432 Pair<Integer, Long> reasonWithNetworkTypes =
1433 (Pair<Integer, Long>) request.argument;
1434 getPhoneFromRequest(request).setAllowedNetworkTypes(
1435 reasonWithNetworkTypes.first,
1436 reasonWithNetworkTypes.second,
1437 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001438 break;
1439
SongFerngWang3ef3e072020-12-21 16:41:52 +08001440 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1441 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001442 break;
1443
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001444 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1445 request = (MainThreadRequest)msg.obj;
1446 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001447 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001448 break;
1449
1450 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1451 ar = (AsyncResult)msg.obj;
1452 request = (MainThreadRequest)ar.userObj;
1453 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001454 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001455 break;
1456
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001457 case CMD_SET_VOICEMAIL_NUMBER:
1458 request = (MainThreadRequest) msg.obj;
1459 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1460 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001461 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1462 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001463 break;
1464
1465 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1466 handleNullReturnEvent(msg, "setVoicemailNumber");
1467 break;
1468
Stuart Scott54788802015-03-30 13:18:01 -07001469 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1470 request = (MainThreadRequest) msg.obj;
1471 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1472 request);
1473 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1474 break;
1475
1476 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1477 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1478 break;
1479
Shishir Agrawal302c8692015-06-19 13:49:39 -07001480 case CMD_PERFORM_NETWORK_SCAN:
1481 request = (MainThreadRequest) msg.obj;
1482 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1483 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1484 break;
1485
Hall Liu27d24262020-09-18 19:04:59 -07001486 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001487 request = (MainThreadRequest) msg.obj;
1488 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001489 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1490 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1491 request.argument;
1492 int callForwardingReason = args.first;
1493 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001494 break;
Hall Liu27d24262020-09-18 19:04:59 -07001495 }
1496 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001497 ar = (AsyncResult) msg.obj;
1498 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001499 TelephonyManager.CallForwardingInfoCallback callback =
1500 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1501 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001502 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001503 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001504 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1505 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1506 // Service Class is a bit mask per 3gpp 27.007. Search for
1507 // any service for voice call.
1508 if ((callForwardInfo.serviceClass
1509 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001510 callForwardingInfo = new CallForwardingInfo(
1511 callForwardInfo.status
1512 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001513 callForwardInfo.reason,
1514 callForwardInfo.number,
1515 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001516 break;
1517 }
1518 }
1519 // Didn't find a call forward info for voice call.
1520 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001521 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1522 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001523 }
Hall Liu27d24262020-09-18 19:04:59 -07001524 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001525 } else {
1526 if (ar.result == null) {
1527 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1528 }
1529 if (ar.exception != null) {
1530 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1531 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001532 int errorCode = TelephonyManager
1533 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001534 if (ar.exception instanceof CommandException) {
1535 CommandException.Error error =
1536 ((CommandException) (ar.exception)).getCommandError();
1537 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001538 errorCode = TelephonyManager
1539 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001540 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001541 errorCode = TelephonyManager
1542 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001543 }
1544 }
Hall Liu27d24262020-09-18 19:04:59 -07001545 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001546 }
Shuo Qian4a594052020-01-23 11:59:30 -08001547 break;
Hall Liu27d24262020-09-18 19:04:59 -07001548 }
Shuo Qian4a594052020-01-23 11:59:30 -08001549
Hall Liu27d24262020-09-18 19:04:59 -07001550 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001551 request = (MainThreadRequest) msg.obj;
1552 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001553 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001554 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001555 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1556 request.argument).first;
1557 request.phone.setCallForwardingOption(
1558 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001559 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001560 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001561 callForwardingInfoToSet.getReason(),
1562 callForwardingInfoToSet.getNumber(),
1563 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1564 break;
Hall Liu27d24262020-09-18 19:04:59 -07001565 }
Shuo Qian4a594052020-01-23 11:59:30 -08001566
Hall Liu27d24262020-09-18 19:04:59 -07001567 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001568 ar = (AsyncResult) msg.obj;
1569 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001570 Consumer<Integer> callback =
1571 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1572 request.argument).second;
1573 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001574 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001575 int errorCode = TelephonyManager.CallForwardingInfoCallback
1576 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001577 if (ar.exception instanceof CommandException) {
1578 CommandException.Error error =
1579 ((CommandException) (ar.exception)).getCommandError();
1580 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001581 errorCode = TelephonyManager.CallForwardingInfoCallback
1582 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001583 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001584 errorCode = TelephonyManager.CallForwardingInfoCallback
1585 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001586 }
1587 }
1588 callback.accept(errorCode);
1589 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001590 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001591 }
Shuo Qian4a594052020-01-23 11:59:30 -08001592 break;
Hall Liu27d24262020-09-18 19:04:59 -07001593 }
Shuo Qian4a594052020-01-23 11:59:30 -08001594
Hall Liu27d24262020-09-18 19:04:59 -07001595 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001596 request = (MainThreadRequest) msg.obj;
1597 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1598 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1599 break;
Hall Liu27d24262020-09-18 19:04:59 -07001600 }
Shuo Qian4a594052020-01-23 11:59:30 -08001601
Hall Liu27d24262020-09-18 19:04:59 -07001602 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001603 ar = (AsyncResult) msg.obj;
1604 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001605 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001606 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001607 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001608 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001609 // Service Class is a bit mask per 3gpp 27.007.
1610 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001611 if (callForwardResults.length > 1
1612 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001613 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001614 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001615 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1616 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001617 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001618 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001619 }
1620 } else {
1621 if (ar.result == null) {
1622 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1623 }
1624 if (ar.exception != null) {
1625 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1626 }
1627 if (ar.exception instanceof CommandException) {
1628 CommandException.Error error =
1629 ((CommandException) (ar.exception)).getCommandError();
1630 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001631 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001632 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001633 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1634 callWaitingStatus =
1635 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001636 }
1637 }
1638 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001639 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001640 break;
Hall Liu27d24262020-09-18 19:04:59 -07001641 }
Shuo Qian4a594052020-01-23 11:59:30 -08001642
Hall Liu27d24262020-09-18 19:04:59 -07001643 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001644 request = (MainThreadRequest) msg.obj;
1645 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001646 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1647 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001648 break;
Hall Liu27d24262020-09-18 19:04:59 -07001649 }
Shuo Qian4a594052020-01-23 11:59:30 -08001650
Hall Liu27d24262020-09-18 19:04:59 -07001651 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001652 ar = (AsyncResult) msg.obj;
1653 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001654 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1655 Consumer<Integer> callback =
1656 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1657 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001658 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001659 if (ar.exception instanceof CommandException) {
1660 CommandException.Error error =
1661 ((CommandException) (ar.exception)).getCommandError();
1662 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1663 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001664 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1665 callback.accept(
1666 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001667 } else {
1668 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1669 }
1670 } else {
1671 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1672 }
1673 } else {
1674 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1675 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001676 }
Shuo Qian4a594052020-01-23 11:59:30 -08001677 break;
Hall Liu27d24262020-09-18 19:04:59 -07001678 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001679 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1680 ar = (AsyncResult) msg.obj;
1681 request = (MainThreadRequest) ar.userObj;
1682 CellNetworkScanResult cellScanResult;
1683 if (ar.exception == null && ar.result != null) {
1684 cellScanResult = new CellNetworkScanResult(
1685 CellNetworkScanResult.STATUS_SUCCESS,
1686 (List<OperatorInfo>) ar.result);
1687 } else {
1688 if (ar.result == null) {
1689 loge("getCellNetworkScanResults: Empty response");
1690 }
1691 if (ar.exception != null) {
1692 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1693 }
1694 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1695 if (ar.exception instanceof CommandException) {
1696 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001697 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001698 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1699 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1700 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1701 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1702 }
1703 }
1704 cellScanResult = new CellNetworkScanResult(errorCode, null);
1705 }
1706 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001707 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001708 break;
1709
1710 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1711 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001712 ManualNetworkSelectionArgument selArg =
1713 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001714 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1715 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001716 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1717 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001718 break;
1719
1720 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001721 ar = (AsyncResult) msg.obj;
1722 request = (MainThreadRequest) ar.userObj;
1723 if (ar.exception == null) {
1724 request.result = true;
1725 } else {
1726 request.result = false;
1727 loge("setNetworkSelectionModeManual " + ar.exception);
1728 }
1729 notifyRequester(request);
1730 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001731 break;
1732
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001733 case CMD_GET_MODEM_ACTIVITY_INFO:
1734 request = (MainThreadRequest) msg.obj;
1735 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001736 if (defaultPhone != null) {
1737 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001738 } else {
1739 ResultReceiver result = (ResultReceiver) request.argument;
1740 Bundle bundle = new Bundle();
1741 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001742 new ModemActivityInfo(0, 0, 0,
1743 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001744 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001745 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001746 break;
1747
Hall Liud0f208c2020-10-14 16:54:44 -07001748 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001749 ar = (AsyncResult) msg.obj;
1750 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001751 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001752 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001753 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001754 if (mLastModemActivityInfo == null) {
1755 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1756 mLastModemActivitySpecificInfo[0] =
1757 new ActivityStatsTechSpecificInfo(
1758 0,
1759 0,
1760 new int[ModemActivityInfo.getNumTxPowerLevels()],
1761 0);
1762 mLastModemActivityInfo =
1763 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1764 }
1765
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001766 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001767 // Update the last modem activity info and the result of the request.
1768 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1769 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001770 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001771 } else {
1772 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001773 }
Kai Shi917fdc62022-11-28 14:01:02 -08001774 // This is needed to decouple ret from mLastModemActivityInfo
1775 // We don't want to return mLastModemActivityInfo which is updated
1776 // inside mergeModemActivityInfo()
1777 ret = new ModemActivityInfo(
1778 mLastModemActivityInfo.getTimestampMillis(),
1779 mLastModemActivityInfo.getSleepTimeMillis(),
1780 mLastModemActivityInfo.getIdleTimeMillis(),
1781 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001782
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001783 } else {
1784 if (ar.result == null) {
1785 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001786 error = TelephonyManager.ModemActivityInfoException
1787 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001788 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001789 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001790 error = TelephonyManager.ModemActivityInfoException
1791 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001792 } else {
1793 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001794 error = TelephonyManager.ModemActivityInfoException
1795 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001796 }
1797 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001798 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001799 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001800 bundle.putParcelable(
1801 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001802 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001803 } else {
1804 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1805 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001806 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001807 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001808 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001809 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001810
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001811 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001812 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001813 CarrierRestrictionRules argument =
1814 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001815 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001816 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001817 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001818 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001819
1820 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1821 ar = (AsyncResult) msg.obj;
1822 request = (MainThreadRequest) ar.userObj;
1823 if (ar.exception == null && ar.result != null) {
1824 request.result = ar.result;
1825 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001826 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1827 if (ar.exception instanceof CommandException) {
1828 loge("setAllowedCarriers: CommandException: " + ar.exception);
1829 CommandException.Error error =
1830 ((CommandException) (ar.exception)).getCommandError();
1831 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1832 request.result =
1833 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1834 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001835 } else {
1836 loge("setAllowedCarriers: Unknown exception");
1837 }
1838 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001839 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001840 break;
1841
1842 case CMD_GET_ALLOWED_CARRIERS:
1843 request = (MainThreadRequest) msg.obj;
1844 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001845 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001846 break;
1847
1848 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1849 ar = (AsyncResult) msg.obj;
1850 request = (MainThreadRequest) ar.userObj;
1851 if (ar.exception == null && ar.result != null) {
1852 request.result = ar.result;
1853 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001854 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001855 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001856 if (ar.result == null) {
1857 loge("getAllowedCarriers: Empty response");
1858 } else if (ar.exception instanceof CommandException) {
1859 loge("getAllowedCarriers: CommandException: " +
1860 ar.exception);
1861 } else {
1862 loge("getAllowedCarriers: Unknown exception");
1863 }
1864 }
arunvoddud7401012022-12-15 16:08:12 +00001865 if (request.argument != null) {
1866 // This is for the implementation of carrierRestrictionStatus.
1867 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1868 Consumer<Integer> callback = callbackInfo.getConsumer();
1869 int callerCarrierId = callbackInfo.getCarrierId();
1870 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1871 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1872 CarrierRestrictionRules carrierRestrictionRules =
1873 (CarrierRestrictionRules) ar.result;
1874 int carrierId = -1;
1875 try {
1876 CarrierIdentifier carrierIdentifier =
1877 carrierRestrictionRules.getAllowedCarriers().get(0);
1878 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1879 carrierIdentifier);
1880 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1881 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1882 }
1883 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
1884 if (carrierId != -1 && callerCarrierId == carrierId && lockStatus
1885 == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001886 lockStatus = TelephonyManager
1887 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001888 }
1889 } else {
1890 Rlog.e(LOG_TAG,
1891 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1892 }
1893 callback.accept(lockStatus);
1894 } else {
1895 // This is for the implementation of getAllowedCarriers.
1896 notifyRequester(request);
1897 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001898 break;
1899
Nathan Haroldb3014052017-01-25 15:57:32 -08001900 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1901 ar = (AsyncResult) msg.obj;
1902 request = (MainThreadRequest) ar.userObj;
1903 if (ar.exception == null && ar.result != null) {
1904 request.result = ar.result;
1905 } else {
1906 request.result = new IllegalArgumentException(
1907 "Failed to retrieve Forbidden Plmns");
1908 if (ar.result == null) {
1909 loge("getForbiddenPlmns: Empty response");
1910 } else {
1911 loge("getForbiddenPlmns: Unknown exception");
1912 }
1913 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001914 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001915 break;
1916
1917 case CMD_GET_FORBIDDEN_PLMNS:
1918 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001919 uiccPort = getUiccPortFromRequest(request);
1920 if (uiccPort == null) {
1921 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001922 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001923 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001924 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001925 break;
1926 }
1927 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001928 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001929 if (uiccApp == null) {
1930 loge("getForbiddenPlmns() no app with specified type -- "
1931 + appType);
1932 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001933 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001934 break;
1935 } else {
1936 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1937 + " specified type -- " + appType);
1938 }
1939 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1940 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001941 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001942 break;
1943
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001944 case CMD_SWITCH_SLOTS:
1945 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001946 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001947 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001948 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001949 break;
1950
1951 case EVENT_SWITCH_SLOTS_DONE:
1952 ar = (AsyncResult) msg.obj;
1953 request = (MainThreadRequest) ar.userObj;
1954 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001955 notifyRequester(request);
1956 break;
1957 case CMD_GET_NETWORK_SELECTION_MODE:
1958 request = (MainThreadRequest) msg.obj;
1959 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1960 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1961 break;
1962
1963 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1964 ar = (AsyncResult) msg.obj;
1965 request = (MainThreadRequest) ar.userObj;
1966 if (ar.exception != null) {
1967 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1968 } else {
1969 int mode = ((int[]) ar.result)[0];
1970 if (mode == 0) {
1971 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1972 } else {
1973 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1974 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001975 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001976 notifyRequester(request);
1977 break;
1978 case CMD_GET_CDMA_ROAMING_MODE:
1979 request = (MainThreadRequest) msg.obj;
1980 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1981 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1982 break;
1983 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1984 ar = (AsyncResult) msg.obj;
1985 request = (MainThreadRequest) ar.userObj;
1986 if (ar.exception != null) {
1987 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1988 } else {
1989 request.result = ((int[]) ar.result)[0];
1990 }
1991 notifyRequester(request);
1992 break;
1993 case CMD_SET_CDMA_ROAMING_MODE:
1994 request = (MainThreadRequest) msg.obj;
1995 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1996 int mode = (int) request.argument;
1997 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1998 break;
1999 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
2000 ar = (AsyncResult) msg.obj;
2001 request = (MainThreadRequest) ar.userObj;
2002 request.result = ar.exception == null;
2003 notifyRequester(request);
2004 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07002005 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
2006 request = (MainThreadRequest) msg.obj;
2007 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
2008 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
2009 break;
2010 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
2011 ar = (AsyncResult) msg.obj;
2012 request = (MainThreadRequest) ar.userObj;
2013 if (ar.exception != null) {
2014 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
2015 } else {
2016 request.result = ((int[]) ar.result)[0];
2017 }
2018 notifyRequester(request);
2019 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07002020 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
2021 request = (MainThreadRequest) msg.obj;
2022 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
2023 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07002024 getPhoneFromRequest(request).setCdmaSubscriptionMode(
2025 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07002026 break;
2027 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
2028 ar = (AsyncResult) msg.obj;
2029 request = (MainThreadRequest) ar.userObj;
2030 request.result = ar.exception == null;
2031 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00002032 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07002033 case CMD_GET_ALL_CELL_INFO:
2034 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07002035 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07002036 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07002037 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07002038 case EVENT_GET_ALL_CELL_INFO_DONE:
2039 ar = (AsyncResult) msg.obj;
2040 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07002041 // If a timeout occurs, the response will be null
2042 request.result = (ar.exception == null && ar.result != null)
2043 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07002044 synchronized (request) {
2045 request.notifyAll();
2046 }
2047 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002048 case CMD_REQUEST_CELL_INFO_UPDATE:
2049 request = (MainThreadRequest) msg.obj;
2050 request.phone.requestCellInfoUpdate(request.workSource,
2051 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
2052 break;
2053 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
2054 ar = (AsyncResult) msg.obj;
2055 request = (MainThreadRequest) ar.userObj;
2056 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
2057 try {
2058 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002059 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07002060 cb.onError(
2061 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
2062 ar.exception.getClass().getName(),
2063 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002064 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002065 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07002066 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002067 } else {
2068 // use the result as returned
2069 cb.onCellInfo((List<CellInfo>) ar.result);
2070 }
2071 } catch (RemoteException re) {
2072 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
2073 }
2074 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08002075 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07002076 request = (MainThreadRequest) msg.obj;
2077 WorkSource ws = (WorkSource) request.argument;
2078 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08002079 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07002080 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08002081 }
2082 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07002083 ar = (AsyncResult) msg.obj;
2084 request = (MainThreadRequest) ar.userObj;
2085 if (ar.exception == null) {
2086 request.result = ar.result;
2087 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08002088 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07002089 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08002090 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07002091 }
2092
2093 synchronized (request) {
2094 request.notifyAll();
2095 }
2096 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08002097 }
chen xu6dac5ab2018-10-26 17:39:23 -07002098 case CMD_MODEM_REBOOT:
2099 request = (MainThreadRequest) msg.obj;
2100 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002101 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07002102 break;
chen xu6dac5ab2018-10-26 17:39:23 -07002103 case EVENT_CMD_MODEM_REBOOT_DONE:
2104 handleNullReturnEvent(msg, "rebootModem");
2105 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002106 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08002107 request = (MainThreadRequest) msg.obj;
2108 boolean enable = (boolean) request.argument;
2109 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08002110 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08002111 PhoneConfigurationManager.getInstance()
2112 .enablePhone(request.phone, enable, onCompleted);
2113 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002114 }
Michele Berionne5e411512020-11-13 02:36:59 +00002115 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08002116 ar = (AsyncResult) msg.obj;
2117 request = (MainThreadRequest) ar.userObj;
2118 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07002119 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08002120 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07002121 if ((boolean) request.result) {
2122 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
2123 updateModemStateMetrics();
2124 } else {
2125 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
2126 + ar.exception);
2127 }
2128 notifyRequester(request);
2129 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002130 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07002131 case CMD_GET_MODEM_STATUS:
2132 request = (MainThreadRequest) msg.obj;
2133 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
2134 PhoneConfigurationManager.getInstance()
2135 .getPhoneStatusFromModem(request.phone, onCompleted);
2136 break;
2137 case EVENT_GET_MODEM_STATUS_DONE:
2138 ar = (AsyncResult) msg.obj;
2139 request = (MainThreadRequest) ar.userObj;
2140 int id = request.phone.getPhoneId();
2141 if (ar.exception == null && ar.result != null) {
2142 request.result = ar.result;
2143 //update the cache as modem status has changed
2144 mPhoneConfigurationManager.addToPhoneStatusCache(id,
2145 (boolean) request.result);
2146 } else {
2147 // Return true if modem status cannot be retrieved. For most cases,
2148 // modem status is on. And for older version modems, GET_MODEM_STATUS
2149 // and disable modem are not supported. Modem is always on.
2150 // TODO: this should be fixed in R to support a third
2151 // status UNKNOWN b/131631629
2152 request.result = true;
2153 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
2154 + ar.exception);
2155 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08002156 notifyRequester(request);
2157 break;
Hall Liu73f5d362020-01-20 13:42:00 -08002158 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
2159 request = (MainThreadRequest) msg.obj;
2160 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
2161 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
2162 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
2163 request.phone.setSystemSelectionChannels(args.first, onCompleted);
2164 break;
2165 }
2166 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
2167 ar = (AsyncResult) msg.obj;
2168 request = (MainThreadRequest) ar.userObj;
2169 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
2170 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
2171 args.second.accept(ar.exception == null);
2172 notifyRequester(request);
2173 break;
2174 }
Sarah Chin679c08a2020-11-18 13:39:35 -08002175 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
2176 request = (MainThreadRequest) msg.obj;
2177 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
2178 Phone phone = getPhoneFromRequest(request);
2179 if (phone != null) {
2180 phone.getSystemSelectionChannels(onCompleted);
2181 } else {
2182 loge("getSystemSelectionChannels: No phone object");
2183 request.result = new ArrayList<RadioAccessSpecifier>();
2184 notifyRequester(request);
2185 }
2186 break;
2187 }
2188 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
2189 ar = (AsyncResult) msg.obj;
2190 request = (MainThreadRequest) ar.userObj;
2191 if (ar.exception == null && ar.result != null) {
2192 request.result = ar.result;
2193 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08002194 request.result = new IllegalStateException(
2195 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08002196 if (ar.result == null) {
2197 loge("getSystemSelectionChannels: Empty response");
2198 } else {
2199 loge("getSystemSelectionChannels: Unknown exception");
2200 }
2201 }
2202 notifyRequester(request);
2203 break;
yincheng zhao2737e882019-09-06 17:06:54 -07002204 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
2205 ar = (AsyncResult) msg.obj;
2206 request = (MainThreadRequest) ar.userObj;
2207 if (ar.exception == null && ar.result != null) {
2208 request.result = ar.result;
2209 } else {
2210 request.result = -1;
2211 loge("Failed to set Forbidden Plmns");
2212 if (ar.result == null) {
2213 loge("setForbidenPlmns: Empty response");
2214 } else if (ar.exception != null) {
2215 loge("setForbiddenPlmns: Exception: " + ar.exception);
2216 request.result = -1;
2217 } else {
2218 loge("setForbiddenPlmns: Unknown exception");
2219 }
2220 }
2221 notifyRequester(request);
2222 break;
2223 case CMD_SET_FORBIDDEN_PLMNS:
2224 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002225 uiccPort = getUiccPortFromRequest(request);
2226 if (uiccPort == null) {
2227 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07002228 request.result = -1;
2229 notifyRequester(request);
2230 break;
2231 }
2232 Pair<Integer, List<String>> setFplmnsArgs =
2233 (Pair<Integer, List<String>>) request.argument;
2234 appType = setFplmnsArgs.first;
2235 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002236 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07002237 if (uiccApp == null) {
2238 loge("setForbiddenPlmns: no app with specified type -- " + appType);
2239 request.result = -1;
2240 loge("Failed to get UICC App");
2241 notifyRequester(request);
2242 } else {
2243 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
2244 ((SIMRecords) uiccApp.getIccRecords())
2245 .setForbiddenPlmns(onCompleted, fplmns);
2246 }
yinchengzhao4d163c02019-12-12 15:21:47 -08002247 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07002248 case CMD_ERASE_MODEM_CONFIG:
2249 request = (MainThreadRequest) msg.obj;
2250 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
2251 defaultPhone.eraseModemConfig(onCompleted);
2252 break;
2253 case EVENT_ERASE_MODEM_CONFIG_DONE:
2254 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07002255 break;
zoey chene02881a2019-12-30 16:11:23 +08002256
Kai Shif70f46f2021-03-03 13:59:46 -08002257 case CMD_ERASE_DATA_SHARED_PREFERENCES:
2258 request = (MainThreadRequest) msg.obj;
2259 request.result = defaultPhone.eraseDataInSharedPreferences();
2260 notifyRequester(request);
2261 break;
2262
zoey chene02881a2019-12-30 16:11:23 +08002263 case CMD_CHANGE_ICC_LOCK_PASSWORD:
2264 request = (MainThreadRequest) msg.obj;
2265 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
2266 Pair<String, String> changed = (Pair<String, String>) request.argument;
2267 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
2268 changed.first, changed.second, onCompleted);
2269 break;
2270 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
2271 ar = (AsyncResult) msg.obj;
2272 request = (MainThreadRequest) ar.userObj;
2273 if (ar.exception == null) {
2274 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002275 // If the operation is successful, update the PIN storage
2276 Pair<String, String> passwords = (Pair<String, String>) request.argument;
2277 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00002278 UiccController.getInstance().getPinStorage()
2279 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08002280 } else {
2281 request.result = msg.arg1;
2282 }
2283 notifyRequester(request);
2284 break;
2285
Michele Berionne5e411512020-11-13 02:36:59 +00002286 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002287 request = (MainThreadRequest) msg.obj;
2288 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2289 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2290 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2291 enabled.first, enabled.second, onCompleted);
2292 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002293 }
zoey chene02881a2019-12-30 16:11:23 +08002294 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2295 ar = (AsyncResult) msg.obj;
2296 request = (MainThreadRequest) ar.userObj;
2297 if (ar.exception == null) {
2298 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002299 // If the operation is successful, update the PIN storage
2300 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2301 int phoneId = getPhoneFromRequest(request).getPhoneId();
2302 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002303 UiccController.getInstance().getPinStorage()
2304 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002305 } else {
2306 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2307 }
zoey chene02881a2019-12-30 16:11:23 +08002308 } else {
2309 request.result = msg.arg1;
2310 }
Michele Berionne5e411512020-11-13 02:36:59 +00002311
2312
zoey chene02881a2019-12-30 16:11:23 +08002313 notifyRequester(request);
2314 break;
2315
Peter Wangdafb9ac2020-01-15 14:13:38 -08002316 case MSG_NOTIFY_USER_ACTIVITY:
2317 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002318 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002319 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2320 getDefaultPhone().getContext().sendBroadcastAsUser(
2321 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2322 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002323
2324 case CMD_SET_DATA_THROTTLING: {
2325 request = (MainThreadRequest) msg.obj;
2326 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2327 DataThrottlingRequest dataThrottlingRequest =
2328 (DataThrottlingRequest) request.argument;
2329 Phone phone = getPhoneFromRequest(request);
2330 if (phone != null) {
2331 phone.setDataThrottling(onCompleted,
2332 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2333 dataThrottlingRequest.getCompletionDurationMillis());
2334 } else {
2335 loge("setDataThrottling: No phone object");
2336 request.result =
2337 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2338 notifyRequester(request);
2339 }
2340
2341 break;
2342 }
2343 case EVENT_SET_DATA_THROTTLING_DONE:
2344 ar = (AsyncResult) msg.obj;
2345 request = (MainThreadRequest) ar.userObj;
2346
2347 if (ar.exception == null) {
2348 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2349 } else if (ar.exception instanceof CommandException) {
2350 loge("setDataThrottling: CommandException: " + ar.exception);
2351 CommandException.Error error =
2352 ((CommandException) (ar.exception)).getCommandError();
2353
2354 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2355 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002356 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002357 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2358 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002359 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2360 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002361 } else {
2362 request.result =
2363 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2364 }
2365 } else {
2366 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2367 }
2368 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2369 notifyRequester(request);
2370 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002371
2372 case CMD_SET_SIM_POWER: {
2373 request = (MainThreadRequest) msg.obj;
2374 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2375 request = (MainThreadRequest) msg.obj;
2376 int stateToSet =
2377 ((Pair<Integer, IIntegerConsumer>)
2378 request.argument).first;
2379 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2380 break;
2381 }
2382 case EVENT_SET_SIM_POWER_DONE: {
2383 ar = (AsyncResult) msg.obj;
2384 request = (MainThreadRequest) ar.userObj;
2385 IIntegerConsumer callback =
2386 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2387 if (ar.exception != null) {
2388 loge("setSimPower exception: " + ar.exception);
2389 int errorCode = TelephonyManager.CallForwardingInfoCallback
2390 .RESULT_ERROR_UNKNOWN;
2391 if (ar.exception instanceof CommandException) {
2392 CommandException.Error error =
2393 ((CommandException) (ar.exception)).getCommandError();
2394 if (error == CommandException.Error.SIM_ERR) {
2395 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2396 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2397 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2398 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2399 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2400 } else {
2401 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2402 }
2403 }
2404 try {
2405 callback.accept(errorCode);
2406 } catch (RemoteException e) {
2407 // Ignore if the remote process is no longer available to call back.
2408 Log.w(LOG_TAG, "setSimPower: callback not available.");
2409 }
2410 } else {
2411 try {
2412 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2413 } catch (RemoteException e) {
2414 // Ignore if the remote process is no longer available to call back.
2415 Log.w(LOG_TAG, "setSimPower: callback not available.");
2416 }
2417 }
2418 break;
2419 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002420 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2421 request = (MainThreadRequest) msg.obj;
2422
2423 final Phone phone = getPhoneFromRequest(request);
2424 if (phone == null || phone.getServiceStateTracker() == null) {
2425 request.result = new IllegalStateException("Phone or SST is null");
2426 notifyRequester(request);
2427 break;
2428 }
2429
2430 Pair<Integer, SignalStrengthUpdateRequest> pair =
2431 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2432 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2433 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002434 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002435 request.subId, pair.first /*callingUid*/,
2436 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002437 break;
2438 }
2439 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2440 ar = (AsyncResult) msg.obj;
2441 request = (MainThreadRequest) ar.userObj;
2442 // request.result will be the exception of ar if present, true otherwise.
2443 // Be cautious not to leave result null which will wait() forever
2444 request.result = ar.exception != null ? ar.exception : true;
2445 notifyRequester(request);
2446 break;
2447 }
2448 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2449 request = (MainThreadRequest) msg.obj;
2450
2451 Phone phone = getPhoneFromRequest(request);
2452 if (phone == null || phone.getServiceStateTracker() == null) {
2453 request.result = new IllegalStateException("Phone or SST is null");
2454 notifyRequester(request);
2455 break;
2456 }
2457
2458 Pair<Integer, SignalStrengthUpdateRequest> pair =
2459 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2460 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2461 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002462 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002463 request.subId, pair.first /*callingUid*/,
2464 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002465 break;
2466 }
2467 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2468 ar = (AsyncResult) msg.obj;
2469 request = (MainThreadRequest) ar.userObj;
2470 request.result = ar.exception != null ? ar.exception : true;
2471 notifyRequester(request);
2472 break;
2473 }
Jordan Liu109698e2020-11-24 14:50:34 -08002474
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002475 case CMD_GET_SLICING_CONFIG: {
2476 request = (MainThreadRequest) msg.obj;
2477 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2478 request.phone.getSlicingConfig(onCompleted);
2479 break;
2480 }
2481 case EVENT_GET_SLICING_CONFIG_DONE: {
2482 ar = (AsyncResult) msg.obj;
2483 request = (MainThreadRequest) ar.userObj;
2484 ResultReceiver result = (ResultReceiver) request.argument;
2485
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002486 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002487 Bundle bundle = new Bundle();
2488 int resultCode = 0;
2489 if (ar.exception != null) {
2490 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2491 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002492 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002493 } else if (ar.result == null) {
2494 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002495 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002496 } else {
2497 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002498 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2499 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002500 }
2501
2502 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002503 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002504 }
2505 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2506 result.send(resultCode, bundle);
2507 notifyRequester(request);
2508 break;
2509 }
2510
Sarah Chin71b3a852022-09-28 15:54:19 -07002511 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002512 request = (MainThreadRequest) msg.obj;
2513 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002514 PurchasePremiumCapabilityArgument arg =
2515 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin46355ba2022-11-01 23:51:16 -07002516 SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability(
Sarah Chinb8218c22023-01-04 13:35:29 -08002517 arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002518 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002519 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002520
Sarah Chin71b3a852022-09-28 15:54:19 -07002521 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002522 ar = (AsyncResult) msg.obj;
2523 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002524 PurchasePremiumCapabilityArgument arg =
2525 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002526 try {
2527 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002528 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002529 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002530 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002531 + ", result= "
2532 + TelephonyManager.convertPurchaseResultToString(result));
2533 } catch (RemoteException e) {
2534 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002535 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002536 + " failed: " + e;
2537 if (DBG) log(logStr);
2538 AnomalyReporter.reportAnomaly(
2539 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2540 }
2541 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002542 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002543
Michele Berionne5e411512020-11-13 02:36:59 +00002544 case CMD_PREPARE_UNATTENDED_REBOOT:
2545 request = (MainThreadRequest) msg.obj;
2546 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002547 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002548 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002549 notifyRequester(request);
2550 break;
2551
Sarah Chineccfbd12023-01-20 19:00:35 -08002552 case CMD_START_SATELLITE_POSITION_UPDATES: {
2553 request = (MainThreadRequest) msg.obj;
2554 onCompleted =
2555 obtainMessage(EVENT_START_SATELLITE_POSITION_UPDATES_DONE, request);
Sarah Chin4beb2b72023-02-14 14:47:54 -08002556 if (mIsSatelliteServiceSupported) {
2557 mSatelliteServiceController.startSendingSatellitePointingInfo(onCompleted);
2558 break;
2559 }
Sarah Chineccfbd12023-01-20 19:00:35 -08002560 Phone phone = getPhoneFromRequest(request);
2561 if (phone != null) {
2562 phone.startSatellitePositionUpdates(onCompleted);
2563 } else {
2564 loge("startSatellitePositionUpdates: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002565 ((Consumer<Integer>) request.argument).accept(
2566 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Sarah Chineccfbd12023-01-20 19:00:35 -08002567 }
2568 break;
2569 }
2570
2571 case EVENT_START_SATELLITE_POSITION_UPDATES_DONE: {
2572 ar = (AsyncResult) msg.obj;
2573 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002574 int error = getSatelliteError(ar, "startSatellitePositionUpdates", false);
2575 ((Consumer<Integer>) request.argument).accept(error);
Sarah Chineccfbd12023-01-20 19:00:35 -08002576 break;
2577 }
2578
2579 case CMD_STOP_SATELLITE_POSITION_UPDATES: {
2580 request = (MainThreadRequest) msg.obj;
2581 onCompleted =
2582 obtainMessage(EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE, request);
Sarah Chin4beb2b72023-02-14 14:47:54 -08002583 if (mIsSatelliteServiceSupported) {
2584 mSatelliteServiceController.stopSendingSatellitePointingInfo(onCompleted);
2585 break;
2586 }
Sarah Chineccfbd12023-01-20 19:00:35 -08002587 Phone phone = getPhoneFromRequest(request);
2588 if (phone != null) {
2589 phone.stopSatellitePositionUpdates(onCompleted);
2590 } else {
2591 loge("stopSatellitePositionUpdates: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002592 ((Consumer<Integer>) request.argument).accept(
2593 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Sarah Chineccfbd12023-01-20 19:00:35 -08002594 }
2595 break;
2596 }
2597
2598 case EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE: {
2599 ar = (AsyncResult) msg.obj;
2600 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002601 int error = getSatelliteError(ar, "stopSatellitePositionUpdates", false);
2602 ((Consumer<Integer>) request.argument).accept(error);
Sarah Chineccfbd12023-01-20 19:00:35 -08002603 break;
2604 }
2605
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002606 case CMD_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG: {
2607 request = (MainThreadRequest) msg.obj;
Sarah Chin4beb2b72023-02-14 14:47:54 -08002608 onCompleted =
2609 obtainMessage(EVENT_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG_DONE, request);
2610 if (mIsSatelliteServiceSupported) {
2611 mSatelliteServiceController
2612 .requestMaxCharactersPerMOTextMessage(onCompleted);
2613 break;
2614 }
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002615 Phone phone = getPhoneFromRequest(request);
2616 if (phone != null) {
2617 phone.getMaxCharactersPerSatelliteTextMessage(onCompleted);
2618 } else {
2619 loge("getMaxCharactersPerSatelliteTextMessage: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002620 ((ResultReceiver) request.argument).send(
2621 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002622 }
2623 break;
2624 }
2625
2626 case EVENT_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG_DONE: {
2627 ar = (AsyncResult) msg.obj;
2628 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002629 int error =
2630 getSatelliteError(ar, "getMaxCharactersPerSatelliteTextMessage", true);
2631 Bundle bundle = new Bundle();
2632 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002633 int maxCharLimit = ((int[]) ar.result)[0];
Sarah Chin503828c2023-02-01 23:54:20 -08002634 if (DBG) log("getMaxCharactersPerSatelliteTextMessage: " + maxCharLimit);
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002635 bundle.putInt(SatelliteManager.KEY_MAX_CHARACTERS_PER_SATELLITE_TEXT,
2636 maxCharLimit);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002637 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002638 ((ResultReceiver) request.argument).send(error, bundle);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002639 break;
2640 }
2641
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002642 case CMD_PROVISION_SATELLITE_SERVICE: {
2643 request = (MainThreadRequest) msg.obj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002644 ProvisionSatelliteServiceArgument argument =
2645 (ProvisionSatelliteServiceArgument) request.argument;
Sarah Chin4beb2b72023-02-14 14:47:54 -08002646 if (mSatelliteProvisionCallbacks.containsKey(argument.subId)) {
2647 argument.callback.accept(
2648 SatelliteManager.SATELLITE_SERVICE_PROVISION_IN_PROGRESS);
2649 notifyRequester(request);
2650 break;
2651 }
2652 mSatelliteProvisionCallbacks.put(argument.subId, argument.callback);
2653 onCompleted = obtainMessage(EVENT_PROVISION_SATELLITE_SERVICE_DONE, request);
2654 if (mIsSatelliteServiceSupported) {
2655 mSatelliteServiceController
2656 .provisionSatelliteService(argument.token, onCompleted);
2657 break;
2658 }
2659 Phone phone = getPhoneFromRequest(request);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002660 if (phone != null) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08002661 phone.provisionSatelliteService(onCompleted, argument.token);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002662 } else {
2663 loge("provisionSatelliteService: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002664 argument.callback.accept(
2665 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002666 notifyRequester(request);
2667 }
2668 break;
2669 }
2670
2671 case EVENT_PROVISION_SATELLITE_SERVICE_DONE: {
2672 ar = (AsyncResult) msg.obj;
2673 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002674 int errorCode = getSatelliteError(ar, "provisionSatelliteService", false);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002675 handleEventProvisionSatelliteServiceDone(
2676 (ProvisionSatelliteServiceArgument) request.argument, errorCode);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002677 notifyRequester(request);
2678 break;
2679 }
2680
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002681 case CMD_DEPROVISION_SATELLITE_SERVICE: {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002682 request = (MainThreadRequest) msg.obj;
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002683 ProvisionSatelliteServiceArgument argument =
2684 (ProvisionSatelliteServiceArgument) request.argument;
Sarah Chin4beb2b72023-02-14 14:47:54 -08002685 onCompleted = obtainMessage(EVENT_DEPROVISION_SATELLITE_SERVICE_DONE, request);
2686 if (mIsSatelliteServiceSupported) {
2687 mSatelliteServiceController
2688 .deprovisionSatelliteService(argument.token, onCompleted);
2689 break;
2690 }
2691 Phone phone = getPhoneFromRequest(request);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002692 if (phone != null) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08002693 phone.deprovisionSatelliteService(onCompleted, argument.token);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002694 } else {
2695 loge("deprovisionSatelliteService: No phone object");
2696 if (argument.callback != null) {
2697 argument.callback.accept(
2698 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
2699 }
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002700 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002701 break;
2702 }
2703
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002704 case EVENT_DEPROVISION_SATELLITE_SERVICE_DONE: {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002705 ar = (AsyncResult) msg.obj;
2706 request = (MainThreadRequest) ar.userObj;
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002707 int errorCode = getSatelliteError(ar, "deprovisionSatelliteService", false);
2708 handleEventDeprovisionSatelliteServiceDone(
2709 (ProvisionSatelliteServiceArgument) request.argument, errorCode);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002710 break;
2711 }
2712
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002713 case CMD_SET_SATELLITE_ENABLED: {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002714 request = (MainThreadRequest) msg.obj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002715 Pair<Boolean, Consumer<Integer>> argument =
2716 (Pair<Boolean, Consumer<Integer>>) request.argument;
Sarah Chin4beb2b72023-02-14 14:47:54 -08002717 onCompleted = obtainMessage(EVENT_SET_SATELLITE_ENABLED_DONE, request);
2718 if (mIsSatelliteServiceSupported) {
2719 mSatelliteServiceController
2720 .requestSatelliteEnabled(argument.first, onCompleted);
2721 break;
2722 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002723 Phone phone = getPhoneFromRequest(request);
2724 if (phone != null) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08002725 phone.setSatellitePower(onCompleted, argument.first);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002726 } else {
Sarah Chin4beb2b72023-02-14 14:47:54 -08002727 loge("requestSatelliteEnabled: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002728 argument.second.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002729 }
2730 break;
2731 }
2732
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002733 case EVENT_SET_SATELLITE_ENABLED_DONE: {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002734 ar = (AsyncResult) msg.obj;
2735 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002736 Pair<Boolean, Consumer<Integer>> argument =
2737 (Pair<Boolean, Consumer<Integer>>) request.argument;
2738 int error = getSatelliteError(ar, "setSatelliteEnabled", false);
2739 argument.second.accept(error);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002740 break;
2741 }
2742
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002743 case CMD_IS_SATELLITE_ENABLED: {
Sarah Chin503828c2023-02-01 23:54:20 -08002744 request = (MainThreadRequest) msg.obj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002745 onCompleted = obtainMessage(EVENT_IS_SATELLITE_ENABLED_DONE, request);
Sarah Chin4beb2b72023-02-14 14:47:54 -08002746 if (mIsSatelliteServiceSupported) {
2747 mSatelliteServiceController.requestIsSatelliteEnabled(onCompleted);
2748 break;
2749 }
Sarah Chin503828c2023-02-01 23:54:20 -08002750 Phone phone = getPhoneFromRequest(request);
2751 if (phone != null) {
2752 phone.isSatellitePowerOn(onCompleted);
2753 } else {
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002754 loge("isSatelliteEnabled: No phone object");
2755 ((ResultReceiver) request.argument).send(
2756 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
Sarah Chin503828c2023-02-01 23:54:20 -08002757 }
2758 break;
2759 }
2760
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002761 case EVENT_IS_SATELLITE_ENABLED_DONE: {
Sarah Chin503828c2023-02-01 23:54:20 -08002762 ar = (AsyncResult) msg.obj;
2763 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002764 int error = getSatelliteError(ar, "isSatelliteEnabled", true);
2765 Bundle bundle = new Bundle();
2766 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
2767 boolean enabled = ((int[]) ar.result)[0] == 1;
2768 if (DBG) log("isSatelliteEnabled: " + enabled);
2769 bundle.putBoolean(SatelliteManager.KEY_SATELLITE_ENABLED, enabled);
Sarah Chin503828c2023-02-01 23:54:20 -08002770 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002771 ((ResultReceiver) request.argument).send(error, bundle);
Sarah Chin503828c2023-02-01 23:54:20 -08002772 break;
2773 }
2774
2775 case CMD_IS_SATELLITE_SUPPORTED: {
2776 request = (MainThreadRequest) msg.obj;
2777 onCompleted = obtainMessage(EVENT_IS_SATELLITE_SUPPORTED_DONE, request);
Sarah Chin4beb2b72023-02-14 14:47:54 -08002778 if (mIsSatelliteServiceSupported) {
2779 mSatelliteServiceController.requestIsSatelliteSupported(onCompleted);
2780 break;
2781 }
Sarah Chin503828c2023-02-01 23:54:20 -08002782 Phone phone = getPhoneFromRequest(request);
2783 if (phone != null) {
2784 phone.isSatelliteSupported(onCompleted);
2785 } else {
2786 loge("isSatelliteSupported: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002787 ((ResultReceiver) request.argument).send(
2788 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
Sarah Chin503828c2023-02-01 23:54:20 -08002789 }
2790 break;
2791 }
2792
2793 case EVENT_IS_SATELLITE_SUPPORTED_DONE: {
2794 ar = (AsyncResult) msg.obj;
2795 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002796 int error = getSatelliteError(ar, "isSatelliteSupported", true);
2797 Bundle bundle = new Bundle();
2798 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
2799 boolean supported = ((int[]) ar.result)[0] == 1;
2800 if (DBG) log("isSatelliteSupported: " + supported);
2801 bundle.putBoolean(SatelliteManager.KEY_SATELLITE_SUPPORTED, supported);
Thomas Nguyene77de6d2023-02-10 17:42:43 -08002802 synchronized (mIsSatelliteSupportedLock) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002803 mIsSatelliteSupported = supported;
2804 }
2805 } else {
2806 synchronized (mIsSatelliteSupportedLock) {
2807 mIsSatelliteSupported = null;
Thomas Nguyene77de6d2023-02-10 17:42:43 -08002808 }
Sarah Chin503828c2023-02-01 23:54:20 -08002809 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002810 ((ResultReceiver) request.argument).send(error, bundle);
Sarah Chin503828c2023-02-01 23:54:20 -08002811 break;
2812 }
2813
2814 case CMD_GET_SATELLITE_CAPABILITIES: {
2815 request = (MainThreadRequest) msg.obj;
2816 onCompleted = obtainMessage(EVENT_GET_SATELLITE_CAPABILITIES_DONE, request);
Sarah Chin4beb2b72023-02-14 14:47:54 -08002817 if (mIsSatelliteServiceSupported) {
2818 mSatelliteServiceController.requestSatelliteCapabilities(onCompleted);
2819 break;
2820 }
Sarah Chin503828c2023-02-01 23:54:20 -08002821 Phone phone = getPhoneFromRequest(request);
2822 if (phone != null) {
2823 phone.getSatelliteCapabilities(onCompleted);
2824 } else {
2825 loge("getSatelliteCapabilities: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002826 ((ResultReceiver) request.argument).send(
2827 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
Sarah Chin503828c2023-02-01 23:54:20 -08002828 }
2829 break;
2830 }
2831
2832 case EVENT_GET_SATELLITE_CAPABILITIES_DONE: {
2833 ar = (AsyncResult) msg.obj;
2834 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002835 int error = getSatelliteError(ar, "getSatelliteCapabilities", true);
2836 Bundle bundle = new Bundle();
2837 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
Sarah Chin503828c2023-02-01 23:54:20 -08002838 SatelliteCapabilities capabilities = (SatelliteCapabilities) ar.result;
2839 if (DBG) log("getSatelliteCapabilities: " + capabilities);
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002840 bundle.putParcelable(SatelliteManager.KEY_SATELLITE_CAPABILITIES,
2841 capabilities);
Sarah Chin503828c2023-02-01 23:54:20 -08002842 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002843 ((ResultReceiver) request.argument).send(error, bundle);
Sarah Chin503828c2023-02-01 23:54:20 -08002844 break;
2845 }
2846
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +00002847 case CMD_POLL_PENDING_SATELLITE_DATAGRAMS: {
2848 request = (MainThreadRequest) msg.obj;
Sarah Chin4beb2b72023-02-14 14:47:54 -08002849 onCompleted =
2850 obtainMessage(EVENT_POLL_PENDING_SATELLITE_DATAGRAMS_DONE, request);
2851 if (mIsSatelliteServiceSupported) {
2852 mSatelliteServiceController.pollPendingSatelliteDatagrams(onCompleted);
2853 break;
2854 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +00002855 Phone phone = getPhoneFromRequest(request);
2856 if (phone != null) {
2857 phone.pollPendingSatelliteDatagrams(onCompleted);
2858 } else {
2859 loge("pollPendingSatelliteDatagrams: No phone object");
Sarah Chin4beb2b72023-02-14 14:47:54 -08002860 ((Consumer<Integer>) request.argument).accept(
2861 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +00002862 }
2863 break;
2864 }
2865
2866 case EVENT_POLL_PENDING_SATELLITE_DATAGRAMS_DONE: {
2867 ar = (AsyncResult) msg.obj;
2868 request = (MainThreadRequest) ar.userObj;
Aishwarya Mallampati224317a2023-02-13 22:09:30 +00002869 int error = getSatelliteError(ar, "pollPendingSatelliteDatagrams", false);
2870 ((Consumer<Integer>) request.argument).accept(error);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +00002871 break;
2872 }
2873
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +00002874 case CMD_SEND_SATELLITE_DATAGRAM: {
2875 request = (MainThreadRequest) msg.obj;
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +00002876 SendSatelliteDatagramArgument argument =
2877 (SendSatelliteDatagramArgument) request.argument;
Sarah Chin4beb2b72023-02-14 14:47:54 -08002878 onCompleted = obtainMessage(EVENT_SEND_SATELLITE_DATAGRAM_DONE, request);
2879 if (mIsSatelliteServiceSupported) {
2880 // TODO: set isEmergency properly
2881 mSatelliteServiceController
2882 .sendSatelliteDatagram(argument.datagram, false, onCompleted);
2883 break;
2884 }
2885 Phone phone = getPhoneFromRequest(request);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +00002886 if (phone != null) {
2887 phone.sendSatelliteDatagram(onCompleted, argument.datagram);
2888 } else {
2889 loge("sendSatelliteDatagram: No phone object");
Sarah Chin4beb2b72023-02-14 14:47:54 -08002890 argument.callback.accept(
2891 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +00002892 }
2893 break;
2894 }
2895
2896 case EVENT_SEND_SATELLITE_DATAGRAM_DONE: {
2897 ar = (AsyncResult) msg.obj;
2898 request = (MainThreadRequest) ar.userObj;
Sarah Chin4beb2b72023-02-14 14:47:54 -08002899 int error = getSatelliteError(ar, "sendSatelliteDatagram", false);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +00002900 SendSatelliteDatagramArgument argument =
2901 (SendSatelliteDatagramArgument) request.argument;
2902 argument.callback.accept(error);
2903 break;
2904 }
2905
Sarah Chindf715ec2023-02-13 13:46:24 -08002906 case CMD_IS_SATELLITE_COMMUNICATION_ALLOWED: {
2907 request = (MainThreadRequest) msg.obj;
Sarah Chin4beb2b72023-02-14 14:47:54 -08002908 onCompleted =
2909 obtainMessage(EVENT_IS_SATELLITE_COMMUNICATION_ALLOWED_DONE, request);
2910 if (mIsSatelliteServiceSupported) {
2911 mSatelliteServiceController
2912 .requestIsSatelliteCommunicationAllowedForCurrentLocation(
2913 onCompleted);
2914 break;
2915 }
Sarah Chindf715ec2023-02-13 13:46:24 -08002916 Phone phone = getPhoneFromRequest(request);
2917 if (phone != null) {
2918 phone.isSatelliteCommunicationAllowedForCurrentLocation(onCompleted);
2919 } else {
2920 loge("isSatelliteCommunicationAllowedForCurrentLocation: No phone object");
2921 ((ResultReceiver) request.argument).send(
2922 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
2923 }
2924 break;
2925 }
2926
2927 case EVENT_IS_SATELLITE_COMMUNICATION_ALLOWED_DONE: {
2928 ar = (AsyncResult) msg.obj;
2929 request = (MainThreadRequest) ar.userObj;
2930 int error = getSatelliteError(
2931 ar, "isSatelliteCommunicationAllowedForCurrentLocation", true);
2932 Bundle bundle = new Bundle();
2933 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
2934 boolean communicationAllowed = ((int[]) ar.result)[0] == 1;
2935 if (DBG) {
2936 log("isSatelliteCommunicationAllowedForCurrentLocation: "
2937 + communicationAllowed);
2938 }
2939 bundle.putBoolean(SatelliteManager.KEY_SATELLITE_COMMUNICATION_ALLOWED,
2940 communicationAllowed);
2941 }
2942 ((ResultReceiver) request.argument).send(error, bundle);
2943 break;
2944 }
2945
2946 case CMD_GET_TIME_SATELLITE_NEXT_VISIBLE: {
2947 request = (MainThreadRequest) msg.obj;
2948 onCompleted = obtainMessage(EVENT_GET_TIME_SATELLITE_NEXT_VISIBLE_DONE,
2949 request);
Sarah Chin4beb2b72023-02-14 14:47:54 -08002950 if (mIsSatelliteServiceSupported) {
2951 mSatelliteServiceController
2952 .requestTimeForNextSatelliteVisibility(onCompleted);
2953 break;
2954 }
Sarah Chindf715ec2023-02-13 13:46:24 -08002955 Phone phone = getPhoneFromRequest(request);
2956 if (phone != null) {
2957 phone.requestTimeForNextSatelliteVisibility(onCompleted);
2958 } else {
2959 loge("requestTimeForNextSatelliteVisibility: No phone object");
2960 ((ResultReceiver) request.argument).send(
2961 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
2962 }
2963 break;
2964 }
2965
2966 case EVENT_GET_TIME_SATELLITE_NEXT_VISIBLE_DONE: {
2967 ar = (AsyncResult) msg.obj;
2968 request = (MainThreadRequest) ar.userObj;
2969 int error =
2970 getSatelliteError(ar, "requestTimeForNextSatelliteVisibility", true);
2971 Bundle bundle = new Bundle();
2972 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
2973 int nextVisibilityDuration = ((int[]) ar.result)[0];
2974 if (DBG) {
2975 log("requestTimeForNextSatelliteVisibility: " + nextVisibilityDuration);
2976 }
2977 bundle.putInt(SatelliteManager.KEY_SATELLITE_NEXT_VISIBILITY,
2978 nextVisibilityDuration);
2979 }
2980 ((ResultReceiver) request.argument).send(error, bundle);
2981 break;
2982 }
2983
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002984 default:
2985 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2986 break;
2987 }
2988 }
Jake Hambye994d462014-02-03 13:10:13 -08002989
Pengquan Menga1bb6272018-09-06 09:59:22 -07002990 private void notifyRequester(MainThreadRequest request) {
2991 synchronized (request) {
2992 request.notifyAll();
2993 }
2994 }
2995
Jake Hambye994d462014-02-03 13:10:13 -08002996 private void handleNullReturnEvent(Message msg, String command) {
2997 AsyncResult ar = (AsyncResult) msg.obj;
2998 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2999 if (ar.exception == null) {
3000 request.result = true;
3001 } else {
3002 request.result = false;
3003 if (ar.exception instanceof CommandException) {
3004 loge(command + ": CommandException: " + ar.exception);
3005 } else {
3006 loge(command + ": Unknown exception");
3007 }
3008 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003009 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08003010 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003011 }
3012
3013 /**
3014 * Posts the specified command to be executed on the main thread,
3015 * waits for the request to complete, and returns the result.
3016 * @see #sendRequestAsync
3017 */
3018 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08003019 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
3020 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07003021 }
3022
3023 /**
3024 * Posts the specified command to be executed on the main thread,
3025 * waits for the request to complete, and returns the result.
3026 * @see #sendRequestAsync
3027 */
3028 private Object sendRequest(int command, Object argument, WorkSource workSource) {
3029 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08003030 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07003031 }
3032
3033 /**
3034 * Posts the specified command to be executed on the main thread,
3035 * waits for the request to complete, and returns the result.
3036 * @see #sendRequestAsync
3037 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003038 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08003039 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
3040 }
3041
3042 /**
3043 * Posts the specified command to be executed on the main thread,
3044 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
3045 * if not timeout or null otherwise.
3046 * @see #sendRequestAsync
3047 */
3048 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
3049 long timeoutInMs) {
3050 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07003051 }
3052
3053 /**
3054 * Posts the specified command to be executed on the main thread,
3055 * waits for the request to complete, and returns the result.
3056 * @see #sendRequestAsync
3057 */
Nathan Harold92bed182018-10-12 18:16:49 -07003058 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08003059 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07003060 }
3061
3062 /**
3063 * Posts the specified command to be executed on the main thread,
3064 * waits for the request to complete, and returns the result.
3065 * @see #sendRequestAsync
3066 */
3067 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08003068 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
3069 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07003070 }
3071
3072 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08003073 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
3074 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
3075 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07003076 * @see #sendRequestAsync
3077 */
Rambo Wang0f050d82021-02-12 11:43:36 -08003078 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
3079 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003080 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
3081 throw new RuntimeException("This method will deadlock if called from the main thread.");
3082 }
3083
Nathan Harold92bed182018-10-12 18:16:49 -07003084 MainThreadRequest request = null;
3085 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
3086 throw new IllegalArgumentException("subId and phone cannot both be specified!");
3087 } else if (phone != null) {
3088 request = new MainThreadRequest(argument, phone, workSource);
3089 } else {
3090 request = new MainThreadRequest(argument, subId, workSource);
3091 }
3092
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003093 Message msg = mMainThreadHandler.obtainMessage(command, request);
3094 msg.sendToTarget();
3095
Rambo Wang0f050d82021-02-12 11:43:36 -08003096
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003097 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08003098 if (timeoutInMs >= 0) {
3099 // Wait for at least timeoutInMs before returning null request result
3100 long now = SystemClock.elapsedRealtime();
3101 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07003102 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08003103 try {
3104 request.wait(deadline - now);
3105 } catch (InterruptedException e) {
3106 // Do nothing, go back and check if request is completed or timeout
3107 } finally {
3108 now = SystemClock.elapsedRealtime();
3109 }
3110 }
3111 } else {
3112 // Wait for the request to complete
3113 while (request.result == null) {
3114 try {
3115 request.wait();
3116 } catch (InterruptedException e) {
3117 // Do nothing, go back and wait until the request is complete
3118 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003119 }
3120 }
3121 }
Rambo Wang0f050d82021-02-12 11:43:36 -08003122 if (request.result == null) {
3123 Log.wtf(LOG_TAG,
3124 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
3125 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003126 return request.result;
3127 }
3128
3129 /**
3130 * Asynchronous ("fire and forget") version of sendRequest():
3131 * Posts the specified command to be executed on the main thread, and
3132 * returns immediately.
3133 * @see #sendRequest
3134 */
3135 private void sendRequestAsync(int command) {
3136 mMainThreadHandler.sendEmptyMessage(command);
3137 }
3138
3139 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003140 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003141 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003142 */
3143 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003144 sendRequestAsync(command, argument, null, null);
3145 }
3146
3147 /**
3148 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
3149 * @see {@link #sendRequest(int,Object)}
3150 */
3151 private void sendRequestAsync(
3152 int command, Object argument, Phone phone, WorkSource workSource) {
3153 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003154 Message msg = mMainThreadHandler.obtainMessage(command, request);
3155 msg.sendToTarget();
3156 }
3157
3158 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003159 * Initialize the singleton PhoneInterfaceManager instance.
3160 * This is only done once, at startup, from PhoneApp.onCreate().
3161 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003162 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003163 synchronized (PhoneInterfaceManager.class) {
3164 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003165 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003166 } else {
3167 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
3168 }
3169 return sInstance;
3170 }
3171 }
3172
3173 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00003174 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003175 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003176 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00003177 mImsResolver = ImsResolver.getInstance();
Sarah Chin4beb2b72023-02-14 14:47:54 -08003178 mSatelliteServiceController = SatelliteServiceController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07003179 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003180 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
3181 mMainThreadHandler = new MainThreadHandler();
Jack Yue37dd262022-12-16 11:53:37 -08003182 if (!PhoneFactory.isSubscriptionManagerServiceEnabled()) {
3183 mSubscriptionController = SubscriptionController.getInstance();
3184 } else {
3185 mSubscriptionController = null;
3186 }
Sarah Chin4beb2b72023-02-14 14:47:54 -08003187 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07003188 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07003189 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08003190 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08003191 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07003192 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003193 publish();
arunvoddud7401012022-12-15 16:08:12 +00003194 CarrierAllowListInfo.loadInstance(mApp);
Sarah Chin4a9e8b82023-02-10 21:10:57 -08003195 mSatelliteSupportedReceiver = new ResultReceiver(mMainThreadHandler) {
3196 @Override
3197 protected void onReceiveResult(int resultCode, Bundle resultData) {
3198 if (resultCode == SatelliteManager.SATELLITE_ERROR_NONE
3199 && resultData.containsKey(SatelliteManager.KEY_SATELLITE_SUPPORTED)) {
3200 synchronized (mIsSatelliteSupportedLock) {
3201 mIsSatelliteSupported = resultData.getBoolean(
3202 SatelliteManager.KEY_SATELLITE_SUPPORTED);
3203 }
3204 } else {
3205 synchronized (mIsSatelliteSupportedLock) {
3206 mIsSatelliteSupported = null;
3207 }
3208 }
3209 }
3210 };
3211 requestIsSatelliteSupported(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
3212 mSatelliteSupportedReceiver);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003213 }
3214
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003215 @VisibleForTesting
3216 public SharedPreferences getSharedPreferences() {
3217 return mTelephonySharedPreferences;
3218 }
3219
Gil Cukierman92cc7db2023-01-06 19:25:53 +00003220 /**
3221 * Get the default phone for this device.
3222 */
3223 @VisibleForTesting
3224 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003225 Phone thePhone = getPhone(getDefaultSubscription());
3226 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
3227 }
3228
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003229 private void publish() {
3230 if (DBG) log("publish: " + this);
3231
Peter Wangc035ce42020-01-08 21:00:22 -08003232 TelephonyFrameworkInitializer
3233 .getTelephonyServiceManager()
3234 .getTelephonyServiceRegisterer()
3235 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003236 }
3237
Stuart Scott584921c2015-01-15 17:10:34 -08003238 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08003239 if (request.phone != null) {
3240 return request.phone;
3241 } else {
3242 return getPhoneFromSubId(request.subId);
3243 }
3244 }
3245
3246 private Phone getPhoneFromSubId(int subId) {
3247 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
3248 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08003249 }
3250
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00003251 /**
3252 * Get phone object associated with a subscription.
3253 * Return default phone if phone object associated with subscription is null
3254 * @param subId - subscriptionId
3255 * @return phone object associated with a subscription or default phone if null.
3256 */
3257 private Phone getPhoneFromSubIdOrDefault(int subId) {
3258 Phone phone = getPhoneFromSubId(subId);
3259 if (phone == null) {
3260 phone = getDefaultPhone();
3261 }
3262 return phone;
3263 }
3264
Rambo Wange53e07d2022-05-10 13:01:13 -07003265 @Nullable
3266 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003267 Phone phone = getPhoneFromRequest(request);
3268 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00003269 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003270 }
3271
Wink Saville36469e72014-06-11 15:17:00 -07003272 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07003273 private Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08003274 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07003275 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003276
Kai Shif70f46f2021-03-03 13:59:46 -08003277 private void sendEraseModemConfig(@NonNull Phone phone) {
3278 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
3279 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
3280 }
3281
3282 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
3283 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
3284 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07003285 }
3286
Peter Wang44b186e2020-01-13 23:33:09 -08003287 private boolean isImsAvailableOnDevice() {
3288 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
3289 if (pm == null) {
3290 // For some reason package manger is not available.. This will fail internally anyway,
3291 // so do not throw error and allow.
3292 return true;
3293 }
3294 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
3295 }
3296
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003297 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003298 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07003299 }
3300
Wink Savilleb564aae2014-10-23 10:18:09 -07003301 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003302 if (DBG) log("dial: " + number);
3303 // No permission check needed here: This is just a wrapper around the
3304 // ACTION_DIAL intent, which is available to any app since it puts up
3305 // the UI before it does anything.
3306
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003307 final long identity = Binder.clearCallingIdentity();
3308 try {
3309 String url = createTelUrl(number);
3310 if (url == null) {
3311 return;
3312 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003313
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003314 // PENDING: should we just silently fail if phone is offhook or ringing?
3315 PhoneConstants.State state = mCM.getState(subId);
3316 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
3317 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
3318 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3319 mApp.startActivity(intent);
3320 }
3321 } finally {
3322 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003323 }
3324 }
3325
3326 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003327 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07003328 }
3329
Wink Savilleb564aae2014-10-23 10:18:09 -07003330 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003331 if (DBG) log("call: " + number);
3332
3333 // This is just a wrapper around the ACTION_CALL intent, but we still
3334 // need to do a permission check since we're calling startActivity()
3335 // from the context of the phone app.
3336 enforceCallPermission();
3337
Jordan Liu1617b712019-07-10 15:06:26 -07003338 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003339 != AppOpsManager.MODE_ALLOWED) {
3340 return;
3341 }
3342
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003343 final long identity = Binder.clearCallingIdentity();
3344 try {
3345 String url = createTelUrl(number);
3346 if (url == null) {
3347 return;
3348 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003349
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003350 boolean isValid = false;
3351 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
3352 if (slist != null) {
3353 for (SubscriptionInfo subInfoRecord : slist) {
3354 if (subInfoRecord.getSubscriptionId() == subId) {
3355 isValid = true;
3356 break;
3357 }
Wink Saville3ab207e2014-11-20 13:07:20 -08003358 }
Wink Saville08874612014-08-31 19:19:58 -07003359 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003360 if (!isValid) {
3361 return;
3362 }
Wink Saville08874612014-08-31 19:19:58 -07003363
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003364 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
3365 intent.putExtra(SUBSCRIPTION_KEY, subId);
3366 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3367 mApp.startActivity(intent);
3368 } finally {
3369 Binder.restoreCallingIdentity(identity);
3370 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003371 }
3372
Wink Savilleb564aae2014-10-23 10:18:09 -07003373 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003374 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07003375 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
3376 }
3377
Wink Savilleb564aae2014-10-23 10:18:09 -07003378 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003379 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07003380 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
3381 }
3382
Wink Savilleb564aae2014-10-23 10:18:09 -07003383 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003384 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003385
3386 final long identity = Binder.clearCallingIdentity();
3387 try {
Michele Berionne5e411512020-11-13 02:36:59 +00003388 Phone phone = getPhone(subId);
3389 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003390 checkSimPin.start();
3391 return checkSimPin.unlockSim(null, pin);
3392 } finally {
3393 Binder.restoreCallingIdentity(identity);
3394 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003395 }
3396
Wink Savilleb564aae2014-10-23 10:18:09 -07003397 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003398 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003399
3400 final long identity = Binder.clearCallingIdentity();
3401 try {
Michele Berionne5e411512020-11-13 02:36:59 +00003402 Phone phone = getPhone(subId);
3403 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003404 checkSimPuk.start();
3405 return checkSimPuk.unlockSim(puk, pin);
3406 } finally {
3407 Binder.restoreCallingIdentity(identity);
3408 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003409 }
3410
3411 /**
Wink Saville9de0f752013-10-22 19:04:03 -07003412 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003413 * a synchronous one.
3414 */
3415 private static class UnlockSim extends Thread {
3416
3417 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00003418 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003419
3420 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07003421 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
3422 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003423
3424 // For replies from SimCard interface
3425 private Handler mHandler;
3426
3427 // For async handler to identify request type
3428 private static final int SUPPLY_PIN_COMPLETE = 100;
3429
Michele Berionne5e411512020-11-13 02:36:59 +00003430 UnlockSim(int phoneId, IccCard simCard) {
3431 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003432 mSimCard = simCard;
3433 }
3434
3435 @Override
3436 public void run() {
3437 Looper.prepare();
3438 synchronized (UnlockSim.this) {
3439 mHandler = new Handler() {
3440 @Override
3441 public void handleMessage(Message msg) {
3442 AsyncResult ar = (AsyncResult) msg.obj;
3443 switch (msg.what) {
3444 case SUPPLY_PIN_COMPLETE:
3445 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
3446 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07003447 mRetryCount = msg.arg1;
3448 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08003449 CommandException.Error error = null;
3450 if (ar.exception instanceof CommandException) {
3451 error = ((CommandException) (ar.exception))
3452 .getCommandError();
3453 }
3454 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07003455 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08003456 } else if (error == CommandException.Error.ABORTED) {
3457 /* When UiccCardApp dispose, handle message and return
3458 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08003459 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07003460 } else {
3461 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
3462 }
3463 } else {
3464 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
3465 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003466 mDone = true;
3467 UnlockSim.this.notifyAll();
3468 }
3469 break;
3470 }
3471 }
3472 };
3473 UnlockSim.this.notifyAll();
3474 }
3475 Looper.loop();
3476 }
3477
3478 /*
3479 * Use PIN or PUK to unlock SIM card
3480 *
3481 * If PUK is null, unlock SIM card with PIN
3482 *
3483 * If PUK is not null, unlock SIM card with PUK and set PIN code
3484 */
Wink Saville9de0f752013-10-22 19:04:03 -07003485 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003486
3487 while (mHandler == null) {
3488 try {
3489 wait();
3490 } catch (InterruptedException e) {
3491 Thread.currentThread().interrupt();
3492 }
3493 }
3494 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
3495
3496 if (puk == null) {
3497 mSimCard.supplyPin(pin, callback);
3498 } else {
3499 mSimCard.supplyPuk(puk, pin, callback);
3500 }
3501
3502 while (!mDone) {
3503 try {
3504 Log.d(LOG_TAG, "wait for done");
3505 wait();
3506 } catch (InterruptedException e) {
3507 // Restore the interrupted status
3508 Thread.currentThread().interrupt();
3509 }
3510 }
3511 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07003512 int[] resultArray = new int[2];
3513 resultArray[0] = mResult;
3514 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00003515
3516 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00003517 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00003518 }
3519
Wink Saville9de0f752013-10-22 19:04:03 -07003520 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003521 }
3522 }
3523
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003524 /**
3525 * This method has been removed due to privacy and stability concerns.
3526 */
3527 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003528 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003529 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
3530 return;
Wink Saville36469e72014-06-11 15:17:00 -07003531 }
3532
Nathan Harold1f889d82020-06-04 17:05:26 -07003533 @Override
3534 public void updateServiceLocationWithPackageName(String callingPackage) {
3535 mApp.getSystemService(AppOpsManager.class)
3536 .checkPackage(Binder.getCallingUid(), callingPackage);
3537
Nathan Haroldf096d982020-11-18 17:18:06 -08003538 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07003539 if (targetSdk > android.os.Build.VERSION_CODES.R) {
3540 // Callers targeting S have no business invoking this method.
3541 return;
3542 }
3543
3544 LocationAccessPolicy.LocationPermissionResult locationResult =
3545 LocationAccessPolicy.checkLocationPermission(mApp,
3546 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3547 .setCallingPackage(callingPackage)
3548 .setCallingFeatureId(null)
3549 .setCallingPid(Binder.getCallingPid())
3550 .setCallingUid(Binder.getCallingUid())
3551 .setMethod("updateServiceLocation")
3552 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3553 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3554 .build());
3555 // Apps that lack location permission have no business calling this method;
3556 // however, because no permission was declared in the public API, denials must
3557 // all be "soft".
3558 switch (locationResult) {
3559 case DENIED_HARD: /* fall through */
3560 case DENIED_SOFT:
3561 return;
3562 }
3563
3564 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003565 final long identity = Binder.clearCallingIdentity();
3566 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07003567 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003568 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07003569 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003570 }
3571 } finally {
3572 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003573 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003574 }
3575
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003576 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003577 @Override
3578 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003579 return isRadioOnWithFeature(callingPackage, null);
3580 }
3581
3582
3583 @Override
3584 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
3585 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
3586 callingFeatureId);
3587 }
3588
3589 @Deprecated
3590 @Override
3591 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
3592 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07003593 }
3594
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003595 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003596 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
3597 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003598 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003599 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003600 return false;
3601 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003602
3603 final long identity = Binder.clearCallingIdentity();
3604 try {
3605 return isRadioOnForSubscriber(subId);
3606 } finally {
3607 Binder.restoreCallingIdentity(identity);
3608 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003609 }
3610
3611 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003612 final long identity = Binder.clearCallingIdentity();
3613 try {
3614 final Phone phone = getPhone(subId);
3615 if (phone != null) {
3616 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
3617 } else {
3618 return false;
3619 }
3620 } finally {
3621 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003622 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003623 }
3624
3625 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003626 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003627 }
Wink Saville36469e72014-06-11 15:17:00 -07003628
Wink Savilleb564aae2014-10-23 10:18:09 -07003629 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003630 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003631
3632 final long identity = Binder.clearCallingIdentity();
3633 try {
3634 final Phone phone = getPhone(subId);
3635 if (phone != null) {
3636 phone.setRadioPower(!isRadioOnForSubscriber(subId));
3637 }
3638 } finally {
3639 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003640 }
Wink Saville36469e72014-06-11 15:17:00 -07003641 }
3642
3643 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003644 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07003645 }
3646
Wink Savilleb564aae2014-10-23 10:18:09 -07003647 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07003648 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003649
3650 final long identity = Binder.clearCallingIdentity();
3651 try {
3652 final Phone phone = getPhone(subId);
3653 if (phone == null) {
3654 return false;
3655 }
3656 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
3657 toggleRadioOnOffForSubscriber(subId);
3658 }
3659 return true;
3660 } finally {
3661 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003662 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003663 }
Wink Saville36469e72014-06-11 15:17:00 -07003664
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003665 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08003666 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003667 /*
3668 * If any of the Radios are available, it will need to be
3669 * shutdown. So return true if any Radio is available.
3670 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003671 final long identity = Binder.clearCallingIdentity();
3672 try {
3673 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3674 Phone phone = PhoneFactory.getPhone(i);
3675 if (phone != null && phone.isRadioAvailable()) return true;
3676 }
3677 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
3678 return false;
3679 } finally {
3680 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003681 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003682 }
3683
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003684 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003685 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003686 enforceModifyPermission();
3687
3688 final long identity = Binder.clearCallingIdentity();
3689 try {
3690 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3691 logv("Shutting down Phone " + i);
3692 shutdownRadioUsingPhoneId(i);
3693 }
3694 } finally {
3695 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003696 }
3697 }
3698
3699 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003700 Phone phone = PhoneFactory.getPhone(phoneId);
3701 if (phone != null && phone.isRadioAvailable()) {
3702 phone.shutdownRadio();
3703 }
3704 }
3705
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003706 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07003707 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003708
Ling Ma83dc5ea2023-01-12 15:06:04 -08003709 if (!turnOn) {
3710 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3711 }
3712
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003713 final long identity = Binder.clearCallingIdentity();
3714 try {
3715 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3716 if (defaultPhone != null) {
3717 defaultPhone.setRadioPower(turnOn);
3718 return true;
3719 } else {
3720 loge("There's no default phone.");
3721 return false;
3722 }
3723 } finally {
3724 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003725 }
Wink Saville36469e72014-06-11 15:17:00 -07003726 }
3727
Wink Savilleb564aae2014-10-23 10:18:09 -07003728 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003729 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003730
Ling Ma83dc5ea2023-01-12 15:06:04 -08003731 if (!turnOn) {
3732 log("setRadioPowerForSubscriber off: subId=" + subId
3733 + ",callingPackage=" + getCurrentPackageName());
3734 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003735 final long identity = Binder.clearCallingIdentity();
3736 try {
3737 final Phone phone = getPhone(subId);
3738 if (phone != null) {
3739 phone.setRadioPower(turnOn);
3740 return true;
3741 } else {
3742 return false;
3743 }
3744 } finally {
3745 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003746 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003747 }
3748
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003749 /**
3750 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3751 * no reason to power it off. When any of the voters want to power it off, it will be turned
3752 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3753 * powering it off, and these radio off votes will be cleared.
3754 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3755 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3756 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3757 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3758 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3759 * check its vote.
3760 *
3761 * @param subId The subscription ID.
3762 * @param reason The reason for powering off radio.
3763 * @return true on success and false on failure.
3764 */
3765 public boolean requestRadioPowerOffForReason(int subId,
3766 @TelephonyManager.RadioPowerReason int reason) {
3767 enforceModifyPermission();
3768
Ling Ma83dc5ea2023-01-12 15:06:04 -08003769 log("requestRadioPowerOffForReason: subId=" + subId
3770 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003771 final long identity = Binder.clearCallingIdentity();
3772 try {
3773 final Phone phone = getPhone(subId);
3774 if (phone != null) {
3775 phone.setRadioPowerForReason(false, reason);
3776 return true;
3777 } else {
3778 return false;
3779 }
3780 } finally {
3781 Binder.restoreCallingIdentity(identity);
3782 }
3783 }
3784
3785 /**
3786 * Remove the vote on powering off the radio for a reason, as requested by
3787 * {@link requestRadioPowerOffForReason}.
3788 *
3789 * @param subId The subscription ID.
3790 * @param reason The reason for powering off radio.
3791 * @return true on success and false on failure.
3792 */
3793 public boolean clearRadioPowerOffForReason(int subId,
3794 @TelephonyManager.RadioPowerReason int reason) {
3795 enforceModifyPermission();
3796
3797 final long identity = Binder.clearCallingIdentity();
3798 try {
3799 final Phone phone = getPhone(subId);
3800 if (phone != null) {
3801 phone.setRadioPowerForReason(true, reason);
3802 return true;
3803 } else {
3804 return false;
3805 }
3806 } finally {
3807 Binder.restoreCallingIdentity(identity);
3808 }
3809 }
3810
3811 /**
3812 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3813 *
3814 * @param subId The subscription ID.
3815 * @param callingPackage The package making the call.
3816 * @param callingFeatureId The feature in the package.
3817 * @return List of reasons for powering off radio.
3818 */
3819 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3820 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3821
3822 final long identity = Binder.clearCallingIdentity();
3823 List result = new ArrayList();
3824 try {
3825 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3826 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3827 return result;
3828 }
3829
3830 final Phone phone = getPhone(subId);
3831 if (phone != null) {
3832 result.addAll(phone.getRadioPowerOffReasons());
3833 }
3834 } finally {
3835 Binder.restoreCallingIdentity(identity);
3836 }
3837 return result;
3838 }
3839
Wink Saville36469e72014-06-11 15:17:00 -07003840 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003841 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003842 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003843 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003844
3845 final long identity = Binder.clearCallingIdentity();
3846 try {
Jack Yu285100e2022-12-02 22:48:35 -08003847 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003848 final Phone phone = getPhone(subId);
3849 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003850 phone.getDataSettingsManager().setDataEnabled(
3851 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003852 return true;
3853 } else {
3854 return false;
3855 }
3856 } finally {
3857 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003858 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003859 }
3860
Wink Saville36469e72014-06-11 15:17:00 -07003861 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003862 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003863 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003864 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003865
3866 final long identity = Binder.clearCallingIdentity();
3867 try {
Jack Yu285100e2022-12-02 22:48:35 -08003868 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003869 final Phone phone = getPhone(subId);
3870 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003871 phone.getDataSettingsManager().setDataEnabled(
3872 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003873 return true;
3874 } else {
3875 return false;
3876 }
3877 } finally {
3878 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003879 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003880 }
3881
Sanket Padawe356d7632015-06-22 14:03:32 -07003882 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003883 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003884 final long identity = Binder.clearCallingIdentity();
3885 try {
3886 final Phone phone = getPhone(subId);
3887 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003888 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003889 } else {
3890 return false;
3891 }
3892 } finally {
3893 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003894 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003895 }
3896
3897 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003898 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003899 }
3900
pkanwarae03a6b2016-11-06 20:37:09 -08003901 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003902 enforceCallPermission();
3903
3904 final long identity = Binder.clearCallingIdentity();
3905 try {
3906 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3907 return;
3908 }
3909 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3910 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3911 } finally {
3912 Binder.restoreCallingIdentity(identity);
3913 }
pkanwar32d516d2016-10-14 19:37:38 -07003914 };
3915
Wink Savilleb564aae2014-10-23 10:18:09 -07003916 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003917 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003918
3919 final long identity = Binder.clearCallingIdentity();
3920 try {
3921 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3922 return false;
3923 }
3924 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3925 } finally {
3926 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003927 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003928 }
3929
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003930 /**
3931 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3932 * tag on getCallState Binder call.
3933 */
3934 @Deprecated
3935 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003936 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003937 if (CompatChanges.isChangeEnabled(
3938 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3939 Binder.getCallingUid())) {
3940 // Do not allow this API to be called on API version 31+, it should only be
3941 // called on old apps using this Binder call directly.
3942 throw new SecurityException("This method can only be used for applications "
3943 + "targeting API version 30 or less.");
3944 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003945 final long identity = Binder.clearCallingIdentity();
3946 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003947 Phone phone = getPhone(getDefaultSubscription());
3948 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3949 PhoneConstantConversions.convertCallState(phone.getState());
3950 } finally {
3951 Binder.restoreCallingIdentity(identity);
3952 }
3953 }
3954
3955 @Override
3956 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3957 if (CompatChanges.isChangeEnabled(
3958 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3959 Binder.getCallingUid())) {
3960 // Check READ_PHONE_STATE for API version 31+
3961 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3962 featureId, "getCallStateForSubscription")) {
3963 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3964 + "targeting API level 31+.");
3965 }
3966 }
3967 final long identity = Binder.clearCallingIdentity();
3968 try {
3969 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003970 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3971 PhoneConstantConversions.convertCallState(phone.getState());
3972 } finally {
3973 Binder.restoreCallingIdentity(identity);
3974 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003975 }
3976
Sanket Padawe356d7632015-06-22 14:03:32 -07003977 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003978 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003979 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003980 }
3981
3982 @Override
3983 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003984 final long identity = Binder.clearCallingIdentity();
3985 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003986 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003987 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003988 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003989 } else {
3990 return PhoneConstantConversions.convertDataState(
3991 PhoneConstants.DataState.DISCONNECTED);
3992 }
3993 } finally {
3994 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003995 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003996 }
3997
Sanket Padawe356d7632015-06-22 14:03:32 -07003998 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003999 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08004000 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07004001 }
4002
4003 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07004004 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004005 final long identity = Binder.clearCallingIdentity();
4006 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07004007 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004008 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07004009 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004010 } else {
4011 return TelephonyManager.DATA_ACTIVITY_NONE;
4012 }
4013 } finally {
4014 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004015 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004016 }
4017
4018 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08004019 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004020 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08004021 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08004022
4023 LocationAccessPolicy.LocationPermissionResult locationResult =
4024 LocationAccessPolicy.checkLocationPermission(mApp,
4025 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4026 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004027 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004028 .setCallingPid(Binder.getCallingPid())
4029 .setCallingUid(Binder.getCallingUid())
4030 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08004031 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08004032 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4033 .build());
4034 switch (locationResult) {
4035 case DENIED_HARD:
4036 throw new SecurityException("Not allowed to access cell location");
4037 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08004038 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
4039 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004040 }
4041
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004042 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004043 final long identity = Binder.clearCallingIdentity();
4044 try {
4045 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08004046 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08004047 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004048 } finally {
4049 Binder.restoreCallingIdentity(identity);
4050 }
Svetoslav64fad262015-04-14 14:35:21 -07004051 }
4052
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004053 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08004054 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07004055 // Reporting the correct network country is ambiguous when IWLAN could conflict with
4056 // registered cell info, so return a NULL country instead.
4057 final long identity = Binder.clearCallingIdentity();
4058 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07004059 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
4060 // Get default phone in this case.
4061 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
4062 }
Jack Yu285100e2022-12-02 22:48:35 -08004063 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004064 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07004065 if (phone == null) return "";
4066 ServiceStateTracker sst = phone.getServiceStateTracker();
4067 if (sst == null) return "";
4068 LocaleTracker lt = sst.getLocaleTracker();
4069 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08004070 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07004071 } finally {
4072 Binder.restoreCallingIdentity(identity);
4073 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07004074 }
4075
Nathan Harold7c8d0f12020-05-28 20:40:31 -07004076 /**
4077 * This method was removed due to potential issues caused by performing partial
4078 * updates of service state, and lack of a credible use case.
4079 *
4080 * This has the ability to break the telephony implementation by disabling notification of
4081 * changes in device connectivity. DO NOT USE THIS!
4082 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07004083 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004084 public void enableLocationUpdates() {
4085 mApp.enforceCallingOrSelfPermission(
4086 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004087 }
4088
Nathan Harold7c8d0f12020-05-28 20:40:31 -07004089 /**
4090 * This method was removed due to potential issues caused by performing partial
4091 * updates of service state, and lack of a credible use case.
4092 *
4093 * This has the ability to break the telephony implementation by disabling notification of
4094 * changes in device connectivity. DO NOT USE THIS!
4095 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004096 @Override
4097 public void disableLocationUpdates() {
4098 mApp.enforceCallingOrSelfPermission(
4099 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004100 }
4101
4102 @Override
4103 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004104 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
4105 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07004106 try {
4107 mApp.getSystemService(AppOpsManager.class)
4108 .checkPackage(Binder.getCallingUid(), callingPackage);
4109 } catch (SecurityException e) {
4110 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
4111 throw e;
4112 }
4113
Nathan Haroldf096d982020-11-18 17:18:06 -08004114 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07004115 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
4116 throw new SecurityException(
4117 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
4118 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07004119
Jordan Liu1617b712019-07-10 15:06:26 -07004120 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004121 callingPackage) != AppOpsManager.MODE_ALLOWED) {
4122 return null;
4123 }
Svetoslav64fad262015-04-14 14:35:21 -07004124
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07004125 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004126
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004127 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07004128 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004129
Nathan Haroldf180aac2018-06-01 18:43:55 -07004130 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
4131 for (CellInfo ci : info) {
4132 if (ci instanceof CellInfoGsm) {
4133 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
4134 } else if (ci instanceof CellInfoWcdma) {
4135 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
4136 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004137 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07004138 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004139 }
4140
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004141 private List<CellInfo> getCachedCellInfo() {
4142 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
4143 for (Phone phone : PhoneFactory.getPhones()) {
4144 List<CellInfo> info = phone.getAllCellInfo();
4145 if (info != null) cellInfos.addAll(info);
4146 }
4147 return cellInfos;
4148 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004149
4150 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004151 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004152 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08004153 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08004154
4155 LocationAccessPolicy.LocationPermissionResult locationResult =
4156 LocationAccessPolicy.checkLocationPermission(mApp,
4157 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4158 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004159 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004160 .setCallingPid(Binder.getCallingPid())
4161 .setCallingUid(Binder.getCallingUid())
4162 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08004163 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08004164 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4165 .build());
4166 switch (locationResult) {
4167 case DENIED_HARD:
4168 throw new SecurityException("Not allowed to access cell info");
4169 case DENIED_SOFT:
4170 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004171 }
4172
Nathan Haroldf096d982020-11-18 17:18:06 -08004173 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004174 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
4175 return getCachedCellInfo();
4176 }
4177
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07004178 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004179 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004180 final long identity = Binder.clearCallingIdentity();
4181 try {
4182 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
4183 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07004184 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07004185 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004186 if (info != null) cellInfos.addAll(info);
4187 }
4188 return cellInfos;
4189 } finally {
4190 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004191 }
4192 }
4193
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07004194 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004195 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
4196 String callingFeatureId) {
4197 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
4198 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004199 }
4200
4201 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004202 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
4203 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004204 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004205 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004206 }
4207
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004208 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
4209 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004210 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004211 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08004212
4213 LocationAccessPolicy.LocationPermissionResult locationResult =
4214 LocationAccessPolicy.checkLocationPermission(mApp,
4215 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4216 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004217 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004218 .setCallingPid(Binder.getCallingPid())
4219 .setCallingUid(Binder.getCallingUid())
4220 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07004221 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
4222 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08004223 .build());
4224 switch (locationResult) {
4225 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08004226 if (TelephonyPermissions
4227 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07004228 // Safetynet logging for b/154934934
4229 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
4230 }
Hall Liuf19c44f2018-11-27 14:38:17 -08004231 throw new SecurityException("Not allowed to access cell info");
4232 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08004233 if (TelephonyPermissions
4234 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07004235 // Safetynet logging for b/154934934
4236 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
4237 }
Nathan Harold5320c422019-05-09 10:26:08 -07004238 try {
4239 cb.onCellInfo(new ArrayList<CellInfo>());
4240 } catch (RemoteException re) {
4241 // Drop without consequences
4242 }
Hall Liuf19c44f2018-11-27 14:38:17 -08004243 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004244 }
4245
Nathan Harolda939a962019-05-09 10:13:47 -07004246
4247 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004248 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
4249
4250 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
4251 }
4252
4253 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00004254 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08004255 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004256 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004257
4258 final long identity = Binder.clearCallingIdentity();
4259 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00004260 Phone phone = getPhone(subId);
4261 if (phone == null) {
4262 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
4263 } else {
4264 phone.setCellInfoListRate(rateInMillis, workSource);
4265 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004266 } finally {
4267 Binder.restoreCallingIdentity(identity);
4268 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004269 }
4270
Shishir Agrawala9f32182016-04-12 12:00:16 -07004271 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004272 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004273 Phone phone = PhoneFactory.getPhone(slotIndex);
4274 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004275 return null;
4276 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004277 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07004278 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07004279 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004280 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004281 return null;
4282 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004283
4284 final long identity = Binder.clearCallingIdentity();
4285 try {
4286 return phone.getImei();
4287 } finally {
4288 Binder.restoreCallingIdentity(identity);
4289 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07004290 }
4291
4292 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00004293 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
4294 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
4295 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
4296 callingFeatureId, "getPrimaryImei")) {
4297 throw new SecurityException("Caller does not have permission");
4298 }
4299 final long identity = Binder.clearCallingIdentity();
4300 try {
4301 for (Phone phone : PhoneFactory.getPhones()) {
4302 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
4303 return phone.getImei();
4304 }
4305 }
4306 throw new UnsupportedOperationException("Operation not supported");
4307 } finally {
4308 Binder.restoreCallingIdentity(identity);
4309 }
4310 }
4311
4312 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00004313 public String getTypeAllocationCodeForSlot(int slotIndex) {
4314 Phone phone = PhoneFactory.getPhone(slotIndex);
4315 String tac = null;
4316 if (phone != null) {
4317 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07004318 try {
4319 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
4320 } catch (IndexOutOfBoundsException e) {
4321 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
4322 return null;
4323 }
David Kelly5e06a7f2018-03-12 14:10:59 +00004324 }
4325 return tac;
4326 }
4327
4328 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004329 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07004330 try {
4331 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4332 } catch (SecurityException se) {
4333 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
4334 throw new SecurityException("Package " + callingPackage + " does not belong to "
4335 + Binder.getCallingUid());
4336 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004337 Phone phone = PhoneFactory.getPhone(slotIndex);
4338 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07004339 return null;
4340 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004341
Jeff Davidson913390f2018-02-23 17:11:49 -08004342 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07004343 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004344 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004345 return null;
4346 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004347
4348 final long identity = Binder.clearCallingIdentity();
4349 try {
4350 return phone.getMeid();
4351 } finally {
4352 Binder.restoreCallingIdentity(identity);
4353 }
Jack Yu2af8d712017-03-15 17:14:14 -07004354 }
4355
4356 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00004357 public String getManufacturerCodeForSlot(int slotIndex) {
4358 Phone phone = PhoneFactory.getPhone(slotIndex);
4359 String manufacturerCode = null;
4360 if (phone != null) {
4361 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07004362 try {
4363 manufacturerCode =
4364 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
4365 } catch (IndexOutOfBoundsException e) {
4366 Log.e(LOG_TAG, "MEID length shorter than upper index.");
4367 return null;
4368 }
David Kelly5e06a7f2018-03-12 14:10:59 +00004369 }
4370 return manufacturerCode;
4371 }
4372
4373 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004374 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
4375 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004376 Phone phone = PhoneFactory.getPhone(slotIndex);
4377 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004378 return null;
4379 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004380 int subId = phone.getSubId();
4381 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004382 mApp, subId, callingPackage, callingFeatureId,
4383 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004384 return null;
4385 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004386
4387 final long identity = Binder.clearCallingIdentity();
4388 try {
4389 return phone.getDeviceSvn();
4390 } finally {
4391 Binder.restoreCallingIdentity(identity);
4392 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07004393 }
4394
fionaxu43304da2017-11-27 22:51:16 -08004395 @Override
4396 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004397 final long identity = Binder.clearCallingIdentity();
4398 try {
4399 final Phone phone = getPhone(subId);
4400 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
4401 } finally {
4402 Binder.restoreCallingIdentity(identity);
4403 }
fionaxu43304da2017-11-27 22:51:16 -08004404 }
4405
4406 @Override
4407 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004408 final long identity = Binder.clearCallingIdentity();
4409 try {
4410 final Phone phone = getPhone(subId);
4411 return phone == null ? null : phone.getCarrierName();
4412 } finally {
4413 Binder.restoreCallingIdentity(identity);
4414 }
fionaxu43304da2017-11-27 22:51:16 -08004415 }
4416
calvinpanffe225e2018-11-01 19:43:06 +08004417 @Override
chen xu0026ca62019-03-06 15:28:50 -08004418 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08004419 final long identity = Binder.clearCallingIdentity();
4420 try {
4421 final Phone phone = getPhone(subId);
4422 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08004423 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08004424 } finally {
4425 Binder.restoreCallingIdentity(identity);
4426 }
4427 }
4428
4429 @Override
chen xu0026ca62019-03-06 15:28:50 -08004430 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08004431 final long identity = Binder.clearCallingIdentity();
4432 try {
4433 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08004434 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08004435 } finally {
4436 Binder.restoreCallingIdentity(identity);
4437 }
4438 }
4439
chen xu651eec72018-11-11 19:03:44 -08004440 @Override
chen xu864e11c2018-12-06 22:10:03 -08004441 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
4442 if (!isSubscriptionMccMnc) {
4443 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
4444 }
chen xu651eec72018-11-11 19:03:44 -08004445 final Phone phone = PhoneFactory.getPhone(slotIndex);
4446 if (phone == null) {
4447 return TelephonyManager.UNKNOWN_CARRIER_ID;
4448 }
4449 final long identity = Binder.clearCallingIdentity();
4450 try {
4451 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
4452 } finally {
4453 Binder.restoreCallingIdentity(identity);
4454 }
4455 }
4456
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004457 //
4458 // Internal helper methods.
4459 //
4460
Sanket Padaweee13a9b2016-03-08 17:30:28 -08004461 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07004462 * Make sure the caller is the calling package itself
4463 *
4464 * @throws SecurityException if the caller is not the calling package
4465 */
4466 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
4467 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07004468 PackageManager pm = mApp.getBaseContext().createContextAsUser(
4469 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07004470 try {
Grace Jiadbefca02021-04-26 15:13:31 -07004471 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07004472 } catch (PackageManager.NameNotFoundException e) {
4473 // packageUid is -1
4474 }
4475 if (packageUid != callingUid) {
4476 throw new SecurityException(message + ": Package " + callingPackage
4477 + " does not belong to " + callingUid);
4478 }
4479 }
4480
4481 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004482 * Make sure the caller has the MODIFY_PHONE_STATE permission.
4483 *
4484 * @throws SecurityException if the caller does not have the required permission
4485 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00004486 @VisibleForTesting
4487 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004488 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
4489 }
4490
Gil Cukierman1c0eb932022-12-06 22:28:24 +00004491 /**
arunvoddud7401012022-12-15 16:08:12 +00004492 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00004493 *
4494 * @throws SecurityException if the caller does not have the required permission
4495 */
4496 @VisibleForTesting
4497 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00004498 enforceReadPermission(null);
4499 }
4500
4501 /**
4502 * Make sure the caller has the READ_PHONE_STATE permissions.
4503 *
4504 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
4505 */
4506 @VisibleForTesting
4507 public void enforceReadPermission(String msg) {
4508 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00004509 }
4510
Shuo Qian3b6ee772019-11-13 17:43:31 -08004511 private void enforceActiveEmergencySessionPermission() {
4512 mApp.enforceCallingOrSelfPermission(
4513 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
4514 }
4515
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004516 /**
4517 * Make sure the caller has the CALL_PHONE permission.
4518 *
4519 * @throws SecurityException if the caller does not have the required permission
4520 */
4521 private void enforceCallPermission() {
4522 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
4523 }
4524
paulhu5a773602019-08-23 19:17:33 +08004525 private void enforceSettingsPermission() {
4526 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004527 }
4528
Michele Berionne5e411512020-11-13 02:36:59 +00004529 private void enforceRebootPermission() {
4530 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
4531 }
4532
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00004533 /**
4534 * Make sure the caller has SATELLITE_COMMUNICATION permission.
4535 * @param message - log message to print.
4536 * @throws SecurityException if the caller does not have the required permission
4537 */
4538 private void enforceSatelliteCommunicationPermission(String message) {
4539 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
4540 }
4541
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004542 private String createTelUrl(String number) {
4543 if (TextUtils.isEmpty(number)) {
4544 return null;
4545 }
4546
Jake Hambye994d462014-02-03 13:10:13 -08004547 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004548 }
4549
Ihab Awadf9e92732013-12-05 18:02:52 -08004550 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08004551 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004552 }
4553
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07004554 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08004555 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07004556 }
4557
Ihab Awadf9e92732013-12-05 18:02:52 -08004558 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08004559 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004560 }
4561
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004562 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004563 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07004564 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07004565 }
4566
Sanket Padawe356d7632015-06-22 14:03:32 -07004567 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004568 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004569 final long identity = Binder.clearCallingIdentity();
4570 try {
4571 final Phone phone = PhoneFactory.getPhone(slotIndex);
4572 if (phone == null) {
4573 return PhoneConstants.PHONE_TYPE_NONE;
4574 } else {
4575 return phone.getPhoneType();
4576 }
4577 } finally {
4578 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004579 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004580 }
4581
4582 /**
4583 * Returns the CDMA ERI icon index to display
4584 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004585 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004586 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
4587 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
4588 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004589 }
4590
Sanket Padawe356d7632015-06-22 14:03:32 -07004591 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004592 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
4593 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004594 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004595 mApp, subId, callingPackage, callingFeatureId,
4596 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004597 return -1;
4598 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004599
4600 final long identity = Binder.clearCallingIdentity();
4601 try {
4602 final Phone phone = getPhone(subId);
4603 if (phone != null) {
4604 return phone.getCdmaEriIconIndex();
4605 } else {
4606 return -1;
4607 }
4608 } finally {
4609 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004610 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004611 }
4612
4613 /**
4614 * Returns the CDMA ERI icon mode,
4615 * 0 - ON
4616 * 1 - FLASHING
4617 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004618 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004619 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
4620 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
4621 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004622 }
4623
Sanket Padawe356d7632015-06-22 14:03:32 -07004624 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004625 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
4626 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004627 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004628 mApp, subId, callingPackage, callingFeatureId,
4629 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004630 return -1;
4631 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004632
4633 final long identity = Binder.clearCallingIdentity();
4634 try {
4635 final Phone phone = getPhone(subId);
4636 if (phone != null) {
4637 return phone.getCdmaEriIconMode();
4638 } else {
4639 return -1;
4640 }
4641 } finally {
4642 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004643 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004644 }
4645
4646 /**
4647 * Returns the CDMA ERI text,
4648 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004649 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004650 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
4651 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4652 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004653 }
4654
Sanket Padawe356d7632015-06-22 14:03:32 -07004655 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004656 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4657 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004658 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004659 mApp, subId, callingPackage, callingFeatureId,
4660 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004661 return null;
4662 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004663
4664 final long identity = Binder.clearCallingIdentity();
4665 try {
4666 final Phone phone = getPhone(subId);
4667 if (phone != null) {
4668 return phone.getCdmaEriText();
4669 } else {
4670 return null;
4671 }
4672 } finally {
4673 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004674 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004675 }
4676
4677 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004678 * Returns the CDMA MDN.
4679 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004680 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004681 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004682 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4683 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004684
4685 final long identity = Binder.clearCallingIdentity();
4686 try {
4687 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004688 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004689 return phone.getLine1Number();
4690 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004691 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004692 return null;
4693 }
4694 } finally {
4695 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004696 }
4697 }
4698
4699 /**
4700 * Returns the CDMA MIN.
4701 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004702 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004703 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004704 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4705 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004706
4707 final long identity = Binder.clearCallingIdentity();
4708 try {
4709 final Phone phone = getPhone(subId);
4710 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4711 return phone.getCdmaMin();
4712 } else {
4713 return null;
4714 }
4715 } finally {
4716 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004717 }
4718 }
4719
Hall Liud892bec2018-11-30 14:51:45 -08004720 @Override
4721 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4722 INumberVerificationCallback callback, String callingPackage) {
4723 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4724 != PERMISSION_GRANTED) {
4725 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4726 }
4727 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4728
4729 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4730 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004731 throw new SecurityException("Calling package must be configured in the device config: "
4732 + "calling package: " + callingPackage
4733 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004734 }
4735
4736 if (range == null) {
4737 throw new NullPointerException("Range must be non-null");
4738 }
4739
4740 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004741 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004742
4743 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4744 }
4745
Junda Liuca05d5d2014-08-14 22:36:34 -07004746 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004747 * Returns true if CDMA provisioning needs to run.
4748 */
4749 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004750 final long identity = Binder.clearCallingIdentity();
4751 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004752 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004753 } finally {
4754 Binder.restoreCallingIdentity(identity);
4755 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004756 }
4757
4758 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004759 * Sets the voice mail number of a given subId.
4760 */
4761 @Override
4762 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004763 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4764 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004765
4766 final long identity = Binder.clearCallingIdentity();
4767 try {
4768 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4769 new Pair<String, String>(alphaTag, number), new Integer(subId));
4770 return success;
4771 } finally {
4772 Binder.restoreCallingIdentity(identity);
4773 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004774 }
4775
Ta-wei Yen87c49842016-05-13 21:19:52 -07004776 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004777 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4778 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004779 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4780 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004781 if (!TextUtils.equals(callingPackage, systemDialer)) {
4782 throw new SecurityException("caller must be system dialer");
4783 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004784
4785 final long identity = Binder.clearCallingIdentity();
4786 try {
4787 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4788 if (phoneAccountHandle == null) {
4789 return null;
4790 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004791 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004792 } finally {
4793 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004794 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004795 }
4796
4797 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004798 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4799 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004800 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004801 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004802 mApp, subId, callingPackage, callingFeatureId,
4803 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004804 return null;
4805 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004806
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004807 final long identity = Binder.clearCallingIdentity();
4808 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004809 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004810 } finally {
4811 Binder.restoreCallingIdentity(identity);
4812 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004813 }
4814
4815 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004816 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4817 VisualVoicemailSmsFilterSettings settings) {
4818 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004819
4820 final long identity = Binder.clearCallingIdentity();
4821 try {
4822 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004823 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004824 } finally {
4825 Binder.restoreCallingIdentity(identity);
4826 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004827 }
4828
4829 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004830 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4831 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004832
4833 final long identity = Binder.clearCallingIdentity();
4834 try {
4835 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004836 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004837 } finally {
4838 Binder.restoreCallingIdentity(identity);
4839 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004840 }
4841
4842 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004843 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4844 String callingPackage, int subId) {
4845 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004846
4847 final long identity = Binder.clearCallingIdentity();
4848 try {
4849 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004850 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004851 } finally {
4852 Binder.restoreCallingIdentity(identity);
4853 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004854 }
4855
4856 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004857 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004858 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004859
4860 final long identity = Binder.clearCallingIdentity();
4861 try {
4862 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004863 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004864 } finally {
4865 Binder.restoreCallingIdentity(identity);
4866 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004867 }
4868
4869 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004870 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4871 String callingAttributionTag, int subId, String number, int port, String text,
4872 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004873 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004874 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004875 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07004876 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004877 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4878 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004879 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004880
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004881 /**
fionaxu0152e512016-11-14 13:36:14 -08004882 * Sets the voice activation state of a given subId.
4883 */
4884 @Override
4885 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004886 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4887 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004888
4889 final long identity = Binder.clearCallingIdentity();
4890 try {
4891 final Phone phone = getPhone(subId);
4892 if (phone != null) {
4893 phone.setVoiceActivationState(activationState);
4894 } else {
4895 loge("setVoiceActivationState fails with invalid subId: " + subId);
4896 }
4897 } finally {
4898 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004899 }
4900 }
4901
4902 /**
4903 * Sets the data activation state of a given subId.
4904 */
4905 @Override
4906 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004907 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4908 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004909
4910 final long identity = Binder.clearCallingIdentity();
4911 try {
4912 final Phone phone = getPhone(subId);
4913 if (phone != null) {
4914 phone.setDataActivationState(activationState);
4915 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004916 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004917 }
4918 } finally {
4919 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004920 }
4921 }
4922
4923 /**
4924 * Returns the voice activation state of a given subId.
4925 */
4926 @Override
4927 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004928 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004929
fionaxu0152e512016-11-14 13:36:14 -08004930 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004931 final long identity = Binder.clearCallingIdentity();
4932 try {
4933 if (phone != null) {
4934 return phone.getVoiceActivationState();
4935 } else {
4936 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4937 }
4938 } finally {
4939 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004940 }
4941 }
4942
4943 /**
4944 * Returns the data activation state of a given subId.
4945 */
4946 @Override
4947 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004948 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004949
fionaxu0152e512016-11-14 13:36:14 -08004950 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004951 final long identity = Binder.clearCallingIdentity();
4952 try {
4953 if (phone != null) {
4954 return phone.getDataActivationState();
4955 } else {
4956 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4957 }
4958 } finally {
4959 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004960 }
4961 }
4962
4963 /**
Wink Saville36469e72014-06-11 15:17:00 -07004964 * Returns the unread count of voicemails for a subId
4965 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004966 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004967 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4968 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004969 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004970 mApp, subId, callingPackage, callingFeatureId,
4971 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004972 return 0;
4973 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004974 final long identity = Binder.clearCallingIdentity();
4975 try {
4976 final Phone phone = getPhone(subId);
4977 if (phone != null) {
4978 return phone.getVoiceMessageCount();
4979 } else {
4980 return 0;
4981 }
4982 } finally {
4983 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004984 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004985 }
4986
4987 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004988 * returns true, if the device is in a state where both voice and data
4989 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004990 */
4991 @Override
4992 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004993 final long identity = Binder.clearCallingIdentity();
4994 try {
4995 final Phone phone = getPhone(subId);
4996 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
4997 } finally {
4998 Binder.restoreCallingIdentity(identity);
4999 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08005000 }
5001
5002 /**
fionaxu235cc5e2017-03-06 22:25:57 -08005003 * Send the dialer code if called from the current default dialer or the caller has
5004 * carrier privilege.
5005 * @param inputCode The dialer code to send
5006 */
5007 @Override
5008 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005009 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08005010 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07005011 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
5012 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08005013 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005014 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005015 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08005016 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005017
5018 final long identity = Binder.clearCallingIdentity();
5019 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005020 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005021 } finally {
5022 Binder.restoreCallingIdentity(identity);
5023 }
fionaxu235cc5e2017-03-06 22:25:57 -08005024 }
5025
Pengquan Menga1bb6272018-09-06 09:59:22 -07005026 @Override
5027 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08005028 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005029 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5030 mApp, subId, "getNetworkSelectionMode");
shilufc958392020-01-20 11:36:01 -08005031 final long identity = Binder.clearCallingIdentity();
5032 try {
5033 if (!isActiveSubscription(subId)) {
5034 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
5035 }
5036 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
5037 } finally {
5038 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07005039 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005040 }
5041
Brad Ebinger35c841c2018-10-01 10:40:55 -07005042 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07005043 public boolean isInEmergencySmsMode() {
5044 enforceReadPrivilegedPermission("isInEmergencySmsMode");
5045 final long identity = Binder.clearCallingIdentity();
5046 try {
5047 for (Phone phone : PhoneFactory.getPhones()) {
5048 if (phone.isInEmergencySmsMode()) {
5049 return true;
5050 }
5051 }
5052 } finally {
5053 Binder.restoreCallingIdentity(identity);
5054 }
5055 return false;
5056 }
5057
shilu366312e2019-12-17 09:28:10 -08005058 /**
5059 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5060 * @param subId The subscription to use to check the configuration.
5061 * @param c The callback that will be used to send the result.
5062 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07005063 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005064 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
5065 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07005066 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005067 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00005068
5069 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5070 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5071 "IMS not available on device.");
5072 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07005073 final long token = Binder.clearCallingIdentity();
5074 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005075 int slotId = getSlotIndexOrException(subId);
5076 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00005077
5078 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5079 if (controller != null) {
5080 ImsManager imsManager = controller.getImsManager(subId);
5081 if (imsManager != null) {
5082 imsManager.addRegistrationCallbackForSubscription(c, subId);
5083 } else {
5084 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5085 }
5086 } else {
5087 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5088 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005089 } catch (ImsException e) {
5090 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005091 } finally {
5092 Binder.restoreCallingIdentity(token);
5093 }
5094 }
5095
shilu366312e2019-12-17 09:28:10 -08005096 /**
5097 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5098 * @param subId The subscription to use to check the configuration.
5099 * @param c The callback that will be used to send the result.
5100 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005101 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005102 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07005103 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005104 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005105 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5106 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5107 }
Meng Wangafbc5852019-09-19 17:37:13 -07005108 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00005109
Meng Wangafbc5852019-09-19 17:37:13 -07005110 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00005111 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5112 if (controller != null) {
5113 ImsManager imsManager = controller.getImsManager(subId);
5114 if (imsManager != null) {
5115 imsManager.removeRegistrationCallbackForSubscription(c, subId);
5116 } else {
5117 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
5118 + "is inactive, ignoring unregister.");
5119 // If the ImsManager is not valid, just return, since the callback
5120 // will already have been removed internally.
5121 }
5122 }
Meng Wangafbc5852019-09-19 17:37:13 -07005123 } finally {
5124 Binder.restoreCallingIdentity(token);
5125 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07005126 }
5127
Brad Ebingera34a6c22019-10-22 17:36:18 -07005128 /**
5129 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
5130 */
5131 @Override
5132 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
5133 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
5134 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5135 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5136 "IMS not available on device.");
5137 }
5138 final long token = Binder.clearCallingIdentity();
5139 try {
5140 Phone phone = getPhone(subId);
5141 if (phone == null) {
5142 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
5143 + subId + "'");
5144 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5145 }
5146 phone.getImsRegistrationState(regState -> {
5147 try {
5148 consumer.accept((regState == null)
5149 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
5150 } catch (RemoteException e) {
5151 // Ignore if the remote process is no longer available to call back.
5152 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
5153 }
5154 });
5155 } finally {
5156 Binder.restoreCallingIdentity(token);
5157 }
5158 }
5159
5160 /**
5161 * Get the transport type for the IMS service registration state.
5162 */
5163 @Override
5164 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07005165 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005166 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07005167 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5168 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5169 "IMS not available on device.");
5170 }
5171 final long token = Binder.clearCallingIdentity();
5172 try {
5173 Phone phone = getPhone(subId);
5174 if (phone == null) {
5175 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
5176 + subId + "'");
5177 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5178 }
5179 phone.getImsRegistrationTech(regTech -> {
5180 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
5181 int regTechConverted = (regTech == null)
5182 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
5183 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
5184 regTechConverted);
5185 try {
5186 consumer.accept(regTechConverted);
5187 } catch (RemoteException e) {
5188 // Ignore if the remote process is no longer available to call back.
5189 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
5190 }
5191 });
5192 } finally {
5193 Binder.restoreCallingIdentity(token);
5194 }
5195 }
5196
shilu366312e2019-12-17 09:28:10 -08005197 /**
5198 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5199 * @param subId The subscription to use to check the configuration.
5200 * @param c The callback that will be used to send the result.
5201 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005202 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005203 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
5204 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07005205 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005206 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00005207 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5208 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5209 "IMS not available on device.");
5210 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07005211 final long token = Binder.clearCallingIdentity();
5212 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005213 int slotId = getSlotIndexOrException(subId);
5214 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005215
5216 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5217 if (controller != null) {
5218 ImsManager imsManager = controller.getImsManager(subId);
5219 if (imsManager != null) {
5220 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
5221 } else {
5222 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5223 }
5224 } else {
5225 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5226 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005227 } catch (ImsException e) {
5228 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005229 } finally {
5230 Binder.restoreCallingIdentity(token);
5231 }
5232 }
5233
shilu366312e2019-12-17 09:28:10 -08005234 /**
5235 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5236 * @param subId The subscription to use to check the configuration.
5237 * @param c The callback that will be used to send the result.
5238 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005239 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005240 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07005241 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005242 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005243 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5244 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5245 }
Meng Wangafbc5852019-09-19 17:37:13 -07005246
5247 final long token = Binder.clearCallingIdentity();
5248 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005249 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5250 if (controller != null) {
5251 ImsManager imsManager = controller.getImsManager(subId);
5252 if (imsManager != null) {
5253 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
5254 } else {
5255 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
5256 + " is inactive, ignoring unregister.");
5257 // If the ImsManager is not valid, just return, since the callback
5258 // will already have been removed internally.
5259 }
5260 }
Meng Wangafbc5852019-09-19 17:37:13 -07005261 } finally {
5262 Binder.restoreCallingIdentity(token);
5263 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07005264 }
5265
5266 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005267 public boolean isCapable(int subId, int capability, int regTech) {
5268 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005269 final long token = Binder.clearCallingIdentity();
5270 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005271 int slotId = getSlotIndexOrException(subId);
5272 verifyImsMmTelConfiguredOrThrow(slotId);
5273 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
5274 } catch (com.android.ims.ImsException e) {
5275 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
5276 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005277 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08005278 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
5279 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07005280 } finally {
5281 Binder.restoreCallingIdentity(token);
5282 }
5283 }
5284
5285 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005286 public boolean isAvailable(int subId, int capability, int regTech) {
5287 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005288 final long token = Binder.clearCallingIdentity();
5289 try {
5290 Phone phone = getPhone(subId);
5291 if (phone == null) return false;
5292 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07005293 } catch (com.android.ims.ImsException e) {
5294 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
5295 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07005296 } finally {
5297 Binder.restoreCallingIdentity(token);
5298 }
5299 }
5300
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005301 /**
5302 * Determines if the MmTel feature capability is supported by the carrier configuration for this
5303 * subscription.
5304 * @param subId The subscription to use to check the configuration.
5305 * @param callback The callback that will be used to send the result.
5306 * @param capability The MmTelFeature capability that will be used to send the result.
5307 * @param transportType The transport type of the MmTelFeature capability.
5308 */
5309 @Override
5310 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
5311 int transportType) {
5312 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00005313 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5314 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5315 "IMS not available on device.");
5316 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005317 final long token = Binder.clearCallingIdentity();
5318 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005319 int slotId = getSlotIndex(subId);
5320 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5321 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
5322 + subId + "'");
5323 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5324 }
5325 verifyImsMmTelConfiguredOrThrow(slotId);
5326 ImsManager.getInstance(mApp, slotId).isSupported(capability,
5327 transportType, aBoolean -> {
5328 try {
5329 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
5330 } catch (RemoteException e) {
5331 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
5332 + "running. Ignore");
5333 }
5334 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005335 } catch (ImsException e) {
5336 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005337 } finally {
5338 Binder.restoreCallingIdentity(token);
5339 }
5340 }
5341
shilu366312e2019-12-17 09:28:10 -08005342 /**
5343 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5344 * @param subId The subscription to use to check the configuration.
5345 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005346 @Override
5347 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005348 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005349 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08005350
Brad Ebinger35c841c2018-10-01 10:40:55 -07005351 final long token = Binder.clearCallingIdentity();
5352 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005353 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005354 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005355 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005356 } catch (ImsException e) {
5357 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005358 } finally {
5359 Binder.restoreCallingIdentity(token);
5360 }
5361 }
5362
5363 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005364 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005365 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005366 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005367 final long identity = Binder.clearCallingIdentity();
5368 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005369 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005370 // This setting doesn't require an active ImsService connection, so do not verify. The
5371 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005372 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005373 } catch (ImsException e) {
5374 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005375 } finally {
5376 Binder.restoreCallingIdentity(identity);
5377 }
5378 }
5379
shilu366312e2019-12-17 09:28:10 -08005380 /**
5381 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5382 * @param subId The subscription to use to check the configuration.
5383 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005384 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005385 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005386 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005387 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005388 final long identity = Binder.clearCallingIdentity();
5389 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005390 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005391 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005392 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005393 } catch (ImsException e) {
5394 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005395 } finally {
5396 Binder.restoreCallingIdentity(identity);
5397 }
5398 }
5399
5400 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005401 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005402 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005403 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005404 final long identity = Binder.clearCallingIdentity();
5405 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005406 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005407 // This setting doesn't require an active ImsService connection, so do not verify. The
5408 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005409 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005410 } catch (ImsException e) {
5411 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005412 } finally {
5413 Binder.restoreCallingIdentity(identity);
5414 }
5415 }
5416
shilu366312e2019-12-17 09:28:10 -08005417 /**
5418 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5419 * @param subId The subscription to use to check the configuration.
5420 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005421 @Override
5422 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005423 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005424 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005425 final long identity = Binder.clearCallingIdentity();
5426 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005427 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005428 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005429 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005430 } catch (ImsException e) {
5431 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005432 } finally {
5433 Binder.restoreCallingIdentity(identity);
5434 }
5435 }
5436
5437 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005438 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005439 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005440 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005441 final long identity = Binder.clearCallingIdentity();
5442 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005443 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005444 // This setting doesn't require an active ImsService connection, so do not verify. The
5445 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005446 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005447 } catch (ImsException e) {
5448 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005449 } finally {
5450 Binder.restoreCallingIdentity(identity);
5451 }
5452 }
5453
shilu366312e2019-12-17 09:28:10 -08005454 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005455 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5456 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5457 * @param subId The subscription to use to check the configuration.
5458 */
5459 @Override
5460 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005461 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005462 mApp, subId, "isCrossSimCallingEnabledByUser");
5463 final long identity = Binder.clearCallingIdentity();
5464 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005465 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005466 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005467 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005468 } catch (ImsException e) {
5469 throw new ServiceSpecificException(e.getCode());
5470 } finally {
5471 Binder.restoreCallingIdentity(identity);
5472 }
5473 }
5474
5475 /**
5476 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5477 * Requires MODIFY_PHONE_STATE permission.
5478 * @param subId The subscription to use to check the configuration.
5479 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5480 * false otherwise
5481 */
5482 @Override
5483 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5484 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5485 "setCrossSimCallingEnabled");
5486 final long identity = Binder.clearCallingIdentity();
5487 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005488 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005489 // This setting doesn't require an active ImsService connection, so do not verify. The
5490 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005491 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005492 } catch (ImsException e) {
5493 throw new ServiceSpecificException(e.getCode());
5494 } finally {
5495 Binder.restoreCallingIdentity(identity);
5496 }
5497 }
5498
5499 /**
shilu366312e2019-12-17 09:28:10 -08005500 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5501 * @param subId The subscription to use to check the configuration.
5502 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005503 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005504
Brad Ebinger35c841c2018-10-01 10:40:55 -07005505 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005506 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005507 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005508 final long identity = Binder.clearCallingIdentity();
5509 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005510 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005511 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005512 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005513 } catch (ImsException e) {
5514 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005515 } finally {
5516 Binder.restoreCallingIdentity(identity);
5517 }
5518 }
5519
5520 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005521 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005522 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005523 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005524 final long identity = Binder.clearCallingIdentity();
5525 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005526 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005527 // This setting doesn't require an active ImsService connection, so do not verify. The
5528 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005529 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005530 } catch (ImsException e) {
5531 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005532 } finally {
5533 Binder.restoreCallingIdentity(identity);
5534 }
5535 }
5536
5537 @Override
5538 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5539 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5540 "setVoWiFiNonPersistent");
5541 final long identity = Binder.clearCallingIdentity();
5542 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005543 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005544 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005545 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005546 } catch (ImsException e) {
5547 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005548 } finally {
5549 Binder.restoreCallingIdentity(identity);
5550 }
5551 }
5552
shilu366312e2019-12-17 09:28:10 -08005553 /**
5554 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5555 * @param subId The subscription to use to check the configuration.
5556 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005557 @Override
5558 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005559 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005560 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005561 final long identity = Binder.clearCallingIdentity();
5562 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005563 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005564 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005565 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005566 } catch (ImsException e) {
5567 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005568 } finally {
5569 Binder.restoreCallingIdentity(identity);
5570 }
5571 }
5572
5573 @Override
5574 public void setVoWiFiModeSetting(int subId, int mode) {
5575 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5576 "setVoWiFiModeSetting");
5577 final long identity = Binder.clearCallingIdentity();
5578 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005579 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005580 // This setting doesn't require an active ImsService connection, so do not verify. The
5581 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005582 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005583 } catch (ImsException e) {
5584 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005585 } finally {
5586 Binder.restoreCallingIdentity(identity);
5587 }
5588 }
5589
5590 @Override
5591 public int getVoWiFiRoamingModeSetting(int subId) {
5592 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
5593 final long identity = Binder.clearCallingIdentity();
5594 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005595 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005596 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005597 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005598 } catch (ImsException e) {
5599 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005600 } finally {
5601 Binder.restoreCallingIdentity(identity);
5602 }
5603 }
5604
5605 @Override
5606 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5607 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5608 "setVoWiFiRoamingModeSetting");
5609 final long identity = Binder.clearCallingIdentity();
5610 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005611 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005612 // This setting doesn't require an active ImsService connection, so do not verify. The
5613 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005614 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005615 } catch (ImsException e) {
5616 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005617 } finally {
5618 Binder.restoreCallingIdentity(identity);
5619 }
5620 }
5621
5622 @Override
5623 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5624 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5625 "setRttCapabilityEnabled");
5626 final long identity = Binder.clearCallingIdentity();
5627 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005628 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005629 // This setting doesn't require an active ImsService connection, so do not verify. The
5630 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005631 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005632 } catch (ImsException e) {
5633 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005634 } finally {
5635 Binder.restoreCallingIdentity(identity);
5636 }
5637 }
5638
shilu366312e2019-12-17 09:28:10 -08005639 /**
5640 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5641 * @param subId The subscription to use to check the configuration.
5642 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005643 @Override
5644 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005645 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005646 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005647 final long identity = Binder.clearCallingIdentity();
5648 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005649 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005650 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005651 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005652 } catch (ImsException e) {
5653 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005654 } finally {
5655 Binder.restoreCallingIdentity(identity);
5656 }
5657 }
5658
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005659 @Override
5660 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5661 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005662
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005663 final long identity = Binder.clearCallingIdentity();
5664 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005665 if (!isImsAvailableOnDevice()) {
5666 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5667 "IMS not available on device.");
5668 }
5669 int slotId = getSlotIndexOrException(subId);
5670 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005671
5672 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5673 if (controller != null) {
5674 ImsManager imsManager = controller.getImsManager(subId);
5675 if (imsManager != null) {
5676 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5677 } else {
5678 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5679 }
5680 } else {
5681 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5682 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005683 } catch (ImsException e) {
5684 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005685 } finally {
5686 Binder.restoreCallingIdentity(identity);
5687 }
5688 }
5689
5690 @Override
5691 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5692 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005693
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005694 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005695 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5696 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5697 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005698 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005699 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5700 if (controller != null) {
5701 ImsManager imsManager = controller.getImsManager(subId);
5702 if (imsManager != null) {
5703 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5704 } else {
5705 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5706 + " is inactive, ignoring unregister.");
5707 // If the ImsManager is not valid, just return, since the callback will already
5708 // have been removed internally.
5709 }
5710 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005711 } finally {
5712 Binder.restoreCallingIdentity(identity);
5713 }
5714 }
5715
joonhunshincffb7fc2021-11-28 07:32:01 +00005716 @Override
5717 public void registerFeatureProvisioningChangedCallback(int subId,
5718 IFeatureProvisioningCallback callback) {
5719 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5720 mApp, subId, "registerFeatureProvisioningChangedCallback");
5721
5722 final long identity = Binder.clearCallingIdentity();
5723 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5724 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5725 }
5726
joonhunshin91bc1952022-04-29 08:47:15 +00005727 try {
5728 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5729 if (controller == null) {
5730 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5731 "Device does not support IMS");
5732 }
5733 controller.addFeatureProvisioningChangedCallback(subId, callback);
5734 } finally {
5735 Binder.restoreCallingIdentity(identity);
5736 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005737 }
5738
5739 @Override
5740 public void unregisterFeatureProvisioningChangedCallback(int subId,
5741 IFeatureProvisioningCallback callback) {
5742 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5743 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5744
5745 final long identity = Binder.clearCallingIdentity();
5746 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5747 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5748 }
5749
joonhunshin91bc1952022-04-29 08:47:15 +00005750 try {
5751 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5752 if (controller == null) {
5753 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5754 return;
5755 }
5756 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5757 } finally {
5758 Binder.restoreCallingIdentity(identity);
5759 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005760 }
allenwtsu99c623b2020-01-03 18:24:23 +08005761
5762 private void checkModifyPhoneStatePermission(int subId, String message) {
5763 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5764 message);
5765 }
5766
allenwtsu99c623b2020-01-03 18:24:23 +08005767 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005768 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005769 boolean isProvisioned) {
5770 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5771
5772 final long identity = Binder.clearCallingIdentity();
5773 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005774 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5775 if (controller == null) {
5776 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5777 return;
5778 }
5779 controller.setRcsProvisioningStatusForCapability(
5780 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005781 } finally {
5782 Binder.restoreCallingIdentity(identity);
5783 }
allenwtsu99c623b2020-01-03 18:24:23 +08005784 }
5785
5786
5787 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005788 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5789 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5790 mApp, subId, "getRcsProvisioningStatusForCapability");
5791
allenwtsu99c623b2020-01-03 18:24:23 +08005792 final long identity = Binder.clearCallingIdentity();
5793 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005794 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5795 if (controller == null) {
5796 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5797
5798 // device does not support IMS, this method will return true always.
5799 return true;
5800 }
5801 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005802 } finally {
5803 Binder.restoreCallingIdentity(identity);
5804 }
5805 }
5806
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005807 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005808 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5809 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005810 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005811
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005812 final long identity = Binder.clearCallingIdentity();
5813 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005814 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5815 if (controller == null) {
5816 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5817 return;
5818 }
5819 controller.setImsProvisioningStatusForCapability(
5820 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005821 } finally {
5822 Binder.restoreCallingIdentity(identity);
5823 }
5824 }
5825
5826 @Override
5827 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005828 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5829 mApp, subId, "getProvisioningStatusForCapability");
5830
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005831 final long identity = Binder.clearCallingIdentity();
5832 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005833 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5834 if (controller == null) {
5835 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005836
joonhunshin91bc1952022-04-29 08:47:15 +00005837 // device does not support IMS, this method will return true always.
5838 return true;
5839 }
5840 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005841 } finally {
5842 Binder.restoreCallingIdentity(identity);
5843 }
5844 }
5845
5846 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005847 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5848 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5849 mApp, subId, "isProvisioningRequiredForCapability");
5850
5851 final long identity = Binder.clearCallingIdentity();
5852 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005853 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5854 if (controller == null) {
5855 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5856
5857 // device does not support IMS, this method will return false
5858 return false;
5859 }
5860 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005861 } finally {
5862 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005863 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005864 }
5865
5866 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005867 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5868 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5869 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005870
joonhunshincffb7fc2021-11-28 07:32:01 +00005871 final long identity = Binder.clearCallingIdentity();
5872 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005873 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5874 if (controller == null) {
5875 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5876
5877 // device does not support IMS, this method will return false
5878 return false;
5879 }
5880 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005881 } finally {
5882 Binder.restoreCallingIdentity(identity);
5883 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005884 }
5885
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005886 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005887 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005888 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5889 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5890 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005891 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5892 mApp, subId, "getImsProvisioningInt");
5893
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005894 final long identity = Binder.clearCallingIdentity();
5895 try {
5896 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005897 int slotId = getSlotIndex(subId);
5898 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5899 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5900 + subId + "' for key:" + key);
5901 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5902 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005903
joonhunshin91bc1952022-04-29 08:47:15 +00005904 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5905 if (controller == null) {
5906 loge("getImsProvisioningInt: Device does not support IMS");
5907
5908 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5909 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5910 }
5911 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005912 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5913 return retVal;
5914 }
5915
calvinpanb5a34062021-02-08 19:59:36 +08005916 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005917 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005918 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5919 + subId + "' for key:" + key);
5920 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005921 } finally {
5922 Binder.restoreCallingIdentity(identity);
5923 }
5924 }
5925
5926 @Override
5927 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005928 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5929 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5930 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005931 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5932 mApp, subId, "getImsProvisioningString");
5933
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005934 final long identity = Binder.clearCallingIdentity();
5935 try {
5936 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005937 int slotId = getSlotIndex(subId);
5938 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5939 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5940 + subId + "' for key:" + key);
5941 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5942 }
calvinpanb5a34062021-02-08 19:59:36 +08005943 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005944 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005945 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5946 + subId + "' for key:" + key);
5947 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005948 } finally {
5949 Binder.restoreCallingIdentity(identity);
5950 }
5951 }
5952
5953 @Override
5954 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005955 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5956 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5957 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005958 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5959 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005960
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005961 final long identity = Binder.clearCallingIdentity();
5962 try {
5963 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005964 int slotId = getSlotIndex(subId);
5965 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5966 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5967 + subId + "' for key:" + key);
5968 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5969 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005970
joonhunshin91bc1952022-04-29 08:47:15 +00005971 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5972 if (controller == null) {
5973 loge("setImsProvisioningInt: Device does not support IMS");
5974
5975 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5976 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5977 }
5978 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005979 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5980 return retVal;
5981 }
5982
calvinpanb5a34062021-02-08 19:59:36 +08005983 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5984 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005985 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005986 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005987 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005988 } finally {
5989 Binder.restoreCallingIdentity(identity);
5990 }
5991 }
5992
5993 @Override
5994 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005995 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5996 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5997 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005998 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5999 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07006000 final long identity = Binder.clearCallingIdentity();
6001 try {
6002 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08006003 int slotId = getSlotIndex(subId);
6004 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6005 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
6006 + subId + "' for key:" + key);
6007 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
6008 }
calvinpanb5a34062021-02-08 19:59:36 +08006009 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
6010 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08006011 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08006012 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08006013 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07006014 } finally {
6015 Binder.restoreCallingIdentity(identity);
6016 }
6017 }
6018
Brad Ebinger919631e2021-06-02 17:46:35 -07006019 /**
6020 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
6021 * for the given slot ID or no ImsResolver instance has been created.
6022 * @param slotId The slot ID that the IMS service is created for.
6023 * @throws ImsException If there is no ImsService configured for this slot.
6024 */
6025 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
6026 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
6027 ImsFeature.FEATURE_MMTEL)) {
6028 throw new ImsException("This subscription does not support MMTEL over IMS",
6029 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
6030 }
6031 }
6032
Brad Ebinger1ce9c432019-07-16 13:19:44 -07006033 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006034 int slotId = SubscriptionManager.getSlotIndex(subId);
6035 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07006036 throw new ImsException("Invalid Subscription Id, subId=" + subId,
6037 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07006038 }
6039 return slotId;
6040 }
6041
Brad Ebinger1c8542e2019-01-14 13:43:14 -08006042 private int getSlotIndex(int subId) {
6043 int slotId = SubscriptionManager.getSlotIndex(subId);
6044 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
6045 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
6046 }
6047 return slotId;
6048 }
6049
Wink Saville36469e72014-06-11 15:17:00 -07006050 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07006051 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07006052 */
6053 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006054 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
6055 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07006056 try {
6057 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
6058 } catch (SecurityException se) {
6059 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
6060 throw new SecurityException("Package " + callingPackage + " does not belong to "
6061 + Binder.getCallingUid());
6062 }
Nathan Haroldf096d982020-11-18 17:18:06 -08006063 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07006064 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006065 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07006066 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07006067 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006068 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006069 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006070 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
6071 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07006072
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006073 final long identity = Binder.clearCallingIdentity();
6074 try {
6075 final Phone phone = getPhone(subId);
6076 if (phone != null) {
6077 return phone.getServiceState().getDataNetworkType();
6078 } else {
6079 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
6080 }
6081 } finally {
6082 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006083 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006084 }
6085
6086 /**
6087 * Returns the data network type
6088 */
6089 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006090 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08006091 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08006092 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07006093 }
6094
6095 /**
6096 * Returns the data network type for a subId
6097 */
6098 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006099 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
6100 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006101 String functionName = "getDataNetworkTypeForSubscriber";
6102 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
6103 mApp, functionName)) {
6104 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6105 mApp, subId, callingPackage, callingFeatureId, functionName)) {
6106 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
6107 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006108 }
6109
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006110 final long identity = Binder.clearCallingIdentity();
6111 try {
6112 final Phone phone = getPhone(subId);
6113 if (phone != null) {
6114 return phone.getServiceState().getDataNetworkType();
6115 } else {
6116 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
6117 }
6118 } finally {
6119 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006120 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006121 }
6122
6123 /**
Wink Saville36469e72014-06-11 15:17:00 -07006124 * Returns the Voice network type for a subId
6125 */
6126 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006127 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
6128 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006129 String functionName = "getVoiceNetworkTypeForSubscriber";
6130 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
6131 mApp, functionName)) {
6132 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6133 mApp, subId, callingPackage, callingFeatureId, functionName)) {
6134 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
6135 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07006136 }
6137
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006138 final long identity = Binder.clearCallingIdentity();
6139 try {
6140 final Phone phone = getPhone(subId);
6141 if (phone != null) {
6142 return phone.getServiceState().getVoiceNetworkType();
6143 } else {
6144 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
6145 }
6146 } finally {
6147 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006148 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006149 }
6150
6151 /**
6152 * @return true if a ICC card is present
6153 */
6154 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07006155 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08006156 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006157 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07006158 }
6159
6160 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006161 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07006162 */
Sanket Padawe356d7632015-06-22 14:03:32 -07006163 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006164 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006165 final long identity = Binder.clearCallingIdentity();
6166 try {
6167 final Phone phone = PhoneFactory.getPhone(slotIndex);
6168 if (phone != null) {
6169 return phone.getIccCard().hasIccCard();
6170 } else {
6171 return false;
6172 }
6173 } finally {
6174 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08006175 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006176 }
6177
6178 /**
6179 * Return if the current radio is LTE on CDMA. This
6180 * is a tri-state return value as for a period of time
6181 * the mode may be unknown.
6182 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006183 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006184 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08006185 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006186 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006187 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006188 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
6189 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
6190 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07006191 }
6192
Sanket Padawe356d7632015-06-22 14:03:32 -07006193 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006194 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
6195 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08006196 try {
6197 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
6198 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006199 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
6200 }
6201
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006202 final long identity = Binder.clearCallingIdentity();
6203 try {
6204 final Phone phone = getPhone(subId);
6205 if (phone == null) {
6206 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
6207 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07006208 return TelephonyProperties.lte_on_cdma_device()
6209 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006210 }
6211 } finally {
6212 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006213 }
Wink Saville36469e72014-06-11 15:17:00 -07006214 }
6215
Wink Saville36469e72014-06-11 15:17:00 -07006216 /**
6217 * {@hide}
6218 * Returns Default subId, 0 in the case of single standby.
6219 */
Wink Savilleb564aae2014-10-23 10:18:09 -07006220 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08006221 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07006222 }
6223
Shishir Agrawala9f32182016-04-12 12:00:16 -07006224 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08006225 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07006226 }
6227
Wink Savilleb564aae2014-10-23 10:18:09 -07006228 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08006229 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006230 }
Ihab Awadf2177b72013-11-25 13:33:23 -08006231
Pengquan Menge92a50d2018-09-21 15:54:48 -07006232 private boolean isActiveSubscription(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08006233 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08006234 return getSubscriptionManagerService().isActiveSubId(subId,
Jack Yu285100e2022-12-02 22:48:35 -08006235 mApp.getOpPackageName(), mApp.getFeatureId());
6236 }
Pengquan Menge92a50d2018-09-21 15:54:48 -07006237 return mSubscriptionController.isActiveSubId(subId);
6238 }
6239
Ihab Awadf2177b72013-11-25 13:33:23 -08006240 /**
6241 * @see android.telephony.TelephonyManager.WifiCallingChoices
6242 */
6243 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006244 final long identity = Binder.clearCallingIdentity();
6245 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006246 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006247 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
6248 getWhenToMakeWifiCallsDefaultPreference());
6249 } finally {
6250 Binder.restoreCallingIdentity(identity);
6251 }
Ihab Awadf2177b72013-11-25 13:33:23 -08006252 }
6253
6254 /**
6255 * @see android.telephony.TelephonyManager.WifiCallingChoices
6256 */
6257 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006258 final long identity = Binder.clearCallingIdentity();
6259 try {
6260 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006261 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006262 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
6263 } finally {
6264 Binder.restoreCallingIdentity(identity);
6265 }
Ihab Awadf9e92732013-12-05 18:02:52 -08006266 }
6267
Sailesh Nepald1e68152013-12-12 19:08:02 -08006268 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07006269 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08006270 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08006271 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08006272
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006273 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
6274 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
6275 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08006276 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006277 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006278 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08006279 }
6280 return PhoneFactory.getPhone(phoneId);
6281 }
6282
Shishir Agrawal566b7612013-10-28 14:41:00 -07006283 @Override
Derek Tan740e1672017-06-27 14:56:27 -07006284 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08006285 @NonNull IccLogicalChannelRequest request) {
6286 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6287 /*message=*/ "iccOpenLogicalChannel");
6288
6289 if (DBG) log("iccOpenLogicalChannel: request=" + request);
6290 // Verify that the callingPackage in the request belongs to the calling UID
6291 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
6292
6293 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006294 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006295
Rambo Wanga1782702021-11-10 20:15:19 -08006296 private Phone getPhoneFromValidIccLogicalChannelRequest(
6297 @NonNull IccLogicalChannelRequest request, String message) {
6298 Phone phone;
6299 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
6300 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6301 mApp, request.subId, message);
6302 phone = getPhoneFromSubId(request.subId);
6303 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6304 enforceModifyPermission();
6305 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
6306 } else {
6307 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08006308 }
Rambo Wanga1782702021-11-10 20:15:19 -08006309 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08006310 }
6311
6312 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08006313 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006314 final long identity = Binder.clearCallingIdentity();
6315 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006316 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006317 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006318 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6319 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08006320 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
6321 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006322 loge("The calling package is not allowed to access ISD-R.");
6323 throw new SecurityException(
6324 "The calling package is not allowed to access ISD-R.");
6325 }
Derek Tan740e1672017-06-27 14:56:27 -07006326 }
Derek Tan740e1672017-06-27 14:56:27 -07006327
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006328 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08006329 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
6330 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006331 return response;
6332 } finally {
6333 Binder.restoreCallingIdentity(identity);
6334 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006335 }
6336
6337 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08006338 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
6339 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6340 /*message=*/"iccCloseLogicalChannel");
6341
6342 if (DBG) log("iccCloseLogicalChannel: request=" + request);
6343
6344 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006345 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006346
Rambo Wanga1782702021-11-10 20:15:19 -08006347 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
6348 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08006349 // before this feature is enabled, this API should only return false if
6350 // the operation fails instead of throwing runtime exception for
6351 // backward-compatibility.
6352 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
6353 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006354 final long identity = Binder.clearCallingIdentity();
6355 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006356 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006357 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006358 }
Chen Xue9d737e2022-01-01 23:41:31 -08006359 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006360 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006361 Boolean success = false;
6362 if (result instanceof RuntimeException) {
6363 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006364 if (shouldThrowExceptionOnFailure) {
6365 throw (RuntimeException) result;
6366 } else {
6367 return false;
6368 }
Chen Xue9d737e2022-01-01 23:41:31 -08006369 } else if (result instanceof Boolean) {
6370 success = (Boolean) result;
6371 } else {
6372 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6373 }
Rambo Wanga1782702021-11-10 20:15:19 -08006374 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006375 return success;
6376 } finally {
6377 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006378 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006379 }
6380
6381 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006382 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006383 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006384 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6385 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08006386 if (DBG) {
6387 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6388 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6389 + p3 + " data=" + data);
6390 }
6391 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6392 command, p1, p2, p3, data);
6393 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006394
Jordan Liu4c733742019-02-28 12:03:40 -08006395 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006396 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006397 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006398 enforceModifyPermission();
6399 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006400 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006401 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6402 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006403 }
6404 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006405 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6406 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006407 }
6408
6409 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6410 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006411 final long identity = Binder.clearCallingIdentity();
6412 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006413 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006414 return "";
6415 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006416
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006417 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006418 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6419 null /* workSource */);
6420 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006421
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006422 // Append the returned status code to the end of the response payload.
6423 String s = Integer.toHexString(
6424 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6425 if (response.payload != null) {
6426 s = IccUtils.bytesToHexString(response.payload) + s;
6427 }
6428 return s;
6429 } finally {
6430 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006431 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006432 }
Jake Hambye994d462014-02-03 13:10:13 -08006433
Evan Charltonc66da362014-05-16 14:06:40 -07006434 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006435 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6436 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006437 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6438 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006439 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08006440 if (DBG) {
6441 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6442 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6443 }
6444 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6445 cla, command, p1, p2, p3, data);
6446 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006447
Jordan Liu4c733742019-02-28 12:03:40 -08006448 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006449 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006450 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006451 enforceModifyPermission();
6452 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
6453 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006454 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006455 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6456 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006457 }
6458
6459 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006460 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6461 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006462 }
6463
6464 // open APDU basic channel assuming the caller has sufficient permissions
6465 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6466 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006467 final long identity = Binder.clearCallingIdentity();
6468 try {
6469 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6470 && TextUtils.equals(ISDR_AID, data)) {
6471 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006472 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6473 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006474 if (bestComponent == null
6475 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6476 loge("The calling package is not allowed to select ISD-R.");
6477 throw new SecurityException(
6478 "The calling package is not allowed to select ISD-R.");
6479 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006480 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006481
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006482 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006483 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6484 null /* workSource */);
6485 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006486
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006487 // Append the returned status code to the end of the response payload.
6488 String s = Integer.toHexString(
6489 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6490 if (response.payload != null) {
6491 s = IccUtils.bytesToHexString(response.payload) + s;
6492 }
6493 return s;
6494 } finally {
6495 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006496 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006497 }
6498
6499 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006500 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006501 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006502 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6503 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006504
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006505 final long identity = Binder.clearCallingIdentity();
6506 try {
6507 if (DBG) {
6508 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6509 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6510 }
6511
6512 IccIoResult response =
6513 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6514 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6515 subId);
6516
6517 if (DBG) {
6518 log("Exchange SIM_IO [R]" + response);
6519 }
6520
6521 byte[] result = null;
6522 int length = 2;
6523 if (response.payload != null) {
6524 length = 2 + response.payload.length;
6525 result = new byte[length];
6526 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6527 } else {
6528 result = new byte[length];
6529 }
6530
6531 result[length - 1] = (byte) response.sw2;
6532 result[length - 2] = (byte) response.sw1;
6533 return result;
6534 } finally {
6535 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006536 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006537 }
6538
Nathan Haroldb3014052017-01-25 15:57:32 -08006539 /**
6540 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6541 * on a particular subscription
6542 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006543 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6544 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006545 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006546 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006547 return null;
6548 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006549
6550 final long identity = Binder.clearCallingIdentity();
6551 try {
6552 if (appType != TelephonyManager.APPTYPE_USIM
6553 && appType != TelephonyManager.APPTYPE_SIM) {
6554 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6555 return null;
6556 }
6557 Object response = sendRequest(
6558 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6559 if (response instanceof String[]) {
6560 return (String[]) response;
6561 }
yincheng zhao2737e882019-09-06 17:06:54 -07006562 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006563 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006564 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006565 } finally {
6566 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006567 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006568 }
6569
yincheng zhao2737e882019-09-06 17:06:54 -07006570 /**
6571 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6572 * subscription.
6573 *
6574 * @param subId the id of the subscription.
6575 * @param appType the uicc app type, must be USIM or SIM.
6576 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6577 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006578 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006579 * @return number of fplmns that is successfully written to the SIM.
6580 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006581 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6582 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006583 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6584 mApp, subId, "setForbiddenPlmns");
6585
yincheng zhao2737e882019-09-06 17:06:54 -07006586 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6587 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6588 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6589 }
6590 if (fplmns == null) {
6591 throw new IllegalArgumentException("Fplmn List provided is null");
6592 }
6593 for (String fplmn : fplmns) {
6594 if (!CellIdentity.isValidPlmn(fplmn)) {
6595 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6596 }
6597 }
6598 final long identity = Binder.clearCallingIdentity();
6599 try {
6600 Object response = sendRequest(
6601 CMD_SET_FORBIDDEN_PLMNS,
6602 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6603 subId);
6604 return (int) response;
6605 } finally {
6606 Binder.restoreCallingIdentity(identity);
6607 }
6608 }
6609
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006610 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006611 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006612 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6613 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006614
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006615 final long identity = Binder.clearCallingIdentity();
6616 try {
6617 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6618 if (response.payload == null) {
6619 return "";
6620 }
Evan Charltonc66da362014-05-16 14:06:40 -07006621
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006622 // Append the returned status code to the end of the response payload.
6623 String s = Integer.toHexString(
6624 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6625 s = IccUtils.bytesToHexString(response.payload) + s;
6626 return s;
6627 } finally {
6628 Binder.restoreCallingIdentity(identity);
6629 }
Evan Charltonc66da362014-05-16 14:06:40 -07006630 }
6631
Jake Hambye994d462014-02-03 13:10:13 -08006632 /**
6633 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6634 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6635 *
6636 * @param itemID the ID of the item to read
6637 * @return the NV item as a String, or null on error.
6638 */
6639 @Override
6640 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006641 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006642 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6643 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006644
6645 final long identity = Binder.clearCallingIdentity();
6646 try {
6647 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006648 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006649 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6650 return value;
6651 } finally {
6652 Binder.restoreCallingIdentity(identity);
6653 }
Jake Hambye994d462014-02-03 13:10:13 -08006654 }
6655
6656 /**
6657 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6658 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6659 *
6660 * @param itemID the ID of the item to read
6661 * @param itemValue the value to write, as a String
6662 * @return true on success; false on any failure
6663 */
6664 @Override
6665 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006666 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006667 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6668 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006669
6670 final long identity = Binder.clearCallingIdentity();
6671 try {
6672 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6673 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006674 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006675 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6676 return success;
6677 } finally {
6678 Binder.restoreCallingIdentity(identity);
6679 }
Jake Hambye994d462014-02-03 13:10:13 -08006680 }
6681
6682 /**
6683 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6684 * Used for device configuration by some CDMA operators.
6685 *
6686 * @param preferredRoamingList byte array containing the new PRL
6687 * @return true on success; false on any failure
6688 */
6689 @Override
6690 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006691 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6692 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006693
6694 final long identity = Binder.clearCallingIdentity();
6695 try {
6696 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6697 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6698 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6699 return success;
6700 } finally {
6701 Binder.restoreCallingIdentity(identity);
6702 }
Jake Hambye994d462014-02-03 13:10:13 -08006703 }
6704
6705 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006706 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006707 * Used for device configuration by some CDMA operators.
6708 *
chen xu6dac5ab2018-10-26 17:39:23 -07006709 * @param slotIndex - device slot.
6710 *
Jake Hambye994d462014-02-03 13:10:13 -08006711 * @return true on success; false on any failure
6712 */
6713 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006714 public boolean resetModemConfig(int slotIndex) {
6715 Phone phone = PhoneFactory.getPhone(slotIndex);
6716 if (phone != null) {
6717 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6718 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006719
chen xu6dac5ab2018-10-26 17:39:23 -07006720 final long identity = Binder.clearCallingIdentity();
6721 try {
6722 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6723 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6724 return success;
6725 } finally {
6726 Binder.restoreCallingIdentity(identity);
6727 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006728 }
chen xu6dac5ab2018-10-26 17:39:23 -07006729 return false;
6730 }
6731
6732 /**
6733 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6734 *
6735 * @param slotIndex - device slot.
6736 *
6737 * @return true on success; false on any failure
6738 */
6739 @Override
6740 public boolean rebootModem(int slotIndex) {
6741 Phone phone = PhoneFactory.getPhone(slotIndex);
6742 if (phone != null) {
6743 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6744 mApp, phone.getSubId(), "rebootModem");
6745
6746 final long identity = Binder.clearCallingIdentity();
6747 try {
6748 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6749 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6750 return success;
6751 } finally {
6752 Binder.restoreCallingIdentity(identity);
6753 }
6754 }
6755 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006756 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006757
Brad Ebinger51f743a2017-01-23 13:50:20 -08006758 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006759 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6760 * {@link #disableIms(int)}.
6761 * @param slotIndex device slot.
6762 */
6763 public void resetIms(int slotIndex) {
6764 enforceModifyPermission();
6765
6766 final long identity = Binder.clearCallingIdentity();
6767 try {
6768 if (mImsResolver == null) {
6769 // may happen if the does not support IMS.
6770 return;
6771 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006772 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006773 } finally {
6774 Binder.restoreCallingIdentity(identity);
6775 }
6776 }
6777
6778 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006779 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6780 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006781 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006782 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006783 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006784
6785 final long identity = Binder.clearCallingIdentity();
6786 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006787 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006788 // may happen if the device does not support IMS.
6789 return;
6790 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006791 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006792 } finally {
6793 Binder.restoreCallingIdentity(identity);
6794 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006795 }
6796
6797 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006798 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6799 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006800 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006801 public void disableIms(int slotId) {
6802 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006803
6804 final long identity = Binder.clearCallingIdentity();
6805 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006806 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006807 // may happen if the device does not support IMS.
6808 return;
6809 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006810 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006811 } finally {
6812 Binder.restoreCallingIdentity(identity);
6813 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006814 }
6815
6816 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006817 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6818 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006819 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006820 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006821 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006822 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006823
6824 final long identity = Binder.clearCallingIdentity();
6825 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006826 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006827 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6828 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006829 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006830 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006831 } finally {
6832 Binder.restoreCallingIdentity(identity);
6833 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006834 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006835 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006836 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6837 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006838 @Override
6839 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006840 enforceModifyPermission();
6841
6842 final long identity = Binder.clearCallingIdentity();
6843 try {
6844 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006845 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006846 } finally {
6847 Binder.restoreCallingIdentity(identity);
6848 }
6849 }
6850
6851 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006852 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006853 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006854 */
6855 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6856 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006857
6858 final long identity = Binder.clearCallingIdentity();
6859 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006860 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006861 // may happen if the device does not support IMS.
6862 return null;
6863 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006864 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006865 } finally {
6866 Binder.restoreCallingIdentity(identity);
6867 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006868 }
6869
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006870 /**
6871 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006872 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006873 */
6874 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6875 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006876
6877 final long identity = Binder.clearCallingIdentity();
6878 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006879 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006880 // may happen if the device does not support IMS.
6881 return null;
6882 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006883 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006884 } finally {
6885 Binder.restoreCallingIdentity(identity);
6886 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006887 }
6888
Brad Ebinger884c07b2018-02-15 16:17:40 -08006889 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006890 * Sets the ImsService Package Name that Telephony will bind to.
6891 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006892 * @param slotIndex the slot ID that the ImsService should bind for.
6893 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006894 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006895 * @param featureTypes An integer array of feature types associated with a packageName.
6896 * @param packageName The name of the package that the current configuration will be replaced
6897 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006898 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006899 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006900 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6901 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006902 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006903 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006904 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006905
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006906 final long identity = Binder.clearCallingIdentity();
6907 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006908 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006909 // may happen if the device does not support IMS.
6910 return false;
6911 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006912 Map<Integer, String> featureConfig = new HashMap<>();
6913 for (int featureType : featureTypes) {
6914 featureConfig.put(featureType, packageName);
6915 }
6916 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6917 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006918 } finally {
6919 Binder.restoreCallingIdentity(identity);
6920 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006921 }
6922
6923 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006924 * Clears any carrier ImsService overrides for the slot index specified that were previously
6925 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6926 *
6927 * This should only be used for testing.
6928 *
6929 * @param slotIndex the slot ID that the ImsService should bind for.
6930 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6931 */
6932 @Override
6933 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006934 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6935 "clearCarrierImsServiceOverride");
6936 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006937 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006938
6939 final long identity = Binder.clearCallingIdentity();
6940 try {
6941 if (mImsResolver == null) {
6942 // may happen if the device does not support IMS.
6943 return false;
6944 }
6945 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6946 } finally {
6947 Binder.restoreCallingIdentity(identity);
6948 }
6949 }
6950
6951 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006952 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006953 *
6954 * @param slotId The slot that the ImsService is associated with.
6955 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6956 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006957 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006958 * @return the package name of the ImsService configuration.
6959 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006960 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6961 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006962 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006963 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6964 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006965
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006966 final long identity = Binder.clearCallingIdentity();
6967 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006968 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006969 // may happen if the device does not support IMS.
6970 return "";
6971 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006972 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006973 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6974 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006975 } finally {
6976 Binder.restoreCallingIdentity(identity);
6977 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006978 }
6979
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006980 /**
6981 * Get the MmTelFeature state associated with the requested subscription id.
6982 * @param subId The subscription that the MmTelFeature is associated with.
6983 * @param callback A callback with an integer containing the
6984 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6985 */
6986 @Override
6987 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6988 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006989 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6990 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6991 "IMS not available on device.");
6992 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006993 final long token = Binder.clearCallingIdentity();
6994 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006995 int slotId = getSlotIndex(subId);
6996 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6997 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6998 + subId + "'");
6999 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
7000 }
7001 verifyImsMmTelConfiguredOrThrow(slotId);
7002 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
7003 try {
7004 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
7005 } catch (RemoteException e) {
7006 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
7007 + "Ignore");
7008 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007009 });
Brad Ebinger919631e2021-06-02 17:46:35 -07007010 } catch (ImsException e) {
7011 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007012 } finally {
7013 Binder.restoreCallingIdentity(token);
7014 }
7015 }
7016
Daniel Brightbb5840b2021-01-12 15:48:18 -08007017 /**
7018 * Sets the ims registration state on all valid {@link Phone}s.
7019 */
7020 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07007021 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007022
7023 final long identity = Binder.clearCallingIdentity();
7024 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08007025 // NOTE: Before S, this method only set the default phone.
7026 for (final Phone phone : PhoneFactory.getPhones()) {
7027 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
7028 phone.setImsRegistrationState(registered);
7029 }
7030 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007031 } finally {
7032 Binder.restoreCallingIdentity(identity);
7033 }
Wink Saville36469e72014-06-11 15:17:00 -07007034 }
7035
7036 /**
Stuart Scott54788802015-03-30 13:18:01 -07007037 * Set the network selection mode to automatic.
7038 *
7039 */
7040 @Override
7041 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007042 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7043 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007044
7045 final long identity = Binder.clearCallingIdentity();
7046 try {
shilufc958392020-01-20 11:36:01 -08007047 if (!isActiveSubscription(subId)) {
7048 return;
7049 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007050 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08007051 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
7052 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007053 } finally {
7054 Binder.restoreCallingIdentity(identity);
7055 }
Stuart Scott54788802015-03-30 13:18:01 -07007056 }
7057
Jack Yud10cdd42020-09-28 20:28:01 -07007058 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07007059 * Ask the radio to connect to the input network and change selection mode to manual.
7060 *
7061 * @param subId the id of the subscription.
7062 * @param operatorInfo the operator information, included the PLMN, long name and short name of
7063 * the operator to attach to.
7064 * @param persistSelection whether the selection will persist until reboot. If true, only allows
7065 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
7066 * normal network selection next time.
7067 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07007068 */
7069 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07007070 public boolean setNetworkSelectionModeManual(
7071 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007072 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7073 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07007074
Jack Yu285100e2022-12-02 22:48:35 -08007075 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07007076 if (!isActiveSubscription(subId)) {
7077 return false;
7078 }
7079
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007080 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07007081 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007082 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07007083 if (DBG) {
7084 log("setNetworkSelectionModeManual: subId: " + subId
7085 + " operator: " + operatorInfo);
7086 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007087 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
7088 } finally {
7089 Binder.restoreCallingIdentity(identity);
7090 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07007091 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007092 /**
shilu84f6e8b2019-12-19 13:58:01 -08007093 * Get the manual network selection
7094 *
7095 * @param subId the id of the subscription.
7096 *
7097 * @return the previously saved user selected PLMN
7098 */
7099 @Override
7100 public String getManualNetworkSelectionPlmn(int subId) {
7101 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007102 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
7103 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08007104
7105 final long identity = Binder.clearCallingIdentity();
7106 try {
7107 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07007108 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08007109 }
7110
7111 final Phone phone = getPhone(subId);
7112 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07007113 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08007114 }
7115 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
7116 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007117 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08007118 } finally {
7119 Binder.restoreCallingIdentity(identity);
7120 }
7121 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07007122
7123 /**
7124 * Scans for available networks.
7125 */
7126 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007127 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
7128 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007129 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7130 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08007131 LocationAccessPolicy.LocationPermissionResult locationResult =
7132 LocationAccessPolicy.checkLocationPermission(mApp,
7133 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7134 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007135 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007136 .setCallingPid(Binder.getCallingPid())
7137 .setCallingUid(Binder.getCallingUid())
7138 .setMethod("getCellNetworkScanResults")
7139 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007140 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7141 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007142 .build());
7143 switch (locationResult) {
7144 case DENIED_HARD:
7145 throw new SecurityException("Not allowed to access scan results -- location");
7146 case DENIED_SOFT:
7147 return null;
7148 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007149
Pengquan Menga1bb6272018-09-06 09:59:22 -07007150 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007151 try {
7152 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07007153 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007154 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007155 } finally {
7156 Binder.restoreCallingIdentity(identity);
7157 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07007158 }
7159
7160 /**
Shuo Qian4a594052020-01-23 11:59:30 -08007161 * Get the call forwarding info, given the call forwarding reason.
7162 */
7163 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007164 public void getCallForwarding(int subId, int callForwardingReason,
7165 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007166 enforceReadPrivilegedPermission("getCallForwarding");
7167 long identity = Binder.clearCallingIdentity();
7168 try {
7169 if (DBG) {
7170 log("getCallForwarding: subId " + subId
7171 + " callForwardingReason" + callForwardingReason);
7172 }
Hall Liu27d24262020-09-18 19:04:59 -07007173
7174 Phone phone = getPhone(subId);
7175 if (phone == null) {
7176 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07007177 callback.onError(
7178 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07007179 } catch (RemoteException e) {
7180 // ignore
7181 }
7182 return;
7183 }
7184
7185 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
7186 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
7187 @Override
7188 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
7189 try {
7190 callback.onCallForwardingInfoAvailable(info);
7191 } catch (RemoteException e) {
7192 // ignore
7193 }
7194 }
7195
7196 @Override
7197 public void onError(int error) {
7198 try {
7199 callback.onError(error);
7200 } catch (RemoteException e) {
7201 // ignore
7202 }
7203 }
7204 });
7205 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08007206 } finally {
7207 Binder.restoreCallingIdentity(identity);
7208 }
7209 }
7210
7211 /**
7212 * Sets the voice call forwarding info including status (enable/disable), call forwarding
7213 * reason, the number to forward, and the timeout before the forwarding is attempted.
7214 */
7215 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007216 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
7217 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007218 enforceModifyPermission();
7219 long identity = Binder.clearCallingIdentity();
7220 try {
7221 if (DBG) {
7222 log("setCallForwarding: subId " + subId
7223 + " callForwardingInfo" + callForwardingInfo);
7224 }
Hall Liu27d24262020-09-18 19:04:59 -07007225
7226 Phone phone = getPhone(subId);
7227 if (phone == null) {
7228 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07007229 callback.accept(
7230 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07007231 } catch (RemoteException e) {
7232 // ignore
7233 }
7234 return;
7235 }
7236
7237 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
7238 FunctionalUtils.ignoreRemoteException(callback::accept));
7239
7240 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08007241 } finally {
7242 Binder.restoreCallingIdentity(identity);
7243 }
7244 }
7245
7246 /**
Hall Liu27d24262020-09-18 19:04:59 -07007247 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007248 */
7249 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007250 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08007251 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08007252 long identity = Binder.clearCallingIdentity();
7253 try {
Hall Liu27d24262020-09-18 19:04:59 -07007254 Phone phone = getPhone(subId);
7255 if (phone == null) {
7256 try {
7257 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7258 } catch (RemoteException e) {
7259 // ignore
7260 }
7261 return;
7262 }
SongFerngWang0e767992021-03-31 22:08:45 +08007263 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7264 PersistableBundle c = configManager.getConfigForSubId(subId);
7265 boolean requireUssd = c.getBoolean(
7266 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007267
Shuo Qian4a594052020-01-23 11:59:30 -08007268 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08007269 if (requireUssd) {
7270 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7271 getSubscriptionCarrierId(subId));
7272 String newUssdCommand = "";
7273 try {
7274 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007275 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007276 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
7277 } catch (NullPointerException e) {
7278 loge("Failed to generate USSD number" + e);
7279 }
7280 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7281 mMainThreadHandler, callback, carrierXmlParser,
7282 CarrierXmlParser.SsEntry.SSAction.QUERY);
7283 final String ussdCommand = newUssdCommand;
7284 Executors.newSingleThreadExecutor().execute(() -> {
7285 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7286 });
7287 } else {
7288 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
7289 callback::accept);
7290 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
7291 }
Shuo Qian4a594052020-01-23 11:59:30 -08007292 } finally {
7293 Binder.restoreCallingIdentity(identity);
7294 }
7295 }
7296
7297 /**
Hall Liu27d24262020-09-18 19:04:59 -07007298 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007299 */
7300 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007301 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007302 enforceModifyPermission();
7303 long identity = Binder.clearCallingIdentity();
7304 try {
Hall Liu27d24262020-09-18 19:04:59 -07007305 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7306
7307 Phone phone = getPhone(subId);
7308 if (phone == null) {
7309 try {
7310 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7311 } catch (RemoteException e) {
7312 // ignore
7313 }
7314 return;
7315 }
7316
SongFerngWang0e767992021-03-31 22:08:45 +08007317 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7318 PersistableBundle c = configManager.getConfigForSubId(subId);
7319 boolean requireUssd = c.getBoolean(
7320 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007321
SongFerngWang0e767992021-03-31 22:08:45 +08007322 if (DBG) log("getCallWaitingStatus: subId " + subId);
7323 if (requireUssd) {
7324 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7325 getSubscriptionCarrierId(subId));
7326 CarrierXmlParser.SsEntry.SSAction ssAction =
7327 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7328 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7329 String newUssdCommand = "";
7330 try {
7331 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007332 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007333 .makeCommand(ssAction, null);
7334 } catch (NullPointerException e) {
7335 loge("Failed to generate USSD number" + e);
7336 }
7337 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7338 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7339 final String ussdCommand = newUssdCommand;
7340 Executors.newSingleThreadExecutor().execute(() -> {
7341 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7342 });
7343 } else {
7344 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7345 FunctionalUtils.ignoreRemoteException(callback::accept));
7346
7347 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7348 }
Shuo Qian4a594052020-01-23 11:59:30 -08007349 } finally {
7350 Binder.restoreCallingIdentity(identity);
7351 }
7352 }
7353
7354 /**
yinxub1bed742017-04-17 11:45:04 -07007355 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007356 *
yinxub1bed742017-04-17 11:45:04 -07007357 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007358 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7359 * location related information which will be sent if the caller already possess
7360 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007361 * @param request contains the radio access networks with bands/channels to scan
7362 * @param messenger callback messenger for scan results or errors
7363 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007364 * @return the id of the requested scan which can be used to stop the scan.
7365 */
7366 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007367 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7368 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007369 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007370 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7371 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007372 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007373 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7374 if (!renounceFineLocationAccess) {
7375 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007376 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7377 .setCallingPackage(callingPackage)
7378 .setCallingFeatureId(callingFeatureId)
7379 .setCallingPid(Binder.getCallingPid())
7380 .setCallingUid(Binder.getCallingUid())
7381 .setMethod("requestNetworkScan")
7382 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7383 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7384 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7385 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007386 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007387 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007388 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7389 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007390 if (e != null) {
7391 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7392 throw e;
7393 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007394 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007395 return TelephonyScanManager.INVALID_SCAN_ID;
7396 }
7397 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007398 }
Hall Liu912dfd32019-04-25 14:02:26 -07007399 int callingUid = Binder.getCallingUid();
7400 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007401 final long identity = Binder.clearCallingIdentity();
7402 try {
7403 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007404 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007405 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007406 } finally {
7407 Binder.restoreCallingIdentity(identity);
7408 }
yinxu504e1392017-04-12 16:03:22 -07007409 }
7410
Hall Liub2ac8ef2019-02-28 15:56:23 -08007411 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007412 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007413 boolean hasCarrierPriv;
7414 final long identity = Binder.clearCallingIdentity();
7415 try {
7416 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7417 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7418 } finally {
7419 Binder.restoreCallingIdentity(identity);
7420 }
Hall Liu558027f2019-05-15 19:14:05 -07007421 boolean hasNetworkScanPermission =
7422 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007423 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007424
7425 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7426 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7427 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007428 }
7429
7430 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7431 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007432 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7433 return new SecurityException("Specific channels must not be"
7434 + " scanned without location access.");
7435 }
7436 }
7437 }
7438
Hall Liub2ac8ef2019-02-28 15:56:23 -08007439 return null;
7440 }
7441
yinxu504e1392017-04-12 16:03:22 -07007442 /**
7443 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007444 *
7445 * @param subId id of the subscription
7446 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007447 */
7448 @Override
7449 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007450 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7451 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007452
Hall Liu912dfd32019-04-25 14:02:26 -07007453 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007454 final long identity = Binder.clearCallingIdentity();
7455 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007456 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007457 } finally {
7458 Binder.restoreCallingIdentity(identity);
7459 }
yinxu504e1392017-04-12 16:03:22 -07007460 }
7461
7462 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007463 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007464 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007465 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007466 */
7467 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007468 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007469 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007470 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007471 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007472
7473 final long identity = Binder.clearCallingIdentity();
7474 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007475 if (DBG) log("getAllowedNetworkTypesBitmask");
7476 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7477 int networkTypesBitmask = (result != null ? result[0] : -1);
7478 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7479 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007480 } finally {
7481 Binder.restoreCallingIdentity(identity);
7482 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007483 }
7484
7485 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007486 * Get the allowed network types for certain reason.
7487 *
7488 * @param subId the id of the subscription.
7489 * @param reason the reason the allowed network type change is taking place
7490 * @return the allowed network types.
7491 */
7492 @Override
7493 public long getAllowedNetworkTypesForReason(int subId,
7494 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007495 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007496 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007497 final long identity = Binder.clearCallingIdentity();
7498 try {
7499 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
7500 } finally {
7501 Binder.restoreCallingIdentity(identity);
7502 }
7503 }
7504
7505 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007506 * Enable/Disable E-UTRA-NR Dual Connectivity
7507 * @param subId subscription id of the sim card
7508 * @param nrDualConnectivityState expected NR dual connectivity state
7509 * This can be passed following states
7510 * <ol>
7511 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7512 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7513 * <li>Disable NR dual connectivity and force secondary cell to be released
7514 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7515 * </ol>
7516 * @return operation result.
7517 */
7518 @Override
7519 public int setNrDualConnectivityState(int subId,
7520 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7521 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7522 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007523 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007524 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7525 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7526 }
7527
Sooraj Sasindran37444802020-08-11 10:40:43 -07007528 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7529 final long identity = Binder.clearCallingIdentity();
7530 try {
7531 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7532 nrDualConnectivityState, subId,
7533 workSource);
7534 if (DBG) log("enableNRDualConnectivity result: " + result);
7535 return result;
7536 } finally {
7537 Binder.restoreCallingIdentity(identity);
7538 }
7539 }
7540
7541 /**
7542 * Is E-UTRA-NR Dual Connectivity enabled
7543 * @return true if dual connectivity is enabled else false
7544 */
7545 @Override
7546 public boolean isNrDualConnectivityEnabled(int subId) {
7547 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007548 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007549 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007550 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007551 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7552 return false;
7553 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007554 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7555 final long identity = Binder.clearCallingIdentity();
7556 try {
7557 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7558 null, subId, workSource);
7559 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7560 return isEnabled;
7561 } finally {
7562 Binder.restoreCallingIdentity(identity);
7563 }
7564 }
7565
7566 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007567 * Set the allowed network types of the device and
7568 * provide the reason triggering the allowed network change.
7569 *
7570 * @param subId the id of the subscription.
7571 * @param reason the reason the allowed network type change is taking place
7572 * @param allowedNetworkTypes the allowed network types.
7573 * @return true on success; false on any failure.
7574 */
7575 @Override
7576 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007577 @TelephonyManager.AllowedNetworkTypesReason int reason,
7578 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007579 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7580 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007581 // If the caller only has carrier privileges, then they should not be able to override
7582 // any network types which were set for security reasons.
7583 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7584 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007585 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007586 throw new SecurityException(
7587 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007588 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007589 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08007590 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007591 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007592 return false;
7593 }
7594 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7595 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007596 return false;
7597 }
7598
Jack Yu5b494332023-01-23 18:18:04 +00007599 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7600 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007601
Jack Yue37dd262022-12-16 11:53:37 -08007602 Phone phone = getPhone(subId);
7603 if (phone == null) {
7604 return false;
7605 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007606
Jack Yue37dd262022-12-16 11:53:37 -08007607 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007608 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007609 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007610 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007611
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007612 final long identity = Binder.clearCallingIdentity();
7613 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007614 Boolean success = (Boolean) sendRequest(
7615 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7616 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7617
7618 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7619 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007620 } finally {
7621 Binder.restoreCallingIdentity(identity);
7622 }
7623 }
7624
7625 /**
Miaoa84611c2019-03-15 09:21:10 +08007626 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007627 *
Miaoa84611c2019-03-15 09:21:10 +08007628 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007629 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007630 * @hide
7631 */
7632 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007633 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007634 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007635 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007636 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007637 try {
Miaoa84611c2019-03-15 09:21:10 +08007638 if (phone != null) {
7639 return phone.hasMatchedTetherApnSetting();
7640 } else {
7641 return false;
7642 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007643 } finally {
7644 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007645 }
Junda Liu475951f2014-11-07 16:45:03 -08007646 }
7647
7648 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007649 * Get the user enabled state of Mobile Data.
7650 *
7651 * TODO: remove and use isUserDataEnabled.
7652 * This can't be removed now because some vendor codes
7653 * calls through ITelephony directly while they should
7654 * use TelephonyManager.
7655 *
7656 * @return true on enabled
7657 */
7658 @Override
7659 public boolean getDataEnabled(int subId) {
7660 return isUserDataEnabled(subId);
7661 }
7662
7663 /**
7664 * Get whether mobile data is enabled per user setting.
7665 *
7666 * There are other factors deciding whether mobile data is actually enabled, but they are
7667 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007668 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007669 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7670 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007671 *
7672 * @return {@code true} if data is enabled else {@code false}
7673 */
7674 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007675 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007676 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007677 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007678 try {
7679 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7680 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007681 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007682 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7683 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007684 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007685 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007686 mApp, subId, functionName);
7687
Robert Greenwalt646120a2014-05-23 11:54:03 -07007688 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007689
7690 final long identity = Binder.clearCallingIdentity();
7691 try {
Jack Yu285100e2022-12-02 22:48:35 -08007692 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007693 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7694 Phone phone = PhoneFactory.getPhone(phoneId);
7695 if (phone != null) {
7696 boolean retVal = phone.isUserDataEnabled();
7697 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7698 return retVal;
7699 } else {
7700 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7701 return false;
7702 }
7703 } finally {
7704 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007705 }
7706 }
7707
7708 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007709 * Checks if the device is capable of mobile data by considering whether whether the
7710 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7711 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007712 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007713 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007714 */
7715 @Override
7716 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007717 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007718 try {
7719 try {
7720 mApp.enforceCallingOrSelfPermission(
7721 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007722 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007723 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007724 try {
7725 mApp.enforceCallingOrSelfPermission(
7726 android.Manifest.permission.READ_PHONE_STATE,
7727 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007728 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007729 mApp.enforceCallingOrSelfPermission(
7730 permission.READ_BASIC_PHONE_STATE, functionName);
7731 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007732 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007733 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007734 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007735 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007736
7737 final long identity = Binder.clearCallingIdentity();
7738 try {
Jack Yu285100e2022-12-02 22:48:35 -08007739 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007740 Phone phone = PhoneFactory.getPhone(phoneId);
7741 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007742 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007743 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007744 return retVal;
7745 } else {
7746 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7747 return false;
7748 }
7749 } finally {
7750 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007751 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007752 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007753
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007754 /**
7755 * Check if data is enabled for a specific reason
7756 * @param subId Subscription index
7757 * @param reason the reason the data enable change is taking place
7758 * @return {@code true} if the overall data is enabled; {@code false} if not.
7759 */
7760 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007761 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007762 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007763 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007764 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007765 try {
7766 mApp.enforceCallingOrSelfPermission(
7767 android.Manifest.permission.ACCESS_NETWORK_STATE,
7768 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007769 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007770 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7771 functionName);
7772 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007773 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007774 try {
7775 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007776 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007777 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007778 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007779 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007780 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007781 }
7782
7783
7784 final long identity = Binder.clearCallingIdentity();
7785 try {
Jack Yu285100e2022-12-02 22:48:35 -08007786 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007787 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007788 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007789 + " reason=" + reason);
7790 }
7791 Phone phone = PhoneFactory.getPhone(phoneId);
7792 if (phone != null) {
7793 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007794 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007795 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007796 return retVal;
7797 } else {
7798 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007799 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007800 + subId + " retVal=false");
7801 }
7802 return false;
7803 }
7804 } finally {
7805 Binder.restoreCallingIdentity(identity);
7806 }
7807 }
7808
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007809 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007810 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007811 // No permission needed; this only lets the caller inspect their own status.
7812 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007813 }
Junda Liu29340342014-07-10 15:23:27 -07007814
7815 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007816 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007817 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007818 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7819 }
7820
7821 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7822 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007823 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007824 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007825 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7826 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007827 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7828 if (cpt == null) {
7829 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007830 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7831 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007832 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007833 }
7834
7835 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007836 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007837 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07007838 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007839 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007840 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007841 Phone phone = getPhone(subId);
7842 if (phone == null) {
7843 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7844 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7845 }
7846 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7847 if (cpt == null) {
7848 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007849 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7850 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007851 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007852 }
7853
7854 @Override
7855 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007856 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08007857 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7858 }
7859
7860 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007861 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007862 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007863 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007864 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007865 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7866 Phone phone = PhoneFactory.getPhone(phoneId);
7867 if (phone == null) {
7868 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007869 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007870 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7871 if (cpt == null) {
7872 continue;
7873 }
7874 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007875 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7876 break;
7877 }
7878 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007879 return result;
Junda Liu29340342014-07-10 15:23:27 -07007880 }
Derek Tan89e89d42014-07-08 17:00:10 -07007881
7882 @Override
Junda Liue64de782015-04-16 17:19:16 -07007883 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007884 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00007885 Phone phone = PhoneFactory.getPhone(phoneId);
7886 if (phone == null) {
7887 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007888 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007889 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7890 if (cpt == null) {
7891 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007892 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007893 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007894 }
7895
Amith Yamasani6e118872016-02-19 12:53:51 -08007896 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007897 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007898 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007899 Phone phone = PhoneFactory.getPhone(phoneId);
7900 if (phone == null) {
7901 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007902 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007903 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7904 if (cpt == null) {
7905 return Collections.emptyList();
7906 }
7907 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007908 }
7909
chen xuf7e9fe82019-05-09 19:31:02 -07007910 @Override
7911 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007912 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007913 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007914 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007915 try {
7916 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7917 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7918 }
7919 } finally {
7920 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007921 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007922 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007923 }
7924
Rambo Wang6812ffb2022-03-15 16:54:17 -07007925 @Override
7926 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7927 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7928
7929 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7930 if (phone == null) {
7931 return null;
7932 }
7933 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7934 if (cpt == null) {
7935 return null;
7936 }
7937 return cpt.getCarrierServicePackageName();
7938 }
7939
Wink Savilleb564aae2014-10-23 10:18:09 -07007940 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007941 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007942 UiccPort port = phone == null ? null : phone.getUiccPort();
7943 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007944 return null;
7945 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007946 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007947 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007948 return null;
7949 }
7950 return iccId;
7951 }
7952
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007953 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007954 public void setCallComposerStatus(int subId, int status) {
7955 enforceModifyPermission();
7956
7957 final long identity = Binder.clearCallingIdentity();
7958 try {
7959 Phone phone = getPhone(subId);
7960 if (phone != null) {
7961 Phone defaultPhone = phone.getImsPhone();
7962 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7963 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7964 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007965 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7966 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007967 }
7968 }
Shuo Qian284ae752020-12-22 19:10:14 -08007969 } catch (ImsException e) {
7970 throw new ServiceSpecificException(e.getCode());
7971 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007972 Binder.restoreCallingIdentity(identity);
7973 }
7974 }
7975
7976 @Override
7977 public int getCallComposerStatus(int subId) {
7978 enforceReadPrivilegedPermission("getCallComposerStatus");
7979
7980 final long identity = Binder.clearCallingIdentity();
7981 try {
7982 Phone phone = getPhone(subId);
7983 if (phone != null) {
7984 Phone defaultPhone = phone.getImsPhone();
7985 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7986 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7987 return imsPhone.getCallComposerStatus();
7988 }
7989 }
7990 } finally {
7991 Binder.restoreCallingIdentity(identity);
7992 }
7993 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7994 }
7995
7996 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007997 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7998 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007999 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008000 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07008001
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008002 final long identity = Binder.clearCallingIdentity();
8003 try {
8004 final String iccId = getIccId(subId);
8005 final Phone phone = getPhone(subId);
8006 if (phone == null) {
8007 return false;
8008 }
8009 final String subscriberId = phone.getSubscriberId();
8010
8011 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08008012 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008013 + subscriberId + " to " + number);
8014 }
8015
8016 if (TextUtils.isEmpty(iccId)) {
8017 return false;
8018 }
8019
8020 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
8021
8022 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
8023 if (alphaTag == null) {
8024 editor.remove(alphaTagPrefKey);
8025 } else {
8026 editor.putString(alphaTagPrefKey, alphaTag);
8027 }
8028
8029 // Record both the line number and IMSI for this ICCID, since we need to
8030 // track all merged IMSIs based on line number
8031 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
8032 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
8033 if (number == null) {
8034 editor.remove(numberPrefKey);
8035 editor.remove(subscriberPrefKey);
8036 } else {
8037 editor.putString(numberPrefKey, number);
8038 editor.putString(subscriberPrefKey, subscriberId);
8039 }
8040
8041 editor.commit();
8042 return true;
8043 } finally {
8044 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07008045 }
Derek Tan7226c842014-07-02 17:42:23 -07008046 }
8047
8048 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008049 public String getLine1NumberForDisplay(int subId, String callingPackage,
8050 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07008051 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08008052 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008053 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08008054 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07008055 return null;
8056 }
Derek Tan97ebb422014-09-05 16:55:38 -07008057
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008058 final long identity = Binder.clearCallingIdentity();
8059 try {
8060 String iccId = getIccId(subId);
8061 if (iccId != null) {
8062 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
8063 if (DBG_MERGE) {
8064 log("getLine1NumberForDisplay returning "
8065 + mTelephonySharedPreferences.getString(numberPrefKey, null));
8066 }
8067 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08008068 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008069 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
8070 return null;
8071 } finally {
8072 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07008073 }
Derek Tan7226c842014-07-02 17:42:23 -07008074 }
8075
8076 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008077 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
8078 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008079 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008080 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07008081 return null;
8082 }
Derek Tan97ebb422014-09-05 16:55:38 -07008083
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008084 final long identity = Binder.clearCallingIdentity();
8085 try {
8086 String iccId = getIccId(subId);
8087 if (iccId != null) {
8088 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
8089 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
8090 }
8091 return null;
8092 } finally {
8093 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07008094 }
Derek Tan7226c842014-07-02 17:42:23 -07008095 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008096
8097 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008098 public String[] getMergedSubscriberIds(int subId, String callingPackage,
8099 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008100 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
8101 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08008102 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08008103 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008104 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008105 return null;
8106 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08008107
Jordan Liub49b04b2019-05-06 14:45:15 -07008108 // Clear calling identity, when calling TelephonyManager, because callerUid must be
8109 // the process, where TelephonyManager was instantiated.
8110 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008111 final long identity = Binder.clearCallingIdentity();
8112 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008113 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008114 final TelephonyManager tele = TelephonyManager.from(context);
8115 final SubscriptionManager sub = SubscriptionManager.from(context);
8116
8117 // Figure out what subscribers are currently active
8118 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008119
Jordan Liub49b04b2019-05-06 14:45:15 -07008120 // Only consider subs which match the current subId
8121 // This logic can be simplified. See b/131189269 for progress.
8122 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008123 activeSubscriberIds.add(tele.getSubscriberId(subId));
8124 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008125
8126 // First pass, find a number override for an active subscriber
8127 String mergeNumber = null;
8128 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
8129 for (String key : prefs.keySet()) {
8130 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
8131 final String subscriberId = (String) prefs.get(key);
8132 if (activeSubscriberIds.contains(subscriberId)) {
8133 final String iccId = key.substring(
8134 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
8135 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
8136 mergeNumber = (String) prefs.get(numberKey);
8137 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08008138 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008139 + " for active subscriber " + subscriberId);
8140 }
8141 if (!TextUtils.isEmpty(mergeNumber)) {
8142 break;
8143 }
8144 }
8145 }
8146 }
8147
8148 // Shortcut when no active merged subscribers
8149 if (TextUtils.isEmpty(mergeNumber)) {
8150 return null;
8151 }
8152
8153 // Second pass, find all subscribers under that line override
8154 final ArraySet<String> result = new ArraySet<>();
8155 for (String key : prefs.keySet()) {
8156 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
8157 final String number = (String) prefs.get(key);
8158 if (mergeNumber.equals(number)) {
8159 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
8160 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
8161 final String subscriberId = (String) prefs.get(subscriberKey);
8162 if (!TextUtils.isEmpty(subscriberId)) {
8163 result.add(subscriberId);
8164 }
8165 }
8166 }
8167 }
8168
8169 final String[] resultArray = result.toArray(new String[result.size()]);
8170 Arrays.sort(resultArray);
8171 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08008172 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008173 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
8174 }
8175 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008176 } finally {
8177 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08008178 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08008179 }
8180
8181 @Override
zoey chen38003472019-12-13 17:16:31 +08008182 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
8183 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07008184
8185 final long identity = Binder.clearCallingIdentity();
8186 try {
8187 final TelephonyManager telephonyManager = mApp.getSystemService(
8188 TelephonyManager.class);
8189 String subscriberId = telephonyManager.getSubscriberId(subId);
8190 if (subscriberId == null) {
8191 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08008192 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07008193 + subId);
8194 }
8195 return null;
8196 }
8197
Jack Yu285100e2022-12-02 22:48:35 -08008198 ParcelUuid groupUuid;
8199 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008200 final SubscriptionInfo info = getSubscriptionManagerService()
Jack Yu285100e2022-12-02 22:48:35 -08008201 .getSubscriptionInfo(subId);
8202 groupUuid = info.getGroupUuid();
8203 } else {
8204 final SubscriptionInfo info = mSubscriptionController
8205 .getSubscriptionInfo(subId);
8206 groupUuid = info.getGroupUuid();
8207 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07008208 // If it doesn't belong to any group, return just subscriberId of itself.
8209 if (groupUuid == null) {
8210 return new String[]{subscriberId};
8211 }
8212
8213 // Get all subscriberIds from the group.
8214 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu285100e2022-12-02 22:48:35 -08008215 List<SubscriptionInfo> groupInfos;
8216 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008217 groupInfos = getSubscriptionManagerService()
Jack Yu285100e2022-12-02 22:48:35 -08008218 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8219 mApp.getAttributionTag());
8220 } else {
8221 groupInfos = mSubscriptionController
8222 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8223 mApp.getAttributionTag());
8224 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07008225 for (SubscriptionInfo subInfo : groupInfos) {
8226 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
8227 if (subscriberId != null) {
8228 mergedSubscriberIds.add(subscriberId);
8229 }
8230 }
8231
8232 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
8233 } finally {
8234 Binder.restoreCallingIdentity(identity);
8235
8236 }
8237 }
8238
8239 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008240 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008241 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008242 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008243
8244 final long identity = Binder.clearCallingIdentity();
8245 try {
8246 final Phone phone = getPhone(subId);
8247 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8248 } finally {
8249 Binder.restoreCallingIdentity(identity);
8250 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008251 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008252
8253 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008254 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008255 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8256 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008257 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8258 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008259
8260 final long identity = Binder.clearCallingIdentity();
8261 try {
8262 final Phone phone = getPhone(subId);
8263 if (phone == null) {
8264 return false;
8265 }
8266 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8267 cdmaNonRoamingList);
8268 } finally {
8269 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008270 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008271 }
8272
8273 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00008274 @Deprecated
8275 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
8276 enforceModifyPermission();
8277
8278 int returnValue = 0;
8279 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07008280 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00008281 if(result.exception == null) {
8282 if (result.result != null) {
8283 byte[] responseData = (byte[])(result.result);
8284 if(responseData.length > oemResp.length) {
8285 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
8286 responseData.length + "bytes. Buffer Size is " +
8287 oemResp.length + "bytes.");
8288 }
8289 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
8290 returnValue = responseData.length;
8291 }
8292 } else {
8293 CommandException ex = (CommandException) result.exception;
8294 returnValue = ex.getCommandError().ordinal();
8295 if(returnValue > 0) returnValue *= -1;
8296 }
8297 } catch (RuntimeException e) {
8298 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
8299 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
8300 if(returnValue > 0) returnValue *= -1;
8301 }
8302
8303 return returnValue;
8304 }
8305
8306 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008307 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008308 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07008309 try {
8310 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008311 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008312 mApp, phone.getSubId(), "getRadioAccessFamily");
8313 } catch (SecurityException e) {
8314 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8315 throw e;
8316 }
chen xub97461a2018-10-26 14:17:57 -07008317 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008318 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07008319 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08008320 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008321 final long identity = Binder.clearCallingIdentity();
8322 try {
chen xub97461a2018-10-26 14:17:57 -07008323 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008324 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07008325 mApp, phone.getSubId(), "getRadioAccessFamily");
8326 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008327 } finally {
8328 Binder.restoreCallingIdentity(identity);
8329 }
chen xub97461a2018-10-26 14:17:57 -07008330 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008331 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008332
8333 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008334 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008335 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08008336 try {
8337 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
8338 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008339 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008340 }
8341 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008342 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008343 }
8344 RoleManager rm = mApp.getSystemService(RoleManager.class);
8345 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
8346 if (!dialerRoleHolders.contains(callingPackage)) {
8347 throw new SecurityException("App must be the dialer role holder to"
8348 + " upload a call composer pic");
8349 }
8350
8351 Executors.newSingleThreadExecutor().execute(() -> {
8352 ByteArrayOutputStream output = new ByteArrayOutputStream(
8353 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8354 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8355 boolean readUntilEnd = false;
8356 int totalBytesRead = 0;
8357 byte[] buffer = new byte[16 * 1024];
8358 while (true) {
8359 int numRead;
8360 try {
8361 numRead = input.read(buffer);
8362 } catch (IOException e) {
8363 try {
8364 fd.checkError();
8365 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8366 null);
8367 } catch (IOException e1) {
8368 // This means that the other side closed explicitly with an error. If this
8369 // happens, log and ignore.
8370 loge("Remote end of call composer picture pipe closed: " + e1);
8371 }
8372 break;
8373 }
8374 if (numRead == -1) {
8375 readUntilEnd = true;
8376 break;
8377 }
8378 totalBytesRead += numRead;
8379 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8380 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8381 try {
8382 input.close();
8383 } catch (IOException e) {
8384 // ignore
8385 }
8386 break;
8387 }
8388 output.write(buffer, 0, numRead);
8389 }
8390 // Generally, the remote end will close the file descriptors. The only case where we
8391 // close is above, where the picture size is too big.
8392
8393 try {
8394 fd.checkError();
8395 } catch (IOException e) {
8396 loge("Remote end for call composer closed with an error: " + e);
8397 return;
8398 }
8399
Hall Liuaa4211e2021-01-20 15:43:39 -08008400 if (!readUntilEnd) {
8401 loge("Did not finish reading entire image; aborting");
8402 return;
8403 }
Hall Liu82694d52020-12-11 18:22:04 -08008404
Hall Liuaa4211e2021-01-20 15:43:39 -08008405 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8406 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8407 new CallComposerPictureTransfer.Factory() {},
8408 imageData,
8409 (result) -> {
8410 if (result.first != null) {
8411 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8412 Bundle outputResult = new Bundle();
8413 outputResult.putParcelable(
8414 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8415 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8416 outputResult);
8417 } else {
8418 callback.send(result.second, null);
8419 }
8420 }
8421 );
Hall Liu82694d52020-12-11 18:22:04 -08008422 });
8423 }
8424
8425 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008426 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008427 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008428 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008429
8430 final long identity = Binder.clearCallingIdentity();
8431 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008432 ImsManager.getInstance(defaultPhone.getContext(),
8433 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008434 } finally {
8435 Binder.restoreCallingIdentity(identity);
8436 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008437 }
8438
8439 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008440 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008441 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008442 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8443 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008444 return false;
8445 }
Svet Ganovb320e182015-04-16 12:30:10 -07008446
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008447 final long identity = Binder.clearCallingIdentity();
8448 try {
8449 // Check the user preference and the system-level IMS setting. Even if the user has
8450 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8451 // In the long run, we may instead need to check if there exists a connection service
8452 // which can support video calling.
8453 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008454 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008455 return imsManager.isVtEnabledByPlatform()
8456 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8457 && imsManager.isVtEnabledByUser();
8458 } finally {
8459 Binder.restoreCallingIdentity(identity);
8460 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008461 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008462
Andrew Leea1239f22015-03-02 17:44:07 -08008463 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008464 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8465 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008466 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008467 mApp, subId, callingPackage, callingFeatureId,
8468 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008469 return false;
8470 }
8471
8472 final long identity = Binder.clearCallingIdentity();
8473 try {
8474 CarrierConfigManager configManager =
8475 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008476 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008477 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8478 } finally {
8479 Binder.restoreCallingIdentity(identity);
8480 }
Andrew Leea1239f22015-03-02 17:44:07 -08008481 }
8482
8483 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008484 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008485 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008486 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008487 return false;
8488 }
8489
8490 final long identity = Binder.clearCallingIdentity();
8491 try {
8492 CarrierConfigManager configManager =
8493 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008494 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008495 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8496 } finally {
8497 Binder.restoreCallingIdentity(identity);
8498 }
Andrew Leea1239f22015-03-02 17:44:07 -08008499 }
8500
Andrew Lee9431b832015-03-09 18:46:45 -07008501 @Override
8502 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008503 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008504 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008505 }
8506
8507 @Override
8508 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008509 final long identity = Binder.clearCallingIdentity();
8510 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008511 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008512 } finally {
8513 Binder.restoreCallingIdentity(identity);
8514 }
Andrew Lee9431b832015-03-09 18:46:45 -07008515 }
8516
Hall Liuf6668912018-10-31 17:05:23 -07008517 /**
8518 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8519 * support for the feature and device firmware support.
8520 *
8521 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8522 */
8523 @Override
8524 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008525 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008526 final Phone phone = getPhone(subscriptionId);
8527 if (phone == null) {
8528 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8529 return false;
8530 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008531 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008532 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008533 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
8534 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008535 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008536 return isCarrierSupported && isDeviceSupported;
8537 } finally {
8538 Binder.restoreCallingIdentity(identity);
8539 }
Hall Liu98187582018-01-22 19:15:32 -08008540 }
8541
Hall Liuf6668912018-10-31 17:05:23 -07008542 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008543 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8544 * RTT setting, will return true if the device and carrier both support RTT.
8545 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008546 */
8547 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008548 final long identity = Binder.clearCallingIdentity();
8549 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00008550 boolean isRttSupported = isRttSupported(subscriptionId);
8551 boolean isUserRttSettingOn = Settings.Secure.getInt(
8552 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8553 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8554 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8555 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008556 } finally {
8557 Binder.restoreCallingIdentity(identity);
8558 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008559 }
8560
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008561 @Deprecated
8562 @Override
8563 public String getDeviceId(String callingPackage) {
8564 return getDeviceIdWithFeature(callingPackage, null);
8565 }
8566
Sanket Padawe7310cc72015-01-14 09:53:20 -08008567 /**
8568 * Returns the unique device ID of phone, for example, the IMEI for
8569 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8570 *
8571 * <p>Requires Permission:
8572 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8573 */
8574 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008575 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008576 try {
8577 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8578 } catch (SecurityException se) {
8579 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8580 throw new SecurityException("Package " + callingPackage + " does not belong to "
8581 + Binder.getCallingUid());
8582 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008583 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008584 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008585 return null;
8586 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008587 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008588 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008589 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008590 return null;
8591 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008592
8593 final long identity = Binder.clearCallingIdentity();
8594 try {
8595 return phone.getDeviceId();
8596 } finally {
8597 Binder.restoreCallingIdentity(identity);
8598 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008599 }
8600
Ping Sunc67b7c22016-03-02 19:16:45 +08008601 /**
8602 * {@hide}
8603 * Returns the IMS Registration Status on a particular subid
8604 *
8605 * @param subId
8606 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008607 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008608 Phone phone = getPhone(subId);
8609 if (phone != null) {
8610 return phone.isImsRegistered();
8611 } else {
8612 return false;
8613 }
8614 }
8615
Santos Cordon7a1885b2015-02-03 11:15:19 -08008616 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008617 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008618 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008619 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008620 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008621 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8622 }
8623 final long identity = Binder.clearCallingIdentity();
8624 try {
8625 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8626 } finally {
8627 Binder.restoreCallingIdentity(identity);
8628 }
8629 }
8630
8631 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008632 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008633 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008634 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008635 mApp,
8636 subscriptionId,
8637 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8638 + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07008639 final long identity = Binder.clearCallingIdentity();
8640 try {
8641 Phone phone = getPhone(subscriptionId);
8642 if (phone == null) {
8643 return null;
8644 }
8645 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8646 } finally {
8647 Binder.restoreCallingIdentity(identity);
8648 }
8649 }
8650
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008651 /**
8652 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008653 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008654 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008655 final long identity = Binder.clearCallingIdentity();
8656 try {
8657 Phone phone = getPhone(subId);
8658 if (phone != null) {
8659 return phone.isWifiCallingEnabled();
8660 } else {
8661 return false;
8662 }
8663 } finally {
8664 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008665 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008666 }
8667
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008668 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008669 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008670 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008671 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008672 final long identity = Binder.clearCallingIdentity();
8673 try {
8674 Phone phone = getPhone(subId);
8675 if (phone != null) {
8676 return phone.isVideoEnabled();
8677 } else {
8678 return false;
8679 }
8680 } finally {
8681 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008682 }
8683 }
8684
8685 /**
8686 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8687 * defined in {@link ImsRegistrationImplBase}.
8688 */
8689 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008690 final long identity = Binder.clearCallingIdentity();
8691 try {
8692 Phone phone = getPhone(subId);
8693 if (phone != null) {
8694 return phone.getImsRegistrationTech();
8695 } else {
8696 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8697 }
8698 } finally {
8699 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008700 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008701 }
8702
Stuart Scott8eef64f2015-04-08 15:13:54 -07008703 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008704 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008705 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07008706 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8707 return;
8708 }
Kai Shif70f46f2021-03-03 13:59:46 -08008709 Phone defaultPhone = getDefaultPhone();
8710 if (defaultPhone != null) {
8711 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8712 mApp, getDefaultPhone().getSubId(), "factoryReset");
8713 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008714 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008715
Svet Ganovcc087f82015-05-12 20:35:54 -07008716 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008717 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8718 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008719 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008720 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008721 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008722 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008723 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008724 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08008725 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008726 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008727 // There has been issues when Sms raw table somehow stores orphan
8728 // fragments. They lead to garbled message when new fragments come
8729 // in and combined with those stale ones. In case this happens again,
8730 // user can reset all network settings which will clean up this table.
8731 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008732 // Clean up IMS settings as well here.
8733 int slotId = getSlotIndex(subId);
8734 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8735 ImsManager.getInstance(mApp, slotId).factoryReset();
8736 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008737
Kai Shif70f46f2021-03-03 13:59:46 -08008738 if (defaultPhone == null) {
8739 return;
8740 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008741 // Erase modem config if erase modem on network setting is enabled.
8742 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8743 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8744 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008745 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008746 }
Kai Shif70f46f2021-03-03 13:59:46 -08008747
8748 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008749 } finally {
8750 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008751 }
8752 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008753
SongFerngWangfd89b102021-05-27 22:44:54 +08008754 @VisibleForTesting
8755 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8756 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8757 return;
8758 }
8759 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8760 RILConstants.PREFERRED_NETWORK_MODE);
8761 SubscriptionManager.setSubscriptionProperty(subId,
8762 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8763 "user=" + defaultNetworkType);
8764 phone.loadAllowedNetworksFromSubscriptionDatabase();
8765 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8766 defaultNetworkType, null);
8767 }
8768
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008769 private void cleanUpSmsRawTable(Context context) {
8770 ContentResolver resolver = context.getContentResolver();
8771 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8772 resolver.delete(uri, null, null);
8773 }
8774
Narayan Kamath1c496c22015-04-16 14:40:19 +01008775 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008776 public String getSimLocaleForSubscriber(int subId) {
8777 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
8778 final Phone phone = getPhone(subId);
8779 if (phone == null) {
8780 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008781 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008782 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008783 final long identity = Binder.clearCallingIdentity();
8784 try {
Jack Yu285100e2022-12-02 22:48:35 -08008785 SubscriptionInfo info;
8786 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008787 info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
Jack Yu285100e2022-12-02 22:48:35 -08008788 phone.getContext().getOpPackageName(),
8789 phone.getContext().getAttributionTag());
8790 if (info == null) {
8791 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8792 return null;
8793 }
8794 } else {
8795 info = mSubscriptionController.getActiveSubscriptionInfo(subId,
8796 phone.getContext().getOpPackageName(),
8797 phone.getContext().getAttributionTag());
8798 if (info == null) {
8799 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8800 return null;
8801 }
chen xu6291c472019-02-04 12:55:53 -08008802 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008803 // Try and fetch the locale from the carrier properties or from the SIM language
8804 // preferences (EF-PL and EF-LI)...
8805 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008806 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008807 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8808 if (localeFromDefaultSim != null) {
8809 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8810 if (DBG) log("Using locale from subId: " + subId + " locale: "
8811 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008812 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008813 } else {
8814 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008815 }
8816 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008817
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008818 // The SIM language preferences only store a language (e.g. fr = French), not an
8819 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8820 // the SIM and carrier preferences does not include a country we add the country
8821 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008822 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008823 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008824 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008825 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008826 }
8827
8828 if (DBG) log("No locale found - returning null");
8829 return null;
8830 } finally {
8831 Binder.restoreCallingIdentity(identity);
8832 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008833 }
8834
tom hsu0b59d292022-09-29 23:49:21 +08008835 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008836 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008837 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008838 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008839 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008840 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8841 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008842 Locale.forLanguageTag(localeTag).getCountry())) {
8843 return localeTag;
8844 }
8845 }
8846 return inputLocale.toLanguageTag();
8847 }
8848
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008849 /**
8850 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8851 */
8852 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu285100e2022-12-02 22:48:35 -08008853 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008854 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Jack Yu285100e2022-12-02 22:48:35 -08008855 mApp.getOpPackageName(), mApp.getAttributionTag());
8856 }
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008857 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08008858 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01008859 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008860
Gary Jian3aa9a762022-01-24 16:41:19 +08008861 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8862 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008863
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008864 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008865 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8866 * representing the state of the modem.
8867 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008868 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8869 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008870 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008871 */
8872 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008873 public void requestModemActivityInfo(ResultReceiver result) {
8874 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008875 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008876
8877 final long identity = Binder.clearCallingIdentity();
8878 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008879 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008880 } finally {
8881 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008882 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008883 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008884
Gary Jian76280a42022-12-07 16:18:33 +08008885 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008886 // less than total activity duration.
8887 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8888 if (info == null) {
8889 return false;
8890 }
8891 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008892 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008893 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8894
Hall Liu49656c02020-10-09 19:00:11 -07008895 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8896
Siddharth Rayb8114062018-06-17 15:02:38 -07008897 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008898 && (info.getSleepTimeMillis() <= activityDurationMs)
8899 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008900 }
8901
Gary Jian3aa9a762022-01-24 16:41:19 +08008902 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8903 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8904 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8905 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8906
8907 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8908 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8909 }
8910
8911 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8912 mLastModemActivityInfo.setReceiveTimeMillis(
8913 rat,
8914 freq,
8915 info.getReceiveTimeMillis(rat, freq)
8916 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8917 }
8918
8919 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8920 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8921 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8922 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8923
8924 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8925 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8926 }
8927 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8928 mLastModemActivityInfo.setReceiveTimeMillis(
8929 rat,
8930 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8931 }
8932
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008933 /**
8934 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8935 * @param info recent ModemActivityInfo
8936 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008937 private void mergeModemActivityInfo(ModemActivityInfo info) {
8938 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008939 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008940 boolean matched;
8941 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8942 matched = false;
8943 int rat = info.getSpecificInfoRat(i);
8944 int freq = info.getSpecificInfoFrequencyRange(i);
8945 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8946 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8947 //if it already exists
8948 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8949 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8950 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8951 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8952 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8953 updateLastModemActivityInfo(info, rat, freq);
8954 matched = true;
8955 }
8956 } else {
8957 updateLastModemActivityInfo(info, rat);
8958 matched = true;
8959 }
8960 }
8961 }
8962
8963 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008964 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008965 new ActivityStatsTechSpecificInfo(
8966 rat,
8967 freq,
8968 info.getTransmitTimeMillis(rat, freq),
8969 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008970 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008971 }
8972 }
8973 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8974 mLastModemActivitySpecificInfo =
8975 new ActivityStatsTechSpecificInfo[merged.size()];
8976 merged.toArray(mLastModemActivitySpecificInfo);
8977
8978 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8979 mLastModemActivityInfo.setSleepTimeMillis(
8980 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008981 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008982 mLastModemActivityInfo.setIdleTimeMillis(
8983 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008984 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008985
8986 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008987 new ModemActivityInfo(
8988 mLastModemActivityInfo.getTimestampMillis(),
8989 mLastModemActivityInfo.getSleepTimeMillis(),
8990 mLastModemActivityInfo.getIdleTimeMillis(),
8991 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008992 }
8993
8994 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8995 ActivityStatsTechSpecificInfo[] info) {
8996 int infoSize = info.length;
8997 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8998 for (int i = 0; i < infoSize; i++) {
8999 ret[i] = new ActivityStatsTechSpecificInfo(
9000 info[i].getRat(), info[i].getFrequencyRange(),
9001 info[i].getTransmitTimeMillis(),
9002 (int) info[i].getReceiveTimeMillis());
9003 }
9004 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08009005 }
9006
Jack Yu85bd38a2015-11-09 11:34:32 -08009007 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08009008 * Returns the service state information on specified subscription.
9009 */
9010 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08009011 public ServiceState getServiceStateForSubscriber(int subId,
9012 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
9013 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009014 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009015 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08009016 return null;
9017 }
9018
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08009019 boolean hasFinePermission = false;
9020 boolean hasCoarsePermission = false;
9021 if (!renounceFineLocationAccess) {
9022 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
9023 LocationAccessPolicy.checkLocationPermission(mApp,
9024 new LocationAccessPolicy.LocationPermissionQuery.Builder()
9025 .setCallingPackage(callingPackage)
9026 .setCallingFeatureId(callingFeatureId)
9027 .setCallingPid(Binder.getCallingPid())
9028 .setCallingUid(Binder.getCallingUid())
9029 .setMethod("getServiceStateForSubscriber")
9030 .setLogAsInfo(true)
9031 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
9032 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
9033 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
9034 .build());
9035 hasFinePermission =
9036 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
9037 }
Hall Liuf19c44f2018-11-27 14:38:17 -08009038
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08009039 if (!renounceCoarseLocationAccess) {
9040 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
9041 LocationAccessPolicy.checkLocationPermission(mApp,
9042 new LocationAccessPolicy.LocationPermissionQuery.Builder()
9043 .setCallingPackage(callingPackage)
9044 .setCallingFeatureId(callingFeatureId)
9045 .setCallingPid(Binder.getCallingPid())
9046 .setCallingUid(Binder.getCallingUid())
9047 .setMethod("getServiceStateForSubscriber")
9048 .setLogAsInfo(true)
9049 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
9050 .setMinSdkVersionForFine(Integer.MAX_VALUE)
9051 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
9052 .build());
9053 hasCoarsePermission =
9054 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
9055 }
Hall Liuf19c44f2018-11-27 14:38:17 -08009056
Jack Yu479f40e2020-10-27 21:29:25 -07009057 final Phone phone = getPhone(subId);
9058 if (phone == null) {
9059 return null;
9060 }
9061
Jordan Liu0f2bc442020-11-18 16:47:37 -08009062 final long identity = Binder.clearCallingIdentity();
9063
Jack Yu479f40e2020-10-27 21:29:25 -07009064 boolean isCallingPackageDataService = phone.getDataServicePackages()
9065 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009066 try {
Jordan Liuc437b192020-08-17 10:59:12 -07009067 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu285100e2022-12-02 22:48:35 -08009068 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08009069 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
Jack Yu285100e2022-12-02 22:48:35 -08009070 .getSubscriptionInfoInternal(subId);
9071 if (subInfo == null || !subInfo.isActive()) {
9072 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
9073 + "subId=" + subId);
9074 return null;
9075 }
9076 } else {
9077 if (!mSubscriptionController.isActiveSubId(subId, callingPackage,
9078 callingFeatureId)) {
9079 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
9080 + "subId=" + subId);
9081 return null;
9082 }
Jordan Liuc437b192020-08-17 10:59:12 -07009083 }
9084
Hall Liuf19c44f2018-11-27 14:38:17 -08009085 ServiceState ss = phone.getServiceState();
9086
9087 // Scrub out the location info in ServiceState depending on what level of access
9088 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07009089 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08009090 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
9091 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009092 } finally {
9093 Binder.restoreCallingIdentity(identity);
9094 }
Jack Yu85bd38a2015-11-09 11:34:32 -08009095 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009096
9097 /**
9098 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
9099 *
9100 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
9101 * voicemail ringtone.
9102 * @return The URI for the ringtone to play when receiving a voicemail from a specific
9103 * PhoneAccount.
9104 */
9105 @Override
9106 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009107 final long identity = Binder.clearCallingIdentity();
9108 try {
9109 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
9110 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009111 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009112 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009113
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009114 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
9115 } finally {
9116 Binder.restoreCallingIdentity(identity);
9117 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009118 }
9119
9120 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009121 * Sets the per-account voicemail ringtone.
9122 *
9123 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
9124 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9125 *
9126 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
9127 * voicemail ringtone.
9128 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
9129 * PhoneAccount.
9130 */
9131 @Override
9132 public void setVoicemailRingtoneUri(String callingPackage,
9133 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009134 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009135 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07009136 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
9137 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009138 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9139 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9140 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009141 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009142
9143 final long identity = Binder.clearCallingIdentity();
9144 try {
9145 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9146 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009147 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009148 }
9149 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
9150 } finally {
9151 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009152 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009153 }
9154
9155 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08009156 * Returns whether vibration is set for voicemail notification in Phone settings.
9157 *
9158 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
9159 * voicemail vibration setting.
9160 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
9161 */
9162 @Override
9163 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009164 final long identity = Binder.clearCallingIdentity();
9165 try {
9166 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
9167 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009168 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009169 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009170
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009171 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
9172 } finally {
9173 Binder.restoreCallingIdentity(identity);
9174 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009175 }
9176
Youhan Wange64578a2016-05-02 15:32:42 -07009177 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009178 * Sets the per-account voicemail vibration.
9179 *
9180 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
9181 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9182 *
9183 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
9184 * voicemail vibration setting.
9185 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
9186 * specific PhoneAccount.
9187 */
9188 @Override
9189 public void setVoicemailVibrationEnabled(String callingPackage,
9190 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009191 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009192 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07009193 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
9194 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009195 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9196 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9197 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009198 }
9199
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009200 final long identity = Binder.clearCallingIdentity();
9201 try {
9202 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9203 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009204 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009205 }
9206 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
9207 } finally {
9208 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009209 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009210 }
9211
9212 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009213 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
9214 *
9215 * @throws SecurityException if the caller does not have the required permission
9216 */
arunvoddud7401012022-12-15 16:08:12 +00009217 @VisibleForTesting
9218 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009219 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009220 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009221 }
9222
9223 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009224 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9225 * permission.
9226 *
9227 * @throws SecurityException if the caller does not have the required permission
9228 */
9229 private void enforceSendSmsPermission() {
9230 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9231 }
9232
9233 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009234 * Make sure either called from same process as self (phone) or IPC caller has interact across
9235 * users permission.
9236 *
9237 * @throws SecurityException if the caller does not have the required permission
9238 */
9239 private void enforceInteractAcrossUsersPermission(String message) {
9240 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9241 }
9242
9243 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009244 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009245 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009246 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009247 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009248 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009249 final long identity = Binder.clearCallingIdentity();
9250 try {
9251 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009252 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009253 if (componentName == null) {
9254 throw new SecurityException(
9255 "Caller not current active visual voicemail package[null]");
9256 }
9257 String vvmPackage = componentName.getPackageName();
9258 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009259 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009260 }
9261 } finally {
9262 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009263 }
9264 }
9265
9266 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009267 * Return the application ID for the app type.
9268 *
9269 * @param subId the subscription ID that this request applies to.
9270 * @param appType the uicc app type.
9271 * @return Application ID for specificied app type, or null if no uicc.
9272 */
9273 @Override
9274 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009275 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07009276 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009277
9278 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009279 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009280 if (phone == null) {
9281 return null;
9282 }
9283 String aid = null;
9284 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009285 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009286 .getApplicationByType(appType).getAid();
9287 } catch (Exception e) {
9288 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9289 }
9290 return aid;
9291 } finally {
9292 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009293 }
Youhan Wange64578a2016-05-02 15:32:42 -07009294 }
9295
Youhan Wang4001d252016-05-11 10:29:41 -07009296 /**
9297 * Return the Electronic Serial Number.
9298 *
9299 * @param subId the subscription ID that this request applies to.
9300 * @return ESN or null if error.
9301 */
9302 @Override
9303 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009304 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009305 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009306
9307 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009308 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009309 if (phone == null) {
9310 return null;
9311 }
9312 String esn = null;
9313 try {
9314 esn = phone.getEsn();
9315 } catch (Exception e) {
9316 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9317 }
9318 return esn;
9319 } finally {
9320 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009321 }
Youhan Wang4001d252016-05-11 10:29:41 -07009322 }
9323
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009324 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009325 * Return the Preferred Roaming List Version.
9326 *
9327 * @param subId the subscription ID that this request applies to.
9328 * @return PRLVersion or null if error.
9329 */
9330 @Override
9331 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009332 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07009333 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009334
9335 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009336 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009337 if (phone == null) {
9338 return null;
9339 }
9340 String cdmaPrlVersion = null;
9341 try {
9342 cdmaPrlVersion = phone.getCdmaPrlVersion();
9343 } catch (Exception e) {
9344 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9345 }
9346 return cdmaPrlVersion;
9347 } finally {
9348 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009349 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009350 }
9351
9352 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009353 * Get snapshot of Telephony histograms
9354 * @return List of Telephony histograms
9355 * @hide
9356 */
9357 @Override
9358 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009359 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9360 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009361
9362 final long identity = Binder.clearCallingIdentity();
9363 try {
9364 return RIL.getTelephonyRILTimingHistograms();
9365 } finally {
9366 Binder.restoreCallingIdentity(identity);
9367 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009368 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009369
9370 /**
9371 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009372 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9373 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009374 * Require system privileges. In the future we may add this to carrier APIs.
9375 *
Michele Berionne482f8202018-11-27 18:57:59 -08009376 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009377 */
9378 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009379 @TelephonyManager.SetCarrierRestrictionResult
9380 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009381 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07009382 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009383
Michele Berionne482f8202018-11-27 18:57:59 -08009384 if (carrierRestrictionRules == null) {
9385 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009386 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009387
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009388 final long identity = Binder.clearCallingIdentity();
9389 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009390 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009391 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009392 } finally {
9393 Binder.restoreCallingIdentity(identity);
9394 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009395 }
9396
9397 /**
9398 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009399 * Get the allowed carrier list and the excluded carrier list, including the priority between
9400 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009401 * Require system privileges. In the future we may add this to carrier APIs.
9402 *
Michele Berionne482f8202018-11-27 18:57:59 -08009403 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009404 */
9405 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009406 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009407 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07009408 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009409
9410 final long identity = Binder.clearCallingIdentity();
9411 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009412 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9413 if (response instanceof CarrierRestrictionRules) {
9414 return (CarrierRestrictionRules) response;
9415 }
9416 // Response is an Exception of some kind,
9417 // which is signalled to the user as a NULL retval
9418 return null;
9419 } catch (Exception e) {
9420 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9421 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009422 } finally {
9423 Binder.restoreCallingIdentity(identity);
9424 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009425 }
9426
fionaxu59545b42016-05-25 15:53:37 -07009427 /**
arunvoddud7401012022-12-15 16:08:12 +00009428 * Fetches the carrier restriction status of the device and sends the status to the caller
9429 * through the callback.
9430 *
9431 * @param callback The callback that will be used to send the result.
9432 * @throws SecurityException if the caller does not have the required permission/privileges or
9433 * the caller is not allowlisted.
9434 */
9435 @Override
9436 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
9437 enforceReadPermission("getCarrierRestrictionStatus");
9438 int carrierId = validateCallerAndGetCarrierId(packageName);
9439 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
9440 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9441 throw new SecurityException("Not an authorized caller");
9442 }
9443 final long identity = Binder.clearCallingIdentity();
9444 try {
9445 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
9446 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
9447 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9448 } finally {
9449 Binder.restoreCallingIdentity(identity);
9450 }
9451 }
9452
9453 @VisibleForTesting
9454 public int validateCallerAndGetCarrierId(String packageName) {
9455 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9456 return allowListInfo.validateCallerAndGetCarrierId(packageName);
9457 }
9458
9459 /**
fionaxu59545b42016-05-25 15:53:37 -07009460 * Action set from carrier signalling broadcast receivers to enable/disable radio
9461 * @param subId the subscription ID that this action applies to.
9462 * @param enabled control enable or disable radio.
9463 * {@hide}
9464 */
9465 @Override
9466 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9467 enforceModifyPermission();
9468 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009469
9470 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009471 if (phone == null) {
9472 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9473 return;
9474 }
9475 try {
9476 phone.carrierActionSetRadioEnabled(enabled);
9477 } catch (Exception e) {
9478 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009479 } finally {
9480 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009481 }
9482 }
9483
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009484 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009485 * Enable or disable Voice over NR (VoNR)
9486 * @param subId the subscription ID that this action applies to.
9487 * @param enabled enable or disable VoNR.
9488 * @return operation result.
9489 */
9490 @Override
9491 public int setVoNrEnabled(int subId, boolean enabled) {
9492 enforceModifyPermission();
9493 final Phone phone = getPhone(subId);
9494
9495 final long identity = Binder.clearCallingIdentity();
9496 if (phone == null) {
9497 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9498 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9499 }
9500
9501 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9502 try {
9503 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9504 workSource);
9505 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009506
9507 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9508 if (DBG) {
9509 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9510 }
9511 SubscriptionManager.setSubscriptionProperty(
9512 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9513 (enabled ? "1" : "0"));
9514 }
9515
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009516 return result;
9517 } finally {
9518 Binder.restoreCallingIdentity(identity);
9519 }
9520 }
9521
9522 /**
9523 * Is voice over NR enabled
9524 * @return true if VoNR is enabled else false
9525 */
9526 @Override
9527 public boolean isVoNrEnabled(int subId) {
9528 enforceReadPrivilegedPermission("isVoNrEnabled");
9529 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9530 final long identity = Binder.clearCallingIdentity();
9531 try {
9532 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9533 null, subId, workSource);
9534 if (DBG) log("isVoNrEnabled: " + isEnabled);
9535 return isEnabled;
9536 } finally {
9537 Binder.restoreCallingIdentity(identity);
9538 }
9539 }
9540
9541 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009542 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9543 * network status based on which carrier apps could apply actions accordingly,
9544 * enable/disable default url handler for example.
9545 *
9546 * @param subId the subscription ID that this action applies to.
9547 * @param report control start/stop reporting the default network status.
9548 * {@hide}
9549 */
9550 @Override
9551 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9552 enforceModifyPermission();
9553 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009554
9555 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009556 if (phone == null) {
9557 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9558 return;
9559 }
9560 try {
9561 phone.carrierActionReportDefaultNetworkStatus(report);
9562 } catch (Exception e) {
9563 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009564 } finally {
9565 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009566 }
9567 }
9568
9569 /**
fionaxud9622282017-07-17 17:51:30 -07009570 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9571 * @param subId the subscription ID that this action applies to.
9572 * {@hide}
9573 */
9574 @Override
9575 public void carrierActionResetAll(int subId) {
9576 enforceModifyPermission();
9577 final Phone phone = getPhone(subId);
9578 if (phone == null) {
9579 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9580 return;
9581 }
9582 try {
9583 phone.carrierActionResetAll();
9584 } catch (Exception e) {
9585 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9586 }
9587 }
9588
9589 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009590 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9591 * bug report is being generated.
9592 */
9593 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009594 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009595 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9596 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009597 writer.println("Permission Denial: can't dump Phone from pid="
9598 + Binder.getCallingPid()
9599 + ", uid=" + Binder.getCallingUid()
9600 + "without permission "
9601 + android.Manifest.permission.DUMP);
9602 return;
9603 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009604 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009605 }
Jack Yueb89b242016-06-22 13:27:47 -07009606
Brad Ebingerdac2f002018-04-03 15:17:52 -07009607 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009608 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9609 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9610 @NonNull String[] args) {
9611 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9612 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009613 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009614 }
9615
Jack Yueb89b242016-06-22 13:27:47 -07009616 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009617 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009618 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009619 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009620 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009621 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009622 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009623 */
9624 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009625 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009626 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009627 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9628 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9629 try {
9630 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009631 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009632 } catch (SecurityException se) {
9633 enforceModifyPermission();
9634 }
9635 } else {
9636 enforceModifyPermission();
9637 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009638
9639 final long identity = Binder.clearCallingIdentity();
9640 try {
9641 Phone phone = getPhone(subId);
9642 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009643 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9644 phone.carrierActionSetMeteredApnsEnabled(enabled);
9645 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07009646 phone.getDataSettingsManager().setDataEnabled(
9647 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009648 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009649 }
9650 } finally {
9651 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009652 }
9653 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009654
9655 /**
9656 * Get Client request stats
9657 * @return List of Client Request Stats
9658 * @hide
9659 */
9660 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009661 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9662 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009663 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009664 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009665 return null;
9666 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009667 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009668
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009669 final long identity = Binder.clearCallingIdentity();
9670 try {
9671 if (phone != null) {
9672 return phone.getClientRequestStats();
9673 }
9674
9675 return null;
9676 } finally {
9677 Binder.restoreCallingIdentity(identity);
9678 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009679 }
9680
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009681 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009682 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009683 if (uid == Process.ROOT_UID && packageName == null) {
9684 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9685 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9686 // exception. ROOT_UID seems not to have a valid package name returned by
9687 // PackageManager, so just fake it here to avoid issues when running telephony shell
9688 // commands that plumb through the RIL as root, like so:
9689 // $ adb root
9690 // $ adb shell cmd phone ...
9691 packageName = "root";
9692 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009693 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009694 }
Jack Yueb4124c2017-02-16 15:32:43 -08009695
9696 /**
Grace Chen70990072017-03-24 17:21:30 -07009697 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009698 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009699 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009700 * @param state State of SIM (power down, power up, pass through)
9701 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9702 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9703 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009704 *
9705 **/
9706 @Override
Grace Chen70990072017-03-24 17:21:30 -07009707 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009708 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009709 Phone phone = PhoneFactory.getPhone(slotIndex);
9710
vagdeviaf9a5b92018-08-15 16:01:53 -07009711 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9712
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009713 final long identity = Binder.clearCallingIdentity();
9714 try {
9715 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009716 phone.setSimPowerState(state, null, workSource);
9717 }
9718 } finally {
9719 Binder.restoreCallingIdentity(identity);
9720 }
9721 }
9722
9723 /**
9724 * Set SIM card power state.
9725 *
9726 * @param slotIndex SIM slot id.
9727 * @param state State of SIM (power down, power up, pass through)
9728 * @param callback callback to trigger after success or failure
9729 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9730 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9731 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9732 *
9733 **/
9734 @Override
9735 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9736 IIntegerConsumer callback) {
9737 enforceModifyPermission();
9738 Phone phone = PhoneFactory.getPhone(slotIndex);
9739
9740 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9741
9742 final long identity = Binder.clearCallingIdentity();
9743 try {
9744 if (phone != null) {
9745 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9746 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009747 }
9748 } finally {
9749 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009750 }
9751 }
Shuo Qiandd210312017-04-12 22:11:33 +00009752
Tyler Gunn65d45c22017-06-05 11:22:26 -07009753 private boolean isUssdApiAllowed(int subId) {
9754 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009755 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009756 if (configManager == null) {
9757 return false;
9758 }
9759 PersistableBundle pb = configManager.getConfigForSubId(subId);
9760 if (pb == null) {
9761 return false;
9762 }
9763 return pb.getBoolean(
9764 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9765 }
9766
Shuo Qiandd210312017-04-12 22:11:33 +00009767 /**
9768 * Check if phone is in emergency callback mode
9769 * @return true if phone is in emergency callback mode
9770 * @param subId sub id
9771 */
goneil9c5f4872017-12-05 14:07:56 -08009772 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009773 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009774 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00009775 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009776
9777 final long identity = Binder.clearCallingIdentity();
9778 try {
9779 if (phone != null) {
9780 return phone.isInEcm();
9781 } else {
9782 return false;
9783 }
9784 } finally {
9785 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009786 }
9787 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009788
9789 /**
9790 * Get the current signal strength information for the given subscription.
9791 * Because this information is not updated when the device is in a low power state
9792 * it should not be relied-upon to be current.
9793 * @param subId Subscription index
9794 * @return the most recent cached signal strength info from the modem
9795 */
9796 @Override
9797 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009798 final long identity = Binder.clearCallingIdentity();
9799 try {
9800 Phone p = getPhone(subId);
9801 if (p == null) {
9802 return null;
9803 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009804
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009805 return p.getSignalStrength();
9806 } finally {
9807 Binder.restoreCallingIdentity(identity);
9808 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009809 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009810
Pengquan Meng77b7f132018-08-22 14:49:57 -07009811 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009812 * Get the current modem radio state for the given slot.
9813 * @param slotIndex slot index.
9814 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009815 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009816 * @return the current radio power state from the modem
9817 */
9818 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009819 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009820 Phone phone = PhoneFactory.getPhone(slotIndex);
9821 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009822 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9823 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009824 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9825 }
9826
9827 final long identity = Binder.clearCallingIdentity();
9828 try {
9829 return phone.getRadioPowerState();
9830 } finally {
9831 Binder.restoreCallingIdentity(identity);
9832 }
9833 }
9834 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9835 }
9836
9837 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009838 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9839 *
9840 * <p>Requires one of the following permissions:
9841 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009842 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009843 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9844 * privileges.
9845 *
9846 * @param subId subscription id
9847 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9848 * {@code false}.
9849 */
9850 @Override
9851 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009852 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009853 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009854 try {
9855 mApp.enforceCallingOrSelfPermission(
9856 android.Manifest.permission.ACCESS_NETWORK_STATE,
9857 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009858 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009859 mApp.enforceCallingOrSelfPermission(
9860 permission.READ_BASIC_PHONE_STATE, functionName);
9861 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009862 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009863 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009864 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009865 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009866
Pengquan Menga1bb6272018-09-06 09:59:22 -07009867 boolean isEnabled = false;
9868 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009869 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009870 Phone phone = getPhone(subId);
9871 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009872 } finally {
9873 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009874 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009875 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009876 }
9877
9878
9879 /**
9880 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9881 *
9882 * <p> Requires permission:
9883 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9884 * privileges.
9885 *
9886 * @param subId subscription id
9887 * @param isEnabled {@code true} means enable, {@code false} means disable.
9888 */
9889 @Override
9890 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009891 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9892 mApp, subId, "setDataRoamingEnabled");
9893
Pengquan Menga1bb6272018-09-06 09:59:22 -07009894 final long identity = Binder.clearCallingIdentity();
9895 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009896 Phone phone = getPhone(subId);
9897 if (phone != null) {
9898 phone.setDataRoamingEnabled(isEnabled);
9899 }
9900 } finally {
9901 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009902 }
9903 }
9904
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009905 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009906 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009907 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009908 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009909 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009910
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009911 boolean isAllowed = true;
9912 final long identity = Binder.clearCallingIdentity();
9913 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009914 Phone phone = getPhone(subId);
9915 if (phone != null) {
9916 isAllowed = phone.isCspPlmnEnabled();
9917 }
9918 } finally {
9919 Binder.restoreCallingIdentity(identity);
9920 }
9921 return isAllowed;
9922 }
9923
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009924 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9925 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009926 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009927 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009928 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009929 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9930 if (phone == null) {
9931 return false;
9932 }
9933 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9934 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9935 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009936 }
9937
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009938 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009939 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009940 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009941 mApp.getSystemService(AppOpsManager.class)
9942 .checkPackage(Binder.getCallingUid(), callingPackage);
9943
Jordan Liu1e142fc2019-04-22 15:10:43 -07009944 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009945 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009946 try {
9947 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009948 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009949 } catch (SecurityException e) {
9950 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9951 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009952 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009953 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009954 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009955 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009956 }
sandeepjsb6c87872021-09-27 15:34:44 +00009957 // checking compatibility, if calling app's target SDK is T and beyond.
9958 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9959 Binder.getCallingUid())) {
9960 isIccIdAccessRestricted = true;
9961 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009962 final long identity = Binder.clearCallingIdentity();
9963 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009964 UiccController uiccController = UiccController.getInstance();
9965 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009966 if (hasReadPermission) {
9967 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009968 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009969
9970 // Remove private info if the caller doesn't have access
9971 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9972 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009973 //setting the value after compatibility check
9974 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009975 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9976 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009977 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009978 if (card == null) {
9979 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009980 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009981 continue;
9982 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009983 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9984 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009985 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009986 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009987 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009988 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9989 for (UiccPortInfo portInfo : portInfos) {
9990 UiccPort port = uiccController.getUiccPortForSlot(
9991 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9992 if (port == null) {
9993 // assume no access if port is null
9994 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9995 continue;
9996 }
9997 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9998 uiccPortInfos.add(portInfo);
9999 } else {
10000 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
10001 }
10002 }
10003 filteredInfos.add(new UiccCardInfo(
10004 cardInfo.isEuicc(),
10005 cardInfo.getCardId(),
10006 null,
10007 cardInfo.getPhysicalSlotIndex(),
10008 cardInfo.isRemovable(),
10009 cardInfo.isMultipleEnabledProfilesSupported(),
10010 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -070010011 }
10012 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -080010013 } finally {
10014 Binder.restoreCallingIdentity(identity);
10015 }
10016 }
10017
sandeepjsb6c87872021-09-27 15:34:44 +000010018 /**
10019 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
10020 * generally private and require carrier privileges to view.
10021 *
10022 * @hide
10023 */
10024 @NonNull
10025 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
10026 List<UiccPortInfo> portinfo = new ArrayList<>();
10027 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
10028 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
10029 }
10030 return new UiccCardInfo(
10031 cardInfo.isEuicc(),
10032 cardInfo.getCardId(),
10033 null,
10034 cardInfo.getPhysicalSlotIndex(),
10035 cardInfo.isRemovable(),
10036 cardInfo.isMultipleEnabledProfilesSupported(),
10037 portinfo
10038 );
10039 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010040
sandeepjsb6c87872021-09-27 15:34:44 +000010041 /**
10042 * @hide
10043 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
10044 * These values are generally private and require carrier privileges to view.
10045 */
10046 @NonNull
10047 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
10048 return new UiccPortInfo(
10049 UiccPortInfo.ICCID_REDACTED,
10050 portInfo.getPortIndex(),
10051 portInfo.getLogicalSlotIndex(),
10052 portInfo.isActive()
10053 );
10054 }
10055 @Override
10056 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +000010057 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +000010058 mApp.getSystemService(AppOpsManager.class)
10059 .checkPackage(Binder.getCallingUid(), callingPackage);
10060
sandeepjsb6c87872021-09-27 15:34:44 +000010061 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +000010062
Aman Guptaf3c90b32022-03-17 04:54:16 +000010063 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
10064 // we are reading iccId which is PII data.
10065 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +000010066
10067 // checking compatibility, if calling app's target SDK is T and beyond.
10068 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
10069 Binder.getCallingUid())) {
10070 isLogicalSlotAccessRestricted = true;
10071 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010072 final long identity = Binder.clearCallingIdentity();
10073 try {
10074 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +000010075 if (slots == null || slots.length == 0) {
10076 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010077 return null;
10078 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010079 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
10080 for (int i = 0; i < slots.length; i++) {
10081 UiccSlot slot = slots[i];
10082 if (slot == null) {
10083 continue;
10084 }
10085
Jordan Liu7be7e652019-05-06 18:55:02 +000010086 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010087 UiccCard card = slot.getUiccCard();
10088 if (card != null) {
10089 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +000010090 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -070010091 cardId = slot.getEid();
10092 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +000010093 // If cardId is null, use iccId of default port as cardId.
10094 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -070010095 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010096 }
10097
Jordan Liu857451f2019-05-09 16:35:35 -070010098 if (cardId != null) {
10099 // if cardId is an ICCID, strip off trailing Fs before exposing to user
10100 // if cardId is an EID, it's all digits so this is fine
10101 cardId = IccUtils.stripTrailingFs(cardId);
10102 }
10103
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010104 int cardState = 0;
10105 switch (slot.getCardState()) {
10106 case CARDSTATE_ABSENT:
10107 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
10108 break;
10109 case CARDSTATE_PRESENT:
10110 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
10111 break;
10112 case CARDSTATE_ERROR:
10113 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
10114 break;
10115 case CARDSTATE_RESTRICTED:
10116 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
10117 break;
10118 default:
10119 break;
10120
10121 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010122 List<UiccPortInfo> portInfos = new ArrayList<>();
10123 int[] portIndexes = slot.getPortList();
10124 for (int portIdx : portIndexes) {
10125 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +000010126 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +000010127 portInfos.add(new UiccPortInfo(iccId, portIdx,
10128 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010129 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010130 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010131 slot.isEuicc(),
10132 cardId,
10133 cardState,
Jordan Liua2619582019-02-14 12:56:40 -080010134 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010135 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +000010136 //setting the value after compatibility check
10137 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010138 }
10139 return infos;
10140 } finally {
10141 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -070010142 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010143 }
10144
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010145 /* Returns null if doesn't have read permission or carrier privilege access. */
10146 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
10147 boolean hasReadPermission) {
10148 String iccId = slot.getIccId(portIndex);
10149 if (hasReadPermission) { // if has read permission
10150 return iccId;
10151 } else {
10152 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10153 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10154 // if no read permission, checking carrier privilege access
10155 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10156 return iccId;
10157 }
10158 }
10159 }
10160 // No read permission or carrier privilege access.
10161 return UiccPortInfo.ICCID_REDACTED;
10162 }
10163
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010164 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010165 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010166 public boolean switchSlots(int[] physicalSlots) {
10167 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010168
10169 final long identity = Binder.clearCallingIdentity();
10170 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010171 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10172 for (int i = 0; i < physicalSlots.length; i++) {
10173 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10174 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10175 physicalSlots[i], i));
10176 }
10177 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010178 } finally {
10179 Binder.restoreCallingIdentity(identity);
10180 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010181 }
Jack Yu4c988042018-02-27 15:30:01 -080010182
10183 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010184 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10185 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10186 enforceModifyPermission();
10187
10188 final long identity = Binder.clearCallingIdentity();
10189 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010190 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010191 } finally {
10192 Binder.restoreCallingIdentity(identity);
10193 }
10194 }
10195
10196 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010197 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -080010198 final long identity = Binder.clearCallingIdentity();
10199 try {
10200 return UiccController.getInstance().getCardIdForDefaultEuicc();
10201 } finally {
10202 Binder.restoreCallingIdentity(identity);
10203 }
10204 }
10205
Pengquan Meng85728fb2018-03-12 16:31:21 -070010206 /**
goneil47ffb6e2018-04-06 15:40:58 -070010207 * A test API to reload the UICC profile.
10208 *
10209 * <p>Requires that the calling app has permission
10210 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10211 * @hide
10212 */
10213 @Override
10214 public void refreshUiccProfile(int subId) {
10215 enforceModifyPermission();
10216
10217 final long identity = Binder.clearCallingIdentity();
10218 try {
10219 Phone phone = getPhone(subId);
10220 if (phone == null) {
10221 return;
10222 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010223 UiccPort uiccPort = phone.getUiccPort();
10224 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010225 return;
10226 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010227 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010228 if (uiccProfile == null) {
10229 return;
10230 }
10231 uiccProfile.refresh();
10232 } finally {
10233 Binder.restoreCallingIdentity(identity);
10234 }
10235 }
10236
10237 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010238 * Returns false if the mobile data is disabled by default, otherwise return true.
10239 */
10240 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010241 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010242 }
10243
10244 /**
10245 * Returns true if the data roaming is enabled by default, i.e the system property
10246 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
10247 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
10248 */
10249 private boolean getDefaultDataRoamingEnabled(int subId) {
10250 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010251 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -070010252 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010253 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
10254 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
10255 return isDataRoamingEnabled;
10256 }
10257
10258 /**
10259 * Returns the default network type for the given {@code subId}, if the default network type is
10260 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10261 */
10262 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010263 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010264 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010265 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10266 return list.get(phoneId);
10267 }
10268 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010269 }
fionaxua13278b2018-03-21 00:08:13 -070010270
10271 @Override
10272 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010273 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010274 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010275
10276 final long identity = Binder.clearCallingIdentity();
10277 try {
10278 final Phone phone = getPhone(subId);
10279 if (phone == null) {
10280 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10281 return;
10282 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010283 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10284 if (cpt != null) {
10285 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10286 }
10287 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010288 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10289 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010290 if (carrierPrivilegeRules == null) {
10291 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10292 } else {
10293 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10294 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010295 } finally {
10296 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010297 }
fionaxua13278b2018-03-21 00:08:13 -070010298 }
10299
10300 @Override
10301 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010302 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010303
10304 final long identity = Binder.clearCallingIdentity();
10305 try {
10306 final Phone phone = getPhone(subId);
10307 if (phone == null) {
10308 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10309 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10310 }
10311 return phone.getCarrierIdListVersion();
10312 } finally {
10313 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010314 }
fionaxua13278b2018-03-21 00:08:13 -070010315 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010316
10317 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010318 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10319 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010320 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010321 mApp, subId, callingPackage, callingFeatureId,
10322 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010323 return -1;
10324 }
10325
10326 final long identity = Binder.clearCallingIdentity();
10327 try {
10328 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10329 } finally {
10330 Binder.restoreCallingIdentity(identity);
10331 }
10332 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010333
10334 @Override
10335 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010336 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010337 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010338 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010339
10340 final long identity = Binder.clearCallingIdentity();
10341 try {
10342 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10343 } finally {
10344 Binder.restoreCallingIdentity(identity);
10345 }
10346 }
10347
10348 @Override
10349 public boolean setCdmaRoamingMode(int subId, int mode) {
10350 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10351 mApp, subId, "setCdmaRoamingMode");
10352
10353 final long identity = Binder.clearCallingIdentity();
10354 try {
10355 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10356 } finally {
10357 Binder.restoreCallingIdentity(identity);
10358 }
10359 }
10360
10361 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010362 public int getCdmaSubscriptionMode(int subId) {
10363 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010364 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010365 mApp, subId, "getCdmaSubscriptionMode");
10366
10367 final long identity = Binder.clearCallingIdentity();
10368 try {
10369 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10370 } finally {
10371 Binder.restoreCallingIdentity(identity);
10372 }
10373 }
10374
10375 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010376 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10377 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10378 mApp, subId, "setCdmaSubscriptionMode");
10379
10380 final long identity = Binder.clearCallingIdentity();
10381 try {
10382 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10383 } finally {
10384 Binder.restoreCallingIdentity(identity);
10385 }
10386 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010387
sqianc5eccab2018-10-19 18:46:41 -070010388 @Override
sqian8c685422019-02-22 15:55:18 -080010389 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010390 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010391 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010392 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10393 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010394 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10395 }
10396 final long identity = Binder.clearCallingIdentity();
10397 try {
sqian854d44b2018-12-12 16:48:18 -080010398 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10399 for (Phone phone: PhoneFactory.getPhones()) {
10400 if (phone.getEmergencyNumberTracker() != null
10401 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10402 emergencyNumberListInternal.put(
10403 phone.getSubId(),
10404 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10405 }
sqian11b7a0e2018-12-05 18:48:28 -080010406 }
sqian854d44b2018-12-12 16:48:18 -080010407 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010408 } finally {
10409 Binder.restoreCallingIdentity(identity);
10410 }
sqianc5eccab2018-10-19 18:46:41 -070010411 }
10412
10413 @Override
sqian8c685422019-02-22 15:55:18 -080010414 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010415 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010416 if (!exactMatch) {
10417 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010418 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010419 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010420 }
10421 final long identity = Binder.clearCallingIdentity();
10422 try {
sqian854d44b2018-12-12 16:48:18 -080010423 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010424 //Note: we ignore passed in param exactMatch. We can remove it once
10425 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010426 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010427 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010428 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010429 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010430 }
sqian11b7a0e2018-12-05 18:48:28 -080010431 }
10432 return false;
10433 } finally {
10434 Binder.restoreCallingIdentity(identity);
10435 }
10436 }
10437
sqianf4ca7ed2019-01-15 18:32:07 -080010438 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010439 * Start emergency callback mode for GsmCdmaPhone for testing.
10440 */
10441 @Override
10442 public void startEmergencyCallbackMode() {
10443 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10444 "startEmergencyCallbackMode");
10445 enforceModifyPermission();
10446 final long identity = Binder.clearCallingIdentity();
10447 try {
10448 for (Phone phone : PhoneFactory.getPhones()) {
10449 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10450 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10451 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10452 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10453 gsmCdmaPhone.obtainMessage(
10454 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10455 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10456 }
10457 }
10458 } finally {
10459 Binder.restoreCallingIdentity(identity);
10460 }
10461 }
10462
10463 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010464 * Update emergency number list for test mode.
10465 */
10466 @Override
10467 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10468 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10469 "updateEmergencyNumberListTestMode");
10470
10471 final long identity = Binder.clearCallingIdentity();
10472 try {
10473 for (Phone phone: PhoneFactory.getPhones()) {
10474 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10475 if (tracker != null) {
10476 tracker.executeEmergencyNumberTestModeCommand(action, num);
10477 }
10478 }
10479 } finally {
10480 Binder.restoreCallingIdentity(identity);
10481 }
10482 }
10483
10484 /**
10485 * Get the full emergency number list for test mode.
10486 */
10487 @Override
10488 public List<String> getEmergencyNumberListTestMode() {
10489 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10490 "getEmergencyNumberListTestMode");
10491
10492 final long identity = Binder.clearCallingIdentity();
10493 try {
10494 Set<String> emergencyNumbers = new HashSet<>();
10495 for (Phone phone: PhoneFactory.getPhones()) {
10496 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10497 if (tracker != null) {
10498 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10499 emergencyNumbers.add(num.getNumber());
10500 }
10501 }
10502 }
10503 return new ArrayList<>(emergencyNumbers);
10504 } finally {
10505 Binder.restoreCallingIdentity(identity);
10506 }
10507 }
10508
chen xud6b45bd2018-10-30 22:27:10 -070010509 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010510 public int getEmergencyNumberDbVersion(int subId) {
10511 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10512
10513 final long identity = Binder.clearCallingIdentity();
10514 try {
10515 final Phone phone = getPhone(subId);
10516 if (phone == null) {
10517 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10518 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10519 }
10520 return phone.getEmergencyNumberDbVersion();
10521 } finally {
10522 Binder.restoreCallingIdentity(identity);
10523 }
10524 }
10525
10526 @Override
10527 public void notifyOtaEmergencyNumberDbInstalled() {
10528 enforceModifyPermission();
10529
10530 final long identity = Binder.clearCallingIdentity();
10531 try {
10532 for (Phone phone: PhoneFactory.getPhones()) {
10533 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10534 if (tracker != null) {
10535 tracker.updateOtaEmergencyNumberDatabase();
10536 }
10537 }
10538 } finally {
10539 Binder.restoreCallingIdentity(identity);
10540 }
10541 }
10542
10543 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010544 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010545 enforceActiveEmergencySessionPermission();
10546
10547 final long identity = Binder.clearCallingIdentity();
10548 try {
10549 for (Phone phone: PhoneFactory.getPhones()) {
10550 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10551 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010552 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10553 }
10554 }
10555 } finally {
10556 Binder.restoreCallingIdentity(identity);
10557 }
10558 }
10559
10560 @Override
10561 public void resetOtaEmergencyNumberDbFilePath() {
10562 enforceActiveEmergencySessionPermission();
10563
10564 final long identity = Binder.clearCallingIdentity();
10565 try {
10566 for (Phone phone: PhoneFactory.getPhones()) {
10567 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10568 if (tracker != null) {
10569 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010570 }
10571 }
10572 } finally {
10573 Binder.restoreCallingIdentity(identity);
10574 }
10575 }
10576
10577 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010578 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10579 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10580 Phone phone = getPhone(subId);
10581 if (phone == null) {
10582 return null;
10583 }
10584 final long identity = Binder.clearCallingIdentity();
10585 try {
10586 UiccProfile profile = UiccController.getInstance()
10587 .getUiccProfileForPhone(phone.getPhoneId());
10588 if (profile != null) {
10589 return profile.getCertsFromCarrierPrivilegeAccessRules();
10590 }
10591 } finally {
10592 Binder.restoreCallingIdentity(identity);
10593 }
10594 return null;
10595 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010596
10597 /**
10598 * Enable or disable a modem stack.
10599 */
10600 @Override
10601 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10602 enforceModifyPermission();
10603
10604 final long identity = Binder.clearCallingIdentity();
10605 try {
10606 Phone phone = PhoneFactory.getPhone(slotIndex);
10607 if (phone == null) {
10608 return false;
10609 } else {
10610 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10611 }
10612 } finally {
10613 Binder.restoreCallingIdentity(identity);
10614 }
10615 }
Michelecea4cf22018-12-21 15:00:11 -080010616
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010617 /**
10618 * Whether a modem stack is enabled or not.
10619 */
10620 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010621 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10622 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010623 Phone phone = PhoneFactory.getPhone(slotIndex);
10624 if (phone == null) return false;
10625
10626 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010627 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10628 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010629 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10630 }
10631
10632 final long identity = Binder.clearCallingIdentity();
10633 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010634 try {
10635 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10636 } catch (NoSuchElementException ex) {
10637 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10638 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010639 } finally {
10640 Binder.restoreCallingIdentity(identity);
10641 }
10642 }
10643
Michelecea4cf22018-12-21 15:00:11 -080010644 @Override
Michele0ea7d782019-03-19 14:58:42 -070010645 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010646 enforceModifyPermission();
10647
10648 final long identity = Binder.clearCallingIdentity();
10649 try {
10650 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010651 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010652 .commit();
10653 } finally {
10654 Binder.restoreCallingIdentity(identity);
10655 }
10656 }
10657
10658 @Override
Michele0ea7d782019-03-19 14:58:42 -070010659 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010660 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010661 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010662 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10663 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010664 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010665 }
Michelecea4cf22018-12-21 15:00:11 -080010666
10667 final long identity = Binder.clearCallingIdentity();
10668 try {
Michele0ea7d782019-03-19 14:58:42 -070010669 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010670 } finally {
10671 Binder.restoreCallingIdentity(identity);
10672 }
10673 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010674
Michele0ea7d782019-03-19 14:58:42 -070010675 @TelephonyManager.IsMultiSimSupportedResult
10676 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010677 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10678 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10679 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010680 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10681 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010682 }
10683 // Check if the hardware supports multisim functionality. If usage of multisim is not
10684 // supported by the modem, indicate that it is restricted.
10685 PhoneCapability staticCapability =
10686 mPhoneConfigurationManager.getStaticPhoneCapability();
10687 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010688 loge("isMultiSimSupportedInternal: no static configuration available");
10689 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010690 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010691 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010692 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10693 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010694 }
10695 // Check if support of multiple SIMs is restricted by carrier
10696 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010697 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010698 }
10699
Michele0ea7d782019-03-19 14:58:42 -070010700 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010701 }
10702
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010703 /**
10704 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010705 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10706 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10707 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010708 * @param numOfSims number of active sims we want to switch to
10709 */
10710 @Override
10711 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010712 if (numOfSims == 1) {
10713 enforceModifyPermission();
10714 } else {
10715 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10716 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10717 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010718 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010719
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010720 try {
Michele30b57b22019-03-01 12:01:14 -080010721 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010722 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010723 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10724 return;
10725 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010726 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10727 } finally {
10728 Binder.restoreCallingIdentity(identity);
10729 }
10730 }
10731
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010732 @Override
10733 public boolean isApplicationOnUicc(int subId, int appType) {
10734 enforceReadPrivilegedPermission("isApplicationOnUicc");
10735 Phone phone = getPhone(subId);
10736 if (phone == null) {
10737 return false;
10738 }
10739 final long identity = Binder.clearCallingIdentity();
10740 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010741 UiccPort uiccPort = phone.getUiccPort();
10742 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010743 return false;
10744 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010745 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010746 if (uiccProfile == null) {
10747 return false;
10748 }
10749 if (TelephonyManager.APPTYPE_SIM <= appType
10750 && appType <= TelephonyManager.APPTYPE_ISIM) {
10751 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10752 }
10753 return false;
10754 } finally {
10755 Binder.restoreCallingIdentity(identity);
10756 }
10757 }
10758
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010759 /**
chen xub4baa772019-04-03 10:23:41 -070010760 * Get whether making changes to modem configurations will trigger reboot.
10761 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010762 */
10763 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010764 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10765 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010766 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010767 mApp, subId, callingPackage, callingFeatureId,
10768 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010769 return false;
10770 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010771 final long identity = Binder.clearCallingIdentity();
10772 try {
10773 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10774 } finally {
10775 Binder.restoreCallingIdentity(identity);
10776 }
10777 }
10778
Nathan Harold29f5f052019-02-15 13:41:57 -080010779 private void updateModemStateMetrics() {
10780 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10781 // TODO: check the state for each modem if the api is ready.
10782 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10783 }
10784
Pengquan Meng3889a572019-01-23 11:16:29 -080010785 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010786 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010787 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010788 // Verify that the callingPackage belongs to the calling UID
10789 mApp.getSystemService(AppOpsManager.class)
10790 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -080010791 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010792 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010793 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010794 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10795 if (slotInfos != null) {
10796 for (int i = 0; i < slotInfos.length; i++) {
10797 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10798 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10799 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10800 portInfo.getLogicalSlotIndex()));
10801 }
10802 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010803 }
10804 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010805 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010806 } finally {
10807 Binder.restoreCallingIdentity(identity);
10808 }
10809 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010810
10811 /**
10812 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010813 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010814 */
jimsunf9ec1622022-09-13 21:18:43 +080010815 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010816 @Override
10817 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010818 return getHalVersion(HAL_SERVICE_RADIO);
10819 }
10820
10821 /**
10822 * Get the HAL Version of a specific service
10823 */
10824 @Override
10825 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010826 Phone phone = getDefaultPhone();
10827 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010828 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010829 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10830 return hv.major * 100 + hv.minor;
10831 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010832
10833 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010834 * Get the current calling package name.
10835 * @return the current calling package name
10836 */
10837 @Override
10838 public String getCurrentPackageName() {
10839 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
10840 }
10841
10842 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010843 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10844 * corresponding network requests on a subId.
10845 *
10846 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010847 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010848 * 2) APN is un-metered for this subscription, or
10849 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010850 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010851 *
10852 * @return whether data is allowed for a apn type.
10853 *
10854 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010855 */
10856 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010857 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010858 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10859 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010860
10861 // Now that all security checks passes, perform the operation as ourselves.
10862 final long identity = Binder.clearCallingIdentity();
10863 try {
10864 Phone phone = getPhone(subId);
10865 if (phone == null) return false;
10866
Jack Yu27422a52022-03-21 10:38:05 -070010867 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010868 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010869 isMetered = phone.getDataNetworkController().getDataConfigManager()
10870 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10871 phone.getServiceState().getDataRoaming());
10872 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010873 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010874 } finally {
10875 Binder.restoreCallingIdentity(identity);
10876 }
10877 }
10878
10879 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010880 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010881 enforceReadPrivilegedPermission("isApnMetered");
10882
10883 // Now that all security checks passes, perform the operation as ourselves.
10884 final long identity = Binder.clearCallingIdentity();
10885 try {
10886 Phone phone = getPhone(subId);
10887 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010888 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10889 DataUtils.apnTypeToNetworkCapability(apnType),
10890 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010891 } finally {
10892 Binder.restoreCallingIdentity(identity);
10893 }
10894 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010895
10896 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010897 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10898 int subscriptionId, IBooleanConsumer resultCallback) {
10899 enforceModifyPermission();
10900 long token = Binder.clearCallingIdentity();
10901 try {
10902 Phone phone = getPhone(subscriptionId);
10903 if (phone == null) {
10904 try {
10905 if (resultCallback != null) {
10906 resultCallback.accept(false);
10907 }
10908 } catch (RemoteException e) {
10909 // ignore
10910 }
10911 return;
10912 }
10913 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10914 Pair.create(specifiers, (x) -> {
10915 try {
10916 if (resultCallback != null) {
10917 resultCallback.accept(x);
10918 }
10919 } catch (RemoteException e) {
10920 // ignore
10921 }
10922 });
10923 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10924 } finally {
10925 Binder.restoreCallingIdentity(token);
10926 }
10927 }
10928
10929 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010930 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10931 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010932 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010933 mApp, subId, "getSystemSelectionChannels");
10934 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10935 final long identity = Binder.clearCallingIdentity();
10936 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010937 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10938 if (result instanceof IllegalStateException) {
10939 throw (IllegalStateException) result;
10940 }
10941 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010942 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10943 return specifiers;
10944 } finally {
10945 Binder.restoreCallingIdentity(identity);
10946 }
10947 }
10948
10949 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010950 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010951 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010952 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010953 }
10954
10955 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010956 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10957 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010958 if (callingPackage == null) {
10959 callingPackage = getCurrentPackageName();
10960 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010961 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10962 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010963 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10964 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010965 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10966 }
10967 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10968 Intent intent = new Intent();
10969 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10970 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10971 // Bring up choose default SMS subscription dialog right now
10972 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10973 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10974 mApp.startActivity(intent);
10975 }
chen xud5ca2d52019-05-28 15:20:57 -070010976
10977 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010978 public void showSwitchToManagedProfileDialog() {
10979 enforceModifyPermission();
10980
10981 Intent intent = new Intent();
10982 intent.setClass(mApp, ErrorDialogActivity.class);
10983 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10984 mApp.startActivity(intent);
10985 }
10986
10987 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010988 public String getMmsUAProfUrl(int subId) {
10989 //TODO investigate if this API should require proper permission check in R b/133791609
10990 final long identity = Binder.clearCallingIdentity();
10991 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010992 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10993 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10994 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10995 return carrierUAProfUrl;
10996 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010997 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10998 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010999 } finally {
11000 Binder.restoreCallingIdentity(identity);
11001 }
11002 }
11003
11004 @Override
11005 public String getMmsUserAgent(int subId) {
11006 //TODO investigate if this API should require proper permission check in R b/133791609
11007 final long identity = Binder.clearCallingIdentity();
11008 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080011009 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
11010 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
11011 if (!TextUtils.isEmpty(carrierUserAgent)) {
11012 return carrierUserAgent;
11013 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080011014 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
11015 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070011016 } finally {
11017 Binder.restoreCallingIdentity(identity);
11018 }
11019 }
Jack Yub07d4972019-05-28 16:12:25 -070011020
11021 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070011022 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
11023 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070011024
Jack Yub07d4972019-05-28 16:12:25 -070011025 final long identity = Binder.clearCallingIdentity();
11026 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011027 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070011028 if (phone == null) return false;
11029
Ling Maf188d502022-09-16 15:22:36 -070011030 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070011031 } finally {
11032 Binder.restoreCallingIdentity(identity);
11033 }
11034 }
11035
11036 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080011037 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070011038 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080011039 enforceModifyPermission();
11040
changbettyd5c246e2019-12-24 15:40:37 +080011041 final long identity = Binder.clearCallingIdentity();
11042 try {
Hall Liua62f5da2020-09-25 10:42:19 -070011043 Phone phone = getPhone(subscriptionId);
11044 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080011045
Ling Maf188d502022-09-16 15:22:36 -070011046 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080011047 } finally {
11048 Binder.restoreCallingIdentity(identity);
11049 }
11050 }
11051
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011052 /**
Hall Liu746e03c2020-09-25 11:13:49 -070011053 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070011054 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
11055 * otherwise.
11056 */
11057 @Override
11058 public void setCepEnabled(boolean isCepEnabled) {
11059 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
11060
11061 final long identity = Binder.clearCallingIdentity();
11062 try {
11063 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
11064 for (Phone phone : PhoneFactory.getPhones()) {
11065 Phone defaultPhone = phone.getImsPhone();
11066 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
11067 ImsPhone imsPhone = (ImsPhone) defaultPhone;
11068 ImsPhoneCallTracker imsPhoneCallTracker =
11069 (ImsPhoneCallTracker) imsPhone.getCallTracker();
11070 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
11071 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
11072 + imsPhone.getMsisdn());
11073 }
11074 }
11075 } finally {
11076 Binder.restoreCallingIdentity(identity);
11077 }
11078 }
allenwtsu46dcc572020-01-08 18:24:03 +080011079
11080 /**
11081 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
11082 *
11083 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
11084 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
11085 * before being read.
11086 */
11087 @Override
11088 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
11089 isCompressed) {
11090 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11091 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000011092 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11093 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11094 }
11095 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000011096 // ProvisioningManager can not handle ServiceSpecificException.
11097 // Throw the IllegalStateException and annotate ProvisioningManager.
11098 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000011099 }
11100
11101 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080011102 try {
Hui Wang761a6682020-10-31 05:12:53 +000011103 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
11104 } finally {
11105 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080011106 }
11107 }
zoey chene02881a2019-12-30 16:11:23 +080011108
11109 @Override
11110 public boolean isIccLockEnabled(int subId) {
11111 enforceReadPrivilegedPermission("isIccLockEnabled");
11112
11113 // Now that all security checks passes, perform the operation as ourselves.
11114 final long identity = Binder.clearCallingIdentity();
11115 try {
11116 Phone phone = getPhone(subId);
11117 if (phone != null && phone.getIccCard() != null) {
11118 return phone.getIccCard().getIccLockEnabled();
11119 } else {
11120 return false;
11121 }
11122 } finally {
11123 Binder.restoreCallingIdentity(identity);
11124 }
11125 }
11126
11127 /**
11128 * Set the ICC pin lock enabled or disabled.
11129 *
11130 * @return an integer representing the status of IccLock enabled or disabled in the following
11131 * three cases:
11132 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11133 * successfully.
11134 * - Positive number and zero for remaining password attempts.
11135 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11136 *
11137 */
11138 @Override
11139 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11140 enforceModifyPermission();
11141
11142 Phone phone = getPhone(subId);
11143 if (phone == null) {
11144 return 0;
11145 }
11146 // Now that all security checks passes, perform the operation as ourselves.
11147 final long identity = Binder.clearCallingIdentity();
11148 try {
11149 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11150 new Pair<Boolean, String>(enabled, password), phone, null);
11151 return attemptsRemaining;
11152
11153 } catch (Exception e) {
11154 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11155 } finally {
11156 Binder.restoreCallingIdentity(identity);
11157 }
11158 return 0;
11159 }
11160
11161 /**
11162 * Change the ICC password used in ICC pin lock.
11163 *
11164 * @return an integer representing the status of IccLock changed in the following three cases:
11165 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11166 * - Positive number and zero for remaining password attempts.
11167 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11168 *
11169 */
11170 @Override
11171 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11172 enforceModifyPermission();
11173
11174 Phone phone = getPhone(subId);
11175 if (phone == null) {
11176 return 0;
11177 }
11178 // Now that all security checks passes, perform the operation as ourselves.
11179 final long identity = Binder.clearCallingIdentity();
11180 try {
11181 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11182 new Pair<String, String>(oldPassword, newPassword), phone, null);
11183 return attemptsRemaining;
11184
11185 } catch (Exception e) {
11186 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11187 } finally {
11188 Binder.restoreCallingIdentity(identity);
11189 }
11190 return 0;
11191 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011192
11193 /**
11194 * Request for receiving user activity notification
11195 */
11196 @Override
11197 public void requestUserActivityNotification() {
11198 if (!mNotifyUserActivity.get()
11199 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11200 mNotifyUserActivity.set(true);
11201 }
11202 }
11203
11204 /**
11205 * Called when userActivity is signalled in the power manager.
11206 * This is safe to call from any thread, with any window manager locks held or not.
11207 */
11208 @Override
11209 public void userActivity() {
11210 // ***************************************
11211 // * Inherited from PhoneWindowManager *
11212 // ***************************************
11213 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11214 // WITH ITS LOCKS HELD.
11215 //
11216 // This code must be VERY careful about the locks
11217 // it acquires.
11218 // In fact, the current code acquires way too many,
11219 // and probably has lurking deadlocks.
11220
11221 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
11222 throw new SecurityException("Only the OS may call notifyUserActivity()");
11223 }
11224
11225 if (mNotifyUserActivity.getAndSet(false)) {
11226 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11227 USER_ACTIVITY_NOTIFICATION_DELAY);
11228 }
11229 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011230
11231 @Override
11232 public boolean canConnectTo5GInDsdsMode() {
11233 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11234 }
Jack Yud10cdd42020-09-28 20:28:01 -070011235
11236 @Override
11237 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11238 String callingFeatureId) {
11239 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11240 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11241 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11242 }
11243
11244 Phone phone = getPhone(subId);
11245 if (phone == null) {
11246 throw new RuntimeException("phone is not available");
11247 }
11248 // Now that all security checks passes, perform the operation as ourselves.
11249 final long identity = Binder.clearCallingIdentity();
11250 try {
11251 return phone.getEquivalentHomePlmns();
11252 } finally {
11253 Binder.restoreCallingIdentity(identity);
11254 }
11255 }
Daniel Bright59e67312020-11-13 11:49:37 -080011256
11257 @Override
11258 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011259 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
11260 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011261 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011262 if (radioInterfaceCapabilities == null) {
11263 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011264 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011265 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011266 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011267
Hui Wang641e81c2020-10-12 12:14:23 -070011268 @Override
11269 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11270 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011271 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11272 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11273 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11274 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11275 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070011276 if (DBG) {
11277 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11278 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11279 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11280 }
11281
11282 if (!SubscriptionManager.isValidSubscriptionId(subId)
11283 || appType < TelephonyManager.APPTYPE_UNKNOWN
11284 || appType > TelephonyManager.APPTYPE_ISIM
11285 || nafUrl == null || securityProtocol == null || callback == null) {
11286 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11287 if (callback != null) {
11288 try {
11289 callback.onAuthenticationFailure(
11290 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11291 } catch (RemoteException exception) {
11292 log("Fail to notify onAuthenticationFailure due to " + exception);
11293 }
11294 return;
11295 }
11296 }
11297
11298 final long token = Binder.clearCallingIdentity();
11299 try {
11300 getGbaManager(subId).bootstrapAuthenticationRequest(
11301 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011302 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011303 } finally {
11304 Binder.restoreCallingIdentity(token);
11305 }
11306 }
11307
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011308 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011309 * Attempts to set the radio power state for all phones for thermal reason.
11310 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011311 * requested radio power state will actually be set. See {@link
11312 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11313 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011314 * @param enable {@code true} if trying to turn radio on.
11315 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11316 * false}.
11317 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011318 private boolean setRadioPowerForThermal(boolean enable) {
11319 boolean isPhoneAvailable = false;
11320 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11321 Phone phone = PhoneFactory.getPhone(i);
11322 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011323 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011324 isPhoneAvailable = true;
11325 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011326 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011327
11328 // return true if successfully informed the phone object about the thermal radio power
11329 // request.
11330 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011331 }
11332
11333 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011334 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011335 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11336 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11337 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11338 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11339 throw new IllegalArgumentException("modem does not support data throttling");
11340 }
11341
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011342 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11343 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011344 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011345 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11346 }
11347
Sarah Chinecc78c42022-03-31 21:16:48 -070011348 setDataEnabledForReason(
11349 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011350
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011351 if (isDataThrottlingSupported) {
11352 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011353 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011354 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11355 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11356 } else if (thermalMitigationResult
11357 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011358 log("Modem likely does not support data throttling on secondary carrier. Data " +
11359 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11360 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011361 }
11362 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011363 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011364
11365 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011366 }
11367
Jack Nudelman644b91a2021-03-12 14:09:48 -080011368 private static List<String> getThermalMitigationAllowlist(Context context) {
11369 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11370 for (String pckg : context.getResources()
11371 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11372 sThermalMitigationAllowlistedPackages.add(pckg);
11373 }
11374 }
11375
11376 return sThermalMitigationAllowlistedPackages;
11377 }
11378
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011379 private boolean isAnyPhoneInEmergencyState() {
11380 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11381 if (tm.isInEmergencyCall()) {
11382 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11383 return true;
11384 }
11385 for (Phone phone : PhoneFactory.getPhones()) {
11386 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11387 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011388 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11389 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011390 return true;
11391 }
11392 }
11393
11394 return false;
11395 }
11396
Jack Nudelman644b91a2021-03-12 14:09:48 -080011397 /**
11398 * Used by shell commands to add an authorized package name for thermal mitigation.
11399 * @param packageName name of package to be allowlisted
11400 * @param context
11401 */
11402 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11403 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11404 sThermalMitigationAllowlistedPackages.add(packageName);
11405 }
11406
11407 /**
11408 * Used by shell commands to remove an authorized package name for thermal mitigation.
11409 * @param packageName name of package to remove from allowlist
11410 * @param context
11411 */
11412 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11413 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11414 sThermalMitigationAllowlistedPackages.remove(packageName);
11415 }
11416
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011417 /**
11418 * Thermal mitigation request to control functionalities at modem.
11419 *
11420 * @param subId the id of the subscription.
11421 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011422 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011423 *
11424 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11425 */
11426 @Override
11427 @ThermalMitigationResult
11428 public int sendThermalMitigationRequest(
11429 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011430 ThermalMitigationRequest thermalMitigationRequest,
11431 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011432 enforceModifyPermission();
11433
Jack Nudelman644b91a2021-03-12 14:09:48 -080011434 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11435 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11436 .contains(callingPackage)) {
11437 throw new SecurityException("Calling package must be configured in the device config. "
11438 + "calling package: " + callingPackage);
11439 }
11440
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011441 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11442 final long identity = Binder.clearCallingIdentity();
11443
11444 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11445 try {
11446 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11447 switch (thermalMitigationAction) {
11448 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11449 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011450 handleDataThrottlingRequest(subId,
11451 thermalMitigationRequest.getDataThrottlingRequest(),
11452 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011453 break;
11454 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11455 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11456 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11457 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11458 }
11459
11460 // Ensure that radio is on. If not able to power on due to phone being
11461 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011462 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011463 thermalMitigationResult =
11464 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11465 break;
11466 }
11467
11468 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011469 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011470 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11471 break;
11472 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11473 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11474 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11475 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11476 }
11477
11478 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11479 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011480 Phone phone = getPhone(subId);
11481 if (phone == null) {
11482 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011483 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011484 break;
11485 }
11486
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011487 TelephonyConnectionService service =
11488 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011489 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011490 Log.e(LOG_TAG, "An emergency call is pending");
11491 thermalMitigationResult =
11492 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11493 break;
11494 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011495 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011496 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011497 break;
11498 }
11499 } else {
11500 thermalMitigationResult =
11501 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11502 break;
11503 }
11504
11505 // Turn radio off. If not able to power off due to phone being unavailable,
11506 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011507 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011508 thermalMitigationResult =
11509 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11510 break;
11511 }
11512 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011513 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011514 break;
11515 default:
11516 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11517 + "not exist. Requested action: " + thermalMitigationAction);
11518 }
11519 } catch (IllegalArgumentException e) {
11520 throw e;
11521 } catch (Exception e) {
11522 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11523 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11524 } finally {
11525 Binder.restoreCallingIdentity(identity);
11526 }
11527
11528 if (DBG) {
11529 log("thermalMitigationRequest returning with thermalMitigationResult: "
11530 + thermalMitigationResult);
11531 }
11532
11533 return thermalMitigationResult;
11534 }
Hui Wang641e81c2020-10-12 12:14:23 -070011535
11536 /**
11537 * Set the GbaService Package Name that Telephony will bind to.
11538 *
11539 * @param subId The sim that the GbaService is associated with.
11540 * @param packageName The name of the package to be replaced with.
11541 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11542 */
11543 @Override
11544 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11545 enforceModifyPermission();
11546
11547 final long identity = Binder.clearCallingIdentity();
11548 try {
11549 return getGbaManager(subId).overrideServicePackage(packageName);
11550 } finally {
11551 Binder.restoreCallingIdentity(identity);
11552 }
11553 }
11554
11555 /**
11556 * Return the package name of the currently bound GbaService.
11557 *
11558 * @param subId The sim that the GbaService is associated with.
11559 * @return the package name of the GbaService configuration, null if GBA is not supported.
11560 */
11561 @Override
11562 public String getBoundGbaService(int subId) {
11563 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11564
11565 final long identity = Binder.clearCallingIdentity();
11566 try {
11567 return getGbaManager(subId).getServicePackage();
11568 } finally {
11569 Binder.restoreCallingIdentity(identity);
11570 }
11571 }
11572
11573 /**
11574 * Set the release time for telephony to unbind GbaService.
11575 *
11576 * @param subId The sim that the GbaService is associated with.
11577 * @param interval The release time to unbind GbaService by millisecond.
11578 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11579 */
11580 @Override
11581 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11582 enforceModifyPermission();
11583
11584 final long identity = Binder.clearCallingIdentity();
11585 try {
11586 return getGbaManager(subId).overrideReleaseTime(interval);
11587 } finally {
11588 Binder.restoreCallingIdentity(identity);
11589 }
11590 }
11591
11592 /**
11593 * Return the release time for telephony to unbind GbaService.
11594 *
11595 * @param subId The sim that the GbaService is associated with.
11596 * @return The release time to unbind GbaService by millisecond.
11597 */
11598 @Override
11599 public int getGbaReleaseTime(int subId) {
11600 enforceReadPrivilegedPermission("getGbaReleaseTime");
11601
11602 final long identity = Binder.clearCallingIdentity();
11603 try {
11604 return getGbaManager(subId).getReleaseTime();
11605 } finally {
11606 Binder.restoreCallingIdentity(identity);
11607 }
11608 }
11609
11610 private GbaManager getGbaManager(int subId) {
11611 GbaManager instance = GbaManager.getInstance(subId);
11612 if (instance == null) {
11613 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11614 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11615 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11616 }
11617 return instance;
11618 }
Hui Wang761a6682020-10-31 05:12:53 +000011619
11620 /**
11621 * indicate whether the device and the carrier can support
11622 * RCS VoLTE single registration.
11623 */
11624 @Override
11625 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011626 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11627 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11628 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11629 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011630
11631 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11632 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11633 }
11634
11635 final long identity = Binder.clearCallingIdentity();
11636 try {
11637 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11638 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011639 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11640 if (isCapable != null) {
11641 return isCapable;
11642 }
Hui Wang761a6682020-10-31 05:12:53 +000011643 }
Hui Wang67af90e2021-06-04 16:57:15 -070011644 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11645 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011646 } finally {
11647 Binder.restoreCallingIdentity(identity);
11648 }
11649 }
11650
11651 /**
11652 * Register RCS provisioning callback.
11653 */
11654 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011655 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011656 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011657 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011658 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011659 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11660 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011661
11662 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11663 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11664 }
11665 if (!isImsAvailableOnDevice()) {
11666 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11667 "IMS not available on device.");
11668 }
11669
11670 final long identity = Binder.clearCallingIdentity();
11671 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011672 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011673 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011674 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11675 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011676 }
Hui Wang761a6682020-10-31 05:12:53 +000011677 } finally {
11678 Binder.restoreCallingIdentity(identity);
11679 }
11680 }
11681
11682 /**
11683 * Unregister RCS provisioning callback.
11684 */
11685 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011686 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011687 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011688 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011689 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011690 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11691 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011692
11693 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11694 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11695 }
11696 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000011697 // operation failed silently
11698 Rlog.w(LOG_TAG, "IMS not available on device.");
11699 return;
Hui Wang761a6682020-10-31 05:12:53 +000011700 }
11701
11702 final long identity = Binder.clearCallingIdentity();
11703 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011704 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011705 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011706 } finally {
11707 Binder.restoreCallingIdentity(identity);
11708 }
11709 }
11710
11711 /**
11712 * trigger RCS reconfiguration.
11713 */
11714 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011715 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11716 "triggerRcsReconfiguration",
11717 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011718
11719 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11720 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11721 }
11722 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000011723 // ProvisioningManager can not handle ServiceSpecificException.
11724 // Throw the IllegalStateException and annotate ProvisioningManager.
11725 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000011726 }
11727
11728 final long identity = Binder.clearCallingIdentity();
11729 try {
11730 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11731 } finally {
11732 Binder.restoreCallingIdentity(identity);
11733 }
11734 }
11735
11736 /**
11737 * Provide the client configuration parameters of the RCS application.
11738 */
11739 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011740 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11741 "setRcsClientConfiguration",
11742 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011743
11744 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11745 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11746 }
11747 if (!isImsAvailableOnDevice()) {
11748 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11749 "IMS not available on device.");
11750 }
11751
11752 final long identity = Binder.clearCallingIdentity();
11753
11754 try {
11755 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11756 if (configBinder == null) {
11757 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011758 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11759 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011760 } else {
11761 configBinder.setRcsClientConfiguration(rcc);
11762 }
joonhunshin3e154242021-09-17 06:33:39 +000011763
11764 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11765 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011766 } catch (RemoteException e) {
11767 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011768 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11769 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011770 } finally {
11771 Binder.restoreCallingIdentity(identity);
11772 }
11773 }
11774
11775 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011776 * Enables or disables the test mode for RCS VoLTE single registration.
11777 */
11778 @Override
11779 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11780 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11781 "setRcsSingleRegistrationTestModeEnabled");
11782
11783 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11784 }
11785
11786 /**
11787 * Gets the test mode for RCS VoLTE single registration.
11788 */
11789 @Override
11790 public boolean getRcsSingleRegistrationTestModeEnabled() {
11791 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11792 "getRcsSingleRegistrationTestModeEnabled");
11793
11794 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11795 }
11796
11797 /**
Hui Wang761a6682020-10-31 05:12:53 +000011798 * Overrides the config of RCS VoLTE single registration enabled for the device.
11799 */
11800 @Override
11801 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11802 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11803 "setDeviceSingleRegistrationEnabledOverride");
11804 enforceModifyPermission();
11805
11806 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11807 : Boolean.parseBoolean(enabledStr);
11808 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011809 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011810 }
11811
11812 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011813 * Sends a device to device communication message. Only usable via shell.
11814 * @param message message to send.
11815 * @param value message value.
11816 */
11817 @Override
11818 public void sendDeviceToDeviceMessage(int message, int value) {
11819 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011820 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011821 enforceModifyPermission();
11822
11823 final long identity = Binder.clearCallingIdentity();
11824 try {
11825 TelephonyConnectionService service =
11826 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11827 if (service == null) {
11828 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11829 return;
11830 }
11831 service.sendTestDeviceToDeviceMessage(message, value);
11832 } finally {
11833 Binder.restoreCallingIdentity(identity);
11834 }
11835 }
11836
Tyler Gunnbabbda02021-02-10 11:05:02 -080011837 /**
11838 * Sets the specified device to device transport active.
11839 * @param transport The transport to set active.
11840 */
11841 @Override
11842 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11843 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11844 "setActiveDeviceToDeviceTransport");
11845 enforceModifyPermission();
11846
11847 final long identity = Binder.clearCallingIdentity();
11848 try {
11849 TelephonyConnectionService service =
11850 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11851 if (service == null) {
11852 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11853 return;
11854 }
11855 service.setActiveDeviceToDeviceTransport(transport);
11856 } finally {
11857 Binder.restoreCallingIdentity(identity);
11858 }
11859 }
Tyler Gunn92479152021-01-20 16:30:10 -080011860
Tyler Gunnd4339262021-05-03 14:46:49 -070011861 @Override
11862 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11863 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11864 "setDeviceToDeviceForceEnabled");
11865
11866 final long identity = Binder.clearCallingIdentity();
11867 try {
11868 Arrays.stream(PhoneFactory.getPhones()).forEach(
11869 p -> {
11870 Phone thePhone = p.getImsPhone();
11871 if (thePhone != null && thePhone instanceof ImsPhone) {
11872 ImsPhone imsPhone = (ImsPhone) thePhone;
11873 CallTracker tracker = imsPhone.getCallTracker();
11874 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11875 ImsPhoneCallTracker imsPhoneCallTracker =
11876 (ImsPhoneCallTracker) tracker;
11877 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11878 }
11879 }
11880 }
11881 );
11882 } finally {
11883 Binder.restoreCallingIdentity(identity);
11884 }
11885 }
11886
Tyler Gunn92479152021-01-20 16:30:10 -080011887 /**
Hui Wang761a6682020-10-31 05:12:53 +000011888 * Gets the config of RCS VoLTE single registration enabled for the device.
11889 */
11890 @Override
11891 public boolean getDeviceSingleRegistrationEnabled() {
11892 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11893 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11894 }
11895
11896 /**
11897 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11898 */
11899 @Override
11900 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11901 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11902 "setCarrierSingleRegistrationEnabledOverride");
11903 enforceModifyPermission();
11904
11905 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11906 : Boolean.parseBoolean(enabledStr);
11907 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11908 subId, enabled);
11909 }
11910
11911 /**
11912 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11913 */
11914 @Override
11915 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11916 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11917 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11918 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011919
11920 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011921 * Overrides the ims feature validation result
11922 */
11923 @Override
11924 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11925 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11926 "setImsFeatureValidationOverride");
11927
11928 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11929 : Boolean.parseBoolean(enabledStr);
11930 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11931 subId, enabled);
11932 }
11933
11934 /**
11935 * Gets the ims feature validation override value
11936 */
11937 @Override
11938 public boolean getImsFeatureValidationOverride(int subId) {
11939 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11940 "getImsFeatureValidationOverride");
11941 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11942 }
11943
11944 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011945 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11946 * their mobile plan.
11947 */
11948 @Override
11949 public String getMobileProvisioningUrl() {
11950 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11951 final long identity = Binder.clearCallingIdentity();
11952 try {
11953 return getDefaultPhone().getMobileProvisioningUrl();
11954 } finally {
11955 Binder.restoreCallingIdentity(identity);
11956 }
11957 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011958
James.cf Linbcdf8b32021-01-14 16:44:13 +080011959 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011960 * Get the EAB contact from the EAB database.
11961 */
11962 @Override
11963 public String getContactFromEab(String contact) {
11964 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11965 enforceModifyPermission();
11966 final long identity = Binder.clearCallingIdentity();
11967 try {
11968 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11969 } finally {
11970 Binder.restoreCallingIdentity(identity);
11971 }
11972 }
11973
11974 /**
Calvin Pana1434322021-07-01 19:27:01 +080011975 * Get the EAB capability from the EAB database.
11976 */
11977 @Override
11978 public String getCapabilityFromEab(String contact) {
11979 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11980 enforceModifyPermission();
11981 final long identity = Binder.clearCallingIdentity();
11982 try {
11983 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11984 } finally {
11985 Binder.restoreCallingIdentity(identity);
11986 }
11987 }
11988
11989 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011990 * Remove the EAB contacts from the EAB database.
11991 */
11992 @Override
11993 public int removeContactFromEab(int subId, String contacts) {
11994 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11995 enforceModifyPermission();
11996 final long identity = Binder.clearCallingIdentity();
11997 try {
11998 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11999 } finally {
12000 Binder.restoreCallingIdentity(identity);
12001 }
12002 }
12003
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012004 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080012005 public boolean getDeviceUceEnabled() {
12006 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
12007 final long identity = Binder.clearCallingIdentity();
12008 try {
12009 return mApp.getDeviceUceEnabled();
12010 } finally {
12011 Binder.restoreCallingIdentity(identity);
12012 }
12013 }
12014
12015 @Override
12016 public void setDeviceUceEnabled(boolean isEnabled) {
12017 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
12018 final long identity = Binder.clearCallingIdentity();
12019 try {
12020 mApp.setDeviceUceEnabled(isEnabled);
12021 } finally {
12022 Binder.restoreCallingIdentity(identity);
12023 }
12024 }
12025
Brad Ebinger14d467f2021-02-12 06:18:28 +000012026 /**
12027 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
12028 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12029 */
12030 // Used for SHELL command only right now.
12031 @Override
12032 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
12033 List<String> featureTags) {
12034 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12035 "addUceRegistrationOverrideShell");
12036 final long identity = Binder.clearCallingIdentity();
12037 try {
12038 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
12039 new ArraySet<>(featureTags));
12040 } catch (ImsException e) {
12041 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12042 } finally {
12043 Binder.restoreCallingIdentity(identity);
12044 }
12045 }
12046
12047 /**
12048 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
12049 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12050 */
12051 // Used for SHELL command only right now.
12052 @Override
12053 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
12054 List<String> featureTags) {
12055 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12056 "removeUceRegistrationOverrideShell");
12057 final long identity = Binder.clearCallingIdentity();
12058 try {
12059 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
12060 new ArraySet<>(featureTags));
12061 } catch (ImsException e) {
12062 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12063 } finally {
12064 Binder.restoreCallingIdentity(identity);
12065 }
12066 }
12067
12068 /**
12069 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
12070 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12071 */
12072 // Used for SHELL command only right now.
12073 @Override
12074 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
12075 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12076 "clearUceRegistrationOverrideShell");
12077 final long identity = Binder.clearCallingIdentity();
12078 try {
12079 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
12080 } catch (ImsException e) {
12081 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12082 } finally {
12083 Binder.restoreCallingIdentity(identity);
12084 }
12085 }
12086
12087 /**
12088 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
12089 */
12090 // Used for SHELL command only right now.
12091 @Override
12092 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
12093 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
12094 "getLatestRcsContactUceCapabilityShell");
12095 final long identity = Binder.clearCallingIdentity();
12096 try {
12097 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
12098 } catch (ImsException e) {
12099 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12100 } finally {
12101 Binder.restoreCallingIdentity(identity);
12102 }
12103 }
12104
12105 /**
12106 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
12107 * device does not have an active PUBLISH.
12108 */
12109 // Used for SHELL command only right now.
12110 @Override
12111 public String getLastUcePidfXmlShell(int subId) {
12112 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
12113 final long identity = Binder.clearCallingIdentity();
12114 try {
12115 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
12116 } catch (ImsException e) {
12117 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12118 } finally {
12119 Binder.restoreCallingIdentity(identity);
12120 }
12121 }
12122
James.cf Line8713a42021-04-29 16:04:26 +080012123 /**
12124 * Remove UCE requests cannot be sent to the network status.
12125 */
12126 // Used for SHELL command only right now.
12127 @Override
12128 public boolean removeUceRequestDisallowedStatus(int subId) {
12129 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12130 final long identity = Binder.clearCallingIdentity();
12131 try {
12132 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12133 } catch (ImsException e) {
12134 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12135 } finally {
12136 Binder.restoreCallingIdentity(identity);
12137 }
12138 }
12139
James.cf Lin18bb9002021-05-25 01:37:38 +080012140 /**
12141 * Remove UCE requests cannot be sent to the network status.
12142 */
12143 // Used for SHELL command only.
12144 @Override
12145 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12146 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12147 final long identity = Binder.clearCallingIdentity();
12148 try {
12149 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12150 } catch (ImsException e) {
12151 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12152 } finally {
12153 Binder.restoreCallingIdentity(identity);
12154 }
12155 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012156
James.cf Lin4b784aa2021-01-31 03:25:15 +080012157 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012158 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12159 String callingPackage) {
12160 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12161 mApp, subId, "setSignalStrengthUpdateRequest");
12162
12163 final int callingUid = Binder.getCallingUid();
12164 // Verify that tha callingPackage belongs to the calling UID
12165 mApp.getSystemService(AppOpsManager.class)
12166 .checkPackage(callingUid, callingPackage);
12167
Rambo Wang3607f502021-02-01 21:51:40 -080012168 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012169
12170 final long identity = Binder.clearCallingIdentity();
12171 try {
12172 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12173 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12174
12175 if (result instanceof IllegalStateException) {
12176 throw (IllegalStateException) result;
12177 }
12178 } finally {
12179 Binder.restoreCallingIdentity(identity);
12180 }
12181 }
12182
12183 @Override
12184 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12185 String callingPackage) {
12186 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12187 mApp, subId, "clearSignalStrengthUpdateRequest");
12188
12189 final int callingUid = Binder.getCallingUid();
12190 // Verify that tha callingPackage belongs to the calling UID
12191 mApp.getSystemService(AppOpsManager.class)
12192 .checkPackage(callingUid, callingPackage);
12193
12194 final long identity = Binder.clearCallingIdentity();
12195 try {
12196 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12197 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12198
12199 if (result instanceof IllegalStateException) {
12200 throw (IllegalStateException) result;
12201 }
12202 } finally {
12203 Binder.restoreCallingIdentity(identity);
12204 }
12205 }
12206
Rambo Wang3607f502021-02-01 21:51:40 -080012207 private static void validateSignalStrengthUpdateRequest(Context context,
12208 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012209 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
12210 // phone/system process do not have further restriction on request
12211 return;
12212 }
12213
12214 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012215 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012216 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012217 context.enforceCallingOrSelfPermission(
12218 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12219 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012220 }
12221
12222 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012223 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012224 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012225 || info.isEnabled()) {
12226 throw new IllegalArgumentException(
12227 "Only system can set hide fields in SignalThresholdInfo");
12228 }
12229
12230 // Thresholds length for each RAN need in range. This has been validated in
12231 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12232 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12233 final int[] thresholds = info.getThresholds();
12234 Objects.requireNonNull(thresholds);
12235 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12236 || thresholds.length
12237 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12238 throw new IllegalArgumentException(
12239 "thresholds length is out of range: " + thresholds.length);
12240 }
12241 }
12242 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012243
12244 /**
12245 * Gets the current phone capability.
12246 *
12247 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12248 * @return the PhoneCapability which describes the data connection capability of modem.
12249 * It's used to evaluate possible phone config change, for example from single
12250 * SIM device to multi-SIM device.
12251 */
12252 @Override
12253 public PhoneCapability getPhoneCapability() {
12254 enforceReadPrivilegedPermission("getPhoneCapability");
12255 final long identity = Binder.clearCallingIdentity();
12256 try {
12257 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12258 } finally {
12259 Binder.restoreCallingIdentity(identity);
12260 }
12261 }
Michele Berionne5e411512020-11-13 02:36:59 +000012262
12263 /**
12264 * Prepare TelephonyManager for an unattended reboot. The reboot is
12265 * required to be done shortly after the API is invoked.
12266 */
12267 @Override
12268 @TelephonyManager.PrepareUnattendedRebootResult
12269 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012270 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012271 enforceRebootPermission();
12272
12273 final long identity = Binder.clearCallingIdentity();
12274 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012275 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012276 } finally {
12277 Binder.restoreCallingIdentity(identity);
12278 }
12279 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012280
12281 /**
12282 * Request to get the current slicing configuration including URSP rules and
12283 * NSSAIs (configured, allowed and rejected).
12284 *
12285 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12286 */
12287 @Override
12288 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012289 TelephonyPermissions
12290 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12291 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012292
12293 final long identity = Binder.clearCallingIdentity();
12294 try {
12295 Phone phone = getDefaultPhone();
12296 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12297 } finally {
12298 Binder.restoreCallingIdentity(identity);
12299 }
12300 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012301
12302 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012303 * Check whether the given premium capability is available for purchase from the carrier.
12304 *
12305 * @param capability The premium capability to check.
12306 * @param subId The subId to check the premium capability for.
12307 *
12308 * @return Whether the given premium capability is available to purchase.
12309 */
12310 @Override
12311 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12312 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12313 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12314 log("Premium capability "
12315 + TelephonyManager.convertPremiumCapabilityToString(capability)
12316 + " is not available for purchase due to missing permissions.");
12317 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12318 + "permission READ_BASIC_PHONE_STATE.");
12319 }
12320
12321 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012322 if (phone == null) {
12323 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12324 return false;
12325 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012326 final long identity = Binder.clearCallingIdentity();
12327 try {
Sarah Chin46355ba2022-11-01 23:51:16 -070012328 return SlicePurchaseController.getInstance(phone)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012329 .isPremiumCapabilityAvailableForPurchase(capability);
12330 } finally {
12331 Binder.restoreCallingIdentity(identity);
12332 }
12333 }
12334
12335 /**
12336 * Purchase the given premium capability from the carrier.
12337 *
12338 * @param capability The premium capability to purchase.
12339 * @param callback The result of the purchase request.
12340 * @param subId The subId to purchase the premium capability for.
12341 */
12342 @Override
12343 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12344 log("purchasePremiumCapability: capability="
12345 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12346 + getCurrentPackageName());
12347
12348 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12349 mApp, "purchasePremiumCapability")) {
12350 log("purchasePremiumCapability "
12351 + TelephonyManager.convertPremiumCapabilityToString(capability)
12352 + " failed due to missing permissions.");
12353 throw new SecurityException("purchasePremiumCapability requires permission "
12354 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012355 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12356 mApp, "purchasePremiumCapability")) {
12357 log("purchasePremiumCapability "
12358 + TelephonyManager.convertPremiumCapabilityToString(capability)
12359 + " failed due to missing permissions.");
12360 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012361 }
12362
12363 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012364 if (phone == null) {
12365 try {
12366 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12367 callback.accept(result);
12368 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12369 } catch (RemoteException e) {
12370 String logStr = "Purchase premium capability "
12371 + TelephonyManager.convertPremiumCapabilityToString(capability)
12372 + " failed due to RemoteException handling null phone: " + e;
12373 if (DBG) log(logStr);
12374 AnomalyReporter.reportAnomaly(
12375 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12376 }
12377 return;
12378 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012379
12380 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012381 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012382 callingProcess = mApp.getPackageManager().getApplicationInfo(
12383 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070012384 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012385 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012386 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012387
12388 boolean isVisible = false;
12389 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12390 if (am != null) {
12391 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12392 if (processes != null) {
12393 for (ActivityManager.RunningAppProcessInfo process : processes) {
12394 log("purchasePremiumCapability: process " + process.processName
12395 + "has importance " + process.importance);
12396 if (process.processName.equals(callingProcess) && process.importance
12397 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12398 isVisible = true;
12399 break;
12400 }
12401 }
12402 }
12403 }
12404
12405 if (!isVisible) {
12406 try {
12407 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12408 callback.accept(result);
12409 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12410 } catch (RemoteException e) {
12411 String logStr = "Purchase premium capability "
12412 + TelephonyManager.convertPremiumCapabilityToString(capability)
12413 + " failed due to RemoteException handling background application: " + e;
12414 if (DBG) log(logStr);
12415 AnomalyReporter.reportAnomaly(
12416 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12417 }
12418 return;
12419 }
12420
Sarah Chin71b3a852022-09-28 15:54:19 -070012421 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012422 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012423 }
12424
12425 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012426 * Register an IMS connection state callback
12427 */
12428 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012429 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12430 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012431 if (feature == ImsFeature.FEATURE_MMTEL) {
12432 // ImsMmTelManager
12433 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12434 TelephonyPermissions
12435 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12436 mApp, subId, "registerImsStateCallback");
12437 } else if (feature == ImsFeature.FEATURE_RCS) {
12438 // ImsRcsManager or SipDelegateManager
12439 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12440 Binder.getCallingUid(), "registerImsStateCallback",
12441 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12442 Manifest.permission.READ_PRECISE_PHONE_STATE,
12443 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12444 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12445 }
12446
12447 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12448 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12449 "IMS not available on device.");
12450 }
12451
12452 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12453 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12454 }
12455
12456 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12457 if (controller == null) {
12458 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12459 "IMS not available on device.");
12460 }
12461
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012462 if (callingPackage == null) {
12463 callingPackage = getCurrentPackageName();
12464 }
12465
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012466 final long token = Binder.clearCallingIdentity();
12467 try {
12468 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012469 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012470 } catch (ImsException e) {
12471 throw new ServiceSpecificException(e.getCode());
12472 } finally {
12473 Binder.restoreCallingIdentity(token);
12474 }
12475 }
12476
12477 /**
12478 * Unregister an IMS connection state callback
12479 */
12480 @Override
12481 public void unregisterImsStateCallback(IImsStateCallback cb) {
12482 final long token = Binder.clearCallingIdentity();
12483 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12484 if (controller == null) {
12485 return;
12486 }
12487 try {
12488 controller.unregisterImsStateCallback(cb);
12489 } finally {
12490 Binder.restoreCallingIdentity(token);
12491 }
12492 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012493
12494 /**
12495 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12496 *
12497 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
12498 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
12499 * SecurityException.
12500 * If there is current registered network this value will be same as the registered cell
12501 * identity. If the device goes out of service the previous cell identity is cached and
12502 * will be returned. If the cache age of the Cell identity is more than 24 hours
12503 * it will be cleared and null will be returned.
12504 *
12505 */
12506 @Override
12507 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12508 String callingFeatureId) {
12509 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12510 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12511 LocationAccessPolicy.checkLocationPermission(mApp,
12512 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12513 .setCallingPackage(callingPackage)
12514 .setCallingFeatureId(callingFeatureId)
12515 .setCallingPid(Binder.getCallingPid())
12516 .setCallingUid(Binder.getCallingUid())
12517 .setMethod("getLastKnownCellIdentity")
12518 .setLogAsInfo(true)
12519 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12520 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12521 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12522 .build());
12523
12524 boolean hasFinePermission =
12525 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12526 if (!hasFinePermission
12527 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12528 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012529 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012530 }
12531
12532 final long identity = Binder.clearCallingIdentity();
12533 try {
12534 Phone phone = getPhone(subId);
12535 if (phone == null) return null;
12536 ServiceStateTracker sst = phone.getServiceStateTracker();
12537 if (sst == null) return null;
12538 return sst.getLastKnownCellIdentity();
12539 } finally {
12540 Binder.restoreCallingIdentity(identity);
12541 }
12542 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012543
jimsun3b9ccac2021-10-26 15:01:23 +080012544 /**
12545 * Sets the modem service class Name that Telephony will bind to.
12546 *
12547 * @param serviceName The class name of the modem service.
12548 * @return true if the operation is succeed, otherwise false.
12549 */
12550 public boolean setModemService(String serviceName) {
12551 Log.d(LOG_TAG, "setModemService - " + serviceName);
12552 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12553 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012554 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12555 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012556 return mPhoneConfigurationManager.setModemService(serviceName);
12557 }
12558
12559 /**
12560 * Return the class name of the currently bounded modem service.
12561 *
12562 * @return the class name of the modem service.
12563 */
12564 public String getModemService() {
12565 String result;
12566 Log.d(LOG_TAG, "getModemService");
12567 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12568 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012569 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012570 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12571 "getModemService");
12572 result = mPhoneConfigurationManager.getModemService();
12573 Log.d(LOG_TAG, "result = " + result);
12574 return result;
12575 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012576
12577 @Override
12578 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12579 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12580 mApp.enforceCallingOrSelfPermission(
12581 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12582 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12583
12584 final long identity = Binder.clearCallingIdentity();
12585 try {
12586 Phone phone = getPhone(subId);
12587 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012588 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12589 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012590 phone.setVoiceServiceStateOverride(hasService);
12591 } finally {
12592 Binder.restoreCallingIdentity(identity);
12593 }
12594 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012595
12596 /**
12597 * set removable eSIM as default eUICC.
12598 *
12599 * @hide
12600 */
12601 @Override
12602 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12603 enforceModifyPermission();
12604 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12605
12606 final long identity = Binder.clearCallingIdentity();
12607 try {
12608 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12609 } finally {
12610 Binder.restoreCallingIdentity(identity);
12611 }
12612 }
12613
12614 /**
12615 * Returns whether the removable eSIM is default eUICC or not.
12616 *
12617 * @hide
12618 */
12619 @Override
12620 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12621 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12622 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12623
12624 final long identity = Binder.clearCallingIdentity();
12625 try {
12626 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12627 } finally {
12628 Binder.restoreCallingIdentity(identity);
12629 }
12630 }
12631
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012632 /**
12633 * Get the component name of the default app to direct respond-via-message intent for the
12634 * user associated with this subscription, update the cache if there is no respond-via-message
12635 * application currently configured for this user.
12636 * @return component name of the app and class to direct Respond Via Message intent to, or
12637 * {@code null} if the functionality is not supported.
12638 * @hide
12639 */
12640 @Override
12641 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12642 boolean updateIfNeeded) {
12643 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012644
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012645 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12646
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012647 UserHandle userHandle = null;
12648 final long identity = Binder.clearCallingIdentity();
12649 try {
12650 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12651 } finally {
12652 Binder.restoreCallingIdentity(identity);
12653 }
12654 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12655 updateIfNeeded, userHandle);
12656 }
Jack Yuf5badd92022-12-08 00:50:53 -080012657
12658 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012659 * Set whether the device is able to connect with null ciphering or integrity
12660 * algorithms. This is a global setting and will apply to all active subscriptions
12661 * and all new subscriptions after this.
12662 *
12663 * @param enabled when true, null cipher and integrity algorithms are allowed.
12664 * @hide
12665 */
12666 @Override
12667 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12668 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12669 enforceModifyPermission();
12670 checkForNullCipherAndIntegritySupport();
12671
12672 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12673 // for listening to these preference changes and applying them immediately.
12674 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12675 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12676 editor.apply();
12677
12678 for (Phone phone: PhoneFactory.getPhones()) {
12679 phone.handleNullCipherEnabledChange();
12680 }
12681 }
12682
12683
12684 /**
12685 * Get whether the device is able to connect with null ciphering or integrity
12686 * algorithms. Note that this retrieves the phone-global preference and not
12687 * the state of the radio.
12688 *
12689 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12690 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12691 * version for this feature.
12692 * @hide
12693 */
12694 @Override
12695 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12696 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12697 enforceReadPermission();
12698 checkForNullCipherAndIntegritySupport();
12699 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12700 }
12701
12702 private void checkForNullCipherAndIntegritySupport() {
12703 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12704 throw new UnsupportedOperationException(
12705 "Null cipher and integrity operations require HAL 2.1 or above");
12706 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012707 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12708 throw new UnsupportedOperationException(
12709 "Null cipher and integrity operations unsupported by modem");
12710 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012711 }
12712
12713 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012714 * Get the SIM state for the slot index.
12715 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12716 *
12717 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12718 */
12719 @Override
12720 @SimState
12721 public int getSimStateForSlotIndex(int slotIndex) {
12722 IccCardConstants.State simState;
12723 if (slotIndex < 0) {
12724 simState = IccCardConstants.State.UNKNOWN;
12725 } else {
12726 Phone phone = null;
12727 try {
12728 phone = PhoneFactory.getPhone(slotIndex);
12729 } catch (IllegalStateException e) {
12730 // ignore
12731 }
12732 if (phone == null) {
12733 simState = IccCardConstants.State.UNKNOWN;
12734 } else {
12735 IccCard icc = phone.getIccCard();
12736 if (icc == null) {
12737 simState = IccCardConstants.State.UNKNOWN;
12738 } else {
12739 simState = icc.getState();
12740 }
12741 }
12742 }
12743 return simState.ordinal();
12744 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012745
12746 /**
12747 * Get current cell broadcast ranges.
12748 */
12749 @Override
12750 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12751 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12752 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12753 "getCellBroadcastIdRanges");
12754 final long identity = Binder.clearCallingIdentity();
12755 try {
12756 return getPhone(subId).getCellBroadcastIdRanges();
12757 } finally {
12758 Binder.restoreCallingIdentity(identity);
12759 }
12760 }
12761
12762 /**
12763 * Set reception of cell broadcast messages with the list of the given ranges
12764 *
12765 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12766 */
12767 @Override
12768 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12769 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12770 @Nullable IIntegerConsumer callback) {
12771 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12772 "setCellBroadcastIdRanges");
12773 final long identity = Binder.clearCallingIdentity();
12774 try {
12775 Phone phone = getPhoneFromSubId(subId);
12776 if (DBG) {
12777 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12778 }
12779 phone.setCellBroadcastIdRanges(ranges, result -> {
12780 if (callback != null) {
12781 try {
12782 callback.accept(result);
12783 } catch (RemoteException e) {
12784 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12785 }
12786 }
12787 });
12788 } finally {
12789 Binder.restoreCallingIdentity(identity);
12790 }
12791 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012792
12793 /**
12794 * Returns whether the device supports the domain selection service.
12795 *
12796 * @return {@code true} if the device supports the domain selection service.
12797 */
12798 @Override
12799 public boolean isDomainSelectionSupported() {
12800 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12801 "isDomainSelectionSupported");
12802
12803 final long identity = Binder.clearCallingIdentity();
12804 try {
12805 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12806 } finally {
12807 Binder.restoreCallingIdentity(identity);
12808 }
12809 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012810
12811 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012812 * Enable or disable the satellite modem. If the satellite modem is enabled, this will also
12813 * disable the cellular modem, and if the satellite modem is disabled, this will also re-enable
12814 * the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080012815 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012816 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012817 * @param enable {@code true} to enable the satellite modem and {@code false} to disable.
12818 * @param callback The callback to get the error code of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080012819 *
12820 * @throws SecurityException if the caller doesn't have the required permission.
12821 */
12822 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012823 public void setSatelliteEnabled(int subId, boolean enable, @NonNull IIntegerConsumer callback) {
12824 enforceSatelliteCommunicationPermission("setSatelliteEnabled");
12825 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012826 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012827 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
12828 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012829 }
Sarah Chin503828c2023-02-01 23:54:20 -080012830
12831 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012832 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012833 result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED);
12834 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012835 }
12836
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012837 Phone phone = getPhoneOrDefault(validSubId, "setSatelliteEnabled");
Sarah Chin503828c2023-02-01 23:54:20 -080012838 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012839 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
12840 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012841 }
12842
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012843 Pair<Boolean, Consumer<Integer>> arg = new Pair<>(enable, result);
12844 sendRequestAsync(CMD_SET_SATELLITE_ENABLED, arg, phone, null);
Sarah Chin503828c2023-02-01 23:54:20 -080012845 }
12846
12847 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012848 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080012849 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012850 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012851 * @param result The result receiver that returns whether the satellite modem is enabled
12852 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012853 *
12854 * @throws SecurityException if the caller doesn't have the required permission.
12855 */
12856 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012857 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
12858 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012859 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012860 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
12861 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012862 }
Sarah Chin503828c2023-02-01 23:54:20 -080012863
12864 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012865 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012866 result.send(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED, null);
12867 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012868 }
12869
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012870 Phone phone = getPhoneOrDefault(validSubId, "requestIsSatelliteEnabled");
Sarah Chin503828c2023-02-01 23:54:20 -080012871 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012872 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
12873 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012874 }
12875
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012876 sendRequest(CMD_IS_SATELLITE_ENABLED, result, subId);
Sarah Chin503828c2023-02-01 23:54:20 -080012877 }
12878
12879 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012880 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080012881 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012882 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012883 * @param result The result receiver that returns whether the satellite service is supported on
12884 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012885 */
12886 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012887 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012888 synchronized (mIsSatelliteSupportedLock) {
12889 if (mIsSatelliteSupported != null) {
12890 /* We have already successfully queried the satellite modem. */
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012891 Bundle bundle = new Bundle();
12892 bundle.putBoolean(SatelliteManager.KEY_SATELLITE_SUPPORTED, mIsSatelliteSupported);
12893 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, bundle);
12894 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012895 }
12896 }
Sarah Chin503828c2023-02-01 23:54:20 -080012897
12898 final int validSubId = getValidSatelliteSubId(subId);
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012899 Phone phone = getPhoneOrDefault(validSubId, "requestIsSatelliteSupported");
Sarah Chin503828c2023-02-01 23:54:20 -080012900 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012901 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
12902 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012903 }
12904
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012905 sendRequestAsync(CMD_IS_SATELLITE_SUPPORTED, result, phone, null);
Sarah Chin503828c2023-02-01 23:54:20 -080012906 }
12907
12908 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012909 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080012910 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012911 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012912 * @param result The result receiver that returns the {@link SatelliteCapabilities}
12913 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012914 *
12915 * @throws SecurityException if the caller doesn't have required permission.
12916 */
12917 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012918 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
12919 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012920 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012921 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
12922 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012923 }
Sarah Chin503828c2023-02-01 23:54:20 -080012924
12925 final int validSubId = getValidSatelliteSubId(subId);
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012926 Phone phone = getPhoneOrDefault(validSubId, "requestSatelliteCapabilities");
Sarah Chin503828c2023-02-01 23:54:20 -080012927 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012928 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
12929 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012930 }
12931
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012932 sendRequestAsync(CMD_GET_SATELLITE_CAPABILITIES, result, phone, null);
Sarah Chin503828c2023-02-01 23:54:20 -080012933 }
12934
12935 /**
Sarah Chineccfbd12023-01-20 19:00:35 -080012936 * Start receiving satellite position updates.
12937 * This can be called by the pointing UI when the user starts pointing to the satellite.
12938 * Modem should continue to report the pointing input as the device or satellite moves.
12939 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012940 * @param subId The subId of the subscription to start satellite position updates for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012941 * @param errorCallback The callback to get the error code of the request.
Sarah Chineccfbd12023-01-20 19:00:35 -080012942 * @param callback The callback to notify of changes in satellite position.
Sarah Chin503828c2023-02-01 23:54:20 -080012943 *
12944 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012945 */
12946 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012947 public void startSatellitePositionUpdates(int subId, @NonNull IIntegerConsumer errorCallback,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012948 @NonNull ISatelliteStateListener callback) {
Sarah Chinf75afa72023-02-01 01:32:19 -080012949 enforceSatelliteCommunicationPermission("startSatellitePositionUpdates");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012950 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(errorCallback::accept);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012951 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012952 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
12953 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012954 }
Sarah Chinf75afa72023-02-01 01:32:19 -080012955
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012956 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012957 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012958 result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED);
12959 return;
Sarah Chinf75afa72023-02-01 01:32:19 -080012960 }
12961
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012962 Phone phone = getPhoneOrDefault(validSubId, "startSatellitePositionUpdates");
Sarah Chineccfbd12023-01-20 19:00:35 -080012963 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012964 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
12965 return;
Sarah Chineccfbd12023-01-20 19:00:35 -080012966 }
12967
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012968 if (mSatellitePositionUpdateHandlers.containsKey(callback.asBinder())) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012969 if (DBG) {
12970 log("startSatellitePositionUpdates: callback already registered: "
12971 + callback.asBinder());
12972 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012973 result.accept(SatelliteManager.SATELLITE_ERROR_NONE);
12974 return;
Sarah Chineccfbd12023-01-20 19:00:35 -080012975 }
12976
12977 SatellitePositionUpdateHandler handler =
12978 new SatellitePositionUpdateHandler(callback, Looper.getMainLooper());
12979 phone.registerForSatellitePointingInfoChanged(handler,
12980 SatellitePositionUpdateHandler.EVENT_POSITION_UPDATE, null);
12981 phone.registerForSatelliteMessagesTransferComplete(handler,
12982 SatellitePositionUpdateHandler.EVENT_MESSAGE_TRANSFER_STATE_UPDATE, null);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012983 mSatellitePositionUpdateHandlers.put(callback.asBinder(), handler);
Sarah Chineccfbd12023-01-20 19:00:35 -080012984
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012985 sendRequestAsync(CMD_START_SATELLITE_POSITION_UPDATES, result, phone, null);
Sarah Chineccfbd12023-01-20 19:00:35 -080012986 }
12987
12988 /**
12989 * Stop receiving satellite position updates.
12990 * This can be called by the pointing UI when the user stops pointing to the satellite.
12991 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012992 * @param subId The subId of the subscription to stop satellite position updates for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012993 * @param errorCallback The callback to get the error code of the request.
12994 * @param callback The callback that was passed to {@link
12995 * #startSatellitePositionUpdates(int, IIntegerConsumer, ISatelliteStateListener)}
Sarah Chin503828c2023-02-01 23:54:20 -080012996 *
12997 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012998 */
12999 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013000 public void stopSatellitePositionUpdates(int subId, @NonNull IIntegerConsumer errorCallback,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013001 @NonNull ISatelliteStateListener callback) {
Sarah Chinf75afa72023-02-01 01:32:19 -080013002 enforceSatelliteCommunicationPermission("stopSatellitePositionUpdates");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013003 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(errorCallback::accept);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013004 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013005 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
13006 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013007 }
Sarah Chinf75afa72023-02-01 01:32:19 -080013008
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013009 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013010 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013011 result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED);
13012 return;
Sarah Chinf75afa72023-02-01 01:32:19 -080013013 }
13014
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013015 Phone phone = getPhoneOrDefault(validSubId, "stopSatellitePositionUpdates");
Sarah Chineccfbd12023-01-20 19:00:35 -080013016 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013017 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
13018 return;
Sarah Chineccfbd12023-01-20 19:00:35 -080013019 }
13020
13021 SatellitePositionUpdateHandler handler =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013022 mSatellitePositionUpdateHandlers.remove(callback.asBinder());
Sarah Chineccfbd12023-01-20 19:00:35 -080013023 if (handler == null) {
Sarah Chindf715ec2023-02-13 13:46:24 -080013024 loge("stopSatellitePositionUpdates: No SatellitePositionUpdateHandler");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013025 result.accept(SatelliteManager.SATELLITE_INVALID_ARGUMENTS);
13026 return;
Sarah Chineccfbd12023-01-20 19:00:35 -080013027 } else {
13028 phone.unregisterForSatellitePointingInfoChanged(handler);
13029 phone.unregisterForSatelliteMessagesTransferComplete(handler);
13030 }
13031
13032 if (!mSatellitePositionUpdateHandlers.isEmpty()) {
13033 log("stopSatellitePositionUpdates: other listeners still exist.");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013034 result.accept(SatelliteManager.SATELLITE_ERROR_NONE);
13035 return;
Sarah Chineccfbd12023-01-20 19:00:35 -080013036 }
13037
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013038 sendRequestAsync(CMD_STOP_SATELLITE_POSITION_UPDATES, result, phone, null);
Sarah Chineccfbd12023-01-20 19:00:35 -080013039 }
13040
13041 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013042 * Request to get the maximum number of characters per text message on satellite.
13043 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013044 * @param subId The subId of the subscription to get the maximum number of characters for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013045 * @param result The result receiver that returns the maximum number of characters per text
13046 * message on satellite if the request is successful or an error code
13047 * if the request failed.
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013048 *
13049 * @throws SecurityException if the caller doesn't have the required permission.
13050 */
13051 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013052 public void requestMaxCharactersPerSatelliteTextMessage(int subId,
13053 @NonNull ResultReceiver result) {
13054 enforceSatelliteCommunicationPermission("requestMaxCharactersPerSatelliteTextMessage");
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013055 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013056 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
13057 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013058 }
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013059
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013060 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013061 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013062 result.send(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED, null);
13063 return;
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013064 }
13065
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013066 Phone phone = getPhoneOrDefault(validSubId, "requestMaxCharactersPerSatelliteTextMessage");
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013067 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013068 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
13069 return;
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013070 }
13071
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013072 sendRequestAsync(CMD_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG, result, phone, null);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000013073 }
13074
13075 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013076 * Register the subscription with a satellite provider.
13077 * This is needed to register the subscription if the provider allows dynamic registration.
13078 *
13079 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013080 * @param token The token to be used as a unique identifier for provisioning with satellite
13081 * gateway.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013082 * @param callback The callback to get the error code of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013083 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013084 * @return The signal transport used by the caller to cancel the provision request,
13085 * or {@code null} if the request failed.
13086 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013087 * @throws SecurityException if the caller doesn't have the required permission.
13088 */
13089 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013090 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
13091 @NonNull String token, @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013092 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013093 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013094 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013095 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013096 return null;
13097 }
13098
13099 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013100 Phone phone = getPhoneOrDefault(validSubId, "provisionSatelliteService");
13101 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013102 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013103 return null;
13104 }
13105
13106 if (mSatelliteProvisionCallbacks.containsKey(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013107 result.accept(SatelliteManager.SATELLITE_SERVICE_PROVISION_IN_PROGRESS);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013108 return null;
13109 }
13110
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013111 if (isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013112 result.accept(SatelliteManager.SATELLITE_ERROR_NONE);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013113 return null;
13114 }
13115
13116 sendRequestAsync(CMD_PROVISION_SATELLITE_SERVICE,
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013117 new ProvisionSatelliteServiceArgument(token, result, validSubId), phone, null);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013118
13119 ICancellationSignal cancelTransport = CancellationSignal.createTransport();
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013120 CancellationSignal.fromTransport(cancelTransport).setOnCancelListener(() -> {
13121 sendRequestAsync(CMD_DEPROVISION_SATELLITE_SERVICE,
13122 new ProvisionSatelliteServiceArgument(token, null, validSubId),
13123 phone, null);
13124 });
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013125 return cancelTransport;
13126 }
13127
13128 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013129 * Unregister the device/subscription with the satellite provider.
13130 * This is needed if the provider allows dynamic registration. Once deprovisioned,
13131 * {@link SatelliteCallback.SatelliteProvisionStateListener#onSatelliteProvisionStateChanged}
13132 * should report as deprovisioned.
13133 *
13134 * @param subId The subId of the subscription to be deprovisioned.
13135 * @param token The token of the device/subscription to be deprovisioned.
13136 * @param callback The callback to get the error code of the request.
13137 *
13138 * @throws SecurityException if the caller doesn't have the required permission.
13139 */
13140 @Override
13141 public void deprovisionSatelliteService(int subId,
13142 @NonNull String token, @NonNull IIntegerConsumer callback) {
13143 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
13144 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept);
13145 if (!isSatelliteSupported()) {
13146 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
13147 return;
13148 }
13149
13150 final int validSubId = getValidSatelliteSubId(subId);
13151 if (!isSatelliteProvisioned(validSubId)) {
13152 result.accept(SatelliteManager.SATELLITE_ERROR_NONE);
13153 return;
13154 }
13155
13156 Phone phone = getPhoneOrDefault(validSubId, "deprovisionSatelliteService");
13157 if (phone == null) {
13158 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
13159 return;
13160 }
13161
13162 sendRequestAsync(CMD_DEPROVISION_SATELLITE_SERVICE,
13163 new ProvisionSatelliteServiceArgument(token, result, validSubId), phone, null);
13164 }
13165
13166 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013167 * Register for the satellite provision state change.
13168 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013169 * @param subId The subId of the subscription to register for provision state changes.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013170 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013171 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013172 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
13173 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013174 * @throws SecurityException if the caller doesn't have the required permission.
13175 */
13176 @Override
Sarah Chindf715ec2023-02-13 13:46:24 -080013177 @SatelliteManager.SatelliteError public int registerForSatelliteProvisionStateChanged(int subId,
13178 @NonNull ISatelliteStateListener callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013179 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Sarah Chindf715ec2023-02-13 13:46:24 -080013180 return registerForSatelliteProvisionStateChangedInternal(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013181 }
13182
13183 /**
13184 * Unregister for the satellite provision state change.
13185 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013186 * @param subId The subId of the subscription to unregister for provision state changes.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013187 * @param callback The callback that was passed to {@link
Sarah Chindf715ec2023-02-13 13:46:24 -080013188 * #registerForSatelliteProvisionStateChanged(int, ISatelliteStateListener)}.
13189 *
13190 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013191 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013192 * @throws SecurityException if the caller doesn't have the required permission.
13193 */
13194 @Override
Sarah Chindf715ec2023-02-13 13:46:24 -080013195 @SatelliteManager.SatelliteError public int unregisterForSatelliteProvisionStateChanged(
13196 int subId, @NonNull ISatelliteStateListener callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013197 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013198 if (!isSatelliteSupported()) {
Sarah Chindf715ec2023-02-13 13:46:24 -080013199 return SatelliteManager.SATELLITE_NOT_SUPPORTED;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013200 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013201
13202 final int validSubId = getValidSatelliteSubId(subId);
13203 SatelliteProvisionStateChangedHandler satelliteProvisionStateChangedHandler =
13204 mSatelliteProvisionStateChangedHandlers.get(validSubId);
13205 if (satelliteProvisionStateChangedHandler != null) {
13206 if (satelliteProvisionStateChangedHandler.removeListener(callback)) {
Sarah Chindf715ec2023-02-13 13:46:24 -080013207 return SatelliteManager.SATELLITE_ERROR_NONE;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013208 }
13209 }
Sarah Chindf715ec2023-02-13 13:46:24 -080013210 return SatelliteManager.SATELLITE_INVALID_ARGUMENTS;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013211 }
13212
13213 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013214 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013215 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013216 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013217 * @param result The result receiver that returns whether the device is provisioned with a
13218 * satellite provider if the request is successful or an error code if the
13219 * request failed.
13220 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013221 * @throws SecurityException if the caller doesn't have the required permission.
13222 */
13223 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013224 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
13225 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013226 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013227 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
13228 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013229 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013230
13231 final int validSubId = getValidSatelliteSubId(subId);
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013232 Bundle bundle = new Bundle();
13233 bundle.putBoolean(SatelliteManager.KEY_SATELLITE_PROVISIONED,
13234 isSatelliteProvisioned(validSubId));
13235 result.send(SatelliteManager.SATELLITE_ERROR_NONE, bundle);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013236 }
13237
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013238 /**
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013239 * Register for listening to satellite modem state changes.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013240 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013241 * @param subId The subId of the subscription to register for satellite modem state changes.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013242 * @param callback The callback to handle the satellite modem state change event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013243 *
13244 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
13245 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013246 * @throws SecurityException if the caller doesn't have the required permission.
13247 */
13248 @Override
Sarah Chindf715ec2023-02-13 13:46:24 -080013249 @SatelliteManager.SatelliteError public int registerForSatelliteModemStateChange(int subId,
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013250 @NonNull ISatelliteStateListener callback) {
13251 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChange");
13252
13253 final int validSubId = getValidSatelliteSubId(subId);
13254 Phone phone = getPhoneOrDefault(
13255 validSubId, "registerForSatelliteModemStateChange");
13256 if (phone == null) {
13257 return SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE;
13258 }
13259
13260 SatelliteStateListenerHandler satelliteStateListenerHandler =
13261 mSatelliteStateListenerHandlers.get(validSubId);
13262 if (satelliteStateListenerHandler == null) {
13263 satelliteStateListenerHandler = new SatelliteStateListenerHandler(
13264 Looper.getMainLooper(), validSubId);
13265 phone.registerForSatelliteModemStateChange(satelliteStateListenerHandler,
13266 SatelliteStateListenerHandler.EVENT_SATELLITE_MODEM_STATE_CHANGE, null);
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013267 phone.registerForPendingDatagramCount(satelliteStateListenerHandler,
13268 SatelliteStateListenerHandler.EVENT_PENDING_DATAGRAM_COUNT, null);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013269 }
13270
13271 satelliteStateListenerHandler.addListener(callback);
13272 mSatelliteStateListenerHandlers.put(validSubId, satelliteStateListenerHandler);
13273 return SatelliteManager.SATELLITE_ERROR_NONE;
13274 }
13275
13276 /**
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013277 * Unregister from listening to satellite modem state changes.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013278 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013279 * @param subId The subId of the subscription to unregister for satellite modem state changes.
13280 * @param callback The callback that was passed to
13281 * {@link #registerForSatelliteModemStateChange(int, ISatelliteStateListener)}.
13282 *
13283 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013284 *
13285 * @throws SecurityException if the caller doesn't have the required permission.
13286 */
13287 @Override
Sarah Chindf715ec2023-02-13 13:46:24 -080013288 @SatelliteManager.SatelliteError public int unregisterForSatelliteModemStateChange(int subId,
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013289 @NonNull ISatelliteStateListener callback) {
13290 enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChange");
13291
13292 final int validSubId = getValidSatelliteSubId(subId);
13293 SatelliteStateListenerHandler satelliteStateListenerHandler =
13294 mSatelliteStateListenerHandlers.get(validSubId);
13295 if (satelliteStateListenerHandler != null) {
13296 if (satelliteStateListenerHandler.removeListener(callback)) {
13297 return SatelliteManager.SATELLITE_ERROR_NONE;
13298 }
13299 }
13300 return SatelliteManager.SATELLITE_INVALID_ARGUMENTS;
13301 }
13302
13303 /**
13304 * Register to receive incoming datagrams over satellite.
13305 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013306 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013307 * @param datagramType datagram type indicating whether the datagram is of type
13308 * SOS_SMS or LOCATION_SHARING.
Sarah Chindf715ec2023-02-13 13:46:24 -080013309 * @param callback The callback to handle incoming datagrams over satellite.
13310 *
13311 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
13312 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013313 * @throws SecurityException if the caller doesn't have the required permission.
13314 */
13315 @Override
Sarah Chindf715ec2023-02-13 13:46:24 -080013316 @SatelliteManager.SatelliteError public int registerForSatelliteDatagram(int subId,
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013317 @SatelliteManager.DatagramType int datagramType,
13318 @NonNull ISatelliteStateListener callback) {
13319 enforceSatelliteCommunicationPermission("registerForSatelliteDatagram");
13320
13321 final int validSubId = getValidSatelliteSubId(subId);
Sarah Chindf715ec2023-02-13 13:46:24 -080013322 Phone phone = getPhoneOrDefault(validSubId, "registerForSatelliteDatagram");
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013323 if (phone == null) {
13324 return SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE;
13325 }
13326
13327 SatelliteDatagramListenerHandler satelliteDatagramListenerHandler =
13328 mSatelliteDatagramListenerHandlers.get(validSubId);
13329 if (satelliteDatagramListenerHandler == null) {
13330 satelliteDatagramListenerHandler = new SatelliteDatagramListenerHandler(
13331 Looper.getMainLooper(), validSubId);
13332 phone.registerForNewSatelliteDatagram(satelliteDatagramListenerHandler,
13333 SatelliteDatagramListenerHandler.EVENT_SATELLITE_DATAGRAMS_RECEIVED, null);
13334 }
13335
13336 satelliteDatagramListenerHandler.addListener(callback);
13337 mSatelliteDatagramListenerHandlers.put(validSubId, satelliteDatagramListenerHandler);
13338 return SatelliteManager.SATELLITE_ERROR_NONE;
13339 }
13340
13341 /**
13342 * Unregister to stop receiving incoming datagrams over satellite.
13343 *
Sarah Chindf715ec2023-02-13 13:46:24 -080013344 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
13345 * @param callback The callback that was passed to
13346 * {@link #registerForSatelliteDatagram(int, int, ISatelliteStateListener)}.
13347 *
13348 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013349 *
13350 * @throws SecurityException if the caller doesn't have the required permission.
13351 */
13352 @Override
Sarah Chindf715ec2023-02-13 13:46:24 -080013353 @SatelliteManager.SatelliteError public int unregisterForSatelliteDatagram(int subId,
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013354 @NonNull ISatelliteStateListener callback) {
13355 enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram");
13356
13357 final int validSubId = getValidSatelliteSubId(subId);
13358 SatelliteDatagramListenerHandler satelliteDatagramListenerHandler =
13359 mSatelliteDatagramListenerHandlers.get(validSubId);
13360 if (satelliteDatagramListenerHandler != null) {
13361 if (satelliteDatagramListenerHandler.removeListener(callback)) {
13362 return SatelliteManager.SATELLITE_ERROR_NONE;
13363 }
13364 }
13365 return SatelliteManager.SATELLITE_INVALID_ARGUMENTS;
13366 }
13367
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013368 /**
13369 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013370 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013371 * This method requests modem to check if there are any pending datagrams to be received over
13372 * satellite. If there are any incoming datagrams, they will be received via
13373 * {@link SatelliteCallback.SatelliteDatagramListener#onSatelliteDatagrams(SatelliteDatagram[])}
Sarah Chindf715ec2023-02-13 13:46:24 -080013374 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013375 * @param subId The subId of the subscription used for receiving datagrams.
13376 * @param callback The callback to get {@link SatelliteManager.SatelliteError} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080013377 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013378 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013379 */
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013380 @Override
13381 public void pollPendingSatelliteDatagrams(int subId, IIntegerConsumer callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013382 enforceSatelliteCommunicationPermission("pollPendingSatelliteDatagrams");
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013383 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013384
13385 final int validSubId = getValidSatelliteSubId(subId);
13386 if (!isSatelliteProvisioned(validSubId)) {
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013387 result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED);
13388 return;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013389 }
13390
13391 Phone phone = getPhoneOrDefault(validSubId, "pollPendingSatelliteDatagrams");
13392 if (phone == null) {
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013393 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
13394 return;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013395 }
13396
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013397 sendRequestAsync(CMD_POLL_PENDING_SATELLITE_DATAGRAMS, result, phone, null);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013398 }
13399
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013400 /**
13401 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080013402 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013403 * Gateway encodes SOS SMS or location sharing message into a datagram and passes it as input to
13404 * this method. Datagram received here will be passed down to modem without any encoding or
13405 * encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080013406 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000013407 * @param subId The subId of the subscription to send satellite datagrams for.
13408 * @param datagramType datagram type indicating whether the datagram is of type
13409 * SOS_SMS or LOCATION_SHARING.
13410 * @param datagram encoded gateway datagram which is encrypted by the caller.
13411 * Datagram will be passed down to modem without any encoding or encryption.
13412 * @param callback The callback to get {@link SatelliteManager.SatelliteError} of the request.
13413 *
13414 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013415 */
13416 @Override
13417 public void sendSatelliteDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
13418 SatelliteDatagram datagram, IIntegerConsumer callback) {
13419 enforceSatelliteCommunicationPermission("sendSatelliteDatagram");
13420 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept);
13421
13422 final int validSubId = getValidSatelliteSubId(subId);
13423 if (!isSatelliteProvisioned(validSubId)) {
13424 result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED);
13425 return;
13426 }
13427
13428 Phone phone = getPhoneOrDefault(validSubId, "sendSatelliteDatagram");
13429 if (phone == null) {
13430 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
13431 return;
13432 }
13433
13434 // check if we need to start PointingUI.
13435
13436 sendRequestAsync(CMD_SEND_SATELLITE_DATAGRAM,
13437 new SendSatelliteDatagramArgument(datagramType, datagram, result),
13438 phone, null);
13439 }
13440
Sarah Chindf715ec2023-02-13 13:46:24 -080013441 /**
13442 * Request to get whether satellite communication is allowed for the current location.
13443 *
13444 * @param subId The subId of the subscription to check whether satellite communication is
13445 * allowed for the current location for.
13446 * @param result The result receiver that returns whether satellite communication is allowed
13447 * for the current location if the request is successful or an error code
13448 * if the request failed.
13449 *
13450 * @throws SecurityException if the caller doesn't have the required permission.
13451 */
13452 @Override
13453 public void requestIsSatelliteCommunicationAllowedForCurrentLocation(int subId,
13454 @NonNull ResultReceiver result) {
13455 enforceSatelliteCommunicationPermission(
13456 "requestIsSatelliteCommunicationAllowedForCurrentLocation");
13457 if (!isSatelliteSupported()) {
13458 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
13459 return;
13460 }
13461
13462 final int validSubId = getValidSatelliteSubId(subId);
13463 if (!isSatelliteProvisioned(validSubId)) {
13464 result.send(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED, null);
13465 return;
13466 }
13467
13468 Phone phone = getPhoneOrDefault(validSubId,
13469 "requestIsSatelliteCommunicationAllowedForCurrentLocation");
13470 if (phone == null) {
13471 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
13472 return;
13473 }
13474
13475 sendRequest(CMD_IS_SATELLITE_COMMUNICATION_ALLOWED, result, subId);
13476 }
13477
13478 /**
Sarah Chin5f57c582023-02-14 04:16:10 -080013479 * Request to get the time after which the satellite will be visible
Sarah Chindf715ec2023-02-13 13:46:24 -080013480 *
Sarah Chin5f57c582023-02-14 04:16:10 -080013481 * @param subId The subId to get the time after which the satellite will be visible for.
13482 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080013483 * be visible if the request is successful or an error code if the request failed.
13484 *
13485 * @throws SecurityException if the caller doesn't have the required permission.
13486 */
13487 @Override
13488 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
13489 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
13490 if (!isSatelliteSupported()) {
13491 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
13492 return;
13493 }
13494
13495 final int validSubId = getValidSatelliteSubId(subId);
13496 if (!isSatelliteProvisioned(validSubId)) {
13497 result.send(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED, null);
13498 return;
13499 }
13500
13501 Phone phone = getPhoneOrDefault(validSubId, "requestTimeForNextSatelliteVisibility");
13502 if (phone == null) {
13503 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
13504 return;
13505 }
13506
13507 sendRequestAsync(CMD_GET_TIME_SATELLITE_NEXT_VISIBLE, result, phone, null);
13508 }
13509
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013510 private void handleEventProvisionSatelliteServiceDone(
13511 @NonNull ProvisionSatelliteServiceArgument arg,
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013512 @SatelliteManager.SatelliteError int result) {
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013513 log("handleEventProvisionSatelliteServiceDone: result="
13514 + result + ", subId=" + arg.subId);
13515
13516 Consumer<Integer> callback = mSatelliteProvisionCallbacks.remove(arg.subId);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013517 if (callback == null) {
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013518 loge("handleEventProvisionSatelliteServiceDone: callback is null for subId="
13519 + arg.subId);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013520 return;
13521 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013522 callback.accept(result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013523
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013524 if (result == SatelliteManager.SATELLITE_ERROR_NONE) {
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013525 setSatelliteProvisioned(arg.subId, true);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013526 }
13527
13528 /**
13529 * We need to update satellite provision status in SubscriptionController
13530 * or SatelliteController.
13531 * TODO (b/267826133) we need to do this for all subscriptions on the device.
13532 */
Sarah Chindf715ec2023-02-13 13:46:24 -080013533 registerForSatelliteProvisionStateChangedInternal(arg.subId, null);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013534 }
13535
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013536 private void handleEventDeprovisionSatelliteServiceDone(
13537 @NonNull ProvisionSatelliteServiceArgument arg,
13538 @SatelliteManager.SatelliteError int result) {
13539 if (arg == null) {
13540 loge("handleEventDeprovisionSatelliteServiceDone: arg is null");
13541 return;
13542 }
13543 log("handleEventDeprovisionSatelliteServiceDone: result="
13544 + result + ", subId=" + arg.subId);
13545
13546 if (arg.callback != null) {
13547 arg.callback.accept(result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013548 }
13549
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013550 if (result == SatelliteManager.SATELLITE_ERROR_NONE) {
13551 setSatelliteProvisioned(arg.subId, false);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013552 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013553 }
13554
13555 private Phone getPhoneOrDefault(int subId, String caller) {
13556 Phone phone = getPhone(subId);
13557 if (phone == null) {
13558 loge(caller + " called with invalid subId: " + subId
13559 + ". Retrying with default phone.");
13560 phone = getDefaultPhone();
13561 if (phone == null) {
13562 loge(caller + " failed with no phone object.");
13563 }
13564 }
13565 return phone;
13566 }
13567
13568 /**
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013569 * Check if satellite is provisioned for a subscription or the device.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013570 *
13571 * Note: this is the version without permission check for telephony internal use only. The
13572 * caller need to take care of the permission check.
13573 */
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013574 private boolean isSatelliteProvisioned(int subId) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013575 if (subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
13576 if (mSubscriptionController == null) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013577 loge("isSatelliteProvisioned mSubscriptionController is null");
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013578 return false;
13579 }
13580
13581 String strResult = mSubscriptionController.getSubscriptionProperty(
13582 subId, SubscriptionManager.SATELLITE_ENABLED);
13583 if (strResult != null) {
13584 int intResult = Integer.parseInt(strResult);
13585 return (intResult == 1) ? true : false;
13586 }
13587 } else {
13588 //TODO (b/267826133): check via SatelliteController
13589 }
13590 return false;
13591 }
13592
13593 /**
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013594 * Set satellite provisioned for a subscription or the device.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013595 *
13596 * The permission {@link android.Manifest.permission#MODIFY_PHONE_STATE} will be enforced by
13597 * {@link SubscriptionController} when setting satellite enabled for an active subscription.
13598 * Otherwise, {@link android.Manifest.permission#SATELLITE_COMMUNICATION} will be enforced.
13599 */
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013600 private synchronized void setSatelliteProvisioned(int subId, boolean isEnabled) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013601 if (subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
13602 if (mSubscriptionController == null) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013603 loge("setSatelliteProvisioned mSubscriptionController is null");
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013604 return;
13605 }
13606 mSubscriptionController.setSubscriptionProperty(
13607 subId, SubscriptionManager.SATELLITE_ENABLED, isEnabled ? "1" : "0");
13608 } else {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013609 //TODO (b/267826133): set via SatelliteController
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013610 }
13611 }
13612
13613 private int getValidSatelliteSubId(int subId) {
13614 if (mSubscriptionController == null) {
13615 loge("getValidSatelliteSubId mSubscriptionController is null. "
13616 + "Use DEFAULT_SUBSCRIPTION_ID for subId=" + subId);
13617 return SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
13618 }
13619 final long identity = Binder.clearCallingIdentity();
13620 try {
13621 Context context = getDefaultPhone().getContext();
13622 if (mSubscriptionController.isActiveSubId(
13623 subId, context.getOpPackageName(), context.getAttributionTag())) {
13624 return subId;
13625 }
13626 } finally {
13627 Binder.restoreCallingIdentity(identity);
13628 }
13629 if (DBG) log("getValidSatelliteSubId: use DEFAULT_SUBSCRIPTION_ID for subId=" + subId);
13630 return SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
13631 }
13632
13633 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013634 * If we have not successfully queried the satellite modem for its satellite service support,
13635 * we will retry the query one more time. Otherwise, we will return the queried result.
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013636 */
13637 private boolean isSatelliteSupported() {
13638 synchronized (mIsSatelliteSupportedLock) {
13639 if (mIsSatelliteSupported != null) {
13640 /* We have already successfully queried the satellite modem. */
13641 return mIsSatelliteSupported;
13642 }
13643 }
13644 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013645 * We have not successfully checked whether the modem supports satellite service.
13646 * Thus, we need to retry it now.
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013647 */
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013648 requestIsSatelliteSupported(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
13649 mSatelliteSupportedReceiver);
13650 return false;
13651 }
13652
13653 /**
13654 * Get the {@link SatelliteManager.SatelliteError} from the provided result.
Sarah Chindf715ec2023-02-13 13:46:24 -080013655 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013656 * @param ar AsyncResult used to determine the error code.
13657 * @param caller The satellite request.
13658 * @param checkResult Whether to check if the result exists.
Sarah Chindf715ec2023-02-13 13:46:24 -080013659 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013660 * @return The {@link SatelliteManager.SatelliteError} error code from the request.
13661 */
13662 @SatelliteManager.SatelliteError private int getSatelliteError(@NonNull AsyncResult ar,
13663 @NonNull String caller, boolean checkResult) {
13664 int errorCode;
13665 if (ar.exception == null) {
13666 errorCode = SatelliteManager.SATELLITE_ERROR_NONE;
13667 if (checkResult && ar.result == null) {
13668 loge(caller + ": result is null");
13669 errorCode = SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE;
13670 }
13671 } else {
13672 errorCode = SatelliteManager.SATELLITE_ERROR;
13673 if (ar.exception instanceof CommandException) {
Sarah Chin4beb2b72023-02-14 14:47:54 -080013674 CommandException.Error error = ((CommandException) ar.exception).getCommandError();
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013675 errorCode = RILUtils.convertToSatelliteError(error);
13676 loge(caller + " CommandException: " + ar.exception);
Sarah Chin4beb2b72023-02-14 14:47:54 -080013677 } else if (ar.exception instanceof SatelliteManager.SatelliteException) {
13678 errorCode = ((SatelliteManager.SatelliteException) ar.exception).getErrorCode();
13679 loge(caller + " SatelliteException: " + ar.exception);
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013680 } else {
13681 loge(caller + " unknown exception: " + ar.exception);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013682 }
13683 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013684 log(caller + " error: " + errorCode);
13685 return errorCode;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013686 }
13687
13688 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013689 * Register for the satellite provision state change.
13690 *
13691 * @param subId The subId of the subscription associated with the satellite service.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013692 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080013693 *
13694 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013695 */
Sarah Chindf715ec2023-02-13 13:46:24 -080013696 @SatelliteManager.SatelliteError private int registerForSatelliteProvisionStateChangedInternal(
13697 int subId, @Nullable ISatelliteStateListener callback) {
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013698 if (!isSatelliteSupported()) {
Sarah Chindf715ec2023-02-13 13:46:24 -080013699 return SatelliteManager.SATELLITE_NOT_SUPPORTED;
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013700 }
13701
13702 final int validSubId = getValidSatelliteSubId(subId);
13703 Phone phone = getPhoneOrDefault(validSubId, "registerForSatelliteProvisionStateChanged");
13704 if (phone == null) {
Sarah Chindf715ec2023-02-13 13:46:24 -080013705 return SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE;
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013706 }
13707
13708 SatelliteProvisionStateChangedHandler satelliteProvisionStateChangedHandler =
13709 mSatelliteProvisionStateChangedHandlers.get(validSubId);
13710 if (satelliteProvisionStateChangedHandler == null) {
13711 satelliteProvisionStateChangedHandler = new SatelliteProvisionStateChangedHandler(
13712 Looper.getMainLooper(), validSubId);
13713 phone.registerForSatelliteProvisionStateChanged(satelliteProvisionStateChangedHandler,
13714 SatelliteProvisionStateChangedHandler.EVENT_PROVISION_STATE_CHANGED, null);
13715 }
13716
13717 if (callback != null) {
13718 satelliteProvisionStateChangedHandler.addListener(callback);
13719 }
13720 mSatelliteProvisionStateChangedHandlers.put(
13721 validSubId, satelliteProvisionStateChangedHandler);
Sarah Chindf715ec2023-02-13 13:46:24 -080013722 return SatelliteManager.SATELLITE_ERROR_NONE;
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013723 }
13724
13725 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000013726 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
13727 *
13728 * <p>This method behaves in one of the following ways:
13729 * <ul>
13730 * <li>return true : if the calling package has the appop permission {@link
13731 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
13732 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
13733 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
13734 * Owner device identifier access check, or the calling package has carrier privileges</>
13735 * <li>throw SecurityException: if the caller does not meet any of the requirements.
13736 * </ul>
13737 */
13738 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
13739 String callingPackage, @Nullable String callingFeatureId, String message) {
13740 for (Phone phone : PhoneFactory.getPhones()) {
13741 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
13742 phone.getSubId(), callingPackage, callingFeatureId, message)) {
13743 return true;
13744 }
13745 }
13746 return false;
13747 }
arunvoddud7401012022-12-15 16:08:12 +000013748
13749 /**
Jack Yufa8ed012023-02-11 15:42:28 -080013750 * @return The subscription manager service instance.
13751 */
13752 public SubscriptionManagerService getSubscriptionManagerService() {
13753 return SubscriptionManagerService.getInstance();
13754 }
13755
13756 /**
arunvoddud7401012022-12-15 16:08:12 +000013757 * Class binds the consumer[callback] and carrierId.
13758 */
13759 private static class CallerCallbackInfo {
13760 private final Consumer<Integer> mConsumer;
13761 private final int mCarrierId;
13762
13763 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
13764 mConsumer = consumer;
13765 mCarrierId = carrierId;
13766 }
13767
13768 public Consumer<Integer> getConsumer() {
13769 return mConsumer;
13770 }
13771
13772 public int getCarrierId() {
13773 return mCarrierId;
13774 }
13775 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013776
13777 private static SatelliteDatagram[] convertToSatelliteDatagramArray(byte[][] datagrams) {
13778 // Convert 2D byte array into SatelliteDatagramArray.
13779 SatelliteDatagram[] satelliteDatagramArray =
13780 new SatelliteDatagram[datagrams.length];
13781 for (int i = 0; i < datagrams.length; i++) {
13782 satelliteDatagramArray[i] = new SatelliteDatagram(datagrams[i]);
13783 }
13784 return satelliteDatagramArray;
13785 }
Jack Yufa8ed012023-02-11 15:42:28 -080013786}