blob: b8e429f1283c057e9ea646ee845bb5b6a0acf782 [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;
150import android.telephony.satellite.SatelliteManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700151import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800152import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700153import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700154import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800155import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800156
Andrew Lee312e8172014-10-23 17:01:36 -0700157import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800158import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800159import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800160import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800161import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700162import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700163import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700164import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800165import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800166import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700167import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700168import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800169import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700170import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800171import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800172import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800173import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700174import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000175import com.android.internal.telephony.IImsStateCallback;
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800176import com.android.internal.telephony.IIntArrayConsumer;
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;
397 private static final int CMD_GET_PROVISIONED_SATELLITE_FEATURES = 129;
398 private static final int EVENT_GET_PROVISIONED_SATELLITE_FEATURES_DONE = 130;
399
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800400 // Parameters of select command.
401 private static final int SELECT_COMMAND = 0xA4;
402 private static final int SELECT_P1 = 0x04;
403 private static final int SELECT_P2 = 0;
404 private static final int SELECT_P3 = 0x10;
405
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000406 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
407 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
408
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700409 /** The singleton instance. */
410 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800411 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700412
Wink Saville3ab207e2014-11-20 13:07:20 -0800413 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800414 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800415 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700416 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800417 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700418 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800419 private MainThreadHandler mMainThreadHandler;
Jack Yue37dd262022-12-16 11:53:37 -0800420 private final SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800421 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700422 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800423 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700424
Peter Wangdafb9ac2020-01-15 14:13:38 -0800425 /** User Activity */
426 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800427 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
428
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700429 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800430 private ConcurrentHashMap<IBinder, SatellitePositionUpdateHandler>
431 mSatellitePositionUpdateHandlers = new ConcurrentHashMap<>();
432 /**
433 * Map key: subId, value: callback to get error code of the provision request.
434 */
435 private ConcurrentHashMap<Integer, IIntegerConsumer> mSatelliteProvisionCallbacks =
Sarah Chineccfbd12023-01-20 19:00:35 -0800436 new ConcurrentHashMap<>();
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700437
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800438 /**
439 * Map key: subId, value: SatelliteProvisionStateChangedHandler to notify registrants.
440 */
441 private ConcurrentHashMap<Integer, SatelliteProvisionStateChangedHandler>
442 mSatelliteProvisionStateChangedHandlers = new ConcurrentHashMap<>();
443
Derek Tan97ebb422014-09-05 16:55:38 -0700444 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
445 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800446 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800447 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700448
Michelecea4cf22018-12-21 15:00:11 -0800449 // String to store multi SIM allowed
450 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
451
Derek Tan740e1672017-06-27 14:56:27 -0700452 // The AID of ISD-R.
453 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
454
yinxub1bed742017-04-17 11:45:04 -0700455 private NetworkScanRequestTracker mNetworkScanRequestTracker;
456
David Kelly5e06a7f2018-03-12 14:10:59 +0000457 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
458 private static final int MANUFACTURER_CODE_LENGTH = 8;
459
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800460 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800461 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800462
Sarah Chin2ec39f62022-08-31 17:03:26 -0700463 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
464 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
465
Derek Tan89e89d42014-07-08 17:00:10 -0700466 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700467 * Experiment flag to enable erase modem config on reset network, default value is false
468 */
469 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
470 "reset_network_erase_modem_config_enabled";
471
Rambo Wang0f050d82021-02-12 11:43:36 -0800472 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800473
Gary Jian76280a42022-12-07 16:18:33 +0800474 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
475
sandeepjsb6c87872021-09-27 15:34:44 +0000476 /**
477 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
478 * one ICCID active at the same time.
479 * Apps should use below API signatures if targeting SDK is T and beyond.
480 *
481 * @hide
482 */
483 @ChangeId
484 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
485 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800486
Naina Nallurid63128d2019-09-17 14:10:30 -0700487 /**
Chen Xu540470b2021-12-14 17:15:47 -0800488 * Apps targeting on Android T and beyond will get exception whenever icc close channel
489 * operation fails.
490 */
491 @ChangeId
492 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
493 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
494
495 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700496 * A request object to use for transmitting data to an ICC.
497 */
498 private static final class IccAPDUArgument {
499 public int channel, cla, command, p1, p2, p3;
500 public String data;
501
502 public IccAPDUArgument(int channel, int cla, int command,
503 int p1, int p2, int p3, String data) {
504 this.channel = channel;
505 this.cla = cla;
506 this.command = command;
507 this.p1 = p1;
508 this.p2 = p2;
509 this.p3 = p3;
510 this.data = data;
511 }
512 }
513
514 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700515 * A request object to use for transmitting data to an ICC.
516 */
517 private static final class ManualNetworkSelectionArgument {
518 public OperatorInfo operatorInfo;
519 public boolean persistSelection;
520
521 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
522 this.operatorInfo = operatorInfo;
523 this.persistSelection = persistSelection;
524 }
525 }
526
Sarah Chin71b3a852022-09-28 15:54:19 -0700527 private static final class PurchasePremiumCapabilityArgument {
528 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700529 public @NonNull IIntegerConsumer callback;
530
531 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800532 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700533 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700534 this.callback = callback;
535 }
536 }
537
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800538 private static final class ProvisionSatelliteServiceArgument {
539 public @NonNull int[] features;
540 public @NonNull IIntegerConsumer callback;
541 public int subId;
542
543 ProvisionSatelliteServiceArgument(int[] features, IIntegerConsumer callback, int subId) {
544 this.features = features;
545 this.callback = callback;
546 this.subId = subId;
547 }
548 }
549
Sarah Chineccfbd12023-01-20 19:00:35 -0800550 private static final class SatellitePositionUpdateHandler extends Handler {
551 public static final int EVENT_POSITION_UPDATE = 1;
552 public static final int EVENT_MESSAGE_TRANSFER_STATE_UPDATE = 2;
553
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800554 private final ISatelliteStateListener mCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800555
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800556 SatellitePositionUpdateHandler(ISatelliteStateListener callback, Looper looper) {
Sarah Chineccfbd12023-01-20 19:00:35 -0800557 super(looper);
558 mCallback = callback;
559 }
560
561 @Override
562 public void handleMessage(@NonNull Message msg) {
563 switch (msg.what) {
564 case EVENT_POSITION_UPDATE: {
565 AsyncResult ar = (AsyncResult) msg.obj;
566 PointingInfo pointingInfo = (PointingInfo) ar.result;
567 try {
568 mCallback.onSatellitePositionUpdate(pointingInfo);
569 } catch (RemoteException e) {
570 loge("EVENT_POSITION_UPDATE RemoteException: " + e);
571 }
572 break;
573 }
574 case EVENT_MESSAGE_TRANSFER_STATE_UPDATE: {
575 AsyncResult ar = (AsyncResult) msg.obj;
576 int state = (int) ar.result;
577 try {
578 mCallback.onMessageTransferStateUpdate(state);
579 } catch (RemoteException e) {
580 loge("EVENT_MESSAGE_TRANSFER_STATE_UPDATE RemoteException: " + e);
581 }
582 break;
583 }
584 default:
585 loge("SatellitePositionUpdateHandler unknown event: " + msg.what);
586 }
587 }
588 }
589
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800590 private static final class SatelliteProvisionStateChangedHandler extends Handler {
591 public static final int EVENT_PROVISION_STATE_CHANGED = 1;
592
593 private ConcurrentHashMap<IBinder, ISatelliteStateListener> mListeners;
594 private final int mSubId;
595
596 SatelliteProvisionStateChangedHandler(Looper looper, int subId) {
597 super(looper);
598 mListeners = new ConcurrentHashMap<>();
599 mSubId = subId;
600 }
601
602 public void addListener(ISatelliteStateListener listener) {
603 mListeners.put(listener.asBinder(), listener);
604 }
605
606 public boolean removeListener(ISatelliteStateListener listener) {
607 return (mListeners.remove(listener.asBinder()) != null);
608 }
609
610 @Override
611 public void handleMessage(@NonNull Message msg) {
612 switch (msg.what) {
613 case EVENT_PROVISION_STATE_CHANGED: {
614 AsyncResult ar = (AsyncResult) msg.obj;
615 boolean provisioned = (boolean) ar.userObj;
616 int[] features = (int[]) ar.result;
617 log("Received EVENT_PROVISION_STATE_CHANGED for subId=" + mSubId
618 + ", features=" + Arrays.toString(features)
619 + ", provisioned=" + provisioned);
620 mListeners.values().forEach(listener -> {
621 try {
622 listener.onSatelliteProvisionStateChanged(features, provisioned);
623 } catch (RemoteException e) {
624 log("EVENT_PROVISION_STATE_CHANGED RemoteException: " + e);
625 }
626 });
627
628 setSatelliteEnabled(provisioned);
629 /**
630 * TODO: Take bugreport if provisioned is true and user did not initiate the
631 * provision procedure for the corresponding subscription.
632 */
633 break;
634 }
635 default:
636 loge("SatelliteProvisionStateChangedHandler unknown event: " + msg.what);
637 }
638 }
639
640 private void setSatelliteEnabled(boolean isEnabled) {
641 if (mSubId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
642 SubscriptionManager.setSubscriptionProperty(
643 mSubId, SubscriptionManager.SATELLITE_ENABLED, isEnabled ? "1" : "0");
644 } else {
645 //TODO (b/267826133): set enabled via SatelliteController.
646 }
647 }
648 }
649
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700650 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700651 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
652 * request after sending. The main thread will notify the request when it is complete.
653 */
654 private static final class MainThreadRequest {
655 /** The argument to use for the request */
656 public Object argument;
657 /** The result of the request that is run on the main thread */
658 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800659 // The subscriber id that this request applies to. Defaults to
660 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
661 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700662
Nathan Harold92bed182018-10-12 18:16:49 -0700663 // In cases where subId is unavailable, the caller needs to specify the phone.
664 public Phone phone;
665
vagdeviaf9a5b92018-08-15 16:01:53 -0700666 public WorkSource workSource;
667
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700668 public MainThreadRequest(Object argument) {
669 this.argument = argument;
670 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800671
Nathan Harold92bed182018-10-12 18:16:49 -0700672 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
673 this.argument = argument;
674 if (phone != null) {
675 this.phone = phone;
676 }
677 this.workSource = workSource;
678 }
679
vagdeviaf9a5b92018-08-15 16:01:53 -0700680 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800681 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800682 if (subId != null) {
683 this.subId = subId;
684 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700685 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800686 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700687 }
688
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800689 private static final class IncomingThirdPartyCallArgs {
690 public final ComponentName component;
691 public final String callId;
692 public final String callerDisplayName;
693
694 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
695 String callerDisplayName) {
696 this.component = component;
697 this.callId = callId;
698 this.callerDisplayName = callerDisplayName;
699 }
700 }
701
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700702 /**
703 * A handler that processes messages on the main thread in the phone process. Since many
704 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
705 * inbound binder threads to the main thread in the phone process. The Binder thread
706 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
707 * on, which will be notified when the operation completes and will contain the result of the
708 * request.
709 *
710 * <p>If a MainThreadRequest object is provided in the msg.obj field,
711 * note that request.result must be set to something non-null for the calling thread to
712 * unblock.
713 */
714 private final class MainThreadHandler extends Handler {
715 @Override
716 public void handleMessage(Message msg) {
717 MainThreadRequest request;
718 Message onCompleted;
719 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000720 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700721 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800722 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700723
724 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700725 case CMD_HANDLE_USSD_REQUEST: {
726 request = (MainThreadRequest) msg.obj;
727 final Phone phone = getPhoneFromRequest(request);
728 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800729 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700730 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700731
Pengquan Menga1bb6272018-09-06 09:59:22 -0700732 if (!isUssdApiAllowed(request.subId)) {
733 // Carrier does not support use of this API, return failure.
734 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
735 UssdResponse response = new UssdResponse(ussdRequest, null);
736 Bundle returnData = new Bundle();
737 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
738 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700739
Pengquan Menga1bb6272018-09-06 09:59:22 -0700740 request.result = true;
741 notifyRequester(request);
742 return;
743 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700744
Pengquan Menga1bb6272018-09-06 09:59:22 -0700745 try {
746 request.result = phone != null
747 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
748 } catch (CallStateException cse) {
749 request.result = false;
750 }
751 // Wake up the requesting thread
752 notifyRequester(request);
753 break;
pkanwar32d516d2016-10-14 19:37:38 -0700754 }
755
Yorke Lee716f67e2015-06-17 15:39:16 -0700756 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700757 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700758 final Phone phone = getPhoneFromRequest(request);
759 request.result = phone != null ?
760 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
761 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700762 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700763 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700764 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700765 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700766
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700767 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700768 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700769 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000770 uiccPort = getUiccPortFromRequest(request);
771 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700772 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800773 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700774 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700775 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700776 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800777 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000778 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800779 iccArgument.channel, iccArgument.cla, iccArgument.command,
780 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
781 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700782 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700783 break;
784
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700785 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700786 ar = (AsyncResult) msg.obj;
787 request = (MainThreadRequest) ar.userObj;
788 if (ar.exception == null && ar.result != null) {
789 request.result = ar.result;
790 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800791 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700792 if (ar.result == null) {
793 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800794 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700795 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800796 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700797 } else {
798 loge("iccTransmitApduLogicalChannel: Unknown exception");
799 }
800 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700801 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700802 break;
803
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700804 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
805 request = (MainThreadRequest) msg.obj;
806 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000807 uiccPort = getUiccPortFromRequest(request);
808 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700809 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800810 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700811 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700812 } else {
813 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800814 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000815 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800816 iccArgument.cla, iccArgument.command, iccArgument.p1,
817 iccArgument.p2,
818 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700819 }
820 break;
821
822 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
823 ar = (AsyncResult) msg.obj;
824 request = (MainThreadRequest) ar.userObj;
825 if (ar.exception == null && ar.result != null) {
826 request.result = ar.result;
827 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800828 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700829 if (ar.result == null) {
830 loge("iccTransmitApduBasicChannel: Empty response");
831 } else if (ar.exception instanceof CommandException) {
832 loge("iccTransmitApduBasicChannel: CommandException: " +
833 ar.exception);
834 } else {
835 loge("iccTransmitApduBasicChannel: Unknown exception");
836 }
837 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700838 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700839 break;
840
841 case CMD_EXCHANGE_SIM_IO:
842 request = (MainThreadRequest) msg.obj;
843 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000844 uiccPort = getUiccPortFromRequest(request);
845 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700846 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800847 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700848 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700849 } else {
850 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
851 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000852 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700853 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
854 iccArgument.data, onCompleted);
855 }
856 break;
857
858 case EVENT_EXCHANGE_SIM_IO_DONE:
859 ar = (AsyncResult) msg.obj;
860 request = (MainThreadRequest) ar.userObj;
861 if (ar.exception == null && ar.result != null) {
862 request.result = ar.result;
863 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800864 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700865 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700866 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700867 break;
868
Derek Tan4d5e5c12014-02-04 11:54:58 -0800869 case CMD_SEND_ENVELOPE:
870 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000871 uiccPort = getUiccPortFromRequest(request);
872 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700873 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800874 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700875 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700876 } else {
877 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800878 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700879 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800880 break;
881
882 case EVENT_SEND_ENVELOPE_DONE:
883 ar = (AsyncResult) msg.obj;
884 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700885 if (ar.exception == null && ar.result != null) {
886 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800887 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800888 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700889 if (ar.result == null) {
890 loge("sendEnvelopeWithStatus: Empty response");
891 } else if (ar.exception instanceof CommandException) {
892 loge("sendEnvelopeWithStatus: CommandException: " +
893 ar.exception);
894 } else {
895 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
896 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800897 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700898 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800899 break;
900
Shishir Agrawal566b7612013-10-28 14:41:00 -0700901 case CMD_OPEN_CHANNEL:
902 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000903 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800904 IccLogicalChannelRequest openChannelRequest =
905 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000906 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700907 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800908 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800909 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700910 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700911 } else {
912 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800913 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
914 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700915 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700916 break;
917
918 case EVENT_OPEN_CHANNEL_DONE:
919 ar = (AsyncResult) msg.obj;
920 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700921 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700922 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700923 int[] result = (int[]) ar.result;
924 int channelId = result[0];
925 byte[] selectResponse = null;
926 if (result.length > 1) {
927 selectResponse = new byte[result.length - 1];
928 for (int i = 1; i < result.length; ++i) {
929 selectResponse[i - 1] = (byte) result[i];
930 }
931 }
932 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800933 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800934
935 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700936 if (uiccPort == null) {
937 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
938 } else {
939 IccLogicalChannelRequest channelRequest =
940 (IccLogicalChannelRequest) request.argument;
941 channelRequest.channel = channelId;
942 uiccPort.onLogicalChannelOpened(channelRequest);
943 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700944 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700945 if (ar.result == null) {
946 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700947 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700948 if (ar.exception != null) {
949 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
950 }
951
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700952 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700953 if (ar.exception instanceof CommandException) {
954 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800955 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700956 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700957 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700958 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700959 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700960 }
961 }
962 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800963 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700964 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700965 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700966 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700967 break;
968
969 case CMD_CLOSE_CHANNEL:
970 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000971 uiccPort = getUiccPortFromRequest(request);
972 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700973 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800974 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800975 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800976 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700977 } else {
978 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000979 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700980 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700981 break;
982
983 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800984 ar = (AsyncResult) msg.obj;
985 request = (MainThreadRequest) ar.userObj;
986 if (ar.exception == null) {
987 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800988 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700989 if (uiccPort == null) {
990 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
991 } else {
992 final int channelId = (Integer) request.argument;
993 uiccPort.onLogicalChannelClosed(channelId);
994 }
Chen Xu540470b2021-12-14 17:15:47 -0800995 } else {
996 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800997 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800998 if (ar.exception instanceof CommandException) {
999 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
1000 CommandException.Error error =
1001 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -08001002 if (error == CommandException.Error.INVALID_ARGUMENTS) {
1003 // should only throw exceptions from the binder threads.
1004 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -08001005 "iccCloseLogicalChannel: invalid argument ");
1006 }
1007 } else {
1008 loge("iccCloseLogicalChannel: Unknown exception");
1009 }
Chen Xua8f0dff2022-02-12 00:34:15 -08001010 request.result = (exception != null) ? exception :
1011 new IllegalStateException(
1012 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -08001013 }
1014 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001015 break;
1016
1017 case CMD_NV_READ_ITEM:
1018 request = (MainThreadRequest) msg.obj;
1019 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001020 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
1021 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -08001022 break;
1023
1024 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -07001025 ar = (AsyncResult) msg.obj;
1026 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -08001027 if (ar.exception == null && ar.result != null) {
1028 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -07001029 } else {
Jake Hambye994d462014-02-03 13:10:13 -08001030 request.result = "";
1031 if (ar.result == null) {
1032 loge("nvReadItem: Empty response");
1033 } else if (ar.exception instanceof CommandException) {
1034 loge("nvReadItem: CommandException: " +
1035 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001036 } else {
Jake Hambye994d462014-02-03 13:10:13 -08001037 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -07001038 }
1039 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001040 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001041 break;
1042
Jake Hambye994d462014-02-03 13:10:13 -08001043 case CMD_NV_WRITE_ITEM:
1044 request = (MainThreadRequest) msg.obj;
1045 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
1046 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001047 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -07001048 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -08001049 break;
1050
1051 case EVENT_NV_WRITE_ITEM_DONE:
1052 handleNullReturnEvent(msg, "nvWriteItem");
1053 break;
1054
1055 case CMD_NV_WRITE_CDMA_PRL:
1056 request = (MainThreadRequest) msg.obj;
1057 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001058 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -08001059 break;
1060
1061 case EVENT_NV_WRITE_CDMA_PRL_DONE:
1062 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
1063 break;
1064
chen xu6dac5ab2018-10-26 17:39:23 -07001065 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -08001066 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -07001067 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001068 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -08001069 break;
1070
chen xu6dac5ab2018-10-26 17:39:23 -07001071 case EVENT_RESET_MODEM_CONFIG_DONE:
1072 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -08001073 break;
1074
Sooraj Sasindran37444802020-08-11 10:40:43 -07001075 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
1076 request = (MainThreadRequest) msg.obj;
1077 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
1078 request);
1079 Phone phone = getPhoneFromRequest(request);
1080 if (phone != null) {
1081 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
1082 } else {
1083 loge("isNRDualConnectivityEnabled: No phone object");
1084 request.result = false;
1085 notifyRequester(request);
1086 }
1087 break;
1088 }
1089
1090 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
1091 ar = (AsyncResult) msg.obj;
1092 request = (MainThreadRequest) ar.userObj;
1093 if (ar.exception == null && ar.result != null) {
1094 request.result = ar.result;
1095 } else {
1096 // request.result must be set to something non-null
1097 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001098 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -07001099 request.result = ar.result;
1100 } else {
1101 request.result = false;
1102 }
1103 if (ar.result == null) {
1104 loge("isNRDualConnectivityEnabled: Empty response");
1105 } else if (ar.exception instanceof CommandException) {
1106 loge("isNRDualConnectivityEnabled: CommandException: "
1107 + ar.exception);
1108 } else {
1109 loge("isNRDualConnectivityEnabled: Unknown exception");
1110 }
1111 }
1112 notifyRequester(request);
1113 break;
1114
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001115 case CMD_IS_VONR_ENABLED: {
1116 request = (MainThreadRequest) msg.obj;
1117 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
1118 request);
1119 Phone phone = getPhoneFromRequest(request);
1120 if (phone != null) {
1121 phone.isVoNrEnabled(onCompleted, request.workSource);
1122 } else {
1123 loge("isVoNrEnabled: No phone object");
1124 request.result = false;
1125 notifyRequester(request);
1126 }
1127 break;
1128 }
1129
1130 case EVENT_IS_VONR_ENABLED_DONE:
1131 ar = (AsyncResult) msg.obj;
1132 request = (MainThreadRequest) ar.userObj;
1133 if (ar.exception == null && ar.result != null) {
1134 request.result = ar.result;
1135 } else {
1136 // request.result must be set to something non-null
1137 // for the calling thread to unblock
1138 if (ar.result != null) {
1139 request.result = ar.result;
1140 } else {
1141 request.result = false;
1142 }
1143 if (ar.result == null) {
1144 loge("isVoNrEnabled: Empty response");
1145 } else if (ar.exception instanceof CommandException) {
1146 loge("isVoNrEnabled: CommandException: "
1147 + ar.exception);
1148 } else {
1149 loge("isVoNrEnabled: Unknown exception");
1150 }
1151 }
1152 notifyRequester(request);
1153 break;
1154
Sooraj Sasindran37444802020-08-11 10:40:43 -07001155 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1156 request = (MainThreadRequest) msg.obj;
1157 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1158 Phone phone = getPhoneFromRequest(request);
1159 if (phone != null) {
1160 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1161 request.workSource);
1162 } else {
1163 loge("enableNrDualConnectivity: No phone object");
1164 request.result =
1165 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1166 notifyRequester(request);
1167 }
1168 break;
1169 }
1170
1171 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1172 ar = (AsyncResult) msg.obj;
1173 request = (MainThreadRequest) ar.userObj;
1174 if (ar.exception == null) {
1175 request.result =
1176 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1177 } else {
1178 request.result =
1179 TelephonyManager
1180 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1181 if (ar.exception instanceof CommandException) {
1182 CommandException.Error error =
1183 ((CommandException) (ar.exception)).getCommandError();
1184 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1185 request.result =
1186 TelephonyManager
1187 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001188 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1189 request.result =
1190 TelephonyManager
1191 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001192 }
1193 loge("enableNrDualConnectivity" + ": CommandException: "
1194 + ar.exception);
1195 } else {
1196 loge("enableNrDualConnectivity" + ": Unknown exception");
1197 }
1198 }
1199 notifyRequester(request);
1200 break;
1201 }
1202
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001203 case CMD_ENABLE_VONR: {
1204 request = (MainThreadRequest) msg.obj;
1205 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1206 Phone phone = getPhoneFromRequest(request);
1207 if (phone != null) {
1208 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1209 request.workSource);
1210 } else {
1211 loge("setVoNrEnabled: No phone object");
1212 request.result =
1213 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1214 notifyRequester(request);
1215 }
1216 break;
1217 }
1218
1219 case EVENT_ENABLE_VONR_DONE: {
1220 ar = (AsyncResult) msg.obj;
1221 request = (MainThreadRequest) ar.userObj;
1222 if (ar.exception == null) {
1223 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1224 } else {
1225 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1226 if (ar.exception instanceof CommandException) {
1227 CommandException.Error error =
1228 ((CommandException) (ar.exception)).getCommandError();
1229 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1230 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1231 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1232 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1233 } else {
1234 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1235 }
1236 loge("setVoNrEnabled" + ": CommandException: "
1237 + ar.exception);
1238 } else {
1239 loge("setVoNrEnabled" + ": Unknown exception");
1240 }
1241 }
1242 notifyRequester(request);
1243 break;
1244 }
1245
SongFerngWang3ef3e072020-12-21 16:41:52 +08001246 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001247 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001248 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1249 request);
1250 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001251 break;
1252
SongFerngWang3ef3e072020-12-21 16:41:52 +08001253 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001254 ar = (AsyncResult) msg.obj;
1255 request = (MainThreadRequest) ar.userObj;
1256 if (ar.exception == null && ar.result != null) {
1257 request.result = ar.result; // Integer
1258 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301259 // request.result must be set to something non-null
1260 // for the calling thread to unblock
1261 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001262 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001263 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001264 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001265 loge("getAllowedNetworkTypesBitmask: CommandException: "
1266 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001267 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001268 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001269 }
1270 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001271 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001272 break;
1273
SongFerngWang3ef3e072020-12-21 16:41:52 +08001274 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001275 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001276 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1277 request);
1278 Pair<Integer, Long> reasonWithNetworkTypes =
1279 (Pair<Integer, Long>) request.argument;
1280 getPhoneFromRequest(request).setAllowedNetworkTypes(
1281 reasonWithNetworkTypes.first,
1282 reasonWithNetworkTypes.second,
1283 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001284 break;
1285
SongFerngWang3ef3e072020-12-21 16:41:52 +08001286 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1287 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001288 break;
1289
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001290 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1291 request = (MainThreadRequest)msg.obj;
1292 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001293 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001294 break;
1295
1296 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1297 ar = (AsyncResult)msg.obj;
1298 request = (MainThreadRequest)ar.userObj;
1299 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001300 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001301 break;
1302
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001303 case CMD_SET_VOICEMAIL_NUMBER:
1304 request = (MainThreadRequest) msg.obj;
1305 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1306 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001307 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1308 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001309 break;
1310
1311 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1312 handleNullReturnEvent(msg, "setVoicemailNumber");
1313 break;
1314
Stuart Scott54788802015-03-30 13:18:01 -07001315 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1316 request = (MainThreadRequest) msg.obj;
1317 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1318 request);
1319 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1320 break;
1321
1322 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1323 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1324 break;
1325
Shishir Agrawal302c8692015-06-19 13:49:39 -07001326 case CMD_PERFORM_NETWORK_SCAN:
1327 request = (MainThreadRequest) msg.obj;
1328 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1329 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1330 break;
1331
Hall Liu27d24262020-09-18 19:04:59 -07001332 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001333 request = (MainThreadRequest) msg.obj;
1334 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001335 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1336 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1337 request.argument;
1338 int callForwardingReason = args.first;
1339 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001340 break;
Hall Liu27d24262020-09-18 19:04:59 -07001341 }
1342 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001343 ar = (AsyncResult) msg.obj;
1344 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001345 TelephonyManager.CallForwardingInfoCallback callback =
1346 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1347 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001348 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001349 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001350 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1351 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1352 // Service Class is a bit mask per 3gpp 27.007. Search for
1353 // any service for voice call.
1354 if ((callForwardInfo.serviceClass
1355 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001356 callForwardingInfo = new CallForwardingInfo(
1357 callForwardInfo.status
1358 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001359 callForwardInfo.reason,
1360 callForwardInfo.number,
1361 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001362 break;
1363 }
1364 }
1365 // Didn't find a call forward info for voice call.
1366 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001367 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1368 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001369 }
Hall Liu27d24262020-09-18 19:04:59 -07001370 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001371 } else {
1372 if (ar.result == null) {
1373 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1374 }
1375 if (ar.exception != null) {
1376 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1377 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001378 int errorCode = TelephonyManager
1379 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001380 if (ar.exception instanceof CommandException) {
1381 CommandException.Error error =
1382 ((CommandException) (ar.exception)).getCommandError();
1383 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001384 errorCode = TelephonyManager
1385 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001386 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001387 errorCode = TelephonyManager
1388 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001389 }
1390 }
Hall Liu27d24262020-09-18 19:04:59 -07001391 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001392 }
Shuo Qian4a594052020-01-23 11:59:30 -08001393 break;
Hall Liu27d24262020-09-18 19:04:59 -07001394 }
Shuo Qian4a594052020-01-23 11:59:30 -08001395
Hall Liu27d24262020-09-18 19:04:59 -07001396 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001397 request = (MainThreadRequest) msg.obj;
1398 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001399 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001400 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001401 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1402 request.argument).first;
1403 request.phone.setCallForwardingOption(
1404 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001405 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001406 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001407 callForwardingInfoToSet.getReason(),
1408 callForwardingInfoToSet.getNumber(),
1409 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1410 break;
Hall Liu27d24262020-09-18 19:04:59 -07001411 }
Shuo Qian4a594052020-01-23 11:59:30 -08001412
Hall Liu27d24262020-09-18 19:04:59 -07001413 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001414 ar = (AsyncResult) msg.obj;
1415 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001416 Consumer<Integer> callback =
1417 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1418 request.argument).second;
1419 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001420 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001421 int errorCode = TelephonyManager.CallForwardingInfoCallback
1422 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001423 if (ar.exception instanceof CommandException) {
1424 CommandException.Error error =
1425 ((CommandException) (ar.exception)).getCommandError();
1426 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001427 errorCode = TelephonyManager.CallForwardingInfoCallback
1428 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001429 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001430 errorCode = TelephonyManager.CallForwardingInfoCallback
1431 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001432 }
1433 }
1434 callback.accept(errorCode);
1435 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001436 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001437 }
Shuo Qian4a594052020-01-23 11:59:30 -08001438 break;
Hall Liu27d24262020-09-18 19:04:59 -07001439 }
Shuo Qian4a594052020-01-23 11:59:30 -08001440
Hall Liu27d24262020-09-18 19:04:59 -07001441 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001442 request = (MainThreadRequest) msg.obj;
1443 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1444 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1445 break;
Hall Liu27d24262020-09-18 19:04:59 -07001446 }
Shuo Qian4a594052020-01-23 11:59:30 -08001447
Hall Liu27d24262020-09-18 19:04:59 -07001448 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001449 ar = (AsyncResult) msg.obj;
1450 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001451 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001452 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001453 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001454 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001455 // Service Class is a bit mask per 3gpp 27.007.
1456 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001457 if (callForwardResults.length > 1
1458 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001459 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001460 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001461 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1462 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001463 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001464 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001465 }
1466 } else {
1467 if (ar.result == null) {
1468 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1469 }
1470 if (ar.exception != null) {
1471 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1472 }
1473 if (ar.exception instanceof CommandException) {
1474 CommandException.Error error =
1475 ((CommandException) (ar.exception)).getCommandError();
1476 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001477 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001478 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001479 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1480 callWaitingStatus =
1481 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001482 }
1483 }
1484 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001485 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001486 break;
Hall Liu27d24262020-09-18 19:04:59 -07001487 }
Shuo Qian4a594052020-01-23 11:59:30 -08001488
Hall Liu27d24262020-09-18 19:04:59 -07001489 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001490 request = (MainThreadRequest) msg.obj;
1491 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001492 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1493 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001494 break;
Hall Liu27d24262020-09-18 19:04:59 -07001495 }
Shuo Qian4a594052020-01-23 11:59:30 -08001496
Hall Liu27d24262020-09-18 19:04:59 -07001497 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001498 ar = (AsyncResult) msg.obj;
1499 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001500 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1501 Consumer<Integer> callback =
1502 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1503 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001504 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001505 if (ar.exception instanceof CommandException) {
1506 CommandException.Error error =
1507 ((CommandException) (ar.exception)).getCommandError();
1508 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1509 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001510 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1511 callback.accept(
1512 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001513 } else {
1514 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1515 }
1516 } else {
1517 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1518 }
1519 } else {
1520 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1521 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001522 }
Shuo Qian4a594052020-01-23 11:59:30 -08001523 break;
Hall Liu27d24262020-09-18 19:04:59 -07001524 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001525 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1526 ar = (AsyncResult) msg.obj;
1527 request = (MainThreadRequest) ar.userObj;
1528 CellNetworkScanResult cellScanResult;
1529 if (ar.exception == null && ar.result != null) {
1530 cellScanResult = new CellNetworkScanResult(
1531 CellNetworkScanResult.STATUS_SUCCESS,
1532 (List<OperatorInfo>) ar.result);
1533 } else {
1534 if (ar.result == null) {
1535 loge("getCellNetworkScanResults: Empty response");
1536 }
1537 if (ar.exception != null) {
1538 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1539 }
1540 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1541 if (ar.exception instanceof CommandException) {
1542 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001543 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001544 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1545 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1546 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1547 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1548 }
1549 }
1550 cellScanResult = new CellNetworkScanResult(errorCode, null);
1551 }
1552 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001553 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001554 break;
1555
1556 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1557 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001558 ManualNetworkSelectionArgument selArg =
1559 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001560 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1561 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001562 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1563 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001564 break;
1565
1566 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001567 ar = (AsyncResult) msg.obj;
1568 request = (MainThreadRequest) ar.userObj;
1569 if (ar.exception == null) {
1570 request.result = true;
1571 } else {
1572 request.result = false;
1573 loge("setNetworkSelectionModeManual " + ar.exception);
1574 }
1575 notifyRequester(request);
1576 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001577 break;
1578
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001579 case CMD_GET_MODEM_ACTIVITY_INFO:
1580 request = (MainThreadRequest) msg.obj;
1581 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001582 if (defaultPhone != null) {
1583 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001584 } else {
1585 ResultReceiver result = (ResultReceiver) request.argument;
1586 Bundle bundle = new Bundle();
1587 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001588 new ModemActivityInfo(0, 0, 0,
1589 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001590 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001591 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001592 break;
1593
Hall Liud0f208c2020-10-14 16:54:44 -07001594 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001595 ar = (AsyncResult) msg.obj;
1596 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001597 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001598 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001599 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001600 if (mLastModemActivityInfo == null) {
1601 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1602 mLastModemActivitySpecificInfo[0] =
1603 new ActivityStatsTechSpecificInfo(
1604 0,
1605 0,
1606 new int[ModemActivityInfo.getNumTxPowerLevels()],
1607 0);
1608 mLastModemActivityInfo =
1609 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1610 }
1611
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001612 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001613 // Update the last modem activity info and the result of the request.
1614 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1615 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001616 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001617 } else {
1618 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001619 }
Kai Shi917fdc62022-11-28 14:01:02 -08001620 // This is needed to decouple ret from mLastModemActivityInfo
1621 // We don't want to return mLastModemActivityInfo which is updated
1622 // inside mergeModemActivityInfo()
1623 ret = new ModemActivityInfo(
1624 mLastModemActivityInfo.getTimestampMillis(),
1625 mLastModemActivityInfo.getSleepTimeMillis(),
1626 mLastModemActivityInfo.getIdleTimeMillis(),
1627 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001628
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001629 } else {
1630 if (ar.result == null) {
1631 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001632 error = TelephonyManager.ModemActivityInfoException
1633 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001634 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001635 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001636 error = TelephonyManager.ModemActivityInfoException
1637 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001638 } else {
1639 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001640 error = TelephonyManager.ModemActivityInfoException
1641 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001642 }
1643 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001644 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001645 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001646 bundle.putParcelable(
1647 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001648 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001649 } else {
1650 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1651 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001652 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001653 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001654 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001655 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001656
Meng Wang1a7c35a2016-05-05 20:56:15 -07001657 case CMD_SET_ALLOWED_CARRIERS:
1658 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001659 CarrierRestrictionRules argument =
1660 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001661 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001662 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001663 break;
1664
1665 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1666 ar = (AsyncResult) msg.obj;
1667 request = (MainThreadRequest) ar.userObj;
1668 if (ar.exception == null && ar.result != null) {
1669 request.result = ar.result;
1670 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001671 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1672 if (ar.exception instanceof CommandException) {
1673 loge("setAllowedCarriers: CommandException: " + ar.exception);
1674 CommandException.Error error =
1675 ((CommandException) (ar.exception)).getCommandError();
1676 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1677 request.result =
1678 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1679 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001680 } else {
1681 loge("setAllowedCarriers: Unknown exception");
1682 }
1683 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001684 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001685 break;
1686
1687 case CMD_GET_ALLOWED_CARRIERS:
1688 request = (MainThreadRequest) msg.obj;
1689 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001690 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001691 break;
1692
1693 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1694 ar = (AsyncResult) msg.obj;
1695 request = (MainThreadRequest) ar.userObj;
1696 if (ar.exception == null && ar.result != null) {
1697 request.result = ar.result;
1698 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001699 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001700 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001701 if (ar.result == null) {
1702 loge("getAllowedCarriers: Empty response");
1703 } else if (ar.exception instanceof CommandException) {
1704 loge("getAllowedCarriers: CommandException: " +
1705 ar.exception);
1706 } else {
1707 loge("getAllowedCarriers: Unknown exception");
1708 }
1709 }
arunvoddud7401012022-12-15 16:08:12 +00001710 if (request.argument != null) {
1711 // This is for the implementation of carrierRestrictionStatus.
1712 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1713 Consumer<Integer> callback = callbackInfo.getConsumer();
1714 int callerCarrierId = callbackInfo.getCarrierId();
1715 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1716 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1717 CarrierRestrictionRules carrierRestrictionRules =
1718 (CarrierRestrictionRules) ar.result;
1719 int carrierId = -1;
1720 try {
1721 CarrierIdentifier carrierIdentifier =
1722 carrierRestrictionRules.getAllowedCarriers().get(0);
1723 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1724 carrierIdentifier);
1725 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1726 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1727 }
1728 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
1729 if (carrierId != -1 && callerCarrierId == carrierId && lockStatus
1730 == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001731 lockStatus = TelephonyManager
1732 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001733 }
1734 } else {
1735 Rlog.e(LOG_TAG,
1736 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1737 }
1738 callback.accept(lockStatus);
1739 } else {
1740 // This is for the implementation of getAllowedCarriers.
1741 notifyRequester(request);
1742 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001743 break;
1744
Nathan Haroldb3014052017-01-25 15:57:32 -08001745 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1746 ar = (AsyncResult) msg.obj;
1747 request = (MainThreadRequest) ar.userObj;
1748 if (ar.exception == null && ar.result != null) {
1749 request.result = ar.result;
1750 } else {
1751 request.result = new IllegalArgumentException(
1752 "Failed to retrieve Forbidden Plmns");
1753 if (ar.result == null) {
1754 loge("getForbiddenPlmns: Empty response");
1755 } else {
1756 loge("getForbiddenPlmns: Unknown exception");
1757 }
1758 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001759 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001760 break;
1761
1762 case CMD_GET_FORBIDDEN_PLMNS:
1763 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001764 uiccPort = getUiccPortFromRequest(request);
1765 if (uiccPort == null) {
1766 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001767 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001768 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001769 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001770 break;
1771 }
1772 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001773 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001774 if (uiccApp == null) {
1775 loge("getForbiddenPlmns() no app with specified type -- "
1776 + appType);
1777 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001778 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001779 break;
1780 } else {
1781 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1782 + " specified type -- " + appType);
1783 }
1784 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1785 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001786 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001787 break;
1788
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001789 case CMD_SWITCH_SLOTS:
1790 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001791 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001792 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001793 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001794 break;
1795
1796 case EVENT_SWITCH_SLOTS_DONE:
1797 ar = (AsyncResult) msg.obj;
1798 request = (MainThreadRequest) ar.userObj;
1799 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001800 notifyRequester(request);
1801 break;
1802 case CMD_GET_NETWORK_SELECTION_MODE:
1803 request = (MainThreadRequest) msg.obj;
1804 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1805 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1806 break;
1807
1808 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1809 ar = (AsyncResult) msg.obj;
1810 request = (MainThreadRequest) ar.userObj;
1811 if (ar.exception != null) {
1812 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1813 } else {
1814 int mode = ((int[]) ar.result)[0];
1815 if (mode == 0) {
1816 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1817 } else {
1818 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1819 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001820 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001821 notifyRequester(request);
1822 break;
1823 case CMD_GET_CDMA_ROAMING_MODE:
1824 request = (MainThreadRequest) msg.obj;
1825 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1826 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1827 break;
1828 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1829 ar = (AsyncResult) msg.obj;
1830 request = (MainThreadRequest) ar.userObj;
1831 if (ar.exception != null) {
1832 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1833 } else {
1834 request.result = ((int[]) ar.result)[0];
1835 }
1836 notifyRequester(request);
1837 break;
1838 case CMD_SET_CDMA_ROAMING_MODE:
1839 request = (MainThreadRequest) msg.obj;
1840 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1841 int mode = (int) request.argument;
1842 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1843 break;
1844 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1845 ar = (AsyncResult) msg.obj;
1846 request = (MainThreadRequest) ar.userObj;
1847 request.result = ar.exception == null;
1848 notifyRequester(request);
1849 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001850 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1851 request = (MainThreadRequest) msg.obj;
1852 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1853 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1854 break;
1855 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1856 ar = (AsyncResult) msg.obj;
1857 request = (MainThreadRequest) ar.userObj;
1858 if (ar.exception != null) {
1859 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1860 } else {
1861 request.result = ((int[]) ar.result)[0];
1862 }
1863 notifyRequester(request);
1864 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001865 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1866 request = (MainThreadRequest) msg.obj;
1867 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1868 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001869 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1870 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001871 break;
1872 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1873 ar = (AsyncResult) msg.obj;
1874 request = (MainThreadRequest) ar.userObj;
1875 request.result = ar.exception == null;
1876 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001877 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001878 case CMD_GET_ALL_CELL_INFO:
1879 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001880 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001881 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001882 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001883 case EVENT_GET_ALL_CELL_INFO_DONE:
1884 ar = (AsyncResult) msg.obj;
1885 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001886 // If a timeout occurs, the response will be null
1887 request.result = (ar.exception == null && ar.result != null)
1888 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001889 synchronized (request) {
1890 request.notifyAll();
1891 }
1892 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001893 case CMD_REQUEST_CELL_INFO_UPDATE:
1894 request = (MainThreadRequest) msg.obj;
1895 request.phone.requestCellInfoUpdate(request.workSource,
1896 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1897 break;
1898 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1899 ar = (AsyncResult) msg.obj;
1900 request = (MainThreadRequest) ar.userObj;
1901 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1902 try {
1903 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001904 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001905 cb.onError(
1906 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1907 ar.exception.getClass().getName(),
1908 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001909 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001910 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001911 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001912 } else {
1913 // use the result as returned
1914 cb.onCellInfo((List<CellInfo>) ar.result);
1915 }
1916 } catch (RemoteException re) {
1917 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1918 }
1919 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001920 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001921 request = (MainThreadRequest) msg.obj;
1922 WorkSource ws = (WorkSource) request.argument;
1923 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001924 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001925 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001926 }
1927 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001928 ar = (AsyncResult) msg.obj;
1929 request = (MainThreadRequest) ar.userObj;
1930 if (ar.exception == null) {
1931 request.result = ar.result;
1932 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001933 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001934 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001935 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001936 }
1937
1938 synchronized (request) {
1939 request.notifyAll();
1940 }
1941 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001942 }
chen xu6dac5ab2018-10-26 17:39:23 -07001943 case CMD_MODEM_REBOOT:
1944 request = (MainThreadRequest) msg.obj;
1945 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001946 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001947 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001948 case EVENT_CMD_MODEM_REBOOT_DONE:
1949 handleNullReturnEvent(msg, "rebootModem");
1950 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001951 case CMD_REQUEST_ENABLE_MODEM:
1952 request = (MainThreadRequest) msg.obj;
1953 boolean enable = (boolean) request.argument;
1954 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001955 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001956 PhoneConfigurationManager.getInstance()
1957 .enablePhone(request.phone, enable, onCompleted);
1958 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001959 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001960 ar = (AsyncResult) msg.obj;
1961 request = (MainThreadRequest) ar.userObj;
1962 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001963 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001964 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001965 if ((boolean) request.result) {
1966 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1967 updateModemStateMetrics();
1968 } else {
1969 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1970 + ar.exception);
1971 }
1972 notifyRequester(request);
1973 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001974 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001975 case CMD_GET_MODEM_STATUS:
1976 request = (MainThreadRequest) msg.obj;
1977 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1978 PhoneConfigurationManager.getInstance()
1979 .getPhoneStatusFromModem(request.phone, onCompleted);
1980 break;
1981 case EVENT_GET_MODEM_STATUS_DONE:
1982 ar = (AsyncResult) msg.obj;
1983 request = (MainThreadRequest) ar.userObj;
1984 int id = request.phone.getPhoneId();
1985 if (ar.exception == null && ar.result != null) {
1986 request.result = ar.result;
1987 //update the cache as modem status has changed
1988 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1989 (boolean) request.result);
1990 } else {
1991 // Return true if modem status cannot be retrieved. For most cases,
1992 // modem status is on. And for older version modems, GET_MODEM_STATUS
1993 // and disable modem are not supported. Modem is always on.
1994 // TODO: this should be fixed in R to support a third
1995 // status UNKNOWN b/131631629
1996 request.result = true;
1997 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1998 + ar.exception);
1999 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08002000 notifyRequester(request);
2001 break;
Hall Liu73f5d362020-01-20 13:42:00 -08002002 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
2003 request = (MainThreadRequest) msg.obj;
2004 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
2005 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
2006 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
2007 request.phone.setSystemSelectionChannels(args.first, onCompleted);
2008 break;
2009 }
2010 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
2011 ar = (AsyncResult) msg.obj;
2012 request = (MainThreadRequest) ar.userObj;
2013 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
2014 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
2015 args.second.accept(ar.exception == null);
2016 notifyRequester(request);
2017 break;
2018 }
Sarah Chin679c08a2020-11-18 13:39:35 -08002019 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
2020 request = (MainThreadRequest) msg.obj;
2021 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
2022 Phone phone = getPhoneFromRequest(request);
2023 if (phone != null) {
2024 phone.getSystemSelectionChannels(onCompleted);
2025 } else {
2026 loge("getSystemSelectionChannels: No phone object");
2027 request.result = new ArrayList<RadioAccessSpecifier>();
2028 notifyRequester(request);
2029 }
2030 break;
2031 }
2032 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
2033 ar = (AsyncResult) msg.obj;
2034 request = (MainThreadRequest) ar.userObj;
2035 if (ar.exception == null && ar.result != null) {
2036 request.result = ar.result;
2037 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08002038 request.result = new IllegalStateException(
2039 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08002040 if (ar.result == null) {
2041 loge("getSystemSelectionChannels: Empty response");
2042 } else {
2043 loge("getSystemSelectionChannels: Unknown exception");
2044 }
2045 }
2046 notifyRequester(request);
2047 break;
yincheng zhao2737e882019-09-06 17:06:54 -07002048 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
2049 ar = (AsyncResult) msg.obj;
2050 request = (MainThreadRequest) ar.userObj;
2051 if (ar.exception == null && ar.result != null) {
2052 request.result = ar.result;
2053 } else {
2054 request.result = -1;
2055 loge("Failed to set Forbidden Plmns");
2056 if (ar.result == null) {
2057 loge("setForbidenPlmns: Empty response");
2058 } else if (ar.exception != null) {
2059 loge("setForbiddenPlmns: Exception: " + ar.exception);
2060 request.result = -1;
2061 } else {
2062 loge("setForbiddenPlmns: Unknown exception");
2063 }
2064 }
2065 notifyRequester(request);
2066 break;
2067 case CMD_SET_FORBIDDEN_PLMNS:
2068 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002069 uiccPort = getUiccPortFromRequest(request);
2070 if (uiccPort == null) {
2071 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07002072 request.result = -1;
2073 notifyRequester(request);
2074 break;
2075 }
2076 Pair<Integer, List<String>> setFplmnsArgs =
2077 (Pair<Integer, List<String>>) request.argument;
2078 appType = setFplmnsArgs.first;
2079 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002080 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07002081 if (uiccApp == null) {
2082 loge("setForbiddenPlmns: no app with specified type -- " + appType);
2083 request.result = -1;
2084 loge("Failed to get UICC App");
2085 notifyRequester(request);
2086 } else {
2087 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
2088 ((SIMRecords) uiccApp.getIccRecords())
2089 .setForbiddenPlmns(onCompleted, fplmns);
2090 }
yinchengzhao4d163c02019-12-12 15:21:47 -08002091 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07002092 case CMD_ERASE_MODEM_CONFIG:
2093 request = (MainThreadRequest) msg.obj;
2094 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
2095 defaultPhone.eraseModemConfig(onCompleted);
2096 break;
2097 case EVENT_ERASE_MODEM_CONFIG_DONE:
2098 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07002099 break;
zoey chene02881a2019-12-30 16:11:23 +08002100
Kai Shif70f46f2021-03-03 13:59:46 -08002101 case CMD_ERASE_DATA_SHARED_PREFERENCES:
2102 request = (MainThreadRequest) msg.obj;
2103 request.result = defaultPhone.eraseDataInSharedPreferences();
2104 notifyRequester(request);
2105 break;
2106
zoey chene02881a2019-12-30 16:11:23 +08002107 case CMD_CHANGE_ICC_LOCK_PASSWORD:
2108 request = (MainThreadRequest) msg.obj;
2109 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
2110 Pair<String, String> changed = (Pair<String, String>) request.argument;
2111 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
2112 changed.first, changed.second, onCompleted);
2113 break;
2114 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
2115 ar = (AsyncResult) msg.obj;
2116 request = (MainThreadRequest) ar.userObj;
2117 if (ar.exception == null) {
2118 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002119 // If the operation is successful, update the PIN storage
2120 Pair<String, String> passwords = (Pair<String, String>) request.argument;
2121 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00002122 UiccController.getInstance().getPinStorage()
2123 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08002124 } else {
2125 request.result = msg.arg1;
2126 }
2127 notifyRequester(request);
2128 break;
2129
Michele Berionne5e411512020-11-13 02:36:59 +00002130 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002131 request = (MainThreadRequest) msg.obj;
2132 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2133 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2134 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2135 enabled.first, enabled.second, onCompleted);
2136 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002137 }
zoey chene02881a2019-12-30 16:11:23 +08002138 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2139 ar = (AsyncResult) msg.obj;
2140 request = (MainThreadRequest) ar.userObj;
2141 if (ar.exception == null) {
2142 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002143 // If the operation is successful, update the PIN storage
2144 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2145 int phoneId = getPhoneFromRequest(request).getPhoneId();
2146 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002147 UiccController.getInstance().getPinStorage()
2148 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002149 } else {
2150 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2151 }
zoey chene02881a2019-12-30 16:11:23 +08002152 } else {
2153 request.result = msg.arg1;
2154 }
Michele Berionne5e411512020-11-13 02:36:59 +00002155
2156
zoey chene02881a2019-12-30 16:11:23 +08002157 notifyRequester(request);
2158 break;
2159
Peter Wangdafb9ac2020-01-15 14:13:38 -08002160 case MSG_NOTIFY_USER_ACTIVITY:
2161 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002162 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002163 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2164 getDefaultPhone().getContext().sendBroadcastAsUser(
2165 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2166 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002167
2168 case CMD_SET_DATA_THROTTLING: {
2169 request = (MainThreadRequest) msg.obj;
2170 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2171 DataThrottlingRequest dataThrottlingRequest =
2172 (DataThrottlingRequest) request.argument;
2173 Phone phone = getPhoneFromRequest(request);
2174 if (phone != null) {
2175 phone.setDataThrottling(onCompleted,
2176 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2177 dataThrottlingRequest.getCompletionDurationMillis());
2178 } else {
2179 loge("setDataThrottling: No phone object");
2180 request.result =
2181 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2182 notifyRequester(request);
2183 }
2184
2185 break;
2186 }
2187 case EVENT_SET_DATA_THROTTLING_DONE:
2188 ar = (AsyncResult) msg.obj;
2189 request = (MainThreadRequest) ar.userObj;
2190
2191 if (ar.exception == null) {
2192 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2193 } else if (ar.exception instanceof CommandException) {
2194 loge("setDataThrottling: CommandException: " + ar.exception);
2195 CommandException.Error error =
2196 ((CommandException) (ar.exception)).getCommandError();
2197
2198 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2199 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002200 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002201 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2202 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002203 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2204 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002205 } else {
2206 request.result =
2207 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2208 }
2209 } else {
2210 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2211 }
2212 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2213 notifyRequester(request);
2214 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002215
2216 case CMD_SET_SIM_POWER: {
2217 request = (MainThreadRequest) msg.obj;
2218 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2219 request = (MainThreadRequest) msg.obj;
2220 int stateToSet =
2221 ((Pair<Integer, IIntegerConsumer>)
2222 request.argument).first;
2223 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2224 break;
2225 }
2226 case EVENT_SET_SIM_POWER_DONE: {
2227 ar = (AsyncResult) msg.obj;
2228 request = (MainThreadRequest) ar.userObj;
2229 IIntegerConsumer callback =
2230 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2231 if (ar.exception != null) {
2232 loge("setSimPower exception: " + ar.exception);
2233 int errorCode = TelephonyManager.CallForwardingInfoCallback
2234 .RESULT_ERROR_UNKNOWN;
2235 if (ar.exception instanceof CommandException) {
2236 CommandException.Error error =
2237 ((CommandException) (ar.exception)).getCommandError();
2238 if (error == CommandException.Error.SIM_ERR) {
2239 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2240 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2241 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2242 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2243 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2244 } else {
2245 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2246 }
2247 }
2248 try {
2249 callback.accept(errorCode);
2250 } catch (RemoteException e) {
2251 // Ignore if the remote process is no longer available to call back.
2252 Log.w(LOG_TAG, "setSimPower: callback not available.");
2253 }
2254 } else {
2255 try {
2256 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2257 } catch (RemoteException e) {
2258 // Ignore if the remote process is no longer available to call back.
2259 Log.w(LOG_TAG, "setSimPower: callback not available.");
2260 }
2261 }
2262 break;
2263 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002264 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2265 request = (MainThreadRequest) msg.obj;
2266
2267 final Phone phone = getPhoneFromRequest(request);
2268 if (phone == null || phone.getServiceStateTracker() == null) {
2269 request.result = new IllegalStateException("Phone or SST is null");
2270 notifyRequester(request);
2271 break;
2272 }
2273
2274 Pair<Integer, SignalStrengthUpdateRequest> pair =
2275 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2276 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2277 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002278 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002279 request.subId, pair.first /*callingUid*/,
2280 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002281 break;
2282 }
2283 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2284 ar = (AsyncResult) msg.obj;
2285 request = (MainThreadRequest) ar.userObj;
2286 // request.result will be the exception of ar if present, true otherwise.
2287 // Be cautious not to leave result null which will wait() forever
2288 request.result = ar.exception != null ? ar.exception : true;
2289 notifyRequester(request);
2290 break;
2291 }
2292 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2293 request = (MainThreadRequest) msg.obj;
2294
2295 Phone phone = getPhoneFromRequest(request);
2296 if (phone == null || phone.getServiceStateTracker() == null) {
2297 request.result = new IllegalStateException("Phone or SST is null");
2298 notifyRequester(request);
2299 break;
2300 }
2301
2302 Pair<Integer, SignalStrengthUpdateRequest> pair =
2303 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2304 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2305 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002306 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002307 request.subId, pair.first /*callingUid*/,
2308 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002309 break;
2310 }
2311 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2312 ar = (AsyncResult) msg.obj;
2313 request = (MainThreadRequest) ar.userObj;
2314 request.result = ar.exception != null ? ar.exception : true;
2315 notifyRequester(request);
2316 break;
2317 }
Jordan Liu109698e2020-11-24 14:50:34 -08002318
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002319 case CMD_GET_SLICING_CONFIG: {
2320 request = (MainThreadRequest) msg.obj;
2321 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2322 request.phone.getSlicingConfig(onCompleted);
2323 break;
2324 }
2325 case EVENT_GET_SLICING_CONFIG_DONE: {
2326 ar = (AsyncResult) msg.obj;
2327 request = (MainThreadRequest) ar.userObj;
2328 ResultReceiver result = (ResultReceiver) request.argument;
2329
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002330 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002331 Bundle bundle = new Bundle();
2332 int resultCode = 0;
2333 if (ar.exception != null) {
2334 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2335 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002336 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002337 } else if (ar.result == null) {
2338 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002339 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002340 } else {
2341 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002342 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2343 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002344 }
2345
2346 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002347 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002348 }
2349 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2350 result.send(resultCode, bundle);
2351 notifyRequester(request);
2352 break;
2353 }
2354
Sarah Chin71b3a852022-09-28 15:54:19 -07002355 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002356 request = (MainThreadRequest) msg.obj;
2357 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002358 PurchasePremiumCapabilityArgument arg =
2359 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin46355ba2022-11-01 23:51:16 -07002360 SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability(
Sarah Chinb8218c22023-01-04 13:35:29 -08002361 arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002362 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002363 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002364
Sarah Chin71b3a852022-09-28 15:54:19 -07002365 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002366 ar = (AsyncResult) msg.obj;
2367 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002368 PurchasePremiumCapabilityArgument arg =
2369 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002370 try {
2371 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002372 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002373 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002374 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002375 + ", result= "
2376 + TelephonyManager.convertPurchaseResultToString(result));
2377 } catch (RemoteException e) {
2378 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002379 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002380 + " failed: " + e;
2381 if (DBG) log(logStr);
2382 AnomalyReporter.reportAnomaly(
2383 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2384 }
2385 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002386 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002387
Michele Berionne5e411512020-11-13 02:36:59 +00002388 case CMD_PREPARE_UNATTENDED_REBOOT:
2389 request = (MainThreadRequest) msg.obj;
2390 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002391 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002392 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002393 notifyRequester(request);
2394 break;
2395
Sarah Chineccfbd12023-01-20 19:00:35 -08002396 case CMD_START_SATELLITE_POSITION_UPDATES: {
2397 request = (MainThreadRequest) msg.obj;
2398 onCompleted =
2399 obtainMessage(EVENT_START_SATELLITE_POSITION_UPDATES_DONE, request);
2400 Phone phone = getPhoneFromRequest(request);
2401 if (phone != null) {
2402 phone.startSatellitePositionUpdates(onCompleted);
2403 } else {
2404 loge("startSatellitePositionUpdates: No phone object");
Sarah Chinf75afa72023-02-01 01:32:19 -08002405 request.result =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002406 SatelliteManager.SATELLITE_SERVICE_INVALID_TELEPHONY_STATE;
Sarah Chineccfbd12023-01-20 19:00:35 -08002407 notifyRequester(request);
2408 }
2409 break;
2410 }
2411
2412 case EVENT_START_SATELLITE_POSITION_UPDATES_DONE: {
2413 ar = (AsyncResult) msg.obj;
2414 request = (MainThreadRequest) ar.userObj;
2415 if (ar.exception == null) {
2416 request.result = SatelliteManager.SATELLITE_SERVICE_SUCCESS;
2417 } else {
2418 request.result = SatelliteManager.SATELLITE_SERVICE_ERROR;
2419 if (ar.exception instanceof CommandException) {
2420 CommandException.Error error =
2421 ((CommandException) (ar.exception)).getCommandError();
2422 request.result = RILUtils.convertToSatelliteError(error);
2423 loge("startSatellitePositionUpdates CommandException: " + ar.exception);
2424 } else {
2425 loge("startSatellitePositionUpdates unknown exception:" + ar.exception);
2426 }
2427 }
2428 notifyRequester(request);
2429 break;
2430 }
2431
2432 case CMD_STOP_SATELLITE_POSITION_UPDATES: {
2433 request = (MainThreadRequest) msg.obj;
2434 onCompleted =
2435 obtainMessage(EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE, request);
2436 Phone phone = getPhoneFromRequest(request);
2437 if (phone != null) {
2438 phone.stopSatellitePositionUpdates(onCompleted);
2439 } else {
2440 loge("stopSatellitePositionUpdates: No phone object");
Sarah Chinf75afa72023-02-01 01:32:19 -08002441 request.result =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002442 SatelliteManager.SATELLITE_SERVICE_INVALID_TELEPHONY_STATE;
Sarah Chineccfbd12023-01-20 19:00:35 -08002443 notifyRequester(request);
2444 }
2445 break;
2446 }
2447
2448 case EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE: {
2449 ar = (AsyncResult) msg.obj;
2450 request = (MainThreadRequest) ar.userObj;
2451 if (ar.exception == null) {
2452 request.result = SatelliteManager.SATELLITE_SERVICE_SUCCESS;
2453 } else {
2454 request.result = SatelliteManager.SATELLITE_SERVICE_ERROR;
2455 if (ar.exception instanceof CommandException) {
2456 CommandException.Error error =
2457 ((CommandException) (ar.exception)).getCommandError();
2458 request.result = RILUtils.convertToSatelliteError(error);
2459 loge("stopSatellitePositionUpdates CommandException: " + ar.exception);
2460 } else {
2461 loge("stopSatellitePositionUpdates unknown exception:" + ar.exception);
2462 }
2463 }
2464 notifyRequester(request);
2465 break;
2466 }
2467
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002468 case CMD_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG: {
2469 request = (MainThreadRequest) msg.obj;
2470 onCompleted = obtainMessage(EVENT_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG_DONE,
2471 request);
2472 Phone phone = getPhoneFromRequest(request);
2473 if (phone != null) {
2474 phone.getMaxCharactersPerSatelliteTextMessage(onCompleted);
2475 } else {
2476 loge("getMaxCharactersPerSatelliteTextMessage: No phone object");
2477 request.result = SatelliteManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002478 .SATELLITE_SERVICE_INVALID_TELEPHONY_STATE;
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002479 notifyRequester(request);
2480 }
2481 break;
2482 }
2483
2484 case EVENT_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG_DONE: {
2485 ar = (AsyncResult) msg.obj;
2486 request = (MainThreadRequest) ar.userObj;
2487 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
2488 if (ar.exception != null) {
2489 request.result = SatelliteManager.SATELLITE_SERVICE_ERROR;
2490 if (ar.exception instanceof CommandException) {
2491 CommandException.Error error =
2492 ((CommandException) (ar.exception)).getCommandError();
2493 request.result = RILUtils.convertToSatelliteError(error);
2494 loge("getMaxCharactersPerSatelliteTextMessage: "
2495 + "CommandException: " + ar.exception);
2496 } else {
2497 loge("getMaxCharactersPerSatelliteTextMessage: "
2498 + "unknown exception:" + ar.exception);
2499 }
2500 } else if (ar.result == null) {
2501 request.result = SatelliteManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002502 .SATELLITE_SERVICE_INVALID_TELEPHONY_STATE;
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002503 loge("getMaxCharactersPerSatelliteTextMessage: result is null");
2504 } else {
2505 request.result = SatelliteManager.SATELLITE_SERVICE_SUCCESS;
2506 int maxCharLimit = ((int[]) ar.result)[0];
2507 if(DBG) log("getMaxCharactersPerSatelliteTextMessage "
2508 + "maxCharLimit:" + maxCharLimit);
2509 callback.accept(maxCharLimit);
2510 }
2511 notifyRequester(request);
2512 break;
2513 }
2514
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002515 case CMD_PROVISION_SATELLITE_SERVICE: {
2516 request = (MainThreadRequest) msg.obj;
2517 onCompleted =
2518 obtainMessage(EVENT_PROVISION_SATELLITE_SERVICE_DONE, request);
2519 Phone phone = getPhoneFromRequest(request);
2520 if (phone != null) {
2521 handleCmdProvisionSatelliteService(
2522 (ProvisionSatelliteServiceArgument) request.argument,
2523 phone, onCompleted);
2524 } else {
2525 loge("provisionSatelliteService: No phone object");
2526 request.result =
2527 SatelliteManager.SATELLITE_SERVICE_INVALID_TELEPHONY_STATE;
2528 notifyRequester(request);
2529 }
2530 break;
2531 }
2532
2533 case EVENT_PROVISION_SATELLITE_SERVICE_DONE: {
2534 ar = (AsyncResult) msg.obj;
2535 request = (MainThreadRequest) ar.userObj;
2536 if (ar.exception == null) {
2537 request.result = SatelliteManager.SATELLITE_SERVICE_SUCCESS;
2538 } else {
2539 request.result = SatelliteManager.SATELLITE_SERVICE_ERROR;
2540 if (ar.exception instanceof CommandException) {
2541 CommandException.Error error =
2542 ((CommandException) (ar.exception)).getCommandError();
2543 request.result = RILUtils.convertToSatelliteError(error);
2544 loge("provisionSatelliteService CommandException: " + ar.exception);
2545 } else {
2546 loge("provisionSatelliteService unknown exception:" + ar.exception);
2547 }
2548 }
2549 handleEventProvisionSatelliteServiceDone(request);
2550 notifyRequester(request);
2551 break;
2552 }
2553
2554 case CMD_CANCEL_PROVISION_SATELLITE_SERVICE: {
2555 request = (MainThreadRequest) msg.obj;
2556 onCompleted =
2557 obtainMessage(EVENT_CANCEL_PROVISION_SATELLITE_SERVICE_DONE, request);
2558 handleCmdCancelProvisionSatelliteService((int) request.argument, onCompleted);
2559 break;
2560 }
2561
2562 case EVENT_CANCEL_PROVISION_SATELLITE_SERVICE_DONE: {
2563 ar = (AsyncResult) msg.obj;
2564 request = (MainThreadRequest) ar.userObj;
2565
2566 if (ar.exception == null) {
2567 request.result = SatelliteManager.SATELLITE_SERVICE_SUCCESS;
2568 log("cancelProvisionSatelliteService succeeded for subId="
2569 + (int) request.argument);
2570 } else {
2571 request.result = SatelliteManager.SATELLITE_SERVICE_ERROR;
2572 if (ar.exception instanceof CommandException) {
2573 CommandException.Error error =
2574 ((CommandException) (ar.exception)).getCommandError();
2575 request.result = RILUtils.convertToSatelliteError(error);
2576 loge("cancelProvisionSatelliteService CommandException: "
2577 + ar.exception + ", error code:" + request.result);
2578 } else {
2579 loge("cancelProvisionSatelliteService unknown exception:"
2580 + ar.exception);
2581 }
2582 }
2583 notifyRequester(request);
2584 break;
2585 }
2586
2587 case CMD_GET_PROVISIONED_SATELLITE_FEATURES: {
2588 request = (MainThreadRequest) msg.obj;
2589 onCompleted = obtainMessage(EVENT_GET_PROVISIONED_SATELLITE_FEATURES_DONE,
2590 request);
2591 Phone phone = getPhoneFromRequest(request);
2592 if (phone != null) {
2593 phone.getProvisionedSatelliteFeatures(onCompleted);
2594 } else {
2595 loge("getProvisionedSatelliteFeatures: No phone object");
2596 request.result = SatelliteManager
2597 .SATELLITE_SERVICE_INVALID_TELEPHONY_STATE;
2598 notifyRequester(request);
2599 }
2600 break;
2601 }
2602
2603 case EVENT_GET_PROVISIONED_SATELLITE_FEATURES_DONE: {
2604 ar = (AsyncResult) msg.obj;
2605 request = (MainThreadRequest) ar.userObj;
2606 if (ar.exception != null) {
2607 request.result = SatelliteManager.SATELLITE_SERVICE_ERROR;
2608 if (ar.exception instanceof CommandException) {
2609 CommandException.Error error =
2610 ((CommandException) (ar.exception)).getCommandError();
2611 request.result = RILUtils.convertToSatelliteError(error);
2612 loge("getProvisionedSatelliteFeatures: "
2613 + "CommandException: " + ar.exception);
2614 } else {
2615 loge("getProvisionedSatelliteFeatures: "
2616 + "unknown exception:" + ar.exception);
2617 }
2618 } else if (ar.result == null) {
2619 request.result = SatelliteManager
2620 .SATELLITE_SERVICE_INVALID_TELEPHONY_STATE;
2621 loge("getProvisionedSatelliteFeatures: result is null");
2622 } else {
2623 request.result = SatelliteManager.SATELLITE_SERVICE_SUCCESS;
2624 int[] features = ((int[]) ar.result);
2625 if (DBG) {
2626 log("getProvisionedSatelliteFeatures features:"
2627 + Arrays.toString(features));
2628 }
2629 IIntArrayConsumer callback = (IIntArrayConsumer) request.argument;
2630 if (callback != null) {
2631 try {
2632 callback.accept(features);
2633 } catch (RemoteException ex) {
2634 log("getProvisionedSatelliteFeatures: remote callback"
2635 + " not available");
2636 }
2637 } else {
2638 log("getProvisionedSatelliteFeatures: callback is null");
2639 }
2640 }
2641 notifyRequester(request);
2642 break;
2643 }
2644
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002645 default:
2646 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2647 break;
2648 }
2649 }
Jake Hambye994d462014-02-03 13:10:13 -08002650
Pengquan Menga1bb6272018-09-06 09:59:22 -07002651 private void notifyRequester(MainThreadRequest request) {
2652 synchronized (request) {
2653 request.notifyAll();
2654 }
2655 }
2656
Jake Hambye994d462014-02-03 13:10:13 -08002657 private void handleNullReturnEvent(Message msg, String command) {
2658 AsyncResult ar = (AsyncResult) msg.obj;
2659 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2660 if (ar.exception == null) {
2661 request.result = true;
2662 } else {
2663 request.result = false;
2664 if (ar.exception instanceof CommandException) {
2665 loge(command + ": CommandException: " + ar.exception);
2666 } else {
2667 loge(command + ": Unknown exception");
2668 }
2669 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002670 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002671 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002672 }
2673
2674 /**
2675 * Posts the specified command to be executed on the main thread,
2676 * waits for the request to complete, and returns the result.
2677 * @see #sendRequestAsync
2678 */
2679 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002680 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2681 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002682 }
2683
2684 /**
2685 * Posts the specified command to be executed on the main thread,
2686 * waits for the request to complete, and returns the result.
2687 * @see #sendRequestAsync
2688 */
2689 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2690 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002691 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002692 }
2693
2694 /**
2695 * Posts the specified command to be executed on the main thread,
2696 * waits for the request to complete, and returns the result.
2697 * @see #sendRequestAsync
2698 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002699 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002700 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2701 }
2702
2703 /**
2704 * Posts the specified command to be executed on the main thread,
2705 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2706 * if not timeout or null otherwise.
2707 * @see #sendRequestAsync
2708 */
2709 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2710 long timeoutInMs) {
2711 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002712 }
2713
2714 /**
2715 * Posts the specified command to be executed on the main thread,
2716 * waits for the request to complete, and returns the result.
2717 * @see #sendRequestAsync
2718 */
Nathan Harold92bed182018-10-12 18:16:49 -07002719 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002720 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002721 }
2722
2723 /**
2724 * Posts the specified command to be executed on the main thread,
2725 * waits for the request to complete, and returns the result.
2726 * @see #sendRequestAsync
2727 */
2728 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002729 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2730 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002731 }
2732
2733 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002734 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2735 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2736 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002737 * @see #sendRequestAsync
2738 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002739 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2740 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002741 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2742 throw new RuntimeException("This method will deadlock if called from the main thread.");
2743 }
2744
Nathan Harold92bed182018-10-12 18:16:49 -07002745 MainThreadRequest request = null;
2746 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2747 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2748 } else if (phone != null) {
2749 request = new MainThreadRequest(argument, phone, workSource);
2750 } else {
2751 request = new MainThreadRequest(argument, subId, workSource);
2752 }
2753
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002754 Message msg = mMainThreadHandler.obtainMessage(command, request);
2755 msg.sendToTarget();
2756
Rambo Wang0f050d82021-02-12 11:43:36 -08002757
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002758 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002759 if (timeoutInMs >= 0) {
2760 // Wait for at least timeoutInMs before returning null request result
2761 long now = SystemClock.elapsedRealtime();
2762 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002763 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002764 try {
2765 request.wait(deadline - now);
2766 } catch (InterruptedException e) {
2767 // Do nothing, go back and check if request is completed or timeout
2768 } finally {
2769 now = SystemClock.elapsedRealtime();
2770 }
2771 }
2772 } else {
2773 // Wait for the request to complete
2774 while (request.result == null) {
2775 try {
2776 request.wait();
2777 } catch (InterruptedException e) {
2778 // Do nothing, go back and wait until the request is complete
2779 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002780 }
2781 }
2782 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002783 if (request.result == null) {
2784 Log.wtf(LOG_TAG,
2785 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2786 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002787 return request.result;
2788 }
2789
2790 /**
2791 * Asynchronous ("fire and forget") version of sendRequest():
2792 * Posts the specified command to be executed on the main thread, and
2793 * returns immediately.
2794 * @see #sendRequest
2795 */
2796 private void sendRequestAsync(int command) {
2797 mMainThreadHandler.sendEmptyMessage(command);
2798 }
2799
2800 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002801 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002802 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002803 */
2804 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002805 sendRequestAsync(command, argument, null, null);
2806 }
2807
2808 /**
2809 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2810 * @see {@link #sendRequest(int,Object)}
2811 */
2812 private void sendRequestAsync(
2813 int command, Object argument, Phone phone, WorkSource workSource) {
2814 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002815 Message msg = mMainThreadHandler.obtainMessage(command, request);
2816 msg.sendToTarget();
2817 }
2818
2819 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002820 * Initialize the singleton PhoneInterfaceManager instance.
2821 * This is only done once, at startup, from PhoneApp.onCreate().
2822 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002823 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002824 synchronized (PhoneInterfaceManager.class) {
2825 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002826 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002827 } else {
2828 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2829 }
2830 return sInstance;
2831 }
2832 }
2833
2834 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002835 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002836 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002837 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002838 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002839 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002840 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002841 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002842 mMainThreadHandler = new MainThreadHandler();
Jack Yue37dd262022-12-16 11:53:37 -08002843 if (!PhoneFactory.isSubscriptionManagerServiceEnabled()) {
2844 mSubscriptionController = SubscriptionController.getInstance();
2845 } else {
2846 mSubscriptionController = null;
2847 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002848 mTelephonySharedPreferences =
2849 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002850 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002851 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002852 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002853 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002854 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002855 publish();
arunvoddud7401012022-12-15 16:08:12 +00002856 CarrierAllowListInfo.loadInstance(mApp);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002857 }
2858
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002859 @VisibleForTesting
2860 public SharedPreferences getSharedPreferences() {
2861 return mTelephonySharedPreferences;
2862 }
2863
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002864 /**
2865 * Get the default phone for this device.
2866 */
2867 @VisibleForTesting
2868 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002869 Phone thePhone = getPhone(getDefaultSubscription());
2870 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2871 }
2872
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002873 private void publish() {
2874 if (DBG) log("publish: " + this);
2875
Peter Wangc035ce42020-01-08 21:00:22 -08002876 TelephonyFrameworkInitializer
2877 .getTelephonyServiceManager()
2878 .getTelephonyServiceRegisterer()
2879 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002880 }
2881
Stuart Scott584921c2015-01-15 17:10:34 -08002882 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002883 if (request.phone != null) {
2884 return request.phone;
2885 } else {
2886 return getPhoneFromSubId(request.subId);
2887 }
2888 }
2889
2890 private Phone getPhoneFromSubId(int subId) {
2891 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2892 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002893 }
2894
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002895 /**
2896 * Get phone object associated with a subscription.
2897 * Return default phone if phone object associated with subscription is null
2898 * @param subId - subscriptionId
2899 * @return phone object associated with a subscription or default phone if null.
2900 */
2901 private Phone getPhoneFromSubIdOrDefault(int subId) {
2902 Phone phone = getPhoneFromSubId(subId);
2903 if (phone == null) {
2904 phone = getDefaultPhone();
2905 }
2906 return phone;
2907 }
2908
Rambo Wange53e07d2022-05-10 13:01:13 -07002909 @Nullable
2910 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002911 Phone phone = getPhoneFromRequest(request);
2912 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002913 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002914 }
2915
Wink Saville36469e72014-06-11 15:17:00 -07002916 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002917 private Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002918 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002919 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002920
Kai Shif70f46f2021-03-03 13:59:46 -08002921 private void sendEraseModemConfig(@NonNull Phone phone) {
2922 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2923 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2924 }
2925
2926 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2927 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2928 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002929 }
2930
Peter Wang44b186e2020-01-13 23:33:09 -08002931 private boolean isImsAvailableOnDevice() {
2932 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2933 if (pm == null) {
2934 // For some reason package manger is not available.. This will fail internally anyway,
2935 // so do not throw error and allow.
2936 return true;
2937 }
2938 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2939 }
2940
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002941 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002942 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002943 }
2944
Wink Savilleb564aae2014-10-23 10:18:09 -07002945 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002946 if (DBG) log("dial: " + number);
2947 // No permission check needed here: This is just a wrapper around the
2948 // ACTION_DIAL intent, which is available to any app since it puts up
2949 // the UI before it does anything.
2950
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002951 final long identity = Binder.clearCallingIdentity();
2952 try {
2953 String url = createTelUrl(number);
2954 if (url == null) {
2955 return;
2956 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002957
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002958 // PENDING: should we just silently fail if phone is offhook or ringing?
2959 PhoneConstants.State state = mCM.getState(subId);
2960 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2961 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2962 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2963 mApp.startActivity(intent);
2964 }
2965 } finally {
2966 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002967 }
2968 }
2969
2970 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002971 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002972 }
2973
Wink Savilleb564aae2014-10-23 10:18:09 -07002974 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002975 if (DBG) log("call: " + number);
2976
2977 // This is just a wrapper around the ACTION_CALL intent, but we still
2978 // need to do a permission check since we're calling startActivity()
2979 // from the context of the phone app.
2980 enforceCallPermission();
2981
Jordan Liu1617b712019-07-10 15:06:26 -07002982 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002983 != AppOpsManager.MODE_ALLOWED) {
2984 return;
2985 }
2986
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002987 final long identity = Binder.clearCallingIdentity();
2988 try {
2989 String url = createTelUrl(number);
2990 if (url == null) {
2991 return;
2992 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002993
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002994 boolean isValid = false;
2995 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2996 if (slist != null) {
2997 for (SubscriptionInfo subInfoRecord : slist) {
2998 if (subInfoRecord.getSubscriptionId() == subId) {
2999 isValid = true;
3000 break;
3001 }
Wink Saville3ab207e2014-11-20 13:07:20 -08003002 }
Wink Saville08874612014-08-31 19:19:58 -07003003 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003004 if (!isValid) {
3005 return;
3006 }
Wink Saville08874612014-08-31 19:19:58 -07003007
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003008 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
3009 intent.putExtra(SUBSCRIPTION_KEY, subId);
3010 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3011 mApp.startActivity(intent);
3012 } finally {
3013 Binder.restoreCallingIdentity(identity);
3014 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003015 }
3016
Wink Savilleb564aae2014-10-23 10:18:09 -07003017 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003018 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07003019 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
3020 }
3021
Wink Savilleb564aae2014-10-23 10:18:09 -07003022 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003023 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07003024 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
3025 }
3026
Wink Savilleb564aae2014-10-23 10:18:09 -07003027 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003028 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003029
3030 final long identity = Binder.clearCallingIdentity();
3031 try {
Michele Berionne5e411512020-11-13 02:36:59 +00003032 Phone phone = getPhone(subId);
3033 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003034 checkSimPin.start();
3035 return checkSimPin.unlockSim(null, pin);
3036 } finally {
3037 Binder.restoreCallingIdentity(identity);
3038 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003039 }
3040
Wink Savilleb564aae2014-10-23 10:18:09 -07003041 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003042 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003043
3044 final long identity = Binder.clearCallingIdentity();
3045 try {
Michele Berionne5e411512020-11-13 02:36:59 +00003046 Phone phone = getPhone(subId);
3047 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003048 checkSimPuk.start();
3049 return checkSimPuk.unlockSim(puk, pin);
3050 } finally {
3051 Binder.restoreCallingIdentity(identity);
3052 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003053 }
3054
3055 /**
Wink Saville9de0f752013-10-22 19:04:03 -07003056 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003057 * a synchronous one.
3058 */
3059 private static class UnlockSim extends Thread {
3060
3061 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00003062 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003063
3064 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07003065 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
3066 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003067
3068 // For replies from SimCard interface
3069 private Handler mHandler;
3070
3071 // For async handler to identify request type
3072 private static final int SUPPLY_PIN_COMPLETE = 100;
3073
Michele Berionne5e411512020-11-13 02:36:59 +00003074 UnlockSim(int phoneId, IccCard simCard) {
3075 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003076 mSimCard = simCard;
3077 }
3078
3079 @Override
3080 public void run() {
3081 Looper.prepare();
3082 synchronized (UnlockSim.this) {
3083 mHandler = new Handler() {
3084 @Override
3085 public void handleMessage(Message msg) {
3086 AsyncResult ar = (AsyncResult) msg.obj;
3087 switch (msg.what) {
3088 case SUPPLY_PIN_COMPLETE:
3089 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
3090 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07003091 mRetryCount = msg.arg1;
3092 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08003093 CommandException.Error error = null;
3094 if (ar.exception instanceof CommandException) {
3095 error = ((CommandException) (ar.exception))
3096 .getCommandError();
3097 }
3098 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07003099 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08003100 } else if (error == CommandException.Error.ABORTED) {
3101 /* When UiccCardApp dispose, handle message and return
3102 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08003103 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07003104 } else {
3105 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
3106 }
3107 } else {
3108 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
3109 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003110 mDone = true;
3111 UnlockSim.this.notifyAll();
3112 }
3113 break;
3114 }
3115 }
3116 };
3117 UnlockSim.this.notifyAll();
3118 }
3119 Looper.loop();
3120 }
3121
3122 /*
3123 * Use PIN or PUK to unlock SIM card
3124 *
3125 * If PUK is null, unlock SIM card with PIN
3126 *
3127 * If PUK is not null, unlock SIM card with PUK and set PIN code
3128 */
Wink Saville9de0f752013-10-22 19:04:03 -07003129 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003130
3131 while (mHandler == null) {
3132 try {
3133 wait();
3134 } catch (InterruptedException e) {
3135 Thread.currentThread().interrupt();
3136 }
3137 }
3138 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
3139
3140 if (puk == null) {
3141 mSimCard.supplyPin(pin, callback);
3142 } else {
3143 mSimCard.supplyPuk(puk, pin, callback);
3144 }
3145
3146 while (!mDone) {
3147 try {
3148 Log.d(LOG_TAG, "wait for done");
3149 wait();
3150 } catch (InterruptedException e) {
3151 // Restore the interrupted status
3152 Thread.currentThread().interrupt();
3153 }
3154 }
3155 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07003156 int[] resultArray = new int[2];
3157 resultArray[0] = mResult;
3158 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00003159
3160 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00003161 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00003162 }
3163
Wink Saville9de0f752013-10-22 19:04:03 -07003164 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003165 }
3166 }
3167
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003168 /**
3169 * This method has been removed due to privacy and stability concerns.
3170 */
3171 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003172 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003173 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
3174 return;
Wink Saville36469e72014-06-11 15:17:00 -07003175 }
3176
Nathan Harold1f889d82020-06-04 17:05:26 -07003177 @Override
3178 public void updateServiceLocationWithPackageName(String callingPackage) {
3179 mApp.getSystemService(AppOpsManager.class)
3180 .checkPackage(Binder.getCallingUid(), callingPackage);
3181
Nathan Haroldf096d982020-11-18 17:18:06 -08003182 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07003183 if (targetSdk > android.os.Build.VERSION_CODES.R) {
3184 // Callers targeting S have no business invoking this method.
3185 return;
3186 }
3187
3188 LocationAccessPolicy.LocationPermissionResult locationResult =
3189 LocationAccessPolicy.checkLocationPermission(mApp,
3190 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3191 .setCallingPackage(callingPackage)
3192 .setCallingFeatureId(null)
3193 .setCallingPid(Binder.getCallingPid())
3194 .setCallingUid(Binder.getCallingUid())
3195 .setMethod("updateServiceLocation")
3196 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3197 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3198 .build());
3199 // Apps that lack location permission have no business calling this method;
3200 // however, because no permission was declared in the public API, denials must
3201 // all be "soft".
3202 switch (locationResult) {
3203 case DENIED_HARD: /* fall through */
3204 case DENIED_SOFT:
3205 return;
3206 }
3207
3208 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003209 final long identity = Binder.clearCallingIdentity();
3210 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07003211 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003212 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07003213 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003214 }
3215 } finally {
3216 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003217 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003218 }
3219
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003220 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003221 @Override
3222 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003223 return isRadioOnWithFeature(callingPackage, null);
3224 }
3225
3226
3227 @Override
3228 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
3229 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
3230 callingFeatureId);
3231 }
3232
3233 @Deprecated
3234 @Override
3235 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
3236 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07003237 }
3238
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003239 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003240 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
3241 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003242 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003243 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003244 return false;
3245 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003246
3247 final long identity = Binder.clearCallingIdentity();
3248 try {
3249 return isRadioOnForSubscriber(subId);
3250 } finally {
3251 Binder.restoreCallingIdentity(identity);
3252 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003253 }
3254
3255 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003256 final long identity = Binder.clearCallingIdentity();
3257 try {
3258 final Phone phone = getPhone(subId);
3259 if (phone != null) {
3260 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
3261 } else {
3262 return false;
3263 }
3264 } finally {
3265 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003266 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003267 }
3268
3269 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003270 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003271 }
Wink Saville36469e72014-06-11 15:17:00 -07003272
Wink Savilleb564aae2014-10-23 10:18:09 -07003273 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003274 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003275
3276 final long identity = Binder.clearCallingIdentity();
3277 try {
3278 final Phone phone = getPhone(subId);
3279 if (phone != null) {
3280 phone.setRadioPower(!isRadioOnForSubscriber(subId));
3281 }
3282 } finally {
3283 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003284 }
Wink Saville36469e72014-06-11 15:17:00 -07003285 }
3286
3287 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003288 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07003289 }
3290
Wink Savilleb564aae2014-10-23 10:18:09 -07003291 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07003292 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003293
3294 final long identity = Binder.clearCallingIdentity();
3295 try {
3296 final Phone phone = getPhone(subId);
3297 if (phone == null) {
3298 return false;
3299 }
3300 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
3301 toggleRadioOnOffForSubscriber(subId);
3302 }
3303 return true;
3304 } finally {
3305 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003306 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003307 }
Wink Saville36469e72014-06-11 15:17:00 -07003308
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003309 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08003310 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003311 /*
3312 * If any of the Radios are available, it will need to be
3313 * shutdown. So return true if any Radio is available.
3314 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003315 final long identity = Binder.clearCallingIdentity();
3316 try {
3317 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3318 Phone phone = PhoneFactory.getPhone(i);
3319 if (phone != null && phone.isRadioAvailable()) return true;
3320 }
3321 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
3322 return false;
3323 } finally {
3324 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003325 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003326 }
3327
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003328 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003329 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003330 enforceModifyPermission();
3331
3332 final long identity = Binder.clearCallingIdentity();
3333 try {
3334 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3335 logv("Shutting down Phone " + i);
3336 shutdownRadioUsingPhoneId(i);
3337 }
3338 } finally {
3339 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003340 }
3341 }
3342
3343 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003344 Phone phone = PhoneFactory.getPhone(phoneId);
3345 if (phone != null && phone.isRadioAvailable()) {
3346 phone.shutdownRadio();
3347 }
3348 }
3349
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003350 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07003351 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003352
Ling Ma83dc5ea2023-01-12 15:06:04 -08003353 if (!turnOn) {
3354 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3355 }
3356
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003357 final long identity = Binder.clearCallingIdentity();
3358 try {
3359 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3360 if (defaultPhone != null) {
3361 defaultPhone.setRadioPower(turnOn);
3362 return true;
3363 } else {
3364 loge("There's no default phone.");
3365 return false;
3366 }
3367 } finally {
3368 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003369 }
Wink Saville36469e72014-06-11 15:17:00 -07003370 }
3371
Wink Savilleb564aae2014-10-23 10:18:09 -07003372 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003373 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003374
Ling Ma83dc5ea2023-01-12 15:06:04 -08003375 if (!turnOn) {
3376 log("setRadioPowerForSubscriber off: subId=" + subId
3377 + ",callingPackage=" + getCurrentPackageName());
3378 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003379 final long identity = Binder.clearCallingIdentity();
3380 try {
3381 final Phone phone = getPhone(subId);
3382 if (phone != null) {
3383 phone.setRadioPower(turnOn);
3384 return true;
3385 } else {
3386 return false;
3387 }
3388 } finally {
3389 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003390 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003391 }
3392
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003393 /**
3394 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3395 * no reason to power it off. When any of the voters want to power it off, it will be turned
3396 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3397 * powering it off, and these radio off votes will be cleared.
3398 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3399 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3400 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3401 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3402 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3403 * check its vote.
3404 *
3405 * @param subId The subscription ID.
3406 * @param reason The reason for powering off radio.
3407 * @return true on success and false on failure.
3408 */
3409 public boolean requestRadioPowerOffForReason(int subId,
3410 @TelephonyManager.RadioPowerReason int reason) {
3411 enforceModifyPermission();
3412
Ling Ma83dc5ea2023-01-12 15:06:04 -08003413 log("requestRadioPowerOffForReason: subId=" + subId
3414 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003415 final long identity = Binder.clearCallingIdentity();
3416 try {
3417 final Phone phone = getPhone(subId);
3418 if (phone != null) {
3419 phone.setRadioPowerForReason(false, reason);
3420 return true;
3421 } else {
3422 return false;
3423 }
3424 } finally {
3425 Binder.restoreCallingIdentity(identity);
3426 }
3427 }
3428
3429 /**
3430 * Remove the vote on powering off the radio for a reason, as requested by
3431 * {@link requestRadioPowerOffForReason}.
3432 *
3433 * @param subId The subscription ID.
3434 * @param reason The reason for powering off radio.
3435 * @return true on success and false on failure.
3436 */
3437 public boolean clearRadioPowerOffForReason(int subId,
3438 @TelephonyManager.RadioPowerReason int reason) {
3439 enforceModifyPermission();
3440
3441 final long identity = Binder.clearCallingIdentity();
3442 try {
3443 final Phone phone = getPhone(subId);
3444 if (phone != null) {
3445 phone.setRadioPowerForReason(true, reason);
3446 return true;
3447 } else {
3448 return false;
3449 }
3450 } finally {
3451 Binder.restoreCallingIdentity(identity);
3452 }
3453 }
3454
3455 /**
3456 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3457 *
3458 * @param subId The subscription ID.
3459 * @param callingPackage The package making the call.
3460 * @param callingFeatureId The feature in the package.
3461 * @return List of reasons for powering off radio.
3462 */
3463 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3464 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3465
3466 final long identity = Binder.clearCallingIdentity();
3467 List result = new ArrayList();
3468 try {
3469 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3470 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3471 return result;
3472 }
3473
3474 final Phone phone = getPhone(subId);
3475 if (phone != null) {
3476 result.addAll(phone.getRadioPowerOffReasons());
3477 }
3478 } finally {
3479 Binder.restoreCallingIdentity(identity);
3480 }
3481 return result;
3482 }
3483
Wink Saville36469e72014-06-11 15:17:00 -07003484 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003485 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003486 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003487 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003488
3489 final long identity = Binder.clearCallingIdentity();
3490 try {
Jack Yu285100e2022-12-02 22:48:35 -08003491 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003492 final Phone phone = getPhone(subId);
3493 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003494 phone.getDataSettingsManager().setDataEnabled(
3495 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003496 return true;
3497 } else {
3498 return false;
3499 }
3500 } finally {
3501 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003502 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003503 }
3504
Wink Saville36469e72014-06-11 15:17:00 -07003505 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003506 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003507 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003508 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003509
3510 final long identity = Binder.clearCallingIdentity();
3511 try {
Jack Yu285100e2022-12-02 22:48:35 -08003512 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003513 final Phone phone = getPhone(subId);
3514 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003515 phone.getDataSettingsManager().setDataEnabled(
3516 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003517 return true;
3518 } else {
3519 return false;
3520 }
3521 } finally {
3522 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003523 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003524 }
3525
Sanket Padawe356d7632015-06-22 14:03:32 -07003526 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003527 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003528 final long identity = Binder.clearCallingIdentity();
3529 try {
3530 final Phone phone = getPhone(subId);
3531 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003532 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003533 } else {
3534 return false;
3535 }
3536 } finally {
3537 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003538 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003539 }
3540
3541 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003542 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003543 }
3544
pkanwarae03a6b2016-11-06 20:37:09 -08003545 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003546 enforceCallPermission();
3547
3548 final long identity = Binder.clearCallingIdentity();
3549 try {
3550 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3551 return;
3552 }
3553 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3554 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3555 } finally {
3556 Binder.restoreCallingIdentity(identity);
3557 }
pkanwar32d516d2016-10-14 19:37:38 -07003558 };
3559
Wink Savilleb564aae2014-10-23 10:18:09 -07003560 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003561 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003562
3563 final long identity = Binder.clearCallingIdentity();
3564 try {
3565 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3566 return false;
3567 }
3568 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3569 } finally {
3570 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003571 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003572 }
3573
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003574 /**
3575 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3576 * tag on getCallState Binder call.
3577 */
3578 @Deprecated
3579 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003580 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003581 if (CompatChanges.isChangeEnabled(
3582 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3583 Binder.getCallingUid())) {
3584 // Do not allow this API to be called on API version 31+, it should only be
3585 // called on old apps using this Binder call directly.
3586 throw new SecurityException("This method can only be used for applications "
3587 + "targeting API version 30 or less.");
3588 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003589 final long identity = Binder.clearCallingIdentity();
3590 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003591 Phone phone = getPhone(getDefaultSubscription());
3592 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3593 PhoneConstantConversions.convertCallState(phone.getState());
3594 } finally {
3595 Binder.restoreCallingIdentity(identity);
3596 }
3597 }
3598
3599 @Override
3600 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3601 if (CompatChanges.isChangeEnabled(
3602 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3603 Binder.getCallingUid())) {
3604 // Check READ_PHONE_STATE for API version 31+
3605 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3606 featureId, "getCallStateForSubscription")) {
3607 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3608 + "targeting API level 31+.");
3609 }
3610 }
3611 final long identity = Binder.clearCallingIdentity();
3612 try {
3613 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003614 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3615 PhoneConstantConversions.convertCallState(phone.getState());
3616 } finally {
3617 Binder.restoreCallingIdentity(identity);
3618 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003619 }
3620
Sanket Padawe356d7632015-06-22 14:03:32 -07003621 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003622 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003623 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003624 }
3625
3626 @Override
3627 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003628 final long identity = Binder.clearCallingIdentity();
3629 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003630 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003631 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003632 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003633 } else {
3634 return PhoneConstantConversions.convertDataState(
3635 PhoneConstants.DataState.DISCONNECTED);
3636 }
3637 } finally {
3638 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003639 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003640 }
3641
Sanket Padawe356d7632015-06-22 14:03:32 -07003642 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003643 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003644 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003645 }
3646
3647 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003648 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003649 final long identity = Binder.clearCallingIdentity();
3650 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003651 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003652 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003653 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003654 } else {
3655 return TelephonyManager.DATA_ACTIVITY_NONE;
3656 }
3657 } finally {
3658 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003659 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003660 }
3661
3662 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003663 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003664 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003665 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003666
3667 LocationAccessPolicy.LocationPermissionResult locationResult =
3668 LocationAccessPolicy.checkLocationPermission(mApp,
3669 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3670 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003671 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003672 .setCallingPid(Binder.getCallingPid())
3673 .setCallingUid(Binder.getCallingUid())
3674 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003675 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003676 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3677 .build());
3678 switch (locationResult) {
3679 case DENIED_HARD:
3680 throw new SecurityException("Not allowed to access cell location");
3681 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003682 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3683 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003684 }
3685
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003686 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003687 final long identity = Binder.clearCallingIdentity();
3688 try {
3689 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003690 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003691 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003692 } finally {
3693 Binder.restoreCallingIdentity(identity);
3694 }
Svetoslav64fad262015-04-14 14:35:21 -07003695 }
3696
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003697 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003698 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003699 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3700 // registered cell info, so return a NULL country instead.
3701 final long identity = Binder.clearCallingIdentity();
3702 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003703 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3704 // Get default phone in this case.
3705 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3706 }
Jack Yu285100e2022-12-02 22:48:35 -08003707 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003708 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003709 if (phone == null) return "";
3710 ServiceStateTracker sst = phone.getServiceStateTracker();
3711 if (sst == null) return "";
3712 LocaleTracker lt = sst.getLocaleTracker();
3713 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003714 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003715 } finally {
3716 Binder.restoreCallingIdentity(identity);
3717 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003718 }
3719
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003720 /**
3721 * This method was removed due to potential issues caused by performing partial
3722 * updates of service state, and lack of a credible use case.
3723 *
3724 * This has the ability to break the telephony implementation by disabling notification of
3725 * changes in device connectivity. DO NOT USE THIS!
3726 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003727 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003728 public void enableLocationUpdates() {
3729 mApp.enforceCallingOrSelfPermission(
3730 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003731 }
3732
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003733 /**
3734 * This method was removed due to potential issues caused by performing partial
3735 * updates of service state, and lack of a credible use case.
3736 *
3737 * This has the ability to break the telephony implementation by disabling notification of
3738 * changes in device connectivity. DO NOT USE THIS!
3739 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003740 @Override
3741 public void disableLocationUpdates() {
3742 mApp.enforceCallingOrSelfPermission(
3743 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003744 }
3745
3746 @Override
3747 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003748 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3749 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003750 try {
3751 mApp.getSystemService(AppOpsManager.class)
3752 .checkPackage(Binder.getCallingUid(), callingPackage);
3753 } catch (SecurityException e) {
3754 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3755 throw e;
3756 }
3757
Nathan Haroldf096d982020-11-18 17:18:06 -08003758 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003759 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3760 throw new SecurityException(
3761 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3762 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003763
Jordan Liu1617b712019-07-10 15:06:26 -07003764 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003765 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3766 return null;
3767 }
Svetoslav64fad262015-04-14 14:35:21 -07003768
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003769 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003770
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003771 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003772 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003773
Nathan Haroldf180aac2018-06-01 18:43:55 -07003774 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3775 for (CellInfo ci : info) {
3776 if (ci instanceof CellInfoGsm) {
3777 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3778 } else if (ci instanceof CellInfoWcdma) {
3779 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3780 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003781 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003782 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003783 }
3784
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003785 private List<CellInfo> getCachedCellInfo() {
3786 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3787 for (Phone phone : PhoneFactory.getPhones()) {
3788 List<CellInfo> info = phone.getAllCellInfo();
3789 if (info != null) cellInfos.addAll(info);
3790 }
3791 return cellInfos;
3792 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003793
3794 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003795 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003796 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003797 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003798
3799 LocationAccessPolicy.LocationPermissionResult locationResult =
3800 LocationAccessPolicy.checkLocationPermission(mApp,
3801 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3802 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003803 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003804 .setCallingPid(Binder.getCallingPid())
3805 .setCallingUid(Binder.getCallingUid())
3806 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003807 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003808 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3809 .build());
3810 switch (locationResult) {
3811 case DENIED_HARD:
3812 throw new SecurityException("Not allowed to access cell info");
3813 case DENIED_SOFT:
3814 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003815 }
3816
Nathan Haroldf096d982020-11-18 17:18:06 -08003817 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003818 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3819 return getCachedCellInfo();
3820 }
3821
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003822 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003823 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003824 final long identity = Binder.clearCallingIdentity();
3825 try {
3826 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3827 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003828 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003829 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003830 if (info != null) cellInfos.addAll(info);
3831 }
3832 return cellInfos;
3833 } finally {
3834 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003835 }
3836 }
3837
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003838 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003839 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3840 String callingFeatureId) {
3841 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3842 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003843 }
3844
3845 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003846 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3847 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003848 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003849 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003850 }
3851
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003852 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3853 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003854 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003855 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003856
3857 LocationAccessPolicy.LocationPermissionResult locationResult =
3858 LocationAccessPolicy.checkLocationPermission(mApp,
3859 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3860 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003861 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003862 .setCallingPid(Binder.getCallingPid())
3863 .setCallingUid(Binder.getCallingUid())
3864 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003865 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3866 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003867 .build());
3868 switch (locationResult) {
3869 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003870 if (TelephonyPermissions
3871 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003872 // Safetynet logging for b/154934934
3873 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3874 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003875 throw new SecurityException("Not allowed to access cell info");
3876 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003877 if (TelephonyPermissions
3878 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003879 // Safetynet logging for b/154934934
3880 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3881 }
Nathan Harold5320c422019-05-09 10:26:08 -07003882 try {
3883 cb.onCellInfo(new ArrayList<CellInfo>());
3884 } catch (RemoteException re) {
3885 // Drop without consequences
3886 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003887 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003888 }
3889
Nathan Harolda939a962019-05-09 10:13:47 -07003890
3891 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003892 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3893
3894 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3895 }
3896
3897 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003898 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003899 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003900 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003901
3902 final long identity = Binder.clearCallingIdentity();
3903 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003904 Phone phone = getPhone(subId);
3905 if (phone == null) {
3906 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3907 } else {
3908 phone.setCellInfoListRate(rateInMillis, workSource);
3909 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003910 } finally {
3911 Binder.restoreCallingIdentity(identity);
3912 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003913 }
3914
Shishir Agrawala9f32182016-04-12 12:00:16 -07003915 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003916 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003917 Phone phone = PhoneFactory.getPhone(slotIndex);
3918 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003919 return null;
3920 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003921 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003922 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003923 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003924 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003925 return null;
3926 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003927
3928 final long identity = Binder.clearCallingIdentity();
3929 try {
3930 return phone.getImei();
3931 } finally {
3932 Binder.restoreCallingIdentity(identity);
3933 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003934 }
3935
3936 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003937 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3938 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3939 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3940 callingFeatureId, "getPrimaryImei")) {
3941 throw new SecurityException("Caller does not have permission");
3942 }
3943 final long identity = Binder.clearCallingIdentity();
3944 try {
3945 for (Phone phone : PhoneFactory.getPhones()) {
3946 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3947 return phone.getImei();
3948 }
3949 }
3950 throw new UnsupportedOperationException("Operation not supported");
3951 } finally {
3952 Binder.restoreCallingIdentity(identity);
3953 }
3954 }
3955
3956 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003957 public String getTypeAllocationCodeForSlot(int slotIndex) {
3958 Phone phone = PhoneFactory.getPhone(slotIndex);
3959 String tac = null;
3960 if (phone != null) {
3961 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003962 try {
3963 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3964 } catch (IndexOutOfBoundsException e) {
3965 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3966 return null;
3967 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003968 }
3969 return tac;
3970 }
3971
3972 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003973 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003974 try {
3975 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3976 } catch (SecurityException se) {
3977 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3978 throw new SecurityException("Package " + callingPackage + " does not belong to "
3979 + Binder.getCallingUid());
3980 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003981 Phone phone = PhoneFactory.getPhone(slotIndex);
3982 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003983 return null;
3984 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003985
Jeff Davidson913390f2018-02-23 17:11:49 -08003986 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003987 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003988 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003989 return null;
3990 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003991
3992 final long identity = Binder.clearCallingIdentity();
3993 try {
3994 return phone.getMeid();
3995 } finally {
3996 Binder.restoreCallingIdentity(identity);
3997 }
Jack Yu2af8d712017-03-15 17:14:14 -07003998 }
3999
4000 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00004001 public String getManufacturerCodeForSlot(int slotIndex) {
4002 Phone phone = PhoneFactory.getPhone(slotIndex);
4003 String manufacturerCode = null;
4004 if (phone != null) {
4005 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07004006 try {
4007 manufacturerCode =
4008 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
4009 } catch (IndexOutOfBoundsException e) {
4010 Log.e(LOG_TAG, "MEID length shorter than upper index.");
4011 return null;
4012 }
David Kelly5e06a7f2018-03-12 14:10:59 +00004013 }
4014 return manufacturerCode;
4015 }
4016
4017 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004018 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
4019 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004020 Phone phone = PhoneFactory.getPhone(slotIndex);
4021 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004022 return null;
4023 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004024 int subId = phone.getSubId();
4025 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004026 mApp, subId, callingPackage, callingFeatureId,
4027 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004028 return null;
4029 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004030
4031 final long identity = Binder.clearCallingIdentity();
4032 try {
4033 return phone.getDeviceSvn();
4034 } finally {
4035 Binder.restoreCallingIdentity(identity);
4036 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07004037 }
4038
fionaxu43304da2017-11-27 22:51:16 -08004039 @Override
4040 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004041 final long identity = Binder.clearCallingIdentity();
4042 try {
4043 final Phone phone = getPhone(subId);
4044 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
4045 } finally {
4046 Binder.restoreCallingIdentity(identity);
4047 }
fionaxu43304da2017-11-27 22:51:16 -08004048 }
4049
4050 @Override
4051 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004052 final long identity = Binder.clearCallingIdentity();
4053 try {
4054 final Phone phone = getPhone(subId);
4055 return phone == null ? null : phone.getCarrierName();
4056 } finally {
4057 Binder.restoreCallingIdentity(identity);
4058 }
fionaxu43304da2017-11-27 22:51:16 -08004059 }
4060
calvinpanffe225e2018-11-01 19:43:06 +08004061 @Override
chen xu0026ca62019-03-06 15:28:50 -08004062 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08004063 final long identity = Binder.clearCallingIdentity();
4064 try {
4065 final Phone phone = getPhone(subId);
4066 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08004067 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08004068 } finally {
4069 Binder.restoreCallingIdentity(identity);
4070 }
4071 }
4072
4073 @Override
chen xu0026ca62019-03-06 15:28:50 -08004074 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08004075 final long identity = Binder.clearCallingIdentity();
4076 try {
4077 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08004078 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08004079 } finally {
4080 Binder.restoreCallingIdentity(identity);
4081 }
4082 }
4083
chen xu651eec72018-11-11 19:03:44 -08004084 @Override
chen xu864e11c2018-12-06 22:10:03 -08004085 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
4086 if (!isSubscriptionMccMnc) {
4087 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
4088 }
chen xu651eec72018-11-11 19:03:44 -08004089 final Phone phone = PhoneFactory.getPhone(slotIndex);
4090 if (phone == null) {
4091 return TelephonyManager.UNKNOWN_CARRIER_ID;
4092 }
4093 final long identity = Binder.clearCallingIdentity();
4094 try {
4095 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
4096 } finally {
4097 Binder.restoreCallingIdentity(identity);
4098 }
4099 }
4100
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004101 //
4102 // Internal helper methods.
4103 //
4104
Sanket Padaweee13a9b2016-03-08 17:30:28 -08004105 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07004106 * Make sure the caller is the calling package itself
4107 *
4108 * @throws SecurityException if the caller is not the calling package
4109 */
4110 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
4111 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07004112 PackageManager pm = mApp.getBaseContext().createContextAsUser(
4113 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07004114 try {
Grace Jiadbefca02021-04-26 15:13:31 -07004115 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07004116 } catch (PackageManager.NameNotFoundException e) {
4117 // packageUid is -1
4118 }
4119 if (packageUid != callingUid) {
4120 throw new SecurityException(message + ": Package " + callingPackage
4121 + " does not belong to " + callingUid);
4122 }
4123 }
4124
4125 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004126 * Make sure the caller has the MODIFY_PHONE_STATE permission.
4127 *
4128 * @throws SecurityException if the caller does not have the required permission
4129 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00004130 @VisibleForTesting
4131 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004132 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
4133 }
4134
Gil Cukierman1c0eb932022-12-06 22:28:24 +00004135 /**
arunvoddud7401012022-12-15 16:08:12 +00004136 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00004137 *
4138 * @throws SecurityException if the caller does not have the required permission
4139 */
4140 @VisibleForTesting
4141 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00004142 enforceReadPermission(null);
4143 }
4144
4145 /**
4146 * Make sure the caller has the READ_PHONE_STATE permissions.
4147 *
4148 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
4149 */
4150 @VisibleForTesting
4151 public void enforceReadPermission(String msg) {
4152 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00004153 }
4154
Shuo Qian3b6ee772019-11-13 17:43:31 -08004155 private void enforceActiveEmergencySessionPermission() {
4156 mApp.enforceCallingOrSelfPermission(
4157 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
4158 }
4159
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004160 /**
4161 * Make sure the caller has the CALL_PHONE permission.
4162 *
4163 * @throws SecurityException if the caller does not have the required permission
4164 */
4165 private void enforceCallPermission() {
4166 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
4167 }
4168
paulhu5a773602019-08-23 19:17:33 +08004169 private void enforceSettingsPermission() {
4170 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004171 }
4172
Michele Berionne5e411512020-11-13 02:36:59 +00004173 private void enforceRebootPermission() {
4174 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
4175 }
4176
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00004177 /**
4178 * Make sure the caller has SATELLITE_COMMUNICATION permission.
4179 * @param message - log message to print.
4180 * @throws SecurityException if the caller does not have the required permission
4181 */
4182 private void enforceSatelliteCommunicationPermission(String message) {
4183 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
4184 }
4185
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004186 private String createTelUrl(String number) {
4187 if (TextUtils.isEmpty(number)) {
4188 return null;
4189 }
4190
Jake Hambye994d462014-02-03 13:10:13 -08004191 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004192 }
4193
Ihab Awadf9e92732013-12-05 18:02:52 -08004194 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08004195 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004196 }
4197
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07004198 private static void logv(String msg) {
4199 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
4200 }
4201
Ihab Awadf9e92732013-12-05 18:02:52 -08004202 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004203 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
4204 }
4205
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004206 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004207 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07004208 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07004209 }
4210
Sanket Padawe356d7632015-06-22 14:03:32 -07004211 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004212 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004213 final long identity = Binder.clearCallingIdentity();
4214 try {
4215 final Phone phone = PhoneFactory.getPhone(slotIndex);
4216 if (phone == null) {
4217 return PhoneConstants.PHONE_TYPE_NONE;
4218 } else {
4219 return phone.getPhoneType();
4220 }
4221 } finally {
4222 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004223 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004224 }
4225
4226 /**
4227 * Returns the CDMA ERI icon index to display
4228 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004229 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004230 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
4231 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
4232 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004233 }
4234
Sanket Padawe356d7632015-06-22 14:03:32 -07004235 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004236 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
4237 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004238 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004239 mApp, subId, callingPackage, callingFeatureId,
4240 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004241 return -1;
4242 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004243
4244 final long identity = Binder.clearCallingIdentity();
4245 try {
4246 final Phone phone = getPhone(subId);
4247 if (phone != null) {
4248 return phone.getCdmaEriIconIndex();
4249 } else {
4250 return -1;
4251 }
4252 } finally {
4253 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004254 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004255 }
4256
4257 /**
4258 * Returns the CDMA ERI icon mode,
4259 * 0 - ON
4260 * 1 - FLASHING
4261 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004262 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004263 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
4264 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
4265 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004266 }
4267
Sanket Padawe356d7632015-06-22 14:03:32 -07004268 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004269 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
4270 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004271 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004272 mApp, subId, callingPackage, callingFeatureId,
4273 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004274 return -1;
4275 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004276
4277 final long identity = Binder.clearCallingIdentity();
4278 try {
4279 final Phone phone = getPhone(subId);
4280 if (phone != null) {
4281 return phone.getCdmaEriIconMode();
4282 } else {
4283 return -1;
4284 }
4285 } finally {
4286 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004287 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004288 }
4289
4290 /**
4291 * Returns the CDMA ERI text,
4292 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004293 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004294 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
4295 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4296 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004297 }
4298
Sanket Padawe356d7632015-06-22 14:03:32 -07004299 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004300 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4301 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004302 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004303 mApp, subId, callingPackage, callingFeatureId,
4304 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004305 return null;
4306 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004307
4308 final long identity = Binder.clearCallingIdentity();
4309 try {
4310 final Phone phone = getPhone(subId);
4311 if (phone != null) {
4312 return phone.getCdmaEriText();
4313 } else {
4314 return null;
4315 }
4316 } finally {
4317 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004318 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004319 }
4320
4321 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004322 * Returns the CDMA MDN.
4323 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004324 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004325 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004326 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4327 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004328
4329 final long identity = Binder.clearCallingIdentity();
4330 try {
4331 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004332 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004333 return phone.getLine1Number();
4334 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004335 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004336 return null;
4337 }
4338 } finally {
4339 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004340 }
4341 }
4342
4343 /**
4344 * Returns the CDMA MIN.
4345 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004346 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004347 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004348 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4349 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004350
4351 final long identity = Binder.clearCallingIdentity();
4352 try {
4353 final Phone phone = getPhone(subId);
4354 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4355 return phone.getCdmaMin();
4356 } else {
4357 return null;
4358 }
4359 } finally {
4360 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004361 }
4362 }
4363
Hall Liud892bec2018-11-30 14:51:45 -08004364 @Override
4365 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4366 INumberVerificationCallback callback, String callingPackage) {
4367 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4368 != PERMISSION_GRANTED) {
4369 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4370 }
4371 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4372
4373 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4374 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004375 throw new SecurityException("Calling package must be configured in the device config: "
4376 + "calling package: " + callingPackage
4377 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004378 }
4379
4380 if (range == null) {
4381 throw new NullPointerException("Range must be non-null");
4382 }
4383
4384 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004385 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004386
4387 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4388 }
4389
Junda Liuca05d5d2014-08-14 22:36:34 -07004390 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004391 * Returns true if CDMA provisioning needs to run.
4392 */
4393 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004394 final long identity = Binder.clearCallingIdentity();
4395 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004396 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004397 } finally {
4398 Binder.restoreCallingIdentity(identity);
4399 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004400 }
4401
4402 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004403 * Sets the voice mail number of a given subId.
4404 */
4405 @Override
4406 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004407 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4408 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004409
4410 final long identity = Binder.clearCallingIdentity();
4411 try {
4412 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4413 new Pair<String, String>(alphaTag, number), new Integer(subId));
4414 return success;
4415 } finally {
4416 Binder.restoreCallingIdentity(identity);
4417 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004418 }
4419
Ta-wei Yen87c49842016-05-13 21:19:52 -07004420 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004421 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4422 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004423 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4424 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004425 if (!TextUtils.equals(callingPackage, systemDialer)) {
4426 throw new SecurityException("caller must be system dialer");
4427 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004428
4429 final long identity = Binder.clearCallingIdentity();
4430 try {
4431 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4432 if (phoneAccountHandle == null) {
4433 return null;
4434 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004435 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004436 } finally {
4437 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004438 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004439 }
4440
4441 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004442 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4443 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004444 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004445 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004446 mApp, subId, callingPackage, callingFeatureId,
4447 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004448 return null;
4449 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004450
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004451 final long identity = Binder.clearCallingIdentity();
4452 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004453 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004454 } finally {
4455 Binder.restoreCallingIdentity(identity);
4456 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004457 }
4458
4459 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004460 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4461 VisualVoicemailSmsFilterSettings settings) {
4462 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004463
4464 final long identity = Binder.clearCallingIdentity();
4465 try {
4466 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004467 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004468 } finally {
4469 Binder.restoreCallingIdentity(identity);
4470 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004471 }
4472
4473 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004474 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4475 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004476
4477 final long identity = Binder.clearCallingIdentity();
4478 try {
4479 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004480 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004481 } finally {
4482 Binder.restoreCallingIdentity(identity);
4483 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004484 }
4485
4486 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004487 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4488 String callingPackage, int subId) {
4489 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004490
4491 final long identity = Binder.clearCallingIdentity();
4492 try {
4493 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004494 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004495 } finally {
4496 Binder.restoreCallingIdentity(identity);
4497 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004498 }
4499
4500 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004501 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004502 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004503
4504 final long identity = Binder.clearCallingIdentity();
4505 try {
4506 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004507 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004508 } finally {
4509 Binder.restoreCallingIdentity(identity);
4510 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004511 }
4512
4513 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004514 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4515 String callingAttributionTag, int subId, String number, int port, String text,
4516 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004517 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004518 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004519 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07004520 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004521 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4522 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004523 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004524
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004525 /**
fionaxu0152e512016-11-14 13:36:14 -08004526 * Sets the voice activation state of a given subId.
4527 */
4528 @Override
4529 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004530 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4531 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004532
4533 final long identity = Binder.clearCallingIdentity();
4534 try {
4535 final Phone phone = getPhone(subId);
4536 if (phone != null) {
4537 phone.setVoiceActivationState(activationState);
4538 } else {
4539 loge("setVoiceActivationState fails with invalid subId: " + subId);
4540 }
4541 } finally {
4542 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004543 }
4544 }
4545
4546 /**
4547 * Sets the data activation state of a given subId.
4548 */
4549 @Override
4550 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004551 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4552 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004553
4554 final long identity = Binder.clearCallingIdentity();
4555 try {
4556 final Phone phone = getPhone(subId);
4557 if (phone != null) {
4558 phone.setDataActivationState(activationState);
4559 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004560 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004561 }
4562 } finally {
4563 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004564 }
4565 }
4566
4567 /**
4568 * Returns the voice activation state of a given subId.
4569 */
4570 @Override
4571 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004572 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004573
fionaxu0152e512016-11-14 13:36:14 -08004574 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004575 final long identity = Binder.clearCallingIdentity();
4576 try {
4577 if (phone != null) {
4578 return phone.getVoiceActivationState();
4579 } else {
4580 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4581 }
4582 } finally {
4583 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004584 }
4585 }
4586
4587 /**
4588 * Returns the data activation state of a given subId.
4589 */
4590 @Override
4591 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004592 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004593
fionaxu0152e512016-11-14 13:36:14 -08004594 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004595 final long identity = Binder.clearCallingIdentity();
4596 try {
4597 if (phone != null) {
4598 return phone.getDataActivationState();
4599 } else {
4600 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4601 }
4602 } finally {
4603 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004604 }
4605 }
4606
4607 /**
Wink Saville36469e72014-06-11 15:17:00 -07004608 * Returns the unread count of voicemails for a subId
4609 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004610 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004611 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4612 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004613 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004614 mApp, subId, callingPackage, callingFeatureId,
4615 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004616 return 0;
4617 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004618 final long identity = Binder.clearCallingIdentity();
4619 try {
4620 final Phone phone = getPhone(subId);
4621 if (phone != null) {
4622 return phone.getVoiceMessageCount();
4623 } else {
4624 return 0;
4625 }
4626 } finally {
4627 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004628 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004629 }
4630
4631 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004632 * returns true, if the device is in a state where both voice and data
4633 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004634 */
4635 @Override
4636 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004637 final long identity = Binder.clearCallingIdentity();
4638 try {
4639 final Phone phone = getPhone(subId);
4640 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
4641 } finally {
4642 Binder.restoreCallingIdentity(identity);
4643 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004644 }
4645
4646 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004647 * Send the dialer code if called from the current default dialer or the caller has
4648 * carrier privilege.
4649 * @param inputCode The dialer code to send
4650 */
4651 @Override
4652 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004653 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004654 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004655 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4656 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004657 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004658 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004659 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004660 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004661
4662 final long identity = Binder.clearCallingIdentity();
4663 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004664 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004665 } finally {
4666 Binder.restoreCallingIdentity(identity);
4667 }
fionaxu235cc5e2017-03-06 22:25:57 -08004668 }
4669
Pengquan Menga1bb6272018-09-06 09:59:22 -07004670 @Override
4671 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004672 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004673 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4674 mApp, subId, "getNetworkSelectionMode");
shilufc958392020-01-20 11:36:01 -08004675 final long identity = Binder.clearCallingIdentity();
4676 try {
4677 if (!isActiveSubscription(subId)) {
4678 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4679 }
4680 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4681 } finally {
4682 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004683 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004684 }
4685
Brad Ebinger35c841c2018-10-01 10:40:55 -07004686 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004687 public boolean isInEmergencySmsMode() {
4688 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4689 final long identity = Binder.clearCallingIdentity();
4690 try {
4691 for (Phone phone : PhoneFactory.getPhones()) {
4692 if (phone.isInEmergencySmsMode()) {
4693 return true;
4694 }
4695 }
4696 } finally {
4697 Binder.restoreCallingIdentity(identity);
4698 }
4699 return false;
4700 }
4701
shilu366312e2019-12-17 09:28:10 -08004702 /**
4703 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4704 * @param subId The subscription to use to check the configuration.
4705 * @param c The callback that will be used to send the result.
4706 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004707 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004708 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4709 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004710 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004711 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004712
4713 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4714 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4715 "IMS not available on device.");
4716 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004717 final long token = Binder.clearCallingIdentity();
4718 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004719 int slotId = getSlotIndexOrException(subId);
4720 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004721
4722 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4723 if (controller != null) {
4724 ImsManager imsManager = controller.getImsManager(subId);
4725 if (imsManager != null) {
4726 imsManager.addRegistrationCallbackForSubscription(c, subId);
4727 } else {
4728 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4729 }
4730 } else {
4731 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4732 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004733 } catch (ImsException e) {
4734 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004735 } finally {
4736 Binder.restoreCallingIdentity(token);
4737 }
4738 }
4739
shilu366312e2019-12-17 09:28:10 -08004740 /**
4741 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4742 * @param subId The subscription to use to check the configuration.
4743 * @param c The callback that will be used to send the result.
4744 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004745 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004746 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004747 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004748 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004749 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4750 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4751 }
Meng Wangafbc5852019-09-19 17:37:13 -07004752 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004753
Meng Wangafbc5852019-09-19 17:37:13 -07004754 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004755 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4756 if (controller != null) {
4757 ImsManager imsManager = controller.getImsManager(subId);
4758 if (imsManager != null) {
4759 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4760 } else {
4761 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4762 + "is inactive, ignoring unregister.");
4763 // If the ImsManager is not valid, just return, since the callback
4764 // will already have been removed internally.
4765 }
4766 }
Meng Wangafbc5852019-09-19 17:37:13 -07004767 } finally {
4768 Binder.restoreCallingIdentity(token);
4769 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004770 }
4771
Brad Ebingera34a6c22019-10-22 17:36:18 -07004772 /**
4773 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4774 */
4775 @Override
4776 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4777 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4778 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4779 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4780 "IMS not available on device.");
4781 }
4782 final long token = Binder.clearCallingIdentity();
4783 try {
4784 Phone phone = getPhone(subId);
4785 if (phone == null) {
4786 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4787 + subId + "'");
4788 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4789 }
4790 phone.getImsRegistrationState(regState -> {
4791 try {
4792 consumer.accept((regState == null)
4793 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4794 } catch (RemoteException e) {
4795 // Ignore if the remote process is no longer available to call back.
4796 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4797 }
4798 });
4799 } finally {
4800 Binder.restoreCallingIdentity(token);
4801 }
4802 }
4803
4804 /**
4805 * Get the transport type for the IMS service registration state.
4806 */
4807 @Override
4808 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004809 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004810 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004811 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4812 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4813 "IMS not available on device.");
4814 }
4815 final long token = Binder.clearCallingIdentity();
4816 try {
4817 Phone phone = getPhone(subId);
4818 if (phone == null) {
4819 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4820 + subId + "'");
4821 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4822 }
4823 phone.getImsRegistrationTech(regTech -> {
4824 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4825 int regTechConverted = (regTech == null)
4826 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4827 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4828 regTechConverted);
4829 try {
4830 consumer.accept(regTechConverted);
4831 } catch (RemoteException e) {
4832 // Ignore if the remote process is no longer available to call back.
4833 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4834 }
4835 });
4836 } finally {
4837 Binder.restoreCallingIdentity(token);
4838 }
4839 }
4840
shilu366312e2019-12-17 09:28:10 -08004841 /**
4842 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4843 * @param subId The subscription to use to check the configuration.
4844 * @param c The callback that will be used to send the result.
4845 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004846 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004847 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4848 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004849 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004850 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004851 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4852 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4853 "IMS not available on device.");
4854 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004855 final long token = Binder.clearCallingIdentity();
4856 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004857 int slotId = getSlotIndexOrException(subId);
4858 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004859
4860 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4861 if (controller != null) {
4862 ImsManager imsManager = controller.getImsManager(subId);
4863 if (imsManager != null) {
4864 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4865 } else {
4866 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4867 }
4868 } else {
4869 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4870 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004871 } catch (ImsException e) {
4872 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004873 } finally {
4874 Binder.restoreCallingIdentity(token);
4875 }
4876 }
4877
shilu366312e2019-12-17 09:28:10 -08004878 /**
4879 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4880 * @param subId The subscription to use to check the configuration.
4881 * @param c The callback that will be used to send the result.
4882 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004883 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004884 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004885 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004886 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004887 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4888 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4889 }
Meng Wangafbc5852019-09-19 17:37:13 -07004890
4891 final long token = Binder.clearCallingIdentity();
4892 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004893 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4894 if (controller != null) {
4895 ImsManager imsManager = controller.getImsManager(subId);
4896 if (imsManager != null) {
4897 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4898 } else {
4899 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4900 + " is inactive, ignoring unregister.");
4901 // If the ImsManager is not valid, just return, since the callback
4902 // will already have been removed internally.
4903 }
4904 }
Meng Wangafbc5852019-09-19 17:37:13 -07004905 } finally {
4906 Binder.restoreCallingIdentity(token);
4907 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004908 }
4909
4910 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004911 public boolean isCapable(int subId, int capability, int regTech) {
4912 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004913 final long token = Binder.clearCallingIdentity();
4914 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004915 int slotId = getSlotIndexOrException(subId);
4916 verifyImsMmTelConfiguredOrThrow(slotId);
4917 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4918 } catch (com.android.ims.ImsException e) {
4919 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4920 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004921 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004922 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4923 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004924 } finally {
4925 Binder.restoreCallingIdentity(token);
4926 }
4927 }
4928
4929 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004930 public boolean isAvailable(int subId, int capability, int regTech) {
4931 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004932 final long token = Binder.clearCallingIdentity();
4933 try {
4934 Phone phone = getPhone(subId);
4935 if (phone == null) return false;
4936 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004937 } catch (com.android.ims.ImsException e) {
4938 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4939 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004940 } finally {
4941 Binder.restoreCallingIdentity(token);
4942 }
4943 }
4944
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004945 /**
4946 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4947 * subscription.
4948 * @param subId The subscription to use to check the configuration.
4949 * @param callback The callback that will be used to send the result.
4950 * @param capability The MmTelFeature capability that will be used to send the result.
4951 * @param transportType The transport type of the MmTelFeature capability.
4952 */
4953 @Override
4954 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4955 int transportType) {
4956 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004957 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4958 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4959 "IMS not available on device.");
4960 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004961 final long token = Binder.clearCallingIdentity();
4962 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004963 int slotId = getSlotIndex(subId);
4964 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4965 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4966 + subId + "'");
4967 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4968 }
4969 verifyImsMmTelConfiguredOrThrow(slotId);
4970 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4971 transportType, aBoolean -> {
4972 try {
4973 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4974 } catch (RemoteException e) {
4975 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4976 + "running. Ignore");
4977 }
4978 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004979 } catch (ImsException e) {
4980 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004981 } finally {
4982 Binder.restoreCallingIdentity(token);
4983 }
4984 }
4985
shilu366312e2019-12-17 09:28:10 -08004986 /**
4987 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4988 * @param subId The subscription to use to check the configuration.
4989 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004990 @Override
4991 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004992 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004993 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004994
Brad Ebinger35c841c2018-10-01 10:40:55 -07004995 final long token = Binder.clearCallingIdentity();
4996 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004997 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004998 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004999 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005000 } catch (ImsException e) {
5001 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005002 } finally {
5003 Binder.restoreCallingIdentity(token);
5004 }
5005 }
5006
5007 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005008 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005009 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005010 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005011 final long identity = Binder.clearCallingIdentity();
5012 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005013 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005014 // This setting doesn't require an active ImsService connection, so do not verify. The
5015 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005016 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005017 } catch (ImsException e) {
5018 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005019 } finally {
5020 Binder.restoreCallingIdentity(identity);
5021 }
5022 }
5023
shilu366312e2019-12-17 09:28:10 -08005024 /**
5025 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5026 * @param subId The subscription to use to check the configuration.
5027 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005028 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005029 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005030 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005031 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005032 final long identity = Binder.clearCallingIdentity();
5033 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005034 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005035 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005036 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005037 } catch (ImsException e) {
5038 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005039 } finally {
5040 Binder.restoreCallingIdentity(identity);
5041 }
5042 }
5043
5044 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005045 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005046 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005047 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005048 final long identity = Binder.clearCallingIdentity();
5049 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005050 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005051 // This setting doesn't require an active ImsService connection, so do not verify. The
5052 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005053 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005054 } catch (ImsException e) {
5055 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005056 } finally {
5057 Binder.restoreCallingIdentity(identity);
5058 }
5059 }
5060
shilu366312e2019-12-17 09:28:10 -08005061 /**
5062 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5063 * @param subId The subscription to use to check the configuration.
5064 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005065 @Override
5066 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005067 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005068 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005069 final long identity = Binder.clearCallingIdentity();
5070 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005071 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005072 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005073 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005074 } catch (ImsException e) {
5075 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005076 } finally {
5077 Binder.restoreCallingIdentity(identity);
5078 }
5079 }
5080
5081 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005082 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005083 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005084 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005085 final long identity = Binder.clearCallingIdentity();
5086 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005087 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005088 // This setting doesn't require an active ImsService connection, so do not verify. The
5089 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005090 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005091 } catch (ImsException e) {
5092 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005093 } finally {
5094 Binder.restoreCallingIdentity(identity);
5095 }
5096 }
5097
shilu366312e2019-12-17 09:28:10 -08005098 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005099 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5100 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5101 * @param subId The subscription to use to check the configuration.
5102 */
5103 @Override
5104 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005105 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005106 mApp, subId, "isCrossSimCallingEnabledByUser");
5107 final long identity = Binder.clearCallingIdentity();
5108 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005109 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005110 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005111 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005112 } catch (ImsException e) {
5113 throw new ServiceSpecificException(e.getCode());
5114 } finally {
5115 Binder.restoreCallingIdentity(identity);
5116 }
5117 }
5118
5119 /**
5120 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5121 * Requires MODIFY_PHONE_STATE permission.
5122 * @param subId The subscription to use to check the configuration.
5123 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5124 * false otherwise
5125 */
5126 @Override
5127 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5128 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5129 "setCrossSimCallingEnabled");
5130 final long identity = Binder.clearCallingIdentity();
5131 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005132 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005133 // This setting doesn't require an active ImsService connection, so do not verify. The
5134 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005135 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005136 } catch (ImsException e) {
5137 throw new ServiceSpecificException(e.getCode());
5138 } finally {
5139 Binder.restoreCallingIdentity(identity);
5140 }
5141 }
5142
5143 /**
shilu366312e2019-12-17 09:28:10 -08005144 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5145 * @param subId The subscription to use to check the configuration.
5146 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005147 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005148
Brad Ebinger35c841c2018-10-01 10:40:55 -07005149 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005150 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005151 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005152 final long identity = Binder.clearCallingIdentity();
5153 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005154 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005155 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005156 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005157 } catch (ImsException e) {
5158 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005159 } finally {
5160 Binder.restoreCallingIdentity(identity);
5161 }
5162 }
5163
5164 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005165 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005166 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005167 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005168 final long identity = Binder.clearCallingIdentity();
5169 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005170 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005171 // This setting doesn't require an active ImsService connection, so do not verify. The
5172 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005173 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005174 } catch (ImsException e) {
5175 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005176 } finally {
5177 Binder.restoreCallingIdentity(identity);
5178 }
5179 }
5180
5181 @Override
5182 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5183 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5184 "setVoWiFiNonPersistent");
5185 final long identity = Binder.clearCallingIdentity();
5186 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005187 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005188 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005189 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005190 } catch (ImsException e) {
5191 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005192 } finally {
5193 Binder.restoreCallingIdentity(identity);
5194 }
5195 }
5196
shilu366312e2019-12-17 09:28:10 -08005197 /**
5198 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5199 * @param subId The subscription to use to check the configuration.
5200 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005201 @Override
5202 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005203 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005204 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005205 final long identity = Binder.clearCallingIdentity();
5206 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005207 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005208 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005209 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005210 } catch (ImsException e) {
5211 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005212 } finally {
5213 Binder.restoreCallingIdentity(identity);
5214 }
5215 }
5216
5217 @Override
5218 public void setVoWiFiModeSetting(int subId, int mode) {
5219 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5220 "setVoWiFiModeSetting");
5221 final long identity = Binder.clearCallingIdentity();
5222 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005223 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005224 // This setting doesn't require an active ImsService connection, so do not verify. The
5225 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005226 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005227 } catch (ImsException e) {
5228 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005229 } finally {
5230 Binder.restoreCallingIdentity(identity);
5231 }
5232 }
5233
5234 @Override
5235 public int getVoWiFiRoamingModeSetting(int subId) {
5236 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
5237 final long identity = Binder.clearCallingIdentity();
5238 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005239 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005240 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005241 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005242 } catch (ImsException e) {
5243 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005244 } finally {
5245 Binder.restoreCallingIdentity(identity);
5246 }
5247 }
5248
5249 @Override
5250 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5251 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5252 "setVoWiFiRoamingModeSetting");
5253 final long identity = Binder.clearCallingIdentity();
5254 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005255 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005256 // This setting doesn't require an active ImsService connection, so do not verify. The
5257 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005258 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005259 } catch (ImsException e) {
5260 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005261 } finally {
5262 Binder.restoreCallingIdentity(identity);
5263 }
5264 }
5265
5266 @Override
5267 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5268 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5269 "setRttCapabilityEnabled");
5270 final long identity = Binder.clearCallingIdentity();
5271 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005272 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005273 // This setting doesn't require an active ImsService connection, so do not verify. The
5274 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005275 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005276 } catch (ImsException e) {
5277 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005278 } finally {
5279 Binder.restoreCallingIdentity(identity);
5280 }
5281 }
5282
shilu366312e2019-12-17 09:28:10 -08005283 /**
5284 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5285 * @param subId The subscription to use to check the configuration.
5286 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005287 @Override
5288 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005289 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005290 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005291 final long identity = Binder.clearCallingIdentity();
5292 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005293 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005294 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005295 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005296 } catch (ImsException e) {
5297 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005298 } finally {
5299 Binder.restoreCallingIdentity(identity);
5300 }
5301 }
5302
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005303 @Override
5304 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5305 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005306
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005307 final long identity = Binder.clearCallingIdentity();
5308 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005309 if (!isImsAvailableOnDevice()) {
5310 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5311 "IMS not available on device.");
5312 }
5313 int slotId = getSlotIndexOrException(subId);
5314 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005315
5316 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5317 if (controller != null) {
5318 ImsManager imsManager = controller.getImsManager(subId);
5319 if (imsManager != null) {
5320 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5321 } else {
5322 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5323 }
5324 } else {
5325 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5326 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005327 } catch (ImsException e) {
5328 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005329 } finally {
5330 Binder.restoreCallingIdentity(identity);
5331 }
5332 }
5333
5334 @Override
5335 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5336 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005337
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005338 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005339 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5340 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5341 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005342 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005343 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5344 if (controller != null) {
5345 ImsManager imsManager = controller.getImsManager(subId);
5346 if (imsManager != null) {
5347 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5348 } else {
5349 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5350 + " is inactive, ignoring unregister.");
5351 // If the ImsManager is not valid, just return, since the callback will already
5352 // have been removed internally.
5353 }
5354 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005355 } finally {
5356 Binder.restoreCallingIdentity(identity);
5357 }
5358 }
5359
joonhunshincffb7fc2021-11-28 07:32:01 +00005360 @Override
5361 public void registerFeatureProvisioningChangedCallback(int subId,
5362 IFeatureProvisioningCallback callback) {
5363 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5364 mApp, subId, "registerFeatureProvisioningChangedCallback");
5365
5366 final long identity = Binder.clearCallingIdentity();
5367 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5368 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5369 }
5370
joonhunshin91bc1952022-04-29 08:47:15 +00005371 try {
5372 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5373 if (controller == null) {
5374 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5375 "Device does not support IMS");
5376 }
5377 controller.addFeatureProvisioningChangedCallback(subId, callback);
5378 } finally {
5379 Binder.restoreCallingIdentity(identity);
5380 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005381 }
5382
5383 @Override
5384 public void unregisterFeatureProvisioningChangedCallback(int subId,
5385 IFeatureProvisioningCallback callback) {
5386 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5387 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5388
5389 final long identity = Binder.clearCallingIdentity();
5390 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5391 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5392 }
5393
joonhunshin91bc1952022-04-29 08:47:15 +00005394 try {
5395 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5396 if (controller == null) {
5397 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5398 return;
5399 }
5400 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5401 } finally {
5402 Binder.restoreCallingIdentity(identity);
5403 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005404 }
allenwtsu99c623b2020-01-03 18:24:23 +08005405
5406 private void checkModifyPhoneStatePermission(int subId, String message) {
5407 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5408 message);
5409 }
5410
allenwtsu99c623b2020-01-03 18:24:23 +08005411 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005412 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005413 boolean isProvisioned) {
5414 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5415
5416 final long identity = Binder.clearCallingIdentity();
5417 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005418 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5419 if (controller == null) {
5420 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5421 return;
5422 }
5423 controller.setRcsProvisioningStatusForCapability(
5424 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005425 } finally {
5426 Binder.restoreCallingIdentity(identity);
5427 }
allenwtsu99c623b2020-01-03 18:24:23 +08005428 }
5429
5430
5431 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005432 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5433 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5434 mApp, subId, "getRcsProvisioningStatusForCapability");
5435
allenwtsu99c623b2020-01-03 18:24:23 +08005436 final long identity = Binder.clearCallingIdentity();
5437 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005438 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5439 if (controller == null) {
5440 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5441
5442 // device does not support IMS, this method will return true always.
5443 return true;
5444 }
5445 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005446 } finally {
5447 Binder.restoreCallingIdentity(identity);
5448 }
5449 }
5450
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005451 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005452 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5453 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005454 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005455
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005456 final long identity = Binder.clearCallingIdentity();
5457 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005458 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5459 if (controller == null) {
5460 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5461 return;
5462 }
5463 controller.setImsProvisioningStatusForCapability(
5464 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005465 } finally {
5466 Binder.restoreCallingIdentity(identity);
5467 }
5468 }
5469
5470 @Override
5471 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005472 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5473 mApp, subId, "getProvisioningStatusForCapability");
5474
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005475 final long identity = Binder.clearCallingIdentity();
5476 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005477 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5478 if (controller == null) {
5479 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005480
joonhunshin91bc1952022-04-29 08:47:15 +00005481 // device does not support IMS, this method will return true always.
5482 return true;
5483 }
5484 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005485 } finally {
5486 Binder.restoreCallingIdentity(identity);
5487 }
5488 }
5489
5490 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005491 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5492 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5493 mApp, subId, "isProvisioningRequiredForCapability");
5494
5495 final long identity = Binder.clearCallingIdentity();
5496 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005497 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5498 if (controller == null) {
5499 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5500
5501 // device does not support IMS, this method will return false
5502 return false;
5503 }
5504 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005505 } finally {
5506 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005507 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005508 }
5509
5510 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005511 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5512 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5513 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005514
joonhunshincffb7fc2021-11-28 07:32:01 +00005515 final long identity = Binder.clearCallingIdentity();
5516 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005517 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5518 if (controller == null) {
5519 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5520
5521 // device does not support IMS, this method will return false
5522 return false;
5523 }
5524 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005525 } finally {
5526 Binder.restoreCallingIdentity(identity);
5527 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005528 }
5529
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005530 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005531 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005532 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5533 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5534 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005535 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5536 mApp, subId, "getImsProvisioningInt");
5537
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005538 final long identity = Binder.clearCallingIdentity();
5539 try {
5540 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005541 int slotId = getSlotIndex(subId);
5542 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5543 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5544 + subId + "' for key:" + key);
5545 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5546 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005547
joonhunshin91bc1952022-04-29 08:47:15 +00005548 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5549 if (controller == null) {
5550 loge("getImsProvisioningInt: Device does not support IMS");
5551
5552 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5553 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5554 }
5555 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005556 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5557 return retVal;
5558 }
5559
calvinpanb5a34062021-02-08 19:59:36 +08005560 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005561 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005562 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5563 + subId + "' for key:" + key);
5564 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005565 } finally {
5566 Binder.restoreCallingIdentity(identity);
5567 }
5568 }
5569
5570 @Override
5571 public String getImsProvisioningString(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, "getImsProvisioningString");
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, "getImsProvisioningString: called for an inactive subscription id '"
5584 + subId + "' for key:" + key);
5585 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5586 }
calvinpanb5a34062021-02-08 19:59:36 +08005587 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005588 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005589 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5590 + subId + "' for key:" + key);
5591 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005592 } finally {
5593 Binder.restoreCallingIdentity(identity);
5594 }
5595 }
5596
5597 @Override
5598 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005599 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5600 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5601 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005602 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5603 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005604
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005605 final long identity = Binder.clearCallingIdentity();
5606 try {
5607 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005608 int slotId = getSlotIndex(subId);
5609 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5610 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5611 + subId + "' for key:" + key);
5612 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5613 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005614
joonhunshin91bc1952022-04-29 08:47:15 +00005615 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5616 if (controller == null) {
5617 loge("setImsProvisioningInt: Device does not support IMS");
5618
5619 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5620 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5621 }
5622 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005623 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5624 return retVal;
5625 }
5626
calvinpanb5a34062021-02-08 19:59:36 +08005627 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5628 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005629 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005630 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005631 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005632 } finally {
5633 Binder.restoreCallingIdentity(identity);
5634 }
5635 }
5636
5637 @Override
5638 public int setImsProvisioningString(int subId, int key, String 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 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005644 final long identity = Binder.clearCallingIdentity();
5645 try {
5646 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005647 int slotId = getSlotIndex(subId);
5648 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5649 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5650 + subId + "' for key:" + key);
5651 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5652 }
calvinpanb5a34062021-02-08 19:59:36 +08005653 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5654 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005655 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005656 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005657 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005658 } finally {
5659 Binder.restoreCallingIdentity(identity);
5660 }
5661 }
5662
Brad Ebinger919631e2021-06-02 17:46:35 -07005663 /**
5664 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5665 * for the given slot ID or no ImsResolver instance has been created.
5666 * @param slotId The slot ID that the IMS service is created for.
5667 * @throws ImsException If there is no ImsService configured for this slot.
5668 */
5669 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5670 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5671 ImsFeature.FEATURE_MMTEL)) {
5672 throw new ImsException("This subscription does not support MMTEL over IMS",
5673 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5674 }
5675 }
5676
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005677 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005678 int slotId = SubscriptionManager.getSlotIndex(subId);
5679 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005680 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5681 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005682 }
5683 return slotId;
5684 }
5685
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005686 private int getSlotIndex(int subId) {
5687 int slotId = SubscriptionManager.getSlotIndex(subId);
5688 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5689 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5690 }
5691 return slotId;
5692 }
5693
Wink Saville36469e72014-06-11 15:17:00 -07005694 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005695 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005696 */
5697 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005698 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5699 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005700 try {
5701 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5702 } catch (SecurityException se) {
5703 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5704 throw new SecurityException("Package " + callingPackage + " does not belong to "
5705 + Binder.getCallingUid());
5706 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005707 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005708 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005709 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005710 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005711 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005712 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005713 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005714 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5715 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005716
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005717 final long identity = Binder.clearCallingIdentity();
5718 try {
5719 final Phone phone = getPhone(subId);
5720 if (phone != null) {
5721 return phone.getServiceState().getDataNetworkType();
5722 } else {
5723 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5724 }
5725 } finally {
5726 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005727 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005728 }
5729
5730 /**
5731 * Returns the data network type
5732 */
5733 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005734 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005735 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005736 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005737 }
5738
5739 /**
5740 * Returns the data network type for a subId
5741 */
5742 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005743 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5744 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005745 String functionName = "getDataNetworkTypeForSubscriber";
5746 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5747 mApp, functionName)) {
5748 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5749 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5750 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5751 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005752 }
5753
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005754 final long identity = Binder.clearCallingIdentity();
5755 try {
5756 final Phone phone = getPhone(subId);
5757 if (phone != null) {
5758 return phone.getServiceState().getDataNetworkType();
5759 } else {
5760 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5761 }
5762 } finally {
5763 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005764 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005765 }
5766
5767 /**
Wink Saville36469e72014-06-11 15:17:00 -07005768 * Returns the Voice network type for a subId
5769 */
5770 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005771 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5772 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005773 String functionName = "getVoiceNetworkTypeForSubscriber";
5774 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5775 mApp, functionName)) {
5776 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5777 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5778 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5779 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005780 }
5781
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005782 final long identity = Binder.clearCallingIdentity();
5783 try {
5784 final Phone phone = getPhone(subId);
5785 if (phone != null) {
5786 return phone.getServiceState().getVoiceNetworkType();
5787 } else {
5788 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5789 }
5790 } finally {
5791 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005792 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005793 }
5794
5795 /**
5796 * @return true if a ICC card is present
5797 */
5798 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005799 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005800 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005801 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005802 }
5803
5804 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005805 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005806 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005807 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005808 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005809 final long identity = Binder.clearCallingIdentity();
5810 try {
5811 final Phone phone = PhoneFactory.getPhone(slotIndex);
5812 if (phone != null) {
5813 return phone.getIccCard().hasIccCard();
5814 } else {
5815 return false;
5816 }
5817 } finally {
5818 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005819 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005820 }
5821
5822 /**
5823 * Return if the current radio is LTE on CDMA. This
5824 * is a tri-state return value as for a period of time
5825 * the mode may be unknown.
5826 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005827 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005828 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005829 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005830 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005831 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005832 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5833 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5834 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005835 }
5836
Sanket Padawe356d7632015-06-22 14:03:32 -07005837 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005838 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5839 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005840 try {
5841 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5842 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005843 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5844 }
5845
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005846 final long identity = Binder.clearCallingIdentity();
5847 try {
5848 final Phone phone = getPhone(subId);
5849 if (phone == null) {
5850 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5851 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005852 return TelephonyProperties.lte_on_cdma_device()
5853 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005854 }
5855 } finally {
5856 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005857 }
Wink Saville36469e72014-06-11 15:17:00 -07005858 }
5859
Wink Saville36469e72014-06-11 15:17:00 -07005860 /**
5861 * {@hide}
5862 * Returns Default subId, 0 in the case of single standby.
5863 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005864 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005865 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005866 }
5867
Shishir Agrawala9f32182016-04-12 12:00:16 -07005868 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005869 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005870 }
5871
Wink Savilleb564aae2014-10-23 10:18:09 -07005872 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005873 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005874 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005875
Pengquan Menge92a50d2018-09-21 15:54:48 -07005876 private boolean isActiveSubscription(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08005877 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
5878 return SubscriptionManagerService.getInstance().isActiveSubId(subId,
5879 mApp.getOpPackageName(), mApp.getFeatureId());
5880 }
Pengquan Menge92a50d2018-09-21 15:54:48 -07005881 return mSubscriptionController.isActiveSubId(subId);
5882 }
5883
Ihab Awadf2177b72013-11-25 13:33:23 -08005884 /**
5885 * @see android.telephony.TelephonyManager.WifiCallingChoices
5886 */
5887 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005888 final long identity = Binder.clearCallingIdentity();
5889 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005890 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005891 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5892 getWhenToMakeWifiCallsDefaultPreference());
5893 } finally {
5894 Binder.restoreCallingIdentity(identity);
5895 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005896 }
5897
5898 /**
5899 * @see android.telephony.TelephonyManager.WifiCallingChoices
5900 */
5901 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005902 final long identity = Binder.clearCallingIdentity();
5903 try {
5904 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005905 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005906 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5907 } finally {
5908 Binder.restoreCallingIdentity(identity);
5909 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005910 }
5911
Sailesh Nepald1e68152013-12-12 19:08:02 -08005912 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005913 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005914 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005915 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005916
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005917 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5918 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5919 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005920 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005921 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005922 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005923 }
5924 return PhoneFactory.getPhone(phoneId);
5925 }
5926
Shishir Agrawal566b7612013-10-28 14:41:00 -07005927 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005928 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005929 @NonNull IccLogicalChannelRequest request) {
5930 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5931 /*message=*/ "iccOpenLogicalChannel");
5932
5933 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5934 // Verify that the callingPackage in the request belongs to the calling UID
5935 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5936
5937 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005938 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005939
Rambo Wanga1782702021-11-10 20:15:19 -08005940 private Phone getPhoneFromValidIccLogicalChannelRequest(
5941 @NonNull IccLogicalChannelRequest request, String message) {
5942 Phone phone;
5943 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5944 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5945 mApp, request.subId, message);
5946 phone = getPhoneFromSubId(request.subId);
5947 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5948 enforceModifyPermission();
5949 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5950 } else {
5951 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005952 }
Rambo Wanga1782702021-11-10 20:15:19 -08005953 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005954 }
5955
5956 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005957 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005958 final long identity = Binder.clearCallingIdentity();
5959 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005960 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005961 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005962 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5963 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005964 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5965 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005966 loge("The calling package is not allowed to access ISD-R.");
5967 throw new SecurityException(
5968 "The calling package is not allowed to access ISD-R.");
5969 }
Derek Tan740e1672017-06-27 14:56:27 -07005970 }
Derek Tan740e1672017-06-27 14:56:27 -07005971
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005972 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005973 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5974 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005975 return response;
5976 } finally {
5977 Binder.restoreCallingIdentity(identity);
5978 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005979 }
5980
5981 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005982 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5983 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5984 /*message=*/"iccCloseLogicalChannel");
5985
5986 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5987
5988 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005989 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005990
Rambo Wanga1782702021-11-10 20:15:19 -08005991 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5992 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005993 // before this feature is enabled, this API should only return false if
5994 // the operation fails instead of throwing runtime exception for
5995 // backward-compatibility.
5996 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5997 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005998 final long identity = Binder.clearCallingIdentity();
5999 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006000 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006001 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006002 }
Chen Xue9d737e2022-01-01 23:41:31 -08006003 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006004 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006005 Boolean success = false;
6006 if (result instanceof RuntimeException) {
6007 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006008 if (shouldThrowExceptionOnFailure) {
6009 throw (RuntimeException) result;
6010 } else {
6011 return false;
6012 }
Chen Xue9d737e2022-01-01 23:41:31 -08006013 } else if (result instanceof Boolean) {
6014 success = (Boolean) result;
6015 } else {
6016 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6017 }
Rambo Wanga1782702021-11-10 20:15:19 -08006018 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006019 return success;
6020 } finally {
6021 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006022 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006023 }
6024
6025 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006026 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006027 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006028 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6029 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08006030 if (DBG) {
6031 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6032 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6033 + p3 + " data=" + data);
6034 }
6035 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6036 command, p1, p2, p3, data);
6037 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006038
Jordan Liu4c733742019-02-28 12:03:40 -08006039 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006040 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006041 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006042 enforceModifyPermission();
6043 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006044 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006045 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6046 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006047 }
6048 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006049 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6050 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006051 }
6052
6053 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6054 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006055 final long identity = Binder.clearCallingIdentity();
6056 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006057 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006058 return "";
6059 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006060
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006061 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006062 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6063 null /* workSource */);
6064 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006065
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006066 // Append the returned status code to the end of the response payload.
6067 String s = Integer.toHexString(
6068 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6069 if (response.payload != null) {
6070 s = IccUtils.bytesToHexString(response.payload) + s;
6071 }
6072 return s;
6073 } finally {
6074 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006075 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006076 }
Jake Hambye994d462014-02-03 13:10:13 -08006077
Evan Charltonc66da362014-05-16 14:06:40 -07006078 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006079 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6080 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006081 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6082 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006083 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08006084 if (DBG) {
6085 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6086 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6087 }
6088 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6089 cla, command, p1, p2, p3, data);
6090 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006091
Jordan Liu4c733742019-02-28 12:03:40 -08006092 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006093 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006094 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006095 enforceModifyPermission();
6096 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
6097 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006098 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006099 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6100 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006101 }
6102
6103 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006104 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6105 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006106 }
6107
6108 // open APDU basic channel assuming the caller has sufficient permissions
6109 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6110 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006111 final long identity = Binder.clearCallingIdentity();
6112 try {
6113 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6114 && TextUtils.equals(ISDR_AID, data)) {
6115 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006116 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6117 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006118 if (bestComponent == null
6119 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6120 loge("The calling package is not allowed to select ISD-R.");
6121 throw new SecurityException(
6122 "The calling package is not allowed to select ISD-R.");
6123 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006124 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006125
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006126 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006127 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6128 null /* workSource */);
6129 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006130
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006131 // Append the returned status code to the end of the response payload.
6132 String s = Integer.toHexString(
6133 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6134 if (response.payload != null) {
6135 s = IccUtils.bytesToHexString(response.payload) + s;
6136 }
6137 return s;
6138 } finally {
6139 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006140 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006141 }
6142
6143 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006144 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006145 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006146 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6147 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006148
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006149 final long identity = Binder.clearCallingIdentity();
6150 try {
6151 if (DBG) {
6152 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6153 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6154 }
6155
6156 IccIoResult response =
6157 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6158 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6159 subId);
6160
6161 if (DBG) {
6162 log("Exchange SIM_IO [R]" + response);
6163 }
6164
6165 byte[] result = null;
6166 int length = 2;
6167 if (response.payload != null) {
6168 length = 2 + response.payload.length;
6169 result = new byte[length];
6170 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6171 } else {
6172 result = new byte[length];
6173 }
6174
6175 result[length - 1] = (byte) response.sw2;
6176 result[length - 2] = (byte) response.sw1;
6177 return result;
6178 } finally {
6179 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006180 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006181 }
6182
Nathan Haroldb3014052017-01-25 15:57:32 -08006183 /**
6184 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6185 * on a particular subscription
6186 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006187 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6188 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006189 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006190 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006191 return null;
6192 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006193
6194 final long identity = Binder.clearCallingIdentity();
6195 try {
6196 if (appType != TelephonyManager.APPTYPE_USIM
6197 && appType != TelephonyManager.APPTYPE_SIM) {
6198 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6199 return null;
6200 }
6201 Object response = sendRequest(
6202 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6203 if (response instanceof String[]) {
6204 return (String[]) response;
6205 }
yincheng zhao2737e882019-09-06 17:06:54 -07006206 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006207 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006208 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006209 } finally {
6210 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006211 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006212 }
6213
yincheng zhao2737e882019-09-06 17:06:54 -07006214 /**
6215 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6216 * subscription.
6217 *
6218 * @param subId the id of the subscription.
6219 * @param appType the uicc app type, must be USIM or SIM.
6220 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6221 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006222 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006223 * @return number of fplmns that is successfully written to the SIM.
6224 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006225 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6226 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006227 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6228 mApp, subId, "setForbiddenPlmns");
6229
yincheng zhao2737e882019-09-06 17:06:54 -07006230 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6231 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6232 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6233 }
6234 if (fplmns == null) {
6235 throw new IllegalArgumentException("Fplmn List provided is null");
6236 }
6237 for (String fplmn : fplmns) {
6238 if (!CellIdentity.isValidPlmn(fplmn)) {
6239 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6240 }
6241 }
6242 final long identity = Binder.clearCallingIdentity();
6243 try {
6244 Object response = sendRequest(
6245 CMD_SET_FORBIDDEN_PLMNS,
6246 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6247 subId);
6248 return (int) response;
6249 } finally {
6250 Binder.restoreCallingIdentity(identity);
6251 }
6252 }
6253
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006254 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006255 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006256 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6257 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006258
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006259 final long identity = Binder.clearCallingIdentity();
6260 try {
6261 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6262 if (response.payload == null) {
6263 return "";
6264 }
Evan Charltonc66da362014-05-16 14:06:40 -07006265
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006266 // Append the returned status code to the end of the response payload.
6267 String s = Integer.toHexString(
6268 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6269 s = IccUtils.bytesToHexString(response.payload) + s;
6270 return s;
6271 } finally {
6272 Binder.restoreCallingIdentity(identity);
6273 }
Evan Charltonc66da362014-05-16 14:06:40 -07006274 }
6275
Jake Hambye994d462014-02-03 13:10:13 -08006276 /**
6277 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6278 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6279 *
6280 * @param itemID the ID of the item to read
6281 * @return the NV item as a String, or null on error.
6282 */
6283 @Override
6284 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006285 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006286 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6287 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006288
6289 final long identity = Binder.clearCallingIdentity();
6290 try {
6291 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006292 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006293 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6294 return value;
6295 } finally {
6296 Binder.restoreCallingIdentity(identity);
6297 }
Jake Hambye994d462014-02-03 13:10:13 -08006298 }
6299
6300 /**
6301 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6302 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6303 *
6304 * @param itemID the ID of the item to read
6305 * @param itemValue the value to write, as a String
6306 * @return true on success; false on any failure
6307 */
6308 @Override
6309 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006310 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006311 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6312 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006313
6314 final long identity = Binder.clearCallingIdentity();
6315 try {
6316 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6317 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006318 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006319 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6320 return success;
6321 } finally {
6322 Binder.restoreCallingIdentity(identity);
6323 }
Jake Hambye994d462014-02-03 13:10:13 -08006324 }
6325
6326 /**
6327 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6328 * Used for device configuration by some CDMA operators.
6329 *
6330 * @param preferredRoamingList byte array containing the new PRL
6331 * @return true on success; false on any failure
6332 */
6333 @Override
6334 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006335 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6336 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006337
6338 final long identity = Binder.clearCallingIdentity();
6339 try {
6340 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6341 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6342 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6343 return success;
6344 } finally {
6345 Binder.restoreCallingIdentity(identity);
6346 }
Jake Hambye994d462014-02-03 13:10:13 -08006347 }
6348
6349 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006350 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006351 * Used for device configuration by some CDMA operators.
6352 *
chen xu6dac5ab2018-10-26 17:39:23 -07006353 * @param slotIndex - device slot.
6354 *
Jake Hambye994d462014-02-03 13:10:13 -08006355 * @return true on success; false on any failure
6356 */
6357 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006358 public boolean resetModemConfig(int slotIndex) {
6359 Phone phone = PhoneFactory.getPhone(slotIndex);
6360 if (phone != null) {
6361 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6362 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006363
chen xu6dac5ab2018-10-26 17:39:23 -07006364 final long identity = Binder.clearCallingIdentity();
6365 try {
6366 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6367 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6368 return success;
6369 } finally {
6370 Binder.restoreCallingIdentity(identity);
6371 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006372 }
chen xu6dac5ab2018-10-26 17:39:23 -07006373 return false;
6374 }
6375
6376 /**
6377 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6378 *
6379 * @param slotIndex - device slot.
6380 *
6381 * @return true on success; false on any failure
6382 */
6383 @Override
6384 public boolean rebootModem(int slotIndex) {
6385 Phone phone = PhoneFactory.getPhone(slotIndex);
6386 if (phone != null) {
6387 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6388 mApp, phone.getSubId(), "rebootModem");
6389
6390 final long identity = Binder.clearCallingIdentity();
6391 try {
6392 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6393 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6394 return success;
6395 } finally {
6396 Binder.restoreCallingIdentity(identity);
6397 }
6398 }
6399 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006400 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006401
Brad Ebinger51f743a2017-01-23 13:50:20 -08006402 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006403 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6404 * {@link #disableIms(int)}.
6405 * @param slotIndex device slot.
6406 */
6407 public void resetIms(int slotIndex) {
6408 enforceModifyPermission();
6409
6410 final long identity = Binder.clearCallingIdentity();
6411 try {
6412 if (mImsResolver == null) {
6413 // may happen if the does not support IMS.
6414 return;
6415 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006416 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006417 } finally {
6418 Binder.restoreCallingIdentity(identity);
6419 }
6420 }
6421
6422 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006423 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6424 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006425 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006426 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006427 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006428
6429 final long identity = Binder.clearCallingIdentity();
6430 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006431 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006432 // may happen if the device does not support IMS.
6433 return;
6434 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006435 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006436 } finally {
6437 Binder.restoreCallingIdentity(identity);
6438 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006439 }
6440
6441 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006442 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6443 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006444 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006445 public void disableIms(int slotId) {
6446 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006447
6448 final long identity = Binder.clearCallingIdentity();
6449 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006450 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006451 // may happen if the device does not support IMS.
6452 return;
6453 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006454 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006455 } finally {
6456 Binder.restoreCallingIdentity(identity);
6457 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006458 }
6459
6460 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006461 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6462 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006463 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006464 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006465 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006466 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006467
6468 final long identity = Binder.clearCallingIdentity();
6469 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006470 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006471 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6472 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006473 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006474 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006475 } finally {
6476 Binder.restoreCallingIdentity(identity);
6477 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006478 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006479 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006480 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6481 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006482 @Override
6483 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006484 enforceModifyPermission();
6485
6486 final long identity = Binder.clearCallingIdentity();
6487 try {
6488 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006489 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006490 } finally {
6491 Binder.restoreCallingIdentity(identity);
6492 }
6493 }
6494
6495 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006496 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006497 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006498 */
6499 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6500 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006501
6502 final long identity = Binder.clearCallingIdentity();
6503 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006504 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006505 // may happen if the device does not support IMS.
6506 return null;
6507 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006508 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006509 } finally {
6510 Binder.restoreCallingIdentity(identity);
6511 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006512 }
6513
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006514 /**
6515 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006516 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006517 */
6518 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6519 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006520
6521 final long identity = Binder.clearCallingIdentity();
6522 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006523 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006524 // may happen if the device does not support IMS.
6525 return null;
6526 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006527 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006528 } finally {
6529 Binder.restoreCallingIdentity(identity);
6530 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006531 }
6532
Brad Ebinger884c07b2018-02-15 16:17:40 -08006533 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006534 * Sets the ImsService Package Name that Telephony will bind to.
6535 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006536 * @param slotIndex the slot ID that the ImsService should bind for.
6537 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006538 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006539 * @param featureTypes An integer array of feature types associated with a packageName.
6540 * @param packageName The name of the package that the current configuration will be replaced
6541 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006542 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006543 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006544 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6545 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006546 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006547 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006548 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006549
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006550 final long identity = Binder.clearCallingIdentity();
6551 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006552 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006553 // may happen if the device does not support IMS.
6554 return false;
6555 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006556 Map<Integer, String> featureConfig = new HashMap<>();
6557 for (int featureType : featureTypes) {
6558 featureConfig.put(featureType, packageName);
6559 }
6560 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6561 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006562 } finally {
6563 Binder.restoreCallingIdentity(identity);
6564 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006565 }
6566
6567 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006568 * Clears any carrier ImsService overrides for the slot index specified that were previously
6569 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6570 *
6571 * This should only be used for testing.
6572 *
6573 * @param slotIndex the slot ID that the ImsService should bind for.
6574 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6575 */
6576 @Override
6577 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006578 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6579 "clearCarrierImsServiceOverride");
6580 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006581 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006582
6583 final long identity = Binder.clearCallingIdentity();
6584 try {
6585 if (mImsResolver == null) {
6586 // may happen if the device does not support IMS.
6587 return false;
6588 }
6589 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6590 } finally {
6591 Binder.restoreCallingIdentity(identity);
6592 }
6593 }
6594
6595 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006596 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006597 *
6598 * @param slotId The slot that the ImsService is associated with.
6599 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6600 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006601 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006602 * @return the package name of the ImsService configuration.
6603 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006604 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6605 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006606 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006607 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6608 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006609
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006610 final long identity = Binder.clearCallingIdentity();
6611 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006612 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006613 // may happen if the device does not support IMS.
6614 return "";
6615 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006616 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006617 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6618 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006619 } finally {
6620 Binder.restoreCallingIdentity(identity);
6621 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006622 }
6623
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006624 /**
6625 * Get the MmTelFeature state associated with the requested subscription id.
6626 * @param subId The subscription that the MmTelFeature is associated with.
6627 * @param callback A callback with an integer containing the
6628 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6629 */
6630 @Override
6631 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6632 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006633 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6634 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6635 "IMS not available on device.");
6636 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006637 final long token = Binder.clearCallingIdentity();
6638 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006639 int slotId = getSlotIndex(subId);
6640 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6641 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6642 + subId + "'");
6643 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6644 }
6645 verifyImsMmTelConfiguredOrThrow(slotId);
6646 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6647 try {
6648 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6649 } catch (RemoteException e) {
6650 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6651 + "Ignore");
6652 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006653 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006654 } catch (ImsException e) {
6655 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006656 } finally {
6657 Binder.restoreCallingIdentity(token);
6658 }
6659 }
6660
Daniel Brightbb5840b2021-01-12 15:48:18 -08006661 /**
6662 * Sets the ims registration state on all valid {@link Phone}s.
6663 */
6664 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006665 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006666
6667 final long identity = Binder.clearCallingIdentity();
6668 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006669 // NOTE: Before S, this method only set the default phone.
6670 for (final Phone phone : PhoneFactory.getPhones()) {
6671 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6672 phone.setImsRegistrationState(registered);
6673 }
6674 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006675 } finally {
6676 Binder.restoreCallingIdentity(identity);
6677 }
Wink Saville36469e72014-06-11 15:17:00 -07006678 }
6679
6680 /**
Stuart Scott54788802015-03-30 13:18:01 -07006681 * Set the network selection mode to automatic.
6682 *
6683 */
6684 @Override
6685 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006686 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6687 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006688
6689 final long identity = Binder.clearCallingIdentity();
6690 try {
shilufc958392020-01-20 11:36:01 -08006691 if (!isActiveSubscription(subId)) {
6692 return;
6693 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006694 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006695 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6696 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006697 } finally {
6698 Binder.restoreCallingIdentity(identity);
6699 }
Stuart Scott54788802015-03-30 13:18:01 -07006700 }
6701
Jack Yud10cdd42020-09-28 20:28:01 -07006702 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006703 * Ask the radio to connect to the input network and change selection mode to manual.
6704 *
6705 * @param subId the id of the subscription.
6706 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6707 * the operator to attach to.
6708 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6709 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6710 * normal network selection next time.
6711 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006712 */
6713 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006714 public boolean setNetworkSelectionModeManual(
6715 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006716 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6717 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006718
Jack Yu285100e2022-12-02 22:48:35 -08006719 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006720 if (!isActiveSubscription(subId)) {
6721 return false;
6722 }
6723
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006724 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006725 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006726 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006727 if (DBG) {
6728 log("setNetworkSelectionModeManual: subId: " + subId
6729 + " operator: " + operatorInfo);
6730 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006731 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6732 } finally {
6733 Binder.restoreCallingIdentity(identity);
6734 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006735 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006736 /**
shilu84f6e8b2019-12-19 13:58:01 -08006737 * Get the manual network selection
6738 *
6739 * @param subId the id of the subscription.
6740 *
6741 * @return the previously saved user selected PLMN
6742 */
6743 @Override
6744 public String getManualNetworkSelectionPlmn(int subId) {
6745 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006746 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6747 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006748
6749 final long identity = Binder.clearCallingIdentity();
6750 try {
6751 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006752 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006753 }
6754
6755 final Phone phone = getPhone(subId);
6756 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006757 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006758 }
6759 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6760 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006761 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006762 } finally {
6763 Binder.restoreCallingIdentity(identity);
6764 }
6765 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006766
6767 /**
6768 * Scans for available networks.
6769 */
6770 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006771 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6772 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006773 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6774 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006775 LocationAccessPolicy.LocationPermissionResult locationResult =
6776 LocationAccessPolicy.checkLocationPermission(mApp,
6777 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6778 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006779 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006780 .setCallingPid(Binder.getCallingPid())
6781 .setCallingUid(Binder.getCallingUid())
6782 .setMethod("getCellNetworkScanResults")
6783 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006784 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6785 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006786 .build());
6787 switch (locationResult) {
6788 case DENIED_HARD:
6789 throw new SecurityException("Not allowed to access scan results -- location");
6790 case DENIED_SOFT:
6791 return null;
6792 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006793
Pengquan Menga1bb6272018-09-06 09:59:22 -07006794 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006795 try {
6796 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006797 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006798 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006799 } finally {
6800 Binder.restoreCallingIdentity(identity);
6801 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006802 }
6803
6804 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006805 * Get the call forwarding info, given the call forwarding reason.
6806 */
6807 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006808 public void getCallForwarding(int subId, int callForwardingReason,
6809 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006810 enforceReadPrivilegedPermission("getCallForwarding");
6811 long identity = Binder.clearCallingIdentity();
6812 try {
6813 if (DBG) {
6814 log("getCallForwarding: subId " + subId
6815 + " callForwardingReason" + callForwardingReason);
6816 }
Hall Liu27d24262020-09-18 19:04:59 -07006817
6818 Phone phone = getPhone(subId);
6819 if (phone == null) {
6820 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006821 callback.onError(
6822 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006823 } catch (RemoteException e) {
6824 // ignore
6825 }
6826 return;
6827 }
6828
6829 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6830 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6831 @Override
6832 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6833 try {
6834 callback.onCallForwardingInfoAvailable(info);
6835 } catch (RemoteException e) {
6836 // ignore
6837 }
6838 }
6839
6840 @Override
6841 public void onError(int error) {
6842 try {
6843 callback.onError(error);
6844 } catch (RemoteException e) {
6845 // ignore
6846 }
6847 }
6848 });
6849 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006850 } finally {
6851 Binder.restoreCallingIdentity(identity);
6852 }
6853 }
6854
6855 /**
6856 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6857 * reason, the number to forward, and the timeout before the forwarding is attempted.
6858 */
6859 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006860 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6861 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006862 enforceModifyPermission();
6863 long identity = Binder.clearCallingIdentity();
6864 try {
6865 if (DBG) {
6866 log("setCallForwarding: subId " + subId
6867 + " callForwardingInfo" + callForwardingInfo);
6868 }
Hall Liu27d24262020-09-18 19:04:59 -07006869
6870 Phone phone = getPhone(subId);
6871 if (phone == null) {
6872 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006873 callback.accept(
6874 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006875 } catch (RemoteException e) {
6876 // ignore
6877 }
6878 return;
6879 }
6880
6881 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6882 FunctionalUtils.ignoreRemoteException(callback::accept));
6883
6884 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006885 } finally {
6886 Binder.restoreCallingIdentity(identity);
6887 }
6888 }
6889
6890 /**
Hall Liu27d24262020-09-18 19:04:59 -07006891 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006892 */
6893 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006894 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006895 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006896 long identity = Binder.clearCallingIdentity();
6897 try {
Hall Liu27d24262020-09-18 19:04:59 -07006898 Phone phone = getPhone(subId);
6899 if (phone == null) {
6900 try {
6901 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6902 } catch (RemoteException e) {
6903 // ignore
6904 }
6905 return;
6906 }
SongFerngWang0e767992021-03-31 22:08:45 +08006907 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6908 PersistableBundle c = configManager.getConfigForSubId(subId);
6909 boolean requireUssd = c.getBoolean(
6910 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006911
Shuo Qian4a594052020-01-23 11:59:30 -08006912 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006913 if (requireUssd) {
6914 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6915 getSubscriptionCarrierId(subId));
6916 String newUssdCommand = "";
6917 try {
6918 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006919 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006920 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6921 } catch (NullPointerException e) {
6922 loge("Failed to generate USSD number" + e);
6923 }
6924 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6925 mMainThreadHandler, callback, carrierXmlParser,
6926 CarrierXmlParser.SsEntry.SSAction.QUERY);
6927 final String ussdCommand = newUssdCommand;
6928 Executors.newSingleThreadExecutor().execute(() -> {
6929 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6930 });
6931 } else {
6932 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6933 callback::accept);
6934 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6935 }
Shuo Qian4a594052020-01-23 11:59:30 -08006936 } finally {
6937 Binder.restoreCallingIdentity(identity);
6938 }
6939 }
6940
6941 /**
Hall Liu27d24262020-09-18 19:04:59 -07006942 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006943 */
6944 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006945 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006946 enforceModifyPermission();
6947 long identity = Binder.clearCallingIdentity();
6948 try {
Hall Liu27d24262020-09-18 19:04:59 -07006949 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6950
6951 Phone phone = getPhone(subId);
6952 if (phone == null) {
6953 try {
6954 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6955 } catch (RemoteException e) {
6956 // ignore
6957 }
6958 return;
6959 }
6960
SongFerngWang0e767992021-03-31 22:08:45 +08006961 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6962 PersistableBundle c = configManager.getConfigForSubId(subId);
6963 boolean requireUssd = c.getBoolean(
6964 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006965
SongFerngWang0e767992021-03-31 22:08:45 +08006966 if (DBG) log("getCallWaitingStatus: subId " + subId);
6967 if (requireUssd) {
6968 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6969 getSubscriptionCarrierId(subId));
6970 CarrierXmlParser.SsEntry.SSAction ssAction =
6971 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6972 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6973 String newUssdCommand = "";
6974 try {
6975 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006976 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006977 .makeCommand(ssAction, null);
6978 } catch (NullPointerException e) {
6979 loge("Failed to generate USSD number" + e);
6980 }
6981 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6982 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6983 final String ussdCommand = newUssdCommand;
6984 Executors.newSingleThreadExecutor().execute(() -> {
6985 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6986 });
6987 } else {
6988 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6989 FunctionalUtils.ignoreRemoteException(callback::accept));
6990
6991 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6992 }
Shuo Qian4a594052020-01-23 11:59:30 -08006993 } finally {
6994 Binder.restoreCallingIdentity(identity);
6995 }
6996 }
6997
6998 /**
yinxub1bed742017-04-17 11:45:04 -07006999 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007000 *
yinxub1bed742017-04-17 11:45:04 -07007001 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007002 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7003 * location related information which will be sent if the caller already possess
7004 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007005 * @param request contains the radio access networks with bands/channels to scan
7006 * @param messenger callback messenger for scan results or errors
7007 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007008 * @return the id of the requested scan which can be used to stop the scan.
7009 */
7010 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007011 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7012 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007013 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007014 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7015 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007016 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007017 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7018 if (!renounceFineLocationAccess) {
7019 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007020 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7021 .setCallingPackage(callingPackage)
7022 .setCallingFeatureId(callingFeatureId)
7023 .setCallingPid(Binder.getCallingPid())
7024 .setCallingUid(Binder.getCallingUid())
7025 .setMethod("requestNetworkScan")
7026 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7027 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7028 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7029 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007030 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007031 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007032 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7033 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007034 if (e != null) {
7035 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7036 throw e;
7037 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007038 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007039 return TelephonyScanManager.INVALID_SCAN_ID;
7040 }
7041 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007042 }
Hall Liu912dfd32019-04-25 14:02:26 -07007043 int callingUid = Binder.getCallingUid();
7044 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007045 final long identity = Binder.clearCallingIdentity();
7046 try {
7047 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007048 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007049 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007050 } finally {
7051 Binder.restoreCallingIdentity(identity);
7052 }
yinxu504e1392017-04-12 16:03:22 -07007053 }
7054
Hall Liub2ac8ef2019-02-28 15:56:23 -08007055 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007056 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007057 boolean hasCarrierPriv;
7058 final long identity = Binder.clearCallingIdentity();
7059 try {
7060 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7061 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7062 } finally {
7063 Binder.restoreCallingIdentity(identity);
7064 }
Hall Liu558027f2019-05-15 19:14:05 -07007065 boolean hasNetworkScanPermission =
7066 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007067 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007068
7069 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7070 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7071 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007072 }
7073
7074 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7075 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007076 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7077 return new SecurityException("Specific channels must not be"
7078 + " scanned without location access.");
7079 }
7080 }
7081 }
7082
Hall Liub2ac8ef2019-02-28 15:56:23 -08007083 return null;
7084 }
7085
yinxu504e1392017-04-12 16:03:22 -07007086 /**
7087 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007088 *
7089 * @param subId id of the subscription
7090 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007091 */
7092 @Override
7093 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007094 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7095 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007096
Hall Liu912dfd32019-04-25 14:02:26 -07007097 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007098 final long identity = Binder.clearCallingIdentity();
7099 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007100 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007101 } finally {
7102 Binder.restoreCallingIdentity(identity);
7103 }
yinxu504e1392017-04-12 16:03:22 -07007104 }
7105
7106 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007107 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007108 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007109 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007110 */
7111 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007112 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007113 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007114 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007115 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007116
7117 final long identity = Binder.clearCallingIdentity();
7118 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007119 if (DBG) log("getAllowedNetworkTypesBitmask");
7120 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7121 int networkTypesBitmask = (result != null ? result[0] : -1);
7122 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7123 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007124 } finally {
7125 Binder.restoreCallingIdentity(identity);
7126 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007127 }
7128
7129 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007130 * Get the allowed network types for certain reason.
7131 *
7132 * @param subId the id of the subscription.
7133 * @param reason the reason the allowed network type change is taking place
7134 * @return the allowed network types.
7135 */
7136 @Override
7137 public long getAllowedNetworkTypesForReason(int subId,
7138 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007139 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007140 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007141 final long identity = Binder.clearCallingIdentity();
7142 try {
7143 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
7144 } finally {
7145 Binder.restoreCallingIdentity(identity);
7146 }
7147 }
7148
7149 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007150 * Enable/Disable E-UTRA-NR Dual Connectivity
7151 * @param subId subscription id of the sim card
7152 * @param nrDualConnectivityState expected NR dual connectivity state
7153 * This can be passed following states
7154 * <ol>
7155 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7156 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7157 * <li>Disable NR dual connectivity and force secondary cell to be released
7158 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7159 * </ol>
7160 * @return operation result.
7161 */
7162 @Override
7163 public int setNrDualConnectivityState(int subId,
7164 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7165 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7166 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007167 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007168 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7169 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7170 }
7171
Sooraj Sasindran37444802020-08-11 10:40:43 -07007172 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7173 final long identity = Binder.clearCallingIdentity();
7174 try {
7175 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7176 nrDualConnectivityState, subId,
7177 workSource);
7178 if (DBG) log("enableNRDualConnectivity result: " + result);
7179 return result;
7180 } finally {
7181 Binder.restoreCallingIdentity(identity);
7182 }
7183 }
7184
7185 /**
7186 * Is E-UTRA-NR Dual Connectivity enabled
7187 * @return true if dual connectivity is enabled else false
7188 */
7189 @Override
7190 public boolean isNrDualConnectivityEnabled(int subId) {
7191 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007192 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007193 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007194 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007195 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7196 return false;
7197 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007198 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7199 final long identity = Binder.clearCallingIdentity();
7200 try {
7201 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7202 null, subId, workSource);
7203 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7204 return isEnabled;
7205 } finally {
7206 Binder.restoreCallingIdentity(identity);
7207 }
7208 }
7209
7210 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007211 * Set the allowed network types of the device and
7212 * provide the reason triggering the allowed network change.
7213 *
7214 * @param subId the id of the subscription.
7215 * @param reason the reason the allowed network type change is taking place
7216 * @param allowedNetworkTypes the allowed network types.
7217 * @return true on success; false on any failure.
7218 */
7219 @Override
7220 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007221 @TelephonyManager.AllowedNetworkTypesReason int reason,
7222 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007223 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7224 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007225 // If the caller only has carrier privileges, then they should not be able to override
7226 // any network types which were set for security reasons.
7227 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7228 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007229 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007230 throw new SecurityException(
7231 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007232 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007233 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08007234 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007235 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007236 return false;
7237 }
7238 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7239 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007240 return false;
7241 }
7242
Jack Yu5b494332023-01-23 18:18:04 +00007243 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7244 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007245
Jack Yue37dd262022-12-16 11:53:37 -08007246 Phone phone = getPhone(subId);
7247 if (phone == null) {
7248 return false;
7249 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007250
Jack Yue37dd262022-12-16 11:53:37 -08007251 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007252 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007253 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007254 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007255
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007256 final long identity = Binder.clearCallingIdentity();
7257 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007258 Boolean success = (Boolean) sendRequest(
7259 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7260 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7261
7262 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7263 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007264 } finally {
7265 Binder.restoreCallingIdentity(identity);
7266 }
7267 }
7268
7269 /**
Miaoa84611c2019-03-15 09:21:10 +08007270 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007271 *
Miaoa84611c2019-03-15 09:21:10 +08007272 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007273 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007274 * @hide
7275 */
7276 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007277 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007278 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007279 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007280 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007281 try {
Miaoa84611c2019-03-15 09:21:10 +08007282 if (phone != null) {
7283 return phone.hasMatchedTetherApnSetting();
7284 } else {
7285 return false;
7286 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007287 } finally {
7288 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007289 }
Junda Liu475951f2014-11-07 16:45:03 -08007290 }
7291
7292 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007293 * Get the user enabled state of Mobile Data.
7294 *
7295 * TODO: remove and use isUserDataEnabled.
7296 * This can't be removed now because some vendor codes
7297 * calls through ITelephony directly while they should
7298 * use TelephonyManager.
7299 *
7300 * @return true on enabled
7301 */
7302 @Override
7303 public boolean getDataEnabled(int subId) {
7304 return isUserDataEnabled(subId);
7305 }
7306
7307 /**
7308 * Get whether mobile data is enabled per user setting.
7309 *
7310 * There are other factors deciding whether mobile data is actually enabled, but they are
7311 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007312 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007313 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7314 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007315 *
7316 * @return {@code true} if data is enabled else {@code false}
7317 */
7318 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007319 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007320 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007321 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007322 try {
7323 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7324 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007325 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007326 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7327 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007328 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007329 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007330 mApp, subId, functionName);
7331
Robert Greenwalt646120a2014-05-23 11:54:03 -07007332 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007333
7334 final long identity = Binder.clearCallingIdentity();
7335 try {
Jack Yu285100e2022-12-02 22:48:35 -08007336 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007337 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7338 Phone phone = PhoneFactory.getPhone(phoneId);
7339 if (phone != null) {
7340 boolean retVal = phone.isUserDataEnabled();
7341 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7342 return retVal;
7343 } else {
7344 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7345 return false;
7346 }
7347 } finally {
7348 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007349 }
7350 }
7351
7352 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007353 * Checks if the device is capable of mobile data by considering whether whether the
7354 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7355 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007356 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007357 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007358 */
7359 @Override
7360 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007361 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007362 try {
7363 try {
7364 mApp.enforceCallingOrSelfPermission(
7365 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007366 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007367 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007368 try {
7369 mApp.enforceCallingOrSelfPermission(
7370 android.Manifest.permission.READ_PHONE_STATE,
7371 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007372 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007373 mApp.enforceCallingOrSelfPermission(
7374 permission.READ_BASIC_PHONE_STATE, functionName);
7375 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007376 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007377 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007378 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007379 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007380
7381 final long identity = Binder.clearCallingIdentity();
7382 try {
Jack Yu285100e2022-12-02 22:48:35 -08007383 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007384 Phone phone = PhoneFactory.getPhone(phoneId);
7385 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007386 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007387 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007388 return retVal;
7389 } else {
7390 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7391 return false;
7392 }
7393 } finally {
7394 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007395 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007396 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007397
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007398 /**
7399 * Check if data is enabled for a specific reason
7400 * @param subId Subscription index
7401 * @param reason the reason the data enable change is taking place
7402 * @return {@code true} if the overall data is enabled; {@code false} if not.
7403 */
7404 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007405 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007406 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007407 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007408 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007409 try {
7410 mApp.enforceCallingOrSelfPermission(
7411 android.Manifest.permission.ACCESS_NETWORK_STATE,
7412 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007413 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007414 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7415 functionName);
7416 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007417 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007418 try {
7419 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007420 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007421 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007422 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007423 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007424 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007425 }
7426
7427
7428 final long identity = Binder.clearCallingIdentity();
7429 try {
Jack Yu285100e2022-12-02 22:48:35 -08007430 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007431 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007432 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007433 + " reason=" + reason);
7434 }
7435 Phone phone = PhoneFactory.getPhone(phoneId);
7436 if (phone != null) {
7437 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007438 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007439 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007440 return retVal;
7441 } else {
7442 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007443 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007444 + subId + " retVal=false");
7445 }
7446 return false;
7447 }
7448 } finally {
7449 Binder.restoreCallingIdentity(identity);
7450 }
7451 }
7452
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007453 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007454 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007455 // No permission needed; this only lets the caller inspect their own status.
7456 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007457 }
Junda Liu29340342014-07-10 15:23:27 -07007458
7459 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007460 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007461 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007462 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7463 }
7464
7465 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7466 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007467 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007468 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007469 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7470 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007471 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7472 if (cpt == null) {
7473 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007474 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7475 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007476 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007477 }
7478
7479 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007480 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007481 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07007482 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007483 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007484 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007485 Phone phone = getPhone(subId);
7486 if (phone == null) {
7487 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7488 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7489 }
7490 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7491 if (cpt == null) {
7492 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007493 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7494 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007495 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007496 }
7497
7498 @Override
7499 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007500 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08007501 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7502 }
7503
7504 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007505 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007506 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007507 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007508 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007509 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7510 Phone phone = PhoneFactory.getPhone(phoneId);
7511 if (phone == null) {
7512 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007513 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007514 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7515 if (cpt == null) {
7516 continue;
7517 }
7518 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007519 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7520 break;
7521 }
7522 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007523 return result;
Junda Liu29340342014-07-10 15:23:27 -07007524 }
Derek Tan89e89d42014-07-08 17:00:10 -07007525
7526 @Override
Junda Liue64de782015-04-16 17:19:16 -07007527 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007528 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00007529 Phone phone = PhoneFactory.getPhone(phoneId);
7530 if (phone == null) {
7531 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007532 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007533 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7534 if (cpt == null) {
7535 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007536 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007537 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007538 }
7539
Amith Yamasani6e118872016-02-19 12:53:51 -08007540 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007541 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007542 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007543 Phone phone = PhoneFactory.getPhone(phoneId);
7544 if (phone == null) {
7545 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007546 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007547 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7548 if (cpt == null) {
7549 return Collections.emptyList();
7550 }
7551 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007552 }
7553
chen xuf7e9fe82019-05-09 19:31:02 -07007554 @Override
7555 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007556 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007557 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007558 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007559 try {
7560 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7561 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7562 }
7563 } finally {
7564 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007565 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007566 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007567 }
7568
Rambo Wang6812ffb2022-03-15 16:54:17 -07007569 @Override
7570 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7571 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7572
7573 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7574 if (phone == null) {
7575 return null;
7576 }
7577 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7578 if (cpt == null) {
7579 return null;
7580 }
7581 return cpt.getCarrierServicePackageName();
7582 }
7583
Wink Savilleb564aae2014-10-23 10:18:09 -07007584 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007585 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007586 UiccPort port = phone == null ? null : phone.getUiccPort();
7587 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007588 return null;
7589 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007590 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007591 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007592 return null;
7593 }
7594 return iccId;
7595 }
7596
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007597 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007598 public void setCallComposerStatus(int subId, int status) {
7599 enforceModifyPermission();
7600
7601 final long identity = Binder.clearCallingIdentity();
7602 try {
7603 Phone phone = getPhone(subId);
7604 if (phone != null) {
7605 Phone defaultPhone = phone.getImsPhone();
7606 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7607 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7608 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007609 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7610 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007611 }
7612 }
Shuo Qian284ae752020-12-22 19:10:14 -08007613 } catch (ImsException e) {
7614 throw new ServiceSpecificException(e.getCode());
7615 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007616 Binder.restoreCallingIdentity(identity);
7617 }
7618 }
7619
7620 @Override
7621 public int getCallComposerStatus(int subId) {
7622 enforceReadPrivilegedPermission("getCallComposerStatus");
7623
7624 final long identity = Binder.clearCallingIdentity();
7625 try {
7626 Phone phone = getPhone(subId);
7627 if (phone != null) {
7628 Phone defaultPhone = phone.getImsPhone();
7629 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7630 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7631 return imsPhone.getCallComposerStatus();
7632 }
7633 }
7634 } finally {
7635 Binder.restoreCallingIdentity(identity);
7636 }
7637 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7638 }
7639
7640 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007641 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7642 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007643 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007644 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007645
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007646 final long identity = Binder.clearCallingIdentity();
7647 try {
7648 final String iccId = getIccId(subId);
7649 final Phone phone = getPhone(subId);
7650 if (phone == null) {
7651 return false;
7652 }
7653 final String subscriberId = phone.getSubscriberId();
7654
7655 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007656 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007657 + subscriberId + " to " + number);
7658 }
7659
7660 if (TextUtils.isEmpty(iccId)) {
7661 return false;
7662 }
7663
7664 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7665
7666 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7667 if (alphaTag == null) {
7668 editor.remove(alphaTagPrefKey);
7669 } else {
7670 editor.putString(alphaTagPrefKey, alphaTag);
7671 }
7672
7673 // Record both the line number and IMSI for this ICCID, since we need to
7674 // track all merged IMSIs based on line number
7675 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7676 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7677 if (number == null) {
7678 editor.remove(numberPrefKey);
7679 editor.remove(subscriberPrefKey);
7680 } else {
7681 editor.putString(numberPrefKey, number);
7682 editor.putString(subscriberPrefKey, subscriberId);
7683 }
7684
7685 editor.commit();
7686 return true;
7687 } finally {
7688 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007689 }
Derek Tan7226c842014-07-02 17:42:23 -07007690 }
7691
7692 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007693 public String getLine1NumberForDisplay(int subId, String callingPackage,
7694 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007695 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007696 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007697 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007698 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007699 return null;
7700 }
Derek Tan97ebb422014-09-05 16:55:38 -07007701
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007702 final long identity = Binder.clearCallingIdentity();
7703 try {
7704 String iccId = getIccId(subId);
7705 if (iccId != null) {
7706 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7707 if (DBG_MERGE) {
7708 log("getLine1NumberForDisplay returning "
7709 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7710 }
7711 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007712 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007713 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7714 return null;
7715 } finally {
7716 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007717 }
Derek Tan7226c842014-07-02 17:42:23 -07007718 }
7719
7720 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007721 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7722 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007723 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007724 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007725 return null;
7726 }
Derek Tan97ebb422014-09-05 16:55:38 -07007727
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007728 final long identity = Binder.clearCallingIdentity();
7729 try {
7730 String iccId = getIccId(subId);
7731 if (iccId != null) {
7732 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7733 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7734 }
7735 return null;
7736 } finally {
7737 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007738 }
Derek Tan7226c842014-07-02 17:42:23 -07007739 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007740
7741 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007742 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7743 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007744 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7745 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007746 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007747 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007748 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007749 return null;
7750 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007751
Jordan Liub49b04b2019-05-06 14:45:15 -07007752 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7753 // the process, where TelephonyManager was instantiated.
7754 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007755 final long identity = Binder.clearCallingIdentity();
7756 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007757 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007758 final TelephonyManager tele = TelephonyManager.from(context);
7759 final SubscriptionManager sub = SubscriptionManager.from(context);
7760
7761 // Figure out what subscribers are currently active
7762 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007763
Jordan Liub49b04b2019-05-06 14:45:15 -07007764 // Only consider subs which match the current subId
7765 // This logic can be simplified. See b/131189269 for progress.
7766 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007767 activeSubscriberIds.add(tele.getSubscriberId(subId));
7768 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007769
7770 // First pass, find a number override for an active subscriber
7771 String mergeNumber = null;
7772 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7773 for (String key : prefs.keySet()) {
7774 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7775 final String subscriberId = (String) prefs.get(key);
7776 if (activeSubscriberIds.contains(subscriberId)) {
7777 final String iccId = key.substring(
7778 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7779 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7780 mergeNumber = (String) prefs.get(numberKey);
7781 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007782 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007783 + " for active subscriber " + subscriberId);
7784 }
7785 if (!TextUtils.isEmpty(mergeNumber)) {
7786 break;
7787 }
7788 }
7789 }
7790 }
7791
7792 // Shortcut when no active merged subscribers
7793 if (TextUtils.isEmpty(mergeNumber)) {
7794 return null;
7795 }
7796
7797 // Second pass, find all subscribers under that line override
7798 final ArraySet<String> result = new ArraySet<>();
7799 for (String key : prefs.keySet()) {
7800 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7801 final String number = (String) prefs.get(key);
7802 if (mergeNumber.equals(number)) {
7803 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7804 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7805 final String subscriberId = (String) prefs.get(subscriberKey);
7806 if (!TextUtils.isEmpty(subscriberId)) {
7807 result.add(subscriberId);
7808 }
7809 }
7810 }
7811 }
7812
7813 final String[] resultArray = result.toArray(new String[result.size()]);
7814 Arrays.sort(resultArray);
7815 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007816 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007817 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7818 }
7819 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007820 } finally {
7821 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007822 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007823 }
7824
7825 @Override
zoey chen38003472019-12-13 17:16:31 +08007826 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7827 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007828
7829 final long identity = Binder.clearCallingIdentity();
7830 try {
7831 final TelephonyManager telephonyManager = mApp.getSystemService(
7832 TelephonyManager.class);
7833 String subscriberId = telephonyManager.getSubscriberId(subId);
7834 if (subscriberId == null) {
7835 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007836 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007837 + subId);
7838 }
7839 return null;
7840 }
7841
Jack Yu285100e2022-12-02 22:48:35 -08007842 ParcelUuid groupUuid;
7843 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7844 final SubscriptionInfo info = SubscriptionManagerService.getInstance()
7845 .getSubscriptionInfo(subId);
7846 groupUuid = info.getGroupUuid();
7847 } else {
7848 final SubscriptionInfo info = mSubscriptionController
7849 .getSubscriptionInfo(subId);
7850 groupUuid = info.getGroupUuid();
7851 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007852 // If it doesn't belong to any group, return just subscriberId of itself.
7853 if (groupUuid == null) {
7854 return new String[]{subscriberId};
7855 }
7856
7857 // Get all subscriberIds from the group.
7858 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu285100e2022-12-02 22:48:35 -08007859 List<SubscriptionInfo> groupInfos;
7860 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7861 groupInfos = SubscriptionManagerService.getInstance()
7862 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7863 mApp.getAttributionTag());
7864 } else {
7865 groupInfos = mSubscriptionController
7866 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7867 mApp.getAttributionTag());
7868 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007869 for (SubscriptionInfo subInfo : groupInfos) {
7870 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7871 if (subscriberId != null) {
7872 mergedSubscriberIds.add(subscriberId);
7873 }
7874 }
7875
7876 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7877 } finally {
7878 Binder.restoreCallingIdentity(identity);
7879
7880 }
7881 }
7882
7883 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007884 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007885 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007886 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007887
7888 final long identity = Binder.clearCallingIdentity();
7889 try {
7890 final Phone phone = getPhone(subId);
7891 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7892 } finally {
7893 Binder.restoreCallingIdentity(identity);
7894 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007895 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007896
7897 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007898 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007899 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7900 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007901 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7902 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007903
7904 final long identity = Binder.clearCallingIdentity();
7905 try {
7906 final Phone phone = getPhone(subId);
7907 if (phone == null) {
7908 return false;
7909 }
7910 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7911 cdmaNonRoamingList);
7912 } finally {
7913 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007914 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007915 }
7916
7917 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007918 @Deprecated
7919 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7920 enforceModifyPermission();
7921
7922 int returnValue = 0;
7923 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007924 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007925 if(result.exception == null) {
7926 if (result.result != null) {
7927 byte[] responseData = (byte[])(result.result);
7928 if(responseData.length > oemResp.length) {
7929 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7930 responseData.length + "bytes. Buffer Size is " +
7931 oemResp.length + "bytes.");
7932 }
7933 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7934 returnValue = responseData.length;
7935 }
7936 } else {
7937 CommandException ex = (CommandException) result.exception;
7938 returnValue = ex.getCommandError().ordinal();
7939 if(returnValue > 0) returnValue *= -1;
7940 }
7941 } catch (RuntimeException e) {
7942 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7943 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7944 if(returnValue > 0) returnValue *= -1;
7945 }
7946
7947 return returnValue;
7948 }
7949
7950 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007951 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007952 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007953 try {
7954 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007955 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007956 mApp, phone.getSubId(), "getRadioAccessFamily");
7957 } catch (SecurityException e) {
7958 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7959 throw e;
7960 }
chen xub97461a2018-10-26 14:17:57 -07007961 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007962 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007963 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007964 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007965 final long identity = Binder.clearCallingIdentity();
7966 try {
chen xub97461a2018-10-26 14:17:57 -07007967 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007968 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007969 mApp, phone.getSubId(), "getRadioAccessFamily");
7970 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007971 } finally {
7972 Binder.restoreCallingIdentity(identity);
7973 }
chen xub97461a2018-10-26 14:17:57 -07007974 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007975 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007976
7977 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007978 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007979 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007980 try {
7981 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7982 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007983 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007984 }
7985 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007986 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007987 }
7988 RoleManager rm = mApp.getSystemService(RoleManager.class);
7989 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7990 if (!dialerRoleHolders.contains(callingPackage)) {
7991 throw new SecurityException("App must be the dialer role holder to"
7992 + " upload a call composer pic");
7993 }
7994
7995 Executors.newSingleThreadExecutor().execute(() -> {
7996 ByteArrayOutputStream output = new ByteArrayOutputStream(
7997 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7998 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7999 boolean readUntilEnd = false;
8000 int totalBytesRead = 0;
8001 byte[] buffer = new byte[16 * 1024];
8002 while (true) {
8003 int numRead;
8004 try {
8005 numRead = input.read(buffer);
8006 } catch (IOException e) {
8007 try {
8008 fd.checkError();
8009 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8010 null);
8011 } catch (IOException e1) {
8012 // This means that the other side closed explicitly with an error. If this
8013 // happens, log and ignore.
8014 loge("Remote end of call composer picture pipe closed: " + e1);
8015 }
8016 break;
8017 }
8018 if (numRead == -1) {
8019 readUntilEnd = true;
8020 break;
8021 }
8022 totalBytesRead += numRead;
8023 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8024 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8025 try {
8026 input.close();
8027 } catch (IOException e) {
8028 // ignore
8029 }
8030 break;
8031 }
8032 output.write(buffer, 0, numRead);
8033 }
8034 // Generally, the remote end will close the file descriptors. The only case where we
8035 // close is above, where the picture size is too big.
8036
8037 try {
8038 fd.checkError();
8039 } catch (IOException e) {
8040 loge("Remote end for call composer closed with an error: " + e);
8041 return;
8042 }
8043
Hall Liuaa4211e2021-01-20 15:43:39 -08008044 if (!readUntilEnd) {
8045 loge("Did not finish reading entire image; aborting");
8046 return;
8047 }
Hall Liu82694d52020-12-11 18:22:04 -08008048
Hall Liuaa4211e2021-01-20 15:43:39 -08008049 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8050 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8051 new CallComposerPictureTransfer.Factory() {},
8052 imageData,
8053 (result) -> {
8054 if (result.first != null) {
8055 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8056 Bundle outputResult = new Bundle();
8057 outputResult.putParcelable(
8058 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8059 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8060 outputResult);
8061 } else {
8062 callback.send(result.second, null);
8063 }
8064 }
8065 );
Hall Liu82694d52020-12-11 18:22:04 -08008066 });
8067 }
8068
8069 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008070 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008071 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008072 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008073
8074 final long identity = Binder.clearCallingIdentity();
8075 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008076 ImsManager.getInstance(defaultPhone.getContext(),
8077 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008078 } finally {
8079 Binder.restoreCallingIdentity(identity);
8080 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008081 }
8082
8083 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008084 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008085 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008086 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8087 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008088 return false;
8089 }
Svet Ganovb320e182015-04-16 12:30:10 -07008090
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008091 final long identity = Binder.clearCallingIdentity();
8092 try {
8093 // Check the user preference and the system-level IMS setting. Even if the user has
8094 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8095 // In the long run, we may instead need to check if there exists a connection service
8096 // which can support video calling.
8097 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008098 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008099 return imsManager.isVtEnabledByPlatform()
8100 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8101 && imsManager.isVtEnabledByUser();
8102 } finally {
8103 Binder.restoreCallingIdentity(identity);
8104 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008105 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008106
Andrew Leea1239f22015-03-02 17:44:07 -08008107 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008108 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8109 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008110 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008111 mApp, subId, callingPackage, callingFeatureId,
8112 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008113 return false;
8114 }
8115
8116 final long identity = Binder.clearCallingIdentity();
8117 try {
8118 CarrierConfigManager configManager =
8119 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008120 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008121 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8122 } finally {
8123 Binder.restoreCallingIdentity(identity);
8124 }
Andrew Leea1239f22015-03-02 17:44:07 -08008125 }
8126
8127 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008128 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008129 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008130 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008131 return false;
8132 }
8133
8134 final long identity = Binder.clearCallingIdentity();
8135 try {
8136 CarrierConfigManager configManager =
8137 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008138 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008139 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8140 } finally {
8141 Binder.restoreCallingIdentity(identity);
8142 }
Andrew Leea1239f22015-03-02 17:44:07 -08008143 }
8144
Andrew Lee9431b832015-03-09 18:46:45 -07008145 @Override
8146 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008147 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008148 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008149 }
8150
8151 @Override
8152 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008153 final long identity = Binder.clearCallingIdentity();
8154 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008155 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008156 } finally {
8157 Binder.restoreCallingIdentity(identity);
8158 }
Andrew Lee9431b832015-03-09 18:46:45 -07008159 }
8160
Hall Liuf6668912018-10-31 17:05:23 -07008161 /**
8162 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8163 * support for the feature and device firmware support.
8164 *
8165 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8166 */
8167 @Override
8168 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008169 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008170 final Phone phone = getPhone(subscriptionId);
8171 if (phone == null) {
8172 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8173 return false;
8174 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008175 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008176 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008177 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
8178 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008179 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008180 return isCarrierSupported && isDeviceSupported;
8181 } finally {
8182 Binder.restoreCallingIdentity(identity);
8183 }
Hall Liu98187582018-01-22 19:15:32 -08008184 }
8185
Hall Liuf6668912018-10-31 17:05:23 -07008186 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008187 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8188 * RTT setting, will return true if the device and carrier both support RTT.
8189 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008190 */
8191 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008192 final long identity = Binder.clearCallingIdentity();
8193 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00008194 boolean isRttSupported = isRttSupported(subscriptionId);
8195 boolean isUserRttSettingOn = Settings.Secure.getInt(
8196 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8197 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8198 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8199 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008200 } finally {
8201 Binder.restoreCallingIdentity(identity);
8202 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008203 }
8204
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008205 @Deprecated
8206 @Override
8207 public String getDeviceId(String callingPackage) {
8208 return getDeviceIdWithFeature(callingPackage, null);
8209 }
8210
Sanket Padawe7310cc72015-01-14 09:53:20 -08008211 /**
8212 * Returns the unique device ID of phone, for example, the IMEI for
8213 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8214 *
8215 * <p>Requires Permission:
8216 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8217 */
8218 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008219 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008220 try {
8221 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8222 } catch (SecurityException se) {
8223 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8224 throw new SecurityException("Package " + callingPackage + " does not belong to "
8225 + Binder.getCallingUid());
8226 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008227 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008228 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008229 return null;
8230 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008231 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008232 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008233 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008234 return null;
8235 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008236
8237 final long identity = Binder.clearCallingIdentity();
8238 try {
8239 return phone.getDeviceId();
8240 } finally {
8241 Binder.restoreCallingIdentity(identity);
8242 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008243 }
8244
Ping Sunc67b7c22016-03-02 19:16:45 +08008245 /**
8246 * {@hide}
8247 * Returns the IMS Registration Status on a particular subid
8248 *
8249 * @param subId
8250 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008251 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008252 Phone phone = getPhone(subId);
8253 if (phone != null) {
8254 return phone.isImsRegistered();
8255 } else {
8256 return false;
8257 }
8258 }
8259
Santos Cordon7a1885b2015-02-03 11:15:19 -08008260 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008261 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008262 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008263 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008264 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008265 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8266 }
8267 final long identity = Binder.clearCallingIdentity();
8268 try {
8269 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8270 } finally {
8271 Binder.restoreCallingIdentity(identity);
8272 }
8273 }
8274
8275 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008276 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008277 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008278 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008279 mApp,
8280 subscriptionId,
8281 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8282 + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07008283 final long identity = Binder.clearCallingIdentity();
8284 try {
8285 Phone phone = getPhone(subscriptionId);
8286 if (phone == null) {
8287 return null;
8288 }
8289 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8290 } finally {
8291 Binder.restoreCallingIdentity(identity);
8292 }
8293 }
8294
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008295 /**
8296 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008297 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008298 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008299 final long identity = Binder.clearCallingIdentity();
8300 try {
8301 Phone phone = getPhone(subId);
8302 if (phone != null) {
8303 return phone.isWifiCallingEnabled();
8304 } else {
8305 return false;
8306 }
8307 } finally {
8308 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008309 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008310 }
8311
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008312 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008313 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008314 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008315 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008316 final long identity = Binder.clearCallingIdentity();
8317 try {
8318 Phone phone = getPhone(subId);
8319 if (phone != null) {
8320 return phone.isVideoEnabled();
8321 } else {
8322 return false;
8323 }
8324 } finally {
8325 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008326 }
8327 }
8328
8329 /**
8330 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8331 * defined in {@link ImsRegistrationImplBase}.
8332 */
8333 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008334 final long identity = Binder.clearCallingIdentity();
8335 try {
8336 Phone phone = getPhone(subId);
8337 if (phone != null) {
8338 return phone.getImsRegistrationTech();
8339 } else {
8340 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8341 }
8342 } finally {
8343 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008344 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008345 }
8346
Stuart Scott8eef64f2015-04-08 15:13:54 -07008347 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008348 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008349 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07008350 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8351 return;
8352 }
Kai Shif70f46f2021-03-03 13:59:46 -08008353 Phone defaultPhone = getDefaultPhone();
8354 if (defaultPhone != null) {
8355 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8356 mApp, getDefaultPhone().getSubId(), "factoryReset");
8357 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008358 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008359
Svet Ganovcc087f82015-05-12 20:35:54 -07008360 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008361 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8362 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008363 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008364 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008365 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008366 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008367 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008368 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08008369 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008370 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008371 // There has been issues when Sms raw table somehow stores orphan
8372 // fragments. They lead to garbled message when new fragments come
8373 // in and combined with those stale ones. In case this happens again,
8374 // user can reset all network settings which will clean up this table.
8375 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008376 // Clean up IMS settings as well here.
8377 int slotId = getSlotIndex(subId);
8378 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8379 ImsManager.getInstance(mApp, slotId).factoryReset();
8380 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008381
Kai Shif70f46f2021-03-03 13:59:46 -08008382 if (defaultPhone == null) {
8383 return;
8384 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008385 // Erase modem config if erase modem on network setting is enabled.
8386 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8387 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8388 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008389 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008390 }
Kai Shif70f46f2021-03-03 13:59:46 -08008391
8392 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008393 } finally {
8394 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008395 }
8396 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008397
SongFerngWangfd89b102021-05-27 22:44:54 +08008398 @VisibleForTesting
8399 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8400 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8401 return;
8402 }
8403 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8404 RILConstants.PREFERRED_NETWORK_MODE);
8405 SubscriptionManager.setSubscriptionProperty(subId,
8406 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8407 "user=" + defaultNetworkType);
8408 phone.loadAllowedNetworksFromSubscriptionDatabase();
8409 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8410 defaultNetworkType, null);
8411 }
8412
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008413 private void cleanUpSmsRawTable(Context context) {
8414 ContentResolver resolver = context.getContentResolver();
8415 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8416 resolver.delete(uri, null, null);
8417 }
8418
Narayan Kamath1c496c22015-04-16 14:40:19 +01008419 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008420 public String getSimLocaleForSubscriber(int subId) {
8421 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
8422 final Phone phone = getPhone(subId);
8423 if (phone == null) {
8424 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008425 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008426 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008427 final long identity = Binder.clearCallingIdentity();
8428 try {
Jack Yu285100e2022-12-02 22:48:35 -08008429 SubscriptionInfo info;
8430 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
8431 info = SubscriptionManagerService.getInstance().getActiveSubscriptionInfo(subId,
8432 phone.getContext().getOpPackageName(),
8433 phone.getContext().getAttributionTag());
8434 if (info == null) {
8435 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8436 return null;
8437 }
8438 } else {
8439 info = mSubscriptionController.getActiveSubscriptionInfo(subId,
8440 phone.getContext().getOpPackageName(),
8441 phone.getContext().getAttributionTag());
8442 if (info == null) {
8443 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8444 return null;
8445 }
chen xu6291c472019-02-04 12:55:53 -08008446 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008447 // Try and fetch the locale from the carrier properties or from the SIM language
8448 // preferences (EF-PL and EF-LI)...
8449 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008450 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008451 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8452 if (localeFromDefaultSim != null) {
8453 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8454 if (DBG) log("Using locale from subId: " + subId + " locale: "
8455 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008456 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008457 } else {
8458 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008459 }
8460 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008461
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008462 // The SIM language preferences only store a language (e.g. fr = French), not an
8463 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8464 // the SIM and carrier preferences does not include a country we add the country
8465 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008466 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008467 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008468 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008469 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008470 }
8471
8472 if (DBG) log("No locale found - returning null");
8473 return null;
8474 } finally {
8475 Binder.restoreCallingIdentity(identity);
8476 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008477 }
8478
tom hsu0b59d292022-09-29 23:49:21 +08008479 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008480 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008481 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008482 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008483 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008484 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8485 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008486 Locale.forLanguageTag(localeTag).getCountry())) {
8487 return localeTag;
8488 }
8489 }
8490 return inputLocale.toLanguageTag();
8491 }
8492
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008493 /**
8494 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8495 */
8496 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu285100e2022-12-02 22:48:35 -08008497 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
8498 return SubscriptionManagerService.getInstance().getActiveSubscriptionInfoList(
8499 mApp.getOpPackageName(), mApp.getAttributionTag());
8500 }
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008501 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08008502 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01008503 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008504
Gary Jian3aa9a762022-01-24 16:41:19 +08008505 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8506 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008507
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008508 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008509 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8510 * representing the state of the modem.
8511 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008512 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8513 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008514 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008515 */
8516 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008517 public void requestModemActivityInfo(ResultReceiver result) {
8518 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008519 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008520
8521 final long identity = Binder.clearCallingIdentity();
8522 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008523 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008524 } finally {
8525 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008526 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008527 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008528
Gary Jian76280a42022-12-07 16:18:33 +08008529 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008530 // less than total activity duration.
8531 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8532 if (info == null) {
8533 return false;
8534 }
8535 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008536 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008537 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8538
Hall Liu49656c02020-10-09 19:00:11 -07008539 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8540
Siddharth Rayb8114062018-06-17 15:02:38 -07008541 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008542 && (info.getSleepTimeMillis() <= activityDurationMs)
8543 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008544 }
8545
Gary Jian3aa9a762022-01-24 16:41:19 +08008546 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8547 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8548 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8549 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8550
8551 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8552 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8553 }
8554
8555 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8556 mLastModemActivityInfo.setReceiveTimeMillis(
8557 rat,
8558 freq,
8559 info.getReceiveTimeMillis(rat, freq)
8560 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8561 }
8562
8563 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8564 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8565 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8566 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8567
8568 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8569 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8570 }
8571 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8572 mLastModemActivityInfo.setReceiveTimeMillis(
8573 rat,
8574 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8575 }
8576
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008577 /**
8578 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8579 * @param info recent ModemActivityInfo
8580 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008581 private void mergeModemActivityInfo(ModemActivityInfo info) {
8582 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008583 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008584 boolean matched;
8585 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8586 matched = false;
8587 int rat = info.getSpecificInfoRat(i);
8588 int freq = info.getSpecificInfoFrequencyRange(i);
8589 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8590 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8591 //if it already exists
8592 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8593 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8594 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8595 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8596 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8597 updateLastModemActivityInfo(info, rat, freq);
8598 matched = true;
8599 }
8600 } else {
8601 updateLastModemActivityInfo(info, rat);
8602 matched = true;
8603 }
8604 }
8605 }
8606
8607 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008608 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008609 new ActivityStatsTechSpecificInfo(
8610 rat,
8611 freq,
8612 info.getTransmitTimeMillis(rat, freq),
8613 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008614 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008615 }
8616 }
8617 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8618 mLastModemActivitySpecificInfo =
8619 new ActivityStatsTechSpecificInfo[merged.size()];
8620 merged.toArray(mLastModemActivitySpecificInfo);
8621
8622 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8623 mLastModemActivityInfo.setSleepTimeMillis(
8624 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008625 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008626 mLastModemActivityInfo.setIdleTimeMillis(
8627 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008628 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008629
8630 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008631 new ModemActivityInfo(
8632 mLastModemActivityInfo.getTimestampMillis(),
8633 mLastModemActivityInfo.getSleepTimeMillis(),
8634 mLastModemActivityInfo.getIdleTimeMillis(),
8635 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008636 }
8637
8638 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8639 ActivityStatsTechSpecificInfo[] info) {
8640 int infoSize = info.length;
8641 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8642 for (int i = 0; i < infoSize; i++) {
8643 ret[i] = new ActivityStatsTechSpecificInfo(
8644 info[i].getRat(), info[i].getFrequencyRange(),
8645 info[i].getTransmitTimeMillis(),
8646 (int) info[i].getReceiveTimeMillis());
8647 }
8648 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008649 }
8650
Jack Yu85bd38a2015-11-09 11:34:32 -08008651 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008652 * Returns the service state information on specified subscription.
8653 */
8654 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008655 public ServiceState getServiceStateForSubscriber(int subId,
8656 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8657 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008658 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008659 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008660 return null;
8661 }
8662
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008663 boolean hasFinePermission = false;
8664 boolean hasCoarsePermission = false;
8665 if (!renounceFineLocationAccess) {
8666 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8667 LocationAccessPolicy.checkLocationPermission(mApp,
8668 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8669 .setCallingPackage(callingPackage)
8670 .setCallingFeatureId(callingFeatureId)
8671 .setCallingPid(Binder.getCallingPid())
8672 .setCallingUid(Binder.getCallingUid())
8673 .setMethod("getServiceStateForSubscriber")
8674 .setLogAsInfo(true)
8675 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8676 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8677 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8678 .build());
8679 hasFinePermission =
8680 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8681 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008682
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008683 if (!renounceCoarseLocationAccess) {
8684 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8685 LocationAccessPolicy.checkLocationPermission(mApp,
8686 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8687 .setCallingPackage(callingPackage)
8688 .setCallingFeatureId(callingFeatureId)
8689 .setCallingPid(Binder.getCallingPid())
8690 .setCallingUid(Binder.getCallingUid())
8691 .setMethod("getServiceStateForSubscriber")
8692 .setLogAsInfo(true)
8693 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8694 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8695 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8696 .build());
8697 hasCoarsePermission =
8698 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8699 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008700
Jack Yu479f40e2020-10-27 21:29:25 -07008701 final Phone phone = getPhone(subId);
8702 if (phone == null) {
8703 return null;
8704 }
8705
Jordan Liu0f2bc442020-11-18 16:47:37 -08008706 final long identity = Binder.clearCallingIdentity();
8707
Jack Yu479f40e2020-10-27 21:29:25 -07008708 boolean isCallingPackageDataService = phone.getDataServicePackages()
8709 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008710 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008711 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu285100e2022-12-02 22:48:35 -08008712 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
8713 SubscriptionInfoInternal subInfo = SubscriptionManagerService.getInstance()
8714 .getSubscriptionInfoInternal(subId);
8715 if (subInfo == null || !subInfo.isActive()) {
8716 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8717 + "subId=" + subId);
8718 return null;
8719 }
8720 } else {
8721 if (!mSubscriptionController.isActiveSubId(subId, callingPackage,
8722 callingFeatureId)) {
8723 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8724 + "subId=" + subId);
8725 return null;
8726 }
Jordan Liuc437b192020-08-17 10:59:12 -07008727 }
8728
Hall Liuf19c44f2018-11-27 14:38:17 -08008729 ServiceState ss = phone.getServiceState();
8730
8731 // Scrub out the location info in ServiceState depending on what level of access
8732 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008733 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008734 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8735 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008736 } finally {
8737 Binder.restoreCallingIdentity(identity);
8738 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008739 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008740
8741 /**
8742 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8743 *
8744 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8745 * voicemail ringtone.
8746 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8747 * PhoneAccount.
8748 */
8749 @Override
8750 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008751 final long identity = Binder.clearCallingIdentity();
8752 try {
8753 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8754 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008755 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008756 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008757
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008758 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8759 } finally {
8760 Binder.restoreCallingIdentity(identity);
8761 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008762 }
8763
8764 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008765 * Sets the per-account voicemail ringtone.
8766 *
8767 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8768 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8769 *
8770 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8771 * voicemail ringtone.
8772 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8773 * PhoneAccount.
8774 */
8775 @Override
8776 public void setVoicemailRingtoneUri(String callingPackage,
8777 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008778 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008779 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008780 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8781 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008782 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8783 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8784 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008785 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008786
8787 final long identity = Binder.clearCallingIdentity();
8788 try {
8789 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8790 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008791 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008792 }
8793 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8794 } finally {
8795 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008796 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008797 }
8798
8799 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008800 * Returns whether vibration is set for voicemail notification in Phone settings.
8801 *
8802 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8803 * voicemail vibration setting.
8804 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8805 */
8806 @Override
8807 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008808 final long identity = Binder.clearCallingIdentity();
8809 try {
8810 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8811 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008812 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008813 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008814
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008815 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8816 } finally {
8817 Binder.restoreCallingIdentity(identity);
8818 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008819 }
8820
Youhan Wange64578a2016-05-02 15:32:42 -07008821 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008822 * Sets the per-account voicemail vibration.
8823 *
8824 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8825 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8826 *
8827 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8828 * voicemail vibration setting.
8829 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8830 * specific PhoneAccount.
8831 */
8832 @Override
8833 public void setVoicemailVibrationEnabled(String callingPackage,
8834 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008835 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008836 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008837 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8838 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008839 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8840 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8841 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008842 }
8843
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008844 final long identity = Binder.clearCallingIdentity();
8845 try {
8846 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8847 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008848 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008849 }
8850 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8851 } finally {
8852 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008853 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008854 }
8855
8856 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008857 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8858 *
8859 * @throws SecurityException if the caller does not have the required permission
8860 */
arunvoddud7401012022-12-15 16:08:12 +00008861 @VisibleForTesting
8862 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008863 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008864 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008865 }
8866
8867 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008868 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8869 * permission.
8870 *
8871 * @throws SecurityException if the caller does not have the required permission
8872 */
8873 private void enforceSendSmsPermission() {
8874 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8875 }
8876
8877 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00008878 * Make sure either called from same process as self (phone) or IPC caller has interact across
8879 * users permission.
8880 *
8881 * @throws SecurityException if the caller does not have the required permission
8882 */
8883 private void enforceInteractAcrossUsersPermission(String message) {
8884 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
8885 }
8886
8887 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008888 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008889 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008890 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008891 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008892 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008893 final long identity = Binder.clearCallingIdentity();
8894 try {
8895 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008896 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008897 if (componentName == null) {
8898 throw new SecurityException(
8899 "Caller not current active visual voicemail package[null]");
8900 }
8901 String vvmPackage = componentName.getPackageName();
8902 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008903 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008904 }
8905 } finally {
8906 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008907 }
8908 }
8909
8910 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008911 * Return the application ID for the app type.
8912 *
8913 * @param subId the subscription ID that this request applies to.
8914 * @param appType the uicc app type.
8915 * @return Application ID for specificied app type, or null if no uicc.
8916 */
8917 @Override
8918 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008919 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008920 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008921
8922 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008923 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008924 if (phone == null) {
8925 return null;
8926 }
8927 String aid = null;
8928 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008929 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008930 .getApplicationByType(appType).getAid();
8931 } catch (Exception e) {
8932 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8933 }
8934 return aid;
8935 } finally {
8936 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008937 }
Youhan Wange64578a2016-05-02 15:32:42 -07008938 }
8939
Youhan Wang4001d252016-05-11 10:29:41 -07008940 /**
8941 * Return the Electronic Serial Number.
8942 *
8943 * @param subId the subscription ID that this request applies to.
8944 * @return ESN or null if error.
8945 */
8946 @Override
8947 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008948 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008949 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008950
8951 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008952 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008953 if (phone == null) {
8954 return null;
8955 }
8956 String esn = null;
8957 try {
8958 esn = phone.getEsn();
8959 } catch (Exception e) {
8960 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8961 }
8962 return esn;
8963 } finally {
8964 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008965 }
Youhan Wang4001d252016-05-11 10:29:41 -07008966 }
8967
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008968 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008969 * Return the Preferred Roaming List Version.
8970 *
8971 * @param subId the subscription ID that this request applies to.
8972 * @return PRLVersion or null if error.
8973 */
8974 @Override
8975 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008976 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008977 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008978
8979 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008980 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008981 if (phone == null) {
8982 return null;
8983 }
8984 String cdmaPrlVersion = null;
8985 try {
8986 cdmaPrlVersion = phone.getCdmaPrlVersion();
8987 } catch (Exception e) {
8988 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8989 }
8990 return cdmaPrlVersion;
8991 } finally {
8992 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008993 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008994 }
8995
8996 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008997 * Get snapshot of Telephony histograms
8998 * @return List of Telephony histograms
8999 * @hide
9000 */
9001 @Override
9002 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009003 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9004 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009005
9006 final long identity = Binder.clearCallingIdentity();
9007 try {
9008 return RIL.getTelephonyRILTimingHistograms();
9009 } finally {
9010 Binder.restoreCallingIdentity(identity);
9011 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009012 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009013
9014 /**
9015 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009016 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9017 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009018 * Require system privileges. In the future we may add this to carrier APIs.
9019 *
Michele Berionne482f8202018-11-27 18:57:59 -08009020 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009021 */
9022 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009023 @TelephonyManager.SetCarrierRestrictionResult
9024 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009025 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07009026 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009027
Michele Berionne482f8202018-11-27 18:57:59 -08009028 if (carrierRestrictionRules == null) {
9029 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009030 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009031
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009032 final long identity = Binder.clearCallingIdentity();
9033 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009034 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009035 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009036 } finally {
9037 Binder.restoreCallingIdentity(identity);
9038 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009039 }
9040
9041 /**
9042 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009043 * Get the allowed carrier list and the excluded carrier list, including the priority between
9044 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009045 * Require system privileges. In the future we may add this to carrier APIs.
9046 *
Michele Berionne482f8202018-11-27 18:57:59 -08009047 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009048 */
9049 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009050 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009051 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07009052 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009053
9054 final long identity = Binder.clearCallingIdentity();
9055 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009056 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9057 if (response instanceof CarrierRestrictionRules) {
9058 return (CarrierRestrictionRules) response;
9059 }
9060 // Response is an Exception of some kind,
9061 // which is signalled to the user as a NULL retval
9062 return null;
9063 } catch (Exception e) {
9064 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9065 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009066 } finally {
9067 Binder.restoreCallingIdentity(identity);
9068 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009069 }
9070
fionaxu59545b42016-05-25 15:53:37 -07009071 /**
arunvoddud7401012022-12-15 16:08:12 +00009072 * Fetches the carrier restriction status of the device and sends the status to the caller
9073 * through the callback.
9074 *
9075 * @param callback The callback that will be used to send the result.
9076 * @throws SecurityException if the caller does not have the required permission/privileges or
9077 * the caller is not allowlisted.
9078 */
9079 @Override
9080 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
9081 enforceReadPermission("getCarrierRestrictionStatus");
9082 int carrierId = validateCallerAndGetCarrierId(packageName);
9083 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
9084 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9085 throw new SecurityException("Not an authorized caller");
9086 }
9087 final long identity = Binder.clearCallingIdentity();
9088 try {
9089 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
9090 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
9091 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9092 } finally {
9093 Binder.restoreCallingIdentity(identity);
9094 }
9095 }
9096
9097 @VisibleForTesting
9098 public int validateCallerAndGetCarrierId(String packageName) {
9099 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9100 return allowListInfo.validateCallerAndGetCarrierId(packageName);
9101 }
9102
9103 /**
fionaxu59545b42016-05-25 15:53:37 -07009104 * Action set from carrier signalling broadcast receivers to enable/disable radio
9105 * @param subId the subscription ID that this action applies to.
9106 * @param enabled control enable or disable radio.
9107 * {@hide}
9108 */
9109 @Override
9110 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9111 enforceModifyPermission();
9112 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009113
9114 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009115 if (phone == null) {
9116 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9117 return;
9118 }
9119 try {
9120 phone.carrierActionSetRadioEnabled(enabled);
9121 } catch (Exception e) {
9122 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009123 } finally {
9124 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009125 }
9126 }
9127
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009128 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009129 * Enable or disable Voice over NR (VoNR)
9130 * @param subId the subscription ID that this action applies to.
9131 * @param enabled enable or disable VoNR.
9132 * @return operation result.
9133 */
9134 @Override
9135 public int setVoNrEnabled(int subId, boolean enabled) {
9136 enforceModifyPermission();
9137 final Phone phone = getPhone(subId);
9138
9139 final long identity = Binder.clearCallingIdentity();
9140 if (phone == null) {
9141 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9142 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9143 }
9144
9145 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9146 try {
9147 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9148 workSource);
9149 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009150
9151 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9152 if (DBG) {
9153 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9154 }
9155 SubscriptionManager.setSubscriptionProperty(
9156 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9157 (enabled ? "1" : "0"));
9158 }
9159
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009160 return result;
9161 } finally {
9162 Binder.restoreCallingIdentity(identity);
9163 }
9164 }
9165
9166 /**
9167 * Is voice over NR enabled
9168 * @return true if VoNR is enabled else false
9169 */
9170 @Override
9171 public boolean isVoNrEnabled(int subId) {
9172 enforceReadPrivilegedPermission("isVoNrEnabled");
9173 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9174 final long identity = Binder.clearCallingIdentity();
9175 try {
9176 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9177 null, subId, workSource);
9178 if (DBG) log("isVoNrEnabled: " + isEnabled);
9179 return isEnabled;
9180 } finally {
9181 Binder.restoreCallingIdentity(identity);
9182 }
9183 }
9184
9185 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009186 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9187 * network status based on which carrier apps could apply actions accordingly,
9188 * enable/disable default url handler for example.
9189 *
9190 * @param subId the subscription ID that this action applies to.
9191 * @param report control start/stop reporting the default network status.
9192 * {@hide}
9193 */
9194 @Override
9195 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9196 enforceModifyPermission();
9197 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009198
9199 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009200 if (phone == null) {
9201 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9202 return;
9203 }
9204 try {
9205 phone.carrierActionReportDefaultNetworkStatus(report);
9206 } catch (Exception e) {
9207 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009208 } finally {
9209 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009210 }
9211 }
9212
9213 /**
fionaxud9622282017-07-17 17:51:30 -07009214 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9215 * @param subId the subscription ID that this action applies to.
9216 * {@hide}
9217 */
9218 @Override
9219 public void carrierActionResetAll(int subId) {
9220 enforceModifyPermission();
9221 final Phone phone = getPhone(subId);
9222 if (phone == null) {
9223 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9224 return;
9225 }
9226 try {
9227 phone.carrierActionResetAll();
9228 } catch (Exception e) {
9229 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9230 }
9231 }
9232
9233 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009234 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9235 * bug report is being generated.
9236 */
9237 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009238 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009239 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9240 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009241 writer.println("Permission Denial: can't dump Phone from pid="
9242 + Binder.getCallingPid()
9243 + ", uid=" + Binder.getCallingUid()
9244 + "without permission "
9245 + android.Manifest.permission.DUMP);
9246 return;
9247 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009248 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009249 }
Jack Yueb89b242016-06-22 13:27:47 -07009250
Brad Ebingerdac2f002018-04-03 15:17:52 -07009251 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009252 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9253 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9254 @NonNull String[] args) {
9255 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9256 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009257 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009258 }
9259
Jack Yueb89b242016-06-22 13:27:47 -07009260 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009261 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009262 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009263 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009264 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009265 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009266 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009267 */
9268 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009269 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009270 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009271 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9272 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9273 try {
9274 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009275 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009276 } catch (SecurityException se) {
9277 enforceModifyPermission();
9278 }
9279 } else {
9280 enforceModifyPermission();
9281 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009282
9283 final long identity = Binder.clearCallingIdentity();
9284 try {
9285 Phone phone = getPhone(subId);
9286 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009287 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9288 phone.carrierActionSetMeteredApnsEnabled(enabled);
9289 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07009290 phone.getDataSettingsManager().setDataEnabled(
9291 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009292 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009293 }
9294 } finally {
9295 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009296 }
9297 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009298
9299 /**
9300 * Get Client request stats
9301 * @return List of Client Request Stats
9302 * @hide
9303 */
9304 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009305 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9306 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009307 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009308 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009309 return null;
9310 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009311 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009312
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009313 final long identity = Binder.clearCallingIdentity();
9314 try {
9315 if (phone != null) {
9316 return phone.getClientRequestStats();
9317 }
9318
9319 return null;
9320 } finally {
9321 Binder.restoreCallingIdentity(identity);
9322 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009323 }
9324
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009325 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009326 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009327 if (uid == Process.ROOT_UID && packageName == null) {
9328 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9329 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9330 // exception. ROOT_UID seems not to have a valid package name returned by
9331 // PackageManager, so just fake it here to avoid issues when running telephony shell
9332 // commands that plumb through the RIL as root, like so:
9333 // $ adb root
9334 // $ adb shell cmd phone ...
9335 packageName = "root";
9336 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009337 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009338 }
Jack Yueb4124c2017-02-16 15:32:43 -08009339
9340 /**
Grace Chen70990072017-03-24 17:21:30 -07009341 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009342 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009343 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009344 * @param state State of SIM (power down, power up, pass through)
9345 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9346 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9347 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009348 *
9349 **/
9350 @Override
Grace Chen70990072017-03-24 17:21:30 -07009351 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009352 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009353 Phone phone = PhoneFactory.getPhone(slotIndex);
9354
vagdeviaf9a5b92018-08-15 16:01:53 -07009355 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9356
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009357 final long identity = Binder.clearCallingIdentity();
9358 try {
9359 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009360 phone.setSimPowerState(state, null, workSource);
9361 }
9362 } finally {
9363 Binder.restoreCallingIdentity(identity);
9364 }
9365 }
9366
9367 /**
9368 * Set SIM card power state.
9369 *
9370 * @param slotIndex SIM slot id.
9371 * @param state State of SIM (power down, power up, pass through)
9372 * @param callback callback to trigger after success or failure
9373 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9374 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9375 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9376 *
9377 **/
9378 @Override
9379 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9380 IIntegerConsumer callback) {
9381 enforceModifyPermission();
9382 Phone phone = PhoneFactory.getPhone(slotIndex);
9383
9384 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9385
9386 final long identity = Binder.clearCallingIdentity();
9387 try {
9388 if (phone != null) {
9389 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9390 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009391 }
9392 } finally {
9393 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009394 }
9395 }
Shuo Qiandd210312017-04-12 22:11:33 +00009396
Tyler Gunn65d45c22017-06-05 11:22:26 -07009397 private boolean isUssdApiAllowed(int subId) {
9398 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009399 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009400 if (configManager == null) {
9401 return false;
9402 }
9403 PersistableBundle pb = configManager.getConfigForSubId(subId);
9404 if (pb == null) {
9405 return false;
9406 }
9407 return pb.getBoolean(
9408 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9409 }
9410
Shuo Qiandd210312017-04-12 22:11:33 +00009411 /**
9412 * Check if phone is in emergency callback mode
9413 * @return true if phone is in emergency callback mode
9414 * @param subId sub id
9415 */
goneil9c5f4872017-12-05 14:07:56 -08009416 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009417 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009418 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00009419 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009420
9421 final long identity = Binder.clearCallingIdentity();
9422 try {
9423 if (phone != null) {
9424 return phone.isInEcm();
9425 } else {
9426 return false;
9427 }
9428 } finally {
9429 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009430 }
9431 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009432
9433 /**
9434 * Get the current signal strength information for the given subscription.
9435 * Because this information is not updated when the device is in a low power state
9436 * it should not be relied-upon to be current.
9437 * @param subId Subscription index
9438 * @return the most recent cached signal strength info from the modem
9439 */
9440 @Override
9441 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009442 final long identity = Binder.clearCallingIdentity();
9443 try {
9444 Phone p = getPhone(subId);
9445 if (p == null) {
9446 return null;
9447 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009448
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009449 return p.getSignalStrength();
9450 } finally {
9451 Binder.restoreCallingIdentity(identity);
9452 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009453 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009454
Pengquan Meng77b7f132018-08-22 14:49:57 -07009455 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009456 * Get the current modem radio state for the given slot.
9457 * @param slotIndex slot index.
9458 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009459 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009460 * @return the current radio power state from the modem
9461 */
9462 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009463 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009464 Phone phone = PhoneFactory.getPhone(slotIndex);
9465 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009466 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9467 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009468 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9469 }
9470
9471 final long identity = Binder.clearCallingIdentity();
9472 try {
9473 return phone.getRadioPowerState();
9474 } finally {
9475 Binder.restoreCallingIdentity(identity);
9476 }
9477 }
9478 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9479 }
9480
9481 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009482 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9483 *
9484 * <p>Requires one of the following permissions:
9485 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009486 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009487 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9488 * privileges.
9489 *
9490 * @param subId subscription id
9491 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9492 * {@code false}.
9493 */
9494 @Override
9495 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009496 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009497 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009498 try {
9499 mApp.enforceCallingOrSelfPermission(
9500 android.Manifest.permission.ACCESS_NETWORK_STATE,
9501 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009502 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009503 mApp.enforceCallingOrSelfPermission(
9504 permission.READ_BASIC_PHONE_STATE, functionName);
9505 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009506 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009507 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009508 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009509 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009510
Pengquan Menga1bb6272018-09-06 09:59:22 -07009511 boolean isEnabled = false;
9512 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009513 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009514 Phone phone = getPhone(subId);
9515 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009516 } finally {
9517 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009518 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009519 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009520 }
9521
9522
9523 /**
9524 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9525 *
9526 * <p> Requires permission:
9527 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9528 * privileges.
9529 *
9530 * @param subId subscription id
9531 * @param isEnabled {@code true} means enable, {@code false} means disable.
9532 */
9533 @Override
9534 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009535 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9536 mApp, subId, "setDataRoamingEnabled");
9537
Pengquan Menga1bb6272018-09-06 09:59:22 -07009538 final long identity = Binder.clearCallingIdentity();
9539 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009540 Phone phone = getPhone(subId);
9541 if (phone != null) {
9542 phone.setDataRoamingEnabled(isEnabled);
9543 }
9544 } finally {
9545 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009546 }
9547 }
9548
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009549 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009550 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009551 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009552 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009553 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009554
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009555 boolean isAllowed = true;
9556 final long identity = Binder.clearCallingIdentity();
9557 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009558 Phone phone = getPhone(subId);
9559 if (phone != null) {
9560 isAllowed = phone.isCspPlmnEnabled();
9561 }
9562 } finally {
9563 Binder.restoreCallingIdentity(identity);
9564 }
9565 return isAllowed;
9566 }
9567
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009568 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9569 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009570 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009571 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009572 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009573 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9574 if (phone == null) {
9575 return false;
9576 }
9577 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9578 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9579 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009580 }
9581
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009582 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009583 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009584 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009585 mApp.getSystemService(AppOpsManager.class)
9586 .checkPackage(Binder.getCallingUid(), callingPackage);
9587
Jordan Liu1e142fc2019-04-22 15:10:43 -07009588 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009589 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009590 try {
9591 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009592 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009593 } catch (SecurityException e) {
9594 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9595 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009596 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009597 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009598 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009599 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009600 }
sandeepjsb6c87872021-09-27 15:34:44 +00009601 // checking compatibility, if calling app's target SDK is T and beyond.
9602 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9603 Binder.getCallingUid())) {
9604 isIccIdAccessRestricted = true;
9605 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009606 final long identity = Binder.clearCallingIdentity();
9607 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009608 UiccController uiccController = UiccController.getInstance();
9609 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009610 if (hasReadPermission) {
9611 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009612 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009613
9614 // Remove private info if the caller doesn't have access
9615 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9616 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009617 //setting the value after compatibility check
9618 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009619 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9620 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009621 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009622 if (card == null) {
9623 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009624 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009625 continue;
9626 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009627 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9628 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009629 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009630 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009631 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009632 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9633 for (UiccPortInfo portInfo : portInfos) {
9634 UiccPort port = uiccController.getUiccPortForSlot(
9635 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9636 if (port == null) {
9637 // assume no access if port is null
9638 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9639 continue;
9640 }
9641 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9642 uiccPortInfos.add(portInfo);
9643 } else {
9644 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9645 }
9646 }
9647 filteredInfos.add(new UiccCardInfo(
9648 cardInfo.isEuicc(),
9649 cardInfo.getCardId(),
9650 null,
9651 cardInfo.getPhysicalSlotIndex(),
9652 cardInfo.isRemovable(),
9653 cardInfo.isMultipleEnabledProfilesSupported(),
9654 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009655 }
9656 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009657 } finally {
9658 Binder.restoreCallingIdentity(identity);
9659 }
9660 }
9661
sandeepjsb6c87872021-09-27 15:34:44 +00009662 /**
9663 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9664 * generally private and require carrier privileges to view.
9665 *
9666 * @hide
9667 */
9668 @NonNull
9669 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9670 List<UiccPortInfo> portinfo = new ArrayList<>();
9671 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9672 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9673 }
9674 return new UiccCardInfo(
9675 cardInfo.isEuicc(),
9676 cardInfo.getCardId(),
9677 null,
9678 cardInfo.getPhysicalSlotIndex(),
9679 cardInfo.isRemovable(),
9680 cardInfo.isMultipleEnabledProfilesSupported(),
9681 portinfo
9682 );
9683 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009684
sandeepjsb6c87872021-09-27 15:34:44 +00009685 /**
9686 * @hide
9687 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9688 * These values are generally private and require carrier privileges to view.
9689 */
9690 @NonNull
9691 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9692 return new UiccPortInfo(
9693 UiccPortInfo.ICCID_REDACTED,
9694 portInfo.getPortIndex(),
9695 portInfo.getLogicalSlotIndex(),
9696 portInfo.isActive()
9697 );
9698 }
9699 @Override
9700 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009701 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009702 mApp.getSystemService(AppOpsManager.class)
9703 .checkPackage(Binder.getCallingUid(), callingPackage);
9704
sandeepjsb6c87872021-09-27 15:34:44 +00009705 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009706
Aman Guptaf3c90b32022-03-17 04:54:16 +00009707 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9708 // we are reading iccId which is PII data.
9709 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009710
9711 // checking compatibility, if calling app's target SDK is T and beyond.
9712 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9713 Binder.getCallingUid())) {
9714 isLogicalSlotAccessRestricted = true;
9715 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009716 final long identity = Binder.clearCallingIdentity();
9717 try {
9718 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009719 if (slots == null || slots.length == 0) {
9720 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009721 return null;
9722 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009723 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9724 for (int i = 0; i < slots.length; i++) {
9725 UiccSlot slot = slots[i];
9726 if (slot == null) {
9727 continue;
9728 }
9729
Jordan Liu7be7e652019-05-06 18:55:02 +00009730 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009731 UiccCard card = slot.getUiccCard();
9732 if (card != null) {
9733 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009734 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009735 cardId = slot.getEid();
9736 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009737 // If cardId is null, use iccId of default port as cardId.
9738 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009739 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009740 }
9741
Jordan Liu857451f2019-05-09 16:35:35 -07009742 if (cardId != null) {
9743 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9744 // if cardId is an EID, it's all digits so this is fine
9745 cardId = IccUtils.stripTrailingFs(cardId);
9746 }
9747
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009748 int cardState = 0;
9749 switch (slot.getCardState()) {
9750 case CARDSTATE_ABSENT:
9751 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9752 break;
9753 case CARDSTATE_PRESENT:
9754 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9755 break;
9756 case CARDSTATE_ERROR:
9757 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9758 break;
9759 case CARDSTATE_RESTRICTED:
9760 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9761 break;
9762 default:
9763 break;
9764
9765 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009766 List<UiccPortInfo> portInfos = new ArrayList<>();
9767 int[] portIndexes = slot.getPortList();
9768 for (int portIdx : portIndexes) {
9769 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009770 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009771 portInfos.add(new UiccPortInfo(iccId, portIdx,
9772 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009773 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009774 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009775 slot.isEuicc(),
9776 cardId,
9777 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009778 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009779 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009780 //setting the value after compatibility check
9781 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009782 }
9783 return infos;
9784 } finally {
9785 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009786 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009787 }
9788
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009789 /* Returns null if doesn't have read permission or carrier privilege access. */
9790 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9791 boolean hasReadPermission) {
9792 String iccId = slot.getIccId(portIndex);
9793 if (hasReadPermission) { // if has read permission
9794 return iccId;
9795 } else {
9796 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9797 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9798 // if no read permission, checking carrier privilege access
9799 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9800 return iccId;
9801 }
9802 }
9803 }
9804 // No read permission or carrier privilege access.
9805 return UiccPortInfo.ICCID_REDACTED;
9806 }
9807
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009808 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009809 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009810 public boolean switchSlots(int[] physicalSlots) {
9811 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009812
9813 final long identity = Binder.clearCallingIdentity();
9814 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009815 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9816 for (int i = 0; i < physicalSlots.length; i++) {
9817 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9818 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9819 physicalSlots[i], i));
9820 }
9821 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009822 } finally {
9823 Binder.restoreCallingIdentity(identity);
9824 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009825 }
Jack Yu4c988042018-02-27 15:30:01 -08009826
9827 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009828 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9829 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9830 enforceModifyPermission();
9831
9832 final long identity = Binder.clearCallingIdentity();
9833 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009834 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009835 } finally {
9836 Binder.restoreCallingIdentity(identity);
9837 }
9838 }
9839
9840 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009841 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009842 final long identity = Binder.clearCallingIdentity();
9843 try {
9844 return UiccController.getInstance().getCardIdForDefaultEuicc();
9845 } finally {
9846 Binder.restoreCallingIdentity(identity);
9847 }
9848 }
9849
Pengquan Meng85728fb2018-03-12 16:31:21 -07009850 /**
goneil47ffb6e2018-04-06 15:40:58 -07009851 * A test API to reload the UICC profile.
9852 *
9853 * <p>Requires that the calling app has permission
9854 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9855 * @hide
9856 */
9857 @Override
9858 public void refreshUiccProfile(int subId) {
9859 enforceModifyPermission();
9860
9861 final long identity = Binder.clearCallingIdentity();
9862 try {
9863 Phone phone = getPhone(subId);
9864 if (phone == null) {
9865 return;
9866 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009867 UiccPort uiccPort = phone.getUiccPort();
9868 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009869 return;
9870 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009871 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009872 if (uiccProfile == null) {
9873 return;
9874 }
9875 uiccProfile.refresh();
9876 } finally {
9877 Binder.restoreCallingIdentity(identity);
9878 }
9879 }
9880
9881 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009882 * Returns false if the mobile data is disabled by default, otherwise return true.
9883 */
9884 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009885 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009886 }
9887
9888 /**
9889 * Returns true if the data roaming is enabled by default, i.e the system property
9890 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9891 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9892 */
9893 private boolean getDefaultDataRoamingEnabled(int subId) {
9894 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009895 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009896 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009897 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9898 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9899 return isDataRoamingEnabled;
9900 }
9901
9902 /**
9903 * Returns the default network type for the given {@code subId}, if the default network type is
9904 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9905 */
9906 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009907 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -08009908 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +09009909 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9910 return list.get(phoneId);
9911 }
9912 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009913 }
fionaxua13278b2018-03-21 00:08:13 -07009914
9915 @Override
9916 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009917 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009918 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009919
9920 final long identity = Binder.clearCallingIdentity();
9921 try {
9922 final Phone phone = getPhone(subId);
9923 if (phone == null) {
9924 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9925 return;
9926 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009927 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9928 if (cpt != null) {
9929 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9930 }
9931 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009932 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9933 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009934 if (carrierPrivilegeRules == null) {
9935 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9936 } else {
9937 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9938 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009939 } finally {
9940 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009941 }
fionaxua13278b2018-03-21 00:08:13 -07009942 }
9943
9944 @Override
9945 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009946 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009947
9948 final long identity = Binder.clearCallingIdentity();
9949 try {
9950 final Phone phone = getPhone(subId);
9951 if (phone == null) {
9952 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9953 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9954 }
9955 return phone.getCarrierIdListVersion();
9956 } finally {
9957 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009958 }
fionaxua13278b2018-03-21 00:08:13 -07009959 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009960
9961 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009962 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9963 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009964 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009965 mApp, subId, callingPackage, callingFeatureId,
9966 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009967 return -1;
9968 }
9969
9970 final long identity = Binder.clearCallingIdentity();
9971 try {
9972 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9973 } finally {
9974 Binder.restoreCallingIdentity(identity);
9975 }
9976 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009977
9978 @Override
9979 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009980 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009981 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009982 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -07009983
9984 final long identity = Binder.clearCallingIdentity();
9985 try {
9986 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9987 } finally {
9988 Binder.restoreCallingIdentity(identity);
9989 }
9990 }
9991
9992 @Override
9993 public boolean setCdmaRoamingMode(int subId, int mode) {
9994 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9995 mApp, subId, "setCdmaRoamingMode");
9996
9997 final long identity = Binder.clearCallingIdentity();
9998 try {
9999 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10000 } finally {
10001 Binder.restoreCallingIdentity(identity);
10002 }
10003 }
10004
10005 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010006 public int getCdmaSubscriptionMode(int subId) {
10007 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010008 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010009 mApp, subId, "getCdmaSubscriptionMode");
10010
10011 final long identity = Binder.clearCallingIdentity();
10012 try {
10013 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10014 } finally {
10015 Binder.restoreCallingIdentity(identity);
10016 }
10017 }
10018
10019 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010020 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10021 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10022 mApp, subId, "setCdmaSubscriptionMode");
10023
10024 final long identity = Binder.clearCallingIdentity();
10025 try {
10026 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10027 } finally {
10028 Binder.restoreCallingIdentity(identity);
10029 }
10030 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010031
sqianc5eccab2018-10-19 18:46:41 -070010032 @Override
sqian8c685422019-02-22 15:55:18 -080010033 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010034 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010035 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010036 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10037 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010038 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10039 }
10040 final long identity = Binder.clearCallingIdentity();
10041 try {
sqian854d44b2018-12-12 16:48:18 -080010042 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10043 for (Phone phone: PhoneFactory.getPhones()) {
10044 if (phone.getEmergencyNumberTracker() != null
10045 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10046 emergencyNumberListInternal.put(
10047 phone.getSubId(),
10048 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10049 }
sqian11b7a0e2018-12-05 18:48:28 -080010050 }
sqian854d44b2018-12-12 16:48:18 -080010051 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010052 } finally {
10053 Binder.restoreCallingIdentity(identity);
10054 }
sqianc5eccab2018-10-19 18:46:41 -070010055 }
10056
10057 @Override
sqian8c685422019-02-22 15:55:18 -080010058 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010059 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010060 if (!exactMatch) {
10061 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010062 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010063 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010064 }
10065 final long identity = Binder.clearCallingIdentity();
10066 try {
sqian854d44b2018-12-12 16:48:18 -080010067 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010068 //Note: we ignore passed in param exactMatch. We can remove it once
10069 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010070 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010071 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010072 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010073 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010074 }
sqian11b7a0e2018-12-05 18:48:28 -080010075 }
10076 return false;
10077 } finally {
10078 Binder.restoreCallingIdentity(identity);
10079 }
10080 }
10081
sqianf4ca7ed2019-01-15 18:32:07 -080010082 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010083 * Start emergency callback mode for GsmCdmaPhone for testing.
10084 */
10085 @Override
10086 public void startEmergencyCallbackMode() {
10087 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10088 "startEmergencyCallbackMode");
10089 enforceModifyPermission();
10090 final long identity = Binder.clearCallingIdentity();
10091 try {
10092 for (Phone phone : PhoneFactory.getPhones()) {
10093 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10094 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10095 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10096 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10097 gsmCdmaPhone.obtainMessage(
10098 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10099 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10100 }
10101 }
10102 } finally {
10103 Binder.restoreCallingIdentity(identity);
10104 }
10105 }
10106
10107 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010108 * Update emergency number list for test mode.
10109 */
10110 @Override
10111 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10112 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10113 "updateEmergencyNumberListTestMode");
10114
10115 final long identity = Binder.clearCallingIdentity();
10116 try {
10117 for (Phone phone: PhoneFactory.getPhones()) {
10118 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10119 if (tracker != null) {
10120 tracker.executeEmergencyNumberTestModeCommand(action, num);
10121 }
10122 }
10123 } finally {
10124 Binder.restoreCallingIdentity(identity);
10125 }
10126 }
10127
10128 /**
10129 * Get the full emergency number list for test mode.
10130 */
10131 @Override
10132 public List<String> getEmergencyNumberListTestMode() {
10133 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10134 "getEmergencyNumberListTestMode");
10135
10136 final long identity = Binder.clearCallingIdentity();
10137 try {
10138 Set<String> emergencyNumbers = new HashSet<>();
10139 for (Phone phone: PhoneFactory.getPhones()) {
10140 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10141 if (tracker != null) {
10142 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10143 emergencyNumbers.add(num.getNumber());
10144 }
10145 }
10146 }
10147 return new ArrayList<>(emergencyNumbers);
10148 } finally {
10149 Binder.restoreCallingIdentity(identity);
10150 }
10151 }
10152
chen xud6b45bd2018-10-30 22:27:10 -070010153 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010154 public int getEmergencyNumberDbVersion(int subId) {
10155 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10156
10157 final long identity = Binder.clearCallingIdentity();
10158 try {
10159 final Phone phone = getPhone(subId);
10160 if (phone == null) {
10161 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10162 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10163 }
10164 return phone.getEmergencyNumberDbVersion();
10165 } finally {
10166 Binder.restoreCallingIdentity(identity);
10167 }
10168 }
10169
10170 @Override
10171 public void notifyOtaEmergencyNumberDbInstalled() {
10172 enforceModifyPermission();
10173
10174 final long identity = Binder.clearCallingIdentity();
10175 try {
10176 for (Phone phone: PhoneFactory.getPhones()) {
10177 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10178 if (tracker != null) {
10179 tracker.updateOtaEmergencyNumberDatabase();
10180 }
10181 }
10182 } finally {
10183 Binder.restoreCallingIdentity(identity);
10184 }
10185 }
10186
10187 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010188 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010189 enforceActiveEmergencySessionPermission();
10190
10191 final long identity = Binder.clearCallingIdentity();
10192 try {
10193 for (Phone phone: PhoneFactory.getPhones()) {
10194 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10195 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010196 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10197 }
10198 }
10199 } finally {
10200 Binder.restoreCallingIdentity(identity);
10201 }
10202 }
10203
10204 @Override
10205 public void resetOtaEmergencyNumberDbFilePath() {
10206 enforceActiveEmergencySessionPermission();
10207
10208 final long identity = Binder.clearCallingIdentity();
10209 try {
10210 for (Phone phone: PhoneFactory.getPhones()) {
10211 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10212 if (tracker != null) {
10213 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010214 }
10215 }
10216 } finally {
10217 Binder.restoreCallingIdentity(identity);
10218 }
10219 }
10220
10221 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010222 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10223 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10224 Phone phone = getPhone(subId);
10225 if (phone == null) {
10226 return null;
10227 }
10228 final long identity = Binder.clearCallingIdentity();
10229 try {
10230 UiccProfile profile = UiccController.getInstance()
10231 .getUiccProfileForPhone(phone.getPhoneId());
10232 if (profile != null) {
10233 return profile.getCertsFromCarrierPrivilegeAccessRules();
10234 }
10235 } finally {
10236 Binder.restoreCallingIdentity(identity);
10237 }
10238 return null;
10239 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010240
10241 /**
10242 * Enable or disable a modem stack.
10243 */
10244 @Override
10245 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10246 enforceModifyPermission();
10247
10248 final long identity = Binder.clearCallingIdentity();
10249 try {
10250 Phone phone = PhoneFactory.getPhone(slotIndex);
10251 if (phone == null) {
10252 return false;
10253 } else {
10254 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10255 }
10256 } finally {
10257 Binder.restoreCallingIdentity(identity);
10258 }
10259 }
Michelecea4cf22018-12-21 15:00:11 -080010260
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010261 /**
10262 * Whether a modem stack is enabled or not.
10263 */
10264 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010265 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10266 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010267 Phone phone = PhoneFactory.getPhone(slotIndex);
10268 if (phone == null) return false;
10269
10270 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010271 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10272 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010273 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10274 }
10275
10276 final long identity = Binder.clearCallingIdentity();
10277 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010278 try {
10279 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10280 } catch (NoSuchElementException ex) {
10281 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10282 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010283 } finally {
10284 Binder.restoreCallingIdentity(identity);
10285 }
10286 }
10287
Michelecea4cf22018-12-21 15:00:11 -080010288 @Override
Michele0ea7d782019-03-19 14:58:42 -070010289 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010290 enforceModifyPermission();
10291
10292 final long identity = Binder.clearCallingIdentity();
10293 try {
10294 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010295 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010296 .commit();
10297 } finally {
10298 Binder.restoreCallingIdentity(identity);
10299 }
10300 }
10301
10302 @Override
Michele0ea7d782019-03-19 14:58:42 -070010303 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010304 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010305 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010306 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10307 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010308 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010309 }
Michelecea4cf22018-12-21 15:00:11 -080010310
10311 final long identity = Binder.clearCallingIdentity();
10312 try {
Michele0ea7d782019-03-19 14:58:42 -070010313 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010314 } finally {
10315 Binder.restoreCallingIdentity(identity);
10316 }
10317 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010318
Michele0ea7d782019-03-19 14:58:42 -070010319 @TelephonyManager.IsMultiSimSupportedResult
10320 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010321 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10322 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10323 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010324 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10325 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010326 }
10327 // Check if the hardware supports multisim functionality. If usage of multisim is not
10328 // supported by the modem, indicate that it is restricted.
10329 PhoneCapability staticCapability =
10330 mPhoneConfigurationManager.getStaticPhoneCapability();
10331 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010332 loge("isMultiSimSupportedInternal: no static configuration available");
10333 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010334 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010335 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010336 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10337 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010338 }
10339 // Check if support of multiple SIMs is restricted by carrier
10340 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010341 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010342 }
10343
Michele0ea7d782019-03-19 14:58:42 -070010344 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010345 }
10346
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010347 /**
10348 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010349 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10350 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10351 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010352 * @param numOfSims number of active sims we want to switch to
10353 */
10354 @Override
10355 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010356 if (numOfSims == 1) {
10357 enforceModifyPermission();
10358 } else {
10359 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10360 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10361 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010362 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010363
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010364 try {
Michele30b57b22019-03-01 12:01:14 -080010365 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010366 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010367 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10368 return;
10369 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010370 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10371 } finally {
10372 Binder.restoreCallingIdentity(identity);
10373 }
10374 }
10375
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010376 @Override
10377 public boolean isApplicationOnUicc(int subId, int appType) {
10378 enforceReadPrivilegedPermission("isApplicationOnUicc");
10379 Phone phone = getPhone(subId);
10380 if (phone == null) {
10381 return false;
10382 }
10383 final long identity = Binder.clearCallingIdentity();
10384 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010385 UiccPort uiccPort = phone.getUiccPort();
10386 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010387 return false;
10388 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010389 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010390 if (uiccProfile == null) {
10391 return false;
10392 }
10393 if (TelephonyManager.APPTYPE_SIM <= appType
10394 && appType <= TelephonyManager.APPTYPE_ISIM) {
10395 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10396 }
10397 return false;
10398 } finally {
10399 Binder.restoreCallingIdentity(identity);
10400 }
10401 }
10402
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010403 /**
chen xub4baa772019-04-03 10:23:41 -070010404 * Get whether making changes to modem configurations will trigger reboot.
10405 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010406 */
10407 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010408 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10409 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010410 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010411 mApp, subId, callingPackage, callingFeatureId,
10412 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010413 return false;
10414 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010415 final long identity = Binder.clearCallingIdentity();
10416 try {
10417 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10418 } finally {
10419 Binder.restoreCallingIdentity(identity);
10420 }
10421 }
10422
Nathan Harold29f5f052019-02-15 13:41:57 -080010423 private void updateModemStateMetrics() {
10424 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10425 // TODO: check the state for each modem if the api is ready.
10426 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10427 }
10428
Pengquan Meng3889a572019-01-23 11:16:29 -080010429 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010430 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010431 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010432 // Verify that the callingPackage belongs to the calling UID
10433 mApp.getSystemService(AppOpsManager.class)
10434 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -080010435 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010436 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010437 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010438 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10439 if (slotInfos != null) {
10440 for (int i = 0; i < slotInfos.length; i++) {
10441 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10442 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10443 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10444 portInfo.getLogicalSlotIndex()));
10445 }
10446 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010447 }
10448 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010449 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010450 } finally {
10451 Binder.restoreCallingIdentity(identity);
10452 }
10453 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010454
10455 /**
10456 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010457 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010458 */
jimsunf9ec1622022-09-13 21:18:43 +080010459 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010460 @Override
10461 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010462 return getHalVersion(HAL_SERVICE_RADIO);
10463 }
10464
10465 /**
10466 * Get the HAL Version of a specific service
10467 */
10468 @Override
10469 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010470 Phone phone = getDefaultPhone();
10471 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010472 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010473 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10474 return hv.major * 100 + hv.minor;
10475 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010476
10477 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010478 * Get the current calling package name.
10479 * @return the current calling package name
10480 */
10481 @Override
10482 public String getCurrentPackageName() {
10483 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
10484 }
10485
10486 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010487 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10488 * corresponding network requests on a subId.
10489 *
10490 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010491 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010492 * 2) APN is un-metered for this subscription, or
10493 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010494 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010495 *
10496 * @return whether data is allowed for a apn type.
10497 *
10498 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010499 */
10500 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010501 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010502 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10503 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010504
10505 // Now that all security checks passes, perform the operation as ourselves.
10506 final long identity = Binder.clearCallingIdentity();
10507 try {
10508 Phone phone = getPhone(subId);
10509 if (phone == null) return false;
10510
Jack Yu27422a52022-03-21 10:38:05 -070010511 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010512 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010513 isMetered = phone.getDataNetworkController().getDataConfigManager()
10514 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10515 phone.getServiceState().getDataRoaming());
10516 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010517 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010518 } finally {
10519 Binder.restoreCallingIdentity(identity);
10520 }
10521 }
10522
10523 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010524 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010525 enforceReadPrivilegedPermission("isApnMetered");
10526
10527 // Now that all security checks passes, perform the operation as ourselves.
10528 final long identity = Binder.clearCallingIdentity();
10529 try {
10530 Phone phone = getPhone(subId);
10531 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010532 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10533 DataUtils.apnTypeToNetworkCapability(apnType),
10534 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010535 } finally {
10536 Binder.restoreCallingIdentity(identity);
10537 }
10538 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010539
10540 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010541 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10542 int subscriptionId, IBooleanConsumer resultCallback) {
10543 enforceModifyPermission();
10544 long token = Binder.clearCallingIdentity();
10545 try {
10546 Phone phone = getPhone(subscriptionId);
10547 if (phone == null) {
10548 try {
10549 if (resultCallback != null) {
10550 resultCallback.accept(false);
10551 }
10552 } catch (RemoteException e) {
10553 // ignore
10554 }
10555 return;
10556 }
10557 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10558 Pair.create(specifiers, (x) -> {
10559 try {
10560 if (resultCallback != null) {
10561 resultCallback.accept(x);
10562 }
10563 } catch (RemoteException e) {
10564 // ignore
10565 }
10566 });
10567 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10568 } finally {
10569 Binder.restoreCallingIdentity(token);
10570 }
10571 }
10572
10573 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010574 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10575 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010576 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010577 mApp, subId, "getSystemSelectionChannels");
10578 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10579 final long identity = Binder.clearCallingIdentity();
10580 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010581 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10582 if (result instanceof IllegalStateException) {
10583 throw (IllegalStateException) result;
10584 }
10585 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010586 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10587 return specifiers;
10588 } finally {
10589 Binder.restoreCallingIdentity(identity);
10590 }
10591 }
10592
10593 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010594 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010595 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010596 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010597 }
10598
10599 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010600 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10601 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010602 if (callingPackage == null) {
10603 callingPackage = getCurrentPackageName();
10604 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010605 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10606 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010607 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10608 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010609 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10610 }
10611 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10612 Intent intent = new Intent();
10613 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10614 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10615 // Bring up choose default SMS subscription dialog right now
10616 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10617 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10618 mApp.startActivity(intent);
10619 }
chen xud5ca2d52019-05-28 15:20:57 -070010620
10621 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010622 public void showSwitchToManagedProfileDialog() {
10623 enforceModifyPermission();
10624
10625 Intent intent = new Intent();
10626 intent.setClass(mApp, ErrorDialogActivity.class);
10627 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10628 mApp.startActivity(intent);
10629 }
10630
10631 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010632 public String getMmsUAProfUrl(int subId) {
10633 //TODO investigate if this API should require proper permission check in R b/133791609
10634 final long identity = Binder.clearCallingIdentity();
10635 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010636 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10637 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10638 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10639 return carrierUAProfUrl;
10640 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010641 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10642 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010643 } finally {
10644 Binder.restoreCallingIdentity(identity);
10645 }
10646 }
10647
10648 @Override
10649 public String getMmsUserAgent(int subId) {
10650 //TODO investigate if this API should require proper permission check in R b/133791609
10651 final long identity = Binder.clearCallingIdentity();
10652 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010653 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10654 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10655 if (!TextUtils.isEmpty(carrierUserAgent)) {
10656 return carrierUserAgent;
10657 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010658 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10659 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010660 } finally {
10661 Binder.restoreCallingIdentity(identity);
10662 }
10663 }
Jack Yub07d4972019-05-28 16:12:25 -070010664
10665 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010666 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10667 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010668
Jack Yub07d4972019-05-28 16:12:25 -070010669 final long identity = Binder.clearCallingIdentity();
10670 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010671 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010672 if (phone == null) return false;
10673
Ling Maf188d502022-09-16 15:22:36 -070010674 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010675 } finally {
10676 Binder.restoreCallingIdentity(identity);
10677 }
10678 }
10679
10680 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010681 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010682 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010683 enforceModifyPermission();
10684
changbettyd5c246e2019-12-24 15:40:37 +080010685 final long identity = Binder.clearCallingIdentity();
10686 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010687 Phone phone = getPhone(subscriptionId);
10688 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010689
Ling Maf188d502022-09-16 15:22:36 -070010690 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010691 } finally {
10692 Binder.restoreCallingIdentity(identity);
10693 }
10694 }
10695
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010696 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010697 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010698 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10699 * otherwise.
10700 */
10701 @Override
10702 public void setCepEnabled(boolean isCepEnabled) {
10703 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10704
10705 final long identity = Binder.clearCallingIdentity();
10706 try {
10707 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10708 for (Phone phone : PhoneFactory.getPhones()) {
10709 Phone defaultPhone = phone.getImsPhone();
10710 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10711 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10712 ImsPhoneCallTracker imsPhoneCallTracker =
10713 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10714 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10715 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10716 + imsPhone.getMsisdn());
10717 }
10718 }
10719 } finally {
10720 Binder.restoreCallingIdentity(identity);
10721 }
10722 }
allenwtsu46dcc572020-01-08 18:24:03 +080010723
10724 /**
10725 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10726 *
10727 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10728 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10729 * before being read.
10730 */
10731 @Override
10732 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10733 isCompressed) {
10734 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10735 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010736 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10737 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10738 }
10739 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010740 // ProvisioningManager can not handle ServiceSpecificException.
10741 // Throw the IllegalStateException and annotate ProvisioningManager.
10742 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010743 }
10744
10745 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010746 try {
Hui Wang761a6682020-10-31 05:12:53 +000010747 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10748 } finally {
10749 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010750 }
10751 }
zoey chene02881a2019-12-30 16:11:23 +080010752
10753 @Override
10754 public boolean isIccLockEnabled(int subId) {
10755 enforceReadPrivilegedPermission("isIccLockEnabled");
10756
10757 // Now that all security checks passes, perform the operation as ourselves.
10758 final long identity = Binder.clearCallingIdentity();
10759 try {
10760 Phone phone = getPhone(subId);
10761 if (phone != null && phone.getIccCard() != null) {
10762 return phone.getIccCard().getIccLockEnabled();
10763 } else {
10764 return false;
10765 }
10766 } finally {
10767 Binder.restoreCallingIdentity(identity);
10768 }
10769 }
10770
10771 /**
10772 * Set the ICC pin lock enabled or disabled.
10773 *
10774 * @return an integer representing the status of IccLock enabled or disabled in the following
10775 * three cases:
10776 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10777 * successfully.
10778 * - Positive number and zero for remaining password attempts.
10779 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10780 *
10781 */
10782 @Override
10783 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10784 enforceModifyPermission();
10785
10786 Phone phone = getPhone(subId);
10787 if (phone == null) {
10788 return 0;
10789 }
10790 // Now that all security checks passes, perform the operation as ourselves.
10791 final long identity = Binder.clearCallingIdentity();
10792 try {
10793 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10794 new Pair<Boolean, String>(enabled, password), phone, null);
10795 return attemptsRemaining;
10796
10797 } catch (Exception e) {
10798 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10799 } finally {
10800 Binder.restoreCallingIdentity(identity);
10801 }
10802 return 0;
10803 }
10804
10805 /**
10806 * Change the ICC password used in ICC pin lock.
10807 *
10808 * @return an integer representing the status of IccLock changed in the following three cases:
10809 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10810 * - Positive number and zero for remaining password attempts.
10811 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10812 *
10813 */
10814 @Override
10815 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10816 enforceModifyPermission();
10817
10818 Phone phone = getPhone(subId);
10819 if (phone == null) {
10820 return 0;
10821 }
10822 // Now that all security checks passes, perform the operation as ourselves.
10823 final long identity = Binder.clearCallingIdentity();
10824 try {
10825 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10826 new Pair<String, String>(oldPassword, newPassword), phone, null);
10827 return attemptsRemaining;
10828
10829 } catch (Exception e) {
10830 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10831 } finally {
10832 Binder.restoreCallingIdentity(identity);
10833 }
10834 return 0;
10835 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010836
10837 /**
10838 * Request for receiving user activity notification
10839 */
10840 @Override
10841 public void requestUserActivityNotification() {
10842 if (!mNotifyUserActivity.get()
10843 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10844 mNotifyUserActivity.set(true);
10845 }
10846 }
10847
10848 /**
10849 * Called when userActivity is signalled in the power manager.
10850 * This is safe to call from any thread, with any window manager locks held or not.
10851 */
10852 @Override
10853 public void userActivity() {
10854 // ***************************************
10855 // * Inherited from PhoneWindowManager *
10856 // ***************************************
10857 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10858 // WITH ITS LOCKS HELD.
10859 //
10860 // This code must be VERY careful about the locks
10861 // it acquires.
10862 // In fact, the current code acquires way too many,
10863 // and probably has lurking deadlocks.
10864
10865 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10866 throw new SecurityException("Only the OS may call notifyUserActivity()");
10867 }
10868
10869 if (mNotifyUserActivity.getAndSet(false)) {
10870 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10871 USER_ACTIVITY_NOTIFICATION_DELAY);
10872 }
10873 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010874
10875 @Override
10876 public boolean canConnectTo5GInDsdsMode() {
10877 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10878 }
Jack Yud10cdd42020-09-28 20:28:01 -070010879
10880 @Override
10881 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10882 String callingFeatureId) {
10883 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10884 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10885 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10886 }
10887
10888 Phone phone = getPhone(subId);
10889 if (phone == null) {
10890 throw new RuntimeException("phone is not available");
10891 }
10892 // Now that all security checks passes, perform the operation as ourselves.
10893 final long identity = Binder.clearCallingIdentity();
10894 try {
10895 return phone.getEquivalentHomePlmns();
10896 } finally {
10897 Binder.restoreCallingIdentity(identity);
10898 }
10899 }
Daniel Bright59e67312020-11-13 11:49:37 -080010900
10901 @Override
10902 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010903 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10904 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010905 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010906 if (radioInterfaceCapabilities == null) {
10907 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010908 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010909 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010910 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010911
Hui Wang641e81c2020-10-12 12:14:23 -070010912 @Override
10913 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10914 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010915 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10916 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10917 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10918 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10919 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010920 if (DBG) {
10921 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10922 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10923 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10924 }
10925
10926 if (!SubscriptionManager.isValidSubscriptionId(subId)
10927 || appType < TelephonyManager.APPTYPE_UNKNOWN
10928 || appType > TelephonyManager.APPTYPE_ISIM
10929 || nafUrl == null || securityProtocol == null || callback == null) {
10930 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10931 if (callback != null) {
10932 try {
10933 callback.onAuthenticationFailure(
10934 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10935 } catch (RemoteException exception) {
10936 log("Fail to notify onAuthenticationFailure due to " + exception);
10937 }
10938 return;
10939 }
10940 }
10941
10942 final long token = Binder.clearCallingIdentity();
10943 try {
10944 getGbaManager(subId).bootstrapAuthenticationRequest(
10945 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010946 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070010947 } finally {
10948 Binder.restoreCallingIdentity(token);
10949 }
10950 }
10951
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010952 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010953 * Attempts to set the radio power state for all phones for thermal reason.
10954 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010955 * requested radio power state will actually be set. See {@link
10956 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10957 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010958 * @param enable {@code true} if trying to turn radio on.
10959 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10960 * false}.
10961 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010962 private boolean setRadioPowerForThermal(boolean enable) {
10963 boolean isPhoneAvailable = false;
10964 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10965 Phone phone = PhoneFactory.getPhone(i);
10966 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010967 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010968 isPhoneAvailable = true;
10969 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010970 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010971
10972 // return true if successfully informed the phone object about the thermal radio power
10973 // request.
10974 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010975 }
10976
10977 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010978 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010979 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10980 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10981 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10982 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10983 throw new IllegalArgumentException("modem does not support data throttling");
10984 }
10985
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010986 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10987 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010988 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010989 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10990 }
10991
Sarah Chinecc78c42022-03-31 21:16:48 -070010992 setDataEnabledForReason(
10993 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010994
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010995 if (isDataThrottlingSupported) {
10996 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010997 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010998 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10999 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11000 } else if (thermalMitigationResult
11001 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011002 log("Modem likely does not support data throttling on secondary carrier. Data " +
11003 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11004 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011005 }
11006 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011007 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011008
11009 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011010 }
11011
Jack Nudelman644b91a2021-03-12 14:09:48 -080011012 private static List<String> getThermalMitigationAllowlist(Context context) {
11013 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11014 for (String pckg : context.getResources()
11015 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11016 sThermalMitigationAllowlistedPackages.add(pckg);
11017 }
11018 }
11019
11020 return sThermalMitigationAllowlistedPackages;
11021 }
11022
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011023 private boolean isAnyPhoneInEmergencyState() {
11024 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11025 if (tm.isInEmergencyCall()) {
11026 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11027 return true;
11028 }
11029 for (Phone phone : PhoneFactory.getPhones()) {
11030 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11031 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011032 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11033 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011034 return true;
11035 }
11036 }
11037
11038 return false;
11039 }
11040
Jack Nudelman644b91a2021-03-12 14:09:48 -080011041 /**
11042 * Used by shell commands to add an authorized package name for thermal mitigation.
11043 * @param packageName name of package to be allowlisted
11044 * @param context
11045 */
11046 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11047 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11048 sThermalMitigationAllowlistedPackages.add(packageName);
11049 }
11050
11051 /**
11052 * Used by shell commands to remove an authorized package name for thermal mitigation.
11053 * @param packageName name of package to remove from allowlist
11054 * @param context
11055 */
11056 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11057 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11058 sThermalMitigationAllowlistedPackages.remove(packageName);
11059 }
11060
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011061 /**
11062 * Thermal mitigation request to control functionalities at modem.
11063 *
11064 * @param subId the id of the subscription.
11065 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011066 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011067 *
11068 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11069 */
11070 @Override
11071 @ThermalMitigationResult
11072 public int sendThermalMitigationRequest(
11073 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011074 ThermalMitigationRequest thermalMitigationRequest,
11075 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011076 enforceModifyPermission();
11077
Jack Nudelman644b91a2021-03-12 14:09:48 -080011078 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11079 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11080 .contains(callingPackage)) {
11081 throw new SecurityException("Calling package must be configured in the device config. "
11082 + "calling package: " + callingPackage);
11083 }
11084
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011085 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11086 final long identity = Binder.clearCallingIdentity();
11087
11088 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11089 try {
11090 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11091 switch (thermalMitigationAction) {
11092 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11093 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011094 handleDataThrottlingRequest(subId,
11095 thermalMitigationRequest.getDataThrottlingRequest(),
11096 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011097 break;
11098 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11099 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11100 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11101 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11102 }
11103
11104 // Ensure that radio is on. If not able to power on due to phone being
11105 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011106 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011107 thermalMitigationResult =
11108 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11109 break;
11110 }
11111
11112 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011113 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011114 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11115 break;
11116 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11117 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11118 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11119 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11120 }
11121
11122 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11123 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011124 Phone phone = getPhone(subId);
11125 if (phone == null) {
11126 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011127 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011128 break;
11129 }
11130
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011131 TelephonyConnectionService service =
11132 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011133 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011134 Log.e(LOG_TAG, "An emergency call is pending");
11135 thermalMitigationResult =
11136 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11137 break;
11138 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011139 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011140 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011141 break;
11142 }
11143 } else {
11144 thermalMitigationResult =
11145 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11146 break;
11147 }
11148
11149 // Turn radio off. If not able to power off due to phone being unavailable,
11150 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011151 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011152 thermalMitigationResult =
11153 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11154 break;
11155 }
11156 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011157 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011158 break;
11159 default:
11160 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11161 + "not exist. Requested action: " + thermalMitigationAction);
11162 }
11163 } catch (IllegalArgumentException e) {
11164 throw e;
11165 } catch (Exception e) {
11166 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11167 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11168 } finally {
11169 Binder.restoreCallingIdentity(identity);
11170 }
11171
11172 if (DBG) {
11173 log("thermalMitigationRequest returning with thermalMitigationResult: "
11174 + thermalMitigationResult);
11175 }
11176
11177 return thermalMitigationResult;
11178 }
Hui Wang641e81c2020-10-12 12:14:23 -070011179
11180 /**
11181 * Set the GbaService Package Name that Telephony will bind to.
11182 *
11183 * @param subId The sim that the GbaService is associated with.
11184 * @param packageName The name of the package to be replaced with.
11185 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11186 */
11187 @Override
11188 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11189 enforceModifyPermission();
11190
11191 final long identity = Binder.clearCallingIdentity();
11192 try {
11193 return getGbaManager(subId).overrideServicePackage(packageName);
11194 } finally {
11195 Binder.restoreCallingIdentity(identity);
11196 }
11197 }
11198
11199 /**
11200 * Return the package name of the currently bound GbaService.
11201 *
11202 * @param subId The sim that the GbaService is associated with.
11203 * @return the package name of the GbaService configuration, null if GBA is not supported.
11204 */
11205 @Override
11206 public String getBoundGbaService(int subId) {
11207 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11208
11209 final long identity = Binder.clearCallingIdentity();
11210 try {
11211 return getGbaManager(subId).getServicePackage();
11212 } finally {
11213 Binder.restoreCallingIdentity(identity);
11214 }
11215 }
11216
11217 /**
11218 * Set the release time for telephony to unbind GbaService.
11219 *
11220 * @param subId The sim that the GbaService is associated with.
11221 * @param interval The release time to unbind GbaService by millisecond.
11222 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11223 */
11224 @Override
11225 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11226 enforceModifyPermission();
11227
11228 final long identity = Binder.clearCallingIdentity();
11229 try {
11230 return getGbaManager(subId).overrideReleaseTime(interval);
11231 } finally {
11232 Binder.restoreCallingIdentity(identity);
11233 }
11234 }
11235
11236 /**
11237 * Return the release time for telephony to unbind GbaService.
11238 *
11239 * @param subId The sim that the GbaService is associated with.
11240 * @return The release time to unbind GbaService by millisecond.
11241 */
11242 @Override
11243 public int getGbaReleaseTime(int subId) {
11244 enforceReadPrivilegedPermission("getGbaReleaseTime");
11245
11246 final long identity = Binder.clearCallingIdentity();
11247 try {
11248 return getGbaManager(subId).getReleaseTime();
11249 } finally {
11250 Binder.restoreCallingIdentity(identity);
11251 }
11252 }
11253
11254 private GbaManager getGbaManager(int subId) {
11255 GbaManager instance = GbaManager.getInstance(subId);
11256 if (instance == null) {
11257 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11258 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11259 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11260 }
11261 return instance;
11262 }
Hui Wang761a6682020-10-31 05:12:53 +000011263
11264 /**
11265 * indicate whether the device and the carrier can support
11266 * RCS VoLTE single registration.
11267 */
11268 @Override
11269 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011270 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11271 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11272 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11273 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011274
11275 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11276 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11277 }
11278
11279 final long identity = Binder.clearCallingIdentity();
11280 try {
11281 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11282 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011283 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11284 if (isCapable != null) {
11285 return isCapable;
11286 }
Hui Wang761a6682020-10-31 05:12:53 +000011287 }
Hui Wang67af90e2021-06-04 16:57:15 -070011288 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11289 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011290 } finally {
11291 Binder.restoreCallingIdentity(identity);
11292 }
11293 }
11294
11295 /**
11296 * Register RCS provisioning callback.
11297 */
11298 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011299 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011300 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011301 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011302 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011303 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11304 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011305
11306 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11307 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11308 }
11309 if (!isImsAvailableOnDevice()) {
11310 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11311 "IMS not available on device.");
11312 }
11313
11314 final long identity = Binder.clearCallingIdentity();
11315 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011316 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011317 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011318 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11319 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011320 }
Hui Wang761a6682020-10-31 05:12:53 +000011321 } finally {
11322 Binder.restoreCallingIdentity(identity);
11323 }
11324 }
11325
11326 /**
11327 * Unregister RCS provisioning callback.
11328 */
11329 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011330 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011331 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011332 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011333 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011334 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11335 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011336
11337 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11338 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11339 }
11340 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000011341 // operation failed silently
11342 Rlog.w(LOG_TAG, "IMS not available on device.");
11343 return;
Hui Wang761a6682020-10-31 05:12:53 +000011344 }
11345
11346 final long identity = Binder.clearCallingIdentity();
11347 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011348 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011349 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011350 } finally {
11351 Binder.restoreCallingIdentity(identity);
11352 }
11353 }
11354
11355 /**
11356 * trigger RCS reconfiguration.
11357 */
11358 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011359 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11360 "triggerRcsReconfiguration",
11361 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011362
11363 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11364 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11365 }
11366 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000011367 // ProvisioningManager can not handle ServiceSpecificException.
11368 // Throw the IllegalStateException and annotate ProvisioningManager.
11369 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000011370 }
11371
11372 final long identity = Binder.clearCallingIdentity();
11373 try {
11374 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11375 } finally {
11376 Binder.restoreCallingIdentity(identity);
11377 }
11378 }
11379
11380 /**
11381 * Provide the client configuration parameters of the RCS application.
11382 */
11383 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011384 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11385 "setRcsClientConfiguration",
11386 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011387
11388 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11389 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11390 }
11391 if (!isImsAvailableOnDevice()) {
11392 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11393 "IMS not available on device.");
11394 }
11395
11396 final long identity = Binder.clearCallingIdentity();
11397
11398 try {
11399 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11400 if (configBinder == null) {
11401 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011402 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11403 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011404 } else {
11405 configBinder.setRcsClientConfiguration(rcc);
11406 }
joonhunshin3e154242021-09-17 06:33:39 +000011407
11408 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11409 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011410 } catch (RemoteException e) {
11411 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011412 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11413 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011414 } finally {
11415 Binder.restoreCallingIdentity(identity);
11416 }
11417 }
11418
11419 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011420 * Enables or disables the test mode for RCS VoLTE single registration.
11421 */
11422 @Override
11423 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11424 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11425 "setRcsSingleRegistrationTestModeEnabled");
11426
11427 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11428 }
11429
11430 /**
11431 * Gets the test mode for RCS VoLTE single registration.
11432 */
11433 @Override
11434 public boolean getRcsSingleRegistrationTestModeEnabled() {
11435 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11436 "getRcsSingleRegistrationTestModeEnabled");
11437
11438 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11439 }
11440
11441 /**
Hui Wang761a6682020-10-31 05:12:53 +000011442 * Overrides the config of RCS VoLTE single registration enabled for the device.
11443 */
11444 @Override
11445 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11446 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11447 "setDeviceSingleRegistrationEnabledOverride");
11448 enforceModifyPermission();
11449
11450 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11451 : Boolean.parseBoolean(enabledStr);
11452 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011453 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011454 }
11455
11456 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011457 * Sends a device to device communication message. Only usable via shell.
11458 * @param message message to send.
11459 * @param value message value.
11460 */
11461 @Override
11462 public void sendDeviceToDeviceMessage(int message, int value) {
11463 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011464 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011465 enforceModifyPermission();
11466
11467 final long identity = Binder.clearCallingIdentity();
11468 try {
11469 TelephonyConnectionService service =
11470 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11471 if (service == null) {
11472 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11473 return;
11474 }
11475 service.sendTestDeviceToDeviceMessage(message, value);
11476 } finally {
11477 Binder.restoreCallingIdentity(identity);
11478 }
11479 }
11480
Tyler Gunnbabbda02021-02-10 11:05:02 -080011481 /**
11482 * Sets the specified device to device transport active.
11483 * @param transport The transport to set active.
11484 */
11485 @Override
11486 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11487 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11488 "setActiveDeviceToDeviceTransport");
11489 enforceModifyPermission();
11490
11491 final long identity = Binder.clearCallingIdentity();
11492 try {
11493 TelephonyConnectionService service =
11494 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11495 if (service == null) {
11496 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11497 return;
11498 }
11499 service.setActiveDeviceToDeviceTransport(transport);
11500 } finally {
11501 Binder.restoreCallingIdentity(identity);
11502 }
11503 }
Tyler Gunn92479152021-01-20 16:30:10 -080011504
Tyler Gunnd4339262021-05-03 14:46:49 -070011505 @Override
11506 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11507 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11508 "setDeviceToDeviceForceEnabled");
11509
11510 final long identity = Binder.clearCallingIdentity();
11511 try {
11512 Arrays.stream(PhoneFactory.getPhones()).forEach(
11513 p -> {
11514 Phone thePhone = p.getImsPhone();
11515 if (thePhone != null && thePhone instanceof ImsPhone) {
11516 ImsPhone imsPhone = (ImsPhone) thePhone;
11517 CallTracker tracker = imsPhone.getCallTracker();
11518 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11519 ImsPhoneCallTracker imsPhoneCallTracker =
11520 (ImsPhoneCallTracker) tracker;
11521 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11522 }
11523 }
11524 }
11525 );
11526 } finally {
11527 Binder.restoreCallingIdentity(identity);
11528 }
11529 }
11530
Tyler Gunn92479152021-01-20 16:30:10 -080011531 /**
Hui Wang761a6682020-10-31 05:12:53 +000011532 * Gets the config of RCS VoLTE single registration enabled for the device.
11533 */
11534 @Override
11535 public boolean getDeviceSingleRegistrationEnabled() {
11536 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11537 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11538 }
11539
11540 /**
11541 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11542 */
11543 @Override
11544 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11545 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11546 "setCarrierSingleRegistrationEnabledOverride");
11547 enforceModifyPermission();
11548
11549 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11550 : Boolean.parseBoolean(enabledStr);
11551 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11552 subId, enabled);
11553 }
11554
11555 /**
11556 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11557 */
11558 @Override
11559 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11560 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11561 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11562 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011563
11564 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011565 * Overrides the ims feature validation result
11566 */
11567 @Override
11568 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11569 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11570 "setImsFeatureValidationOverride");
11571
11572 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11573 : Boolean.parseBoolean(enabledStr);
11574 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11575 subId, enabled);
11576 }
11577
11578 /**
11579 * Gets the ims feature validation override value
11580 */
11581 @Override
11582 public boolean getImsFeatureValidationOverride(int subId) {
11583 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11584 "getImsFeatureValidationOverride");
11585 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11586 }
11587
11588 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011589 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11590 * their mobile plan.
11591 */
11592 @Override
11593 public String getMobileProvisioningUrl() {
11594 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11595 final long identity = Binder.clearCallingIdentity();
11596 try {
11597 return getDefaultPhone().getMobileProvisioningUrl();
11598 } finally {
11599 Binder.restoreCallingIdentity(identity);
11600 }
11601 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011602
James.cf Linbcdf8b32021-01-14 16:44:13 +080011603 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011604 * Get the EAB contact from the EAB database.
11605 */
11606 @Override
11607 public String getContactFromEab(String contact) {
11608 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11609 enforceModifyPermission();
11610 final long identity = Binder.clearCallingIdentity();
11611 try {
11612 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11613 } finally {
11614 Binder.restoreCallingIdentity(identity);
11615 }
11616 }
11617
11618 /**
Calvin Pana1434322021-07-01 19:27:01 +080011619 * Get the EAB capability from the EAB database.
11620 */
11621 @Override
11622 public String getCapabilityFromEab(String contact) {
11623 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11624 enforceModifyPermission();
11625 final long identity = Binder.clearCallingIdentity();
11626 try {
11627 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11628 } finally {
11629 Binder.restoreCallingIdentity(identity);
11630 }
11631 }
11632
11633 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011634 * Remove the EAB contacts from the EAB database.
11635 */
11636 @Override
11637 public int removeContactFromEab(int subId, String contacts) {
11638 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11639 enforceModifyPermission();
11640 final long identity = Binder.clearCallingIdentity();
11641 try {
11642 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11643 } finally {
11644 Binder.restoreCallingIdentity(identity);
11645 }
11646 }
11647
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011648 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011649 public boolean getDeviceUceEnabled() {
11650 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11651 final long identity = Binder.clearCallingIdentity();
11652 try {
11653 return mApp.getDeviceUceEnabled();
11654 } finally {
11655 Binder.restoreCallingIdentity(identity);
11656 }
11657 }
11658
11659 @Override
11660 public void setDeviceUceEnabled(boolean isEnabled) {
11661 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11662 final long identity = Binder.clearCallingIdentity();
11663 try {
11664 mApp.setDeviceUceEnabled(isEnabled);
11665 } finally {
11666 Binder.restoreCallingIdentity(identity);
11667 }
11668 }
11669
Brad Ebinger14d467f2021-02-12 06:18:28 +000011670 /**
11671 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11672 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11673 */
11674 // Used for SHELL command only right now.
11675 @Override
11676 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11677 List<String> featureTags) {
11678 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11679 "addUceRegistrationOverrideShell");
11680 final long identity = Binder.clearCallingIdentity();
11681 try {
11682 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11683 new ArraySet<>(featureTags));
11684 } catch (ImsException e) {
11685 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11686 } finally {
11687 Binder.restoreCallingIdentity(identity);
11688 }
11689 }
11690
11691 /**
11692 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11693 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11694 */
11695 // Used for SHELL command only right now.
11696 @Override
11697 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11698 List<String> featureTags) {
11699 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11700 "removeUceRegistrationOverrideShell");
11701 final long identity = Binder.clearCallingIdentity();
11702 try {
11703 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11704 new ArraySet<>(featureTags));
11705 } catch (ImsException e) {
11706 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11707 } finally {
11708 Binder.restoreCallingIdentity(identity);
11709 }
11710 }
11711
11712 /**
11713 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11714 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11715 */
11716 // Used for SHELL command only right now.
11717 @Override
11718 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11719 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11720 "clearUceRegistrationOverrideShell");
11721 final long identity = Binder.clearCallingIdentity();
11722 try {
11723 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11724 } catch (ImsException e) {
11725 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11726 } finally {
11727 Binder.restoreCallingIdentity(identity);
11728 }
11729 }
11730
11731 /**
11732 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11733 */
11734 // Used for SHELL command only right now.
11735 @Override
11736 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11737 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11738 "getLatestRcsContactUceCapabilityShell");
11739 final long identity = Binder.clearCallingIdentity();
11740 try {
11741 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11742 } catch (ImsException e) {
11743 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11744 } finally {
11745 Binder.restoreCallingIdentity(identity);
11746 }
11747 }
11748
11749 /**
11750 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11751 * device does not have an active PUBLISH.
11752 */
11753 // Used for SHELL command only right now.
11754 @Override
11755 public String getLastUcePidfXmlShell(int subId) {
11756 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11757 final long identity = Binder.clearCallingIdentity();
11758 try {
11759 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11760 } catch (ImsException e) {
11761 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11762 } finally {
11763 Binder.restoreCallingIdentity(identity);
11764 }
11765 }
11766
James.cf Line8713a42021-04-29 16:04:26 +080011767 /**
11768 * Remove UCE requests cannot be sent to the network status.
11769 */
11770 // Used for SHELL command only right now.
11771 @Override
11772 public boolean removeUceRequestDisallowedStatus(int subId) {
11773 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11774 final long identity = Binder.clearCallingIdentity();
11775 try {
11776 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11777 } catch (ImsException e) {
11778 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11779 } finally {
11780 Binder.restoreCallingIdentity(identity);
11781 }
11782 }
11783
James.cf Lin18bb9002021-05-25 01:37:38 +080011784 /**
11785 * Remove UCE requests cannot be sent to the network status.
11786 */
11787 // Used for SHELL command only.
11788 @Override
11789 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11790 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11791 final long identity = Binder.clearCallingIdentity();
11792 try {
11793 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11794 } catch (ImsException e) {
11795 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11796 } finally {
11797 Binder.restoreCallingIdentity(identity);
11798 }
11799 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011800
James.cf Lin4b784aa2021-01-31 03:25:15 +080011801 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011802 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11803 String callingPackage) {
11804 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11805 mApp, subId, "setSignalStrengthUpdateRequest");
11806
11807 final int callingUid = Binder.getCallingUid();
11808 // Verify that tha callingPackage belongs to the calling UID
11809 mApp.getSystemService(AppOpsManager.class)
11810 .checkPackage(callingUid, callingPackage);
11811
Rambo Wang3607f502021-02-01 21:51:40 -080011812 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011813
11814 final long identity = Binder.clearCallingIdentity();
11815 try {
11816 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11817 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11818
11819 if (result instanceof IllegalStateException) {
11820 throw (IllegalStateException) result;
11821 }
11822 } finally {
11823 Binder.restoreCallingIdentity(identity);
11824 }
11825 }
11826
11827 @Override
11828 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11829 String callingPackage) {
11830 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11831 mApp, subId, "clearSignalStrengthUpdateRequest");
11832
11833 final int callingUid = Binder.getCallingUid();
11834 // Verify that tha callingPackage belongs to the calling UID
11835 mApp.getSystemService(AppOpsManager.class)
11836 .checkPackage(callingUid, callingPackage);
11837
11838 final long identity = Binder.clearCallingIdentity();
11839 try {
11840 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11841 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11842
11843 if (result instanceof IllegalStateException) {
11844 throw (IllegalStateException) result;
11845 }
11846 } finally {
11847 Binder.restoreCallingIdentity(identity);
11848 }
11849 }
11850
Rambo Wang3607f502021-02-01 21:51:40 -080011851 private static void validateSignalStrengthUpdateRequest(Context context,
11852 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011853 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11854 // phone/system process do not have further restriction on request
11855 return;
11856 }
11857
11858 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011859 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011860 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011861 context.enforceCallingOrSelfPermission(
11862 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11863 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011864 }
11865
11866 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000011867 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011868 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011869 || info.isEnabled()) {
11870 throw new IllegalArgumentException(
11871 "Only system can set hide fields in SignalThresholdInfo");
11872 }
11873
11874 // Thresholds length for each RAN need in range. This has been validated in
11875 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11876 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11877 final int[] thresholds = info.getThresholds();
11878 Objects.requireNonNull(thresholds);
11879 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11880 || thresholds.length
11881 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11882 throw new IllegalArgumentException(
11883 "thresholds length is out of range: " + thresholds.length);
11884 }
11885 }
11886 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011887
11888 /**
11889 * Gets the current phone capability.
11890 *
11891 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11892 * @return the PhoneCapability which describes the data connection capability of modem.
11893 * It's used to evaluate possible phone config change, for example from single
11894 * SIM device to multi-SIM device.
11895 */
11896 @Override
11897 public PhoneCapability getPhoneCapability() {
11898 enforceReadPrivilegedPermission("getPhoneCapability");
11899 final long identity = Binder.clearCallingIdentity();
11900 try {
11901 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11902 } finally {
11903 Binder.restoreCallingIdentity(identity);
11904 }
11905 }
Michele Berionne5e411512020-11-13 02:36:59 +000011906
11907 /**
11908 * Prepare TelephonyManager for an unattended reboot. The reboot is
11909 * required to be done shortly after the API is invoked.
11910 */
11911 @Override
11912 @TelephonyManager.PrepareUnattendedRebootResult
11913 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011914 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011915 enforceRebootPermission();
11916
11917 final long identity = Binder.clearCallingIdentity();
11918 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011919 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011920 } finally {
11921 Binder.restoreCallingIdentity(identity);
11922 }
11923 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011924
11925 /**
11926 * Request to get the current slicing configuration including URSP rules and
11927 * NSSAIs (configured, allowed and rejected).
11928 *
11929 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11930 */
11931 @Override
11932 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011933 TelephonyPermissions
11934 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11935 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011936
11937 final long identity = Binder.clearCallingIdentity();
11938 try {
11939 Phone phone = getDefaultPhone();
11940 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11941 } finally {
11942 Binder.restoreCallingIdentity(identity);
11943 }
11944 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011945
11946 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011947 * Check whether the given premium capability is available for purchase from the carrier.
11948 *
11949 * @param capability The premium capability to check.
11950 * @param subId The subId to check the premium capability for.
11951 *
11952 * @return Whether the given premium capability is available to purchase.
11953 */
11954 @Override
11955 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11956 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11957 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11958 log("Premium capability "
11959 + TelephonyManager.convertPremiumCapabilityToString(capability)
11960 + " is not available for purchase due to missing permissions.");
11961 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11962 + "permission READ_BASIC_PHONE_STATE.");
11963 }
11964
11965 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080011966 if (phone == null) {
11967 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
11968 return false;
11969 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070011970 final long identity = Binder.clearCallingIdentity();
11971 try {
Sarah Chin46355ba2022-11-01 23:51:16 -070011972 return SlicePurchaseController.getInstance(phone)
Sarah Chin2ec39f62022-08-31 17:03:26 -070011973 .isPremiumCapabilityAvailableForPurchase(capability);
11974 } finally {
11975 Binder.restoreCallingIdentity(identity);
11976 }
11977 }
11978
11979 /**
11980 * Purchase the given premium capability from the carrier.
11981 *
11982 * @param capability The premium capability to purchase.
11983 * @param callback The result of the purchase request.
11984 * @param subId The subId to purchase the premium capability for.
11985 */
11986 @Override
11987 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11988 log("purchasePremiumCapability: capability="
11989 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11990 + getCurrentPackageName());
11991
11992 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11993 mApp, "purchasePremiumCapability")) {
11994 log("purchasePremiumCapability "
11995 + TelephonyManager.convertPremiumCapabilityToString(capability)
11996 + " failed due to missing permissions.");
11997 throw new SecurityException("purchasePremiumCapability requires permission "
11998 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080011999 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12000 mApp, "purchasePremiumCapability")) {
12001 log("purchasePremiumCapability "
12002 + TelephonyManager.convertPremiumCapabilityToString(capability)
12003 + " failed due to missing permissions.");
12004 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012005 }
12006
12007 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012008 if (phone == null) {
12009 try {
12010 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12011 callback.accept(result);
12012 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12013 } catch (RemoteException e) {
12014 String logStr = "Purchase premium capability "
12015 + TelephonyManager.convertPremiumCapabilityToString(capability)
12016 + " failed due to RemoteException handling null phone: " + e;
12017 if (DBG) log(logStr);
12018 AnomalyReporter.reportAnomaly(
12019 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12020 }
12021 return;
12022 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012023
12024 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012025 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012026 callingProcess = mApp.getPackageManager().getApplicationInfo(
12027 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070012028 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012029 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012030 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012031
12032 boolean isVisible = false;
12033 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12034 if (am != null) {
12035 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12036 if (processes != null) {
12037 for (ActivityManager.RunningAppProcessInfo process : processes) {
12038 log("purchasePremiumCapability: process " + process.processName
12039 + "has importance " + process.importance);
12040 if (process.processName.equals(callingProcess) && process.importance
12041 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12042 isVisible = true;
12043 break;
12044 }
12045 }
12046 }
12047 }
12048
12049 if (!isVisible) {
12050 try {
12051 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12052 callback.accept(result);
12053 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12054 } catch (RemoteException e) {
12055 String logStr = "Purchase premium capability "
12056 + TelephonyManager.convertPremiumCapabilityToString(capability)
12057 + " failed due to RemoteException handling background application: " + e;
12058 if (DBG) log(logStr);
12059 AnomalyReporter.reportAnomaly(
12060 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12061 }
12062 return;
12063 }
12064
Sarah Chin71b3a852022-09-28 15:54:19 -070012065 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012066 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012067 }
12068
12069 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012070 * Register an IMS connection state callback
12071 */
12072 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012073 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12074 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012075 if (feature == ImsFeature.FEATURE_MMTEL) {
12076 // ImsMmTelManager
12077 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12078 TelephonyPermissions
12079 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12080 mApp, subId, "registerImsStateCallback");
12081 } else if (feature == ImsFeature.FEATURE_RCS) {
12082 // ImsRcsManager or SipDelegateManager
12083 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12084 Binder.getCallingUid(), "registerImsStateCallback",
12085 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12086 Manifest.permission.READ_PRECISE_PHONE_STATE,
12087 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12088 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12089 }
12090
12091 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12092 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12093 "IMS not available on device.");
12094 }
12095
12096 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12097 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12098 }
12099
12100 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12101 if (controller == null) {
12102 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12103 "IMS not available on device.");
12104 }
12105
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012106 if (callingPackage == null) {
12107 callingPackage = getCurrentPackageName();
12108 }
12109
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012110 final long token = Binder.clearCallingIdentity();
12111 try {
12112 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012113 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012114 } catch (ImsException e) {
12115 throw new ServiceSpecificException(e.getCode());
12116 } finally {
12117 Binder.restoreCallingIdentity(token);
12118 }
12119 }
12120
12121 /**
12122 * Unregister an IMS connection state callback
12123 */
12124 @Override
12125 public void unregisterImsStateCallback(IImsStateCallback cb) {
12126 final long token = Binder.clearCallingIdentity();
12127 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12128 if (controller == null) {
12129 return;
12130 }
12131 try {
12132 controller.unregisterImsStateCallback(cb);
12133 } finally {
12134 Binder.restoreCallingIdentity(token);
12135 }
12136 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012137
12138 /**
12139 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12140 *
12141 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
12142 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
12143 * SecurityException.
12144 * If there is current registered network this value will be same as the registered cell
12145 * identity. If the device goes out of service the previous cell identity is cached and
12146 * will be returned. If the cache age of the Cell identity is more than 24 hours
12147 * it will be cleared and null will be returned.
12148 *
12149 */
12150 @Override
12151 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12152 String callingFeatureId) {
12153 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12154 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12155 LocationAccessPolicy.checkLocationPermission(mApp,
12156 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12157 .setCallingPackage(callingPackage)
12158 .setCallingFeatureId(callingFeatureId)
12159 .setCallingPid(Binder.getCallingPid())
12160 .setCallingUid(Binder.getCallingUid())
12161 .setMethod("getLastKnownCellIdentity")
12162 .setLogAsInfo(true)
12163 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12164 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12165 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12166 .build());
12167
12168 boolean hasFinePermission =
12169 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12170 if (!hasFinePermission
12171 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12172 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012173 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012174 }
12175
12176 final long identity = Binder.clearCallingIdentity();
12177 try {
12178 Phone phone = getPhone(subId);
12179 if (phone == null) return null;
12180 ServiceStateTracker sst = phone.getServiceStateTracker();
12181 if (sst == null) return null;
12182 return sst.getLastKnownCellIdentity();
12183 } finally {
12184 Binder.restoreCallingIdentity(identity);
12185 }
12186 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012187
jimsun3b9ccac2021-10-26 15:01:23 +080012188 /**
12189 * Sets the modem service class Name that Telephony will bind to.
12190 *
12191 * @param serviceName The class name of the modem service.
12192 * @return true if the operation is succeed, otherwise false.
12193 */
12194 public boolean setModemService(String serviceName) {
12195 Log.d(LOG_TAG, "setModemService - " + serviceName);
12196 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12197 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012198 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12199 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012200 return mPhoneConfigurationManager.setModemService(serviceName);
12201 }
12202
12203 /**
12204 * Return the class name of the currently bounded modem service.
12205 *
12206 * @return the class name of the modem service.
12207 */
12208 public String getModemService() {
12209 String result;
12210 Log.d(LOG_TAG, "getModemService");
12211 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12212 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012213 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012214 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12215 "getModemService");
12216 result = mPhoneConfigurationManager.getModemService();
12217 Log.d(LOG_TAG, "result = " + result);
12218 return result;
12219 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012220
12221 @Override
12222 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12223 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12224 mApp.enforceCallingOrSelfPermission(
12225 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12226 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12227
12228 final long identity = Binder.clearCallingIdentity();
12229 try {
12230 Phone phone = getPhone(subId);
12231 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012232 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12233 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012234 phone.setVoiceServiceStateOverride(hasService);
12235 } finally {
12236 Binder.restoreCallingIdentity(identity);
12237 }
12238 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012239
12240 /**
12241 * set removable eSIM as default eUICC.
12242 *
12243 * @hide
12244 */
12245 @Override
12246 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12247 enforceModifyPermission();
12248 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12249
12250 final long identity = Binder.clearCallingIdentity();
12251 try {
12252 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12253 } finally {
12254 Binder.restoreCallingIdentity(identity);
12255 }
12256 }
12257
12258 /**
12259 * Returns whether the removable eSIM is default eUICC or not.
12260 *
12261 * @hide
12262 */
12263 @Override
12264 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12265 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12266 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12267
12268 final long identity = Binder.clearCallingIdentity();
12269 try {
12270 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12271 } finally {
12272 Binder.restoreCallingIdentity(identity);
12273 }
12274 }
12275
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012276 /**
12277 * Get the component name of the default app to direct respond-via-message intent for the
12278 * user associated with this subscription, update the cache if there is no respond-via-message
12279 * application currently configured for this user.
12280 * @return component name of the app and class to direct Respond Via Message intent to, or
12281 * {@code null} if the functionality is not supported.
12282 * @hide
12283 */
12284 @Override
12285 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12286 boolean updateIfNeeded) {
12287 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012288
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012289 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12290
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012291 UserHandle userHandle = null;
12292 final long identity = Binder.clearCallingIdentity();
12293 try {
12294 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12295 } finally {
12296 Binder.restoreCallingIdentity(identity);
12297 }
12298 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12299 updateIfNeeded, userHandle);
12300 }
Jack Yuf5badd92022-12-08 00:50:53 -080012301
12302 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012303 * Set whether the device is able to connect with null ciphering or integrity
12304 * algorithms. This is a global setting and will apply to all active subscriptions
12305 * and all new subscriptions after this.
12306 *
12307 * @param enabled when true, null cipher and integrity algorithms are allowed.
12308 * @hide
12309 */
12310 @Override
12311 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12312 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12313 enforceModifyPermission();
12314 checkForNullCipherAndIntegritySupport();
12315
12316 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12317 // for listening to these preference changes and applying them immediately.
12318 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12319 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12320 editor.apply();
12321
12322 for (Phone phone: PhoneFactory.getPhones()) {
12323 phone.handleNullCipherEnabledChange();
12324 }
12325 }
12326
12327
12328 /**
12329 * Get whether the device is able to connect with null ciphering or integrity
12330 * algorithms. Note that this retrieves the phone-global preference and not
12331 * the state of the radio.
12332 *
12333 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12334 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12335 * version for this feature.
12336 * @hide
12337 */
12338 @Override
12339 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12340 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12341 enforceReadPermission();
12342 checkForNullCipherAndIntegritySupport();
12343 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12344 }
12345
12346 private void checkForNullCipherAndIntegritySupport() {
12347 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12348 throw new UnsupportedOperationException(
12349 "Null cipher and integrity operations require HAL 2.1 or above");
12350 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012351 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12352 throw new UnsupportedOperationException(
12353 "Null cipher and integrity operations unsupported by modem");
12354 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012355 }
12356
12357 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012358 * Get the SIM state for the slot index.
12359 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12360 *
12361 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12362 */
12363 @Override
12364 @SimState
12365 public int getSimStateForSlotIndex(int slotIndex) {
12366 IccCardConstants.State simState;
12367 if (slotIndex < 0) {
12368 simState = IccCardConstants.State.UNKNOWN;
12369 } else {
12370 Phone phone = null;
12371 try {
12372 phone = PhoneFactory.getPhone(slotIndex);
12373 } catch (IllegalStateException e) {
12374 // ignore
12375 }
12376 if (phone == null) {
12377 simState = IccCardConstants.State.UNKNOWN;
12378 } else {
12379 IccCard icc = phone.getIccCard();
12380 if (icc == null) {
12381 simState = IccCardConstants.State.UNKNOWN;
12382 } else {
12383 simState = icc.getState();
12384 }
12385 }
12386 }
12387 return simState.ordinal();
12388 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012389
12390 /**
12391 * Get current cell broadcast ranges.
12392 */
12393 @Override
12394 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12395 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12396 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12397 "getCellBroadcastIdRanges");
12398 final long identity = Binder.clearCallingIdentity();
12399 try {
12400 return getPhone(subId).getCellBroadcastIdRanges();
12401 } finally {
12402 Binder.restoreCallingIdentity(identity);
12403 }
12404 }
12405
12406 /**
12407 * Set reception of cell broadcast messages with the list of the given ranges
12408 *
12409 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12410 */
12411 @Override
12412 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12413 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12414 @Nullable IIntegerConsumer callback) {
12415 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12416 "setCellBroadcastIdRanges");
12417 final long identity = Binder.clearCallingIdentity();
12418 try {
12419 Phone phone = getPhoneFromSubId(subId);
12420 if (DBG) {
12421 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12422 }
12423 phone.setCellBroadcastIdRanges(ranges, result -> {
12424 if (callback != null) {
12425 try {
12426 callback.accept(result);
12427 } catch (RemoteException e) {
12428 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12429 }
12430 }
12431 });
12432 } finally {
12433 Binder.restoreCallingIdentity(identity);
12434 }
12435 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012436
12437 /**
12438 * Returns whether the device supports the domain selection service.
12439 *
12440 * @return {@code true} if the device supports the domain selection service.
12441 */
12442 @Override
12443 public boolean isDomainSelectionSupported() {
12444 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12445 "isDomainSelectionSupported");
12446
12447 final long identity = Binder.clearCallingIdentity();
12448 try {
12449 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12450 } finally {
12451 Binder.restoreCallingIdentity(identity);
12452 }
12453 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012454
12455 /**
Sarah Chineccfbd12023-01-20 19:00:35 -080012456 * Start receiving satellite position updates.
12457 * This can be called by the pointing UI when the user starts pointing to the satellite.
12458 * Modem should continue to report the pointing input as the device or satellite moves.
12459 *
12460 * @param subId The subId to start satellite position updates for.
Sarah Chineccfbd12023-01-20 19:00:35 -080012461 * @param callback The callback to notify of changes in satellite position.
12462 * @return The result of the operation.
12463 */
12464 @Override
12465 @SatelliteManager.SatelliteServiceResult public int startSatellitePositionUpdates(int subId,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012466 @NonNull ISatelliteStateListener callback) {
Sarah Chinf75afa72023-02-01 01:32:19 -080012467 enforceSatelliteCommunicationPermission("startSatellitePositionUpdates");
12468
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012469 final int validSubId = getValidSatelliteSubId(subId);
12470 if (!isSatelliteEnabled(validSubId)) {
Sarah Chinf75afa72023-02-01 01:32:19 -080012471 return SatelliteManager.SATELLITE_SERVICE_DISABLED;
12472 }
12473
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012474 Phone phone = getPhoneOrDefault(validSubId, "startSatellitePositionUpdates");
Sarah Chineccfbd12023-01-20 19:00:35 -080012475 if (phone == null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012476 return SatelliteManager.SATELLITE_SERVICE_INVALID_TELEPHONY_STATE;
Sarah Chineccfbd12023-01-20 19:00:35 -080012477 }
12478
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012479 if (mSatellitePositionUpdateHandlers.containsKey(callback.asBinder())) {
12480 log("startSatellitePositionUpdates: callback already registered: "
12481 + callback.asBinder());
12482 return SatelliteManager.SATELLITE_SERVICE_CALLBACK_ALREADY_REGISTERED;
Sarah Chineccfbd12023-01-20 19:00:35 -080012483 }
12484
12485 SatellitePositionUpdateHandler handler =
12486 new SatellitePositionUpdateHandler(callback, Looper.getMainLooper());
12487 phone.registerForSatellitePointingInfoChanged(handler,
12488 SatellitePositionUpdateHandler.EVENT_POSITION_UPDATE, null);
12489 phone.registerForSatelliteMessagesTransferComplete(handler,
12490 SatellitePositionUpdateHandler.EVENT_MESSAGE_TRANSFER_STATE_UPDATE, null);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012491 mSatellitePositionUpdateHandlers.put(callback.asBinder(), handler);
Sarah Chineccfbd12023-01-20 19:00:35 -080012492
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012493 int result = (int) sendRequest(CMD_START_SATELLITE_POSITION_UPDATES, null, validSubId);
Sarah Chineccfbd12023-01-20 19:00:35 -080012494 if (DBG) log("startSatellitePositionUpdates result: " + result);
12495 return result;
12496 }
12497
12498 /**
12499 * Stop receiving satellite position updates.
12500 * This can be called by the pointing UI when the user stops pointing to the satellite.
12501 *
12502 * @param subId The subId to stop satellite position updates for.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012503 * @param callback The callback that was passed in {@link
12504 * #startSatellitePositionUpdates(int, ISatelliteStateListener)}
Sarah Chineccfbd12023-01-20 19:00:35 -080012505 * @return The result of the operation.
12506 */
12507 @Override
12508 @SatelliteManager.SatelliteServiceResult public int stopSatellitePositionUpdates(int subId,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012509 @NonNull ISatelliteStateListener callback) {
Sarah Chinf75afa72023-02-01 01:32:19 -080012510 enforceSatelliteCommunicationPermission("stopSatellitePositionUpdates");
12511
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012512 final int validSubId = getValidSatelliteSubId(subId);
12513 if (!isSatelliteEnabled(validSubId)) {
Sarah Chinf75afa72023-02-01 01:32:19 -080012514 return SatelliteManager.SATELLITE_SERVICE_DISABLED;
12515 }
12516
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012517 Phone phone = getPhoneOrDefault(validSubId, "stopSatellitePositionUpdates");
Sarah Chineccfbd12023-01-20 19:00:35 -080012518 if (phone == null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012519 return SatelliteManager.SATELLITE_SERVICE_INVALID_TELEPHONY_STATE;
Sarah Chineccfbd12023-01-20 19:00:35 -080012520 }
12521
12522 SatellitePositionUpdateHandler handler =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012523 mSatellitePositionUpdateHandlers.remove(callback.asBinder());
Sarah Chineccfbd12023-01-20 19:00:35 -080012524 if (handler == null) {
12525 loge("stopSatellitePositionUpdates: No SatellitePositionArgument");
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012526 return SatelliteManager.SATELLITE_SERVICE_CALLBACK_NOT_REGISTERED;
Sarah Chineccfbd12023-01-20 19:00:35 -080012527 } else {
12528 phone.unregisterForSatellitePointingInfoChanged(handler);
12529 phone.unregisterForSatelliteMessagesTransferComplete(handler);
12530 }
12531
12532 if (!mSatellitePositionUpdateHandlers.isEmpty()) {
12533 log("stopSatellitePositionUpdates: other listeners still exist.");
12534 return SatelliteManager.SATELLITE_SERVICE_SUCCESS;
12535 }
12536
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012537 int result = (int) sendRequest(CMD_STOP_SATELLITE_POSITION_UPDATES, null, validSubId);
Sarah Chineccfbd12023-01-20 19:00:35 -080012538 if (DBG) log("stopSatellitePositionUpdates result: " + result);
12539 return result;
12540 }
12541
12542 /**
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012543 * Get maximum number of characters per text message on satellite.
12544 * @param subId - The subId of the subscription.
12545 * @param callback - The callback that will be used to send maximum characters limit
12546 * if operation is successful.
12547 * @return The result of the operation.
12548 *
12549 * @throws SecurityException if the caller doesn't have the required permission.
12550 */
12551 @Override
12552 public int getMaxCharactersPerSatelliteTextMessage(int subId, IIntegerConsumer callback) {
12553 enforceSatelliteCommunicationPermission("getMaxCharactersPerSatelliteTextMessage");
12554
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012555 final int validSubId = getValidSatelliteSubId(subId);
12556 if (!isSatelliteEnabled(validSubId)) {
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012557 return SatelliteManager.SATELLITE_SERVICE_DISABLED;
12558 }
12559
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012560 Phone phone = getPhoneOrDefault(validSubId, "getMaxCharactersPerSatelliteTextMessage");
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012561 if (phone == null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012562 return SatelliteManager.SATELLITE_SERVICE_INVALID_TELEPHONY_STATE;
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012563 }
12564
12565 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012566 int result = (int) sendRequest(
12567 CMD_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG, argument, validSubId);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012568 if (DBG) log("getMaxCharPerTextMessageOnSatellite result: " + result);
12569 return result;
12570 }
12571
12572 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012573 * Register the subscription with a satellite provider.
12574 * This is needed to register the subscription if the provider allows dynamic registration.
12575 *
12576 * @param subId The subId of the subscription to be provisioned.
12577 * @param features List of features to be provisioned.
12578 * @param callback The callback to get the error code of the request.
12579 * @return The signal transport used by the caller to cancel the provision request.
12580 * @throws SecurityException if the caller doesn't have the required permission.
12581 */
12582 @Override
12583 public ICancellationSignal provisionSatelliteService(int subId, int[] features,
12584 IIntegerConsumer callback) {
12585 enforceSatelliteCommunicationPermission("provisionSatelliteService");
12586
12587 final int validSubId = getValidSatelliteSubId(subId);
12588 String callbackRemoteExErrorMessage = "provisionSatelliteService: callback not available.";
12589 Phone phone = getPhoneOrDefault(validSubId, "provisionSatelliteService");
12590 if (phone == null) {
12591 sendResponse(callback, SatelliteManager.SATELLITE_SERVICE_INVALID_TELEPHONY_STATE,
12592 callbackRemoteExErrorMessage);
12593 return null;
12594 }
12595
12596 if (mSatelliteProvisionCallbacks.containsKey(validSubId)) {
12597 sendResponse(callback, SatelliteManager.SATELLITE_SERVICE_PROVISION_IN_PROGRESS,
12598 callbackRemoteExErrorMessage);
12599 return null;
12600 }
12601
12602 if (isSatelliteEnabled(validSubId)) {
12603 sendResponse(callback, SatelliteManager.SATELLITE_SERVICE_ALREADY_PROVISIONED,
12604 callbackRemoteExErrorMessage);
12605 return null;
12606 }
12607
12608 sendRequestAsync(CMD_PROVISION_SATELLITE_SERVICE,
12609 new ProvisionSatelliteServiceArgument(features, callback, validSubId), phone, null);
12610
12611 ICancellationSignal cancelTransport = CancellationSignal.createTransport();
12612 CancellationSignal.fromTransport(cancelTransport)
12613 .setOnCancelListener(() -> {
12614 sendRequestAsync(CMD_CANCEL_PROVISION_SATELLITE_SERVICE, validSubId);
12615 });
12616 return cancelTransport;
12617 }
12618
12619 /**
12620 * Register for the satellite provision state change.
12621 *
12622 * @param subId The subId of the subscription associated with the satellite service.
12623 * @param callback The callback to handle the satellite provision state changed event.
12624 * @throws SecurityException if the caller doesn't have the required permission.
12625 */
12626 @Override
12627 @SatelliteManager.SatelliteServiceResult
12628 public int registerForSatelliteProvisionStateChanged(
12629 int subId, ISatelliteStateListener callback) {
12630 //enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
12631
12632 final int validSubId = getValidSatelliteSubId(subId);
12633 Phone phone = getPhoneOrDefault(
12634 validSubId, "registerForSatelliteProvisionStateChanged");
12635 if (phone == null) {
12636 return SatelliteManager.SATELLITE_SERVICE_INVALID_TELEPHONY_STATE;
12637 }
12638
12639 SatelliteProvisionStateChangedHandler satelliteProvisionStateChangedHandler =
12640 mSatelliteProvisionStateChangedHandlers.get(validSubId);
12641 if (satelliteProvisionStateChangedHandler == null) {
12642 satelliteProvisionStateChangedHandler =
12643 new SatelliteProvisionStateChangedHandler(
12644 Looper.getMainLooper(), validSubId);
12645 phone.registerForSatelliteProvisionStateChanged(
12646 satelliteProvisionStateChangedHandler,
12647 SatelliteProvisionStateChangedHandler.EVENT_PROVISION_STATE_CHANGED, null);
12648 }
12649
12650 if (callback != null) {
12651 satelliteProvisionStateChangedHandler.addListener(callback);
12652 }
12653 mSatelliteProvisionStateChangedHandlers.put(
12654 validSubId, satelliteProvisionStateChangedHandler);
12655 return SatelliteManager.SATELLITE_SERVICE_SUCCESS;
12656 }
12657
12658 /**
12659 * Unregister for the satellite provision state change.
12660 *
12661 * @param subId The subId of the subscription associated with the satellite service.
12662 * @param callback The callback that was passed to
12663 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteStateListener)}
12664 * @throws SecurityException if the caller doesn't have the required permission.
12665 */
12666 @Override
12667 @SatelliteManager.SatelliteServiceResult
12668 public int unregisterForSatelliteProvisionStateChanged(
12669 int subId, ISatelliteStateListener callback) {
12670 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
12671
12672 final int validSubId = getValidSatelliteSubId(subId);
12673 SatelliteProvisionStateChangedHandler satelliteProvisionStateChangedHandler =
12674 mSatelliteProvisionStateChangedHandlers.get(validSubId);
12675 if (satelliteProvisionStateChangedHandler != null) {
12676 if (satelliteProvisionStateChangedHandler.removeListener(callback)) {
12677 return SatelliteManager.SATELLITE_SERVICE_SUCCESS;
12678 }
12679 }
12680 return SatelliteManager.SATELLITE_SERVICE_CALLBACK_NOT_REGISTERED;
12681 }
12682
12683 /**
12684 * Get the list of provisioned satellite features.
12685 *
12686 * @param subId The subId of the subscription associated with the satellite service.
12687 * @param callback The callback to get the list of provisioned satellite features.
12688 * @return The error code of the request.
12689 * @throws SecurityException if the caller doesn't have the required permission.
12690 */
12691 @Override
12692 @SatelliteManager.SatelliteServiceResult
12693 public int getProvisionedSatelliteFeatures(int subId, IIntArrayConsumer callback) {
12694 enforceSatelliteCommunicationPermission("getProvisionedSatelliteFeatures");
12695
12696 final int validSubId = getValidSatelliteSubId(subId);
12697 if (!isSatelliteEnabled(validSubId)) {
12698 return SatelliteManager.SATELLITE_SERVICE_DISABLED;
12699 }
12700
12701 final Phone phone = getPhoneOrDefault(validSubId, "getProvisionedSatelliteFeatures");
12702 if (phone == null) {
12703 return SatelliteManager.SATELLITE_SERVICE_INVALID_TELEPHONY_STATE;
12704 }
12705
12706 int result = (int) sendRequest(
12707 CMD_GET_PROVISIONED_SATELLITE_FEATURES, callback, validSubId);
12708 if (DBG) log("getProvisionedSatelliteFeatures result: " + result);
12709 return result;
12710 }
12711
12712 private void handleCmdProvisionSatelliteService(@NonNull ProvisionSatelliteServiceArgument arg,
12713 @NonNull Phone phone, Message onCompleted) {
12714 String callbackRemoteExErrorMessage =
12715 "handleCmdProvisionSatelliteService: callback not available.";
12716 if (arg == null) {
12717 loge("handleCmdProvisionSatelliteService: arg is null");
12718 return;
12719 }
12720 if (phone == null) {
12721 loge("handleCmdProvisionSatelliteService: phone is null");
12722 sendResponse(arg.callback, SatelliteManager.SATELLITE_SERVICE_INVALID_TELEPHONY_STATE,
12723 callbackRemoteExErrorMessage);
12724 return;
12725 }
12726
12727 if (!mSatelliteProvisionCallbacks.containsKey(arg.subId)) {
12728 mSatelliteProvisionCallbacks.put(arg.subId, arg.callback);
12729 phone.provisionSatelliteService(onCompleted, phone.getImei(), phone.getMsisdn(),
12730 getSatelliteImsi(arg.subId), arg.features);
12731 } else {
12732 sendResponse(arg.callback, SatelliteManager.SATELLITE_SERVICE_PROVISION_IN_PROGRESS,
12733 callbackRemoteExErrorMessage);
12734 }
12735 }
12736
12737 private void handleEventProvisionSatelliteServiceDone(MainThreadRequest request) {
12738 final ProvisionSatelliteServiceArgument arg =
12739 (ProvisionSatelliteServiceArgument) request.argument;
12740 if (arg == null) {
12741 loge("handleEventProvisionSatelliteServiceDone: arg is null");
12742 return;
12743 }
12744
12745 IIntegerConsumer callback = mSatelliteProvisionCallbacks.remove(arg.subId);
12746 if (callback == null) {
12747 loge("handleEventProvisionSatelliteServiceDone: callback is null for subId="
12748 + arg.subId);
12749 return;
12750 }
12751
12752 int result = (int) request.result;
12753 if (DBG) {
12754 log("handleEventProvisionSatelliteServiceDone: result="
12755 + result + ", subId=" + arg.subId);
12756 }
12757 sendResponse(callback, result,
12758 "handleEventProvisionSatelliteServiceDone: callback not available.");
12759
12760 if (result == SatelliteManager.SATELLITE_SERVICE_SUCCESS) {
12761 setSatelliteEnabled(arg.subId, true);
12762 }
12763
12764 /**
12765 * We need to update satellite provision status in SubscriptionController
12766 * or SatelliteController.
12767 * TODO (b/267826133) we need to do this for all subscriptions on the device.
12768 */
12769 registerForSatelliteProvisionStateChanged(arg.subId, null);
12770 }
12771
12772 private void handleCmdCancelProvisionSatelliteService(int subId, Message onCompleted) {
12773 final Phone phone = getPhoneOrDefault(
12774 subId, "handleCmdCancelProvisionSatelliteService");
12775 if (phone == null) {
12776 return;
12777 }
12778 phone.cancelProvisionSatelliteService(onCompleted, getSatelliteImsi(subId));
12779 }
12780
12781 private void sendResponse(@NonNull IIntegerConsumer callback, int result, String message) {
12782 Objects.requireNonNull(callback);
12783
12784 try {
12785 callback.accept(result);
12786 } catch (RemoteException e) {
12787 Log.w(LOG_TAG, message);
12788 }
12789 }
12790
12791 private String getSatelliteImsi(int subId) {
12792 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12793 return "";
12794 }
12795
12796 if (mSubscriptionController == null) {
12797 loge("getSatelliteImsi: mSubscriptionController is null");
12798 return "";
12799 }
12800 return mSubscriptionController.getImsiPrivileged(subId);
12801 }
12802
12803 private Phone getPhoneOrDefault(int subId, String caller) {
12804 Phone phone = getPhone(subId);
12805 if (phone == null) {
12806 loge(caller + " called with invalid subId: " + subId
12807 + ". Retrying with default phone.");
12808 phone = getDefaultPhone();
12809 if (phone == null) {
12810 loge(caller + " failed with no phone object.");
12811 }
12812 }
12813 return phone;
12814 }
12815
12816 /**
12817 * Check if satellite is enabled for a subscription.
12818 *
12819 * Note: this is the version without permission check for telephony internal use only. The
12820 * caller need to take care of the permission check.
12821 */
12822 private boolean isSatelliteEnabled(int subId) {
12823 if (subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12824 if (mSubscriptionController == null) {
12825 loge("setSatelliteEnabled mSubscriptionController is null");
12826 return false;
12827 }
12828
12829 String strResult = mSubscriptionController.getSubscriptionProperty(
12830 subId, SubscriptionManager.SATELLITE_ENABLED);
12831 if (strResult != null) {
12832 int intResult = Integer.parseInt(strResult);
12833 return (intResult == 1) ? true : false;
12834 }
12835 } else {
12836 //TODO (b/267826133): check via SatelliteController
12837 }
12838 return false;
12839 }
12840
12841 /**
12842 * Set satellite enabled for a subscription.
12843 *
12844 * The permission {@link android.Manifest.permission#MODIFY_PHONE_STATE} will be enforced by
12845 * {@link SubscriptionController} when setting satellite enabled for an active subscription.
12846 * Otherwise, {@link android.Manifest.permission#SATELLITE_COMMUNICATION} will be enforced.
12847 */
12848 private void setSatelliteEnabled(int subId, boolean isEnabled) {
12849 if (subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12850 if (mSubscriptionController == null) {
12851 loge("setSatelliteEnabled mSubscriptionController is null");
12852 return;
12853 }
12854 mSubscriptionController.setSubscriptionProperty(
12855 subId, SubscriptionManager.SATELLITE_ENABLED, isEnabled ? "1" : "0");
12856 } else {
12857 //TODO (b/267826133): enable via SatelliteController
12858 }
12859 }
12860
12861 private int getValidSatelliteSubId(int subId) {
12862 if (mSubscriptionController == null) {
12863 loge("getValidSatelliteSubId mSubscriptionController is null. "
12864 + "Use DEFAULT_SUBSCRIPTION_ID for subId=" + subId);
12865 return SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
12866 }
12867 final long identity = Binder.clearCallingIdentity();
12868 try {
12869 Context context = getDefaultPhone().getContext();
12870 if (mSubscriptionController.isActiveSubId(
12871 subId, context.getOpPackageName(), context.getAttributionTag())) {
12872 return subId;
12873 }
12874 } finally {
12875 Binder.restoreCallingIdentity(identity);
12876 }
12877 if (DBG) log("getValidSatelliteSubId: use DEFAULT_SUBSCRIPTION_ID for subId=" + subId);
12878 return SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
12879 }
12880
12881 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000012882 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
12883 *
12884 * <p>This method behaves in one of the following ways:
12885 * <ul>
12886 * <li>return true : if the calling package has the appop permission {@link
12887 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
12888 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
12889 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
12890 * Owner device identifier access check, or the calling package has carrier privileges</>
12891 * <li>throw SecurityException: if the caller does not meet any of the requirements.
12892 * </ul>
12893 */
12894 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
12895 String callingPackage, @Nullable String callingFeatureId, String message) {
12896 for (Phone phone : PhoneFactory.getPhones()) {
12897 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
12898 phone.getSubId(), callingPackage, callingFeatureId, message)) {
12899 return true;
12900 }
12901 }
12902 return false;
12903 }
arunvoddud7401012022-12-15 16:08:12 +000012904
12905 /**
12906 * Class binds the consumer[callback] and carrierId.
12907 */
12908 private static class CallerCallbackInfo {
12909 private final Consumer<Integer> mConsumer;
12910 private final int mCarrierId;
12911
12912 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
12913 mConsumer = consumer;
12914 mCarrierId = carrierId;
12915 }
12916
12917 public Consumer<Integer> getConsumer() {
12918 return mConsumer;
12919 }
12920
12921 public int getCarrierId() {
12922 return mCarrierId;
12923 }
12924 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012925}