blob: cf1f784c3a808536eefeecf14b540f68c76dab59 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
Gil Cukierman1c0eb932022-12-06 22:28:24 +000020import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK;
jimsunf9ec1622022-09-13 21:18:43 +080021import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO;
Hall Liud892bec2018-11-30 14:51:45 -080022
Shuo Qianccbaf742021-02-22 18:32:21 -080023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
24import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070025import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070026import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000027import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070028
Brad Ebinger34c09a52021-02-17 23:23:21 +000029import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080030import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080031import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070032import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000033import android.annotation.RequiresPermission;
Sarah Chin532d6bb2022-12-28 22:50:43 -080034import android.app.ActivityManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080036import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070037import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000038import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080039import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000040import android.compat.annotation.ChangeId;
41import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070042import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070043import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.content.Context;
45import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070046import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070047import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070048import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049import android.net.Uri;
50import android.os.AsyncResult;
51import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080052import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.os.Bundle;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080054import android.os.CancellationSignal;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070056import android.os.IBinder;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080057import android.os.ICancellationSignal;
tom hsu0b59d292022-09-29 23:49:21 +080058import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070059import android.os.Looper;
60import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070061import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080062import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070063import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070064import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080065import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080066import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070067import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070068import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080069import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070070import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070071import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070072import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070073import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070074import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080075import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070076import android.provider.Telephony;
arunvoddud7401012022-12-15 16:08:12 +000077import android.service.carrier.CarrierIdentifier;
Inseob Kim14bb3d02018-12-13 17:11:34 +090078import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080079import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080080import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070081import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080082import android.telephony.AccessNetworkConstants;
83import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070084import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070085import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080086import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070087import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080088import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070089import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080090import android.telephony.CarrierRestrictionRules;
Hui Wang9b5793a2022-12-05 14:38:06 -060091import android.telephony.CellBroadcastIdRange;
yincheng zhao2737e882019-09-06 17:06:54 -070092import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080093import android.telephony.CellIdentityCdma;
94import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070096import android.telephony.CellInfoGsm;
97import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070098import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080099import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -0700100import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700101import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700102import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -0800103import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700104import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -0800105import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -0700106import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800107import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800108import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700109import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800110import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700111import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800112import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800113import android.telephony.SignalStrengthUpdateRequest;
114import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800115import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800116import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800117import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700118import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700119import android.telephony.TelephonyManager;
Jack Yuf5badd92022-12-08 00:50:53 -0800120import android.telephony.TelephonyManager.SimState;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800121import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800122import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800123import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000124import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000125import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000126import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700127import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700128import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800129import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800130import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700131import android.telephony.gba.GbaAuthRequest;
132import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700133import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800134import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000135import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000136import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700137import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000138import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700139import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800140import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700141import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800142import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700143import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000144import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700145import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800146import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800147import android.telephony.ims.stub.ImsRegistrationImplBase;
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800148import android.telephony.satellite.ISatelliteStateListener;
Sarah Chineccfbd12023-01-20 19:00:35 -0800149import android.telephony.satellite.PointingInfo;
Sarah Chin503828c2023-02-01 23:54:20 -0800150import android.telephony.satellite.SatelliteCapabilities;
Sarah Chineccfbd12023-01-20 19:00:35 -0800151import android.telephony.satellite.SatelliteManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700152import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800153import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700154import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700155import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800156import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800157
Andrew Lee312e8172014-10-23 17:01:36 -0700158import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800159import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800160import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800161import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800162import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700163import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700164import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700165import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800166import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800167import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700168import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700169import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800170import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700171import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800172import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800173import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800174import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700175import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000176import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700177import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800178import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700179import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800180import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800181import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800182import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700183import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700184import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700185import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700186import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700187import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800188import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700189import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700190import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700191import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700192import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800193import com.android.internal.telephony.RILConstants;
Sarah Chineccfbd12023-01-20 19:00:35 -0800194import com.android.internal.telephony.RILUtils;
Daniel Bright94f43662021-03-01 14:43:40 -0800195import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700196import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000197import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700198import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700199import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800200import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800201import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800202import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700203import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000204import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800205import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700206import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800207import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700208import com.android.internal.telephony.imsphone.ImsPhone;
209import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000210import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800211import com.android.internal.telephony.metrics.TelephonyMetrics;
Jack Yu285100e2022-12-02 22:48:35 -0800212import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
213import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700214import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700215import com.android.internal.telephony.uicc.IccIoResult;
216import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800217import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700218import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800219import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700220import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000221import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800222import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000223import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800224import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000225import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700226import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700227import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800228import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800229import com.android.phone.callcomposer.CallComposerPictureManager;
230import com.android.phone.callcomposer.CallComposerPictureTransfer;
231import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700232import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700233import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000234import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700235import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800236import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700237import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700238import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800239import com.android.services.telephony.TelecomAccountRegistry;
240import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800241import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800242
Hall Liu82694d52020-12-11 18:22:04 -0800243import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700244import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800245import java.io.IOException;
246import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700247import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700248import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800249import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000250import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800251import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800252import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800253import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800254import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100255import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800256import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700257import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800258import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800259import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700260import java.util.UUID;
Sarah Chineccfbd12023-01-20 19:00:35 -0800261import java.util.concurrent.ConcurrentHashMap;
Hall Liu82694d52020-12-11 18:22:04 -0800262import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800263import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800264import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700265
266/**
267 * Implementation of the ITelephony interface.
268 */
Santos Cordon117fee72014-05-16 17:56:12 -0700269public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700270 private static final String LOG_TAG = "PhoneInterfaceManager";
271 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
272 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800273 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700274
275 // Message codes used with mMainThreadHandler
276 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700277 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
278 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700279 private static final int CMD_OPEN_CHANNEL = 9;
280 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
281 private static final int CMD_CLOSE_CHANNEL = 11;
282 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800283 private static final int CMD_NV_READ_ITEM = 13;
284 private static final int EVENT_NV_READ_ITEM_DONE = 14;
285 private static final int CMD_NV_WRITE_ITEM = 15;
286 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
287 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
288 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700289 private static final int CMD_RESET_MODEM_CONFIG = 19;
290 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800291 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
292 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800293 private static final int CMD_SEND_ENVELOPE = 25;
294 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000295 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
296 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700297 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
298 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
299 private static final int CMD_EXCHANGE_SIM_IO = 31;
300 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800301 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
302 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700303 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
304 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700305 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
306 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700307 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
308 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
309 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
310 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700311 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
312 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
313 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
314 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700315 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800316 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
317 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000318 private static final int CMD_SWITCH_SLOTS = 50;
319 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700320 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
321 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
322 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
323 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
324 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
325 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
326 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
327 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700328 private static final int CMD_GET_ALL_CELL_INFO = 60;
329 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
330 private static final int CMD_GET_CELL_LOCATION = 62;
331 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700332 private static final int CMD_MODEM_REBOOT = 64;
333 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700334 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
335 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800336 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
337 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700338 private static final int CMD_GET_MODEM_STATUS = 70;
339 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700340 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
341 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700342 private static final int CMD_ERASE_MODEM_CONFIG = 74;
343 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800344 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
345 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
346 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
347 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800348 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
349 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800350 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800351 private static final int CMD_GET_CALL_FORWARDING = 83;
352 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
353 private static final int CMD_SET_CALL_FORWARDING = 85;
354 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
355 private static final int CMD_GET_CALL_WAITING = 87;
356 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
357 private static final int CMD_SET_CALL_WAITING = 89;
358 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700359 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
360 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
361 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
362 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700363 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
364 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800365 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
366 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800367 private static final int CMD_SET_DATA_THROTTLING = 99;
368 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800369 private static final int CMD_SET_SIM_POWER = 101;
370 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800371 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
372 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
373 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
374 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800375 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
376 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000377 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800378 private static final int CMD_GET_SLICING_CONFIG = 110;
379 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800380 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700381 private static final int CMD_ENABLE_VONR = 113;
382 private static final int EVENT_ENABLE_VONR_DONE = 114;
383 private static final int CMD_IS_VONR_ENABLED = 115;
384 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700385 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
386 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Sarah Chineccfbd12023-01-20 19:00:35 -0800387 private static final int CMD_START_SATELLITE_POSITION_UPDATES = 119;
388 private static final int EVENT_START_SATELLITE_POSITION_UPDATES_DONE = 120;
389 private static final int CMD_STOP_SATELLITE_POSITION_UPDATES = 121;
390 private static final int EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE = 122;
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +0000391 private static final int CMD_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG = 123;
392 private static final int EVENT_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG_DONE = 124;
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800393 private static final int CMD_PROVISION_SATELLITE_SERVICE = 125;
394 private static final int EVENT_PROVISION_SATELLITE_SERVICE_DONE = 126;
395 private static final int CMD_CANCEL_PROVISION_SATELLITE_SERVICE = 127;
396 private static final int EVENT_CANCEL_PROVISION_SATELLITE_SERVICE_DONE = 128;
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800397 private static final int CMD_SET_SATELLITE_ENABLED = 129;
398 private static final int EVENT_SET_SATELLITE_ENABLED_DONE = 130;
399 private static final int CMD_IS_SATELLITE_ENABLED = 131;
400 private static final int EVENT_IS_SATELLITE_ENABLED_DONE = 132;
401 private static final int CMD_IS_SATELLITE_SUPPORTED = 133;
402 private static final int EVENT_IS_SATELLITE_SUPPORTED_DONE = 134;
403 private static final int CMD_GET_SATELLITE_CAPABILITIES = 135;
404 private static final int EVENT_GET_SATELLITE_CAPABILITIES_DONE = 136;
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800405 // Parameters of select command.
406 private static final int SELECT_COMMAND = 0xA4;
407 private static final int SELECT_P1 = 0x04;
408 private static final int SELECT_P2 = 0;
409 private static final int SELECT_P3 = 0x10;
410
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000411 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
412 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
413
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700414 /** The singleton instance. */
415 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800416 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700417
Wink Saville3ab207e2014-11-20 13:07:20 -0800418 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800419 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800420 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700421 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800422 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700423 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800424 private MainThreadHandler mMainThreadHandler;
Jack Yue37dd262022-12-16 11:53:37 -0800425 private final SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800426 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700427 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800428 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700429
Peter Wangdafb9ac2020-01-15 14:13:38 -0800430 /** User Activity */
431 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800432 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
433
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700434 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800435
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800436 /**
437 * Map key: subId, value: callback to get error code of the provision request.
438 */
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800439 private final ConcurrentHashMap<Integer, Consumer<Integer>> mSatelliteProvisionCallbacks =
Sarah Chineccfbd12023-01-20 19:00:35 -0800440 new ConcurrentHashMap<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800441 /**
442 * Map key: subId, value: SatellitePositionUpdateHandler to notify registrants.
443 */
444 private final ConcurrentHashMap<IBinder, SatellitePositionUpdateHandler>
445 mSatellitePositionUpdateHandlers = new ConcurrentHashMap<>();
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800446 /**
447 * Map key: subId, value: SatelliteProvisionStateChangedHandler to notify registrants.
448 */
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800449 private final ConcurrentHashMap<Integer, SatelliteProvisionStateChangedHandler>
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800450 mSatelliteProvisionStateChangedHandlers = new ConcurrentHashMap<>();
451
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800452 private Boolean mIsSatelliteSupported = null;
453 private final Object mIsSatelliteSupportedLock = new Object();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800454 private final ResultReceiver mSatelliteSupportedReceiver;
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800455
Derek Tan97ebb422014-09-05 16:55:38 -0700456 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
457 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800458 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800459 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700460
Michelecea4cf22018-12-21 15:00:11 -0800461 // String to store multi SIM allowed
462 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
463
Derek Tan740e1672017-06-27 14:56:27 -0700464 // The AID of ISD-R.
465 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
466
yinxub1bed742017-04-17 11:45:04 -0700467 private NetworkScanRequestTracker mNetworkScanRequestTracker;
468
David Kelly5e06a7f2018-03-12 14:10:59 +0000469 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
470 private static final int MANUFACTURER_CODE_LENGTH = 8;
471
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800472 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800473 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800474
Sarah Chin2ec39f62022-08-31 17:03:26 -0700475 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
476 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
477
Derek Tan89e89d42014-07-08 17:00:10 -0700478 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700479 * Experiment flag to enable erase modem config on reset network, default value is false
480 */
481 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
482 "reset_network_erase_modem_config_enabled";
483
Rambo Wang0f050d82021-02-12 11:43:36 -0800484 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800485
Gary Jian76280a42022-12-07 16:18:33 +0800486 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
487
sandeepjsb6c87872021-09-27 15:34:44 +0000488 /**
489 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
490 * one ICCID active at the same time.
491 * Apps should use below API signatures if targeting SDK is T and beyond.
492 *
493 * @hide
494 */
495 @ChangeId
496 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
497 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800498
Naina Nallurid63128d2019-09-17 14:10:30 -0700499 /**
Chen Xu540470b2021-12-14 17:15:47 -0800500 * Apps targeting on Android T and beyond will get exception whenever icc close channel
501 * operation fails.
502 */
503 @ChangeId
504 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
505 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
506
507 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700508 * A request object to use for transmitting data to an ICC.
509 */
510 private static final class IccAPDUArgument {
511 public int channel, cla, command, p1, p2, p3;
512 public String data;
513
514 public IccAPDUArgument(int channel, int cla, int command,
515 int p1, int p2, int p3, String data) {
516 this.channel = channel;
517 this.cla = cla;
518 this.command = command;
519 this.p1 = p1;
520 this.p2 = p2;
521 this.p3 = p3;
522 this.data = data;
523 }
524 }
525
526 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700527 * A request object to use for transmitting data to an ICC.
528 */
529 private static final class ManualNetworkSelectionArgument {
530 public OperatorInfo operatorInfo;
531 public boolean persistSelection;
532
533 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
534 this.operatorInfo = operatorInfo;
535 this.persistSelection = persistSelection;
536 }
537 }
538
Sarah Chin71b3a852022-09-28 15:54:19 -0700539 private static final class PurchasePremiumCapabilityArgument {
540 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700541 public @NonNull IIntegerConsumer callback;
542
543 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800544 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700545 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700546 this.callback = callback;
547 }
548 }
549
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800550 private static final class ProvisionSatelliteServiceArgument {
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800551 public @NonNull String token;
552 public @NonNull Consumer<Integer> callback;
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800553 public int subId;
554
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800555 ProvisionSatelliteServiceArgument(String token, Consumer<Integer> callback, int subId) {
556 this.token = token;
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800557 this.callback = callback;
558 this.subId = subId;
559 }
560 }
561
Sarah Chineccfbd12023-01-20 19:00:35 -0800562 private static final class SatellitePositionUpdateHandler extends Handler {
563 public static final int EVENT_POSITION_UPDATE = 1;
564 public static final int EVENT_MESSAGE_TRANSFER_STATE_UPDATE = 2;
565
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800566 private final ISatelliteStateListener mCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800567
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800568 SatellitePositionUpdateHandler(ISatelliteStateListener callback, Looper looper) {
Sarah Chineccfbd12023-01-20 19:00:35 -0800569 super(looper);
570 mCallback = callback;
571 }
572
573 @Override
574 public void handleMessage(@NonNull Message msg) {
575 switch (msg.what) {
576 case EVENT_POSITION_UPDATE: {
577 AsyncResult ar = (AsyncResult) msg.obj;
578 PointingInfo pointingInfo = (PointingInfo) ar.result;
579 try {
580 mCallback.onSatellitePositionUpdate(pointingInfo);
581 } catch (RemoteException e) {
582 loge("EVENT_POSITION_UPDATE RemoteException: " + e);
583 }
584 break;
585 }
586 case EVENT_MESSAGE_TRANSFER_STATE_UPDATE: {
587 AsyncResult ar = (AsyncResult) msg.obj;
588 int state = (int) ar.result;
589 try {
590 mCallback.onMessageTransferStateUpdate(state);
591 } catch (RemoteException e) {
592 loge("EVENT_MESSAGE_TRANSFER_STATE_UPDATE RemoteException: " + e);
593 }
594 break;
595 }
596 default:
597 loge("SatellitePositionUpdateHandler unknown event: " + msg.what);
598 }
599 }
600 }
601
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800602 private static final class SatelliteProvisionStateChangedHandler extends Handler {
603 public static final int EVENT_PROVISION_STATE_CHANGED = 1;
604
605 private ConcurrentHashMap<IBinder, ISatelliteStateListener> mListeners;
606 private final int mSubId;
607
608 SatelliteProvisionStateChangedHandler(Looper looper, int subId) {
609 super(looper);
610 mListeners = new ConcurrentHashMap<>();
611 mSubId = subId;
612 }
613
614 public void addListener(ISatelliteStateListener listener) {
615 mListeners.put(listener.asBinder(), listener);
616 }
617
618 public boolean removeListener(ISatelliteStateListener listener) {
619 return (mListeners.remove(listener.asBinder()) != null);
620 }
621
622 @Override
623 public void handleMessage(@NonNull Message msg) {
624 switch (msg.what) {
625 case EVENT_PROVISION_STATE_CHANGED: {
626 AsyncResult ar = (AsyncResult) msg.obj;
627 boolean provisioned = (boolean) ar.userObj;
628 int[] features = (int[]) ar.result;
629 log("Received EVENT_PROVISION_STATE_CHANGED for subId=" + mSubId
630 + ", features=" + Arrays.toString(features)
631 + ", provisioned=" + provisioned);
632 mListeners.values().forEach(listener -> {
633 try {
634 listener.onSatelliteProvisionStateChanged(features, provisioned);
635 } catch (RemoteException e) {
636 log("EVENT_PROVISION_STATE_CHANGED RemoteException: " + e);
637 }
638 });
639
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800640 setSatelliteProvisioned(provisioned);
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800641 /**
642 * TODO: Take bugreport if provisioned is true and user did not initiate the
643 * provision procedure for the corresponding subscription.
644 */
645 break;
646 }
647 default:
648 loge("SatelliteProvisionStateChangedHandler unknown event: " + msg.what);
649 }
650 }
651
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800652 private void setSatelliteProvisioned(boolean isProvisioned) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800653 if (mSubId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
654 SubscriptionManager.setSubscriptionProperty(
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800655 mSubId, SubscriptionManager.SATELLITE_ENABLED, isProvisioned ? "1" : "0");
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800656 } else {
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800657 //TODO (b/267826133): set via SatelliteController.
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800658 }
659 }
660 }
661
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700662 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700663 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
664 * request after sending. The main thread will notify the request when it is complete.
665 */
666 private static final class MainThreadRequest {
667 /** The argument to use for the request */
668 public Object argument;
669 /** The result of the request that is run on the main thread */
670 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800671 // The subscriber id that this request applies to. Defaults to
672 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
673 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700674
Nathan Harold92bed182018-10-12 18:16:49 -0700675 // In cases where subId is unavailable, the caller needs to specify the phone.
676 public Phone phone;
677
vagdeviaf9a5b92018-08-15 16:01:53 -0700678 public WorkSource workSource;
679
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700680 public MainThreadRequest(Object argument) {
681 this.argument = argument;
682 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800683
Nathan Harold92bed182018-10-12 18:16:49 -0700684 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
685 this.argument = argument;
686 if (phone != null) {
687 this.phone = phone;
688 }
689 this.workSource = workSource;
690 }
691
vagdeviaf9a5b92018-08-15 16:01:53 -0700692 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800693 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800694 if (subId != null) {
695 this.subId = subId;
696 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700697 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800698 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700699 }
700
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800701 private static final class IncomingThirdPartyCallArgs {
702 public final ComponentName component;
703 public final String callId;
704 public final String callerDisplayName;
705
706 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
707 String callerDisplayName) {
708 this.component = component;
709 this.callId = callId;
710 this.callerDisplayName = callerDisplayName;
711 }
712 }
713
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700714 /**
715 * A handler that processes messages on the main thread in the phone process. Since many
716 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
717 * inbound binder threads to the main thread in the phone process. The Binder thread
718 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
719 * on, which will be notified when the operation completes and will contain the result of the
720 * request.
721 *
722 * <p>If a MainThreadRequest object is provided in the msg.obj field,
723 * note that request.result must be set to something non-null for the calling thread to
724 * unblock.
725 */
726 private final class MainThreadHandler extends Handler {
727 @Override
728 public void handleMessage(Message msg) {
729 MainThreadRequest request;
730 Message onCompleted;
731 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000732 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700733 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800734 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700735
736 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700737 case CMD_HANDLE_USSD_REQUEST: {
738 request = (MainThreadRequest) msg.obj;
739 final Phone phone = getPhoneFromRequest(request);
740 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800741 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700742 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700743
Pengquan Menga1bb6272018-09-06 09:59:22 -0700744 if (!isUssdApiAllowed(request.subId)) {
745 // Carrier does not support use of this API, return failure.
746 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
747 UssdResponse response = new UssdResponse(ussdRequest, null);
748 Bundle returnData = new Bundle();
749 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
750 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700751
Pengquan Menga1bb6272018-09-06 09:59:22 -0700752 request.result = true;
753 notifyRequester(request);
754 return;
755 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700756
Pengquan Menga1bb6272018-09-06 09:59:22 -0700757 try {
758 request.result = phone != null
759 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
760 } catch (CallStateException cse) {
761 request.result = false;
762 }
763 // Wake up the requesting thread
764 notifyRequester(request);
765 break;
pkanwar32d516d2016-10-14 19:37:38 -0700766 }
767
Yorke Lee716f67e2015-06-17 15:39:16 -0700768 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700769 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700770 final Phone phone = getPhoneFromRequest(request);
771 request.result = phone != null ?
772 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
773 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700774 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700775 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700776 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700777 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700778
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700779 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700780 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700781 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000782 uiccPort = getUiccPortFromRequest(request);
783 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700784 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800785 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700786 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700787 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700788 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800789 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000790 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800791 iccArgument.channel, iccArgument.cla, iccArgument.command,
792 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
793 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700794 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700795 break;
796
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700797 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700798 ar = (AsyncResult) msg.obj;
799 request = (MainThreadRequest) ar.userObj;
800 if (ar.exception == null && ar.result != null) {
801 request.result = ar.result;
802 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800803 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700804 if (ar.result == null) {
805 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800806 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700807 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800808 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700809 } else {
810 loge("iccTransmitApduLogicalChannel: Unknown exception");
811 }
812 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700813 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700814 break;
815
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700816 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
817 request = (MainThreadRequest) msg.obj;
818 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000819 uiccPort = getUiccPortFromRequest(request);
820 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700821 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800822 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700823 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700824 } else {
825 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800826 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000827 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800828 iccArgument.cla, iccArgument.command, iccArgument.p1,
829 iccArgument.p2,
830 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700831 }
832 break;
833
834 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
835 ar = (AsyncResult) msg.obj;
836 request = (MainThreadRequest) ar.userObj;
837 if (ar.exception == null && ar.result != null) {
838 request.result = ar.result;
839 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800840 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700841 if (ar.result == null) {
842 loge("iccTransmitApduBasicChannel: Empty response");
843 } else if (ar.exception instanceof CommandException) {
844 loge("iccTransmitApduBasicChannel: CommandException: " +
845 ar.exception);
846 } else {
847 loge("iccTransmitApduBasicChannel: Unknown exception");
848 }
849 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700850 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700851 break;
852
853 case CMD_EXCHANGE_SIM_IO:
854 request = (MainThreadRequest) msg.obj;
855 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000856 uiccPort = getUiccPortFromRequest(request);
857 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700858 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800859 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700860 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700861 } else {
862 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
863 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000864 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700865 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
866 iccArgument.data, onCompleted);
867 }
868 break;
869
870 case EVENT_EXCHANGE_SIM_IO_DONE:
871 ar = (AsyncResult) msg.obj;
872 request = (MainThreadRequest) ar.userObj;
873 if (ar.exception == null && ar.result != null) {
874 request.result = ar.result;
875 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800876 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700877 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700878 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700879 break;
880
Derek Tan4d5e5c12014-02-04 11:54:58 -0800881 case CMD_SEND_ENVELOPE:
882 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000883 uiccPort = getUiccPortFromRequest(request);
884 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700885 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800886 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700887 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700888 } else {
889 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800890 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700891 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800892 break;
893
894 case EVENT_SEND_ENVELOPE_DONE:
895 ar = (AsyncResult) msg.obj;
896 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700897 if (ar.exception == null && ar.result != null) {
898 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800899 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800900 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700901 if (ar.result == null) {
902 loge("sendEnvelopeWithStatus: Empty response");
903 } else if (ar.exception instanceof CommandException) {
904 loge("sendEnvelopeWithStatus: CommandException: " +
905 ar.exception);
906 } else {
907 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
908 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800909 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700910 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800911 break;
912
Shishir Agrawal566b7612013-10-28 14:41:00 -0700913 case CMD_OPEN_CHANNEL:
914 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000915 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800916 IccLogicalChannelRequest openChannelRequest =
917 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000918 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700919 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800920 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800921 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700922 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700923 } else {
924 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800925 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
926 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700927 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700928 break;
929
930 case EVENT_OPEN_CHANNEL_DONE:
931 ar = (AsyncResult) msg.obj;
932 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700933 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700934 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700935 int[] result = (int[]) ar.result;
936 int channelId = result[0];
937 byte[] selectResponse = null;
938 if (result.length > 1) {
939 selectResponse = new byte[result.length - 1];
940 for (int i = 1; i < result.length; ++i) {
941 selectResponse[i - 1] = (byte) result[i];
942 }
943 }
944 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800945 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800946
947 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700948 if (uiccPort == null) {
949 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
950 } else {
951 IccLogicalChannelRequest channelRequest =
952 (IccLogicalChannelRequest) request.argument;
953 channelRequest.channel = channelId;
954 uiccPort.onLogicalChannelOpened(channelRequest);
955 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700956 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700957 if (ar.result == null) {
958 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700959 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700960 if (ar.exception != null) {
961 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
962 }
963
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700964 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700965 if (ar.exception instanceof CommandException) {
966 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800967 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700968 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700969 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700970 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700971 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700972 }
973 }
974 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800975 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700976 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700977 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700978 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700979 break;
980
981 case CMD_CLOSE_CHANNEL:
982 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000983 uiccPort = getUiccPortFromRequest(request);
984 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700985 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800986 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800987 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800988 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700989 } else {
990 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000991 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700992 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700993 break;
994
995 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800996 ar = (AsyncResult) msg.obj;
997 request = (MainThreadRequest) ar.userObj;
998 if (ar.exception == null) {
999 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -08001000 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -07001001 if (uiccPort == null) {
1002 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
1003 } else {
1004 final int channelId = (Integer) request.argument;
1005 uiccPort.onLogicalChannelClosed(channelId);
1006 }
Chen Xu540470b2021-12-14 17:15:47 -08001007 } else {
1008 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -08001009 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -08001010 if (ar.exception instanceof CommandException) {
1011 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
1012 CommandException.Error error =
1013 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -08001014 if (error == CommandException.Error.INVALID_ARGUMENTS) {
1015 // should only throw exceptions from the binder threads.
1016 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -08001017 "iccCloseLogicalChannel: invalid argument ");
1018 }
1019 } else {
1020 loge("iccCloseLogicalChannel: Unknown exception");
1021 }
Chen Xua8f0dff2022-02-12 00:34:15 -08001022 request.result = (exception != null) ? exception :
1023 new IllegalStateException(
1024 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -08001025 }
1026 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001027 break;
1028
1029 case CMD_NV_READ_ITEM:
1030 request = (MainThreadRequest) msg.obj;
1031 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001032 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
1033 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -08001034 break;
1035
1036 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -07001037 ar = (AsyncResult) msg.obj;
1038 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -08001039 if (ar.exception == null && ar.result != null) {
1040 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -07001041 } else {
Jake Hambye994d462014-02-03 13:10:13 -08001042 request.result = "";
1043 if (ar.result == null) {
1044 loge("nvReadItem: Empty response");
1045 } else if (ar.exception instanceof CommandException) {
1046 loge("nvReadItem: CommandException: " +
1047 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001048 } else {
Jake Hambye994d462014-02-03 13:10:13 -08001049 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -07001050 }
1051 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001052 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001053 break;
1054
Jake Hambye994d462014-02-03 13:10:13 -08001055 case CMD_NV_WRITE_ITEM:
1056 request = (MainThreadRequest) msg.obj;
1057 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
1058 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001059 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -07001060 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -08001061 break;
1062
1063 case EVENT_NV_WRITE_ITEM_DONE:
1064 handleNullReturnEvent(msg, "nvWriteItem");
1065 break;
1066
1067 case CMD_NV_WRITE_CDMA_PRL:
1068 request = (MainThreadRequest) msg.obj;
1069 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001070 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -08001071 break;
1072
1073 case EVENT_NV_WRITE_CDMA_PRL_DONE:
1074 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
1075 break;
1076
chen xu6dac5ab2018-10-26 17:39:23 -07001077 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -08001078 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -07001079 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001080 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -08001081 break;
1082
chen xu6dac5ab2018-10-26 17:39:23 -07001083 case EVENT_RESET_MODEM_CONFIG_DONE:
1084 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -08001085 break;
1086
Sooraj Sasindran37444802020-08-11 10:40:43 -07001087 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
1088 request = (MainThreadRequest) msg.obj;
1089 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
1090 request);
1091 Phone phone = getPhoneFromRequest(request);
1092 if (phone != null) {
1093 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
1094 } else {
1095 loge("isNRDualConnectivityEnabled: No phone object");
1096 request.result = false;
1097 notifyRequester(request);
1098 }
1099 break;
1100 }
1101
1102 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
1103 ar = (AsyncResult) msg.obj;
1104 request = (MainThreadRequest) ar.userObj;
1105 if (ar.exception == null && ar.result != null) {
1106 request.result = ar.result;
1107 } else {
1108 // request.result must be set to something non-null
1109 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001110 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -07001111 request.result = ar.result;
1112 } else {
1113 request.result = false;
1114 }
1115 if (ar.result == null) {
1116 loge("isNRDualConnectivityEnabled: Empty response");
1117 } else if (ar.exception instanceof CommandException) {
1118 loge("isNRDualConnectivityEnabled: CommandException: "
1119 + ar.exception);
1120 } else {
1121 loge("isNRDualConnectivityEnabled: Unknown exception");
1122 }
1123 }
1124 notifyRequester(request);
1125 break;
1126
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001127 case CMD_IS_VONR_ENABLED: {
1128 request = (MainThreadRequest) msg.obj;
1129 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
1130 request);
1131 Phone phone = getPhoneFromRequest(request);
1132 if (phone != null) {
1133 phone.isVoNrEnabled(onCompleted, request.workSource);
1134 } else {
1135 loge("isVoNrEnabled: No phone object");
1136 request.result = false;
1137 notifyRequester(request);
1138 }
1139 break;
1140 }
1141
1142 case EVENT_IS_VONR_ENABLED_DONE:
1143 ar = (AsyncResult) msg.obj;
1144 request = (MainThreadRequest) ar.userObj;
1145 if (ar.exception == null && ar.result != null) {
1146 request.result = ar.result;
1147 } else {
1148 // request.result must be set to something non-null
1149 // for the calling thread to unblock
1150 if (ar.result != null) {
1151 request.result = ar.result;
1152 } else {
1153 request.result = false;
1154 }
1155 if (ar.result == null) {
1156 loge("isVoNrEnabled: Empty response");
1157 } else if (ar.exception instanceof CommandException) {
1158 loge("isVoNrEnabled: CommandException: "
1159 + ar.exception);
1160 } else {
1161 loge("isVoNrEnabled: Unknown exception");
1162 }
1163 }
1164 notifyRequester(request);
1165 break;
1166
Sooraj Sasindran37444802020-08-11 10:40:43 -07001167 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1168 request = (MainThreadRequest) msg.obj;
1169 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1170 Phone phone = getPhoneFromRequest(request);
1171 if (phone != null) {
1172 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1173 request.workSource);
1174 } else {
1175 loge("enableNrDualConnectivity: No phone object");
1176 request.result =
1177 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1178 notifyRequester(request);
1179 }
1180 break;
1181 }
1182
1183 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1184 ar = (AsyncResult) msg.obj;
1185 request = (MainThreadRequest) ar.userObj;
1186 if (ar.exception == null) {
1187 request.result =
1188 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1189 } else {
1190 request.result =
1191 TelephonyManager
1192 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1193 if (ar.exception instanceof CommandException) {
1194 CommandException.Error error =
1195 ((CommandException) (ar.exception)).getCommandError();
1196 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1197 request.result =
1198 TelephonyManager
1199 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001200 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1201 request.result =
1202 TelephonyManager
1203 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001204 }
1205 loge("enableNrDualConnectivity" + ": CommandException: "
1206 + ar.exception);
1207 } else {
1208 loge("enableNrDualConnectivity" + ": Unknown exception");
1209 }
1210 }
1211 notifyRequester(request);
1212 break;
1213 }
1214
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001215 case CMD_ENABLE_VONR: {
1216 request = (MainThreadRequest) msg.obj;
1217 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1218 Phone phone = getPhoneFromRequest(request);
1219 if (phone != null) {
1220 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1221 request.workSource);
1222 } else {
1223 loge("setVoNrEnabled: No phone object");
1224 request.result =
1225 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1226 notifyRequester(request);
1227 }
1228 break;
1229 }
1230
1231 case EVENT_ENABLE_VONR_DONE: {
1232 ar = (AsyncResult) msg.obj;
1233 request = (MainThreadRequest) ar.userObj;
1234 if (ar.exception == null) {
1235 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1236 } else {
1237 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1238 if (ar.exception instanceof CommandException) {
1239 CommandException.Error error =
1240 ((CommandException) (ar.exception)).getCommandError();
1241 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1242 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1243 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1244 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1245 } else {
1246 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1247 }
1248 loge("setVoNrEnabled" + ": CommandException: "
1249 + ar.exception);
1250 } else {
1251 loge("setVoNrEnabled" + ": Unknown exception");
1252 }
1253 }
1254 notifyRequester(request);
1255 break;
1256 }
1257
SongFerngWang3ef3e072020-12-21 16:41:52 +08001258 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001259 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001260 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1261 request);
1262 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001263 break;
1264
SongFerngWang3ef3e072020-12-21 16:41:52 +08001265 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001266 ar = (AsyncResult) msg.obj;
1267 request = (MainThreadRequest) ar.userObj;
1268 if (ar.exception == null && ar.result != null) {
1269 request.result = ar.result; // Integer
1270 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301271 // request.result must be set to something non-null
1272 // for the calling thread to unblock
1273 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001274 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001275 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001276 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001277 loge("getAllowedNetworkTypesBitmask: CommandException: "
1278 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001279 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001280 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001281 }
1282 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001283 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001284 break;
1285
SongFerngWang3ef3e072020-12-21 16:41:52 +08001286 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001287 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001288 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1289 request);
1290 Pair<Integer, Long> reasonWithNetworkTypes =
1291 (Pair<Integer, Long>) request.argument;
1292 getPhoneFromRequest(request).setAllowedNetworkTypes(
1293 reasonWithNetworkTypes.first,
1294 reasonWithNetworkTypes.second,
1295 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001296 break;
1297
SongFerngWang3ef3e072020-12-21 16:41:52 +08001298 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1299 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001300 break;
1301
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001302 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1303 request = (MainThreadRequest)msg.obj;
1304 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001305 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001306 break;
1307
1308 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1309 ar = (AsyncResult)msg.obj;
1310 request = (MainThreadRequest)ar.userObj;
1311 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001312 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001313 break;
1314
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001315 case CMD_SET_VOICEMAIL_NUMBER:
1316 request = (MainThreadRequest) msg.obj;
1317 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1318 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001319 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1320 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001321 break;
1322
1323 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1324 handleNullReturnEvent(msg, "setVoicemailNumber");
1325 break;
1326
Stuart Scott54788802015-03-30 13:18:01 -07001327 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1328 request = (MainThreadRequest) msg.obj;
1329 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1330 request);
1331 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1332 break;
1333
1334 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1335 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1336 break;
1337
Shishir Agrawal302c8692015-06-19 13:49:39 -07001338 case CMD_PERFORM_NETWORK_SCAN:
1339 request = (MainThreadRequest) msg.obj;
1340 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1341 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1342 break;
1343
Hall Liu27d24262020-09-18 19:04:59 -07001344 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001345 request = (MainThreadRequest) msg.obj;
1346 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001347 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1348 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1349 request.argument;
1350 int callForwardingReason = args.first;
1351 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001352 break;
Hall Liu27d24262020-09-18 19:04:59 -07001353 }
1354 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001355 ar = (AsyncResult) msg.obj;
1356 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001357 TelephonyManager.CallForwardingInfoCallback callback =
1358 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1359 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001360 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001361 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001362 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1363 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1364 // Service Class is a bit mask per 3gpp 27.007. Search for
1365 // any service for voice call.
1366 if ((callForwardInfo.serviceClass
1367 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001368 callForwardingInfo = new CallForwardingInfo(
1369 callForwardInfo.status
1370 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001371 callForwardInfo.reason,
1372 callForwardInfo.number,
1373 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001374 break;
1375 }
1376 }
1377 // Didn't find a call forward info for voice call.
1378 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001379 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1380 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001381 }
Hall Liu27d24262020-09-18 19:04:59 -07001382 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001383 } else {
1384 if (ar.result == null) {
1385 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1386 }
1387 if (ar.exception != null) {
1388 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1389 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001390 int errorCode = TelephonyManager
1391 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001392 if (ar.exception instanceof CommandException) {
1393 CommandException.Error error =
1394 ((CommandException) (ar.exception)).getCommandError();
1395 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001396 errorCode = TelephonyManager
1397 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001398 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001399 errorCode = TelephonyManager
1400 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001401 }
1402 }
Hall Liu27d24262020-09-18 19:04:59 -07001403 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001404 }
Shuo Qian4a594052020-01-23 11:59:30 -08001405 break;
Hall Liu27d24262020-09-18 19:04:59 -07001406 }
Shuo Qian4a594052020-01-23 11:59:30 -08001407
Hall Liu27d24262020-09-18 19:04:59 -07001408 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001409 request = (MainThreadRequest) msg.obj;
1410 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001411 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001412 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001413 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1414 request.argument).first;
1415 request.phone.setCallForwardingOption(
1416 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001417 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001418 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001419 callForwardingInfoToSet.getReason(),
1420 callForwardingInfoToSet.getNumber(),
1421 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1422 break;
Hall Liu27d24262020-09-18 19:04:59 -07001423 }
Shuo Qian4a594052020-01-23 11:59:30 -08001424
Hall Liu27d24262020-09-18 19:04:59 -07001425 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001426 ar = (AsyncResult) msg.obj;
1427 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001428 Consumer<Integer> callback =
1429 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1430 request.argument).second;
1431 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001432 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001433 int errorCode = TelephonyManager.CallForwardingInfoCallback
1434 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001435 if (ar.exception instanceof CommandException) {
1436 CommandException.Error error =
1437 ((CommandException) (ar.exception)).getCommandError();
1438 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001439 errorCode = TelephonyManager.CallForwardingInfoCallback
1440 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001441 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001442 errorCode = TelephonyManager.CallForwardingInfoCallback
1443 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001444 }
1445 }
1446 callback.accept(errorCode);
1447 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001448 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001449 }
Shuo Qian4a594052020-01-23 11:59:30 -08001450 break;
Hall Liu27d24262020-09-18 19:04:59 -07001451 }
Shuo Qian4a594052020-01-23 11:59:30 -08001452
Hall Liu27d24262020-09-18 19:04:59 -07001453 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001454 request = (MainThreadRequest) msg.obj;
1455 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1456 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1457 break;
Hall Liu27d24262020-09-18 19:04:59 -07001458 }
Shuo Qian4a594052020-01-23 11:59:30 -08001459
Hall Liu27d24262020-09-18 19:04:59 -07001460 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001461 ar = (AsyncResult) msg.obj;
1462 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001463 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001464 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001465 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001466 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001467 // Service Class is a bit mask per 3gpp 27.007.
1468 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001469 if (callForwardResults.length > 1
1470 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001471 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001472 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001473 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1474 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001475 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001476 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001477 }
1478 } else {
1479 if (ar.result == null) {
1480 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1481 }
1482 if (ar.exception != null) {
1483 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1484 }
1485 if (ar.exception instanceof CommandException) {
1486 CommandException.Error error =
1487 ((CommandException) (ar.exception)).getCommandError();
1488 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001489 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001490 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001491 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1492 callWaitingStatus =
1493 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001494 }
1495 }
1496 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001497 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001498 break;
Hall Liu27d24262020-09-18 19:04:59 -07001499 }
Shuo Qian4a594052020-01-23 11:59:30 -08001500
Hall Liu27d24262020-09-18 19:04:59 -07001501 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001502 request = (MainThreadRequest) msg.obj;
1503 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001504 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1505 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001506 break;
Hall Liu27d24262020-09-18 19:04:59 -07001507 }
Shuo Qian4a594052020-01-23 11:59:30 -08001508
Hall Liu27d24262020-09-18 19:04:59 -07001509 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001510 ar = (AsyncResult) msg.obj;
1511 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001512 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1513 Consumer<Integer> callback =
1514 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1515 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001516 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001517 if (ar.exception instanceof CommandException) {
1518 CommandException.Error error =
1519 ((CommandException) (ar.exception)).getCommandError();
1520 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1521 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001522 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1523 callback.accept(
1524 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001525 } else {
1526 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1527 }
1528 } else {
1529 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1530 }
1531 } else {
1532 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1533 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001534 }
Shuo Qian4a594052020-01-23 11:59:30 -08001535 break;
Hall Liu27d24262020-09-18 19:04:59 -07001536 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001537 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1538 ar = (AsyncResult) msg.obj;
1539 request = (MainThreadRequest) ar.userObj;
1540 CellNetworkScanResult cellScanResult;
1541 if (ar.exception == null && ar.result != null) {
1542 cellScanResult = new CellNetworkScanResult(
1543 CellNetworkScanResult.STATUS_SUCCESS,
1544 (List<OperatorInfo>) ar.result);
1545 } else {
1546 if (ar.result == null) {
1547 loge("getCellNetworkScanResults: Empty response");
1548 }
1549 if (ar.exception != null) {
1550 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1551 }
1552 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1553 if (ar.exception instanceof CommandException) {
1554 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001555 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001556 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1557 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1558 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1559 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1560 }
1561 }
1562 cellScanResult = new CellNetworkScanResult(errorCode, null);
1563 }
1564 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001565 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001566 break;
1567
1568 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1569 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001570 ManualNetworkSelectionArgument selArg =
1571 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001572 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1573 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001574 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1575 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001576 break;
1577
1578 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001579 ar = (AsyncResult) msg.obj;
1580 request = (MainThreadRequest) ar.userObj;
1581 if (ar.exception == null) {
1582 request.result = true;
1583 } else {
1584 request.result = false;
1585 loge("setNetworkSelectionModeManual " + ar.exception);
1586 }
1587 notifyRequester(request);
1588 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001589 break;
1590
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001591 case CMD_GET_MODEM_ACTIVITY_INFO:
1592 request = (MainThreadRequest) msg.obj;
1593 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001594 if (defaultPhone != null) {
1595 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001596 } else {
1597 ResultReceiver result = (ResultReceiver) request.argument;
1598 Bundle bundle = new Bundle();
1599 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001600 new ModemActivityInfo(0, 0, 0,
1601 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001602 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001603 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001604 break;
1605
Hall Liud0f208c2020-10-14 16:54:44 -07001606 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001607 ar = (AsyncResult) msg.obj;
1608 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001609 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001610 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001611 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001612 if (mLastModemActivityInfo == null) {
1613 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1614 mLastModemActivitySpecificInfo[0] =
1615 new ActivityStatsTechSpecificInfo(
1616 0,
1617 0,
1618 new int[ModemActivityInfo.getNumTxPowerLevels()],
1619 0);
1620 mLastModemActivityInfo =
1621 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1622 }
1623
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001624 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001625 // Update the last modem activity info and the result of the request.
1626 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1627 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001628 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001629 } else {
1630 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001631 }
Kai Shi917fdc62022-11-28 14:01:02 -08001632 // This is needed to decouple ret from mLastModemActivityInfo
1633 // We don't want to return mLastModemActivityInfo which is updated
1634 // inside mergeModemActivityInfo()
1635 ret = new ModemActivityInfo(
1636 mLastModemActivityInfo.getTimestampMillis(),
1637 mLastModemActivityInfo.getSleepTimeMillis(),
1638 mLastModemActivityInfo.getIdleTimeMillis(),
1639 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001640
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001641 } else {
1642 if (ar.result == null) {
1643 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001644 error = TelephonyManager.ModemActivityInfoException
1645 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001646 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001647 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001648 error = TelephonyManager.ModemActivityInfoException
1649 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001650 } else {
1651 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001652 error = TelephonyManager.ModemActivityInfoException
1653 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001654 }
1655 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001656 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001657 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001658 bundle.putParcelable(
1659 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001660 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001661 } else {
1662 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1663 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001664 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001665 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001666 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001667 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001668
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001669 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001670 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001671 CarrierRestrictionRules argument =
1672 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001673 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001674 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001675 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001676 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001677
1678 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1679 ar = (AsyncResult) msg.obj;
1680 request = (MainThreadRequest) ar.userObj;
1681 if (ar.exception == null && ar.result != null) {
1682 request.result = ar.result;
1683 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001684 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1685 if (ar.exception instanceof CommandException) {
1686 loge("setAllowedCarriers: CommandException: " + ar.exception);
1687 CommandException.Error error =
1688 ((CommandException) (ar.exception)).getCommandError();
1689 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1690 request.result =
1691 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1692 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001693 } else {
1694 loge("setAllowedCarriers: Unknown exception");
1695 }
1696 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001697 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001698 break;
1699
1700 case CMD_GET_ALLOWED_CARRIERS:
1701 request = (MainThreadRequest) msg.obj;
1702 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001703 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001704 break;
1705
1706 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1707 ar = (AsyncResult) msg.obj;
1708 request = (MainThreadRequest) ar.userObj;
1709 if (ar.exception == null && ar.result != null) {
1710 request.result = ar.result;
1711 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001712 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001713 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001714 if (ar.result == null) {
1715 loge("getAllowedCarriers: Empty response");
1716 } else if (ar.exception instanceof CommandException) {
1717 loge("getAllowedCarriers: CommandException: " +
1718 ar.exception);
1719 } else {
1720 loge("getAllowedCarriers: Unknown exception");
1721 }
1722 }
arunvoddud7401012022-12-15 16:08:12 +00001723 if (request.argument != null) {
1724 // This is for the implementation of carrierRestrictionStatus.
1725 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1726 Consumer<Integer> callback = callbackInfo.getConsumer();
1727 int callerCarrierId = callbackInfo.getCarrierId();
1728 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1729 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1730 CarrierRestrictionRules carrierRestrictionRules =
1731 (CarrierRestrictionRules) ar.result;
1732 int carrierId = -1;
1733 try {
1734 CarrierIdentifier carrierIdentifier =
1735 carrierRestrictionRules.getAllowedCarriers().get(0);
1736 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1737 carrierIdentifier);
1738 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1739 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1740 }
1741 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
1742 if (carrierId != -1 && callerCarrierId == carrierId && lockStatus
1743 == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001744 lockStatus = TelephonyManager
1745 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001746 }
1747 } else {
1748 Rlog.e(LOG_TAG,
1749 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1750 }
1751 callback.accept(lockStatus);
1752 } else {
1753 // This is for the implementation of getAllowedCarriers.
1754 notifyRequester(request);
1755 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001756 break;
1757
Nathan Haroldb3014052017-01-25 15:57:32 -08001758 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1759 ar = (AsyncResult) msg.obj;
1760 request = (MainThreadRequest) ar.userObj;
1761 if (ar.exception == null && ar.result != null) {
1762 request.result = ar.result;
1763 } else {
1764 request.result = new IllegalArgumentException(
1765 "Failed to retrieve Forbidden Plmns");
1766 if (ar.result == null) {
1767 loge("getForbiddenPlmns: Empty response");
1768 } else {
1769 loge("getForbiddenPlmns: Unknown exception");
1770 }
1771 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001772 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001773 break;
1774
1775 case CMD_GET_FORBIDDEN_PLMNS:
1776 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001777 uiccPort = getUiccPortFromRequest(request);
1778 if (uiccPort == null) {
1779 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001780 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001781 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001782 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001783 break;
1784 }
1785 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001786 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001787 if (uiccApp == null) {
1788 loge("getForbiddenPlmns() no app with specified type -- "
1789 + appType);
1790 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001791 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001792 break;
1793 } else {
1794 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1795 + " specified type -- " + appType);
1796 }
1797 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1798 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001799 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001800 break;
1801
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001802 case CMD_SWITCH_SLOTS:
1803 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001804 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001805 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001806 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001807 break;
1808
1809 case EVENT_SWITCH_SLOTS_DONE:
1810 ar = (AsyncResult) msg.obj;
1811 request = (MainThreadRequest) ar.userObj;
1812 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001813 notifyRequester(request);
1814 break;
1815 case CMD_GET_NETWORK_SELECTION_MODE:
1816 request = (MainThreadRequest) msg.obj;
1817 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1818 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1819 break;
1820
1821 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1822 ar = (AsyncResult) msg.obj;
1823 request = (MainThreadRequest) ar.userObj;
1824 if (ar.exception != null) {
1825 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1826 } else {
1827 int mode = ((int[]) ar.result)[0];
1828 if (mode == 0) {
1829 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1830 } else {
1831 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1832 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001833 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001834 notifyRequester(request);
1835 break;
1836 case CMD_GET_CDMA_ROAMING_MODE:
1837 request = (MainThreadRequest) msg.obj;
1838 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1839 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1840 break;
1841 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1842 ar = (AsyncResult) msg.obj;
1843 request = (MainThreadRequest) ar.userObj;
1844 if (ar.exception != null) {
1845 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1846 } else {
1847 request.result = ((int[]) ar.result)[0];
1848 }
1849 notifyRequester(request);
1850 break;
1851 case CMD_SET_CDMA_ROAMING_MODE:
1852 request = (MainThreadRequest) msg.obj;
1853 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1854 int mode = (int) request.argument;
1855 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1856 break;
1857 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1858 ar = (AsyncResult) msg.obj;
1859 request = (MainThreadRequest) ar.userObj;
1860 request.result = ar.exception == null;
1861 notifyRequester(request);
1862 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001863 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1864 request = (MainThreadRequest) msg.obj;
1865 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1866 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1867 break;
1868 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1869 ar = (AsyncResult) msg.obj;
1870 request = (MainThreadRequest) ar.userObj;
1871 if (ar.exception != null) {
1872 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1873 } else {
1874 request.result = ((int[]) ar.result)[0];
1875 }
1876 notifyRequester(request);
1877 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001878 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1879 request = (MainThreadRequest) msg.obj;
1880 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1881 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001882 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1883 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001884 break;
1885 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1886 ar = (AsyncResult) msg.obj;
1887 request = (MainThreadRequest) ar.userObj;
1888 request.result = ar.exception == null;
1889 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001890 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001891 case CMD_GET_ALL_CELL_INFO:
1892 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001893 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001894 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001895 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001896 case EVENT_GET_ALL_CELL_INFO_DONE:
1897 ar = (AsyncResult) msg.obj;
1898 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001899 // If a timeout occurs, the response will be null
1900 request.result = (ar.exception == null && ar.result != null)
1901 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001902 synchronized (request) {
1903 request.notifyAll();
1904 }
1905 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001906 case CMD_REQUEST_CELL_INFO_UPDATE:
1907 request = (MainThreadRequest) msg.obj;
1908 request.phone.requestCellInfoUpdate(request.workSource,
1909 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1910 break;
1911 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1912 ar = (AsyncResult) msg.obj;
1913 request = (MainThreadRequest) ar.userObj;
1914 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1915 try {
1916 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001917 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001918 cb.onError(
1919 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1920 ar.exception.getClass().getName(),
1921 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001922 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001923 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001924 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001925 } else {
1926 // use the result as returned
1927 cb.onCellInfo((List<CellInfo>) ar.result);
1928 }
1929 } catch (RemoteException re) {
1930 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1931 }
1932 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001933 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001934 request = (MainThreadRequest) msg.obj;
1935 WorkSource ws = (WorkSource) request.argument;
1936 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001937 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001938 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001939 }
1940 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001941 ar = (AsyncResult) msg.obj;
1942 request = (MainThreadRequest) ar.userObj;
1943 if (ar.exception == null) {
1944 request.result = ar.result;
1945 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001946 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001947 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001948 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001949 }
1950
1951 synchronized (request) {
1952 request.notifyAll();
1953 }
1954 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001955 }
chen xu6dac5ab2018-10-26 17:39:23 -07001956 case CMD_MODEM_REBOOT:
1957 request = (MainThreadRequest) msg.obj;
1958 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001959 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001960 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001961 case EVENT_CMD_MODEM_REBOOT_DONE:
1962 handleNullReturnEvent(msg, "rebootModem");
1963 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001964 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001965 request = (MainThreadRequest) msg.obj;
1966 boolean enable = (boolean) request.argument;
1967 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001968 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001969 PhoneConfigurationManager.getInstance()
1970 .enablePhone(request.phone, enable, onCompleted);
1971 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001972 }
Michele Berionne5e411512020-11-13 02:36:59 +00001973 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001974 ar = (AsyncResult) msg.obj;
1975 request = (MainThreadRequest) ar.userObj;
1976 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001977 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001978 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001979 if ((boolean) request.result) {
1980 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1981 updateModemStateMetrics();
1982 } else {
1983 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1984 + ar.exception);
1985 }
1986 notifyRequester(request);
1987 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001988 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001989 case CMD_GET_MODEM_STATUS:
1990 request = (MainThreadRequest) msg.obj;
1991 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1992 PhoneConfigurationManager.getInstance()
1993 .getPhoneStatusFromModem(request.phone, onCompleted);
1994 break;
1995 case EVENT_GET_MODEM_STATUS_DONE:
1996 ar = (AsyncResult) msg.obj;
1997 request = (MainThreadRequest) ar.userObj;
1998 int id = request.phone.getPhoneId();
1999 if (ar.exception == null && ar.result != null) {
2000 request.result = ar.result;
2001 //update the cache as modem status has changed
2002 mPhoneConfigurationManager.addToPhoneStatusCache(id,
2003 (boolean) request.result);
2004 } else {
2005 // Return true if modem status cannot be retrieved. For most cases,
2006 // modem status is on. And for older version modems, GET_MODEM_STATUS
2007 // and disable modem are not supported. Modem is always on.
2008 // TODO: this should be fixed in R to support a third
2009 // status UNKNOWN b/131631629
2010 request.result = true;
2011 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
2012 + ar.exception);
2013 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08002014 notifyRequester(request);
2015 break;
Hall Liu73f5d362020-01-20 13:42:00 -08002016 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
2017 request = (MainThreadRequest) msg.obj;
2018 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
2019 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
2020 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
2021 request.phone.setSystemSelectionChannels(args.first, onCompleted);
2022 break;
2023 }
2024 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
2025 ar = (AsyncResult) msg.obj;
2026 request = (MainThreadRequest) ar.userObj;
2027 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
2028 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
2029 args.second.accept(ar.exception == null);
2030 notifyRequester(request);
2031 break;
2032 }
Sarah Chin679c08a2020-11-18 13:39:35 -08002033 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
2034 request = (MainThreadRequest) msg.obj;
2035 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
2036 Phone phone = getPhoneFromRequest(request);
2037 if (phone != null) {
2038 phone.getSystemSelectionChannels(onCompleted);
2039 } else {
2040 loge("getSystemSelectionChannels: No phone object");
2041 request.result = new ArrayList<RadioAccessSpecifier>();
2042 notifyRequester(request);
2043 }
2044 break;
2045 }
2046 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
2047 ar = (AsyncResult) msg.obj;
2048 request = (MainThreadRequest) ar.userObj;
2049 if (ar.exception == null && ar.result != null) {
2050 request.result = ar.result;
2051 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08002052 request.result = new IllegalStateException(
2053 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08002054 if (ar.result == null) {
2055 loge("getSystemSelectionChannels: Empty response");
2056 } else {
2057 loge("getSystemSelectionChannels: Unknown exception");
2058 }
2059 }
2060 notifyRequester(request);
2061 break;
yincheng zhao2737e882019-09-06 17:06:54 -07002062 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
2063 ar = (AsyncResult) msg.obj;
2064 request = (MainThreadRequest) ar.userObj;
2065 if (ar.exception == null && ar.result != null) {
2066 request.result = ar.result;
2067 } else {
2068 request.result = -1;
2069 loge("Failed to set Forbidden Plmns");
2070 if (ar.result == null) {
2071 loge("setForbidenPlmns: Empty response");
2072 } else if (ar.exception != null) {
2073 loge("setForbiddenPlmns: Exception: " + ar.exception);
2074 request.result = -1;
2075 } else {
2076 loge("setForbiddenPlmns: Unknown exception");
2077 }
2078 }
2079 notifyRequester(request);
2080 break;
2081 case CMD_SET_FORBIDDEN_PLMNS:
2082 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002083 uiccPort = getUiccPortFromRequest(request);
2084 if (uiccPort == null) {
2085 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07002086 request.result = -1;
2087 notifyRequester(request);
2088 break;
2089 }
2090 Pair<Integer, List<String>> setFplmnsArgs =
2091 (Pair<Integer, List<String>>) request.argument;
2092 appType = setFplmnsArgs.first;
2093 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002094 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07002095 if (uiccApp == null) {
2096 loge("setForbiddenPlmns: no app with specified type -- " + appType);
2097 request.result = -1;
2098 loge("Failed to get UICC App");
2099 notifyRequester(request);
2100 } else {
2101 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
2102 ((SIMRecords) uiccApp.getIccRecords())
2103 .setForbiddenPlmns(onCompleted, fplmns);
2104 }
yinchengzhao4d163c02019-12-12 15:21:47 -08002105 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07002106 case CMD_ERASE_MODEM_CONFIG:
2107 request = (MainThreadRequest) msg.obj;
2108 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
2109 defaultPhone.eraseModemConfig(onCompleted);
2110 break;
2111 case EVENT_ERASE_MODEM_CONFIG_DONE:
2112 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07002113 break;
zoey chene02881a2019-12-30 16:11:23 +08002114
Kai Shif70f46f2021-03-03 13:59:46 -08002115 case CMD_ERASE_DATA_SHARED_PREFERENCES:
2116 request = (MainThreadRequest) msg.obj;
2117 request.result = defaultPhone.eraseDataInSharedPreferences();
2118 notifyRequester(request);
2119 break;
2120
zoey chene02881a2019-12-30 16:11:23 +08002121 case CMD_CHANGE_ICC_LOCK_PASSWORD:
2122 request = (MainThreadRequest) msg.obj;
2123 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
2124 Pair<String, String> changed = (Pair<String, String>) request.argument;
2125 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
2126 changed.first, changed.second, onCompleted);
2127 break;
2128 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
2129 ar = (AsyncResult) msg.obj;
2130 request = (MainThreadRequest) ar.userObj;
2131 if (ar.exception == null) {
2132 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002133 // If the operation is successful, update the PIN storage
2134 Pair<String, String> passwords = (Pair<String, String>) request.argument;
2135 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00002136 UiccController.getInstance().getPinStorage()
2137 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08002138 } else {
2139 request.result = msg.arg1;
2140 }
2141 notifyRequester(request);
2142 break;
2143
Michele Berionne5e411512020-11-13 02:36:59 +00002144 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002145 request = (MainThreadRequest) msg.obj;
2146 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2147 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2148 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2149 enabled.first, enabled.second, onCompleted);
2150 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002151 }
zoey chene02881a2019-12-30 16:11:23 +08002152 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2153 ar = (AsyncResult) msg.obj;
2154 request = (MainThreadRequest) ar.userObj;
2155 if (ar.exception == null) {
2156 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002157 // If the operation is successful, update the PIN storage
2158 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2159 int phoneId = getPhoneFromRequest(request).getPhoneId();
2160 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002161 UiccController.getInstance().getPinStorage()
2162 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002163 } else {
2164 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2165 }
zoey chene02881a2019-12-30 16:11:23 +08002166 } else {
2167 request.result = msg.arg1;
2168 }
Michele Berionne5e411512020-11-13 02:36:59 +00002169
2170
zoey chene02881a2019-12-30 16:11:23 +08002171 notifyRequester(request);
2172 break;
2173
Peter Wangdafb9ac2020-01-15 14:13:38 -08002174 case MSG_NOTIFY_USER_ACTIVITY:
2175 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002176 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002177 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2178 getDefaultPhone().getContext().sendBroadcastAsUser(
2179 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2180 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002181
2182 case CMD_SET_DATA_THROTTLING: {
2183 request = (MainThreadRequest) msg.obj;
2184 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2185 DataThrottlingRequest dataThrottlingRequest =
2186 (DataThrottlingRequest) request.argument;
2187 Phone phone = getPhoneFromRequest(request);
2188 if (phone != null) {
2189 phone.setDataThrottling(onCompleted,
2190 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2191 dataThrottlingRequest.getCompletionDurationMillis());
2192 } else {
2193 loge("setDataThrottling: No phone object");
2194 request.result =
2195 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2196 notifyRequester(request);
2197 }
2198
2199 break;
2200 }
2201 case EVENT_SET_DATA_THROTTLING_DONE:
2202 ar = (AsyncResult) msg.obj;
2203 request = (MainThreadRequest) ar.userObj;
2204
2205 if (ar.exception == null) {
2206 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2207 } else if (ar.exception instanceof CommandException) {
2208 loge("setDataThrottling: CommandException: " + ar.exception);
2209 CommandException.Error error =
2210 ((CommandException) (ar.exception)).getCommandError();
2211
2212 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2213 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002214 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002215 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2216 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002217 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2218 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002219 } else {
2220 request.result =
2221 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2222 }
2223 } else {
2224 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2225 }
2226 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2227 notifyRequester(request);
2228 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002229
2230 case CMD_SET_SIM_POWER: {
2231 request = (MainThreadRequest) msg.obj;
2232 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2233 request = (MainThreadRequest) msg.obj;
2234 int stateToSet =
2235 ((Pair<Integer, IIntegerConsumer>)
2236 request.argument).first;
2237 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2238 break;
2239 }
2240 case EVENT_SET_SIM_POWER_DONE: {
2241 ar = (AsyncResult) msg.obj;
2242 request = (MainThreadRequest) ar.userObj;
2243 IIntegerConsumer callback =
2244 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2245 if (ar.exception != null) {
2246 loge("setSimPower exception: " + ar.exception);
2247 int errorCode = TelephonyManager.CallForwardingInfoCallback
2248 .RESULT_ERROR_UNKNOWN;
2249 if (ar.exception instanceof CommandException) {
2250 CommandException.Error error =
2251 ((CommandException) (ar.exception)).getCommandError();
2252 if (error == CommandException.Error.SIM_ERR) {
2253 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2254 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2255 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2256 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2257 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2258 } else {
2259 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2260 }
2261 }
2262 try {
2263 callback.accept(errorCode);
2264 } catch (RemoteException e) {
2265 // Ignore if the remote process is no longer available to call back.
2266 Log.w(LOG_TAG, "setSimPower: callback not available.");
2267 }
2268 } else {
2269 try {
2270 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2271 } catch (RemoteException e) {
2272 // Ignore if the remote process is no longer available to call back.
2273 Log.w(LOG_TAG, "setSimPower: callback not available.");
2274 }
2275 }
2276 break;
2277 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002278 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2279 request = (MainThreadRequest) msg.obj;
2280
2281 final Phone phone = getPhoneFromRequest(request);
2282 if (phone == null || phone.getServiceStateTracker() == null) {
2283 request.result = new IllegalStateException("Phone or SST is null");
2284 notifyRequester(request);
2285 break;
2286 }
2287
2288 Pair<Integer, SignalStrengthUpdateRequest> pair =
2289 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2290 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2291 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002292 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002293 request.subId, pair.first /*callingUid*/,
2294 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002295 break;
2296 }
2297 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2298 ar = (AsyncResult) msg.obj;
2299 request = (MainThreadRequest) ar.userObj;
2300 // request.result will be the exception of ar if present, true otherwise.
2301 // Be cautious not to leave result null which will wait() forever
2302 request.result = ar.exception != null ? ar.exception : true;
2303 notifyRequester(request);
2304 break;
2305 }
2306 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2307 request = (MainThreadRequest) msg.obj;
2308
2309 Phone phone = getPhoneFromRequest(request);
2310 if (phone == null || phone.getServiceStateTracker() == null) {
2311 request.result = new IllegalStateException("Phone or SST is null");
2312 notifyRequester(request);
2313 break;
2314 }
2315
2316 Pair<Integer, SignalStrengthUpdateRequest> pair =
2317 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2318 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2319 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002320 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002321 request.subId, pair.first /*callingUid*/,
2322 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002323 break;
2324 }
2325 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2326 ar = (AsyncResult) msg.obj;
2327 request = (MainThreadRequest) ar.userObj;
2328 request.result = ar.exception != null ? ar.exception : true;
2329 notifyRequester(request);
2330 break;
2331 }
Jordan Liu109698e2020-11-24 14:50:34 -08002332
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002333 case CMD_GET_SLICING_CONFIG: {
2334 request = (MainThreadRequest) msg.obj;
2335 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2336 request.phone.getSlicingConfig(onCompleted);
2337 break;
2338 }
2339 case EVENT_GET_SLICING_CONFIG_DONE: {
2340 ar = (AsyncResult) msg.obj;
2341 request = (MainThreadRequest) ar.userObj;
2342 ResultReceiver result = (ResultReceiver) request.argument;
2343
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002344 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002345 Bundle bundle = new Bundle();
2346 int resultCode = 0;
2347 if (ar.exception != null) {
2348 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2349 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002350 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002351 } else if (ar.result == null) {
2352 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002353 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002354 } else {
2355 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002356 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2357 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002358 }
2359
2360 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002361 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002362 }
2363 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2364 result.send(resultCode, bundle);
2365 notifyRequester(request);
2366 break;
2367 }
2368
Sarah Chin71b3a852022-09-28 15:54:19 -07002369 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002370 request = (MainThreadRequest) msg.obj;
2371 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002372 PurchasePremiumCapabilityArgument arg =
2373 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin46355ba2022-11-01 23:51:16 -07002374 SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability(
Sarah Chinb8218c22023-01-04 13:35:29 -08002375 arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002376 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002377 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002378
Sarah Chin71b3a852022-09-28 15:54:19 -07002379 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002380 ar = (AsyncResult) msg.obj;
2381 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002382 PurchasePremiumCapabilityArgument arg =
2383 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002384 try {
2385 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002386 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002387 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002388 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002389 + ", result= "
2390 + TelephonyManager.convertPurchaseResultToString(result));
2391 } catch (RemoteException e) {
2392 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002393 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002394 + " failed: " + e;
2395 if (DBG) log(logStr);
2396 AnomalyReporter.reportAnomaly(
2397 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2398 }
2399 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002400 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002401
Michele Berionne5e411512020-11-13 02:36:59 +00002402 case CMD_PREPARE_UNATTENDED_REBOOT:
2403 request = (MainThreadRequest) msg.obj;
2404 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002405 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002406 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002407 notifyRequester(request);
2408 break;
2409
Sarah Chineccfbd12023-01-20 19:00:35 -08002410 case CMD_START_SATELLITE_POSITION_UPDATES: {
2411 request = (MainThreadRequest) msg.obj;
2412 onCompleted =
2413 obtainMessage(EVENT_START_SATELLITE_POSITION_UPDATES_DONE, request);
2414 Phone phone = getPhoneFromRequest(request);
2415 if (phone != null) {
2416 phone.startSatellitePositionUpdates(onCompleted);
2417 } else {
2418 loge("startSatellitePositionUpdates: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002419 ((Consumer<Integer>) request.argument).accept(
2420 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Sarah Chineccfbd12023-01-20 19:00:35 -08002421 }
2422 break;
2423 }
2424
2425 case EVENT_START_SATELLITE_POSITION_UPDATES_DONE: {
2426 ar = (AsyncResult) msg.obj;
2427 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002428 int error = getSatelliteError(ar, "startSatellitePositionUpdates", false);
2429 ((Consumer<Integer>) request.argument).accept(error);
Sarah Chineccfbd12023-01-20 19:00:35 -08002430 break;
2431 }
2432
2433 case CMD_STOP_SATELLITE_POSITION_UPDATES: {
2434 request = (MainThreadRequest) msg.obj;
2435 onCompleted =
2436 obtainMessage(EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE, request);
2437 Phone phone = getPhoneFromRequest(request);
2438 if (phone != null) {
2439 phone.stopSatellitePositionUpdates(onCompleted);
2440 } else {
2441 loge("stopSatellitePositionUpdates: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002442 ((Consumer<Integer>) request.argument).accept(
2443 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Sarah Chineccfbd12023-01-20 19:00:35 -08002444 }
2445 break;
2446 }
2447
2448 case EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE: {
2449 ar = (AsyncResult) msg.obj;
2450 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002451 int error = getSatelliteError(ar, "stopSatellitePositionUpdates", false);
2452 ((Consumer<Integer>) request.argument).accept(error);
Sarah Chineccfbd12023-01-20 19:00:35 -08002453 break;
2454 }
2455
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002456 case CMD_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG: {
2457 request = (MainThreadRequest) msg.obj;
2458 onCompleted = obtainMessage(EVENT_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG_DONE,
2459 request);
2460 Phone phone = getPhoneFromRequest(request);
2461 if (phone != null) {
2462 phone.getMaxCharactersPerSatelliteTextMessage(onCompleted);
2463 } else {
2464 loge("getMaxCharactersPerSatelliteTextMessage: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002465 ((ResultReceiver) request.argument).send(
2466 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002467 }
2468 break;
2469 }
2470
2471 case EVENT_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG_DONE: {
2472 ar = (AsyncResult) msg.obj;
2473 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002474 int error =
2475 getSatelliteError(ar, "getMaxCharactersPerSatelliteTextMessage", true);
2476 Bundle bundle = new Bundle();
2477 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002478 int maxCharLimit = ((int[]) ar.result)[0];
Sarah Chin503828c2023-02-01 23:54:20 -08002479 if (DBG) log("getMaxCharactersPerSatelliteTextMessage: " + maxCharLimit);
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002480 bundle.putInt(SatelliteManager.KEY_MAX_CHARACTERS_PER_SATELLITE_TEXT,
2481 maxCharLimit);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002482 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002483 ((ResultReceiver) request.argument).send(error, bundle);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002484 break;
2485 }
2486
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002487 case CMD_PROVISION_SATELLITE_SERVICE: {
2488 request = (MainThreadRequest) msg.obj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002489 onCompleted = obtainMessage(EVENT_PROVISION_SATELLITE_SERVICE_DONE, request);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002490 Phone phone = getPhoneFromRequest(request);
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002491 ProvisionSatelliteServiceArgument argument =
2492 (ProvisionSatelliteServiceArgument) request.argument;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002493 if (phone != null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002494 handleCmdProvisionSatelliteService(argument, phone, onCompleted);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002495 } else {
2496 loge("provisionSatelliteService: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002497 argument.callback.accept(
2498 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002499 notifyRequester(request);
2500 }
2501 break;
2502 }
2503
2504 case EVENT_PROVISION_SATELLITE_SERVICE_DONE: {
2505 ar = (AsyncResult) msg.obj;
2506 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002507 int errorCode = getSatelliteError(ar, "provisionSatelliteService", false);
2508 ProvisionSatelliteServiceArgument argument =
2509 (ProvisionSatelliteServiceArgument) request.argument;
2510 handleEventProvisionSatelliteServiceDone(argument.subId, errorCode);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002511 notifyRequester(request);
2512 break;
2513 }
2514
2515 case CMD_CANCEL_PROVISION_SATELLITE_SERVICE: {
2516 request = (MainThreadRequest) msg.obj;
2517 onCompleted =
2518 obtainMessage(EVENT_CANCEL_PROVISION_SATELLITE_SERVICE_DONE, request);
2519 handleCmdCancelProvisionSatelliteService((int) request.argument, onCompleted);
2520 break;
2521 }
2522
2523 case EVENT_CANCEL_PROVISION_SATELLITE_SERVICE_DONE: {
2524 ar = (AsyncResult) msg.obj;
2525 request = (MainThreadRequest) ar.userObj;
2526
2527 if (ar.exception == null) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -08002528 request.result = SatelliteManager.SATELLITE_ERROR_NONE;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002529 log("cancelProvisionSatelliteService succeeded for subId="
2530 + (int) request.argument);
2531 } else {
Thomas Nguyene77de6d2023-02-10 17:42:43 -08002532 request.result = SatelliteManager.SATELLITE_ERROR;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002533 if (ar.exception instanceof CommandException) {
2534 CommandException.Error error =
2535 ((CommandException) (ar.exception)).getCommandError();
2536 request.result = RILUtils.convertToSatelliteError(error);
2537 loge("cancelProvisionSatelliteService CommandException: "
2538 + ar.exception + ", error code:" + request.result);
2539 } else {
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002540 loge("cancelProvisionSatelliteService unknown exception: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002541 + ar.exception);
2542 }
2543 }
2544 notifyRequester(request);
2545 break;
2546 }
2547
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002548 case CMD_SET_SATELLITE_ENABLED: {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002549 request = (MainThreadRequest) msg.obj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002550 onCompleted = obtainMessage(EVENT_SET_SATELLITE_ENABLED_DONE, request);
2551 Pair<Boolean, Consumer<Integer>> argument =
2552 (Pair<Boolean, Consumer<Integer>>) request.argument;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002553 Phone phone = getPhoneFromRequest(request);
2554 if (phone != null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002555 boolean enable = argument.first.booleanValue();
2556 phone.setSatellitePower(onCompleted, enable);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002557 } else {
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002558 loge("setSatelliteEnabled: No phone object");
2559 argument.second.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002560 notifyRequester(request);
2561 }
2562 break;
2563 }
2564
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002565 case EVENT_SET_SATELLITE_ENABLED_DONE: {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002566 ar = (AsyncResult) msg.obj;
2567 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002568 Pair<Boolean, Consumer<Integer>> argument =
2569 (Pair<Boolean, Consumer<Integer>>) request.argument;
2570 int error = getSatelliteError(ar, "setSatelliteEnabled", false);
2571 argument.second.accept(error);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002572 break;
2573 }
2574
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002575 case CMD_IS_SATELLITE_ENABLED: {
Sarah Chin503828c2023-02-01 23:54:20 -08002576 request = (MainThreadRequest) msg.obj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002577 onCompleted = obtainMessage(EVENT_IS_SATELLITE_ENABLED_DONE, request);
Sarah Chin503828c2023-02-01 23:54:20 -08002578 Phone phone = getPhoneFromRequest(request);
2579 if (phone != null) {
2580 phone.isSatellitePowerOn(onCompleted);
2581 } else {
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002582 loge("isSatelliteEnabled: No phone object");
2583 ((ResultReceiver) request.argument).send(
2584 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
Sarah Chin503828c2023-02-01 23:54:20 -08002585 }
2586 break;
2587 }
2588
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002589 case EVENT_IS_SATELLITE_ENABLED_DONE: {
Sarah Chin503828c2023-02-01 23:54:20 -08002590 ar = (AsyncResult) msg.obj;
2591 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002592 int error = getSatelliteError(ar, "isSatelliteEnabled", true);
2593 Bundle bundle = new Bundle();
2594 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
2595 boolean enabled = ((int[]) ar.result)[0] == 1;
2596 if (DBG) log("isSatelliteEnabled: " + enabled);
2597 bundle.putBoolean(SatelliteManager.KEY_SATELLITE_ENABLED, enabled);
Sarah Chin503828c2023-02-01 23:54:20 -08002598 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002599 ((ResultReceiver) request.argument).send(error, bundle);
Sarah Chin503828c2023-02-01 23:54:20 -08002600 break;
2601 }
2602
2603 case CMD_IS_SATELLITE_SUPPORTED: {
2604 request = (MainThreadRequest) msg.obj;
2605 onCompleted = obtainMessage(EVENT_IS_SATELLITE_SUPPORTED_DONE, request);
2606 Phone phone = getPhoneFromRequest(request);
2607 if (phone != null) {
2608 phone.isSatelliteSupported(onCompleted);
2609 } else {
2610 loge("isSatelliteSupported: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002611 ((ResultReceiver) request.argument).send(
2612 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
Sarah Chin503828c2023-02-01 23:54:20 -08002613 }
2614 break;
2615 }
2616
2617 case EVENT_IS_SATELLITE_SUPPORTED_DONE: {
2618 ar = (AsyncResult) msg.obj;
2619 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002620 int error = getSatelliteError(ar, "isSatelliteSupported", true);
2621 Bundle bundle = new Bundle();
2622 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
2623 boolean supported = ((int[]) ar.result)[0] == 1;
2624 if (DBG) log("isSatelliteSupported: " + supported);
2625 bundle.putBoolean(SatelliteManager.KEY_SATELLITE_SUPPORTED, supported);
Thomas Nguyene77de6d2023-02-10 17:42:43 -08002626 synchronized (mIsSatelliteSupportedLock) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002627 mIsSatelliteSupported = supported;
2628 }
2629 } else {
2630 synchronized (mIsSatelliteSupportedLock) {
2631 mIsSatelliteSupported = null;
Thomas Nguyene77de6d2023-02-10 17:42:43 -08002632 }
Sarah Chin503828c2023-02-01 23:54:20 -08002633 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002634 ((ResultReceiver) request.argument).send(error, bundle);
Sarah Chin503828c2023-02-01 23:54:20 -08002635 break;
2636 }
2637
2638 case CMD_GET_SATELLITE_CAPABILITIES: {
2639 request = (MainThreadRequest) msg.obj;
2640 onCompleted = obtainMessage(EVENT_GET_SATELLITE_CAPABILITIES_DONE, request);
2641 Phone phone = getPhoneFromRequest(request);
2642 if (phone != null) {
2643 phone.getSatelliteCapabilities(onCompleted);
2644 } else {
2645 loge("getSatelliteCapabilities: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002646 ((ResultReceiver) request.argument).send(
2647 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
Sarah Chin503828c2023-02-01 23:54:20 -08002648 }
2649 break;
2650 }
2651
2652 case EVENT_GET_SATELLITE_CAPABILITIES_DONE: {
2653 ar = (AsyncResult) msg.obj;
2654 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002655 int error = getSatelliteError(ar, "getSatelliteCapabilities", true);
2656 Bundle bundle = new Bundle();
2657 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
Sarah Chin503828c2023-02-01 23:54:20 -08002658 SatelliteCapabilities capabilities = (SatelliteCapabilities) ar.result;
2659 if (DBG) log("getSatelliteCapabilities: " + capabilities);
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002660 bundle.putParcelable(SatelliteManager.KEY_SATELLITE_CAPABILITIES,
2661 capabilities);
Sarah Chin503828c2023-02-01 23:54:20 -08002662 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002663 ((ResultReceiver) request.argument).send(error, bundle);
Sarah Chin503828c2023-02-01 23:54:20 -08002664 break;
2665 }
2666
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002667 default:
2668 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2669 break;
2670 }
2671 }
Jake Hambye994d462014-02-03 13:10:13 -08002672
Pengquan Menga1bb6272018-09-06 09:59:22 -07002673 private void notifyRequester(MainThreadRequest request) {
2674 synchronized (request) {
2675 request.notifyAll();
2676 }
2677 }
2678
Jake Hambye994d462014-02-03 13:10:13 -08002679 private void handleNullReturnEvent(Message msg, String command) {
2680 AsyncResult ar = (AsyncResult) msg.obj;
2681 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2682 if (ar.exception == null) {
2683 request.result = true;
2684 } else {
2685 request.result = false;
2686 if (ar.exception instanceof CommandException) {
2687 loge(command + ": CommandException: " + ar.exception);
2688 } else {
2689 loge(command + ": Unknown exception");
2690 }
2691 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002692 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002693 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002694 }
2695
2696 /**
2697 * Posts the specified command to be executed on the main thread,
2698 * waits for the request to complete, and returns the result.
2699 * @see #sendRequestAsync
2700 */
2701 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002702 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2703 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002704 }
2705
2706 /**
2707 * Posts the specified command to be executed on the main thread,
2708 * waits for the request to complete, and returns the result.
2709 * @see #sendRequestAsync
2710 */
2711 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2712 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002713 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002714 }
2715
2716 /**
2717 * Posts the specified command to be executed on the main thread,
2718 * waits for the request to complete, and returns the result.
2719 * @see #sendRequestAsync
2720 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002721 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002722 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2723 }
2724
2725 /**
2726 * Posts the specified command to be executed on the main thread,
2727 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2728 * if not timeout or null otherwise.
2729 * @see #sendRequestAsync
2730 */
2731 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2732 long timeoutInMs) {
2733 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002734 }
2735
2736 /**
2737 * Posts the specified command to be executed on the main thread,
2738 * waits for the request to complete, and returns the result.
2739 * @see #sendRequestAsync
2740 */
Nathan Harold92bed182018-10-12 18:16:49 -07002741 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002742 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002743 }
2744
2745 /**
2746 * Posts the specified command to be executed on the main thread,
2747 * waits for the request to complete, and returns the result.
2748 * @see #sendRequestAsync
2749 */
2750 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002751 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2752 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002753 }
2754
2755 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002756 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2757 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2758 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002759 * @see #sendRequestAsync
2760 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002761 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2762 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002763 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2764 throw new RuntimeException("This method will deadlock if called from the main thread.");
2765 }
2766
Nathan Harold92bed182018-10-12 18:16:49 -07002767 MainThreadRequest request = null;
2768 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2769 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2770 } else if (phone != null) {
2771 request = new MainThreadRequest(argument, phone, workSource);
2772 } else {
2773 request = new MainThreadRequest(argument, subId, workSource);
2774 }
2775
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002776 Message msg = mMainThreadHandler.obtainMessage(command, request);
2777 msg.sendToTarget();
2778
Rambo Wang0f050d82021-02-12 11:43:36 -08002779
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002780 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002781 if (timeoutInMs >= 0) {
2782 // Wait for at least timeoutInMs before returning null request result
2783 long now = SystemClock.elapsedRealtime();
2784 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002785 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002786 try {
2787 request.wait(deadline - now);
2788 } catch (InterruptedException e) {
2789 // Do nothing, go back and check if request is completed or timeout
2790 } finally {
2791 now = SystemClock.elapsedRealtime();
2792 }
2793 }
2794 } else {
2795 // Wait for the request to complete
2796 while (request.result == null) {
2797 try {
2798 request.wait();
2799 } catch (InterruptedException e) {
2800 // Do nothing, go back and wait until the request is complete
2801 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002802 }
2803 }
2804 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002805 if (request.result == null) {
2806 Log.wtf(LOG_TAG,
2807 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2808 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002809 return request.result;
2810 }
2811
2812 /**
2813 * Asynchronous ("fire and forget") version of sendRequest():
2814 * Posts the specified command to be executed on the main thread, and
2815 * returns immediately.
2816 * @see #sendRequest
2817 */
2818 private void sendRequestAsync(int command) {
2819 mMainThreadHandler.sendEmptyMessage(command);
2820 }
2821
2822 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002823 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002824 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002825 */
2826 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002827 sendRequestAsync(command, argument, null, null);
2828 }
2829
2830 /**
2831 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2832 * @see {@link #sendRequest(int,Object)}
2833 */
2834 private void sendRequestAsync(
2835 int command, Object argument, Phone phone, WorkSource workSource) {
2836 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002837 Message msg = mMainThreadHandler.obtainMessage(command, request);
2838 msg.sendToTarget();
2839 }
2840
2841 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002842 * Initialize the singleton PhoneInterfaceManager instance.
2843 * This is only done once, at startup, from PhoneApp.onCreate().
2844 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002845 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002846 synchronized (PhoneInterfaceManager.class) {
2847 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002848 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002849 } else {
2850 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2851 }
2852 return sInstance;
2853 }
2854 }
2855
2856 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002857 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002858 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002859 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002860 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002861 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002862 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002863 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002864 mMainThreadHandler = new MainThreadHandler();
Jack Yue37dd262022-12-16 11:53:37 -08002865 if (!PhoneFactory.isSubscriptionManagerServiceEnabled()) {
2866 mSubscriptionController = SubscriptionController.getInstance();
2867 } else {
2868 mSubscriptionController = null;
2869 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002870 mTelephonySharedPreferences =
2871 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002872 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002873 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002874 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002875 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002876 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002877 publish();
arunvoddud7401012022-12-15 16:08:12 +00002878 CarrierAllowListInfo.loadInstance(mApp);
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002879 mSatelliteSupportedReceiver = new ResultReceiver(mMainThreadHandler) {
2880 @Override
2881 protected void onReceiveResult(int resultCode, Bundle resultData) {
2882 if (resultCode == SatelliteManager.SATELLITE_ERROR_NONE
2883 && resultData.containsKey(SatelliteManager.KEY_SATELLITE_SUPPORTED)) {
2884 synchronized (mIsSatelliteSupportedLock) {
2885 mIsSatelliteSupported = resultData.getBoolean(
2886 SatelliteManager.KEY_SATELLITE_SUPPORTED);
2887 }
2888 } else {
2889 synchronized (mIsSatelliteSupportedLock) {
2890 mIsSatelliteSupported = null;
2891 }
2892 }
2893 }
2894 };
2895 requestIsSatelliteSupported(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
2896 mSatelliteSupportedReceiver);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002897 }
2898
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002899 @VisibleForTesting
2900 public SharedPreferences getSharedPreferences() {
2901 return mTelephonySharedPreferences;
2902 }
2903
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002904 /**
2905 * Get the default phone for this device.
2906 */
2907 @VisibleForTesting
2908 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002909 Phone thePhone = getPhone(getDefaultSubscription());
2910 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2911 }
2912
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002913 private void publish() {
2914 if (DBG) log("publish: " + this);
2915
Peter Wangc035ce42020-01-08 21:00:22 -08002916 TelephonyFrameworkInitializer
2917 .getTelephonyServiceManager()
2918 .getTelephonyServiceRegisterer()
2919 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002920 }
2921
Stuart Scott584921c2015-01-15 17:10:34 -08002922 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002923 if (request.phone != null) {
2924 return request.phone;
2925 } else {
2926 return getPhoneFromSubId(request.subId);
2927 }
2928 }
2929
2930 private Phone getPhoneFromSubId(int subId) {
2931 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2932 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002933 }
2934
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002935 /**
2936 * Get phone object associated with a subscription.
2937 * Return default phone if phone object associated with subscription is null
2938 * @param subId - subscriptionId
2939 * @return phone object associated with a subscription or default phone if null.
2940 */
2941 private Phone getPhoneFromSubIdOrDefault(int subId) {
2942 Phone phone = getPhoneFromSubId(subId);
2943 if (phone == null) {
2944 phone = getDefaultPhone();
2945 }
2946 return phone;
2947 }
2948
Rambo Wange53e07d2022-05-10 13:01:13 -07002949 @Nullable
2950 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002951 Phone phone = getPhoneFromRequest(request);
2952 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002953 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002954 }
2955
Wink Saville36469e72014-06-11 15:17:00 -07002956 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002957 private Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002958 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002959 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002960
Kai Shif70f46f2021-03-03 13:59:46 -08002961 private void sendEraseModemConfig(@NonNull Phone phone) {
2962 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2963 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2964 }
2965
2966 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2967 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2968 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002969 }
2970
Peter Wang44b186e2020-01-13 23:33:09 -08002971 private boolean isImsAvailableOnDevice() {
2972 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2973 if (pm == null) {
2974 // For some reason package manger is not available.. This will fail internally anyway,
2975 // so do not throw error and allow.
2976 return true;
2977 }
2978 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2979 }
2980
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002981 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002982 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002983 }
2984
Wink Savilleb564aae2014-10-23 10:18:09 -07002985 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002986 if (DBG) log("dial: " + number);
2987 // No permission check needed here: This is just a wrapper around the
2988 // ACTION_DIAL intent, which is available to any app since it puts up
2989 // the UI before it does anything.
2990
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002991 final long identity = Binder.clearCallingIdentity();
2992 try {
2993 String url = createTelUrl(number);
2994 if (url == null) {
2995 return;
2996 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002997
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002998 // PENDING: should we just silently fail if phone is offhook or ringing?
2999 PhoneConstants.State state = mCM.getState(subId);
3000 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
3001 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
3002 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3003 mApp.startActivity(intent);
3004 }
3005 } finally {
3006 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003007 }
3008 }
3009
3010 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003011 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07003012 }
3013
Wink Savilleb564aae2014-10-23 10:18:09 -07003014 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003015 if (DBG) log("call: " + number);
3016
3017 // This is just a wrapper around the ACTION_CALL intent, but we still
3018 // need to do a permission check since we're calling startActivity()
3019 // from the context of the phone app.
3020 enforceCallPermission();
3021
Jordan Liu1617b712019-07-10 15:06:26 -07003022 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003023 != AppOpsManager.MODE_ALLOWED) {
3024 return;
3025 }
3026
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003027 final long identity = Binder.clearCallingIdentity();
3028 try {
3029 String url = createTelUrl(number);
3030 if (url == null) {
3031 return;
3032 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003033
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003034 boolean isValid = false;
3035 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
3036 if (slist != null) {
3037 for (SubscriptionInfo subInfoRecord : slist) {
3038 if (subInfoRecord.getSubscriptionId() == subId) {
3039 isValid = true;
3040 break;
3041 }
Wink Saville3ab207e2014-11-20 13:07:20 -08003042 }
Wink Saville08874612014-08-31 19:19:58 -07003043 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003044 if (!isValid) {
3045 return;
3046 }
Wink Saville08874612014-08-31 19:19:58 -07003047
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003048 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
3049 intent.putExtra(SUBSCRIPTION_KEY, subId);
3050 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3051 mApp.startActivity(intent);
3052 } finally {
3053 Binder.restoreCallingIdentity(identity);
3054 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003055 }
3056
Wink Savilleb564aae2014-10-23 10:18:09 -07003057 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003058 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07003059 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
3060 }
3061
Wink Savilleb564aae2014-10-23 10:18:09 -07003062 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003063 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07003064 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
3065 }
3066
Wink Savilleb564aae2014-10-23 10:18:09 -07003067 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003068 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003069
3070 final long identity = Binder.clearCallingIdentity();
3071 try {
Michele Berionne5e411512020-11-13 02:36:59 +00003072 Phone phone = getPhone(subId);
3073 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003074 checkSimPin.start();
3075 return checkSimPin.unlockSim(null, pin);
3076 } finally {
3077 Binder.restoreCallingIdentity(identity);
3078 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003079 }
3080
Wink Savilleb564aae2014-10-23 10:18:09 -07003081 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003082 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003083
3084 final long identity = Binder.clearCallingIdentity();
3085 try {
Michele Berionne5e411512020-11-13 02:36:59 +00003086 Phone phone = getPhone(subId);
3087 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003088 checkSimPuk.start();
3089 return checkSimPuk.unlockSim(puk, pin);
3090 } finally {
3091 Binder.restoreCallingIdentity(identity);
3092 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003093 }
3094
3095 /**
Wink Saville9de0f752013-10-22 19:04:03 -07003096 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003097 * a synchronous one.
3098 */
3099 private static class UnlockSim extends Thread {
3100
3101 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00003102 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003103
3104 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07003105 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
3106 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003107
3108 // For replies from SimCard interface
3109 private Handler mHandler;
3110
3111 // For async handler to identify request type
3112 private static final int SUPPLY_PIN_COMPLETE = 100;
3113
Michele Berionne5e411512020-11-13 02:36:59 +00003114 UnlockSim(int phoneId, IccCard simCard) {
3115 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003116 mSimCard = simCard;
3117 }
3118
3119 @Override
3120 public void run() {
3121 Looper.prepare();
3122 synchronized (UnlockSim.this) {
3123 mHandler = new Handler() {
3124 @Override
3125 public void handleMessage(Message msg) {
3126 AsyncResult ar = (AsyncResult) msg.obj;
3127 switch (msg.what) {
3128 case SUPPLY_PIN_COMPLETE:
3129 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
3130 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07003131 mRetryCount = msg.arg1;
3132 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08003133 CommandException.Error error = null;
3134 if (ar.exception instanceof CommandException) {
3135 error = ((CommandException) (ar.exception))
3136 .getCommandError();
3137 }
3138 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07003139 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08003140 } else if (error == CommandException.Error.ABORTED) {
3141 /* When UiccCardApp dispose, handle message and return
3142 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08003143 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07003144 } else {
3145 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
3146 }
3147 } else {
3148 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
3149 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003150 mDone = true;
3151 UnlockSim.this.notifyAll();
3152 }
3153 break;
3154 }
3155 }
3156 };
3157 UnlockSim.this.notifyAll();
3158 }
3159 Looper.loop();
3160 }
3161
3162 /*
3163 * Use PIN or PUK to unlock SIM card
3164 *
3165 * If PUK is null, unlock SIM card with PIN
3166 *
3167 * If PUK is not null, unlock SIM card with PUK and set PIN code
3168 */
Wink Saville9de0f752013-10-22 19:04:03 -07003169 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003170
3171 while (mHandler == null) {
3172 try {
3173 wait();
3174 } catch (InterruptedException e) {
3175 Thread.currentThread().interrupt();
3176 }
3177 }
3178 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
3179
3180 if (puk == null) {
3181 mSimCard.supplyPin(pin, callback);
3182 } else {
3183 mSimCard.supplyPuk(puk, pin, callback);
3184 }
3185
3186 while (!mDone) {
3187 try {
3188 Log.d(LOG_TAG, "wait for done");
3189 wait();
3190 } catch (InterruptedException e) {
3191 // Restore the interrupted status
3192 Thread.currentThread().interrupt();
3193 }
3194 }
3195 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07003196 int[] resultArray = new int[2];
3197 resultArray[0] = mResult;
3198 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00003199
3200 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00003201 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00003202 }
3203
Wink Saville9de0f752013-10-22 19:04:03 -07003204 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003205 }
3206 }
3207
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003208 /**
3209 * This method has been removed due to privacy and stability concerns.
3210 */
3211 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003212 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003213 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
3214 return;
Wink Saville36469e72014-06-11 15:17:00 -07003215 }
3216
Nathan Harold1f889d82020-06-04 17:05:26 -07003217 @Override
3218 public void updateServiceLocationWithPackageName(String callingPackage) {
3219 mApp.getSystemService(AppOpsManager.class)
3220 .checkPackage(Binder.getCallingUid(), callingPackage);
3221
Nathan Haroldf096d982020-11-18 17:18:06 -08003222 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07003223 if (targetSdk > android.os.Build.VERSION_CODES.R) {
3224 // Callers targeting S have no business invoking this method.
3225 return;
3226 }
3227
3228 LocationAccessPolicy.LocationPermissionResult locationResult =
3229 LocationAccessPolicy.checkLocationPermission(mApp,
3230 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3231 .setCallingPackage(callingPackage)
3232 .setCallingFeatureId(null)
3233 .setCallingPid(Binder.getCallingPid())
3234 .setCallingUid(Binder.getCallingUid())
3235 .setMethod("updateServiceLocation")
3236 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3237 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3238 .build());
3239 // Apps that lack location permission have no business calling this method;
3240 // however, because no permission was declared in the public API, denials must
3241 // all be "soft".
3242 switch (locationResult) {
3243 case DENIED_HARD: /* fall through */
3244 case DENIED_SOFT:
3245 return;
3246 }
3247
3248 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003249 final long identity = Binder.clearCallingIdentity();
3250 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07003251 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003252 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07003253 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003254 }
3255 } finally {
3256 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003257 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003258 }
3259
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003260 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003261 @Override
3262 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003263 return isRadioOnWithFeature(callingPackage, null);
3264 }
3265
3266
3267 @Override
3268 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
3269 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
3270 callingFeatureId);
3271 }
3272
3273 @Deprecated
3274 @Override
3275 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
3276 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07003277 }
3278
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003279 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003280 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
3281 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003282 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003283 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003284 return false;
3285 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003286
3287 final long identity = Binder.clearCallingIdentity();
3288 try {
3289 return isRadioOnForSubscriber(subId);
3290 } finally {
3291 Binder.restoreCallingIdentity(identity);
3292 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003293 }
3294
3295 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003296 final long identity = Binder.clearCallingIdentity();
3297 try {
3298 final Phone phone = getPhone(subId);
3299 if (phone != null) {
3300 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
3301 } else {
3302 return false;
3303 }
3304 } finally {
3305 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003306 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003307 }
3308
3309 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003310 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003311 }
Wink Saville36469e72014-06-11 15:17:00 -07003312
Wink Savilleb564aae2014-10-23 10:18:09 -07003313 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003314 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003315
3316 final long identity = Binder.clearCallingIdentity();
3317 try {
3318 final Phone phone = getPhone(subId);
3319 if (phone != null) {
3320 phone.setRadioPower(!isRadioOnForSubscriber(subId));
3321 }
3322 } finally {
3323 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003324 }
Wink Saville36469e72014-06-11 15:17:00 -07003325 }
3326
3327 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003328 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07003329 }
3330
Wink Savilleb564aae2014-10-23 10:18:09 -07003331 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07003332 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003333
3334 final long identity = Binder.clearCallingIdentity();
3335 try {
3336 final Phone phone = getPhone(subId);
3337 if (phone == null) {
3338 return false;
3339 }
3340 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
3341 toggleRadioOnOffForSubscriber(subId);
3342 }
3343 return true;
3344 } finally {
3345 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003346 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003347 }
Wink Saville36469e72014-06-11 15:17:00 -07003348
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003349 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08003350 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003351 /*
3352 * If any of the Radios are available, it will need to be
3353 * shutdown. So return true if any Radio is available.
3354 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003355 final long identity = Binder.clearCallingIdentity();
3356 try {
3357 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3358 Phone phone = PhoneFactory.getPhone(i);
3359 if (phone != null && phone.isRadioAvailable()) return true;
3360 }
3361 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
3362 return false;
3363 } finally {
3364 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003365 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003366 }
3367
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003368 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003369 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003370 enforceModifyPermission();
3371
3372 final long identity = Binder.clearCallingIdentity();
3373 try {
3374 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3375 logv("Shutting down Phone " + i);
3376 shutdownRadioUsingPhoneId(i);
3377 }
3378 } finally {
3379 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003380 }
3381 }
3382
3383 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003384 Phone phone = PhoneFactory.getPhone(phoneId);
3385 if (phone != null && phone.isRadioAvailable()) {
3386 phone.shutdownRadio();
3387 }
3388 }
3389
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003390 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07003391 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003392
Ling Ma83dc5ea2023-01-12 15:06:04 -08003393 if (!turnOn) {
3394 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3395 }
3396
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003397 final long identity = Binder.clearCallingIdentity();
3398 try {
3399 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3400 if (defaultPhone != null) {
3401 defaultPhone.setRadioPower(turnOn);
3402 return true;
3403 } else {
3404 loge("There's no default phone.");
3405 return false;
3406 }
3407 } finally {
3408 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003409 }
Wink Saville36469e72014-06-11 15:17:00 -07003410 }
3411
Wink Savilleb564aae2014-10-23 10:18:09 -07003412 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003413 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003414
Ling Ma83dc5ea2023-01-12 15:06:04 -08003415 if (!turnOn) {
3416 log("setRadioPowerForSubscriber off: subId=" + subId
3417 + ",callingPackage=" + getCurrentPackageName());
3418 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003419 final long identity = Binder.clearCallingIdentity();
3420 try {
3421 final Phone phone = getPhone(subId);
3422 if (phone != null) {
3423 phone.setRadioPower(turnOn);
3424 return true;
3425 } else {
3426 return false;
3427 }
3428 } finally {
3429 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003430 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003431 }
3432
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003433 /**
3434 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3435 * no reason to power it off. When any of the voters want to power it off, it will be turned
3436 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3437 * powering it off, and these radio off votes will be cleared.
3438 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3439 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3440 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3441 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3442 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3443 * check its vote.
3444 *
3445 * @param subId The subscription ID.
3446 * @param reason The reason for powering off radio.
3447 * @return true on success and false on failure.
3448 */
3449 public boolean requestRadioPowerOffForReason(int subId,
3450 @TelephonyManager.RadioPowerReason int reason) {
3451 enforceModifyPermission();
3452
Ling Ma83dc5ea2023-01-12 15:06:04 -08003453 log("requestRadioPowerOffForReason: subId=" + subId
3454 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003455 final long identity = Binder.clearCallingIdentity();
3456 try {
3457 final Phone phone = getPhone(subId);
3458 if (phone != null) {
3459 phone.setRadioPowerForReason(false, reason);
3460 return true;
3461 } else {
3462 return false;
3463 }
3464 } finally {
3465 Binder.restoreCallingIdentity(identity);
3466 }
3467 }
3468
3469 /**
3470 * Remove the vote on powering off the radio for a reason, as requested by
3471 * {@link requestRadioPowerOffForReason}.
3472 *
3473 * @param subId The subscription ID.
3474 * @param reason The reason for powering off radio.
3475 * @return true on success and false on failure.
3476 */
3477 public boolean clearRadioPowerOffForReason(int subId,
3478 @TelephonyManager.RadioPowerReason int reason) {
3479 enforceModifyPermission();
3480
3481 final long identity = Binder.clearCallingIdentity();
3482 try {
3483 final Phone phone = getPhone(subId);
3484 if (phone != null) {
3485 phone.setRadioPowerForReason(true, reason);
3486 return true;
3487 } else {
3488 return false;
3489 }
3490 } finally {
3491 Binder.restoreCallingIdentity(identity);
3492 }
3493 }
3494
3495 /**
3496 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3497 *
3498 * @param subId The subscription ID.
3499 * @param callingPackage The package making the call.
3500 * @param callingFeatureId The feature in the package.
3501 * @return List of reasons for powering off radio.
3502 */
3503 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3504 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3505
3506 final long identity = Binder.clearCallingIdentity();
3507 List result = new ArrayList();
3508 try {
3509 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3510 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3511 return result;
3512 }
3513
3514 final Phone phone = getPhone(subId);
3515 if (phone != null) {
3516 result.addAll(phone.getRadioPowerOffReasons());
3517 }
3518 } finally {
3519 Binder.restoreCallingIdentity(identity);
3520 }
3521 return result;
3522 }
3523
Wink Saville36469e72014-06-11 15:17:00 -07003524 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003525 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003526 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003527 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003528
3529 final long identity = Binder.clearCallingIdentity();
3530 try {
Jack Yu285100e2022-12-02 22:48:35 -08003531 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003532 final Phone phone = getPhone(subId);
3533 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003534 phone.getDataSettingsManager().setDataEnabled(
3535 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003536 return true;
3537 } else {
3538 return false;
3539 }
3540 } finally {
3541 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003542 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003543 }
3544
Wink Saville36469e72014-06-11 15:17:00 -07003545 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003546 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003547 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003548 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003549
3550 final long identity = Binder.clearCallingIdentity();
3551 try {
Jack Yu285100e2022-12-02 22:48:35 -08003552 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003553 final Phone phone = getPhone(subId);
3554 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003555 phone.getDataSettingsManager().setDataEnabled(
3556 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003557 return true;
3558 } else {
3559 return false;
3560 }
3561 } finally {
3562 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003563 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003564 }
3565
Sanket Padawe356d7632015-06-22 14:03:32 -07003566 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003567 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003568 final long identity = Binder.clearCallingIdentity();
3569 try {
3570 final Phone phone = getPhone(subId);
3571 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003572 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003573 } else {
3574 return false;
3575 }
3576 } finally {
3577 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003578 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003579 }
3580
3581 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003582 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003583 }
3584
pkanwarae03a6b2016-11-06 20:37:09 -08003585 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003586 enforceCallPermission();
3587
3588 final long identity = Binder.clearCallingIdentity();
3589 try {
3590 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3591 return;
3592 }
3593 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3594 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3595 } finally {
3596 Binder.restoreCallingIdentity(identity);
3597 }
pkanwar32d516d2016-10-14 19:37:38 -07003598 };
3599
Wink Savilleb564aae2014-10-23 10:18:09 -07003600 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003601 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003602
3603 final long identity = Binder.clearCallingIdentity();
3604 try {
3605 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3606 return false;
3607 }
3608 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3609 } finally {
3610 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003611 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003612 }
3613
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003614 /**
3615 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3616 * tag on getCallState Binder call.
3617 */
3618 @Deprecated
3619 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003620 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003621 if (CompatChanges.isChangeEnabled(
3622 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3623 Binder.getCallingUid())) {
3624 // Do not allow this API to be called on API version 31+, it should only be
3625 // called on old apps using this Binder call directly.
3626 throw new SecurityException("This method can only be used for applications "
3627 + "targeting API version 30 or less.");
3628 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003629 final long identity = Binder.clearCallingIdentity();
3630 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003631 Phone phone = getPhone(getDefaultSubscription());
3632 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3633 PhoneConstantConversions.convertCallState(phone.getState());
3634 } finally {
3635 Binder.restoreCallingIdentity(identity);
3636 }
3637 }
3638
3639 @Override
3640 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3641 if (CompatChanges.isChangeEnabled(
3642 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3643 Binder.getCallingUid())) {
3644 // Check READ_PHONE_STATE for API version 31+
3645 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3646 featureId, "getCallStateForSubscription")) {
3647 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3648 + "targeting API level 31+.");
3649 }
3650 }
3651 final long identity = Binder.clearCallingIdentity();
3652 try {
3653 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003654 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3655 PhoneConstantConversions.convertCallState(phone.getState());
3656 } finally {
3657 Binder.restoreCallingIdentity(identity);
3658 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003659 }
3660
Sanket Padawe356d7632015-06-22 14:03:32 -07003661 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003662 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003663 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003664 }
3665
3666 @Override
3667 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003668 final long identity = Binder.clearCallingIdentity();
3669 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003670 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003671 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003672 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003673 } else {
3674 return PhoneConstantConversions.convertDataState(
3675 PhoneConstants.DataState.DISCONNECTED);
3676 }
3677 } finally {
3678 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003679 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003680 }
3681
Sanket Padawe356d7632015-06-22 14:03:32 -07003682 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003683 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003684 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003685 }
3686
3687 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003688 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003689 final long identity = Binder.clearCallingIdentity();
3690 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003691 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003692 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003693 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003694 } else {
3695 return TelephonyManager.DATA_ACTIVITY_NONE;
3696 }
3697 } finally {
3698 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003699 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003700 }
3701
3702 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003703 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003704 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003705 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003706
3707 LocationAccessPolicy.LocationPermissionResult locationResult =
3708 LocationAccessPolicy.checkLocationPermission(mApp,
3709 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3710 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003711 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003712 .setCallingPid(Binder.getCallingPid())
3713 .setCallingUid(Binder.getCallingUid())
3714 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003715 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003716 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3717 .build());
3718 switch (locationResult) {
3719 case DENIED_HARD:
3720 throw new SecurityException("Not allowed to access cell location");
3721 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003722 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3723 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003724 }
3725
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003726 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003727 final long identity = Binder.clearCallingIdentity();
3728 try {
3729 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003730 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003731 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003732 } finally {
3733 Binder.restoreCallingIdentity(identity);
3734 }
Svetoslav64fad262015-04-14 14:35:21 -07003735 }
3736
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003737 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003738 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003739 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3740 // registered cell info, so return a NULL country instead.
3741 final long identity = Binder.clearCallingIdentity();
3742 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003743 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3744 // Get default phone in this case.
3745 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3746 }
Jack Yu285100e2022-12-02 22:48:35 -08003747 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003748 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003749 if (phone == null) return "";
3750 ServiceStateTracker sst = phone.getServiceStateTracker();
3751 if (sst == null) return "";
3752 LocaleTracker lt = sst.getLocaleTracker();
3753 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003754 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003755 } finally {
3756 Binder.restoreCallingIdentity(identity);
3757 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003758 }
3759
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003760 /**
3761 * This method was removed due to potential issues caused by performing partial
3762 * updates of service state, and lack of a credible use case.
3763 *
3764 * This has the ability to break the telephony implementation by disabling notification of
3765 * changes in device connectivity. DO NOT USE THIS!
3766 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003767 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003768 public void enableLocationUpdates() {
3769 mApp.enforceCallingOrSelfPermission(
3770 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003771 }
3772
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003773 /**
3774 * This method was removed due to potential issues caused by performing partial
3775 * updates of service state, and lack of a credible use case.
3776 *
3777 * This has the ability to break the telephony implementation by disabling notification of
3778 * changes in device connectivity. DO NOT USE THIS!
3779 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003780 @Override
3781 public void disableLocationUpdates() {
3782 mApp.enforceCallingOrSelfPermission(
3783 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003784 }
3785
3786 @Override
3787 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003788 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3789 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003790 try {
3791 mApp.getSystemService(AppOpsManager.class)
3792 .checkPackage(Binder.getCallingUid(), callingPackage);
3793 } catch (SecurityException e) {
3794 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3795 throw e;
3796 }
3797
Nathan Haroldf096d982020-11-18 17:18:06 -08003798 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003799 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3800 throw new SecurityException(
3801 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3802 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003803
Jordan Liu1617b712019-07-10 15:06:26 -07003804 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003805 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3806 return null;
3807 }
Svetoslav64fad262015-04-14 14:35:21 -07003808
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003809 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003810
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003811 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003812 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003813
Nathan Haroldf180aac2018-06-01 18:43:55 -07003814 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3815 for (CellInfo ci : info) {
3816 if (ci instanceof CellInfoGsm) {
3817 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3818 } else if (ci instanceof CellInfoWcdma) {
3819 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3820 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003821 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003822 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003823 }
3824
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003825 private List<CellInfo> getCachedCellInfo() {
3826 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3827 for (Phone phone : PhoneFactory.getPhones()) {
3828 List<CellInfo> info = phone.getAllCellInfo();
3829 if (info != null) cellInfos.addAll(info);
3830 }
3831 return cellInfos;
3832 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003833
3834 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003835 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003836 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003837 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003838
3839 LocationAccessPolicy.LocationPermissionResult locationResult =
3840 LocationAccessPolicy.checkLocationPermission(mApp,
3841 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3842 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003843 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003844 .setCallingPid(Binder.getCallingPid())
3845 .setCallingUid(Binder.getCallingUid())
3846 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003847 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003848 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3849 .build());
3850 switch (locationResult) {
3851 case DENIED_HARD:
3852 throw new SecurityException("Not allowed to access cell info");
3853 case DENIED_SOFT:
3854 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003855 }
3856
Nathan Haroldf096d982020-11-18 17:18:06 -08003857 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003858 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3859 return getCachedCellInfo();
3860 }
3861
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003862 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003863 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003864 final long identity = Binder.clearCallingIdentity();
3865 try {
3866 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3867 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003868 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003869 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003870 if (info != null) cellInfos.addAll(info);
3871 }
3872 return cellInfos;
3873 } finally {
3874 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003875 }
3876 }
3877
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003878 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003879 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3880 String callingFeatureId) {
3881 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3882 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003883 }
3884
3885 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003886 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3887 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003888 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003889 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003890 }
3891
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003892 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3893 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003894 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003895 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003896
3897 LocationAccessPolicy.LocationPermissionResult locationResult =
3898 LocationAccessPolicy.checkLocationPermission(mApp,
3899 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3900 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003901 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003902 .setCallingPid(Binder.getCallingPid())
3903 .setCallingUid(Binder.getCallingUid())
3904 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003905 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3906 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003907 .build());
3908 switch (locationResult) {
3909 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003910 if (TelephonyPermissions
3911 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003912 // Safetynet logging for b/154934934
3913 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3914 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003915 throw new SecurityException("Not allowed to access cell info");
3916 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003917 if (TelephonyPermissions
3918 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003919 // Safetynet logging for b/154934934
3920 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3921 }
Nathan Harold5320c422019-05-09 10:26:08 -07003922 try {
3923 cb.onCellInfo(new ArrayList<CellInfo>());
3924 } catch (RemoteException re) {
3925 // Drop without consequences
3926 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003927 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003928 }
3929
Nathan Harolda939a962019-05-09 10:13:47 -07003930
3931 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003932 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3933
3934 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3935 }
3936
3937 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003938 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003939 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003940 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003941
3942 final long identity = Binder.clearCallingIdentity();
3943 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003944 Phone phone = getPhone(subId);
3945 if (phone == null) {
3946 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3947 } else {
3948 phone.setCellInfoListRate(rateInMillis, workSource);
3949 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003950 } finally {
3951 Binder.restoreCallingIdentity(identity);
3952 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003953 }
3954
Shishir Agrawala9f32182016-04-12 12:00:16 -07003955 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003956 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003957 Phone phone = PhoneFactory.getPhone(slotIndex);
3958 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003959 return null;
3960 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003961 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003962 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003963 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003964 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003965 return null;
3966 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003967
3968 final long identity = Binder.clearCallingIdentity();
3969 try {
3970 return phone.getImei();
3971 } finally {
3972 Binder.restoreCallingIdentity(identity);
3973 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003974 }
3975
3976 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003977 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3978 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3979 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3980 callingFeatureId, "getPrimaryImei")) {
3981 throw new SecurityException("Caller does not have permission");
3982 }
3983 final long identity = Binder.clearCallingIdentity();
3984 try {
3985 for (Phone phone : PhoneFactory.getPhones()) {
3986 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3987 return phone.getImei();
3988 }
3989 }
3990 throw new UnsupportedOperationException("Operation not supported");
3991 } finally {
3992 Binder.restoreCallingIdentity(identity);
3993 }
3994 }
3995
3996 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003997 public String getTypeAllocationCodeForSlot(int slotIndex) {
3998 Phone phone = PhoneFactory.getPhone(slotIndex);
3999 String tac = null;
4000 if (phone != null) {
4001 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07004002 try {
4003 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
4004 } catch (IndexOutOfBoundsException e) {
4005 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
4006 return null;
4007 }
David Kelly5e06a7f2018-03-12 14:10:59 +00004008 }
4009 return tac;
4010 }
4011
4012 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004013 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07004014 try {
4015 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4016 } catch (SecurityException se) {
4017 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
4018 throw new SecurityException("Package " + callingPackage + " does not belong to "
4019 + Binder.getCallingUid());
4020 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004021 Phone phone = PhoneFactory.getPhone(slotIndex);
4022 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07004023 return null;
4024 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004025
Jeff Davidson913390f2018-02-23 17:11:49 -08004026 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07004027 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004028 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004029 return null;
4030 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004031
4032 final long identity = Binder.clearCallingIdentity();
4033 try {
4034 return phone.getMeid();
4035 } finally {
4036 Binder.restoreCallingIdentity(identity);
4037 }
Jack Yu2af8d712017-03-15 17:14:14 -07004038 }
4039
4040 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00004041 public String getManufacturerCodeForSlot(int slotIndex) {
4042 Phone phone = PhoneFactory.getPhone(slotIndex);
4043 String manufacturerCode = null;
4044 if (phone != null) {
4045 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07004046 try {
4047 manufacturerCode =
4048 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
4049 } catch (IndexOutOfBoundsException e) {
4050 Log.e(LOG_TAG, "MEID length shorter than upper index.");
4051 return null;
4052 }
David Kelly5e06a7f2018-03-12 14:10:59 +00004053 }
4054 return manufacturerCode;
4055 }
4056
4057 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004058 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
4059 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004060 Phone phone = PhoneFactory.getPhone(slotIndex);
4061 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004062 return null;
4063 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004064 int subId = phone.getSubId();
4065 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004066 mApp, subId, callingPackage, callingFeatureId,
4067 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004068 return null;
4069 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004070
4071 final long identity = Binder.clearCallingIdentity();
4072 try {
4073 return phone.getDeviceSvn();
4074 } finally {
4075 Binder.restoreCallingIdentity(identity);
4076 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07004077 }
4078
fionaxu43304da2017-11-27 22:51:16 -08004079 @Override
4080 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004081 final long identity = Binder.clearCallingIdentity();
4082 try {
4083 final Phone phone = getPhone(subId);
4084 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
4085 } finally {
4086 Binder.restoreCallingIdentity(identity);
4087 }
fionaxu43304da2017-11-27 22:51:16 -08004088 }
4089
4090 @Override
4091 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004092 final long identity = Binder.clearCallingIdentity();
4093 try {
4094 final Phone phone = getPhone(subId);
4095 return phone == null ? null : phone.getCarrierName();
4096 } finally {
4097 Binder.restoreCallingIdentity(identity);
4098 }
fionaxu43304da2017-11-27 22:51:16 -08004099 }
4100
calvinpanffe225e2018-11-01 19:43:06 +08004101 @Override
chen xu0026ca62019-03-06 15:28:50 -08004102 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08004103 final long identity = Binder.clearCallingIdentity();
4104 try {
4105 final Phone phone = getPhone(subId);
4106 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08004107 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08004108 } finally {
4109 Binder.restoreCallingIdentity(identity);
4110 }
4111 }
4112
4113 @Override
chen xu0026ca62019-03-06 15:28:50 -08004114 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08004115 final long identity = Binder.clearCallingIdentity();
4116 try {
4117 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08004118 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08004119 } finally {
4120 Binder.restoreCallingIdentity(identity);
4121 }
4122 }
4123
chen xu651eec72018-11-11 19:03:44 -08004124 @Override
chen xu864e11c2018-12-06 22:10:03 -08004125 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
4126 if (!isSubscriptionMccMnc) {
4127 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
4128 }
chen xu651eec72018-11-11 19:03:44 -08004129 final Phone phone = PhoneFactory.getPhone(slotIndex);
4130 if (phone == null) {
4131 return TelephonyManager.UNKNOWN_CARRIER_ID;
4132 }
4133 final long identity = Binder.clearCallingIdentity();
4134 try {
4135 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
4136 } finally {
4137 Binder.restoreCallingIdentity(identity);
4138 }
4139 }
4140
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004141 //
4142 // Internal helper methods.
4143 //
4144
Sanket Padaweee13a9b2016-03-08 17:30:28 -08004145 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07004146 * Make sure the caller is the calling package itself
4147 *
4148 * @throws SecurityException if the caller is not the calling package
4149 */
4150 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
4151 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07004152 PackageManager pm = mApp.getBaseContext().createContextAsUser(
4153 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07004154 try {
Grace Jiadbefca02021-04-26 15:13:31 -07004155 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07004156 } catch (PackageManager.NameNotFoundException e) {
4157 // packageUid is -1
4158 }
4159 if (packageUid != callingUid) {
4160 throw new SecurityException(message + ": Package " + callingPackage
4161 + " does not belong to " + callingUid);
4162 }
4163 }
4164
4165 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004166 * Make sure the caller has the MODIFY_PHONE_STATE permission.
4167 *
4168 * @throws SecurityException if the caller does not have the required permission
4169 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00004170 @VisibleForTesting
4171 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004172 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
4173 }
4174
Gil Cukierman1c0eb932022-12-06 22:28:24 +00004175 /**
arunvoddud7401012022-12-15 16:08:12 +00004176 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00004177 *
4178 * @throws SecurityException if the caller does not have the required permission
4179 */
4180 @VisibleForTesting
4181 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00004182 enforceReadPermission(null);
4183 }
4184
4185 /**
4186 * Make sure the caller has the READ_PHONE_STATE permissions.
4187 *
4188 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
4189 */
4190 @VisibleForTesting
4191 public void enforceReadPermission(String msg) {
4192 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00004193 }
4194
Shuo Qian3b6ee772019-11-13 17:43:31 -08004195 private void enforceActiveEmergencySessionPermission() {
4196 mApp.enforceCallingOrSelfPermission(
4197 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
4198 }
4199
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004200 /**
4201 * Make sure the caller has the CALL_PHONE permission.
4202 *
4203 * @throws SecurityException if the caller does not have the required permission
4204 */
4205 private void enforceCallPermission() {
4206 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
4207 }
4208
paulhu5a773602019-08-23 19:17:33 +08004209 private void enforceSettingsPermission() {
4210 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004211 }
4212
Michele Berionne5e411512020-11-13 02:36:59 +00004213 private void enforceRebootPermission() {
4214 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
4215 }
4216
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00004217 /**
4218 * Make sure the caller has SATELLITE_COMMUNICATION permission.
4219 * @param message - log message to print.
4220 * @throws SecurityException if the caller does not have the required permission
4221 */
4222 private void enforceSatelliteCommunicationPermission(String message) {
4223 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
4224 }
4225
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004226 private String createTelUrl(String number) {
4227 if (TextUtils.isEmpty(number)) {
4228 return null;
4229 }
4230
Jake Hambye994d462014-02-03 13:10:13 -08004231 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004232 }
4233
Ihab Awadf9e92732013-12-05 18:02:52 -08004234 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08004235 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004236 }
4237
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07004238 private static void logv(String msg) {
4239 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
4240 }
4241
Ihab Awadf9e92732013-12-05 18:02:52 -08004242 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004243 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
4244 }
4245
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004246 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004247 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07004248 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07004249 }
4250
Sanket Padawe356d7632015-06-22 14:03:32 -07004251 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004252 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004253 final long identity = Binder.clearCallingIdentity();
4254 try {
4255 final Phone phone = PhoneFactory.getPhone(slotIndex);
4256 if (phone == null) {
4257 return PhoneConstants.PHONE_TYPE_NONE;
4258 } else {
4259 return phone.getPhoneType();
4260 }
4261 } finally {
4262 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004263 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004264 }
4265
4266 /**
4267 * Returns the CDMA ERI icon index to display
4268 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004269 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004270 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
4271 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
4272 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004273 }
4274
Sanket Padawe356d7632015-06-22 14:03:32 -07004275 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004276 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
4277 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004278 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004279 mApp, subId, callingPackage, callingFeatureId,
4280 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004281 return -1;
4282 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004283
4284 final long identity = Binder.clearCallingIdentity();
4285 try {
4286 final Phone phone = getPhone(subId);
4287 if (phone != null) {
4288 return phone.getCdmaEriIconIndex();
4289 } else {
4290 return -1;
4291 }
4292 } finally {
4293 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004294 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004295 }
4296
4297 /**
4298 * Returns the CDMA ERI icon mode,
4299 * 0 - ON
4300 * 1 - FLASHING
4301 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004302 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004303 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
4304 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
4305 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004306 }
4307
Sanket Padawe356d7632015-06-22 14:03:32 -07004308 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004309 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
4310 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004311 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004312 mApp, subId, callingPackage, callingFeatureId,
4313 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004314 return -1;
4315 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004316
4317 final long identity = Binder.clearCallingIdentity();
4318 try {
4319 final Phone phone = getPhone(subId);
4320 if (phone != null) {
4321 return phone.getCdmaEriIconMode();
4322 } else {
4323 return -1;
4324 }
4325 } finally {
4326 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004327 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004328 }
4329
4330 /**
4331 * Returns the CDMA ERI text,
4332 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004333 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004334 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
4335 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4336 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004337 }
4338
Sanket Padawe356d7632015-06-22 14:03:32 -07004339 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004340 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4341 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004342 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004343 mApp, subId, callingPackage, callingFeatureId,
4344 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004345 return null;
4346 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004347
4348 final long identity = Binder.clearCallingIdentity();
4349 try {
4350 final Phone phone = getPhone(subId);
4351 if (phone != null) {
4352 return phone.getCdmaEriText();
4353 } else {
4354 return null;
4355 }
4356 } finally {
4357 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004358 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004359 }
4360
4361 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004362 * Returns the CDMA MDN.
4363 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004364 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004365 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004366 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4367 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004368
4369 final long identity = Binder.clearCallingIdentity();
4370 try {
4371 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004372 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004373 return phone.getLine1Number();
4374 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004375 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004376 return null;
4377 }
4378 } finally {
4379 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004380 }
4381 }
4382
4383 /**
4384 * Returns the CDMA MIN.
4385 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004386 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004387 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004388 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4389 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004390
4391 final long identity = Binder.clearCallingIdentity();
4392 try {
4393 final Phone phone = getPhone(subId);
4394 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4395 return phone.getCdmaMin();
4396 } else {
4397 return null;
4398 }
4399 } finally {
4400 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004401 }
4402 }
4403
Hall Liud892bec2018-11-30 14:51:45 -08004404 @Override
4405 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4406 INumberVerificationCallback callback, String callingPackage) {
4407 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4408 != PERMISSION_GRANTED) {
4409 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4410 }
4411 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4412
4413 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4414 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004415 throw new SecurityException("Calling package must be configured in the device config: "
4416 + "calling package: " + callingPackage
4417 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004418 }
4419
4420 if (range == null) {
4421 throw new NullPointerException("Range must be non-null");
4422 }
4423
4424 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004425 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004426
4427 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4428 }
4429
Junda Liuca05d5d2014-08-14 22:36:34 -07004430 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004431 * Returns true if CDMA provisioning needs to run.
4432 */
4433 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004434 final long identity = Binder.clearCallingIdentity();
4435 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004436 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004437 } finally {
4438 Binder.restoreCallingIdentity(identity);
4439 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004440 }
4441
4442 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004443 * Sets the voice mail number of a given subId.
4444 */
4445 @Override
4446 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004447 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4448 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004449
4450 final long identity = Binder.clearCallingIdentity();
4451 try {
4452 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4453 new Pair<String, String>(alphaTag, number), new Integer(subId));
4454 return success;
4455 } finally {
4456 Binder.restoreCallingIdentity(identity);
4457 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004458 }
4459
Ta-wei Yen87c49842016-05-13 21:19:52 -07004460 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004461 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4462 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004463 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4464 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004465 if (!TextUtils.equals(callingPackage, systemDialer)) {
4466 throw new SecurityException("caller must be system dialer");
4467 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004468
4469 final long identity = Binder.clearCallingIdentity();
4470 try {
4471 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4472 if (phoneAccountHandle == null) {
4473 return null;
4474 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004475 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004476 } finally {
4477 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004478 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004479 }
4480
4481 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004482 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4483 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004484 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004485 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004486 mApp, subId, callingPackage, callingFeatureId,
4487 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004488 return null;
4489 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004490
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004491 final long identity = Binder.clearCallingIdentity();
4492 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004493 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004494 } finally {
4495 Binder.restoreCallingIdentity(identity);
4496 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004497 }
4498
4499 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004500 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4501 VisualVoicemailSmsFilterSettings settings) {
4502 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004503
4504 final long identity = Binder.clearCallingIdentity();
4505 try {
4506 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004507 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004508 } finally {
4509 Binder.restoreCallingIdentity(identity);
4510 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004511 }
4512
4513 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004514 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4515 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004516
4517 final long identity = Binder.clearCallingIdentity();
4518 try {
4519 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004520 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004521 } finally {
4522 Binder.restoreCallingIdentity(identity);
4523 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004524 }
4525
4526 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004527 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4528 String callingPackage, int subId) {
4529 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004530
4531 final long identity = Binder.clearCallingIdentity();
4532 try {
4533 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004534 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004535 } finally {
4536 Binder.restoreCallingIdentity(identity);
4537 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004538 }
4539
4540 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004541 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004542 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004543
4544 final long identity = Binder.clearCallingIdentity();
4545 try {
4546 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004547 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004548 } finally {
4549 Binder.restoreCallingIdentity(identity);
4550 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004551 }
4552
4553 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004554 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4555 String callingAttributionTag, int subId, String number, int port, String text,
4556 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004557 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004558 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004559 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07004560 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004561 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4562 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004563 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004564
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004565 /**
fionaxu0152e512016-11-14 13:36:14 -08004566 * Sets the voice activation state of a given subId.
4567 */
4568 @Override
4569 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004570 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4571 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004572
4573 final long identity = Binder.clearCallingIdentity();
4574 try {
4575 final Phone phone = getPhone(subId);
4576 if (phone != null) {
4577 phone.setVoiceActivationState(activationState);
4578 } else {
4579 loge("setVoiceActivationState fails with invalid subId: " + subId);
4580 }
4581 } finally {
4582 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004583 }
4584 }
4585
4586 /**
4587 * Sets the data activation state of a given subId.
4588 */
4589 @Override
4590 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004591 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4592 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004593
4594 final long identity = Binder.clearCallingIdentity();
4595 try {
4596 final Phone phone = getPhone(subId);
4597 if (phone != null) {
4598 phone.setDataActivationState(activationState);
4599 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004600 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004601 }
4602 } finally {
4603 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004604 }
4605 }
4606
4607 /**
4608 * Returns the voice activation state of a given subId.
4609 */
4610 @Override
4611 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004612 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004613
fionaxu0152e512016-11-14 13:36:14 -08004614 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004615 final long identity = Binder.clearCallingIdentity();
4616 try {
4617 if (phone != null) {
4618 return phone.getVoiceActivationState();
4619 } else {
4620 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4621 }
4622 } finally {
4623 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004624 }
4625 }
4626
4627 /**
4628 * Returns the data activation state of a given subId.
4629 */
4630 @Override
4631 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004632 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004633
fionaxu0152e512016-11-14 13:36:14 -08004634 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004635 final long identity = Binder.clearCallingIdentity();
4636 try {
4637 if (phone != null) {
4638 return phone.getDataActivationState();
4639 } else {
4640 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4641 }
4642 } finally {
4643 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004644 }
4645 }
4646
4647 /**
Wink Saville36469e72014-06-11 15:17:00 -07004648 * Returns the unread count of voicemails for a subId
4649 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004650 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004651 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4652 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004653 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004654 mApp, subId, callingPackage, callingFeatureId,
4655 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004656 return 0;
4657 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004658 final long identity = Binder.clearCallingIdentity();
4659 try {
4660 final Phone phone = getPhone(subId);
4661 if (phone != null) {
4662 return phone.getVoiceMessageCount();
4663 } else {
4664 return 0;
4665 }
4666 } finally {
4667 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004668 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004669 }
4670
4671 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004672 * returns true, if the device is in a state where both voice and data
4673 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004674 */
4675 @Override
4676 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004677 final long identity = Binder.clearCallingIdentity();
4678 try {
4679 final Phone phone = getPhone(subId);
4680 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
4681 } finally {
4682 Binder.restoreCallingIdentity(identity);
4683 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004684 }
4685
4686 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004687 * Send the dialer code if called from the current default dialer or the caller has
4688 * carrier privilege.
4689 * @param inputCode The dialer code to send
4690 */
4691 @Override
4692 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004693 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004694 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004695 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4696 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004697 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004698 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004699 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004700 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004701
4702 final long identity = Binder.clearCallingIdentity();
4703 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004704 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004705 } finally {
4706 Binder.restoreCallingIdentity(identity);
4707 }
fionaxu235cc5e2017-03-06 22:25:57 -08004708 }
4709
Pengquan Menga1bb6272018-09-06 09:59:22 -07004710 @Override
4711 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004712 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004713 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4714 mApp, subId, "getNetworkSelectionMode");
shilufc958392020-01-20 11:36:01 -08004715 final long identity = Binder.clearCallingIdentity();
4716 try {
4717 if (!isActiveSubscription(subId)) {
4718 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4719 }
4720 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4721 } finally {
4722 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004723 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004724 }
4725
Brad Ebinger35c841c2018-10-01 10:40:55 -07004726 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004727 public boolean isInEmergencySmsMode() {
4728 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4729 final long identity = Binder.clearCallingIdentity();
4730 try {
4731 for (Phone phone : PhoneFactory.getPhones()) {
4732 if (phone.isInEmergencySmsMode()) {
4733 return true;
4734 }
4735 }
4736 } finally {
4737 Binder.restoreCallingIdentity(identity);
4738 }
4739 return false;
4740 }
4741
shilu366312e2019-12-17 09:28:10 -08004742 /**
4743 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4744 * @param subId The subscription to use to check the configuration.
4745 * @param c The callback that will be used to send the result.
4746 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004747 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004748 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4749 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004750 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004751 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004752
4753 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4754 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4755 "IMS not available on device.");
4756 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004757 final long token = Binder.clearCallingIdentity();
4758 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004759 int slotId = getSlotIndexOrException(subId);
4760 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004761
4762 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4763 if (controller != null) {
4764 ImsManager imsManager = controller.getImsManager(subId);
4765 if (imsManager != null) {
4766 imsManager.addRegistrationCallbackForSubscription(c, subId);
4767 } else {
4768 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4769 }
4770 } else {
4771 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4772 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004773 } catch (ImsException e) {
4774 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004775 } finally {
4776 Binder.restoreCallingIdentity(token);
4777 }
4778 }
4779
shilu366312e2019-12-17 09:28:10 -08004780 /**
4781 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4782 * @param subId The subscription to use to check the configuration.
4783 * @param c The callback that will be used to send the result.
4784 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004785 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004786 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004787 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004788 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004789 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4790 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4791 }
Meng Wangafbc5852019-09-19 17:37:13 -07004792 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004793
Meng Wangafbc5852019-09-19 17:37:13 -07004794 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004795 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4796 if (controller != null) {
4797 ImsManager imsManager = controller.getImsManager(subId);
4798 if (imsManager != null) {
4799 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4800 } else {
4801 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4802 + "is inactive, ignoring unregister.");
4803 // If the ImsManager is not valid, just return, since the callback
4804 // will already have been removed internally.
4805 }
4806 }
Meng Wangafbc5852019-09-19 17:37:13 -07004807 } finally {
4808 Binder.restoreCallingIdentity(token);
4809 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004810 }
4811
Brad Ebingera34a6c22019-10-22 17:36:18 -07004812 /**
4813 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4814 */
4815 @Override
4816 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4817 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4818 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4819 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4820 "IMS not available on device.");
4821 }
4822 final long token = Binder.clearCallingIdentity();
4823 try {
4824 Phone phone = getPhone(subId);
4825 if (phone == null) {
4826 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4827 + subId + "'");
4828 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4829 }
4830 phone.getImsRegistrationState(regState -> {
4831 try {
4832 consumer.accept((regState == null)
4833 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4834 } catch (RemoteException e) {
4835 // Ignore if the remote process is no longer available to call back.
4836 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4837 }
4838 });
4839 } finally {
4840 Binder.restoreCallingIdentity(token);
4841 }
4842 }
4843
4844 /**
4845 * Get the transport type for the IMS service registration state.
4846 */
4847 @Override
4848 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004849 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004850 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004851 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4852 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4853 "IMS not available on device.");
4854 }
4855 final long token = Binder.clearCallingIdentity();
4856 try {
4857 Phone phone = getPhone(subId);
4858 if (phone == null) {
4859 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4860 + subId + "'");
4861 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4862 }
4863 phone.getImsRegistrationTech(regTech -> {
4864 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4865 int regTechConverted = (regTech == null)
4866 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4867 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4868 regTechConverted);
4869 try {
4870 consumer.accept(regTechConverted);
4871 } catch (RemoteException e) {
4872 // Ignore if the remote process is no longer available to call back.
4873 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4874 }
4875 });
4876 } finally {
4877 Binder.restoreCallingIdentity(token);
4878 }
4879 }
4880
shilu366312e2019-12-17 09:28:10 -08004881 /**
4882 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4883 * @param subId The subscription to use to check the configuration.
4884 * @param c The callback that will be used to send the result.
4885 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004886 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004887 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4888 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004889 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004890 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004891 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4892 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4893 "IMS not available on device.");
4894 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004895 final long token = Binder.clearCallingIdentity();
4896 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004897 int slotId = getSlotIndexOrException(subId);
4898 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004899
4900 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4901 if (controller != null) {
4902 ImsManager imsManager = controller.getImsManager(subId);
4903 if (imsManager != null) {
4904 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4905 } else {
4906 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4907 }
4908 } else {
4909 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4910 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004911 } catch (ImsException e) {
4912 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004913 } finally {
4914 Binder.restoreCallingIdentity(token);
4915 }
4916 }
4917
shilu366312e2019-12-17 09:28:10 -08004918 /**
4919 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4920 * @param subId The subscription to use to check the configuration.
4921 * @param c The callback that will be used to send the result.
4922 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004923 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004924 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004925 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004926 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004927 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4928 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4929 }
Meng Wangafbc5852019-09-19 17:37:13 -07004930
4931 final long token = Binder.clearCallingIdentity();
4932 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004933 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4934 if (controller != null) {
4935 ImsManager imsManager = controller.getImsManager(subId);
4936 if (imsManager != null) {
4937 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4938 } else {
4939 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4940 + " is inactive, ignoring unregister.");
4941 // If the ImsManager is not valid, just return, since the callback
4942 // will already have been removed internally.
4943 }
4944 }
Meng Wangafbc5852019-09-19 17:37:13 -07004945 } finally {
4946 Binder.restoreCallingIdentity(token);
4947 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004948 }
4949
4950 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004951 public boolean isCapable(int subId, int capability, int regTech) {
4952 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004953 final long token = Binder.clearCallingIdentity();
4954 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004955 int slotId = getSlotIndexOrException(subId);
4956 verifyImsMmTelConfiguredOrThrow(slotId);
4957 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4958 } catch (com.android.ims.ImsException e) {
4959 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4960 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004961 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004962 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4963 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004964 } finally {
4965 Binder.restoreCallingIdentity(token);
4966 }
4967 }
4968
4969 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004970 public boolean isAvailable(int subId, int capability, int regTech) {
4971 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004972 final long token = Binder.clearCallingIdentity();
4973 try {
4974 Phone phone = getPhone(subId);
4975 if (phone == null) return false;
4976 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004977 } catch (com.android.ims.ImsException e) {
4978 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4979 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004980 } finally {
4981 Binder.restoreCallingIdentity(token);
4982 }
4983 }
4984
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004985 /**
4986 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4987 * subscription.
4988 * @param subId The subscription to use to check the configuration.
4989 * @param callback The callback that will be used to send the result.
4990 * @param capability The MmTelFeature capability that will be used to send the result.
4991 * @param transportType The transport type of the MmTelFeature capability.
4992 */
4993 @Override
4994 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4995 int transportType) {
4996 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004997 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4998 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4999 "IMS not available on device.");
5000 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005001 final long token = Binder.clearCallingIdentity();
5002 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005003 int slotId = getSlotIndex(subId);
5004 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5005 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
5006 + subId + "'");
5007 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5008 }
5009 verifyImsMmTelConfiguredOrThrow(slotId);
5010 ImsManager.getInstance(mApp, slotId).isSupported(capability,
5011 transportType, aBoolean -> {
5012 try {
5013 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
5014 } catch (RemoteException e) {
5015 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
5016 + "running. Ignore");
5017 }
5018 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005019 } catch (ImsException e) {
5020 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005021 } finally {
5022 Binder.restoreCallingIdentity(token);
5023 }
5024 }
5025
shilu366312e2019-12-17 09:28:10 -08005026 /**
5027 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5028 * @param subId The subscription to use to check the configuration.
5029 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005030 @Override
5031 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005032 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005033 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08005034
Brad Ebinger35c841c2018-10-01 10:40:55 -07005035 final long token = Binder.clearCallingIdentity();
5036 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005037 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005038 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005039 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005040 } catch (ImsException e) {
5041 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005042 } finally {
5043 Binder.restoreCallingIdentity(token);
5044 }
5045 }
5046
5047 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005048 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005049 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005050 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005051 final long identity = Binder.clearCallingIdentity();
5052 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005053 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005054 // This setting doesn't require an active ImsService connection, so do not verify. The
5055 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005056 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005057 } catch (ImsException e) {
5058 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005059 } finally {
5060 Binder.restoreCallingIdentity(identity);
5061 }
5062 }
5063
shilu366312e2019-12-17 09:28:10 -08005064 /**
5065 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5066 * @param subId The subscription to use to check the configuration.
5067 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005068 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005069 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005070 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005071 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005072 final long identity = Binder.clearCallingIdentity();
5073 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005074 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005075 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005076 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005077 } catch (ImsException e) {
5078 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005079 } finally {
5080 Binder.restoreCallingIdentity(identity);
5081 }
5082 }
5083
5084 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005085 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005086 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005087 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005088 final long identity = Binder.clearCallingIdentity();
5089 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005090 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005091 // This setting doesn't require an active ImsService connection, so do not verify. The
5092 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005093 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005094 } catch (ImsException e) {
5095 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005096 } finally {
5097 Binder.restoreCallingIdentity(identity);
5098 }
5099 }
5100
shilu366312e2019-12-17 09:28:10 -08005101 /**
5102 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5103 * @param subId The subscription to use to check the configuration.
5104 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005105 @Override
5106 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005107 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005108 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005109 final long identity = Binder.clearCallingIdentity();
5110 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005111 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005112 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005113 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005114 } catch (ImsException e) {
5115 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005116 } finally {
5117 Binder.restoreCallingIdentity(identity);
5118 }
5119 }
5120
5121 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005122 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005123 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005124 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005125 final long identity = Binder.clearCallingIdentity();
5126 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005127 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005128 // This setting doesn't require an active ImsService connection, so do not verify. The
5129 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005130 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005131 } catch (ImsException e) {
5132 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005133 } finally {
5134 Binder.restoreCallingIdentity(identity);
5135 }
5136 }
5137
shilu366312e2019-12-17 09:28:10 -08005138 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005139 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5140 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5141 * @param subId The subscription to use to check the configuration.
5142 */
5143 @Override
5144 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005145 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005146 mApp, subId, "isCrossSimCallingEnabledByUser");
5147 final long identity = Binder.clearCallingIdentity();
5148 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005149 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005150 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005151 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005152 } catch (ImsException e) {
5153 throw new ServiceSpecificException(e.getCode());
5154 } finally {
5155 Binder.restoreCallingIdentity(identity);
5156 }
5157 }
5158
5159 /**
5160 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5161 * Requires MODIFY_PHONE_STATE permission.
5162 * @param subId The subscription to use to check the configuration.
5163 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5164 * false otherwise
5165 */
5166 @Override
5167 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5168 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5169 "setCrossSimCallingEnabled");
5170 final long identity = Binder.clearCallingIdentity();
5171 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005172 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005173 // This setting doesn't require an active ImsService connection, so do not verify. The
5174 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005175 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005176 } catch (ImsException e) {
5177 throw new ServiceSpecificException(e.getCode());
5178 } finally {
5179 Binder.restoreCallingIdentity(identity);
5180 }
5181 }
5182
5183 /**
shilu366312e2019-12-17 09:28:10 -08005184 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5185 * @param subId The subscription to use to check the configuration.
5186 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005187 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005188
Brad Ebinger35c841c2018-10-01 10:40:55 -07005189 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005190 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005191 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005192 final long identity = Binder.clearCallingIdentity();
5193 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005194 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005195 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005196 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005197 } catch (ImsException e) {
5198 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005199 } finally {
5200 Binder.restoreCallingIdentity(identity);
5201 }
5202 }
5203
5204 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005205 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005206 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005207 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005208 final long identity = Binder.clearCallingIdentity();
5209 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005210 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005211 // This setting doesn't require an active ImsService connection, so do not verify. The
5212 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005213 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005214 } catch (ImsException e) {
5215 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005216 } finally {
5217 Binder.restoreCallingIdentity(identity);
5218 }
5219 }
5220
5221 @Override
5222 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5223 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5224 "setVoWiFiNonPersistent");
5225 final long identity = Binder.clearCallingIdentity();
5226 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005227 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005228 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005229 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005230 } catch (ImsException e) {
5231 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005232 } finally {
5233 Binder.restoreCallingIdentity(identity);
5234 }
5235 }
5236
shilu366312e2019-12-17 09:28:10 -08005237 /**
5238 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5239 * @param subId The subscription to use to check the configuration.
5240 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005241 @Override
5242 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005243 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005244 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005245 final long identity = Binder.clearCallingIdentity();
5246 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005247 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005248 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005249 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005250 } catch (ImsException e) {
5251 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005252 } finally {
5253 Binder.restoreCallingIdentity(identity);
5254 }
5255 }
5256
5257 @Override
5258 public void setVoWiFiModeSetting(int subId, int mode) {
5259 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5260 "setVoWiFiModeSetting");
5261 final long identity = Binder.clearCallingIdentity();
5262 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005263 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005264 // This setting doesn't require an active ImsService connection, so do not verify. The
5265 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005266 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005267 } catch (ImsException e) {
5268 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005269 } finally {
5270 Binder.restoreCallingIdentity(identity);
5271 }
5272 }
5273
5274 @Override
5275 public int getVoWiFiRoamingModeSetting(int subId) {
5276 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
5277 final long identity = Binder.clearCallingIdentity();
5278 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005279 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005280 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005281 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005282 } catch (ImsException e) {
5283 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005284 } finally {
5285 Binder.restoreCallingIdentity(identity);
5286 }
5287 }
5288
5289 @Override
5290 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5291 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5292 "setVoWiFiRoamingModeSetting");
5293 final long identity = Binder.clearCallingIdentity();
5294 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005295 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005296 // This setting doesn't require an active ImsService connection, so do not verify. The
5297 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005298 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005299 } catch (ImsException e) {
5300 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005301 } finally {
5302 Binder.restoreCallingIdentity(identity);
5303 }
5304 }
5305
5306 @Override
5307 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5308 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5309 "setRttCapabilityEnabled");
5310 final long identity = Binder.clearCallingIdentity();
5311 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005312 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005313 // This setting doesn't require an active ImsService connection, so do not verify. The
5314 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005315 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005316 } catch (ImsException e) {
5317 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005318 } finally {
5319 Binder.restoreCallingIdentity(identity);
5320 }
5321 }
5322
shilu366312e2019-12-17 09:28:10 -08005323 /**
5324 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5325 * @param subId The subscription to use to check the configuration.
5326 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005327 @Override
5328 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005329 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005330 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005331 final long identity = Binder.clearCallingIdentity();
5332 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005333 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005334 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005335 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005336 } catch (ImsException e) {
5337 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005338 } finally {
5339 Binder.restoreCallingIdentity(identity);
5340 }
5341 }
5342
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005343 @Override
5344 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5345 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005346
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005347 final long identity = Binder.clearCallingIdentity();
5348 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005349 if (!isImsAvailableOnDevice()) {
5350 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5351 "IMS not available on device.");
5352 }
5353 int slotId = getSlotIndexOrException(subId);
5354 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005355
5356 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5357 if (controller != null) {
5358 ImsManager imsManager = controller.getImsManager(subId);
5359 if (imsManager != null) {
5360 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5361 } else {
5362 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5363 }
5364 } else {
5365 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5366 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005367 } catch (ImsException e) {
5368 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005369 } finally {
5370 Binder.restoreCallingIdentity(identity);
5371 }
5372 }
5373
5374 @Override
5375 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5376 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005377
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005378 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005379 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5380 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5381 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005382 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005383 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5384 if (controller != null) {
5385 ImsManager imsManager = controller.getImsManager(subId);
5386 if (imsManager != null) {
5387 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5388 } else {
5389 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5390 + " is inactive, ignoring unregister.");
5391 // If the ImsManager is not valid, just return, since the callback will already
5392 // have been removed internally.
5393 }
5394 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005395 } finally {
5396 Binder.restoreCallingIdentity(identity);
5397 }
5398 }
5399
joonhunshincffb7fc2021-11-28 07:32:01 +00005400 @Override
5401 public void registerFeatureProvisioningChangedCallback(int subId,
5402 IFeatureProvisioningCallback callback) {
5403 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5404 mApp, subId, "registerFeatureProvisioningChangedCallback");
5405
5406 final long identity = Binder.clearCallingIdentity();
5407 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5408 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5409 }
5410
joonhunshin91bc1952022-04-29 08:47:15 +00005411 try {
5412 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5413 if (controller == null) {
5414 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5415 "Device does not support IMS");
5416 }
5417 controller.addFeatureProvisioningChangedCallback(subId, callback);
5418 } finally {
5419 Binder.restoreCallingIdentity(identity);
5420 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005421 }
5422
5423 @Override
5424 public void unregisterFeatureProvisioningChangedCallback(int subId,
5425 IFeatureProvisioningCallback callback) {
5426 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5427 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5428
5429 final long identity = Binder.clearCallingIdentity();
5430 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5431 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5432 }
5433
joonhunshin91bc1952022-04-29 08:47:15 +00005434 try {
5435 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5436 if (controller == null) {
5437 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5438 return;
5439 }
5440 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5441 } finally {
5442 Binder.restoreCallingIdentity(identity);
5443 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005444 }
allenwtsu99c623b2020-01-03 18:24:23 +08005445
5446 private void checkModifyPhoneStatePermission(int subId, String message) {
5447 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5448 message);
5449 }
5450
allenwtsu99c623b2020-01-03 18:24:23 +08005451 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005452 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005453 boolean isProvisioned) {
5454 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5455
5456 final long identity = Binder.clearCallingIdentity();
5457 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005458 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5459 if (controller == null) {
5460 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5461 return;
5462 }
5463 controller.setRcsProvisioningStatusForCapability(
5464 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005465 } finally {
5466 Binder.restoreCallingIdentity(identity);
5467 }
allenwtsu99c623b2020-01-03 18:24:23 +08005468 }
5469
5470
5471 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005472 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5473 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5474 mApp, subId, "getRcsProvisioningStatusForCapability");
5475
allenwtsu99c623b2020-01-03 18:24:23 +08005476 final long identity = Binder.clearCallingIdentity();
5477 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005478 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5479 if (controller == null) {
5480 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5481
5482 // device does not support IMS, this method will return true always.
5483 return true;
5484 }
5485 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005486 } finally {
5487 Binder.restoreCallingIdentity(identity);
5488 }
5489 }
5490
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005491 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005492 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5493 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005494 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005495
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005496 final long identity = Binder.clearCallingIdentity();
5497 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005498 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5499 if (controller == null) {
5500 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5501 return;
5502 }
5503 controller.setImsProvisioningStatusForCapability(
5504 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005505 } finally {
5506 Binder.restoreCallingIdentity(identity);
5507 }
5508 }
5509
5510 @Override
5511 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005512 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5513 mApp, subId, "getProvisioningStatusForCapability");
5514
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005515 final long identity = Binder.clearCallingIdentity();
5516 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005517 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5518 if (controller == null) {
5519 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005520
joonhunshin91bc1952022-04-29 08:47:15 +00005521 // device does not support IMS, this method will return true always.
5522 return true;
5523 }
5524 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005525 } finally {
5526 Binder.restoreCallingIdentity(identity);
5527 }
5528 }
5529
5530 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005531 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5532 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5533 mApp, subId, "isProvisioningRequiredForCapability");
5534
5535 final long identity = Binder.clearCallingIdentity();
5536 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005537 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5538 if (controller == null) {
5539 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5540
5541 // device does not support IMS, this method will return false
5542 return false;
5543 }
5544 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005545 } finally {
5546 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005547 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005548 }
5549
5550 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005551 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5552 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5553 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005554
joonhunshincffb7fc2021-11-28 07:32:01 +00005555 final long identity = Binder.clearCallingIdentity();
5556 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005557 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5558 if (controller == null) {
5559 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5560
5561 // device does not support IMS, this method will return false
5562 return false;
5563 }
5564 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005565 } finally {
5566 Binder.restoreCallingIdentity(identity);
5567 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005568 }
5569
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005570 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005571 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005572 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5573 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5574 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005575 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5576 mApp, subId, "getImsProvisioningInt");
5577
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005578 final long identity = Binder.clearCallingIdentity();
5579 try {
5580 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005581 int slotId = getSlotIndex(subId);
5582 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5583 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5584 + subId + "' for key:" + key);
5585 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5586 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005587
joonhunshin91bc1952022-04-29 08:47:15 +00005588 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5589 if (controller == null) {
5590 loge("getImsProvisioningInt: Device does not support IMS");
5591
5592 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5593 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5594 }
5595 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005596 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5597 return retVal;
5598 }
5599
calvinpanb5a34062021-02-08 19:59:36 +08005600 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005601 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005602 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5603 + subId + "' for key:" + key);
5604 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005605 } finally {
5606 Binder.restoreCallingIdentity(identity);
5607 }
5608 }
5609
5610 @Override
5611 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005612 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5613 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5614 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005615 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5616 mApp, subId, "getImsProvisioningString");
5617
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005618 final long identity = Binder.clearCallingIdentity();
5619 try {
5620 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005621 int slotId = getSlotIndex(subId);
5622 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5623 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5624 + subId + "' for key:" + key);
5625 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5626 }
calvinpanb5a34062021-02-08 19:59:36 +08005627 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005628 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005629 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5630 + subId + "' for key:" + key);
5631 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005632 } finally {
5633 Binder.restoreCallingIdentity(identity);
5634 }
5635 }
5636
5637 @Override
5638 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005639 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5640 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5641 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005642 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5643 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005644
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005645 final long identity = Binder.clearCallingIdentity();
5646 try {
5647 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005648 int slotId = getSlotIndex(subId);
5649 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5650 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5651 + subId + "' for key:" + key);
5652 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5653 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005654
joonhunshin91bc1952022-04-29 08:47:15 +00005655 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5656 if (controller == null) {
5657 loge("setImsProvisioningInt: Device does not support IMS");
5658
5659 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5660 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5661 }
5662 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005663 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5664 return retVal;
5665 }
5666
calvinpanb5a34062021-02-08 19:59:36 +08005667 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5668 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005669 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005670 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005671 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005672 } finally {
5673 Binder.restoreCallingIdentity(identity);
5674 }
5675 }
5676
5677 @Override
5678 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005679 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5680 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5681 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005682 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5683 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005684 final long identity = Binder.clearCallingIdentity();
5685 try {
5686 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005687 int slotId = getSlotIndex(subId);
5688 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5689 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5690 + subId + "' for key:" + key);
5691 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5692 }
calvinpanb5a34062021-02-08 19:59:36 +08005693 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5694 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005695 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005696 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005697 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005698 } finally {
5699 Binder.restoreCallingIdentity(identity);
5700 }
5701 }
5702
Brad Ebinger919631e2021-06-02 17:46:35 -07005703 /**
5704 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5705 * for the given slot ID or no ImsResolver instance has been created.
5706 * @param slotId The slot ID that the IMS service is created for.
5707 * @throws ImsException If there is no ImsService configured for this slot.
5708 */
5709 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5710 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5711 ImsFeature.FEATURE_MMTEL)) {
5712 throw new ImsException("This subscription does not support MMTEL over IMS",
5713 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5714 }
5715 }
5716
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005717 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005718 int slotId = SubscriptionManager.getSlotIndex(subId);
5719 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005720 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5721 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005722 }
5723 return slotId;
5724 }
5725
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005726 private int getSlotIndex(int subId) {
5727 int slotId = SubscriptionManager.getSlotIndex(subId);
5728 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5729 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5730 }
5731 return slotId;
5732 }
5733
Wink Saville36469e72014-06-11 15:17:00 -07005734 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005735 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005736 */
5737 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005738 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5739 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005740 try {
5741 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5742 } catch (SecurityException se) {
5743 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5744 throw new SecurityException("Package " + callingPackage + " does not belong to "
5745 + Binder.getCallingUid());
5746 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005747 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005748 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005749 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005750 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005751 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005752 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005753 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005754 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5755 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005756
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005757 final long identity = Binder.clearCallingIdentity();
5758 try {
5759 final Phone phone = getPhone(subId);
5760 if (phone != null) {
5761 return phone.getServiceState().getDataNetworkType();
5762 } else {
5763 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5764 }
5765 } finally {
5766 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005767 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005768 }
5769
5770 /**
5771 * Returns the data network type
5772 */
5773 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005774 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005775 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005776 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005777 }
5778
5779 /**
5780 * Returns the data network type for a subId
5781 */
5782 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005783 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5784 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005785 String functionName = "getDataNetworkTypeForSubscriber";
5786 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5787 mApp, functionName)) {
5788 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5789 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5790 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5791 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005792 }
5793
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005794 final long identity = Binder.clearCallingIdentity();
5795 try {
5796 final Phone phone = getPhone(subId);
5797 if (phone != null) {
5798 return phone.getServiceState().getDataNetworkType();
5799 } else {
5800 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5801 }
5802 } finally {
5803 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005804 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005805 }
5806
5807 /**
Wink Saville36469e72014-06-11 15:17:00 -07005808 * Returns the Voice network type for a subId
5809 */
5810 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005811 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5812 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005813 String functionName = "getVoiceNetworkTypeForSubscriber";
5814 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5815 mApp, functionName)) {
5816 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5817 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5818 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5819 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005820 }
5821
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005822 final long identity = Binder.clearCallingIdentity();
5823 try {
5824 final Phone phone = getPhone(subId);
5825 if (phone != null) {
5826 return phone.getServiceState().getVoiceNetworkType();
5827 } else {
5828 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5829 }
5830 } finally {
5831 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005832 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005833 }
5834
5835 /**
5836 * @return true if a ICC card is present
5837 */
5838 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005839 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005840 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005841 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005842 }
5843
5844 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005845 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005846 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005847 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005848 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005849 final long identity = Binder.clearCallingIdentity();
5850 try {
5851 final Phone phone = PhoneFactory.getPhone(slotIndex);
5852 if (phone != null) {
5853 return phone.getIccCard().hasIccCard();
5854 } else {
5855 return false;
5856 }
5857 } finally {
5858 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005859 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005860 }
5861
5862 /**
5863 * Return if the current radio is LTE on CDMA. This
5864 * is a tri-state return value as for a period of time
5865 * the mode may be unknown.
5866 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005867 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005868 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005869 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005870 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005871 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005872 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5873 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5874 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005875 }
5876
Sanket Padawe356d7632015-06-22 14:03:32 -07005877 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005878 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5879 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005880 try {
5881 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5882 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005883 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5884 }
5885
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005886 final long identity = Binder.clearCallingIdentity();
5887 try {
5888 final Phone phone = getPhone(subId);
5889 if (phone == null) {
5890 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5891 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005892 return TelephonyProperties.lte_on_cdma_device()
5893 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005894 }
5895 } finally {
5896 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005897 }
Wink Saville36469e72014-06-11 15:17:00 -07005898 }
5899
Wink Saville36469e72014-06-11 15:17:00 -07005900 /**
5901 * {@hide}
5902 * Returns Default subId, 0 in the case of single standby.
5903 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005904 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005905 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005906 }
5907
Shishir Agrawala9f32182016-04-12 12:00:16 -07005908 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005909 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005910 }
5911
Wink Savilleb564aae2014-10-23 10:18:09 -07005912 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005913 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005914 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005915
Pengquan Menge92a50d2018-09-21 15:54:48 -07005916 private boolean isActiveSubscription(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08005917 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08005918 return getSubscriptionManagerService().isActiveSubId(subId,
Jack Yu285100e2022-12-02 22:48:35 -08005919 mApp.getOpPackageName(), mApp.getFeatureId());
5920 }
Pengquan Menge92a50d2018-09-21 15:54:48 -07005921 return mSubscriptionController.isActiveSubId(subId);
5922 }
5923
Ihab Awadf2177b72013-11-25 13:33:23 -08005924 /**
5925 * @see android.telephony.TelephonyManager.WifiCallingChoices
5926 */
5927 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005928 final long identity = Binder.clearCallingIdentity();
5929 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005930 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005931 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5932 getWhenToMakeWifiCallsDefaultPreference());
5933 } finally {
5934 Binder.restoreCallingIdentity(identity);
5935 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005936 }
5937
5938 /**
5939 * @see android.telephony.TelephonyManager.WifiCallingChoices
5940 */
5941 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005942 final long identity = Binder.clearCallingIdentity();
5943 try {
5944 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005945 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005946 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5947 } finally {
5948 Binder.restoreCallingIdentity(identity);
5949 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005950 }
5951
Sailesh Nepald1e68152013-12-12 19:08:02 -08005952 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005953 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005954 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005955 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005956
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005957 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5958 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5959 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005960 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005961 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005962 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005963 }
5964 return PhoneFactory.getPhone(phoneId);
5965 }
5966
Shishir Agrawal566b7612013-10-28 14:41:00 -07005967 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005968 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005969 @NonNull IccLogicalChannelRequest request) {
5970 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5971 /*message=*/ "iccOpenLogicalChannel");
5972
5973 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5974 // Verify that the callingPackage in the request belongs to the calling UID
5975 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5976
5977 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005978 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005979
Rambo Wanga1782702021-11-10 20:15:19 -08005980 private Phone getPhoneFromValidIccLogicalChannelRequest(
5981 @NonNull IccLogicalChannelRequest request, String message) {
5982 Phone phone;
5983 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5984 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5985 mApp, request.subId, message);
5986 phone = getPhoneFromSubId(request.subId);
5987 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5988 enforceModifyPermission();
5989 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5990 } else {
5991 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005992 }
Rambo Wanga1782702021-11-10 20:15:19 -08005993 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005994 }
5995
5996 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005997 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005998 final long identity = Binder.clearCallingIdentity();
5999 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006000 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006001 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006002 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6003 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08006004 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
6005 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006006 loge("The calling package is not allowed to access ISD-R.");
6007 throw new SecurityException(
6008 "The calling package is not allowed to access ISD-R.");
6009 }
Derek Tan740e1672017-06-27 14:56:27 -07006010 }
Derek Tan740e1672017-06-27 14:56:27 -07006011
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006012 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08006013 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
6014 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006015 return response;
6016 } finally {
6017 Binder.restoreCallingIdentity(identity);
6018 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006019 }
6020
6021 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08006022 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
6023 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6024 /*message=*/"iccCloseLogicalChannel");
6025
6026 if (DBG) log("iccCloseLogicalChannel: request=" + request);
6027
6028 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006029 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006030
Rambo Wanga1782702021-11-10 20:15:19 -08006031 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
6032 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08006033 // before this feature is enabled, this API should only return false if
6034 // the operation fails instead of throwing runtime exception for
6035 // backward-compatibility.
6036 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
6037 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006038 final long identity = Binder.clearCallingIdentity();
6039 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006040 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006041 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006042 }
Chen Xue9d737e2022-01-01 23:41:31 -08006043 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006044 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006045 Boolean success = false;
6046 if (result instanceof RuntimeException) {
6047 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006048 if (shouldThrowExceptionOnFailure) {
6049 throw (RuntimeException) result;
6050 } else {
6051 return false;
6052 }
Chen Xue9d737e2022-01-01 23:41:31 -08006053 } else if (result instanceof Boolean) {
6054 success = (Boolean) result;
6055 } else {
6056 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6057 }
Rambo Wanga1782702021-11-10 20:15:19 -08006058 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006059 return success;
6060 } finally {
6061 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006062 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006063 }
6064
6065 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006066 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006067 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006068 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6069 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08006070 if (DBG) {
6071 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6072 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6073 + p3 + " data=" + data);
6074 }
6075 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6076 command, p1, p2, p3, data);
6077 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006078
Jordan Liu4c733742019-02-28 12:03:40 -08006079 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006080 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006081 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006082 enforceModifyPermission();
6083 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006084 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006085 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6086 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006087 }
6088 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006089 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6090 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006091 }
6092
6093 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6094 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006095 final long identity = Binder.clearCallingIdentity();
6096 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006097 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006098 return "";
6099 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006100
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006101 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006102 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6103 null /* workSource */);
6104 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006105
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006106 // Append the returned status code to the end of the response payload.
6107 String s = Integer.toHexString(
6108 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6109 if (response.payload != null) {
6110 s = IccUtils.bytesToHexString(response.payload) + s;
6111 }
6112 return s;
6113 } finally {
6114 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006115 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006116 }
Jake Hambye994d462014-02-03 13:10:13 -08006117
Evan Charltonc66da362014-05-16 14:06:40 -07006118 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006119 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6120 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006121 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6122 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006123 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08006124 if (DBG) {
6125 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6126 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6127 }
6128 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6129 cla, command, p1, p2, p3, data);
6130 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006131
Jordan Liu4c733742019-02-28 12:03:40 -08006132 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006133 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006134 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006135 enforceModifyPermission();
6136 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
6137 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006138 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006139 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6140 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006141 }
6142
6143 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006144 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6145 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006146 }
6147
6148 // open APDU basic channel assuming the caller has sufficient permissions
6149 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6150 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006151 final long identity = Binder.clearCallingIdentity();
6152 try {
6153 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6154 && TextUtils.equals(ISDR_AID, data)) {
6155 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006156 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6157 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006158 if (bestComponent == null
6159 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6160 loge("The calling package is not allowed to select ISD-R.");
6161 throw new SecurityException(
6162 "The calling package is not allowed to select ISD-R.");
6163 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006164 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006165
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006166 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006167 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6168 null /* workSource */);
6169 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006170
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006171 // Append the returned status code to the end of the response payload.
6172 String s = Integer.toHexString(
6173 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6174 if (response.payload != null) {
6175 s = IccUtils.bytesToHexString(response.payload) + s;
6176 }
6177 return s;
6178 } finally {
6179 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006180 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006181 }
6182
6183 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006184 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006185 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006186 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6187 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006188
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006189 final long identity = Binder.clearCallingIdentity();
6190 try {
6191 if (DBG) {
6192 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6193 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6194 }
6195
6196 IccIoResult response =
6197 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6198 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6199 subId);
6200
6201 if (DBG) {
6202 log("Exchange SIM_IO [R]" + response);
6203 }
6204
6205 byte[] result = null;
6206 int length = 2;
6207 if (response.payload != null) {
6208 length = 2 + response.payload.length;
6209 result = new byte[length];
6210 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6211 } else {
6212 result = new byte[length];
6213 }
6214
6215 result[length - 1] = (byte) response.sw2;
6216 result[length - 2] = (byte) response.sw1;
6217 return result;
6218 } finally {
6219 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006220 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006221 }
6222
Nathan Haroldb3014052017-01-25 15:57:32 -08006223 /**
6224 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6225 * on a particular subscription
6226 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006227 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6228 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006229 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006230 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006231 return null;
6232 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006233
6234 final long identity = Binder.clearCallingIdentity();
6235 try {
6236 if (appType != TelephonyManager.APPTYPE_USIM
6237 && appType != TelephonyManager.APPTYPE_SIM) {
6238 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6239 return null;
6240 }
6241 Object response = sendRequest(
6242 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6243 if (response instanceof String[]) {
6244 return (String[]) response;
6245 }
yincheng zhao2737e882019-09-06 17:06:54 -07006246 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006247 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006248 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006249 } finally {
6250 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006251 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006252 }
6253
yincheng zhao2737e882019-09-06 17:06:54 -07006254 /**
6255 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6256 * subscription.
6257 *
6258 * @param subId the id of the subscription.
6259 * @param appType the uicc app type, must be USIM or SIM.
6260 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6261 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006262 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006263 * @return number of fplmns that is successfully written to the SIM.
6264 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006265 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6266 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006267 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6268 mApp, subId, "setForbiddenPlmns");
6269
yincheng zhao2737e882019-09-06 17:06:54 -07006270 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6271 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6272 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6273 }
6274 if (fplmns == null) {
6275 throw new IllegalArgumentException("Fplmn List provided is null");
6276 }
6277 for (String fplmn : fplmns) {
6278 if (!CellIdentity.isValidPlmn(fplmn)) {
6279 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6280 }
6281 }
6282 final long identity = Binder.clearCallingIdentity();
6283 try {
6284 Object response = sendRequest(
6285 CMD_SET_FORBIDDEN_PLMNS,
6286 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6287 subId);
6288 return (int) response;
6289 } finally {
6290 Binder.restoreCallingIdentity(identity);
6291 }
6292 }
6293
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006294 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006295 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006296 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6297 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006298
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006299 final long identity = Binder.clearCallingIdentity();
6300 try {
6301 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6302 if (response.payload == null) {
6303 return "";
6304 }
Evan Charltonc66da362014-05-16 14:06:40 -07006305
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006306 // Append the returned status code to the end of the response payload.
6307 String s = Integer.toHexString(
6308 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6309 s = IccUtils.bytesToHexString(response.payload) + s;
6310 return s;
6311 } finally {
6312 Binder.restoreCallingIdentity(identity);
6313 }
Evan Charltonc66da362014-05-16 14:06:40 -07006314 }
6315
Jake Hambye994d462014-02-03 13:10:13 -08006316 /**
6317 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6318 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6319 *
6320 * @param itemID the ID of the item to read
6321 * @return the NV item as a String, or null on error.
6322 */
6323 @Override
6324 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006325 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006326 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6327 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006328
6329 final long identity = Binder.clearCallingIdentity();
6330 try {
6331 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006332 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006333 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6334 return value;
6335 } finally {
6336 Binder.restoreCallingIdentity(identity);
6337 }
Jake Hambye994d462014-02-03 13:10:13 -08006338 }
6339
6340 /**
6341 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6342 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6343 *
6344 * @param itemID the ID of the item to read
6345 * @param itemValue the value to write, as a String
6346 * @return true on success; false on any failure
6347 */
6348 @Override
6349 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006350 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006351 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6352 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006353
6354 final long identity = Binder.clearCallingIdentity();
6355 try {
6356 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6357 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006358 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006359 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6360 return success;
6361 } finally {
6362 Binder.restoreCallingIdentity(identity);
6363 }
Jake Hambye994d462014-02-03 13:10:13 -08006364 }
6365
6366 /**
6367 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6368 * Used for device configuration by some CDMA operators.
6369 *
6370 * @param preferredRoamingList byte array containing the new PRL
6371 * @return true on success; false on any failure
6372 */
6373 @Override
6374 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006375 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6376 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006377
6378 final long identity = Binder.clearCallingIdentity();
6379 try {
6380 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6381 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6382 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6383 return success;
6384 } finally {
6385 Binder.restoreCallingIdentity(identity);
6386 }
Jake Hambye994d462014-02-03 13:10:13 -08006387 }
6388
6389 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006390 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006391 * Used for device configuration by some CDMA operators.
6392 *
chen xu6dac5ab2018-10-26 17:39:23 -07006393 * @param slotIndex - device slot.
6394 *
Jake Hambye994d462014-02-03 13:10:13 -08006395 * @return true on success; false on any failure
6396 */
6397 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006398 public boolean resetModemConfig(int slotIndex) {
6399 Phone phone = PhoneFactory.getPhone(slotIndex);
6400 if (phone != null) {
6401 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6402 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006403
chen xu6dac5ab2018-10-26 17:39:23 -07006404 final long identity = Binder.clearCallingIdentity();
6405 try {
6406 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6407 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6408 return success;
6409 } finally {
6410 Binder.restoreCallingIdentity(identity);
6411 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006412 }
chen xu6dac5ab2018-10-26 17:39:23 -07006413 return false;
6414 }
6415
6416 /**
6417 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6418 *
6419 * @param slotIndex - device slot.
6420 *
6421 * @return true on success; false on any failure
6422 */
6423 @Override
6424 public boolean rebootModem(int slotIndex) {
6425 Phone phone = PhoneFactory.getPhone(slotIndex);
6426 if (phone != null) {
6427 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6428 mApp, phone.getSubId(), "rebootModem");
6429
6430 final long identity = Binder.clearCallingIdentity();
6431 try {
6432 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6433 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6434 return success;
6435 } finally {
6436 Binder.restoreCallingIdentity(identity);
6437 }
6438 }
6439 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006440 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006441
Brad Ebinger51f743a2017-01-23 13:50:20 -08006442 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006443 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6444 * {@link #disableIms(int)}.
6445 * @param slotIndex device slot.
6446 */
6447 public void resetIms(int slotIndex) {
6448 enforceModifyPermission();
6449
6450 final long identity = Binder.clearCallingIdentity();
6451 try {
6452 if (mImsResolver == null) {
6453 // may happen if the does not support IMS.
6454 return;
6455 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006456 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006457 } finally {
6458 Binder.restoreCallingIdentity(identity);
6459 }
6460 }
6461
6462 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006463 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6464 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006465 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006466 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006467 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006468
6469 final long identity = Binder.clearCallingIdentity();
6470 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006471 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006472 // may happen if the device does not support IMS.
6473 return;
6474 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006475 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006476 } finally {
6477 Binder.restoreCallingIdentity(identity);
6478 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006479 }
6480
6481 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006482 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6483 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006484 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006485 public void disableIms(int slotId) {
6486 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006487
6488 final long identity = Binder.clearCallingIdentity();
6489 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006490 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006491 // may happen if the device does not support IMS.
6492 return;
6493 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006494 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006495 } finally {
6496 Binder.restoreCallingIdentity(identity);
6497 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006498 }
6499
6500 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006501 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6502 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006503 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006504 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006505 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006506 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006507
6508 final long identity = Binder.clearCallingIdentity();
6509 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006510 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006511 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6512 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006513 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006514 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006515 } finally {
6516 Binder.restoreCallingIdentity(identity);
6517 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006518 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006519 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006520 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6521 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006522 @Override
6523 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006524 enforceModifyPermission();
6525
6526 final long identity = Binder.clearCallingIdentity();
6527 try {
6528 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006529 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006530 } finally {
6531 Binder.restoreCallingIdentity(identity);
6532 }
6533 }
6534
6535 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006536 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006537 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006538 */
6539 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6540 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006541
6542 final long identity = Binder.clearCallingIdentity();
6543 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006544 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006545 // may happen if the device does not support IMS.
6546 return null;
6547 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006548 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006549 } finally {
6550 Binder.restoreCallingIdentity(identity);
6551 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006552 }
6553
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006554 /**
6555 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006556 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006557 */
6558 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6559 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006560
6561 final long identity = Binder.clearCallingIdentity();
6562 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006563 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006564 // may happen if the device does not support IMS.
6565 return null;
6566 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006567 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006568 } finally {
6569 Binder.restoreCallingIdentity(identity);
6570 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006571 }
6572
Brad Ebinger884c07b2018-02-15 16:17:40 -08006573 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006574 * Sets the ImsService Package Name that Telephony will bind to.
6575 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006576 * @param slotIndex the slot ID that the ImsService should bind for.
6577 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006578 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006579 * @param featureTypes An integer array of feature types associated with a packageName.
6580 * @param packageName The name of the package that the current configuration will be replaced
6581 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006582 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006583 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006584 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6585 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006586 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006587 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006588 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006589
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006590 final long identity = Binder.clearCallingIdentity();
6591 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006592 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006593 // may happen if the device does not support IMS.
6594 return false;
6595 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006596 Map<Integer, String> featureConfig = new HashMap<>();
6597 for (int featureType : featureTypes) {
6598 featureConfig.put(featureType, packageName);
6599 }
6600 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6601 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006602 } finally {
6603 Binder.restoreCallingIdentity(identity);
6604 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006605 }
6606
6607 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006608 * Clears any carrier ImsService overrides for the slot index specified that were previously
6609 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6610 *
6611 * This should only be used for testing.
6612 *
6613 * @param slotIndex the slot ID that the ImsService should bind for.
6614 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6615 */
6616 @Override
6617 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006618 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6619 "clearCarrierImsServiceOverride");
6620 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006621 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006622
6623 final long identity = Binder.clearCallingIdentity();
6624 try {
6625 if (mImsResolver == null) {
6626 // may happen if the device does not support IMS.
6627 return false;
6628 }
6629 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6630 } finally {
6631 Binder.restoreCallingIdentity(identity);
6632 }
6633 }
6634
6635 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006636 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006637 *
6638 * @param slotId The slot that the ImsService is associated with.
6639 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6640 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006641 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006642 * @return the package name of the ImsService configuration.
6643 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006644 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6645 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006646 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006647 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6648 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006649
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006650 final long identity = Binder.clearCallingIdentity();
6651 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006652 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006653 // may happen if the device does not support IMS.
6654 return "";
6655 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006656 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006657 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6658 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006659 } finally {
6660 Binder.restoreCallingIdentity(identity);
6661 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006662 }
6663
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006664 /**
6665 * Get the MmTelFeature state associated with the requested subscription id.
6666 * @param subId The subscription that the MmTelFeature is associated with.
6667 * @param callback A callback with an integer containing the
6668 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6669 */
6670 @Override
6671 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6672 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006673 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6674 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6675 "IMS not available on device.");
6676 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006677 final long token = Binder.clearCallingIdentity();
6678 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006679 int slotId = getSlotIndex(subId);
6680 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6681 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6682 + subId + "'");
6683 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6684 }
6685 verifyImsMmTelConfiguredOrThrow(slotId);
6686 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6687 try {
6688 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6689 } catch (RemoteException e) {
6690 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6691 + "Ignore");
6692 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006693 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006694 } catch (ImsException e) {
6695 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006696 } finally {
6697 Binder.restoreCallingIdentity(token);
6698 }
6699 }
6700
Daniel Brightbb5840b2021-01-12 15:48:18 -08006701 /**
6702 * Sets the ims registration state on all valid {@link Phone}s.
6703 */
6704 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006705 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006706
6707 final long identity = Binder.clearCallingIdentity();
6708 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006709 // NOTE: Before S, this method only set the default phone.
6710 for (final Phone phone : PhoneFactory.getPhones()) {
6711 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6712 phone.setImsRegistrationState(registered);
6713 }
6714 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006715 } finally {
6716 Binder.restoreCallingIdentity(identity);
6717 }
Wink Saville36469e72014-06-11 15:17:00 -07006718 }
6719
6720 /**
Stuart Scott54788802015-03-30 13:18:01 -07006721 * Set the network selection mode to automatic.
6722 *
6723 */
6724 @Override
6725 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006726 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6727 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006728
6729 final long identity = Binder.clearCallingIdentity();
6730 try {
shilufc958392020-01-20 11:36:01 -08006731 if (!isActiveSubscription(subId)) {
6732 return;
6733 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006734 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006735 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6736 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006737 } finally {
6738 Binder.restoreCallingIdentity(identity);
6739 }
Stuart Scott54788802015-03-30 13:18:01 -07006740 }
6741
Jack Yud10cdd42020-09-28 20:28:01 -07006742 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006743 * Ask the radio to connect to the input network and change selection mode to manual.
6744 *
6745 * @param subId the id of the subscription.
6746 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6747 * the operator to attach to.
6748 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6749 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6750 * normal network selection next time.
6751 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006752 */
6753 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006754 public boolean setNetworkSelectionModeManual(
6755 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006756 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6757 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006758
Jack Yu285100e2022-12-02 22:48:35 -08006759 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006760 if (!isActiveSubscription(subId)) {
6761 return false;
6762 }
6763
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006764 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006765 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006766 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006767 if (DBG) {
6768 log("setNetworkSelectionModeManual: subId: " + subId
6769 + " operator: " + operatorInfo);
6770 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006771 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6772 } finally {
6773 Binder.restoreCallingIdentity(identity);
6774 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006775 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006776 /**
shilu84f6e8b2019-12-19 13:58:01 -08006777 * Get the manual network selection
6778 *
6779 * @param subId the id of the subscription.
6780 *
6781 * @return the previously saved user selected PLMN
6782 */
6783 @Override
6784 public String getManualNetworkSelectionPlmn(int subId) {
6785 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006786 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6787 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006788
6789 final long identity = Binder.clearCallingIdentity();
6790 try {
6791 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006792 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006793 }
6794
6795 final Phone phone = getPhone(subId);
6796 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006797 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006798 }
6799 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6800 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006801 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006802 } finally {
6803 Binder.restoreCallingIdentity(identity);
6804 }
6805 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006806
6807 /**
6808 * Scans for available networks.
6809 */
6810 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006811 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6812 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006813 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6814 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006815 LocationAccessPolicy.LocationPermissionResult locationResult =
6816 LocationAccessPolicy.checkLocationPermission(mApp,
6817 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6818 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006819 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006820 .setCallingPid(Binder.getCallingPid())
6821 .setCallingUid(Binder.getCallingUid())
6822 .setMethod("getCellNetworkScanResults")
6823 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006824 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6825 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006826 .build());
6827 switch (locationResult) {
6828 case DENIED_HARD:
6829 throw new SecurityException("Not allowed to access scan results -- location");
6830 case DENIED_SOFT:
6831 return null;
6832 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006833
Pengquan Menga1bb6272018-09-06 09:59:22 -07006834 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006835 try {
6836 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006837 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006838 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006839 } finally {
6840 Binder.restoreCallingIdentity(identity);
6841 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006842 }
6843
6844 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006845 * Get the call forwarding info, given the call forwarding reason.
6846 */
6847 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006848 public void getCallForwarding(int subId, int callForwardingReason,
6849 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006850 enforceReadPrivilegedPermission("getCallForwarding");
6851 long identity = Binder.clearCallingIdentity();
6852 try {
6853 if (DBG) {
6854 log("getCallForwarding: subId " + subId
6855 + " callForwardingReason" + callForwardingReason);
6856 }
Hall Liu27d24262020-09-18 19:04:59 -07006857
6858 Phone phone = getPhone(subId);
6859 if (phone == null) {
6860 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006861 callback.onError(
6862 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006863 } catch (RemoteException e) {
6864 // ignore
6865 }
6866 return;
6867 }
6868
6869 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6870 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6871 @Override
6872 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6873 try {
6874 callback.onCallForwardingInfoAvailable(info);
6875 } catch (RemoteException e) {
6876 // ignore
6877 }
6878 }
6879
6880 @Override
6881 public void onError(int error) {
6882 try {
6883 callback.onError(error);
6884 } catch (RemoteException e) {
6885 // ignore
6886 }
6887 }
6888 });
6889 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006890 } finally {
6891 Binder.restoreCallingIdentity(identity);
6892 }
6893 }
6894
6895 /**
6896 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6897 * reason, the number to forward, and the timeout before the forwarding is attempted.
6898 */
6899 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006900 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6901 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006902 enforceModifyPermission();
6903 long identity = Binder.clearCallingIdentity();
6904 try {
6905 if (DBG) {
6906 log("setCallForwarding: subId " + subId
6907 + " callForwardingInfo" + callForwardingInfo);
6908 }
Hall Liu27d24262020-09-18 19:04:59 -07006909
6910 Phone phone = getPhone(subId);
6911 if (phone == null) {
6912 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006913 callback.accept(
6914 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006915 } catch (RemoteException e) {
6916 // ignore
6917 }
6918 return;
6919 }
6920
6921 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6922 FunctionalUtils.ignoreRemoteException(callback::accept));
6923
6924 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006925 } finally {
6926 Binder.restoreCallingIdentity(identity);
6927 }
6928 }
6929
6930 /**
Hall Liu27d24262020-09-18 19:04:59 -07006931 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006932 */
6933 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006934 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006935 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006936 long identity = Binder.clearCallingIdentity();
6937 try {
Hall Liu27d24262020-09-18 19:04:59 -07006938 Phone phone = getPhone(subId);
6939 if (phone == null) {
6940 try {
6941 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6942 } catch (RemoteException e) {
6943 // ignore
6944 }
6945 return;
6946 }
SongFerngWang0e767992021-03-31 22:08:45 +08006947 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6948 PersistableBundle c = configManager.getConfigForSubId(subId);
6949 boolean requireUssd = c.getBoolean(
6950 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006951
Shuo Qian4a594052020-01-23 11:59:30 -08006952 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006953 if (requireUssd) {
6954 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6955 getSubscriptionCarrierId(subId));
6956 String newUssdCommand = "";
6957 try {
6958 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006959 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006960 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6961 } catch (NullPointerException e) {
6962 loge("Failed to generate USSD number" + e);
6963 }
6964 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6965 mMainThreadHandler, callback, carrierXmlParser,
6966 CarrierXmlParser.SsEntry.SSAction.QUERY);
6967 final String ussdCommand = newUssdCommand;
6968 Executors.newSingleThreadExecutor().execute(() -> {
6969 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6970 });
6971 } else {
6972 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6973 callback::accept);
6974 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6975 }
Shuo Qian4a594052020-01-23 11:59:30 -08006976 } finally {
6977 Binder.restoreCallingIdentity(identity);
6978 }
6979 }
6980
6981 /**
Hall Liu27d24262020-09-18 19:04:59 -07006982 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006983 */
6984 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006985 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006986 enforceModifyPermission();
6987 long identity = Binder.clearCallingIdentity();
6988 try {
Hall Liu27d24262020-09-18 19:04:59 -07006989 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6990
6991 Phone phone = getPhone(subId);
6992 if (phone == null) {
6993 try {
6994 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6995 } catch (RemoteException e) {
6996 // ignore
6997 }
6998 return;
6999 }
7000
SongFerngWang0e767992021-03-31 22:08:45 +08007001 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7002 PersistableBundle c = configManager.getConfigForSubId(subId);
7003 boolean requireUssd = c.getBoolean(
7004 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007005
SongFerngWang0e767992021-03-31 22:08:45 +08007006 if (DBG) log("getCallWaitingStatus: subId " + subId);
7007 if (requireUssd) {
7008 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7009 getSubscriptionCarrierId(subId));
7010 CarrierXmlParser.SsEntry.SSAction ssAction =
7011 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7012 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7013 String newUssdCommand = "";
7014 try {
7015 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007016 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007017 .makeCommand(ssAction, null);
7018 } catch (NullPointerException e) {
7019 loge("Failed to generate USSD number" + e);
7020 }
7021 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7022 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7023 final String ussdCommand = newUssdCommand;
7024 Executors.newSingleThreadExecutor().execute(() -> {
7025 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7026 });
7027 } else {
7028 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7029 FunctionalUtils.ignoreRemoteException(callback::accept));
7030
7031 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7032 }
Shuo Qian4a594052020-01-23 11:59:30 -08007033 } finally {
7034 Binder.restoreCallingIdentity(identity);
7035 }
7036 }
7037
7038 /**
yinxub1bed742017-04-17 11:45:04 -07007039 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007040 *
yinxub1bed742017-04-17 11:45:04 -07007041 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007042 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7043 * location related information which will be sent if the caller already possess
7044 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007045 * @param request contains the radio access networks with bands/channels to scan
7046 * @param messenger callback messenger for scan results or errors
7047 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007048 * @return the id of the requested scan which can be used to stop the scan.
7049 */
7050 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007051 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7052 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007053 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007054 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7055 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007056 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007057 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7058 if (!renounceFineLocationAccess) {
7059 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007060 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7061 .setCallingPackage(callingPackage)
7062 .setCallingFeatureId(callingFeatureId)
7063 .setCallingPid(Binder.getCallingPid())
7064 .setCallingUid(Binder.getCallingUid())
7065 .setMethod("requestNetworkScan")
7066 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7067 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7068 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7069 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007070 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007071 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007072 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7073 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007074 if (e != null) {
7075 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7076 throw e;
7077 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007078 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007079 return TelephonyScanManager.INVALID_SCAN_ID;
7080 }
7081 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007082 }
Hall Liu912dfd32019-04-25 14:02:26 -07007083 int callingUid = Binder.getCallingUid();
7084 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007085 final long identity = Binder.clearCallingIdentity();
7086 try {
7087 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007088 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007089 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007090 } finally {
7091 Binder.restoreCallingIdentity(identity);
7092 }
yinxu504e1392017-04-12 16:03:22 -07007093 }
7094
Hall Liub2ac8ef2019-02-28 15:56:23 -08007095 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007096 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007097 boolean hasCarrierPriv;
7098 final long identity = Binder.clearCallingIdentity();
7099 try {
7100 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7101 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7102 } finally {
7103 Binder.restoreCallingIdentity(identity);
7104 }
Hall Liu558027f2019-05-15 19:14:05 -07007105 boolean hasNetworkScanPermission =
7106 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007107 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007108
7109 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7110 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7111 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007112 }
7113
7114 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7115 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007116 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7117 return new SecurityException("Specific channels must not be"
7118 + " scanned without location access.");
7119 }
7120 }
7121 }
7122
Hall Liub2ac8ef2019-02-28 15:56:23 -08007123 return null;
7124 }
7125
yinxu504e1392017-04-12 16:03:22 -07007126 /**
7127 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007128 *
7129 * @param subId id of the subscription
7130 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007131 */
7132 @Override
7133 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007134 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7135 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007136
Hall Liu912dfd32019-04-25 14:02:26 -07007137 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007138 final long identity = Binder.clearCallingIdentity();
7139 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007140 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007141 } finally {
7142 Binder.restoreCallingIdentity(identity);
7143 }
yinxu504e1392017-04-12 16:03:22 -07007144 }
7145
7146 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007147 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007148 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007149 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007150 */
7151 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007152 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007153 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007154 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007155 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007156
7157 final long identity = Binder.clearCallingIdentity();
7158 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007159 if (DBG) log("getAllowedNetworkTypesBitmask");
7160 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7161 int networkTypesBitmask = (result != null ? result[0] : -1);
7162 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7163 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007164 } finally {
7165 Binder.restoreCallingIdentity(identity);
7166 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007167 }
7168
7169 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007170 * Get the allowed network types for certain reason.
7171 *
7172 * @param subId the id of the subscription.
7173 * @param reason the reason the allowed network type change is taking place
7174 * @return the allowed network types.
7175 */
7176 @Override
7177 public long getAllowedNetworkTypesForReason(int subId,
7178 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007179 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007180 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007181 final long identity = Binder.clearCallingIdentity();
7182 try {
7183 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
7184 } finally {
7185 Binder.restoreCallingIdentity(identity);
7186 }
7187 }
7188
7189 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007190 * Enable/Disable E-UTRA-NR Dual Connectivity
7191 * @param subId subscription id of the sim card
7192 * @param nrDualConnectivityState expected NR dual connectivity state
7193 * This can be passed following states
7194 * <ol>
7195 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7196 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7197 * <li>Disable NR dual connectivity and force secondary cell to be released
7198 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7199 * </ol>
7200 * @return operation result.
7201 */
7202 @Override
7203 public int setNrDualConnectivityState(int subId,
7204 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7205 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7206 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007207 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007208 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7209 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7210 }
7211
Sooraj Sasindran37444802020-08-11 10:40:43 -07007212 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7213 final long identity = Binder.clearCallingIdentity();
7214 try {
7215 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7216 nrDualConnectivityState, subId,
7217 workSource);
7218 if (DBG) log("enableNRDualConnectivity result: " + result);
7219 return result;
7220 } finally {
7221 Binder.restoreCallingIdentity(identity);
7222 }
7223 }
7224
7225 /**
7226 * Is E-UTRA-NR Dual Connectivity enabled
7227 * @return true if dual connectivity is enabled else false
7228 */
7229 @Override
7230 public boolean isNrDualConnectivityEnabled(int subId) {
7231 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007232 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007233 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007234 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007235 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7236 return false;
7237 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007238 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7239 final long identity = Binder.clearCallingIdentity();
7240 try {
7241 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7242 null, subId, workSource);
7243 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7244 return isEnabled;
7245 } finally {
7246 Binder.restoreCallingIdentity(identity);
7247 }
7248 }
7249
7250 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007251 * Set the allowed network types of the device and
7252 * provide the reason triggering the allowed network change.
7253 *
7254 * @param subId the id of the subscription.
7255 * @param reason the reason the allowed network type change is taking place
7256 * @param allowedNetworkTypes the allowed network types.
7257 * @return true on success; false on any failure.
7258 */
7259 @Override
7260 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007261 @TelephonyManager.AllowedNetworkTypesReason int reason,
7262 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007263 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7264 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007265 // If the caller only has carrier privileges, then they should not be able to override
7266 // any network types which were set for security reasons.
7267 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7268 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007269 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007270 throw new SecurityException(
7271 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007272 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007273 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08007274 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007275 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007276 return false;
7277 }
7278 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7279 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007280 return false;
7281 }
7282
Jack Yu5b494332023-01-23 18:18:04 +00007283 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7284 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007285
Jack Yue37dd262022-12-16 11:53:37 -08007286 Phone phone = getPhone(subId);
7287 if (phone == null) {
7288 return false;
7289 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007290
Jack Yue37dd262022-12-16 11:53:37 -08007291 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007292 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007293 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007294 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007295
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007296 final long identity = Binder.clearCallingIdentity();
7297 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007298 Boolean success = (Boolean) sendRequest(
7299 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7300 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7301
7302 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7303 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007304 } finally {
7305 Binder.restoreCallingIdentity(identity);
7306 }
7307 }
7308
7309 /**
Miaoa84611c2019-03-15 09:21:10 +08007310 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007311 *
Miaoa84611c2019-03-15 09:21:10 +08007312 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007313 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007314 * @hide
7315 */
7316 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007317 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007318 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007319 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007320 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007321 try {
Miaoa84611c2019-03-15 09:21:10 +08007322 if (phone != null) {
7323 return phone.hasMatchedTetherApnSetting();
7324 } else {
7325 return false;
7326 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007327 } finally {
7328 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007329 }
Junda Liu475951f2014-11-07 16:45:03 -08007330 }
7331
7332 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007333 * Get the user enabled state of Mobile Data.
7334 *
7335 * TODO: remove and use isUserDataEnabled.
7336 * This can't be removed now because some vendor codes
7337 * calls through ITelephony directly while they should
7338 * use TelephonyManager.
7339 *
7340 * @return true on enabled
7341 */
7342 @Override
7343 public boolean getDataEnabled(int subId) {
7344 return isUserDataEnabled(subId);
7345 }
7346
7347 /**
7348 * Get whether mobile data is enabled per user setting.
7349 *
7350 * There are other factors deciding whether mobile data is actually enabled, but they are
7351 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007352 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007353 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7354 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007355 *
7356 * @return {@code true} if data is enabled else {@code false}
7357 */
7358 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007359 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007360 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007361 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007362 try {
7363 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7364 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007365 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007366 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7367 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007368 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007369 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007370 mApp, subId, functionName);
7371
Robert Greenwalt646120a2014-05-23 11:54:03 -07007372 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007373
7374 final long identity = Binder.clearCallingIdentity();
7375 try {
Jack Yu285100e2022-12-02 22:48:35 -08007376 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007377 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7378 Phone phone = PhoneFactory.getPhone(phoneId);
7379 if (phone != null) {
7380 boolean retVal = phone.isUserDataEnabled();
7381 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7382 return retVal;
7383 } else {
7384 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7385 return false;
7386 }
7387 } finally {
7388 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007389 }
7390 }
7391
7392 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007393 * Checks if the device is capable of mobile data by considering whether whether the
7394 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7395 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007396 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007397 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007398 */
7399 @Override
7400 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007401 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007402 try {
7403 try {
7404 mApp.enforceCallingOrSelfPermission(
7405 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007406 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007407 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007408 try {
7409 mApp.enforceCallingOrSelfPermission(
7410 android.Manifest.permission.READ_PHONE_STATE,
7411 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007412 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007413 mApp.enforceCallingOrSelfPermission(
7414 permission.READ_BASIC_PHONE_STATE, functionName);
7415 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007416 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007417 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007418 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007419 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007420
7421 final long identity = Binder.clearCallingIdentity();
7422 try {
Jack Yu285100e2022-12-02 22:48:35 -08007423 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007424 Phone phone = PhoneFactory.getPhone(phoneId);
7425 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007426 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007427 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007428 return retVal;
7429 } else {
7430 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7431 return false;
7432 }
7433 } finally {
7434 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007435 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007436 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007437
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007438 /**
7439 * Check if data is enabled for a specific reason
7440 * @param subId Subscription index
7441 * @param reason the reason the data enable change is taking place
7442 * @return {@code true} if the overall data is enabled; {@code false} if not.
7443 */
7444 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007445 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007446 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007447 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007448 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007449 try {
7450 mApp.enforceCallingOrSelfPermission(
7451 android.Manifest.permission.ACCESS_NETWORK_STATE,
7452 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007453 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007454 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7455 functionName);
7456 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007457 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007458 try {
7459 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007460 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007461 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007462 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007463 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007464 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007465 }
7466
7467
7468 final long identity = Binder.clearCallingIdentity();
7469 try {
Jack Yu285100e2022-12-02 22:48:35 -08007470 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007471 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007472 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007473 + " reason=" + reason);
7474 }
7475 Phone phone = PhoneFactory.getPhone(phoneId);
7476 if (phone != null) {
7477 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007478 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007479 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007480 return retVal;
7481 } else {
7482 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007483 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007484 + subId + " retVal=false");
7485 }
7486 return false;
7487 }
7488 } finally {
7489 Binder.restoreCallingIdentity(identity);
7490 }
7491 }
7492
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007493 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007494 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007495 // No permission needed; this only lets the caller inspect their own status.
7496 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007497 }
Junda Liu29340342014-07-10 15:23:27 -07007498
7499 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007500 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007501 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007502 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7503 }
7504
7505 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7506 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007507 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007508 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007509 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7510 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007511 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7512 if (cpt == null) {
7513 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007514 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7515 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007516 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007517 }
7518
7519 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007520 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007521 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07007522 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007523 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007524 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007525 Phone phone = getPhone(subId);
7526 if (phone == null) {
7527 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7528 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7529 }
7530 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7531 if (cpt == null) {
7532 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007533 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7534 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007535 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007536 }
7537
7538 @Override
7539 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007540 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08007541 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7542 }
7543
7544 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007545 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007546 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007547 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007548 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007549 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7550 Phone phone = PhoneFactory.getPhone(phoneId);
7551 if (phone == null) {
7552 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007553 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007554 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7555 if (cpt == null) {
7556 continue;
7557 }
7558 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007559 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7560 break;
7561 }
7562 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007563 return result;
Junda Liu29340342014-07-10 15:23:27 -07007564 }
Derek Tan89e89d42014-07-08 17:00:10 -07007565
7566 @Override
Junda Liue64de782015-04-16 17:19:16 -07007567 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007568 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00007569 Phone phone = PhoneFactory.getPhone(phoneId);
7570 if (phone == null) {
7571 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007572 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007573 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7574 if (cpt == null) {
7575 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007576 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007577 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007578 }
7579
Amith Yamasani6e118872016-02-19 12:53:51 -08007580 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007581 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007582 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007583 Phone phone = PhoneFactory.getPhone(phoneId);
7584 if (phone == null) {
7585 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007586 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007587 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7588 if (cpt == null) {
7589 return Collections.emptyList();
7590 }
7591 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007592 }
7593
chen xuf7e9fe82019-05-09 19:31:02 -07007594 @Override
7595 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007596 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007597 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007598 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007599 try {
7600 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7601 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7602 }
7603 } finally {
7604 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007605 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007606 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007607 }
7608
Rambo Wang6812ffb2022-03-15 16:54:17 -07007609 @Override
7610 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7611 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7612
7613 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7614 if (phone == null) {
7615 return null;
7616 }
7617 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7618 if (cpt == null) {
7619 return null;
7620 }
7621 return cpt.getCarrierServicePackageName();
7622 }
7623
Wink Savilleb564aae2014-10-23 10:18:09 -07007624 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007625 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007626 UiccPort port = phone == null ? null : phone.getUiccPort();
7627 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007628 return null;
7629 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007630 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007631 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007632 return null;
7633 }
7634 return iccId;
7635 }
7636
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007637 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007638 public void setCallComposerStatus(int subId, int status) {
7639 enforceModifyPermission();
7640
7641 final long identity = Binder.clearCallingIdentity();
7642 try {
7643 Phone phone = getPhone(subId);
7644 if (phone != null) {
7645 Phone defaultPhone = phone.getImsPhone();
7646 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7647 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7648 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007649 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7650 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007651 }
7652 }
Shuo Qian284ae752020-12-22 19:10:14 -08007653 } catch (ImsException e) {
7654 throw new ServiceSpecificException(e.getCode());
7655 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007656 Binder.restoreCallingIdentity(identity);
7657 }
7658 }
7659
7660 @Override
7661 public int getCallComposerStatus(int subId) {
7662 enforceReadPrivilegedPermission("getCallComposerStatus");
7663
7664 final long identity = Binder.clearCallingIdentity();
7665 try {
7666 Phone phone = getPhone(subId);
7667 if (phone != null) {
7668 Phone defaultPhone = phone.getImsPhone();
7669 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7670 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7671 return imsPhone.getCallComposerStatus();
7672 }
7673 }
7674 } finally {
7675 Binder.restoreCallingIdentity(identity);
7676 }
7677 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7678 }
7679
7680 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007681 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7682 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007683 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007684 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007685
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007686 final long identity = Binder.clearCallingIdentity();
7687 try {
7688 final String iccId = getIccId(subId);
7689 final Phone phone = getPhone(subId);
7690 if (phone == null) {
7691 return false;
7692 }
7693 final String subscriberId = phone.getSubscriberId();
7694
7695 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007696 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007697 + subscriberId + " to " + number);
7698 }
7699
7700 if (TextUtils.isEmpty(iccId)) {
7701 return false;
7702 }
7703
7704 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7705
7706 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7707 if (alphaTag == null) {
7708 editor.remove(alphaTagPrefKey);
7709 } else {
7710 editor.putString(alphaTagPrefKey, alphaTag);
7711 }
7712
7713 // Record both the line number and IMSI for this ICCID, since we need to
7714 // track all merged IMSIs based on line number
7715 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7716 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7717 if (number == null) {
7718 editor.remove(numberPrefKey);
7719 editor.remove(subscriberPrefKey);
7720 } else {
7721 editor.putString(numberPrefKey, number);
7722 editor.putString(subscriberPrefKey, subscriberId);
7723 }
7724
7725 editor.commit();
7726 return true;
7727 } finally {
7728 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007729 }
Derek Tan7226c842014-07-02 17:42:23 -07007730 }
7731
7732 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007733 public String getLine1NumberForDisplay(int subId, String callingPackage,
7734 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007735 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007736 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007737 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007738 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007739 return null;
7740 }
Derek Tan97ebb422014-09-05 16:55:38 -07007741
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007742 final long identity = Binder.clearCallingIdentity();
7743 try {
7744 String iccId = getIccId(subId);
7745 if (iccId != null) {
7746 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7747 if (DBG_MERGE) {
7748 log("getLine1NumberForDisplay returning "
7749 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7750 }
7751 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007752 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007753 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7754 return null;
7755 } finally {
7756 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007757 }
Derek Tan7226c842014-07-02 17:42:23 -07007758 }
7759
7760 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007761 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7762 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007763 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007764 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007765 return null;
7766 }
Derek Tan97ebb422014-09-05 16:55:38 -07007767
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007768 final long identity = Binder.clearCallingIdentity();
7769 try {
7770 String iccId = getIccId(subId);
7771 if (iccId != null) {
7772 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7773 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7774 }
7775 return null;
7776 } finally {
7777 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007778 }
Derek Tan7226c842014-07-02 17:42:23 -07007779 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007780
7781 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007782 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7783 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007784 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7785 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007786 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007787 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007788 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007789 return null;
7790 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007791
Jordan Liub49b04b2019-05-06 14:45:15 -07007792 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7793 // the process, where TelephonyManager was instantiated.
7794 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007795 final long identity = Binder.clearCallingIdentity();
7796 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007797 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007798 final TelephonyManager tele = TelephonyManager.from(context);
7799 final SubscriptionManager sub = SubscriptionManager.from(context);
7800
7801 // Figure out what subscribers are currently active
7802 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007803
Jordan Liub49b04b2019-05-06 14:45:15 -07007804 // Only consider subs which match the current subId
7805 // This logic can be simplified. See b/131189269 for progress.
7806 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007807 activeSubscriberIds.add(tele.getSubscriberId(subId));
7808 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007809
7810 // First pass, find a number override for an active subscriber
7811 String mergeNumber = null;
7812 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7813 for (String key : prefs.keySet()) {
7814 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7815 final String subscriberId = (String) prefs.get(key);
7816 if (activeSubscriberIds.contains(subscriberId)) {
7817 final String iccId = key.substring(
7818 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7819 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7820 mergeNumber = (String) prefs.get(numberKey);
7821 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007822 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007823 + " for active subscriber " + subscriberId);
7824 }
7825 if (!TextUtils.isEmpty(mergeNumber)) {
7826 break;
7827 }
7828 }
7829 }
7830 }
7831
7832 // Shortcut when no active merged subscribers
7833 if (TextUtils.isEmpty(mergeNumber)) {
7834 return null;
7835 }
7836
7837 // Second pass, find all subscribers under that line override
7838 final ArraySet<String> result = new ArraySet<>();
7839 for (String key : prefs.keySet()) {
7840 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7841 final String number = (String) prefs.get(key);
7842 if (mergeNumber.equals(number)) {
7843 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7844 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7845 final String subscriberId = (String) prefs.get(subscriberKey);
7846 if (!TextUtils.isEmpty(subscriberId)) {
7847 result.add(subscriberId);
7848 }
7849 }
7850 }
7851 }
7852
7853 final String[] resultArray = result.toArray(new String[result.size()]);
7854 Arrays.sort(resultArray);
7855 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007856 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007857 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7858 }
7859 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007860 } finally {
7861 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007862 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007863 }
7864
7865 @Override
zoey chen38003472019-12-13 17:16:31 +08007866 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7867 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007868
7869 final long identity = Binder.clearCallingIdentity();
7870 try {
7871 final TelephonyManager telephonyManager = mApp.getSystemService(
7872 TelephonyManager.class);
7873 String subscriberId = telephonyManager.getSubscriberId(subId);
7874 if (subscriberId == null) {
7875 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007876 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007877 + subId);
7878 }
7879 return null;
7880 }
7881
Jack Yu285100e2022-12-02 22:48:35 -08007882 ParcelUuid groupUuid;
7883 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08007884 final SubscriptionInfo info = getSubscriptionManagerService()
Jack Yu285100e2022-12-02 22:48:35 -08007885 .getSubscriptionInfo(subId);
7886 groupUuid = info.getGroupUuid();
7887 } else {
7888 final SubscriptionInfo info = mSubscriptionController
7889 .getSubscriptionInfo(subId);
7890 groupUuid = info.getGroupUuid();
7891 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007892 // If it doesn't belong to any group, return just subscriberId of itself.
7893 if (groupUuid == null) {
7894 return new String[]{subscriberId};
7895 }
7896
7897 // Get all subscriberIds from the group.
7898 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu285100e2022-12-02 22:48:35 -08007899 List<SubscriptionInfo> groupInfos;
7900 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08007901 groupInfos = getSubscriptionManagerService()
Jack Yu285100e2022-12-02 22:48:35 -08007902 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7903 mApp.getAttributionTag());
7904 } else {
7905 groupInfos = mSubscriptionController
7906 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7907 mApp.getAttributionTag());
7908 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007909 for (SubscriptionInfo subInfo : groupInfos) {
7910 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7911 if (subscriberId != null) {
7912 mergedSubscriberIds.add(subscriberId);
7913 }
7914 }
7915
7916 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7917 } finally {
7918 Binder.restoreCallingIdentity(identity);
7919
7920 }
7921 }
7922
7923 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007924 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007925 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007926 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007927
7928 final long identity = Binder.clearCallingIdentity();
7929 try {
7930 final Phone phone = getPhone(subId);
7931 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7932 } finally {
7933 Binder.restoreCallingIdentity(identity);
7934 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007935 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007936
7937 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007938 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007939 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7940 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007941 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7942 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007943
7944 final long identity = Binder.clearCallingIdentity();
7945 try {
7946 final Phone phone = getPhone(subId);
7947 if (phone == null) {
7948 return false;
7949 }
7950 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7951 cdmaNonRoamingList);
7952 } finally {
7953 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007954 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007955 }
7956
7957 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007958 @Deprecated
7959 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7960 enforceModifyPermission();
7961
7962 int returnValue = 0;
7963 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007964 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007965 if(result.exception == null) {
7966 if (result.result != null) {
7967 byte[] responseData = (byte[])(result.result);
7968 if(responseData.length > oemResp.length) {
7969 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7970 responseData.length + "bytes. Buffer Size is " +
7971 oemResp.length + "bytes.");
7972 }
7973 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7974 returnValue = responseData.length;
7975 }
7976 } else {
7977 CommandException ex = (CommandException) result.exception;
7978 returnValue = ex.getCommandError().ordinal();
7979 if(returnValue > 0) returnValue *= -1;
7980 }
7981 } catch (RuntimeException e) {
7982 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7983 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7984 if(returnValue > 0) returnValue *= -1;
7985 }
7986
7987 return returnValue;
7988 }
7989
7990 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007991 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007992 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007993 try {
7994 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007995 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007996 mApp, phone.getSubId(), "getRadioAccessFamily");
7997 } catch (SecurityException e) {
7998 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7999 throw e;
8000 }
chen xub97461a2018-10-26 14:17:57 -07008001 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008002 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07008003 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08008004 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008005 final long identity = Binder.clearCallingIdentity();
8006 try {
chen xub97461a2018-10-26 14:17:57 -07008007 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008008 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07008009 mApp, phone.getSubId(), "getRadioAccessFamily");
8010 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008011 } finally {
8012 Binder.restoreCallingIdentity(identity);
8013 }
chen xub97461a2018-10-26 14:17:57 -07008014 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008015 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008016
8017 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008018 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008019 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08008020 try {
8021 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
8022 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008023 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008024 }
8025 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008026 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008027 }
8028 RoleManager rm = mApp.getSystemService(RoleManager.class);
8029 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
8030 if (!dialerRoleHolders.contains(callingPackage)) {
8031 throw new SecurityException("App must be the dialer role holder to"
8032 + " upload a call composer pic");
8033 }
8034
8035 Executors.newSingleThreadExecutor().execute(() -> {
8036 ByteArrayOutputStream output = new ByteArrayOutputStream(
8037 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8038 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8039 boolean readUntilEnd = false;
8040 int totalBytesRead = 0;
8041 byte[] buffer = new byte[16 * 1024];
8042 while (true) {
8043 int numRead;
8044 try {
8045 numRead = input.read(buffer);
8046 } catch (IOException e) {
8047 try {
8048 fd.checkError();
8049 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8050 null);
8051 } catch (IOException e1) {
8052 // This means that the other side closed explicitly with an error. If this
8053 // happens, log and ignore.
8054 loge("Remote end of call composer picture pipe closed: " + e1);
8055 }
8056 break;
8057 }
8058 if (numRead == -1) {
8059 readUntilEnd = true;
8060 break;
8061 }
8062 totalBytesRead += numRead;
8063 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8064 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8065 try {
8066 input.close();
8067 } catch (IOException e) {
8068 // ignore
8069 }
8070 break;
8071 }
8072 output.write(buffer, 0, numRead);
8073 }
8074 // Generally, the remote end will close the file descriptors. The only case where we
8075 // close is above, where the picture size is too big.
8076
8077 try {
8078 fd.checkError();
8079 } catch (IOException e) {
8080 loge("Remote end for call composer closed with an error: " + e);
8081 return;
8082 }
8083
Hall Liuaa4211e2021-01-20 15:43:39 -08008084 if (!readUntilEnd) {
8085 loge("Did not finish reading entire image; aborting");
8086 return;
8087 }
Hall Liu82694d52020-12-11 18:22:04 -08008088
Hall Liuaa4211e2021-01-20 15:43:39 -08008089 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8090 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8091 new CallComposerPictureTransfer.Factory() {},
8092 imageData,
8093 (result) -> {
8094 if (result.first != null) {
8095 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8096 Bundle outputResult = new Bundle();
8097 outputResult.putParcelable(
8098 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8099 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8100 outputResult);
8101 } else {
8102 callback.send(result.second, null);
8103 }
8104 }
8105 );
Hall Liu82694d52020-12-11 18:22:04 -08008106 });
8107 }
8108
8109 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008110 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008111 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008112 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008113
8114 final long identity = Binder.clearCallingIdentity();
8115 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008116 ImsManager.getInstance(defaultPhone.getContext(),
8117 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008118 } finally {
8119 Binder.restoreCallingIdentity(identity);
8120 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008121 }
8122
8123 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008124 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008125 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008126 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8127 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008128 return false;
8129 }
Svet Ganovb320e182015-04-16 12:30:10 -07008130
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008131 final long identity = Binder.clearCallingIdentity();
8132 try {
8133 // Check the user preference and the system-level IMS setting. Even if the user has
8134 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8135 // In the long run, we may instead need to check if there exists a connection service
8136 // which can support video calling.
8137 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008138 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008139 return imsManager.isVtEnabledByPlatform()
8140 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8141 && imsManager.isVtEnabledByUser();
8142 } finally {
8143 Binder.restoreCallingIdentity(identity);
8144 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008145 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008146
Andrew Leea1239f22015-03-02 17:44:07 -08008147 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008148 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8149 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008150 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008151 mApp, subId, callingPackage, callingFeatureId,
8152 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008153 return false;
8154 }
8155
8156 final long identity = Binder.clearCallingIdentity();
8157 try {
8158 CarrierConfigManager configManager =
8159 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008160 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008161 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8162 } finally {
8163 Binder.restoreCallingIdentity(identity);
8164 }
Andrew Leea1239f22015-03-02 17:44:07 -08008165 }
8166
8167 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008168 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008169 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008170 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008171 return false;
8172 }
8173
8174 final long identity = Binder.clearCallingIdentity();
8175 try {
8176 CarrierConfigManager configManager =
8177 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008178 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008179 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8180 } finally {
8181 Binder.restoreCallingIdentity(identity);
8182 }
Andrew Leea1239f22015-03-02 17:44:07 -08008183 }
8184
Andrew Lee9431b832015-03-09 18:46:45 -07008185 @Override
8186 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008187 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008188 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008189 }
8190
8191 @Override
8192 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008193 final long identity = Binder.clearCallingIdentity();
8194 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008195 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008196 } finally {
8197 Binder.restoreCallingIdentity(identity);
8198 }
Andrew Lee9431b832015-03-09 18:46:45 -07008199 }
8200
Hall Liuf6668912018-10-31 17:05:23 -07008201 /**
8202 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8203 * support for the feature and device firmware support.
8204 *
8205 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8206 */
8207 @Override
8208 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008209 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008210 final Phone phone = getPhone(subscriptionId);
8211 if (phone == null) {
8212 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8213 return false;
8214 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008215 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008216 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008217 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
8218 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008219 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008220 return isCarrierSupported && isDeviceSupported;
8221 } finally {
8222 Binder.restoreCallingIdentity(identity);
8223 }
Hall Liu98187582018-01-22 19:15:32 -08008224 }
8225
Hall Liuf6668912018-10-31 17:05:23 -07008226 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008227 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8228 * RTT setting, will return true if the device and carrier both support RTT.
8229 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008230 */
8231 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008232 final long identity = Binder.clearCallingIdentity();
8233 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00008234 boolean isRttSupported = isRttSupported(subscriptionId);
8235 boolean isUserRttSettingOn = Settings.Secure.getInt(
8236 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8237 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8238 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8239 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008240 } finally {
8241 Binder.restoreCallingIdentity(identity);
8242 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008243 }
8244
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008245 @Deprecated
8246 @Override
8247 public String getDeviceId(String callingPackage) {
8248 return getDeviceIdWithFeature(callingPackage, null);
8249 }
8250
Sanket Padawe7310cc72015-01-14 09:53:20 -08008251 /**
8252 * Returns the unique device ID of phone, for example, the IMEI for
8253 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8254 *
8255 * <p>Requires Permission:
8256 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8257 */
8258 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008259 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008260 try {
8261 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8262 } catch (SecurityException se) {
8263 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8264 throw new SecurityException("Package " + callingPackage + " does not belong to "
8265 + Binder.getCallingUid());
8266 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008267 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008268 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008269 return null;
8270 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008271 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008272 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008273 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008274 return null;
8275 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008276
8277 final long identity = Binder.clearCallingIdentity();
8278 try {
8279 return phone.getDeviceId();
8280 } finally {
8281 Binder.restoreCallingIdentity(identity);
8282 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008283 }
8284
Ping Sunc67b7c22016-03-02 19:16:45 +08008285 /**
8286 * {@hide}
8287 * Returns the IMS Registration Status on a particular subid
8288 *
8289 * @param subId
8290 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008291 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008292 Phone phone = getPhone(subId);
8293 if (phone != null) {
8294 return phone.isImsRegistered();
8295 } else {
8296 return false;
8297 }
8298 }
8299
Santos Cordon7a1885b2015-02-03 11:15:19 -08008300 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008301 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008302 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008303 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008304 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008305 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8306 }
8307 final long identity = Binder.clearCallingIdentity();
8308 try {
8309 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8310 } finally {
8311 Binder.restoreCallingIdentity(identity);
8312 }
8313 }
8314
8315 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008316 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008317 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008318 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008319 mApp,
8320 subscriptionId,
8321 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8322 + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07008323 final long identity = Binder.clearCallingIdentity();
8324 try {
8325 Phone phone = getPhone(subscriptionId);
8326 if (phone == null) {
8327 return null;
8328 }
8329 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8330 } finally {
8331 Binder.restoreCallingIdentity(identity);
8332 }
8333 }
8334
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008335 /**
8336 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008337 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008338 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008339 final long identity = Binder.clearCallingIdentity();
8340 try {
8341 Phone phone = getPhone(subId);
8342 if (phone != null) {
8343 return phone.isWifiCallingEnabled();
8344 } else {
8345 return false;
8346 }
8347 } finally {
8348 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008349 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008350 }
8351
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008352 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008353 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008354 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008355 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008356 final long identity = Binder.clearCallingIdentity();
8357 try {
8358 Phone phone = getPhone(subId);
8359 if (phone != null) {
8360 return phone.isVideoEnabled();
8361 } else {
8362 return false;
8363 }
8364 } finally {
8365 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008366 }
8367 }
8368
8369 /**
8370 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8371 * defined in {@link ImsRegistrationImplBase}.
8372 */
8373 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008374 final long identity = Binder.clearCallingIdentity();
8375 try {
8376 Phone phone = getPhone(subId);
8377 if (phone != null) {
8378 return phone.getImsRegistrationTech();
8379 } else {
8380 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8381 }
8382 } finally {
8383 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008384 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008385 }
8386
Stuart Scott8eef64f2015-04-08 15:13:54 -07008387 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008388 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008389 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07008390 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8391 return;
8392 }
Kai Shif70f46f2021-03-03 13:59:46 -08008393 Phone defaultPhone = getDefaultPhone();
8394 if (defaultPhone != null) {
8395 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8396 mApp, getDefaultPhone().getSubId(), "factoryReset");
8397 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008398 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008399
Svet Ganovcc087f82015-05-12 20:35:54 -07008400 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008401 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8402 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008403 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008404 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008405 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008406 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008407 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008408 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08008409 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008410 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008411 // There has been issues when Sms raw table somehow stores orphan
8412 // fragments. They lead to garbled message when new fragments come
8413 // in and combined with those stale ones. In case this happens again,
8414 // user can reset all network settings which will clean up this table.
8415 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008416 // Clean up IMS settings as well here.
8417 int slotId = getSlotIndex(subId);
8418 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8419 ImsManager.getInstance(mApp, slotId).factoryReset();
8420 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008421
Kai Shif70f46f2021-03-03 13:59:46 -08008422 if (defaultPhone == null) {
8423 return;
8424 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008425 // Erase modem config if erase modem on network setting is enabled.
8426 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8427 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8428 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008429 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008430 }
Kai Shif70f46f2021-03-03 13:59:46 -08008431
8432 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008433 } finally {
8434 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008435 }
8436 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008437
SongFerngWangfd89b102021-05-27 22:44:54 +08008438 @VisibleForTesting
8439 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8440 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8441 return;
8442 }
8443 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8444 RILConstants.PREFERRED_NETWORK_MODE);
8445 SubscriptionManager.setSubscriptionProperty(subId,
8446 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8447 "user=" + defaultNetworkType);
8448 phone.loadAllowedNetworksFromSubscriptionDatabase();
8449 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8450 defaultNetworkType, null);
8451 }
8452
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008453 private void cleanUpSmsRawTable(Context context) {
8454 ContentResolver resolver = context.getContentResolver();
8455 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8456 resolver.delete(uri, null, null);
8457 }
8458
Narayan Kamath1c496c22015-04-16 14:40:19 +01008459 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008460 public String getSimLocaleForSubscriber(int subId) {
8461 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
8462 final Phone phone = getPhone(subId);
8463 if (phone == null) {
8464 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008465 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008466 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008467 final long identity = Binder.clearCallingIdentity();
8468 try {
Jack Yu285100e2022-12-02 22:48:35 -08008469 SubscriptionInfo info;
8470 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008471 info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
Jack Yu285100e2022-12-02 22:48:35 -08008472 phone.getContext().getOpPackageName(),
8473 phone.getContext().getAttributionTag());
8474 if (info == null) {
8475 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8476 return null;
8477 }
8478 } else {
8479 info = mSubscriptionController.getActiveSubscriptionInfo(subId,
8480 phone.getContext().getOpPackageName(),
8481 phone.getContext().getAttributionTag());
8482 if (info == null) {
8483 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8484 return null;
8485 }
chen xu6291c472019-02-04 12:55:53 -08008486 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008487 // Try and fetch the locale from the carrier properties or from the SIM language
8488 // preferences (EF-PL and EF-LI)...
8489 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008490 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008491 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8492 if (localeFromDefaultSim != null) {
8493 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8494 if (DBG) log("Using locale from subId: " + subId + " locale: "
8495 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008496 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008497 } else {
8498 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008499 }
8500 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008501
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008502 // The SIM language preferences only store a language (e.g. fr = French), not an
8503 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8504 // the SIM and carrier preferences does not include a country we add the country
8505 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008506 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008507 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008508 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008509 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008510 }
8511
8512 if (DBG) log("No locale found - returning null");
8513 return null;
8514 } finally {
8515 Binder.restoreCallingIdentity(identity);
8516 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008517 }
8518
tom hsu0b59d292022-09-29 23:49:21 +08008519 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008520 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008521 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008522 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008523 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008524 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8525 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008526 Locale.forLanguageTag(localeTag).getCountry())) {
8527 return localeTag;
8528 }
8529 }
8530 return inputLocale.toLanguageTag();
8531 }
8532
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008533 /**
8534 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8535 */
8536 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu285100e2022-12-02 22:48:35 -08008537 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008538 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Jack Yu285100e2022-12-02 22:48:35 -08008539 mApp.getOpPackageName(), mApp.getAttributionTag());
8540 }
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008541 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08008542 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01008543 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008544
Gary Jian3aa9a762022-01-24 16:41:19 +08008545 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8546 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008547
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008548 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008549 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8550 * representing the state of the modem.
8551 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008552 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8553 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008554 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008555 */
8556 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008557 public void requestModemActivityInfo(ResultReceiver result) {
8558 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008559 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008560
8561 final long identity = Binder.clearCallingIdentity();
8562 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008563 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008564 } finally {
8565 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008566 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008567 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008568
Gary Jian76280a42022-12-07 16:18:33 +08008569 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008570 // less than total activity duration.
8571 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8572 if (info == null) {
8573 return false;
8574 }
8575 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008576 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008577 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8578
Hall Liu49656c02020-10-09 19:00:11 -07008579 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8580
Siddharth Rayb8114062018-06-17 15:02:38 -07008581 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008582 && (info.getSleepTimeMillis() <= activityDurationMs)
8583 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008584 }
8585
Gary Jian3aa9a762022-01-24 16:41:19 +08008586 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8587 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8588 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8589 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8590
8591 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8592 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8593 }
8594
8595 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8596 mLastModemActivityInfo.setReceiveTimeMillis(
8597 rat,
8598 freq,
8599 info.getReceiveTimeMillis(rat, freq)
8600 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8601 }
8602
8603 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8604 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8605 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8606 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8607
8608 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8609 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8610 }
8611 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8612 mLastModemActivityInfo.setReceiveTimeMillis(
8613 rat,
8614 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8615 }
8616
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008617 /**
8618 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8619 * @param info recent ModemActivityInfo
8620 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008621 private void mergeModemActivityInfo(ModemActivityInfo info) {
8622 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008623 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008624 boolean matched;
8625 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8626 matched = false;
8627 int rat = info.getSpecificInfoRat(i);
8628 int freq = info.getSpecificInfoFrequencyRange(i);
8629 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8630 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8631 //if it already exists
8632 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8633 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8634 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8635 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8636 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8637 updateLastModemActivityInfo(info, rat, freq);
8638 matched = true;
8639 }
8640 } else {
8641 updateLastModemActivityInfo(info, rat);
8642 matched = true;
8643 }
8644 }
8645 }
8646
8647 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008648 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008649 new ActivityStatsTechSpecificInfo(
8650 rat,
8651 freq,
8652 info.getTransmitTimeMillis(rat, freq),
8653 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008654 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008655 }
8656 }
8657 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8658 mLastModemActivitySpecificInfo =
8659 new ActivityStatsTechSpecificInfo[merged.size()];
8660 merged.toArray(mLastModemActivitySpecificInfo);
8661
8662 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8663 mLastModemActivityInfo.setSleepTimeMillis(
8664 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008665 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008666 mLastModemActivityInfo.setIdleTimeMillis(
8667 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008668 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008669
8670 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008671 new ModemActivityInfo(
8672 mLastModemActivityInfo.getTimestampMillis(),
8673 mLastModemActivityInfo.getSleepTimeMillis(),
8674 mLastModemActivityInfo.getIdleTimeMillis(),
8675 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008676 }
8677
8678 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8679 ActivityStatsTechSpecificInfo[] info) {
8680 int infoSize = info.length;
8681 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8682 for (int i = 0; i < infoSize; i++) {
8683 ret[i] = new ActivityStatsTechSpecificInfo(
8684 info[i].getRat(), info[i].getFrequencyRange(),
8685 info[i].getTransmitTimeMillis(),
8686 (int) info[i].getReceiveTimeMillis());
8687 }
8688 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008689 }
8690
Jack Yu85bd38a2015-11-09 11:34:32 -08008691 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008692 * Returns the service state information on specified subscription.
8693 */
8694 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008695 public ServiceState getServiceStateForSubscriber(int subId,
8696 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8697 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008698 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008699 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008700 return null;
8701 }
8702
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008703 boolean hasFinePermission = false;
8704 boolean hasCoarsePermission = false;
8705 if (!renounceFineLocationAccess) {
8706 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8707 LocationAccessPolicy.checkLocationPermission(mApp,
8708 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8709 .setCallingPackage(callingPackage)
8710 .setCallingFeatureId(callingFeatureId)
8711 .setCallingPid(Binder.getCallingPid())
8712 .setCallingUid(Binder.getCallingUid())
8713 .setMethod("getServiceStateForSubscriber")
8714 .setLogAsInfo(true)
8715 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8716 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8717 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8718 .build());
8719 hasFinePermission =
8720 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8721 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008722
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008723 if (!renounceCoarseLocationAccess) {
8724 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8725 LocationAccessPolicy.checkLocationPermission(mApp,
8726 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8727 .setCallingPackage(callingPackage)
8728 .setCallingFeatureId(callingFeatureId)
8729 .setCallingPid(Binder.getCallingPid())
8730 .setCallingUid(Binder.getCallingUid())
8731 .setMethod("getServiceStateForSubscriber")
8732 .setLogAsInfo(true)
8733 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8734 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8735 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8736 .build());
8737 hasCoarsePermission =
8738 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8739 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008740
Jack Yu479f40e2020-10-27 21:29:25 -07008741 final Phone phone = getPhone(subId);
8742 if (phone == null) {
8743 return null;
8744 }
8745
Jordan Liu0f2bc442020-11-18 16:47:37 -08008746 final long identity = Binder.clearCallingIdentity();
8747
Jack Yu479f40e2020-10-27 21:29:25 -07008748 boolean isCallingPackageDataService = phone.getDataServicePackages()
8749 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008750 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008751 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu285100e2022-12-02 22:48:35 -08008752 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008753 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
Jack Yu285100e2022-12-02 22:48:35 -08008754 .getSubscriptionInfoInternal(subId);
8755 if (subInfo == null || !subInfo.isActive()) {
8756 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8757 + "subId=" + subId);
8758 return null;
8759 }
8760 } else {
8761 if (!mSubscriptionController.isActiveSubId(subId, callingPackage,
8762 callingFeatureId)) {
8763 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8764 + "subId=" + subId);
8765 return null;
8766 }
Jordan Liuc437b192020-08-17 10:59:12 -07008767 }
8768
Hall Liuf19c44f2018-11-27 14:38:17 -08008769 ServiceState ss = phone.getServiceState();
8770
8771 // Scrub out the location info in ServiceState depending on what level of access
8772 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008773 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008774 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8775 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008776 } finally {
8777 Binder.restoreCallingIdentity(identity);
8778 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008779 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008780
8781 /**
8782 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8783 *
8784 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8785 * voicemail ringtone.
8786 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8787 * PhoneAccount.
8788 */
8789 @Override
8790 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008791 final long identity = Binder.clearCallingIdentity();
8792 try {
8793 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8794 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008795 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008796 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008797
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008798 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8799 } finally {
8800 Binder.restoreCallingIdentity(identity);
8801 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008802 }
8803
8804 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008805 * Sets the per-account voicemail ringtone.
8806 *
8807 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8808 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8809 *
8810 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8811 * voicemail ringtone.
8812 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8813 * PhoneAccount.
8814 */
8815 @Override
8816 public void setVoicemailRingtoneUri(String callingPackage,
8817 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008818 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008819 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008820 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8821 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008822 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8823 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8824 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008825 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008826
8827 final long identity = Binder.clearCallingIdentity();
8828 try {
8829 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8830 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008831 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008832 }
8833 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8834 } finally {
8835 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008836 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008837 }
8838
8839 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008840 * Returns whether vibration is set for voicemail notification in Phone settings.
8841 *
8842 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8843 * voicemail vibration setting.
8844 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8845 */
8846 @Override
8847 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008848 final long identity = Binder.clearCallingIdentity();
8849 try {
8850 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8851 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008852 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008853 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008854
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008855 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8856 } finally {
8857 Binder.restoreCallingIdentity(identity);
8858 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008859 }
8860
Youhan Wange64578a2016-05-02 15:32:42 -07008861 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008862 * Sets the per-account voicemail vibration.
8863 *
8864 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8865 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8866 *
8867 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8868 * voicemail vibration setting.
8869 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8870 * specific PhoneAccount.
8871 */
8872 @Override
8873 public void setVoicemailVibrationEnabled(String callingPackage,
8874 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008875 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008876 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008877 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8878 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008879 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8880 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8881 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008882 }
8883
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008884 final long identity = Binder.clearCallingIdentity();
8885 try {
8886 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8887 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008888 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008889 }
8890 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8891 } finally {
8892 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008893 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008894 }
8895
8896 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008897 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8898 *
8899 * @throws SecurityException if the caller does not have the required permission
8900 */
arunvoddud7401012022-12-15 16:08:12 +00008901 @VisibleForTesting
8902 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008903 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008904 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008905 }
8906
8907 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008908 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8909 * permission.
8910 *
8911 * @throws SecurityException if the caller does not have the required permission
8912 */
8913 private void enforceSendSmsPermission() {
8914 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8915 }
8916
8917 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00008918 * Make sure either called from same process as self (phone) or IPC caller has interact across
8919 * users permission.
8920 *
8921 * @throws SecurityException if the caller does not have the required permission
8922 */
8923 private void enforceInteractAcrossUsersPermission(String message) {
8924 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
8925 }
8926
8927 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008928 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008929 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008930 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008931 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008932 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008933 final long identity = Binder.clearCallingIdentity();
8934 try {
8935 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008936 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008937 if (componentName == null) {
8938 throw new SecurityException(
8939 "Caller not current active visual voicemail package[null]");
8940 }
8941 String vvmPackage = componentName.getPackageName();
8942 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008943 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008944 }
8945 } finally {
8946 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008947 }
8948 }
8949
8950 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008951 * Return the application ID for the app type.
8952 *
8953 * @param subId the subscription ID that this request applies to.
8954 * @param appType the uicc app type.
8955 * @return Application ID for specificied app type, or null if no uicc.
8956 */
8957 @Override
8958 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008959 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008960 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008961
8962 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008963 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008964 if (phone == null) {
8965 return null;
8966 }
8967 String aid = null;
8968 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008969 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008970 .getApplicationByType(appType).getAid();
8971 } catch (Exception e) {
8972 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8973 }
8974 return aid;
8975 } finally {
8976 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008977 }
Youhan Wange64578a2016-05-02 15:32:42 -07008978 }
8979
Youhan Wang4001d252016-05-11 10:29:41 -07008980 /**
8981 * Return the Electronic Serial Number.
8982 *
8983 * @param subId the subscription ID that this request applies to.
8984 * @return ESN or null if error.
8985 */
8986 @Override
8987 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008988 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008989 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008990
8991 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008992 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008993 if (phone == null) {
8994 return null;
8995 }
8996 String esn = null;
8997 try {
8998 esn = phone.getEsn();
8999 } catch (Exception e) {
9000 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9001 }
9002 return esn;
9003 } finally {
9004 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009005 }
Youhan Wang4001d252016-05-11 10:29:41 -07009006 }
9007
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009008 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009009 * Return the Preferred Roaming List Version.
9010 *
9011 * @param subId the subscription ID that this request applies to.
9012 * @return PRLVersion or null if error.
9013 */
9014 @Override
9015 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009016 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07009017 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009018
9019 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009020 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009021 if (phone == null) {
9022 return null;
9023 }
9024 String cdmaPrlVersion = null;
9025 try {
9026 cdmaPrlVersion = phone.getCdmaPrlVersion();
9027 } catch (Exception e) {
9028 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9029 }
9030 return cdmaPrlVersion;
9031 } finally {
9032 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009033 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009034 }
9035
9036 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009037 * Get snapshot of Telephony histograms
9038 * @return List of Telephony histograms
9039 * @hide
9040 */
9041 @Override
9042 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009043 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9044 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009045
9046 final long identity = Binder.clearCallingIdentity();
9047 try {
9048 return RIL.getTelephonyRILTimingHistograms();
9049 } finally {
9050 Binder.restoreCallingIdentity(identity);
9051 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009052 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009053
9054 /**
9055 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009056 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9057 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009058 * Require system privileges. In the future we may add this to carrier APIs.
9059 *
Michele Berionne482f8202018-11-27 18:57:59 -08009060 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009061 */
9062 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009063 @TelephonyManager.SetCarrierRestrictionResult
9064 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009065 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07009066 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009067
Michele Berionne482f8202018-11-27 18:57:59 -08009068 if (carrierRestrictionRules == null) {
9069 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009070 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009071
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009072 final long identity = Binder.clearCallingIdentity();
9073 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009074 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009075 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009076 } finally {
9077 Binder.restoreCallingIdentity(identity);
9078 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009079 }
9080
9081 /**
9082 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009083 * Get the allowed carrier list and the excluded carrier list, including the priority between
9084 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009085 * Require system privileges. In the future we may add this to carrier APIs.
9086 *
Michele Berionne482f8202018-11-27 18:57:59 -08009087 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009088 */
9089 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009090 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009091 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07009092 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009093
9094 final long identity = Binder.clearCallingIdentity();
9095 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009096 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9097 if (response instanceof CarrierRestrictionRules) {
9098 return (CarrierRestrictionRules) response;
9099 }
9100 // Response is an Exception of some kind,
9101 // which is signalled to the user as a NULL retval
9102 return null;
9103 } catch (Exception e) {
9104 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9105 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009106 } finally {
9107 Binder.restoreCallingIdentity(identity);
9108 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009109 }
9110
fionaxu59545b42016-05-25 15:53:37 -07009111 /**
arunvoddud7401012022-12-15 16:08:12 +00009112 * Fetches the carrier restriction status of the device and sends the status to the caller
9113 * through the callback.
9114 *
9115 * @param callback The callback that will be used to send the result.
9116 * @throws SecurityException if the caller does not have the required permission/privileges or
9117 * the caller is not allowlisted.
9118 */
9119 @Override
9120 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
9121 enforceReadPermission("getCarrierRestrictionStatus");
9122 int carrierId = validateCallerAndGetCarrierId(packageName);
9123 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
9124 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9125 throw new SecurityException("Not an authorized caller");
9126 }
9127 final long identity = Binder.clearCallingIdentity();
9128 try {
9129 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
9130 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
9131 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9132 } finally {
9133 Binder.restoreCallingIdentity(identity);
9134 }
9135 }
9136
9137 @VisibleForTesting
9138 public int validateCallerAndGetCarrierId(String packageName) {
9139 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9140 return allowListInfo.validateCallerAndGetCarrierId(packageName);
9141 }
9142
9143 /**
fionaxu59545b42016-05-25 15:53:37 -07009144 * Action set from carrier signalling broadcast receivers to enable/disable radio
9145 * @param subId the subscription ID that this action applies to.
9146 * @param enabled control enable or disable radio.
9147 * {@hide}
9148 */
9149 @Override
9150 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9151 enforceModifyPermission();
9152 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009153
9154 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009155 if (phone == null) {
9156 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9157 return;
9158 }
9159 try {
9160 phone.carrierActionSetRadioEnabled(enabled);
9161 } catch (Exception e) {
9162 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009163 } finally {
9164 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009165 }
9166 }
9167
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009168 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009169 * Enable or disable Voice over NR (VoNR)
9170 * @param subId the subscription ID that this action applies to.
9171 * @param enabled enable or disable VoNR.
9172 * @return operation result.
9173 */
9174 @Override
9175 public int setVoNrEnabled(int subId, boolean enabled) {
9176 enforceModifyPermission();
9177 final Phone phone = getPhone(subId);
9178
9179 final long identity = Binder.clearCallingIdentity();
9180 if (phone == null) {
9181 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9182 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9183 }
9184
9185 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9186 try {
9187 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9188 workSource);
9189 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009190
9191 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9192 if (DBG) {
9193 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9194 }
9195 SubscriptionManager.setSubscriptionProperty(
9196 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9197 (enabled ? "1" : "0"));
9198 }
9199
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009200 return result;
9201 } finally {
9202 Binder.restoreCallingIdentity(identity);
9203 }
9204 }
9205
9206 /**
9207 * Is voice over NR enabled
9208 * @return true if VoNR is enabled else false
9209 */
9210 @Override
9211 public boolean isVoNrEnabled(int subId) {
9212 enforceReadPrivilegedPermission("isVoNrEnabled");
9213 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9214 final long identity = Binder.clearCallingIdentity();
9215 try {
9216 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9217 null, subId, workSource);
9218 if (DBG) log("isVoNrEnabled: " + isEnabled);
9219 return isEnabled;
9220 } finally {
9221 Binder.restoreCallingIdentity(identity);
9222 }
9223 }
9224
9225 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009226 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9227 * network status based on which carrier apps could apply actions accordingly,
9228 * enable/disable default url handler for example.
9229 *
9230 * @param subId the subscription ID that this action applies to.
9231 * @param report control start/stop reporting the default network status.
9232 * {@hide}
9233 */
9234 @Override
9235 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9236 enforceModifyPermission();
9237 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009238
9239 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009240 if (phone == null) {
9241 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9242 return;
9243 }
9244 try {
9245 phone.carrierActionReportDefaultNetworkStatus(report);
9246 } catch (Exception e) {
9247 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009248 } finally {
9249 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009250 }
9251 }
9252
9253 /**
fionaxud9622282017-07-17 17:51:30 -07009254 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9255 * @param subId the subscription ID that this action applies to.
9256 * {@hide}
9257 */
9258 @Override
9259 public void carrierActionResetAll(int subId) {
9260 enforceModifyPermission();
9261 final Phone phone = getPhone(subId);
9262 if (phone == null) {
9263 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9264 return;
9265 }
9266 try {
9267 phone.carrierActionResetAll();
9268 } catch (Exception e) {
9269 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9270 }
9271 }
9272
9273 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009274 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9275 * bug report is being generated.
9276 */
9277 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009278 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009279 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9280 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009281 writer.println("Permission Denial: can't dump Phone from pid="
9282 + Binder.getCallingPid()
9283 + ", uid=" + Binder.getCallingUid()
9284 + "without permission "
9285 + android.Manifest.permission.DUMP);
9286 return;
9287 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009288 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009289 }
Jack Yueb89b242016-06-22 13:27:47 -07009290
Brad Ebingerdac2f002018-04-03 15:17:52 -07009291 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009292 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9293 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9294 @NonNull String[] args) {
9295 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9296 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009297 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009298 }
9299
Jack Yueb89b242016-06-22 13:27:47 -07009300 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009301 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009302 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009303 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009304 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009305 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009306 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009307 */
9308 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009309 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009310 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009311 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9312 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9313 try {
9314 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009315 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009316 } catch (SecurityException se) {
9317 enforceModifyPermission();
9318 }
9319 } else {
9320 enforceModifyPermission();
9321 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009322
9323 final long identity = Binder.clearCallingIdentity();
9324 try {
9325 Phone phone = getPhone(subId);
9326 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009327 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9328 phone.carrierActionSetMeteredApnsEnabled(enabled);
9329 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07009330 phone.getDataSettingsManager().setDataEnabled(
9331 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009332 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009333 }
9334 } finally {
9335 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009336 }
9337 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009338
9339 /**
9340 * Get Client request stats
9341 * @return List of Client Request Stats
9342 * @hide
9343 */
9344 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009345 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9346 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009347 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009348 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009349 return null;
9350 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009351 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009352
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009353 final long identity = Binder.clearCallingIdentity();
9354 try {
9355 if (phone != null) {
9356 return phone.getClientRequestStats();
9357 }
9358
9359 return null;
9360 } finally {
9361 Binder.restoreCallingIdentity(identity);
9362 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009363 }
9364
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009365 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009366 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009367 if (uid == Process.ROOT_UID && packageName == null) {
9368 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9369 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9370 // exception. ROOT_UID seems not to have a valid package name returned by
9371 // PackageManager, so just fake it here to avoid issues when running telephony shell
9372 // commands that plumb through the RIL as root, like so:
9373 // $ adb root
9374 // $ adb shell cmd phone ...
9375 packageName = "root";
9376 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009377 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009378 }
Jack Yueb4124c2017-02-16 15:32:43 -08009379
9380 /**
Grace Chen70990072017-03-24 17:21:30 -07009381 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009382 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009383 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009384 * @param state State of SIM (power down, power up, pass through)
9385 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9386 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9387 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009388 *
9389 **/
9390 @Override
Grace Chen70990072017-03-24 17:21:30 -07009391 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009392 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009393 Phone phone = PhoneFactory.getPhone(slotIndex);
9394
vagdeviaf9a5b92018-08-15 16:01:53 -07009395 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9396
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009397 final long identity = Binder.clearCallingIdentity();
9398 try {
9399 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009400 phone.setSimPowerState(state, null, workSource);
9401 }
9402 } finally {
9403 Binder.restoreCallingIdentity(identity);
9404 }
9405 }
9406
9407 /**
9408 * Set SIM card power state.
9409 *
9410 * @param slotIndex SIM slot id.
9411 * @param state State of SIM (power down, power up, pass through)
9412 * @param callback callback to trigger after success or failure
9413 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9414 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9415 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9416 *
9417 **/
9418 @Override
9419 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9420 IIntegerConsumer callback) {
9421 enforceModifyPermission();
9422 Phone phone = PhoneFactory.getPhone(slotIndex);
9423
9424 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9425
9426 final long identity = Binder.clearCallingIdentity();
9427 try {
9428 if (phone != null) {
9429 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9430 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009431 }
9432 } finally {
9433 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009434 }
9435 }
Shuo Qiandd210312017-04-12 22:11:33 +00009436
Tyler Gunn65d45c22017-06-05 11:22:26 -07009437 private boolean isUssdApiAllowed(int subId) {
9438 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009439 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009440 if (configManager == null) {
9441 return false;
9442 }
9443 PersistableBundle pb = configManager.getConfigForSubId(subId);
9444 if (pb == null) {
9445 return false;
9446 }
9447 return pb.getBoolean(
9448 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9449 }
9450
Shuo Qiandd210312017-04-12 22:11:33 +00009451 /**
9452 * Check if phone is in emergency callback mode
9453 * @return true if phone is in emergency callback mode
9454 * @param subId sub id
9455 */
goneil9c5f4872017-12-05 14:07:56 -08009456 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009457 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009458 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00009459 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009460
9461 final long identity = Binder.clearCallingIdentity();
9462 try {
9463 if (phone != null) {
9464 return phone.isInEcm();
9465 } else {
9466 return false;
9467 }
9468 } finally {
9469 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009470 }
9471 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009472
9473 /**
9474 * Get the current signal strength information for the given subscription.
9475 * Because this information is not updated when the device is in a low power state
9476 * it should not be relied-upon to be current.
9477 * @param subId Subscription index
9478 * @return the most recent cached signal strength info from the modem
9479 */
9480 @Override
9481 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009482 final long identity = Binder.clearCallingIdentity();
9483 try {
9484 Phone p = getPhone(subId);
9485 if (p == null) {
9486 return null;
9487 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009488
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009489 return p.getSignalStrength();
9490 } finally {
9491 Binder.restoreCallingIdentity(identity);
9492 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009493 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009494
Pengquan Meng77b7f132018-08-22 14:49:57 -07009495 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009496 * Get the current modem radio state for the given slot.
9497 * @param slotIndex slot index.
9498 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009499 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009500 * @return the current radio power state from the modem
9501 */
9502 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009503 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009504 Phone phone = PhoneFactory.getPhone(slotIndex);
9505 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009506 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9507 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009508 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9509 }
9510
9511 final long identity = Binder.clearCallingIdentity();
9512 try {
9513 return phone.getRadioPowerState();
9514 } finally {
9515 Binder.restoreCallingIdentity(identity);
9516 }
9517 }
9518 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9519 }
9520
9521 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009522 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9523 *
9524 * <p>Requires one of the following permissions:
9525 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009526 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009527 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9528 * privileges.
9529 *
9530 * @param subId subscription id
9531 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9532 * {@code false}.
9533 */
9534 @Override
9535 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009536 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009537 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009538 try {
9539 mApp.enforceCallingOrSelfPermission(
9540 android.Manifest.permission.ACCESS_NETWORK_STATE,
9541 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009542 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009543 mApp.enforceCallingOrSelfPermission(
9544 permission.READ_BASIC_PHONE_STATE, functionName);
9545 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009546 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009547 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009548 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009549 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009550
Pengquan Menga1bb6272018-09-06 09:59:22 -07009551 boolean isEnabled = false;
9552 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009553 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009554 Phone phone = getPhone(subId);
9555 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009556 } finally {
9557 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009558 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009559 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009560 }
9561
9562
9563 /**
9564 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9565 *
9566 * <p> Requires permission:
9567 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9568 * privileges.
9569 *
9570 * @param subId subscription id
9571 * @param isEnabled {@code true} means enable, {@code false} means disable.
9572 */
9573 @Override
9574 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009575 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9576 mApp, subId, "setDataRoamingEnabled");
9577
Pengquan Menga1bb6272018-09-06 09:59:22 -07009578 final long identity = Binder.clearCallingIdentity();
9579 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009580 Phone phone = getPhone(subId);
9581 if (phone != null) {
9582 phone.setDataRoamingEnabled(isEnabled);
9583 }
9584 } finally {
9585 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009586 }
9587 }
9588
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009589 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009590 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009591 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009592 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009593 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009594
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009595 boolean isAllowed = true;
9596 final long identity = Binder.clearCallingIdentity();
9597 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009598 Phone phone = getPhone(subId);
9599 if (phone != null) {
9600 isAllowed = phone.isCspPlmnEnabled();
9601 }
9602 } finally {
9603 Binder.restoreCallingIdentity(identity);
9604 }
9605 return isAllowed;
9606 }
9607
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009608 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9609 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009610 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009611 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009612 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009613 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9614 if (phone == null) {
9615 return false;
9616 }
9617 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9618 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9619 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009620 }
9621
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009622 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009623 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009624 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009625 mApp.getSystemService(AppOpsManager.class)
9626 .checkPackage(Binder.getCallingUid(), callingPackage);
9627
Jordan Liu1e142fc2019-04-22 15:10:43 -07009628 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009629 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009630 try {
9631 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009632 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009633 } catch (SecurityException e) {
9634 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9635 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009636 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009637 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009638 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009639 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009640 }
sandeepjsb6c87872021-09-27 15:34:44 +00009641 // checking compatibility, if calling app's target SDK is T and beyond.
9642 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9643 Binder.getCallingUid())) {
9644 isIccIdAccessRestricted = true;
9645 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009646 final long identity = Binder.clearCallingIdentity();
9647 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009648 UiccController uiccController = UiccController.getInstance();
9649 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009650 if (hasReadPermission) {
9651 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009652 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009653
9654 // Remove private info if the caller doesn't have access
9655 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9656 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009657 //setting the value after compatibility check
9658 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009659 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9660 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009661 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009662 if (card == null) {
9663 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009664 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009665 continue;
9666 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009667 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9668 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009669 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009670 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009671 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009672 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9673 for (UiccPortInfo portInfo : portInfos) {
9674 UiccPort port = uiccController.getUiccPortForSlot(
9675 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9676 if (port == null) {
9677 // assume no access if port is null
9678 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9679 continue;
9680 }
9681 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9682 uiccPortInfos.add(portInfo);
9683 } else {
9684 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9685 }
9686 }
9687 filteredInfos.add(new UiccCardInfo(
9688 cardInfo.isEuicc(),
9689 cardInfo.getCardId(),
9690 null,
9691 cardInfo.getPhysicalSlotIndex(),
9692 cardInfo.isRemovable(),
9693 cardInfo.isMultipleEnabledProfilesSupported(),
9694 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009695 }
9696 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009697 } finally {
9698 Binder.restoreCallingIdentity(identity);
9699 }
9700 }
9701
sandeepjsb6c87872021-09-27 15:34:44 +00009702 /**
9703 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9704 * generally private and require carrier privileges to view.
9705 *
9706 * @hide
9707 */
9708 @NonNull
9709 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9710 List<UiccPortInfo> portinfo = new ArrayList<>();
9711 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9712 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9713 }
9714 return new UiccCardInfo(
9715 cardInfo.isEuicc(),
9716 cardInfo.getCardId(),
9717 null,
9718 cardInfo.getPhysicalSlotIndex(),
9719 cardInfo.isRemovable(),
9720 cardInfo.isMultipleEnabledProfilesSupported(),
9721 portinfo
9722 );
9723 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009724
sandeepjsb6c87872021-09-27 15:34:44 +00009725 /**
9726 * @hide
9727 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9728 * These values are generally private and require carrier privileges to view.
9729 */
9730 @NonNull
9731 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9732 return new UiccPortInfo(
9733 UiccPortInfo.ICCID_REDACTED,
9734 portInfo.getPortIndex(),
9735 portInfo.getLogicalSlotIndex(),
9736 portInfo.isActive()
9737 );
9738 }
9739 @Override
9740 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009741 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009742 mApp.getSystemService(AppOpsManager.class)
9743 .checkPackage(Binder.getCallingUid(), callingPackage);
9744
sandeepjsb6c87872021-09-27 15:34:44 +00009745 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009746
Aman Guptaf3c90b32022-03-17 04:54:16 +00009747 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9748 // we are reading iccId which is PII data.
9749 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009750
9751 // checking compatibility, if calling app's target SDK is T and beyond.
9752 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9753 Binder.getCallingUid())) {
9754 isLogicalSlotAccessRestricted = true;
9755 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009756 final long identity = Binder.clearCallingIdentity();
9757 try {
9758 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009759 if (slots == null || slots.length == 0) {
9760 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009761 return null;
9762 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009763 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9764 for (int i = 0; i < slots.length; i++) {
9765 UiccSlot slot = slots[i];
9766 if (slot == null) {
9767 continue;
9768 }
9769
Jordan Liu7be7e652019-05-06 18:55:02 +00009770 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009771 UiccCard card = slot.getUiccCard();
9772 if (card != null) {
9773 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009774 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009775 cardId = slot.getEid();
9776 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009777 // If cardId is null, use iccId of default port as cardId.
9778 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009779 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009780 }
9781
Jordan Liu857451f2019-05-09 16:35:35 -07009782 if (cardId != null) {
9783 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9784 // if cardId is an EID, it's all digits so this is fine
9785 cardId = IccUtils.stripTrailingFs(cardId);
9786 }
9787
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009788 int cardState = 0;
9789 switch (slot.getCardState()) {
9790 case CARDSTATE_ABSENT:
9791 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9792 break;
9793 case CARDSTATE_PRESENT:
9794 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9795 break;
9796 case CARDSTATE_ERROR:
9797 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9798 break;
9799 case CARDSTATE_RESTRICTED:
9800 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9801 break;
9802 default:
9803 break;
9804
9805 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009806 List<UiccPortInfo> portInfos = new ArrayList<>();
9807 int[] portIndexes = slot.getPortList();
9808 for (int portIdx : portIndexes) {
9809 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009810 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009811 portInfos.add(new UiccPortInfo(iccId, portIdx,
9812 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009813 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009814 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009815 slot.isEuicc(),
9816 cardId,
9817 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009818 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009819 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009820 //setting the value after compatibility check
9821 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009822 }
9823 return infos;
9824 } finally {
9825 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009826 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009827 }
9828
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009829 /* Returns null if doesn't have read permission or carrier privilege access. */
9830 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9831 boolean hasReadPermission) {
9832 String iccId = slot.getIccId(portIndex);
9833 if (hasReadPermission) { // if has read permission
9834 return iccId;
9835 } else {
9836 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9837 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9838 // if no read permission, checking carrier privilege access
9839 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9840 return iccId;
9841 }
9842 }
9843 }
9844 // No read permission or carrier privilege access.
9845 return UiccPortInfo.ICCID_REDACTED;
9846 }
9847
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009848 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009849 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009850 public boolean switchSlots(int[] physicalSlots) {
9851 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009852
9853 final long identity = Binder.clearCallingIdentity();
9854 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009855 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9856 for (int i = 0; i < physicalSlots.length; i++) {
9857 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9858 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9859 physicalSlots[i], i));
9860 }
9861 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009862 } finally {
9863 Binder.restoreCallingIdentity(identity);
9864 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009865 }
Jack Yu4c988042018-02-27 15:30:01 -08009866
9867 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009868 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9869 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9870 enforceModifyPermission();
9871
9872 final long identity = Binder.clearCallingIdentity();
9873 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009874 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009875 } finally {
9876 Binder.restoreCallingIdentity(identity);
9877 }
9878 }
9879
9880 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009881 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009882 final long identity = Binder.clearCallingIdentity();
9883 try {
9884 return UiccController.getInstance().getCardIdForDefaultEuicc();
9885 } finally {
9886 Binder.restoreCallingIdentity(identity);
9887 }
9888 }
9889
Pengquan Meng85728fb2018-03-12 16:31:21 -07009890 /**
goneil47ffb6e2018-04-06 15:40:58 -07009891 * A test API to reload the UICC profile.
9892 *
9893 * <p>Requires that the calling app has permission
9894 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9895 * @hide
9896 */
9897 @Override
9898 public void refreshUiccProfile(int subId) {
9899 enforceModifyPermission();
9900
9901 final long identity = Binder.clearCallingIdentity();
9902 try {
9903 Phone phone = getPhone(subId);
9904 if (phone == null) {
9905 return;
9906 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009907 UiccPort uiccPort = phone.getUiccPort();
9908 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009909 return;
9910 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009911 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009912 if (uiccProfile == null) {
9913 return;
9914 }
9915 uiccProfile.refresh();
9916 } finally {
9917 Binder.restoreCallingIdentity(identity);
9918 }
9919 }
9920
9921 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009922 * Returns false if the mobile data is disabled by default, otherwise return true.
9923 */
9924 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009925 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009926 }
9927
9928 /**
9929 * Returns true if the data roaming is enabled by default, i.e the system property
9930 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9931 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9932 */
9933 private boolean getDefaultDataRoamingEnabled(int subId) {
9934 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009935 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009936 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009937 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9938 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9939 return isDataRoamingEnabled;
9940 }
9941
9942 /**
9943 * Returns the default network type for the given {@code subId}, if the default network type is
9944 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9945 */
9946 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009947 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -08009948 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +09009949 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9950 return list.get(phoneId);
9951 }
9952 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009953 }
fionaxua13278b2018-03-21 00:08:13 -07009954
9955 @Override
9956 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009957 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009958 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009959
9960 final long identity = Binder.clearCallingIdentity();
9961 try {
9962 final Phone phone = getPhone(subId);
9963 if (phone == null) {
9964 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9965 return;
9966 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009967 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9968 if (cpt != null) {
9969 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9970 }
9971 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009972 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9973 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009974 if (carrierPrivilegeRules == null) {
9975 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9976 } else {
9977 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9978 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009979 } finally {
9980 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009981 }
fionaxua13278b2018-03-21 00:08:13 -07009982 }
9983
9984 @Override
9985 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009986 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009987
9988 final long identity = Binder.clearCallingIdentity();
9989 try {
9990 final Phone phone = getPhone(subId);
9991 if (phone == null) {
9992 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9993 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9994 }
9995 return phone.getCarrierIdListVersion();
9996 } finally {
9997 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009998 }
fionaxua13278b2018-03-21 00:08:13 -07009999 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010000
10001 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010002 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10003 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010004 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010005 mApp, subId, callingPackage, callingFeatureId,
10006 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010007 return -1;
10008 }
10009
10010 final long identity = Binder.clearCallingIdentity();
10011 try {
10012 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10013 } finally {
10014 Binder.restoreCallingIdentity(identity);
10015 }
10016 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010017
10018 @Override
10019 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010020 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010021 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010022 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010023
10024 final long identity = Binder.clearCallingIdentity();
10025 try {
10026 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10027 } finally {
10028 Binder.restoreCallingIdentity(identity);
10029 }
10030 }
10031
10032 @Override
10033 public boolean setCdmaRoamingMode(int subId, int mode) {
10034 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10035 mApp, subId, "setCdmaRoamingMode");
10036
10037 final long identity = Binder.clearCallingIdentity();
10038 try {
10039 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10040 } finally {
10041 Binder.restoreCallingIdentity(identity);
10042 }
10043 }
10044
10045 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010046 public int getCdmaSubscriptionMode(int subId) {
10047 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010048 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010049 mApp, subId, "getCdmaSubscriptionMode");
10050
10051 final long identity = Binder.clearCallingIdentity();
10052 try {
10053 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10054 } finally {
10055 Binder.restoreCallingIdentity(identity);
10056 }
10057 }
10058
10059 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010060 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10061 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10062 mApp, subId, "setCdmaSubscriptionMode");
10063
10064 final long identity = Binder.clearCallingIdentity();
10065 try {
10066 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10067 } finally {
10068 Binder.restoreCallingIdentity(identity);
10069 }
10070 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010071
sqianc5eccab2018-10-19 18:46:41 -070010072 @Override
sqian8c685422019-02-22 15:55:18 -080010073 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010074 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010075 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010076 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10077 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010078 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10079 }
10080 final long identity = Binder.clearCallingIdentity();
10081 try {
sqian854d44b2018-12-12 16:48:18 -080010082 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10083 for (Phone phone: PhoneFactory.getPhones()) {
10084 if (phone.getEmergencyNumberTracker() != null
10085 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10086 emergencyNumberListInternal.put(
10087 phone.getSubId(),
10088 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10089 }
sqian11b7a0e2018-12-05 18:48:28 -080010090 }
sqian854d44b2018-12-12 16:48:18 -080010091 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010092 } finally {
10093 Binder.restoreCallingIdentity(identity);
10094 }
sqianc5eccab2018-10-19 18:46:41 -070010095 }
10096
10097 @Override
sqian8c685422019-02-22 15:55:18 -080010098 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010099 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010100 if (!exactMatch) {
10101 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010102 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010103 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010104 }
10105 final long identity = Binder.clearCallingIdentity();
10106 try {
sqian854d44b2018-12-12 16:48:18 -080010107 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010108 //Note: we ignore passed in param exactMatch. We can remove it once
10109 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010110 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010111 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010112 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010113 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010114 }
sqian11b7a0e2018-12-05 18:48:28 -080010115 }
10116 return false;
10117 } finally {
10118 Binder.restoreCallingIdentity(identity);
10119 }
10120 }
10121
sqianf4ca7ed2019-01-15 18:32:07 -080010122 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010123 * Start emergency callback mode for GsmCdmaPhone for testing.
10124 */
10125 @Override
10126 public void startEmergencyCallbackMode() {
10127 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10128 "startEmergencyCallbackMode");
10129 enforceModifyPermission();
10130 final long identity = Binder.clearCallingIdentity();
10131 try {
10132 for (Phone phone : PhoneFactory.getPhones()) {
10133 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10134 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10135 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10136 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10137 gsmCdmaPhone.obtainMessage(
10138 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10139 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10140 }
10141 }
10142 } finally {
10143 Binder.restoreCallingIdentity(identity);
10144 }
10145 }
10146
10147 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010148 * Update emergency number list for test mode.
10149 */
10150 @Override
10151 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10152 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10153 "updateEmergencyNumberListTestMode");
10154
10155 final long identity = Binder.clearCallingIdentity();
10156 try {
10157 for (Phone phone: PhoneFactory.getPhones()) {
10158 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10159 if (tracker != null) {
10160 tracker.executeEmergencyNumberTestModeCommand(action, num);
10161 }
10162 }
10163 } finally {
10164 Binder.restoreCallingIdentity(identity);
10165 }
10166 }
10167
10168 /**
10169 * Get the full emergency number list for test mode.
10170 */
10171 @Override
10172 public List<String> getEmergencyNumberListTestMode() {
10173 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10174 "getEmergencyNumberListTestMode");
10175
10176 final long identity = Binder.clearCallingIdentity();
10177 try {
10178 Set<String> emergencyNumbers = new HashSet<>();
10179 for (Phone phone: PhoneFactory.getPhones()) {
10180 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10181 if (tracker != null) {
10182 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10183 emergencyNumbers.add(num.getNumber());
10184 }
10185 }
10186 }
10187 return new ArrayList<>(emergencyNumbers);
10188 } finally {
10189 Binder.restoreCallingIdentity(identity);
10190 }
10191 }
10192
chen xud6b45bd2018-10-30 22:27:10 -070010193 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010194 public int getEmergencyNumberDbVersion(int subId) {
10195 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10196
10197 final long identity = Binder.clearCallingIdentity();
10198 try {
10199 final Phone phone = getPhone(subId);
10200 if (phone == null) {
10201 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10202 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10203 }
10204 return phone.getEmergencyNumberDbVersion();
10205 } finally {
10206 Binder.restoreCallingIdentity(identity);
10207 }
10208 }
10209
10210 @Override
10211 public void notifyOtaEmergencyNumberDbInstalled() {
10212 enforceModifyPermission();
10213
10214 final long identity = Binder.clearCallingIdentity();
10215 try {
10216 for (Phone phone: PhoneFactory.getPhones()) {
10217 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10218 if (tracker != null) {
10219 tracker.updateOtaEmergencyNumberDatabase();
10220 }
10221 }
10222 } finally {
10223 Binder.restoreCallingIdentity(identity);
10224 }
10225 }
10226
10227 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010228 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010229 enforceActiveEmergencySessionPermission();
10230
10231 final long identity = Binder.clearCallingIdentity();
10232 try {
10233 for (Phone phone: PhoneFactory.getPhones()) {
10234 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10235 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010236 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10237 }
10238 }
10239 } finally {
10240 Binder.restoreCallingIdentity(identity);
10241 }
10242 }
10243
10244 @Override
10245 public void resetOtaEmergencyNumberDbFilePath() {
10246 enforceActiveEmergencySessionPermission();
10247
10248 final long identity = Binder.clearCallingIdentity();
10249 try {
10250 for (Phone phone: PhoneFactory.getPhones()) {
10251 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10252 if (tracker != null) {
10253 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010254 }
10255 }
10256 } finally {
10257 Binder.restoreCallingIdentity(identity);
10258 }
10259 }
10260
10261 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010262 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10263 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10264 Phone phone = getPhone(subId);
10265 if (phone == null) {
10266 return null;
10267 }
10268 final long identity = Binder.clearCallingIdentity();
10269 try {
10270 UiccProfile profile = UiccController.getInstance()
10271 .getUiccProfileForPhone(phone.getPhoneId());
10272 if (profile != null) {
10273 return profile.getCertsFromCarrierPrivilegeAccessRules();
10274 }
10275 } finally {
10276 Binder.restoreCallingIdentity(identity);
10277 }
10278 return null;
10279 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010280
10281 /**
10282 * Enable or disable a modem stack.
10283 */
10284 @Override
10285 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10286 enforceModifyPermission();
10287
10288 final long identity = Binder.clearCallingIdentity();
10289 try {
10290 Phone phone = PhoneFactory.getPhone(slotIndex);
10291 if (phone == null) {
10292 return false;
10293 } else {
10294 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10295 }
10296 } finally {
10297 Binder.restoreCallingIdentity(identity);
10298 }
10299 }
Michelecea4cf22018-12-21 15:00:11 -080010300
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010301 /**
10302 * Whether a modem stack is enabled or not.
10303 */
10304 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010305 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10306 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010307 Phone phone = PhoneFactory.getPhone(slotIndex);
10308 if (phone == null) return false;
10309
10310 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010311 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10312 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010313 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10314 }
10315
10316 final long identity = Binder.clearCallingIdentity();
10317 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010318 try {
10319 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10320 } catch (NoSuchElementException ex) {
10321 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10322 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010323 } finally {
10324 Binder.restoreCallingIdentity(identity);
10325 }
10326 }
10327
Michelecea4cf22018-12-21 15:00:11 -080010328 @Override
Michele0ea7d782019-03-19 14:58:42 -070010329 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010330 enforceModifyPermission();
10331
10332 final long identity = Binder.clearCallingIdentity();
10333 try {
10334 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010335 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010336 .commit();
10337 } finally {
10338 Binder.restoreCallingIdentity(identity);
10339 }
10340 }
10341
10342 @Override
Michele0ea7d782019-03-19 14:58:42 -070010343 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010344 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010345 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010346 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10347 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010348 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010349 }
Michelecea4cf22018-12-21 15:00:11 -080010350
10351 final long identity = Binder.clearCallingIdentity();
10352 try {
Michele0ea7d782019-03-19 14:58:42 -070010353 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010354 } finally {
10355 Binder.restoreCallingIdentity(identity);
10356 }
10357 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010358
Michele0ea7d782019-03-19 14:58:42 -070010359 @TelephonyManager.IsMultiSimSupportedResult
10360 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010361 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10362 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10363 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010364 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10365 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010366 }
10367 // Check if the hardware supports multisim functionality. If usage of multisim is not
10368 // supported by the modem, indicate that it is restricted.
10369 PhoneCapability staticCapability =
10370 mPhoneConfigurationManager.getStaticPhoneCapability();
10371 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010372 loge("isMultiSimSupportedInternal: no static configuration available");
10373 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010374 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010375 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010376 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10377 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010378 }
10379 // Check if support of multiple SIMs is restricted by carrier
10380 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010381 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010382 }
10383
Michele0ea7d782019-03-19 14:58:42 -070010384 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010385 }
10386
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010387 /**
10388 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010389 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10390 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10391 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010392 * @param numOfSims number of active sims we want to switch to
10393 */
10394 @Override
10395 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010396 if (numOfSims == 1) {
10397 enforceModifyPermission();
10398 } else {
10399 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10400 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10401 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010402 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010403
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010404 try {
Michele30b57b22019-03-01 12:01:14 -080010405 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010406 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010407 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10408 return;
10409 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010410 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10411 } finally {
10412 Binder.restoreCallingIdentity(identity);
10413 }
10414 }
10415
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010416 @Override
10417 public boolean isApplicationOnUicc(int subId, int appType) {
10418 enforceReadPrivilegedPermission("isApplicationOnUicc");
10419 Phone phone = getPhone(subId);
10420 if (phone == null) {
10421 return false;
10422 }
10423 final long identity = Binder.clearCallingIdentity();
10424 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010425 UiccPort uiccPort = phone.getUiccPort();
10426 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010427 return false;
10428 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010429 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010430 if (uiccProfile == null) {
10431 return false;
10432 }
10433 if (TelephonyManager.APPTYPE_SIM <= appType
10434 && appType <= TelephonyManager.APPTYPE_ISIM) {
10435 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10436 }
10437 return false;
10438 } finally {
10439 Binder.restoreCallingIdentity(identity);
10440 }
10441 }
10442
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010443 /**
chen xub4baa772019-04-03 10:23:41 -070010444 * Get whether making changes to modem configurations will trigger reboot.
10445 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010446 */
10447 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010448 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10449 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010450 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010451 mApp, subId, callingPackage, callingFeatureId,
10452 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010453 return false;
10454 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010455 final long identity = Binder.clearCallingIdentity();
10456 try {
10457 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10458 } finally {
10459 Binder.restoreCallingIdentity(identity);
10460 }
10461 }
10462
Nathan Harold29f5f052019-02-15 13:41:57 -080010463 private void updateModemStateMetrics() {
10464 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10465 // TODO: check the state for each modem if the api is ready.
10466 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10467 }
10468
Pengquan Meng3889a572019-01-23 11:16:29 -080010469 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010470 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010471 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010472 // Verify that the callingPackage belongs to the calling UID
10473 mApp.getSystemService(AppOpsManager.class)
10474 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -080010475 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010476 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010477 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010478 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10479 if (slotInfos != null) {
10480 for (int i = 0; i < slotInfos.length; i++) {
10481 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10482 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10483 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10484 portInfo.getLogicalSlotIndex()));
10485 }
10486 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010487 }
10488 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010489 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010490 } finally {
10491 Binder.restoreCallingIdentity(identity);
10492 }
10493 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010494
10495 /**
10496 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010497 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010498 */
jimsunf9ec1622022-09-13 21:18:43 +080010499 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010500 @Override
10501 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010502 return getHalVersion(HAL_SERVICE_RADIO);
10503 }
10504
10505 /**
10506 * Get the HAL Version of a specific service
10507 */
10508 @Override
10509 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010510 Phone phone = getDefaultPhone();
10511 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010512 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010513 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10514 return hv.major * 100 + hv.minor;
10515 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010516
10517 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010518 * Get the current calling package name.
10519 * @return the current calling package name
10520 */
10521 @Override
10522 public String getCurrentPackageName() {
10523 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
10524 }
10525
10526 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010527 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10528 * corresponding network requests on a subId.
10529 *
10530 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010531 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010532 * 2) APN is un-metered for this subscription, or
10533 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010534 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010535 *
10536 * @return whether data is allowed for a apn type.
10537 *
10538 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010539 */
10540 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010541 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010542 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10543 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010544
10545 // Now that all security checks passes, perform the operation as ourselves.
10546 final long identity = Binder.clearCallingIdentity();
10547 try {
10548 Phone phone = getPhone(subId);
10549 if (phone == null) return false;
10550
Jack Yu27422a52022-03-21 10:38:05 -070010551 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010552 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010553 isMetered = phone.getDataNetworkController().getDataConfigManager()
10554 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10555 phone.getServiceState().getDataRoaming());
10556 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010557 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010558 } finally {
10559 Binder.restoreCallingIdentity(identity);
10560 }
10561 }
10562
10563 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010564 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010565 enforceReadPrivilegedPermission("isApnMetered");
10566
10567 // Now that all security checks passes, perform the operation as ourselves.
10568 final long identity = Binder.clearCallingIdentity();
10569 try {
10570 Phone phone = getPhone(subId);
10571 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010572 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10573 DataUtils.apnTypeToNetworkCapability(apnType),
10574 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010575 } finally {
10576 Binder.restoreCallingIdentity(identity);
10577 }
10578 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010579
10580 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010581 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10582 int subscriptionId, IBooleanConsumer resultCallback) {
10583 enforceModifyPermission();
10584 long token = Binder.clearCallingIdentity();
10585 try {
10586 Phone phone = getPhone(subscriptionId);
10587 if (phone == null) {
10588 try {
10589 if (resultCallback != null) {
10590 resultCallback.accept(false);
10591 }
10592 } catch (RemoteException e) {
10593 // ignore
10594 }
10595 return;
10596 }
10597 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10598 Pair.create(specifiers, (x) -> {
10599 try {
10600 if (resultCallback != null) {
10601 resultCallback.accept(x);
10602 }
10603 } catch (RemoteException e) {
10604 // ignore
10605 }
10606 });
10607 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10608 } finally {
10609 Binder.restoreCallingIdentity(token);
10610 }
10611 }
10612
10613 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010614 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10615 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010616 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010617 mApp, subId, "getSystemSelectionChannels");
10618 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10619 final long identity = Binder.clearCallingIdentity();
10620 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010621 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10622 if (result instanceof IllegalStateException) {
10623 throw (IllegalStateException) result;
10624 }
10625 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010626 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10627 return specifiers;
10628 } finally {
10629 Binder.restoreCallingIdentity(identity);
10630 }
10631 }
10632
10633 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010634 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010635 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010636 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010637 }
10638
10639 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010640 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10641 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010642 if (callingPackage == null) {
10643 callingPackage = getCurrentPackageName();
10644 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010645 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10646 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010647 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10648 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010649 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10650 }
10651 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10652 Intent intent = new Intent();
10653 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10654 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10655 // Bring up choose default SMS subscription dialog right now
10656 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10657 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10658 mApp.startActivity(intent);
10659 }
chen xud5ca2d52019-05-28 15:20:57 -070010660
10661 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010662 public void showSwitchToManagedProfileDialog() {
10663 enforceModifyPermission();
10664
10665 Intent intent = new Intent();
10666 intent.setClass(mApp, ErrorDialogActivity.class);
10667 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10668 mApp.startActivity(intent);
10669 }
10670
10671 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010672 public String getMmsUAProfUrl(int subId) {
10673 //TODO investigate if this API should require proper permission check in R b/133791609
10674 final long identity = Binder.clearCallingIdentity();
10675 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010676 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10677 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10678 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10679 return carrierUAProfUrl;
10680 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010681 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10682 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010683 } finally {
10684 Binder.restoreCallingIdentity(identity);
10685 }
10686 }
10687
10688 @Override
10689 public String getMmsUserAgent(int subId) {
10690 //TODO investigate if this API should require proper permission check in R b/133791609
10691 final long identity = Binder.clearCallingIdentity();
10692 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010693 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10694 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10695 if (!TextUtils.isEmpty(carrierUserAgent)) {
10696 return carrierUserAgent;
10697 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010698 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10699 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010700 } finally {
10701 Binder.restoreCallingIdentity(identity);
10702 }
10703 }
Jack Yub07d4972019-05-28 16:12:25 -070010704
10705 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010706 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10707 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010708
Jack Yub07d4972019-05-28 16:12:25 -070010709 final long identity = Binder.clearCallingIdentity();
10710 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010711 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010712 if (phone == null) return false;
10713
Ling Maf188d502022-09-16 15:22:36 -070010714 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010715 } finally {
10716 Binder.restoreCallingIdentity(identity);
10717 }
10718 }
10719
10720 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010721 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010722 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010723 enforceModifyPermission();
10724
changbettyd5c246e2019-12-24 15:40:37 +080010725 final long identity = Binder.clearCallingIdentity();
10726 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010727 Phone phone = getPhone(subscriptionId);
10728 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010729
Ling Maf188d502022-09-16 15:22:36 -070010730 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010731 } finally {
10732 Binder.restoreCallingIdentity(identity);
10733 }
10734 }
10735
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010736 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010737 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010738 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10739 * otherwise.
10740 */
10741 @Override
10742 public void setCepEnabled(boolean isCepEnabled) {
10743 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10744
10745 final long identity = Binder.clearCallingIdentity();
10746 try {
10747 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10748 for (Phone phone : PhoneFactory.getPhones()) {
10749 Phone defaultPhone = phone.getImsPhone();
10750 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10751 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10752 ImsPhoneCallTracker imsPhoneCallTracker =
10753 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10754 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10755 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10756 + imsPhone.getMsisdn());
10757 }
10758 }
10759 } finally {
10760 Binder.restoreCallingIdentity(identity);
10761 }
10762 }
allenwtsu46dcc572020-01-08 18:24:03 +080010763
10764 /**
10765 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10766 *
10767 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10768 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10769 * before being read.
10770 */
10771 @Override
10772 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10773 isCompressed) {
10774 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10775 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010776 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10777 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10778 }
10779 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010780 // ProvisioningManager can not handle ServiceSpecificException.
10781 // Throw the IllegalStateException and annotate ProvisioningManager.
10782 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010783 }
10784
10785 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010786 try {
Hui Wang761a6682020-10-31 05:12:53 +000010787 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10788 } finally {
10789 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010790 }
10791 }
zoey chene02881a2019-12-30 16:11:23 +080010792
10793 @Override
10794 public boolean isIccLockEnabled(int subId) {
10795 enforceReadPrivilegedPermission("isIccLockEnabled");
10796
10797 // Now that all security checks passes, perform the operation as ourselves.
10798 final long identity = Binder.clearCallingIdentity();
10799 try {
10800 Phone phone = getPhone(subId);
10801 if (phone != null && phone.getIccCard() != null) {
10802 return phone.getIccCard().getIccLockEnabled();
10803 } else {
10804 return false;
10805 }
10806 } finally {
10807 Binder.restoreCallingIdentity(identity);
10808 }
10809 }
10810
10811 /**
10812 * Set the ICC pin lock enabled or disabled.
10813 *
10814 * @return an integer representing the status of IccLock enabled or disabled in the following
10815 * three cases:
10816 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10817 * successfully.
10818 * - Positive number and zero for remaining password attempts.
10819 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10820 *
10821 */
10822 @Override
10823 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10824 enforceModifyPermission();
10825
10826 Phone phone = getPhone(subId);
10827 if (phone == null) {
10828 return 0;
10829 }
10830 // Now that all security checks passes, perform the operation as ourselves.
10831 final long identity = Binder.clearCallingIdentity();
10832 try {
10833 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10834 new Pair<Boolean, String>(enabled, password), phone, null);
10835 return attemptsRemaining;
10836
10837 } catch (Exception e) {
10838 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10839 } finally {
10840 Binder.restoreCallingIdentity(identity);
10841 }
10842 return 0;
10843 }
10844
10845 /**
10846 * Change the ICC password used in ICC pin lock.
10847 *
10848 * @return an integer representing the status of IccLock changed in the following three cases:
10849 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10850 * - Positive number and zero for remaining password attempts.
10851 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10852 *
10853 */
10854 @Override
10855 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10856 enforceModifyPermission();
10857
10858 Phone phone = getPhone(subId);
10859 if (phone == null) {
10860 return 0;
10861 }
10862 // Now that all security checks passes, perform the operation as ourselves.
10863 final long identity = Binder.clearCallingIdentity();
10864 try {
10865 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10866 new Pair<String, String>(oldPassword, newPassword), phone, null);
10867 return attemptsRemaining;
10868
10869 } catch (Exception e) {
10870 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10871 } finally {
10872 Binder.restoreCallingIdentity(identity);
10873 }
10874 return 0;
10875 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010876
10877 /**
10878 * Request for receiving user activity notification
10879 */
10880 @Override
10881 public void requestUserActivityNotification() {
10882 if (!mNotifyUserActivity.get()
10883 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10884 mNotifyUserActivity.set(true);
10885 }
10886 }
10887
10888 /**
10889 * Called when userActivity is signalled in the power manager.
10890 * This is safe to call from any thread, with any window manager locks held or not.
10891 */
10892 @Override
10893 public void userActivity() {
10894 // ***************************************
10895 // * Inherited from PhoneWindowManager *
10896 // ***************************************
10897 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10898 // WITH ITS LOCKS HELD.
10899 //
10900 // This code must be VERY careful about the locks
10901 // it acquires.
10902 // In fact, the current code acquires way too many,
10903 // and probably has lurking deadlocks.
10904
10905 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10906 throw new SecurityException("Only the OS may call notifyUserActivity()");
10907 }
10908
10909 if (mNotifyUserActivity.getAndSet(false)) {
10910 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10911 USER_ACTIVITY_NOTIFICATION_DELAY);
10912 }
10913 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010914
10915 @Override
10916 public boolean canConnectTo5GInDsdsMode() {
10917 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10918 }
Jack Yud10cdd42020-09-28 20:28:01 -070010919
10920 @Override
10921 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10922 String callingFeatureId) {
10923 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10924 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10925 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10926 }
10927
10928 Phone phone = getPhone(subId);
10929 if (phone == null) {
10930 throw new RuntimeException("phone is not available");
10931 }
10932 // Now that all security checks passes, perform the operation as ourselves.
10933 final long identity = Binder.clearCallingIdentity();
10934 try {
10935 return phone.getEquivalentHomePlmns();
10936 } finally {
10937 Binder.restoreCallingIdentity(identity);
10938 }
10939 }
Daniel Bright59e67312020-11-13 11:49:37 -080010940
10941 @Override
10942 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010943 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10944 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010945 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010946 if (radioInterfaceCapabilities == null) {
10947 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010948 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010949 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010950 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010951
Hui Wang641e81c2020-10-12 12:14:23 -070010952 @Override
10953 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10954 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010955 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10956 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10957 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10958 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10959 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010960 if (DBG) {
10961 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10962 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10963 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10964 }
10965
10966 if (!SubscriptionManager.isValidSubscriptionId(subId)
10967 || appType < TelephonyManager.APPTYPE_UNKNOWN
10968 || appType > TelephonyManager.APPTYPE_ISIM
10969 || nafUrl == null || securityProtocol == null || callback == null) {
10970 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10971 if (callback != null) {
10972 try {
10973 callback.onAuthenticationFailure(
10974 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10975 } catch (RemoteException exception) {
10976 log("Fail to notify onAuthenticationFailure due to " + exception);
10977 }
10978 return;
10979 }
10980 }
10981
10982 final long token = Binder.clearCallingIdentity();
10983 try {
10984 getGbaManager(subId).bootstrapAuthenticationRequest(
10985 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010986 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070010987 } finally {
10988 Binder.restoreCallingIdentity(token);
10989 }
10990 }
10991
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010992 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010993 * Attempts to set the radio power state for all phones for thermal reason.
10994 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010995 * requested radio power state will actually be set. See {@link
10996 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10997 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010998 * @param enable {@code true} if trying to turn radio on.
10999 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11000 * false}.
11001 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011002 private boolean setRadioPowerForThermal(boolean enable) {
11003 boolean isPhoneAvailable = false;
11004 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11005 Phone phone = PhoneFactory.getPhone(i);
11006 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011007 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011008 isPhoneAvailable = true;
11009 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011010 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011011
11012 // return true if successfully informed the phone object about the thermal radio power
11013 // request.
11014 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011015 }
11016
11017 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011018 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011019 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11020 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11021 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11022 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11023 throw new IllegalArgumentException("modem does not support data throttling");
11024 }
11025
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011026 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11027 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011028 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011029 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11030 }
11031
Sarah Chinecc78c42022-03-31 21:16:48 -070011032 setDataEnabledForReason(
11033 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011034
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011035 if (isDataThrottlingSupported) {
11036 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011037 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011038 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11039 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11040 } else if (thermalMitigationResult
11041 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011042 log("Modem likely does not support data throttling on secondary carrier. Data " +
11043 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11044 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011045 }
11046 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011047 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011048
11049 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011050 }
11051
Jack Nudelman644b91a2021-03-12 14:09:48 -080011052 private static List<String> getThermalMitigationAllowlist(Context context) {
11053 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11054 for (String pckg : context.getResources()
11055 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11056 sThermalMitigationAllowlistedPackages.add(pckg);
11057 }
11058 }
11059
11060 return sThermalMitigationAllowlistedPackages;
11061 }
11062
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011063 private boolean isAnyPhoneInEmergencyState() {
11064 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11065 if (tm.isInEmergencyCall()) {
11066 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11067 return true;
11068 }
11069 for (Phone phone : PhoneFactory.getPhones()) {
11070 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11071 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011072 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11073 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011074 return true;
11075 }
11076 }
11077
11078 return false;
11079 }
11080
Jack Nudelman644b91a2021-03-12 14:09:48 -080011081 /**
11082 * Used by shell commands to add an authorized package name for thermal mitigation.
11083 * @param packageName name of package to be allowlisted
11084 * @param context
11085 */
11086 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11087 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11088 sThermalMitigationAllowlistedPackages.add(packageName);
11089 }
11090
11091 /**
11092 * Used by shell commands to remove an authorized package name for thermal mitigation.
11093 * @param packageName name of package to remove from allowlist
11094 * @param context
11095 */
11096 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11097 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11098 sThermalMitigationAllowlistedPackages.remove(packageName);
11099 }
11100
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011101 /**
11102 * Thermal mitigation request to control functionalities at modem.
11103 *
11104 * @param subId the id of the subscription.
11105 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011106 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011107 *
11108 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11109 */
11110 @Override
11111 @ThermalMitigationResult
11112 public int sendThermalMitigationRequest(
11113 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011114 ThermalMitigationRequest thermalMitigationRequest,
11115 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011116 enforceModifyPermission();
11117
Jack Nudelman644b91a2021-03-12 14:09:48 -080011118 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11119 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11120 .contains(callingPackage)) {
11121 throw new SecurityException("Calling package must be configured in the device config. "
11122 + "calling package: " + callingPackage);
11123 }
11124
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011125 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11126 final long identity = Binder.clearCallingIdentity();
11127
11128 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11129 try {
11130 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11131 switch (thermalMitigationAction) {
11132 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11133 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011134 handleDataThrottlingRequest(subId,
11135 thermalMitigationRequest.getDataThrottlingRequest(),
11136 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011137 break;
11138 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11139 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11140 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11141 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11142 }
11143
11144 // Ensure that radio is on. If not able to power on due to phone being
11145 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011146 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011147 thermalMitigationResult =
11148 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11149 break;
11150 }
11151
11152 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011153 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011154 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11155 break;
11156 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11157 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11158 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11159 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11160 }
11161
11162 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11163 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011164 Phone phone = getPhone(subId);
11165 if (phone == null) {
11166 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011167 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011168 break;
11169 }
11170
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011171 TelephonyConnectionService service =
11172 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011173 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011174 Log.e(LOG_TAG, "An emergency call is pending");
11175 thermalMitigationResult =
11176 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11177 break;
11178 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011179 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011180 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011181 break;
11182 }
11183 } else {
11184 thermalMitigationResult =
11185 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11186 break;
11187 }
11188
11189 // Turn radio off. If not able to power off due to phone being unavailable,
11190 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011191 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011192 thermalMitigationResult =
11193 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11194 break;
11195 }
11196 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011197 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011198 break;
11199 default:
11200 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11201 + "not exist. Requested action: " + thermalMitigationAction);
11202 }
11203 } catch (IllegalArgumentException e) {
11204 throw e;
11205 } catch (Exception e) {
11206 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11207 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11208 } finally {
11209 Binder.restoreCallingIdentity(identity);
11210 }
11211
11212 if (DBG) {
11213 log("thermalMitigationRequest returning with thermalMitigationResult: "
11214 + thermalMitigationResult);
11215 }
11216
11217 return thermalMitigationResult;
11218 }
Hui Wang641e81c2020-10-12 12:14:23 -070011219
11220 /**
11221 * Set the GbaService Package Name that Telephony will bind to.
11222 *
11223 * @param subId The sim that the GbaService is associated with.
11224 * @param packageName The name of the package to be replaced with.
11225 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11226 */
11227 @Override
11228 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11229 enforceModifyPermission();
11230
11231 final long identity = Binder.clearCallingIdentity();
11232 try {
11233 return getGbaManager(subId).overrideServicePackage(packageName);
11234 } finally {
11235 Binder.restoreCallingIdentity(identity);
11236 }
11237 }
11238
11239 /**
11240 * Return the package name of the currently bound GbaService.
11241 *
11242 * @param subId The sim that the GbaService is associated with.
11243 * @return the package name of the GbaService configuration, null if GBA is not supported.
11244 */
11245 @Override
11246 public String getBoundGbaService(int subId) {
11247 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11248
11249 final long identity = Binder.clearCallingIdentity();
11250 try {
11251 return getGbaManager(subId).getServicePackage();
11252 } finally {
11253 Binder.restoreCallingIdentity(identity);
11254 }
11255 }
11256
11257 /**
11258 * Set the release time for telephony to unbind GbaService.
11259 *
11260 * @param subId The sim that the GbaService is associated with.
11261 * @param interval The release time to unbind GbaService by millisecond.
11262 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11263 */
11264 @Override
11265 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11266 enforceModifyPermission();
11267
11268 final long identity = Binder.clearCallingIdentity();
11269 try {
11270 return getGbaManager(subId).overrideReleaseTime(interval);
11271 } finally {
11272 Binder.restoreCallingIdentity(identity);
11273 }
11274 }
11275
11276 /**
11277 * Return the release time for telephony to unbind GbaService.
11278 *
11279 * @param subId The sim that the GbaService is associated with.
11280 * @return The release time to unbind GbaService by millisecond.
11281 */
11282 @Override
11283 public int getGbaReleaseTime(int subId) {
11284 enforceReadPrivilegedPermission("getGbaReleaseTime");
11285
11286 final long identity = Binder.clearCallingIdentity();
11287 try {
11288 return getGbaManager(subId).getReleaseTime();
11289 } finally {
11290 Binder.restoreCallingIdentity(identity);
11291 }
11292 }
11293
11294 private GbaManager getGbaManager(int subId) {
11295 GbaManager instance = GbaManager.getInstance(subId);
11296 if (instance == null) {
11297 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11298 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11299 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11300 }
11301 return instance;
11302 }
Hui Wang761a6682020-10-31 05:12:53 +000011303
11304 /**
11305 * indicate whether the device and the carrier can support
11306 * RCS VoLTE single registration.
11307 */
11308 @Override
11309 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011310 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11311 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11312 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11313 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011314
11315 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11316 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11317 }
11318
11319 final long identity = Binder.clearCallingIdentity();
11320 try {
11321 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11322 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011323 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11324 if (isCapable != null) {
11325 return isCapable;
11326 }
Hui Wang761a6682020-10-31 05:12:53 +000011327 }
Hui Wang67af90e2021-06-04 16:57:15 -070011328 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11329 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011330 } finally {
11331 Binder.restoreCallingIdentity(identity);
11332 }
11333 }
11334
11335 /**
11336 * Register RCS provisioning callback.
11337 */
11338 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011339 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011340 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011341 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011342 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011343 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11344 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011345
11346 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11347 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11348 }
11349 if (!isImsAvailableOnDevice()) {
11350 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11351 "IMS not available on device.");
11352 }
11353
11354 final long identity = Binder.clearCallingIdentity();
11355 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011356 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011357 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011358 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11359 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011360 }
Hui Wang761a6682020-10-31 05:12:53 +000011361 } finally {
11362 Binder.restoreCallingIdentity(identity);
11363 }
11364 }
11365
11366 /**
11367 * Unregister RCS provisioning callback.
11368 */
11369 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011370 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011371 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011372 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011373 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011374 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11375 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011376
11377 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11378 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11379 }
11380 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000011381 // operation failed silently
11382 Rlog.w(LOG_TAG, "IMS not available on device.");
11383 return;
Hui Wang761a6682020-10-31 05:12:53 +000011384 }
11385
11386 final long identity = Binder.clearCallingIdentity();
11387 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011388 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011389 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011390 } finally {
11391 Binder.restoreCallingIdentity(identity);
11392 }
11393 }
11394
11395 /**
11396 * trigger RCS reconfiguration.
11397 */
11398 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011399 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11400 "triggerRcsReconfiguration",
11401 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011402
11403 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11404 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11405 }
11406 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000011407 // ProvisioningManager can not handle ServiceSpecificException.
11408 // Throw the IllegalStateException and annotate ProvisioningManager.
11409 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000011410 }
11411
11412 final long identity = Binder.clearCallingIdentity();
11413 try {
11414 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11415 } finally {
11416 Binder.restoreCallingIdentity(identity);
11417 }
11418 }
11419
11420 /**
11421 * Provide the client configuration parameters of the RCS application.
11422 */
11423 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011424 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11425 "setRcsClientConfiguration",
11426 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011427
11428 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11429 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11430 }
11431 if (!isImsAvailableOnDevice()) {
11432 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11433 "IMS not available on device.");
11434 }
11435
11436 final long identity = Binder.clearCallingIdentity();
11437
11438 try {
11439 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11440 if (configBinder == null) {
11441 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011442 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11443 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011444 } else {
11445 configBinder.setRcsClientConfiguration(rcc);
11446 }
joonhunshin3e154242021-09-17 06:33:39 +000011447
11448 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11449 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011450 } catch (RemoteException e) {
11451 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011452 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11453 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011454 } finally {
11455 Binder.restoreCallingIdentity(identity);
11456 }
11457 }
11458
11459 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011460 * Enables or disables the test mode for RCS VoLTE single registration.
11461 */
11462 @Override
11463 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11464 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11465 "setRcsSingleRegistrationTestModeEnabled");
11466
11467 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11468 }
11469
11470 /**
11471 * Gets the test mode for RCS VoLTE single registration.
11472 */
11473 @Override
11474 public boolean getRcsSingleRegistrationTestModeEnabled() {
11475 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11476 "getRcsSingleRegistrationTestModeEnabled");
11477
11478 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11479 }
11480
11481 /**
Hui Wang761a6682020-10-31 05:12:53 +000011482 * Overrides the config of RCS VoLTE single registration enabled for the device.
11483 */
11484 @Override
11485 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11486 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11487 "setDeviceSingleRegistrationEnabledOverride");
11488 enforceModifyPermission();
11489
11490 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11491 : Boolean.parseBoolean(enabledStr);
11492 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011493 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011494 }
11495
11496 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011497 * Sends a device to device communication message. Only usable via shell.
11498 * @param message message to send.
11499 * @param value message value.
11500 */
11501 @Override
11502 public void sendDeviceToDeviceMessage(int message, int value) {
11503 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011504 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011505 enforceModifyPermission();
11506
11507 final long identity = Binder.clearCallingIdentity();
11508 try {
11509 TelephonyConnectionService service =
11510 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11511 if (service == null) {
11512 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11513 return;
11514 }
11515 service.sendTestDeviceToDeviceMessage(message, value);
11516 } finally {
11517 Binder.restoreCallingIdentity(identity);
11518 }
11519 }
11520
Tyler Gunnbabbda02021-02-10 11:05:02 -080011521 /**
11522 * Sets the specified device to device transport active.
11523 * @param transport The transport to set active.
11524 */
11525 @Override
11526 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11527 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11528 "setActiveDeviceToDeviceTransport");
11529 enforceModifyPermission();
11530
11531 final long identity = Binder.clearCallingIdentity();
11532 try {
11533 TelephonyConnectionService service =
11534 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11535 if (service == null) {
11536 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11537 return;
11538 }
11539 service.setActiveDeviceToDeviceTransport(transport);
11540 } finally {
11541 Binder.restoreCallingIdentity(identity);
11542 }
11543 }
Tyler Gunn92479152021-01-20 16:30:10 -080011544
Tyler Gunnd4339262021-05-03 14:46:49 -070011545 @Override
11546 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11547 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11548 "setDeviceToDeviceForceEnabled");
11549
11550 final long identity = Binder.clearCallingIdentity();
11551 try {
11552 Arrays.stream(PhoneFactory.getPhones()).forEach(
11553 p -> {
11554 Phone thePhone = p.getImsPhone();
11555 if (thePhone != null && thePhone instanceof ImsPhone) {
11556 ImsPhone imsPhone = (ImsPhone) thePhone;
11557 CallTracker tracker = imsPhone.getCallTracker();
11558 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11559 ImsPhoneCallTracker imsPhoneCallTracker =
11560 (ImsPhoneCallTracker) tracker;
11561 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11562 }
11563 }
11564 }
11565 );
11566 } finally {
11567 Binder.restoreCallingIdentity(identity);
11568 }
11569 }
11570
Tyler Gunn92479152021-01-20 16:30:10 -080011571 /**
Hui Wang761a6682020-10-31 05:12:53 +000011572 * Gets the config of RCS VoLTE single registration enabled for the device.
11573 */
11574 @Override
11575 public boolean getDeviceSingleRegistrationEnabled() {
11576 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11577 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11578 }
11579
11580 /**
11581 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11582 */
11583 @Override
11584 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11585 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11586 "setCarrierSingleRegistrationEnabledOverride");
11587 enforceModifyPermission();
11588
11589 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11590 : Boolean.parseBoolean(enabledStr);
11591 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11592 subId, enabled);
11593 }
11594
11595 /**
11596 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11597 */
11598 @Override
11599 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11600 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11601 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11602 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011603
11604 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011605 * Overrides the ims feature validation result
11606 */
11607 @Override
11608 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11609 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11610 "setImsFeatureValidationOverride");
11611
11612 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11613 : Boolean.parseBoolean(enabledStr);
11614 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11615 subId, enabled);
11616 }
11617
11618 /**
11619 * Gets the ims feature validation override value
11620 */
11621 @Override
11622 public boolean getImsFeatureValidationOverride(int subId) {
11623 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11624 "getImsFeatureValidationOverride");
11625 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11626 }
11627
11628 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011629 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11630 * their mobile plan.
11631 */
11632 @Override
11633 public String getMobileProvisioningUrl() {
11634 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11635 final long identity = Binder.clearCallingIdentity();
11636 try {
11637 return getDefaultPhone().getMobileProvisioningUrl();
11638 } finally {
11639 Binder.restoreCallingIdentity(identity);
11640 }
11641 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011642
James.cf Linbcdf8b32021-01-14 16:44:13 +080011643 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011644 * Get the EAB contact from the EAB database.
11645 */
11646 @Override
11647 public String getContactFromEab(String contact) {
11648 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11649 enforceModifyPermission();
11650 final long identity = Binder.clearCallingIdentity();
11651 try {
11652 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11653 } finally {
11654 Binder.restoreCallingIdentity(identity);
11655 }
11656 }
11657
11658 /**
Calvin Pana1434322021-07-01 19:27:01 +080011659 * Get the EAB capability from the EAB database.
11660 */
11661 @Override
11662 public String getCapabilityFromEab(String contact) {
11663 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11664 enforceModifyPermission();
11665 final long identity = Binder.clearCallingIdentity();
11666 try {
11667 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11668 } finally {
11669 Binder.restoreCallingIdentity(identity);
11670 }
11671 }
11672
11673 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011674 * Remove the EAB contacts from the EAB database.
11675 */
11676 @Override
11677 public int removeContactFromEab(int subId, String contacts) {
11678 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11679 enforceModifyPermission();
11680 final long identity = Binder.clearCallingIdentity();
11681 try {
11682 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11683 } finally {
11684 Binder.restoreCallingIdentity(identity);
11685 }
11686 }
11687
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011688 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011689 public boolean getDeviceUceEnabled() {
11690 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11691 final long identity = Binder.clearCallingIdentity();
11692 try {
11693 return mApp.getDeviceUceEnabled();
11694 } finally {
11695 Binder.restoreCallingIdentity(identity);
11696 }
11697 }
11698
11699 @Override
11700 public void setDeviceUceEnabled(boolean isEnabled) {
11701 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11702 final long identity = Binder.clearCallingIdentity();
11703 try {
11704 mApp.setDeviceUceEnabled(isEnabled);
11705 } finally {
11706 Binder.restoreCallingIdentity(identity);
11707 }
11708 }
11709
Brad Ebinger14d467f2021-02-12 06:18:28 +000011710 /**
11711 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11712 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11713 */
11714 // Used for SHELL command only right now.
11715 @Override
11716 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11717 List<String> featureTags) {
11718 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11719 "addUceRegistrationOverrideShell");
11720 final long identity = Binder.clearCallingIdentity();
11721 try {
11722 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11723 new ArraySet<>(featureTags));
11724 } catch (ImsException e) {
11725 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11726 } finally {
11727 Binder.restoreCallingIdentity(identity);
11728 }
11729 }
11730
11731 /**
11732 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11733 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11734 */
11735 // Used for SHELL command only right now.
11736 @Override
11737 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11738 List<String> featureTags) {
11739 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11740 "removeUceRegistrationOverrideShell");
11741 final long identity = Binder.clearCallingIdentity();
11742 try {
11743 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11744 new ArraySet<>(featureTags));
11745 } catch (ImsException e) {
11746 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11747 } finally {
11748 Binder.restoreCallingIdentity(identity);
11749 }
11750 }
11751
11752 /**
11753 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11754 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11755 */
11756 // Used for SHELL command only right now.
11757 @Override
11758 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11759 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11760 "clearUceRegistrationOverrideShell");
11761 final long identity = Binder.clearCallingIdentity();
11762 try {
11763 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11764 } catch (ImsException e) {
11765 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11766 } finally {
11767 Binder.restoreCallingIdentity(identity);
11768 }
11769 }
11770
11771 /**
11772 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11773 */
11774 // Used for SHELL command only right now.
11775 @Override
11776 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11777 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11778 "getLatestRcsContactUceCapabilityShell");
11779 final long identity = Binder.clearCallingIdentity();
11780 try {
11781 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11782 } catch (ImsException e) {
11783 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11784 } finally {
11785 Binder.restoreCallingIdentity(identity);
11786 }
11787 }
11788
11789 /**
11790 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11791 * device does not have an active PUBLISH.
11792 */
11793 // Used for SHELL command only right now.
11794 @Override
11795 public String getLastUcePidfXmlShell(int subId) {
11796 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11797 final long identity = Binder.clearCallingIdentity();
11798 try {
11799 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11800 } catch (ImsException e) {
11801 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11802 } finally {
11803 Binder.restoreCallingIdentity(identity);
11804 }
11805 }
11806
James.cf Line8713a42021-04-29 16:04:26 +080011807 /**
11808 * Remove UCE requests cannot be sent to the network status.
11809 */
11810 // Used for SHELL command only right now.
11811 @Override
11812 public boolean removeUceRequestDisallowedStatus(int subId) {
11813 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11814 final long identity = Binder.clearCallingIdentity();
11815 try {
11816 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11817 } catch (ImsException e) {
11818 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11819 } finally {
11820 Binder.restoreCallingIdentity(identity);
11821 }
11822 }
11823
James.cf Lin18bb9002021-05-25 01:37:38 +080011824 /**
11825 * Remove UCE requests cannot be sent to the network status.
11826 */
11827 // Used for SHELL command only.
11828 @Override
11829 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11830 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11831 final long identity = Binder.clearCallingIdentity();
11832 try {
11833 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11834 } catch (ImsException e) {
11835 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11836 } finally {
11837 Binder.restoreCallingIdentity(identity);
11838 }
11839 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011840
James.cf Lin4b784aa2021-01-31 03:25:15 +080011841 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011842 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11843 String callingPackage) {
11844 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11845 mApp, subId, "setSignalStrengthUpdateRequest");
11846
11847 final int callingUid = Binder.getCallingUid();
11848 // Verify that tha callingPackage belongs to the calling UID
11849 mApp.getSystemService(AppOpsManager.class)
11850 .checkPackage(callingUid, callingPackage);
11851
Rambo Wang3607f502021-02-01 21:51:40 -080011852 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011853
11854 final long identity = Binder.clearCallingIdentity();
11855 try {
11856 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11857 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11858
11859 if (result instanceof IllegalStateException) {
11860 throw (IllegalStateException) result;
11861 }
11862 } finally {
11863 Binder.restoreCallingIdentity(identity);
11864 }
11865 }
11866
11867 @Override
11868 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11869 String callingPackage) {
11870 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11871 mApp, subId, "clearSignalStrengthUpdateRequest");
11872
11873 final int callingUid = Binder.getCallingUid();
11874 // Verify that tha callingPackage belongs to the calling UID
11875 mApp.getSystemService(AppOpsManager.class)
11876 .checkPackage(callingUid, callingPackage);
11877
11878 final long identity = Binder.clearCallingIdentity();
11879 try {
11880 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11881 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11882
11883 if (result instanceof IllegalStateException) {
11884 throw (IllegalStateException) result;
11885 }
11886 } finally {
11887 Binder.restoreCallingIdentity(identity);
11888 }
11889 }
11890
Rambo Wang3607f502021-02-01 21:51:40 -080011891 private static void validateSignalStrengthUpdateRequest(Context context,
11892 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011893 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11894 // phone/system process do not have further restriction on request
11895 return;
11896 }
11897
11898 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011899 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011900 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011901 context.enforceCallingOrSelfPermission(
11902 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11903 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011904 }
11905
11906 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000011907 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011908 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011909 || info.isEnabled()) {
11910 throw new IllegalArgumentException(
11911 "Only system can set hide fields in SignalThresholdInfo");
11912 }
11913
11914 // Thresholds length for each RAN need in range. This has been validated in
11915 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11916 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11917 final int[] thresholds = info.getThresholds();
11918 Objects.requireNonNull(thresholds);
11919 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11920 || thresholds.length
11921 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11922 throw new IllegalArgumentException(
11923 "thresholds length is out of range: " + thresholds.length);
11924 }
11925 }
11926 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011927
11928 /**
11929 * Gets the current phone capability.
11930 *
11931 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11932 * @return the PhoneCapability which describes the data connection capability of modem.
11933 * It's used to evaluate possible phone config change, for example from single
11934 * SIM device to multi-SIM device.
11935 */
11936 @Override
11937 public PhoneCapability getPhoneCapability() {
11938 enforceReadPrivilegedPermission("getPhoneCapability");
11939 final long identity = Binder.clearCallingIdentity();
11940 try {
11941 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11942 } finally {
11943 Binder.restoreCallingIdentity(identity);
11944 }
11945 }
Michele Berionne5e411512020-11-13 02:36:59 +000011946
11947 /**
11948 * Prepare TelephonyManager for an unattended reboot. The reboot is
11949 * required to be done shortly after the API is invoked.
11950 */
11951 @Override
11952 @TelephonyManager.PrepareUnattendedRebootResult
11953 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011954 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011955 enforceRebootPermission();
11956
11957 final long identity = Binder.clearCallingIdentity();
11958 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011959 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011960 } finally {
11961 Binder.restoreCallingIdentity(identity);
11962 }
11963 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011964
11965 /**
11966 * Request to get the current slicing configuration including URSP rules and
11967 * NSSAIs (configured, allowed and rejected).
11968 *
11969 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11970 */
11971 @Override
11972 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011973 TelephonyPermissions
11974 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11975 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011976
11977 final long identity = Binder.clearCallingIdentity();
11978 try {
11979 Phone phone = getDefaultPhone();
11980 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11981 } finally {
11982 Binder.restoreCallingIdentity(identity);
11983 }
11984 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011985
11986 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011987 * Check whether the given premium capability is available for purchase from the carrier.
11988 *
11989 * @param capability The premium capability to check.
11990 * @param subId The subId to check the premium capability for.
11991 *
11992 * @return Whether the given premium capability is available to purchase.
11993 */
11994 @Override
11995 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11996 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11997 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11998 log("Premium capability "
11999 + TelephonyManager.convertPremiumCapabilityToString(capability)
12000 + " is not available for purchase due to missing permissions.");
12001 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12002 + "permission READ_BASIC_PHONE_STATE.");
12003 }
12004
12005 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012006 if (phone == null) {
12007 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12008 return false;
12009 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012010 final long identity = Binder.clearCallingIdentity();
12011 try {
Sarah Chin46355ba2022-11-01 23:51:16 -070012012 return SlicePurchaseController.getInstance(phone)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012013 .isPremiumCapabilityAvailableForPurchase(capability);
12014 } finally {
12015 Binder.restoreCallingIdentity(identity);
12016 }
12017 }
12018
12019 /**
12020 * Purchase the given premium capability from the carrier.
12021 *
12022 * @param capability The premium capability to purchase.
12023 * @param callback The result of the purchase request.
12024 * @param subId The subId to purchase the premium capability for.
12025 */
12026 @Override
12027 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12028 log("purchasePremiumCapability: capability="
12029 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12030 + getCurrentPackageName());
12031
12032 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12033 mApp, "purchasePremiumCapability")) {
12034 log("purchasePremiumCapability "
12035 + TelephonyManager.convertPremiumCapabilityToString(capability)
12036 + " failed due to missing permissions.");
12037 throw new SecurityException("purchasePremiumCapability requires permission "
12038 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012039 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12040 mApp, "purchasePremiumCapability")) {
12041 log("purchasePremiumCapability "
12042 + TelephonyManager.convertPremiumCapabilityToString(capability)
12043 + " failed due to missing permissions.");
12044 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012045 }
12046
12047 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012048 if (phone == null) {
12049 try {
12050 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12051 callback.accept(result);
12052 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12053 } catch (RemoteException e) {
12054 String logStr = "Purchase premium capability "
12055 + TelephonyManager.convertPremiumCapabilityToString(capability)
12056 + " failed due to RemoteException handling null phone: " + e;
12057 if (DBG) log(logStr);
12058 AnomalyReporter.reportAnomaly(
12059 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12060 }
12061 return;
12062 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012063
12064 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012065 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012066 callingProcess = mApp.getPackageManager().getApplicationInfo(
12067 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070012068 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012069 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012070 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012071
12072 boolean isVisible = false;
12073 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12074 if (am != null) {
12075 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12076 if (processes != null) {
12077 for (ActivityManager.RunningAppProcessInfo process : processes) {
12078 log("purchasePremiumCapability: process " + process.processName
12079 + "has importance " + process.importance);
12080 if (process.processName.equals(callingProcess) && process.importance
12081 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12082 isVisible = true;
12083 break;
12084 }
12085 }
12086 }
12087 }
12088
12089 if (!isVisible) {
12090 try {
12091 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12092 callback.accept(result);
12093 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12094 } catch (RemoteException e) {
12095 String logStr = "Purchase premium capability "
12096 + TelephonyManager.convertPremiumCapabilityToString(capability)
12097 + " failed due to RemoteException handling background application: " + e;
12098 if (DBG) log(logStr);
12099 AnomalyReporter.reportAnomaly(
12100 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12101 }
12102 return;
12103 }
12104
Sarah Chin71b3a852022-09-28 15:54:19 -070012105 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012106 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012107 }
12108
12109 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012110 * Register an IMS connection state callback
12111 */
12112 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012113 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12114 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012115 if (feature == ImsFeature.FEATURE_MMTEL) {
12116 // ImsMmTelManager
12117 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12118 TelephonyPermissions
12119 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12120 mApp, subId, "registerImsStateCallback");
12121 } else if (feature == ImsFeature.FEATURE_RCS) {
12122 // ImsRcsManager or SipDelegateManager
12123 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12124 Binder.getCallingUid(), "registerImsStateCallback",
12125 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12126 Manifest.permission.READ_PRECISE_PHONE_STATE,
12127 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12128 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12129 }
12130
12131 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12132 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12133 "IMS not available on device.");
12134 }
12135
12136 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12137 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12138 }
12139
12140 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12141 if (controller == null) {
12142 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12143 "IMS not available on device.");
12144 }
12145
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012146 if (callingPackage == null) {
12147 callingPackage = getCurrentPackageName();
12148 }
12149
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012150 final long token = Binder.clearCallingIdentity();
12151 try {
12152 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012153 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012154 } catch (ImsException e) {
12155 throw new ServiceSpecificException(e.getCode());
12156 } finally {
12157 Binder.restoreCallingIdentity(token);
12158 }
12159 }
12160
12161 /**
12162 * Unregister an IMS connection state callback
12163 */
12164 @Override
12165 public void unregisterImsStateCallback(IImsStateCallback cb) {
12166 final long token = Binder.clearCallingIdentity();
12167 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12168 if (controller == null) {
12169 return;
12170 }
12171 try {
12172 controller.unregisterImsStateCallback(cb);
12173 } finally {
12174 Binder.restoreCallingIdentity(token);
12175 }
12176 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012177
12178 /**
12179 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12180 *
12181 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
12182 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
12183 * SecurityException.
12184 * If there is current registered network this value will be same as the registered cell
12185 * identity. If the device goes out of service the previous cell identity is cached and
12186 * will be returned. If the cache age of the Cell identity is more than 24 hours
12187 * it will be cleared and null will be returned.
12188 *
12189 */
12190 @Override
12191 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12192 String callingFeatureId) {
12193 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12194 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12195 LocationAccessPolicy.checkLocationPermission(mApp,
12196 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12197 .setCallingPackage(callingPackage)
12198 .setCallingFeatureId(callingFeatureId)
12199 .setCallingPid(Binder.getCallingPid())
12200 .setCallingUid(Binder.getCallingUid())
12201 .setMethod("getLastKnownCellIdentity")
12202 .setLogAsInfo(true)
12203 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12204 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12205 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12206 .build());
12207
12208 boolean hasFinePermission =
12209 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12210 if (!hasFinePermission
12211 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12212 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012213 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012214 }
12215
12216 final long identity = Binder.clearCallingIdentity();
12217 try {
12218 Phone phone = getPhone(subId);
12219 if (phone == null) return null;
12220 ServiceStateTracker sst = phone.getServiceStateTracker();
12221 if (sst == null) return null;
12222 return sst.getLastKnownCellIdentity();
12223 } finally {
12224 Binder.restoreCallingIdentity(identity);
12225 }
12226 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012227
jimsun3b9ccac2021-10-26 15:01:23 +080012228 /**
12229 * Sets the modem service class Name that Telephony will bind to.
12230 *
12231 * @param serviceName The class name of the modem service.
12232 * @return true if the operation is succeed, otherwise false.
12233 */
12234 public boolean setModemService(String serviceName) {
12235 Log.d(LOG_TAG, "setModemService - " + serviceName);
12236 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12237 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012238 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12239 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012240 return mPhoneConfigurationManager.setModemService(serviceName);
12241 }
12242
12243 /**
12244 * Return the class name of the currently bounded modem service.
12245 *
12246 * @return the class name of the modem service.
12247 */
12248 public String getModemService() {
12249 String result;
12250 Log.d(LOG_TAG, "getModemService");
12251 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12252 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012253 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012254 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12255 "getModemService");
12256 result = mPhoneConfigurationManager.getModemService();
12257 Log.d(LOG_TAG, "result = " + result);
12258 return result;
12259 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012260
12261 @Override
12262 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12263 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12264 mApp.enforceCallingOrSelfPermission(
12265 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12266 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12267
12268 final long identity = Binder.clearCallingIdentity();
12269 try {
12270 Phone phone = getPhone(subId);
12271 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012272 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12273 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012274 phone.setVoiceServiceStateOverride(hasService);
12275 } finally {
12276 Binder.restoreCallingIdentity(identity);
12277 }
12278 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012279
12280 /**
12281 * set removable eSIM as default eUICC.
12282 *
12283 * @hide
12284 */
12285 @Override
12286 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12287 enforceModifyPermission();
12288 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12289
12290 final long identity = Binder.clearCallingIdentity();
12291 try {
12292 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12293 } finally {
12294 Binder.restoreCallingIdentity(identity);
12295 }
12296 }
12297
12298 /**
12299 * Returns whether the removable eSIM is default eUICC or not.
12300 *
12301 * @hide
12302 */
12303 @Override
12304 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12305 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12306 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12307
12308 final long identity = Binder.clearCallingIdentity();
12309 try {
12310 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12311 } finally {
12312 Binder.restoreCallingIdentity(identity);
12313 }
12314 }
12315
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012316 /**
12317 * Get the component name of the default app to direct respond-via-message intent for the
12318 * user associated with this subscription, update the cache if there is no respond-via-message
12319 * application currently configured for this user.
12320 * @return component name of the app and class to direct Respond Via Message intent to, or
12321 * {@code null} if the functionality is not supported.
12322 * @hide
12323 */
12324 @Override
12325 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12326 boolean updateIfNeeded) {
12327 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012328
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012329 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12330
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012331 UserHandle userHandle = null;
12332 final long identity = Binder.clearCallingIdentity();
12333 try {
12334 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12335 } finally {
12336 Binder.restoreCallingIdentity(identity);
12337 }
12338 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12339 updateIfNeeded, userHandle);
12340 }
Jack Yuf5badd92022-12-08 00:50:53 -080012341
12342 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012343 * Set whether the device is able to connect with null ciphering or integrity
12344 * algorithms. This is a global setting and will apply to all active subscriptions
12345 * and all new subscriptions after this.
12346 *
12347 * @param enabled when true, null cipher and integrity algorithms are allowed.
12348 * @hide
12349 */
12350 @Override
12351 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12352 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12353 enforceModifyPermission();
12354 checkForNullCipherAndIntegritySupport();
12355
12356 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12357 // for listening to these preference changes and applying them immediately.
12358 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12359 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12360 editor.apply();
12361
12362 for (Phone phone: PhoneFactory.getPhones()) {
12363 phone.handleNullCipherEnabledChange();
12364 }
12365 }
12366
12367
12368 /**
12369 * Get whether the device is able to connect with null ciphering or integrity
12370 * algorithms. Note that this retrieves the phone-global preference and not
12371 * the state of the radio.
12372 *
12373 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12374 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12375 * version for this feature.
12376 * @hide
12377 */
12378 @Override
12379 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12380 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12381 enforceReadPermission();
12382 checkForNullCipherAndIntegritySupport();
12383 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12384 }
12385
12386 private void checkForNullCipherAndIntegritySupport() {
12387 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12388 throw new UnsupportedOperationException(
12389 "Null cipher and integrity operations require HAL 2.1 or above");
12390 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012391 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12392 throw new UnsupportedOperationException(
12393 "Null cipher and integrity operations unsupported by modem");
12394 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012395 }
12396
12397 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012398 * Get the SIM state for the slot index.
12399 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12400 *
12401 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12402 */
12403 @Override
12404 @SimState
12405 public int getSimStateForSlotIndex(int slotIndex) {
12406 IccCardConstants.State simState;
12407 if (slotIndex < 0) {
12408 simState = IccCardConstants.State.UNKNOWN;
12409 } else {
12410 Phone phone = null;
12411 try {
12412 phone = PhoneFactory.getPhone(slotIndex);
12413 } catch (IllegalStateException e) {
12414 // ignore
12415 }
12416 if (phone == null) {
12417 simState = IccCardConstants.State.UNKNOWN;
12418 } else {
12419 IccCard icc = phone.getIccCard();
12420 if (icc == null) {
12421 simState = IccCardConstants.State.UNKNOWN;
12422 } else {
12423 simState = icc.getState();
12424 }
12425 }
12426 }
12427 return simState.ordinal();
12428 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012429
12430 /**
12431 * Get current cell broadcast ranges.
12432 */
12433 @Override
12434 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12435 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12436 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12437 "getCellBroadcastIdRanges");
12438 final long identity = Binder.clearCallingIdentity();
12439 try {
12440 return getPhone(subId).getCellBroadcastIdRanges();
12441 } finally {
12442 Binder.restoreCallingIdentity(identity);
12443 }
12444 }
12445
12446 /**
12447 * Set reception of cell broadcast messages with the list of the given ranges
12448 *
12449 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12450 */
12451 @Override
12452 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12453 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12454 @Nullable IIntegerConsumer callback) {
12455 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12456 "setCellBroadcastIdRanges");
12457 final long identity = Binder.clearCallingIdentity();
12458 try {
12459 Phone phone = getPhoneFromSubId(subId);
12460 if (DBG) {
12461 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12462 }
12463 phone.setCellBroadcastIdRanges(ranges, result -> {
12464 if (callback != null) {
12465 try {
12466 callback.accept(result);
12467 } catch (RemoteException e) {
12468 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12469 }
12470 }
12471 });
12472 } finally {
12473 Binder.restoreCallingIdentity(identity);
12474 }
12475 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012476
12477 /**
12478 * Returns whether the device supports the domain selection service.
12479 *
12480 * @return {@code true} if the device supports the domain selection service.
12481 */
12482 @Override
12483 public boolean isDomainSelectionSupported() {
12484 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12485 "isDomainSelectionSupported");
12486
12487 final long identity = Binder.clearCallingIdentity();
12488 try {
12489 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12490 } finally {
12491 Binder.restoreCallingIdentity(identity);
12492 }
12493 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012494
12495 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012496 * Enable or disable the satellite modem. If the satellite modem is enabled, this will also
12497 * disable the cellular modem, and if the satellite modem is disabled, this will also re-enable
12498 * the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080012499 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012500 * @param subId The subId to set satellite enabled for.
12501 * @param enable {@code true} to enable the satellite modem and {@code false} to disable.
12502 * @param callback The callback to get the error code of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080012503 *
12504 * @throws SecurityException if the caller doesn't have the required permission.
12505 */
12506 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012507 public void setSatelliteEnabled(int subId, boolean enable, @NonNull IIntegerConsumer callback) {
12508 enforceSatelliteCommunicationPermission("setSatelliteEnabled");
12509 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012510 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012511 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
12512 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012513 }
Sarah Chin503828c2023-02-01 23:54:20 -080012514
12515 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012516 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012517 result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED);
12518 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012519 }
12520
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012521 Phone phone = getPhoneOrDefault(validSubId, "setSatelliteEnabled");
Sarah Chin503828c2023-02-01 23:54:20 -080012522 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012523 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
12524 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012525 }
12526
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012527 Pair<Boolean, Consumer<Integer>> arg = new Pair<>(enable, result);
12528 sendRequestAsync(CMD_SET_SATELLITE_ENABLED, arg, phone, null);
Sarah Chin503828c2023-02-01 23:54:20 -080012529 }
12530
12531 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012532 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080012533 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012534 * @param subId The subId to check whether satellite is enabled for.
12535 * @param result The result receiver that returns whether the satellite modem is enabled
12536 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012537 *
12538 * @throws SecurityException if the caller doesn't have the required permission.
12539 */
12540 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012541 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
12542 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012543 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012544 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
12545 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012546 }
Sarah Chin503828c2023-02-01 23:54:20 -080012547
12548 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012549 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012550 result.send(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED, null);
12551 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012552 }
12553
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012554 Phone phone = getPhoneOrDefault(validSubId, "requestIsSatelliteEnabled");
Sarah Chin503828c2023-02-01 23:54:20 -080012555 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012556 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
12557 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012558 }
12559
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012560 sendRequest(CMD_IS_SATELLITE_ENABLED, result, subId);
Sarah Chin503828c2023-02-01 23:54:20 -080012561 }
12562
12563 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012564 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080012565 *
12566 * @param subId The subId to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012567 * @param result The result receiver that returns whether the satellite service is supported on
12568 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012569 */
12570 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012571 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012572 synchronized (mIsSatelliteSupportedLock) {
12573 if (mIsSatelliteSupported != null) {
12574 /* We have already successfully queried the satellite modem. */
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012575 Bundle bundle = new Bundle();
12576 bundle.putBoolean(SatelliteManager.KEY_SATELLITE_SUPPORTED, mIsSatelliteSupported);
12577 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, bundle);
12578 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012579 }
12580 }
Sarah Chin503828c2023-02-01 23:54:20 -080012581
12582 final int validSubId = getValidSatelliteSubId(subId);
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012583 Phone phone = getPhoneOrDefault(validSubId, "requestIsSatelliteSupported");
Sarah Chin503828c2023-02-01 23:54:20 -080012584 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012585 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
12586 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012587 }
12588
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012589 sendRequestAsync(CMD_IS_SATELLITE_SUPPORTED, result, phone, null);
Sarah Chin503828c2023-02-01 23:54:20 -080012590 }
12591
12592 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012593 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080012594 *
12595 * @param subId The subId to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012596 * @param result The result receiver that returns the {@link SatelliteCapabilities}
12597 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012598 *
12599 * @throws SecurityException if the caller doesn't have required permission.
12600 */
12601 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012602 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
12603 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012604 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012605 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
12606 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012607 }
Sarah Chin503828c2023-02-01 23:54:20 -080012608
12609 final int validSubId = getValidSatelliteSubId(subId);
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012610 Phone phone = getPhoneOrDefault(validSubId, "requestSatelliteCapabilities");
Sarah Chin503828c2023-02-01 23:54:20 -080012611 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012612 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
12613 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012614 }
12615
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012616 sendRequestAsync(CMD_GET_SATELLITE_CAPABILITIES, result, phone, null);
Sarah Chin503828c2023-02-01 23:54:20 -080012617 }
12618
12619 /**
Sarah Chineccfbd12023-01-20 19:00:35 -080012620 * Start receiving satellite position updates.
12621 * This can be called by the pointing UI when the user starts pointing to the satellite.
12622 * Modem should continue to report the pointing input as the device or satellite moves.
12623 *
12624 * @param subId The subId to start satellite position updates for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012625 * @param errorCallback The callback to get the error code of the request.
Sarah Chineccfbd12023-01-20 19:00:35 -080012626 * @param callback The callback to notify of changes in satellite position.
Sarah Chin503828c2023-02-01 23:54:20 -080012627 *
12628 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012629 */
12630 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012631 public void startSatellitePositionUpdates(int subId, @NonNull IIntegerConsumer errorCallback,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012632 @NonNull ISatelliteStateListener callback) {
Sarah Chinf75afa72023-02-01 01:32:19 -080012633 enforceSatelliteCommunicationPermission("startSatellitePositionUpdates");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012634 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(errorCallback::accept);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012635 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012636 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
12637 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012638 }
Sarah Chinf75afa72023-02-01 01:32:19 -080012639
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012640 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012641 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012642 result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED);
12643 return;
Sarah Chinf75afa72023-02-01 01:32:19 -080012644 }
12645
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012646 Phone phone = getPhoneOrDefault(validSubId, "startSatellitePositionUpdates");
Sarah Chineccfbd12023-01-20 19:00:35 -080012647 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012648 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
12649 return;
Sarah Chineccfbd12023-01-20 19:00:35 -080012650 }
12651
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012652 if (mSatellitePositionUpdateHandlers.containsKey(callback.asBinder())) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012653 if (DBG) {
12654 log("startSatellitePositionUpdates: callback already registered: "
12655 + callback.asBinder());
12656 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012657 result.accept(SatelliteManager.SATELLITE_ERROR_NONE);
12658 return;
Sarah Chineccfbd12023-01-20 19:00:35 -080012659 }
12660
12661 SatellitePositionUpdateHandler handler =
12662 new SatellitePositionUpdateHandler(callback, Looper.getMainLooper());
12663 phone.registerForSatellitePointingInfoChanged(handler,
12664 SatellitePositionUpdateHandler.EVENT_POSITION_UPDATE, null);
12665 phone.registerForSatelliteMessagesTransferComplete(handler,
12666 SatellitePositionUpdateHandler.EVENT_MESSAGE_TRANSFER_STATE_UPDATE, null);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012667 mSatellitePositionUpdateHandlers.put(callback.asBinder(), handler);
Sarah Chineccfbd12023-01-20 19:00:35 -080012668
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012669 sendRequestAsync(CMD_START_SATELLITE_POSITION_UPDATES, result, phone, null);
Sarah Chineccfbd12023-01-20 19:00:35 -080012670 }
12671
12672 /**
12673 * Stop receiving satellite position updates.
12674 * This can be called by the pointing UI when the user stops pointing to the satellite.
12675 *
12676 * @param subId The subId to stop satellite position updates for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012677 * @param errorCallback The callback to get the error code of the request.
12678 * @param callback The callback that was passed to {@link
12679 * #startSatellitePositionUpdates(int, IIntegerConsumer, ISatelliteStateListener)}
Sarah Chin503828c2023-02-01 23:54:20 -080012680 *
12681 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012682 */
12683 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012684 public void stopSatellitePositionUpdates(int subId, @NonNull IIntegerConsumer errorCallback,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012685 @NonNull ISatelliteStateListener callback) {
Sarah Chinf75afa72023-02-01 01:32:19 -080012686 enforceSatelliteCommunicationPermission("stopSatellitePositionUpdates");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012687 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(errorCallback::accept);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012688 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012689 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
12690 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012691 }
Sarah Chinf75afa72023-02-01 01:32:19 -080012692
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012693 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012694 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012695 result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED);
12696 return;
Sarah Chinf75afa72023-02-01 01:32:19 -080012697 }
12698
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012699 Phone phone = getPhoneOrDefault(validSubId, "stopSatellitePositionUpdates");
Sarah Chineccfbd12023-01-20 19:00:35 -080012700 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012701 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
12702 return;
Sarah Chineccfbd12023-01-20 19:00:35 -080012703 }
12704
12705 SatellitePositionUpdateHandler handler =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012706 mSatellitePositionUpdateHandlers.remove(callback.asBinder());
Sarah Chineccfbd12023-01-20 19:00:35 -080012707 if (handler == null) {
12708 loge("stopSatellitePositionUpdates: No SatellitePositionArgument");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012709 result.accept(SatelliteManager.SATELLITE_INVALID_ARGUMENTS);
12710 return;
Sarah Chineccfbd12023-01-20 19:00:35 -080012711 } else {
12712 phone.unregisterForSatellitePointingInfoChanged(handler);
12713 phone.unregisterForSatelliteMessagesTransferComplete(handler);
12714 }
12715
12716 if (!mSatellitePositionUpdateHandlers.isEmpty()) {
12717 log("stopSatellitePositionUpdates: other listeners still exist.");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012718 result.accept(SatelliteManager.SATELLITE_ERROR_NONE);
12719 return;
Sarah Chineccfbd12023-01-20 19:00:35 -080012720 }
12721
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012722 sendRequestAsync(CMD_STOP_SATELLITE_POSITION_UPDATES, result, phone, null);
Sarah Chineccfbd12023-01-20 19:00:35 -080012723 }
12724
12725 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012726 * Request to get the maximum number of characters per text message on satellite.
12727 *
12728 * @param subId The subId of the subscription.
12729 * @param result The result receiver that returns the maximum number of characters per text
12730 * message on satellite if the request is successful or an error code
12731 * if the request failed.
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012732 *
12733 * @throws SecurityException if the caller doesn't have the required permission.
12734 */
12735 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012736 public void requestMaxCharactersPerSatelliteTextMessage(int subId,
12737 @NonNull ResultReceiver result) {
12738 enforceSatelliteCommunicationPermission("requestMaxCharactersPerSatelliteTextMessage");
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012739 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012740 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
12741 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012742 }
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012743
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012744 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012745 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012746 result.send(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED, null);
12747 return;
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012748 }
12749
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012750 Phone phone = getPhoneOrDefault(validSubId, "requestMaxCharactersPerSatelliteTextMessage");
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012751 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012752 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
12753 return;
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012754 }
12755
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012756 sendRequestAsync(CMD_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG, result, phone, null);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012757 }
12758
12759 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012760 * Register the subscription with a satellite provider.
12761 * This is needed to register the subscription if the provider allows dynamic registration.
12762 *
12763 * @param subId The subId of the subscription to be provisioned.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012764 * @param token The security token of the device/subscription to be provisioned.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012765 * @param callback The callback to get the error code of the request.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012766 * @return The signal transport used by the caller to cancel the provision request,
12767 * or {@code null} if the request failed.
12768 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012769 * @throws SecurityException if the caller doesn't have the required permission.
12770 */
12771 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012772 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
12773 @NonNull String token, @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012774 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012775 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012776 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012777 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012778 return null;
12779 }
12780
12781 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012782 Phone phone = getPhoneOrDefault(validSubId, "provisionSatelliteService");
12783 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012784 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012785 return null;
12786 }
12787
12788 if (mSatelliteProvisionCallbacks.containsKey(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012789 result.accept(SatelliteManager.SATELLITE_SERVICE_PROVISION_IN_PROGRESS);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012790 return null;
12791 }
12792
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012793 if (isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012794 result.accept(SatelliteManager.SATELLITE_ERROR_NONE);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012795 return null;
12796 }
12797
12798 sendRequestAsync(CMD_PROVISION_SATELLITE_SERVICE,
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012799 new ProvisionSatelliteServiceArgument(token, result, validSubId), phone, null);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012800
12801 ICancellationSignal cancelTransport = CancellationSignal.createTransport();
12802 CancellationSignal.fromTransport(cancelTransport)
12803 .setOnCancelListener(() -> {
12804 sendRequestAsync(CMD_CANCEL_PROVISION_SATELLITE_SERVICE, validSubId);
12805 });
12806 return cancelTransport;
12807 }
12808
12809 /**
12810 * Register for the satellite provision state change.
12811 *
12812 * @param subId The subId of the subscription associated with the satellite service.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012813 * @param errorCallback The callback to get the error code of the request.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012814 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012815 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012816 * @throws SecurityException if the caller doesn't have the required permission.
12817 */
12818 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012819 public void registerForSatelliteProvisionStateChanged(int subId,
12820 @NonNull IIntegerConsumer errorCallback, @NonNull ISatelliteStateListener callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012821 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012822 Consumer<Integer> result = null;
12823 if (errorCallback != null) {
12824 result = FunctionalUtils.ignoreRemoteException(errorCallback::accept);
12825 }
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012826 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012827 if (result != null) {
12828 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
12829 }
12830 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012831 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012832
12833 final int validSubId = getValidSatelliteSubId(subId);
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012834 Phone phone = getPhoneOrDefault(validSubId, "registerForSatelliteProvisionStateChanged");
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012835 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012836 if (result != null) {
12837 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
12838 }
12839 return;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012840 }
12841
12842 SatelliteProvisionStateChangedHandler satelliteProvisionStateChangedHandler =
12843 mSatelliteProvisionStateChangedHandlers.get(validSubId);
12844 if (satelliteProvisionStateChangedHandler == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012845 satelliteProvisionStateChangedHandler = new SatelliteProvisionStateChangedHandler(
12846 Looper.getMainLooper(), validSubId);
12847 phone.registerForSatelliteProvisionStateChanged(satelliteProvisionStateChangedHandler,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012848 SatelliteProvisionStateChangedHandler.EVENT_PROVISION_STATE_CHANGED, null);
12849 }
12850
12851 if (callback != null) {
12852 satelliteProvisionStateChangedHandler.addListener(callback);
12853 }
12854 mSatelliteProvisionStateChangedHandlers.put(
12855 validSubId, satelliteProvisionStateChangedHandler);
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012856 if (result != null) {
12857 result.accept(SatelliteManager.SATELLITE_ERROR_NONE);
12858 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012859 }
12860
12861 /**
12862 * Unregister for the satellite provision state change.
12863 *
12864 * @param subId The subId of the subscription associated with the satellite service.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012865 * @param errorCallback The callback to get the error code of the request.
12866 * @param callback The callback that was passed to {@link
12867 * #registerForSatelliteProvisionStateChanged(int, IIntegerConsumer, ISatelliteStateListener)}.
12868 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012869 * @throws SecurityException if the caller doesn't have the required permission.
12870 */
12871 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012872 public void unregisterForSatelliteProvisionStateChanged(int subId,
12873 @NonNull IIntegerConsumer errorCallback, @NonNull ISatelliteStateListener callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012874 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012875 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(errorCallback::accept);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012876 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012877 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
12878 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012879 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012880
12881 final int validSubId = getValidSatelliteSubId(subId);
12882 SatelliteProvisionStateChangedHandler satelliteProvisionStateChangedHandler =
12883 mSatelliteProvisionStateChangedHandlers.get(validSubId);
12884 if (satelliteProvisionStateChangedHandler != null) {
12885 if (satelliteProvisionStateChangedHandler.removeListener(callback)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012886 result.accept(SatelliteManager.SATELLITE_ERROR_NONE);
12887 return;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012888 }
12889 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012890 result.accept(SatelliteManager.SATELLITE_INVALID_ARGUMENTS);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012891 }
12892
12893 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012894 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012895 *
12896 * @param subId The subId of the subscription associated with the satellite service.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012897 * @param result The result receiver that returns whether the device is provisioned with a
12898 * satellite provider if the request is successful or an error code if the
12899 * request failed.
12900 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012901 * @throws SecurityException if the caller doesn't have the required permission.
12902 */
12903 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012904 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
12905 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012906 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012907 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
12908 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012909 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012910
12911 final int validSubId = getValidSatelliteSubId(subId);
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012912 Bundle bundle = new Bundle();
12913 bundle.putBoolean(SatelliteManager.KEY_SATELLITE_PROVISIONED,
12914 isSatelliteProvisioned(validSubId));
12915 result.send(SatelliteManager.SATELLITE_ERROR_NONE, bundle);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012916 }
12917
12918 private void handleCmdProvisionSatelliteService(@NonNull ProvisionSatelliteServiceArgument arg,
12919 @NonNull Phone phone, Message onCompleted) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012920 if (arg == null) {
12921 loge("handleCmdProvisionSatelliteService: arg is null");
12922 return;
12923 }
12924 if (phone == null) {
12925 loge("handleCmdProvisionSatelliteService: phone is null");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012926 arg.callback.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012927 return;
12928 }
12929
12930 if (!mSatelliteProvisionCallbacks.containsKey(arg.subId)) {
12931 mSatelliteProvisionCallbacks.put(arg.subId, arg.callback);
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012932 phone.provisionSatelliteService(onCompleted, arg.token, phone.getImei(),
12933 phone.getMsisdn(), getSatelliteImsi(arg.subId));
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012934 } else {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012935 arg.callback.accept(SatelliteManager.SATELLITE_SERVICE_PROVISION_IN_PROGRESS);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012936 }
12937 }
12938
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012939 private void handleEventProvisionSatelliteServiceDone(int subId,
12940 @SatelliteManager.SatelliteError int result) {
12941 Consumer<Integer> callback = mSatelliteProvisionCallbacks.remove(subId);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012942 if (callback == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012943 loge("handleEventProvisionSatelliteServiceDone: callback is null for subId=" + subId);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012944 return;
12945 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012946 callback.accept(result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012947
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012948 if (DBG) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012949 log("handleEventProvisionSatelliteServiceDone: result=" + result + ", subId="
12950 + subId);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012951 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012952
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012953 if (result == SatelliteManager.SATELLITE_ERROR_NONE) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012954 setSatelliteProvisioned(subId, true);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012955 }
12956
12957 /**
12958 * We need to update satellite provision status in SubscriptionController
12959 * or SatelliteController.
12960 * TODO (b/267826133) we need to do this for all subscriptions on the device.
12961 */
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012962 registerForSatelliteProvisionStateChanged(subId, null, null);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012963 }
12964
12965 private void handleCmdCancelProvisionSatelliteService(int subId, Message onCompleted) {
12966 final Phone phone = getPhoneOrDefault(
12967 subId, "handleCmdCancelProvisionSatelliteService");
12968 if (phone == null) {
12969 return;
12970 }
12971 phone.cancelProvisionSatelliteService(onCompleted, getSatelliteImsi(subId));
12972 }
12973
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012974 private String getSatelliteImsi(int subId) {
12975 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12976 return "";
12977 }
12978
12979 if (mSubscriptionController == null) {
12980 loge("getSatelliteImsi: mSubscriptionController is null");
12981 return "";
12982 }
12983 return mSubscriptionController.getImsiPrivileged(subId);
12984 }
12985
12986 private Phone getPhoneOrDefault(int subId, String caller) {
12987 Phone phone = getPhone(subId);
12988 if (phone == null) {
12989 loge(caller + " called with invalid subId: " + subId
12990 + ". Retrying with default phone.");
12991 phone = getDefaultPhone();
12992 if (phone == null) {
12993 loge(caller + " failed with no phone object.");
12994 }
12995 }
12996 return phone;
12997 }
12998
12999 /**
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013000 * Check if satellite is provisioned for a subscription or the device.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013001 *
13002 * Note: this is the version without permission check for telephony internal use only. The
13003 * caller need to take care of the permission check.
13004 */
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013005 private boolean isSatelliteProvisioned(int subId) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013006 if (subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
13007 if (mSubscriptionController == null) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013008 loge("isSatelliteProvisioned mSubscriptionController is null");
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013009 return false;
13010 }
13011
13012 String strResult = mSubscriptionController.getSubscriptionProperty(
13013 subId, SubscriptionManager.SATELLITE_ENABLED);
13014 if (strResult != null) {
13015 int intResult = Integer.parseInt(strResult);
13016 return (intResult == 1) ? true : false;
13017 }
13018 } else {
13019 //TODO (b/267826133): check via SatelliteController
13020 }
13021 return false;
13022 }
13023
13024 /**
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013025 * Set satellite provisioned for a subscription or the device.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013026 *
13027 * The permission {@link android.Manifest.permission#MODIFY_PHONE_STATE} will be enforced by
13028 * {@link SubscriptionController} when setting satellite enabled for an active subscription.
13029 * Otherwise, {@link android.Manifest.permission#SATELLITE_COMMUNICATION} will be enforced.
13030 */
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013031 private void setSatelliteProvisioned(int subId, boolean isEnabled) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013032 if (subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
13033 if (mSubscriptionController == null) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013034 loge("setSatelliteProvisioned mSubscriptionController is null");
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013035 return;
13036 }
13037 mSubscriptionController.setSubscriptionProperty(
13038 subId, SubscriptionManager.SATELLITE_ENABLED, isEnabled ? "1" : "0");
13039 } else {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013040 //TODO (b/267826133): set via SatelliteController
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013041 }
13042 }
13043
13044 private int getValidSatelliteSubId(int subId) {
13045 if (mSubscriptionController == null) {
13046 loge("getValidSatelliteSubId mSubscriptionController is null. "
13047 + "Use DEFAULT_SUBSCRIPTION_ID for subId=" + subId);
13048 return SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
13049 }
13050 final long identity = Binder.clearCallingIdentity();
13051 try {
13052 Context context = getDefaultPhone().getContext();
13053 if (mSubscriptionController.isActiveSubId(
13054 subId, context.getOpPackageName(), context.getAttributionTag())) {
13055 return subId;
13056 }
13057 } finally {
13058 Binder.restoreCallingIdentity(identity);
13059 }
13060 if (DBG) log("getValidSatelliteSubId: use DEFAULT_SUBSCRIPTION_ID for subId=" + subId);
13061 return SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
13062 }
13063
13064 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013065 * If we have not successfully queried the satellite modem for its satellite service support,
13066 * we will retry the query one more time. Otherwise, we will return the queried result.
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013067 */
13068 private boolean isSatelliteSupported() {
13069 synchronized (mIsSatelliteSupportedLock) {
13070 if (mIsSatelliteSupported != null) {
13071 /* We have already successfully queried the satellite modem. */
13072 return mIsSatelliteSupported;
13073 }
13074 }
13075 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013076 * We have not successfully checked whether the modem supports satellite service.
13077 * Thus, we need to retry it now.
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013078 */
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013079 requestIsSatelliteSupported(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
13080 mSatelliteSupportedReceiver);
13081 return false;
13082 }
13083
13084 /**
13085 * Get the {@link SatelliteManager.SatelliteError} from the provided result.
13086 * @param ar AsyncResult used to determine the error code.
13087 * @param caller The satellite request.
13088 * @param checkResult Whether to check if the result exists.
13089 * @return The {@link SatelliteManager.SatelliteError} error code from the request.
13090 */
13091 @SatelliteManager.SatelliteError private int getSatelliteError(@NonNull AsyncResult ar,
13092 @NonNull String caller, boolean checkResult) {
13093 int errorCode;
13094 if (ar.exception == null) {
13095 errorCode = SatelliteManager.SATELLITE_ERROR_NONE;
13096 if (checkResult && ar.result == null) {
13097 loge(caller + ": result is null");
13098 errorCode = SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE;
13099 }
13100 } else {
13101 errorCode = SatelliteManager.SATELLITE_ERROR;
13102 if (ar.exception instanceof CommandException) {
13103 CommandException.Error error =
13104 ((CommandException) (ar.exception)).getCommandError();
13105 errorCode = RILUtils.convertToSatelliteError(error);
13106 loge(caller + " CommandException: " + ar.exception);
13107 } else {
13108 loge(caller + " unknown exception: " + ar.exception);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013109 }
13110 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013111 log(caller + " error: " + errorCode);
13112 return errorCode;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013113 }
13114
13115 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000013116 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
13117 *
13118 * <p>This method behaves in one of the following ways:
13119 * <ul>
13120 * <li>return true : if the calling package has the appop permission {@link
13121 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
13122 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
13123 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
13124 * Owner device identifier access check, or the calling package has carrier privileges</>
13125 * <li>throw SecurityException: if the caller does not meet any of the requirements.
13126 * </ul>
13127 */
13128 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
13129 String callingPackage, @Nullable String callingFeatureId, String message) {
13130 for (Phone phone : PhoneFactory.getPhones()) {
13131 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
13132 phone.getSubId(), callingPackage, callingFeatureId, message)) {
13133 return true;
13134 }
13135 }
13136 return false;
13137 }
arunvoddud7401012022-12-15 16:08:12 +000013138
13139 /**
Jack Yufa8ed012023-02-11 15:42:28 -080013140 * @return The subscription manager service instance.
13141 */
13142 public SubscriptionManagerService getSubscriptionManagerService() {
13143 return SubscriptionManagerService.getInstance();
13144 }
13145
13146 /**
arunvoddud7401012022-12-15 16:08:12 +000013147 * Class binds the consumer[callback] and carrierId.
13148 */
13149 private static class CallerCallbackInfo {
13150 private final Consumer<Integer> mConsumer;
13151 private final int mCarrierId;
13152
13153 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
13154 mConsumer = consumer;
13155 mCarrierId = carrierId;
13156 }
13157
13158 public Consumer<Integer> getConsumer() {
13159 return mConsumer;
13160 }
13161
13162 public int getCarrierId() {
13163 return mCarrierId;
13164 }
13165 }
Jack Yufa8ed012023-02-11 15:42:28 -080013166}