blob: 5fe6717e81b1ff61752253df16dcdb72bbf89268 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
Gil Cukierman1c0eb932022-12-06 22:28:24 +000020import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK;
jimsunf9ec1622022-09-13 21:18:43 +080021import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO;
Hall Liud892bec2018-11-30 14:51:45 -080022
Shuo Qianccbaf742021-02-22 18:32:21 -080023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
24import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070025import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070026import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000027import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070028
Brad Ebinger34c09a52021-02-17 23:23:21 +000029import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080030import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080031import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070032import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000033import android.annotation.RequiresPermission;
Sarah Chin532d6bb2022-12-28 22:50:43 -080034import android.app.ActivityManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080036import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070037import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000038import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080039import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000040import android.compat.annotation.ChangeId;
41import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070042import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070043import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.content.Context;
45import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070046import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070047import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070048import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049import android.net.Uri;
50import android.os.AsyncResult;
51import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080052import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.os.Bundle;
54import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070055import android.os.IBinder;
tom hsu0b59d292022-09-29 23:49:21 +080056import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057import android.os.Looper;
58import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070059import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080060import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070061import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070062import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080063import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080064import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070065import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070066import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080067import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070068import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070069import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070070import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070071import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070072import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080073import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070074import android.provider.Telephony;
arunvoddud7401012022-12-15 16:08:12 +000075import android.service.carrier.CarrierIdentifier;
Inseob Kim14bb3d02018-12-13 17:11:34 +090076import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080077import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080078import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070079import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080080import android.telephony.AccessNetworkConstants;
81import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070082import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070083import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080084import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070085import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080086import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070087import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080088import android.telephony.CarrierRestrictionRules;
Hui Wang9b5793a2022-12-05 14:38:06 -060089import android.telephony.CellBroadcastIdRange;
yincheng zhao2737e882019-09-06 17:06:54 -070090import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080091import android.telephony.CellIdentityCdma;
92import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070093import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070094import android.telephony.CellInfoGsm;
95import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070096import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080097import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070098import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070099import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700100import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -0800101import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700102import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -0800103import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -0700104import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800105import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800106import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700107import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800108import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700109import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800110import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800111import android.telephony.SignalStrengthUpdateRequest;
112import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800113import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800114import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800115import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700116import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700117import android.telephony.TelephonyManager;
Jack Yuf5badd92022-12-08 00:50:53 -0800118import android.telephony.TelephonyManager.SimState;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800119import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800120import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800121import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000122import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000123import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000124import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700125import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700126import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800127import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800128import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700129import android.telephony.gba.GbaAuthRequest;
130import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700131import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800132import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000133import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000134import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700135import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000136import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700137import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800138import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700139import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800140import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700141import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000142import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700143import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800144import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800145import android.telephony.ims.stub.ImsRegistrationImplBase;
Sarah Chineccfbd12023-01-20 19:00:35 -0800146import android.telephony.satellite.ISatellitePositionUpdateCallback;
147import android.telephony.satellite.PointingInfo;
148import android.telephony.satellite.SatelliteManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700149import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800150import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700151import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700152import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800153import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800154
Andrew Lee312e8172014-10-23 17:01:36 -0700155import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800156import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800157import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800158import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800159import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700160import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700161import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700162import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800163import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800164import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700165import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700166import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800167import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700168import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800169import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800170import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800171import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700172import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000173import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700174import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800175import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700176import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800177import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800178import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800179import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700180import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700181import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700182import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700183import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700184import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800185import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700186import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700187import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700188import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700189import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800190import com.android.internal.telephony.RILConstants;
Sarah Chineccfbd12023-01-20 19:00:35 -0800191import com.android.internal.telephony.RILUtils;
Daniel Bright94f43662021-03-01 14:43:40 -0800192import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700193import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000194import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700195import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700196import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800197import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800198import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800199import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700200import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000201import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800202import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700203import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800204import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700205import com.android.internal.telephony.imsphone.ImsPhone;
206import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000207import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800208import com.android.internal.telephony.metrics.TelephonyMetrics;
Jack Yu285100e2022-12-02 22:48:35 -0800209import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
210import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700211import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700212import com.android.internal.telephony.uicc.IccIoResult;
213import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800214import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700215import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800216import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700217import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000218import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800219import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000220import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800221import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000222import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700223import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700224import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800225import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800226import com.android.phone.callcomposer.CallComposerPictureManager;
227import com.android.phone.callcomposer.CallComposerPictureTransfer;
228import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700229import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700230import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000231import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700232import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800233import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700234import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700235import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800236import com.android.services.telephony.TelecomAccountRegistry;
237import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800238import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800239
Hall Liu82694d52020-12-11 18:22:04 -0800240import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700241import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800242import java.io.IOException;
243import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700244import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700245import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800246import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000247import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800248import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800249import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800250import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800251import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100252import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800253import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700254import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800255import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800256import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700257import java.util.UUID;
Sarah Chineccfbd12023-01-20 19:00:35 -0800258import java.util.concurrent.ConcurrentHashMap;
Hall Liu82694d52020-12-11 18:22:04 -0800259import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800260import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800261import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700262
263/**
264 * Implementation of the ITelephony interface.
265 */
Santos Cordon117fee72014-05-16 17:56:12 -0700266public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700267 private static final String LOG_TAG = "PhoneInterfaceManager";
268 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
269 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800270 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700271
272 // Message codes used with mMainThreadHandler
273 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700274 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
275 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700276 private static final int CMD_OPEN_CHANNEL = 9;
277 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
278 private static final int CMD_CLOSE_CHANNEL = 11;
279 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800280 private static final int CMD_NV_READ_ITEM = 13;
281 private static final int EVENT_NV_READ_ITEM_DONE = 14;
282 private static final int CMD_NV_WRITE_ITEM = 15;
283 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
284 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
285 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700286 private static final int CMD_RESET_MODEM_CONFIG = 19;
287 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800288 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
289 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800290 private static final int CMD_SEND_ENVELOPE = 25;
291 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000292 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
293 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700294 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
295 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
296 private static final int CMD_EXCHANGE_SIM_IO = 31;
297 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800298 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
299 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700300 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
301 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700302 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
303 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700304 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
305 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
306 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
307 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700308 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
309 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
310 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
311 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700312 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800313 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
314 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000315 private static final int CMD_SWITCH_SLOTS = 50;
316 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700317 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
318 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
319 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
320 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
321 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
322 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
323 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
324 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700325 private static final int CMD_GET_ALL_CELL_INFO = 60;
326 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
327 private static final int CMD_GET_CELL_LOCATION = 62;
328 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700329 private static final int CMD_MODEM_REBOOT = 64;
330 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700331 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
332 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800333 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
334 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700335 private static final int CMD_GET_MODEM_STATUS = 70;
336 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700337 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
338 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700339 private static final int CMD_ERASE_MODEM_CONFIG = 74;
340 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800341 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
342 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
343 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
344 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800345 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
346 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800347 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800348 private static final int CMD_GET_CALL_FORWARDING = 83;
349 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
350 private static final int CMD_SET_CALL_FORWARDING = 85;
351 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
352 private static final int CMD_GET_CALL_WAITING = 87;
353 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
354 private static final int CMD_SET_CALL_WAITING = 89;
355 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700356 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
357 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
358 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
359 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700360 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
361 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800362 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
363 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800364 private static final int CMD_SET_DATA_THROTTLING = 99;
365 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800366 private static final int CMD_SET_SIM_POWER = 101;
367 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800368 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
369 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
370 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
371 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800372 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
373 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000374 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800375 private static final int CMD_GET_SLICING_CONFIG = 110;
376 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800377 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700378 private static final int CMD_ENABLE_VONR = 113;
379 private static final int EVENT_ENABLE_VONR_DONE = 114;
380 private static final int CMD_IS_VONR_ENABLED = 115;
381 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700382 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
383 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Sarah Chineccfbd12023-01-20 19:00:35 -0800384 private static final int CMD_START_SATELLITE_POSITION_UPDATES = 119;
385 private static final int EVENT_START_SATELLITE_POSITION_UPDATES_DONE = 120;
386 private static final int CMD_STOP_SATELLITE_POSITION_UPDATES = 121;
387 private static final int EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE = 122;
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800388 // Parameters of select command.
389 private static final int SELECT_COMMAND = 0xA4;
390 private static final int SELECT_P1 = 0x04;
391 private static final int SELECT_P2 = 0;
392 private static final int SELECT_P3 = 0x10;
393
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000394 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
395 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
396
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700397 /** The singleton instance. */
398 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800399 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700400
Wink Saville3ab207e2014-11-20 13:07:20 -0800401 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800402 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800403 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700404 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800405 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700406 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800407 private MainThreadHandler mMainThreadHandler;
Jack Yue37dd262022-12-16 11:53:37 -0800408 private final SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800409 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700410 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800411 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700412
Peter Wangdafb9ac2020-01-15 14:13:38 -0800413 /** User Activity */
414 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800415 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
416
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700417 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chineccfbd12023-01-20 19:00:35 -0800418 private Map<Integer, SatellitePositionUpdateHandler> mSatellitePositionUpdateHandlers =
419 new ConcurrentHashMap<>();
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700420
Derek Tan97ebb422014-09-05 16:55:38 -0700421 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
422 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800423 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800424 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700425
Michelecea4cf22018-12-21 15:00:11 -0800426 // String to store multi SIM allowed
427 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
428
Derek Tan740e1672017-06-27 14:56:27 -0700429 // The AID of ISD-R.
430 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
431
yinxub1bed742017-04-17 11:45:04 -0700432 private NetworkScanRequestTracker mNetworkScanRequestTracker;
433
David Kelly5e06a7f2018-03-12 14:10:59 +0000434 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
435 private static final int MANUFACTURER_CODE_LENGTH = 8;
436
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800437 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800438 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800439
Sarah Chin2ec39f62022-08-31 17:03:26 -0700440 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
441 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
442
Derek Tan89e89d42014-07-08 17:00:10 -0700443 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700444 * Experiment flag to enable erase modem config on reset network, default value is false
445 */
446 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
447 "reset_network_erase_modem_config_enabled";
448
Rambo Wang0f050d82021-02-12 11:43:36 -0800449 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800450
Gary Jian76280a42022-12-07 16:18:33 +0800451 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
452
sandeepjsb6c87872021-09-27 15:34:44 +0000453 /**
454 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
455 * one ICCID active at the same time.
456 * Apps should use below API signatures if targeting SDK is T and beyond.
457 *
458 * @hide
459 */
460 @ChangeId
461 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
462 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800463
Naina Nallurid63128d2019-09-17 14:10:30 -0700464 /**
Chen Xu540470b2021-12-14 17:15:47 -0800465 * Apps targeting on Android T and beyond will get exception whenever icc close channel
466 * operation fails.
467 */
468 @ChangeId
469 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
470 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
471
472 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700473 * A request object to use for transmitting data to an ICC.
474 */
475 private static final class IccAPDUArgument {
476 public int channel, cla, command, p1, p2, p3;
477 public String data;
478
479 public IccAPDUArgument(int channel, int cla, int command,
480 int p1, int p2, int p3, String data) {
481 this.channel = channel;
482 this.cla = cla;
483 this.command = command;
484 this.p1 = p1;
485 this.p2 = p2;
486 this.p3 = p3;
487 this.data = data;
488 }
489 }
490
491 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700492 * A request object to use for transmitting data to an ICC.
493 */
494 private static final class ManualNetworkSelectionArgument {
495 public OperatorInfo operatorInfo;
496 public boolean persistSelection;
497
498 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
499 this.operatorInfo = operatorInfo;
500 this.persistSelection = persistSelection;
501 }
502 }
503
Sarah Chin71b3a852022-09-28 15:54:19 -0700504 private static final class PurchasePremiumCapabilityArgument {
505 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700506 public @NonNull IIntegerConsumer callback;
507
508 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800509 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700510 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700511 this.callback = callback;
512 }
513 }
514
Sarah Chineccfbd12023-01-20 19:00:35 -0800515 private static final class SatellitePositionUpdateHandler extends Handler {
516 public static final int EVENT_POSITION_UPDATE = 1;
517 public static final int EVENT_MESSAGE_TRANSFER_STATE_UPDATE = 2;
518
519 private final ISatellitePositionUpdateCallback mCallback;
520
521 SatellitePositionUpdateHandler(ISatellitePositionUpdateCallback callback, Looper looper) {
522 super(looper);
523 mCallback = callback;
524 }
525
526 @Override
527 public void handleMessage(@NonNull Message msg) {
528 switch (msg.what) {
529 case EVENT_POSITION_UPDATE: {
530 AsyncResult ar = (AsyncResult) msg.obj;
531 PointingInfo pointingInfo = (PointingInfo) ar.result;
532 try {
533 mCallback.onSatellitePositionUpdate(pointingInfo);
534 } catch (RemoteException e) {
535 loge("EVENT_POSITION_UPDATE RemoteException: " + e);
536 }
537 break;
538 }
539 case EVENT_MESSAGE_TRANSFER_STATE_UPDATE: {
540 AsyncResult ar = (AsyncResult) msg.obj;
541 int state = (int) ar.result;
542 try {
543 mCallback.onMessageTransferStateUpdate(state);
544 } catch (RemoteException e) {
545 loge("EVENT_MESSAGE_TRANSFER_STATE_UPDATE RemoteException: " + e);
546 }
547 break;
548 }
549 default:
550 loge("SatellitePositionUpdateHandler unknown event: " + msg.what);
551 }
552 }
553 }
554
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700555 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700556 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
557 * request after sending. The main thread will notify the request when it is complete.
558 */
559 private static final class MainThreadRequest {
560 /** The argument to use for the request */
561 public Object argument;
562 /** The result of the request that is run on the main thread */
563 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800564 // The subscriber id that this request applies to. Defaults to
565 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
566 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700567
Nathan Harold92bed182018-10-12 18:16:49 -0700568 // In cases where subId is unavailable, the caller needs to specify the phone.
569 public Phone phone;
570
vagdeviaf9a5b92018-08-15 16:01:53 -0700571 public WorkSource workSource;
572
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700573 public MainThreadRequest(Object argument) {
574 this.argument = argument;
575 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800576
Nathan Harold92bed182018-10-12 18:16:49 -0700577 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
578 this.argument = argument;
579 if (phone != null) {
580 this.phone = phone;
581 }
582 this.workSource = workSource;
583 }
584
vagdeviaf9a5b92018-08-15 16:01:53 -0700585 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800586 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800587 if (subId != null) {
588 this.subId = subId;
589 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700590 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800591 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700592 }
593
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800594 private static final class IncomingThirdPartyCallArgs {
595 public final ComponentName component;
596 public final String callId;
597 public final String callerDisplayName;
598
599 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
600 String callerDisplayName) {
601 this.component = component;
602 this.callId = callId;
603 this.callerDisplayName = callerDisplayName;
604 }
605 }
606
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700607 /**
608 * A handler that processes messages on the main thread in the phone process. Since many
609 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
610 * inbound binder threads to the main thread in the phone process. The Binder thread
611 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
612 * on, which will be notified when the operation completes and will contain the result of the
613 * request.
614 *
615 * <p>If a MainThreadRequest object is provided in the msg.obj field,
616 * note that request.result must be set to something non-null for the calling thread to
617 * unblock.
618 */
619 private final class MainThreadHandler extends Handler {
620 @Override
621 public void handleMessage(Message msg) {
622 MainThreadRequest request;
623 Message onCompleted;
624 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000625 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700626 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800627 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700628
629 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700630 case CMD_HANDLE_USSD_REQUEST: {
631 request = (MainThreadRequest) msg.obj;
632 final Phone phone = getPhoneFromRequest(request);
633 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800634 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700635 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700636
Pengquan Menga1bb6272018-09-06 09:59:22 -0700637 if (!isUssdApiAllowed(request.subId)) {
638 // Carrier does not support use of this API, return failure.
639 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
640 UssdResponse response = new UssdResponse(ussdRequest, null);
641 Bundle returnData = new Bundle();
642 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
643 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700644
Pengquan Menga1bb6272018-09-06 09:59:22 -0700645 request.result = true;
646 notifyRequester(request);
647 return;
648 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700649
Pengquan Menga1bb6272018-09-06 09:59:22 -0700650 try {
651 request.result = phone != null
652 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
653 } catch (CallStateException cse) {
654 request.result = false;
655 }
656 // Wake up the requesting thread
657 notifyRequester(request);
658 break;
pkanwar32d516d2016-10-14 19:37:38 -0700659 }
660
Yorke Lee716f67e2015-06-17 15:39:16 -0700661 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700662 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700663 final Phone phone = getPhoneFromRequest(request);
664 request.result = phone != null ?
665 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
666 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700667 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700668 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700669 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700670 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700671
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700672 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700673 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700674 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000675 uiccPort = getUiccPortFromRequest(request);
676 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700677 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800678 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700679 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700680 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700681 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800682 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000683 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800684 iccArgument.channel, iccArgument.cla, iccArgument.command,
685 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
686 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700687 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700688 break;
689
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700690 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700691 ar = (AsyncResult) msg.obj;
692 request = (MainThreadRequest) ar.userObj;
693 if (ar.exception == null && ar.result != null) {
694 request.result = ar.result;
695 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800696 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700697 if (ar.result == null) {
698 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800699 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700700 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800701 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700702 } else {
703 loge("iccTransmitApduLogicalChannel: Unknown exception");
704 }
705 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700706 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700707 break;
708
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700709 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
710 request = (MainThreadRequest) msg.obj;
711 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000712 uiccPort = getUiccPortFromRequest(request);
713 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700714 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800715 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700716 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700717 } else {
718 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800719 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000720 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800721 iccArgument.cla, iccArgument.command, iccArgument.p1,
722 iccArgument.p2,
723 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700724 }
725 break;
726
727 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
728 ar = (AsyncResult) msg.obj;
729 request = (MainThreadRequest) ar.userObj;
730 if (ar.exception == null && ar.result != null) {
731 request.result = ar.result;
732 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800733 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700734 if (ar.result == null) {
735 loge("iccTransmitApduBasicChannel: Empty response");
736 } else if (ar.exception instanceof CommandException) {
737 loge("iccTransmitApduBasicChannel: CommandException: " +
738 ar.exception);
739 } else {
740 loge("iccTransmitApduBasicChannel: Unknown exception");
741 }
742 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700743 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700744 break;
745
746 case CMD_EXCHANGE_SIM_IO:
747 request = (MainThreadRequest) msg.obj;
748 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000749 uiccPort = getUiccPortFromRequest(request);
750 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700751 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800752 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700753 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700754 } else {
755 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
756 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000757 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700758 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
759 iccArgument.data, onCompleted);
760 }
761 break;
762
763 case EVENT_EXCHANGE_SIM_IO_DONE:
764 ar = (AsyncResult) msg.obj;
765 request = (MainThreadRequest) ar.userObj;
766 if (ar.exception == null && ar.result != null) {
767 request.result = ar.result;
768 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800769 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700770 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700771 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700772 break;
773
Derek Tan4d5e5c12014-02-04 11:54:58 -0800774 case CMD_SEND_ENVELOPE:
775 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000776 uiccPort = getUiccPortFromRequest(request);
777 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700778 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800779 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700780 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700781 } else {
782 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800783 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700784 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800785 break;
786
787 case EVENT_SEND_ENVELOPE_DONE:
788 ar = (AsyncResult) msg.obj;
789 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700790 if (ar.exception == null && ar.result != null) {
791 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800792 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800793 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700794 if (ar.result == null) {
795 loge("sendEnvelopeWithStatus: Empty response");
796 } else if (ar.exception instanceof CommandException) {
797 loge("sendEnvelopeWithStatus: CommandException: " +
798 ar.exception);
799 } else {
800 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
801 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800802 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700803 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800804 break;
805
Shishir Agrawal566b7612013-10-28 14:41:00 -0700806 case CMD_OPEN_CHANNEL:
807 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000808 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800809 IccLogicalChannelRequest openChannelRequest =
810 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000811 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700812 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800813 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800814 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700815 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700816 } else {
817 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800818 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
819 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700820 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700821 break;
822
823 case EVENT_OPEN_CHANNEL_DONE:
824 ar = (AsyncResult) msg.obj;
825 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700826 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700827 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700828 int[] result = (int[]) ar.result;
829 int channelId = result[0];
830 byte[] selectResponse = null;
831 if (result.length > 1) {
832 selectResponse = new byte[result.length - 1];
833 for (int i = 1; i < result.length; ++i) {
834 selectResponse[i - 1] = (byte) result[i];
835 }
836 }
837 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800838 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800839
840 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700841 if (uiccPort == null) {
842 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
843 } else {
844 IccLogicalChannelRequest channelRequest =
845 (IccLogicalChannelRequest) request.argument;
846 channelRequest.channel = channelId;
847 uiccPort.onLogicalChannelOpened(channelRequest);
848 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700849 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700850 if (ar.result == null) {
851 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700852 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700853 if (ar.exception != null) {
854 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
855 }
856
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700857 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700858 if (ar.exception instanceof CommandException) {
859 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800860 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700861 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700862 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700863 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700864 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700865 }
866 }
867 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800868 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700869 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700870 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700871 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700872 break;
873
874 case CMD_CLOSE_CHANNEL:
875 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000876 uiccPort = getUiccPortFromRequest(request);
877 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700878 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800879 request.result = new IllegalArgumentException(
Chen Xue9d737e2022-01-01 23:41:31 -0800880 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800881 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700882 } else {
883 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000884 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700885 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700886 break;
887
888 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800889 ar = (AsyncResult) msg.obj;
890 request = (MainThreadRequest) ar.userObj;
891 if (ar.exception == null) {
892 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800893 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700894 if (uiccPort == null) {
895 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
896 } else {
897 final int channelId = (Integer) request.argument;
898 uiccPort.onLogicalChannelClosed(channelId);
899 }
Chen Xu540470b2021-12-14 17:15:47 -0800900 } else {
901 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800902 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800903 if (ar.exception instanceof CommandException) {
904 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
905 CommandException.Error error =
906 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800907 if (error == CommandException.Error.INVALID_ARGUMENTS) {
908 // should only throw exceptions from the binder threads.
909 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800910 "iccCloseLogicalChannel: invalid argument ");
911 }
912 } else {
913 loge("iccCloseLogicalChannel: Unknown exception");
914 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800915 request.result = (exception != null) ? exception :
916 new IllegalStateException(
917 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800918 }
919 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800920 break;
921
922 case CMD_NV_READ_ITEM:
923 request = (MainThreadRequest) msg.obj;
924 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800925 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
926 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800927 break;
928
929 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700930 ar = (AsyncResult) msg.obj;
931 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800932 if (ar.exception == null && ar.result != null) {
933 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700934 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800935 request.result = "";
936 if (ar.result == null) {
937 loge("nvReadItem: Empty response");
938 } else if (ar.exception instanceof CommandException) {
939 loge("nvReadItem: CommandException: " +
940 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700941 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800942 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700943 }
944 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700945 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700946 break;
947
Jake Hambye994d462014-02-03 13:10:13 -0800948 case CMD_NV_WRITE_ITEM:
949 request = (MainThreadRequest) msg.obj;
950 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
951 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800952 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700953 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800954 break;
955
956 case EVENT_NV_WRITE_ITEM_DONE:
957 handleNullReturnEvent(msg, "nvWriteItem");
958 break;
959
960 case CMD_NV_WRITE_CDMA_PRL:
961 request = (MainThreadRequest) msg.obj;
962 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800963 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800964 break;
965
966 case EVENT_NV_WRITE_CDMA_PRL_DONE:
967 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
968 break;
969
chen xu6dac5ab2018-10-26 17:39:23 -0700970 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800971 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700972 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800973 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800974 break;
975
chen xu6dac5ab2018-10-26 17:39:23 -0700976 case EVENT_RESET_MODEM_CONFIG_DONE:
977 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800978 break;
979
Sooraj Sasindran37444802020-08-11 10:40:43 -0700980 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
981 request = (MainThreadRequest) msg.obj;
982 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
983 request);
984 Phone phone = getPhoneFromRequest(request);
985 if (phone != null) {
986 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
987 } else {
988 loge("isNRDualConnectivityEnabled: No phone object");
989 request.result = false;
990 notifyRequester(request);
991 }
992 break;
993 }
994
995 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
996 ar = (AsyncResult) msg.obj;
997 request = (MainThreadRequest) ar.userObj;
998 if (ar.exception == null && ar.result != null) {
999 request.result = ar.result;
1000 } else {
1001 // request.result must be set to something non-null
1002 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001003 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -07001004 request.result = ar.result;
1005 } else {
1006 request.result = false;
1007 }
1008 if (ar.result == null) {
1009 loge("isNRDualConnectivityEnabled: Empty response");
1010 } else if (ar.exception instanceof CommandException) {
1011 loge("isNRDualConnectivityEnabled: CommandException: "
1012 + ar.exception);
1013 } else {
1014 loge("isNRDualConnectivityEnabled: Unknown exception");
1015 }
1016 }
1017 notifyRequester(request);
1018 break;
1019
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001020 case CMD_IS_VONR_ENABLED: {
1021 request = (MainThreadRequest) msg.obj;
1022 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
1023 request);
1024 Phone phone = getPhoneFromRequest(request);
1025 if (phone != null) {
1026 phone.isVoNrEnabled(onCompleted, request.workSource);
1027 } else {
1028 loge("isVoNrEnabled: No phone object");
1029 request.result = false;
1030 notifyRequester(request);
1031 }
1032 break;
1033 }
1034
1035 case EVENT_IS_VONR_ENABLED_DONE:
1036 ar = (AsyncResult) msg.obj;
1037 request = (MainThreadRequest) ar.userObj;
1038 if (ar.exception == null && ar.result != null) {
1039 request.result = ar.result;
1040 } else {
1041 // request.result must be set to something non-null
1042 // for the calling thread to unblock
1043 if (ar.result != null) {
1044 request.result = ar.result;
1045 } else {
1046 request.result = false;
1047 }
1048 if (ar.result == null) {
1049 loge("isVoNrEnabled: Empty response");
1050 } else if (ar.exception instanceof CommandException) {
1051 loge("isVoNrEnabled: CommandException: "
1052 + ar.exception);
1053 } else {
1054 loge("isVoNrEnabled: Unknown exception");
1055 }
1056 }
1057 notifyRequester(request);
1058 break;
1059
Sooraj Sasindran37444802020-08-11 10:40:43 -07001060 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1061 request = (MainThreadRequest) msg.obj;
1062 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1063 Phone phone = getPhoneFromRequest(request);
1064 if (phone != null) {
1065 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1066 request.workSource);
1067 } else {
1068 loge("enableNrDualConnectivity: No phone object");
1069 request.result =
1070 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1071 notifyRequester(request);
1072 }
1073 break;
1074 }
1075
1076 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1077 ar = (AsyncResult) msg.obj;
1078 request = (MainThreadRequest) ar.userObj;
1079 if (ar.exception == null) {
1080 request.result =
1081 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1082 } else {
1083 request.result =
1084 TelephonyManager
1085 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1086 if (ar.exception instanceof CommandException) {
1087 CommandException.Error error =
1088 ((CommandException) (ar.exception)).getCommandError();
1089 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1090 request.result =
1091 TelephonyManager
1092 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001093 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1094 request.result =
1095 TelephonyManager
1096 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001097 }
1098 loge("enableNrDualConnectivity" + ": CommandException: "
1099 + ar.exception);
1100 } else {
1101 loge("enableNrDualConnectivity" + ": Unknown exception");
1102 }
1103 }
1104 notifyRequester(request);
1105 break;
1106 }
1107
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001108 case CMD_ENABLE_VONR: {
1109 request = (MainThreadRequest) msg.obj;
1110 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1111 Phone phone = getPhoneFromRequest(request);
1112 if (phone != null) {
1113 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1114 request.workSource);
1115 } else {
1116 loge("setVoNrEnabled: No phone object");
1117 request.result =
1118 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1119 notifyRequester(request);
1120 }
1121 break;
1122 }
1123
1124 case EVENT_ENABLE_VONR_DONE: {
1125 ar = (AsyncResult) msg.obj;
1126 request = (MainThreadRequest) ar.userObj;
1127 if (ar.exception == null) {
1128 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1129 } else {
1130 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1131 if (ar.exception instanceof CommandException) {
1132 CommandException.Error error =
1133 ((CommandException) (ar.exception)).getCommandError();
1134 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1135 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1136 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1137 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1138 } else {
1139 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1140 }
1141 loge("setVoNrEnabled" + ": CommandException: "
1142 + ar.exception);
1143 } else {
1144 loge("setVoNrEnabled" + ": Unknown exception");
1145 }
1146 }
1147 notifyRequester(request);
1148 break;
1149 }
1150
SongFerngWang3ef3e072020-12-21 16:41:52 +08001151 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001152 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001153 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1154 request);
1155 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001156 break;
1157
SongFerngWang3ef3e072020-12-21 16:41:52 +08001158 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001159 ar = (AsyncResult) msg.obj;
1160 request = (MainThreadRequest) ar.userObj;
1161 if (ar.exception == null && ar.result != null) {
1162 request.result = ar.result; // Integer
1163 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301164 // request.result must be set to something non-null
1165 // for the calling thread to unblock
1166 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001167 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001168 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001169 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001170 loge("getAllowedNetworkTypesBitmask: CommandException: "
1171 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001172 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001173 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001174 }
1175 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001176 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001177 break;
1178
SongFerngWang3ef3e072020-12-21 16:41:52 +08001179 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001180 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001181 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1182 request);
1183 Pair<Integer, Long> reasonWithNetworkTypes =
1184 (Pair<Integer, Long>) request.argument;
1185 getPhoneFromRequest(request).setAllowedNetworkTypes(
1186 reasonWithNetworkTypes.first,
1187 reasonWithNetworkTypes.second,
1188 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001189 break;
1190
SongFerngWang3ef3e072020-12-21 16:41:52 +08001191 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1192 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001193 break;
1194
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001195 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1196 request = (MainThreadRequest)msg.obj;
1197 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001198 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001199 break;
1200
1201 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1202 ar = (AsyncResult)msg.obj;
1203 request = (MainThreadRequest)ar.userObj;
1204 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001205 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001206 break;
1207
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001208 case CMD_SET_VOICEMAIL_NUMBER:
1209 request = (MainThreadRequest) msg.obj;
1210 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1211 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001212 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1213 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001214 break;
1215
1216 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1217 handleNullReturnEvent(msg, "setVoicemailNumber");
1218 break;
1219
Stuart Scott54788802015-03-30 13:18:01 -07001220 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1221 request = (MainThreadRequest) msg.obj;
1222 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1223 request);
1224 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1225 break;
1226
1227 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1228 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1229 break;
1230
Shishir Agrawal302c8692015-06-19 13:49:39 -07001231 case CMD_PERFORM_NETWORK_SCAN:
1232 request = (MainThreadRequest) msg.obj;
1233 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1234 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1235 break;
1236
Hall Liu27d24262020-09-18 19:04:59 -07001237 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001238 request = (MainThreadRequest) msg.obj;
1239 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001240 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1241 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1242 request.argument;
1243 int callForwardingReason = args.first;
1244 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001245 break;
Hall Liu27d24262020-09-18 19:04:59 -07001246 }
1247 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001248 ar = (AsyncResult) msg.obj;
1249 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001250 TelephonyManager.CallForwardingInfoCallback callback =
1251 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1252 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001253 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001254 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001255 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1256 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1257 // Service Class is a bit mask per 3gpp 27.007. Search for
1258 // any service for voice call.
1259 if ((callForwardInfo.serviceClass
1260 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001261 callForwardingInfo = new CallForwardingInfo(
1262 callForwardInfo.status
1263 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001264 callForwardInfo.reason,
1265 callForwardInfo.number,
1266 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001267 break;
1268 }
1269 }
1270 // Didn't find a call forward info for voice call.
1271 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001272 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1273 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001274 }
Hall Liu27d24262020-09-18 19:04:59 -07001275 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001276 } else {
1277 if (ar.result == null) {
1278 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1279 }
1280 if (ar.exception != null) {
1281 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1282 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001283 int errorCode = TelephonyManager
1284 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001285 if (ar.exception instanceof CommandException) {
1286 CommandException.Error error =
1287 ((CommandException) (ar.exception)).getCommandError();
1288 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001289 errorCode = TelephonyManager
1290 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001291 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001292 errorCode = TelephonyManager
1293 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001294 }
1295 }
Hall Liu27d24262020-09-18 19:04:59 -07001296 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001297 }
Shuo Qian4a594052020-01-23 11:59:30 -08001298 break;
Hall Liu27d24262020-09-18 19:04:59 -07001299 }
Shuo Qian4a594052020-01-23 11:59:30 -08001300
Hall Liu27d24262020-09-18 19:04:59 -07001301 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001302 request = (MainThreadRequest) msg.obj;
1303 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001304 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001305 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001306 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1307 request.argument).first;
1308 request.phone.setCallForwardingOption(
1309 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001310 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001311 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001312 callForwardingInfoToSet.getReason(),
1313 callForwardingInfoToSet.getNumber(),
1314 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1315 break;
Hall Liu27d24262020-09-18 19:04:59 -07001316 }
Shuo Qian4a594052020-01-23 11:59:30 -08001317
Hall Liu27d24262020-09-18 19:04:59 -07001318 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001319 ar = (AsyncResult) msg.obj;
1320 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001321 Consumer<Integer> callback =
1322 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1323 request.argument).second;
1324 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001325 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001326 int errorCode = TelephonyManager.CallForwardingInfoCallback
1327 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001328 if (ar.exception instanceof CommandException) {
1329 CommandException.Error error =
1330 ((CommandException) (ar.exception)).getCommandError();
1331 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001332 errorCode = TelephonyManager.CallForwardingInfoCallback
1333 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001334 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001335 errorCode = TelephonyManager.CallForwardingInfoCallback
1336 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001337 }
1338 }
1339 callback.accept(errorCode);
1340 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001341 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001342 }
Shuo Qian4a594052020-01-23 11:59:30 -08001343 break;
Hall Liu27d24262020-09-18 19:04:59 -07001344 }
Shuo Qian4a594052020-01-23 11:59:30 -08001345
Hall Liu27d24262020-09-18 19:04:59 -07001346 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001347 request = (MainThreadRequest) msg.obj;
1348 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1349 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1350 break;
Hall Liu27d24262020-09-18 19:04:59 -07001351 }
Shuo Qian4a594052020-01-23 11:59:30 -08001352
Hall Liu27d24262020-09-18 19:04:59 -07001353 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001354 ar = (AsyncResult) msg.obj;
1355 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001356 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001357 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001358 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001359 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001360 // Service Class is a bit mask per 3gpp 27.007.
1361 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001362 if (callForwardResults.length > 1
1363 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001364 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001365 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001366 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1367 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001368 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001369 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001370 }
1371 } else {
1372 if (ar.result == null) {
1373 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1374 }
1375 if (ar.exception != null) {
1376 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1377 }
1378 if (ar.exception instanceof CommandException) {
1379 CommandException.Error error =
1380 ((CommandException) (ar.exception)).getCommandError();
1381 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001382 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001383 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001384 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1385 callWaitingStatus =
1386 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001387 }
1388 }
1389 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001390 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001391 break;
Hall Liu27d24262020-09-18 19:04:59 -07001392 }
Shuo Qian4a594052020-01-23 11:59:30 -08001393
Hall Liu27d24262020-09-18 19:04:59 -07001394 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001395 request = (MainThreadRequest) msg.obj;
1396 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001397 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1398 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001399 break;
Hall Liu27d24262020-09-18 19:04:59 -07001400 }
Shuo Qian4a594052020-01-23 11:59:30 -08001401
Hall Liu27d24262020-09-18 19:04:59 -07001402 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001403 ar = (AsyncResult) msg.obj;
1404 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001405 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1406 Consumer<Integer> callback =
1407 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1408 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001409 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001410 if (ar.exception instanceof CommandException) {
1411 CommandException.Error error =
1412 ((CommandException) (ar.exception)).getCommandError();
1413 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1414 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001415 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1416 callback.accept(
1417 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001418 } else {
1419 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1420 }
1421 } else {
1422 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1423 }
1424 } else {
1425 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1426 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001427 }
Shuo Qian4a594052020-01-23 11:59:30 -08001428 break;
Hall Liu27d24262020-09-18 19:04:59 -07001429 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001430 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1431 ar = (AsyncResult) msg.obj;
1432 request = (MainThreadRequest) ar.userObj;
1433 CellNetworkScanResult cellScanResult;
1434 if (ar.exception == null && ar.result != null) {
1435 cellScanResult = new CellNetworkScanResult(
1436 CellNetworkScanResult.STATUS_SUCCESS,
1437 (List<OperatorInfo>) ar.result);
1438 } else {
1439 if (ar.result == null) {
1440 loge("getCellNetworkScanResults: Empty response");
1441 }
1442 if (ar.exception != null) {
1443 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1444 }
1445 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1446 if (ar.exception instanceof CommandException) {
1447 CommandException.Error error =
1448 ((CommandException) (ar.exception)).getCommandError();
1449 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1450 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1451 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1452 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1453 }
1454 }
1455 cellScanResult = new CellNetworkScanResult(errorCode, null);
1456 }
1457 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001458 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001459 break;
1460
1461 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1462 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001463 ManualNetworkSelectionArgument selArg =
1464 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001465 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1466 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001467 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1468 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001469 break;
1470
1471 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001472 ar = (AsyncResult) msg.obj;
1473 request = (MainThreadRequest) ar.userObj;
1474 if (ar.exception == null) {
1475 request.result = true;
1476 } else {
1477 request.result = false;
1478 loge("setNetworkSelectionModeManual " + ar.exception);
1479 }
1480 notifyRequester(request);
1481 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001482 break;
1483
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001484 case CMD_GET_MODEM_ACTIVITY_INFO:
1485 request = (MainThreadRequest) msg.obj;
1486 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001487 if (defaultPhone != null) {
1488 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001489 } else {
1490 ResultReceiver result = (ResultReceiver) request.argument;
1491 Bundle bundle = new Bundle();
1492 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001493 new ModemActivityInfo(0, 0, 0,
1494 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001495 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001496 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001497 break;
1498
Hall Liud0f208c2020-10-14 16:54:44 -07001499 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001500 ar = (AsyncResult) msg.obj;
1501 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001502 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001503 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001504 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001505 if (mLastModemActivityInfo == null) {
1506 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1507 mLastModemActivitySpecificInfo[0] =
1508 new ActivityStatsTechSpecificInfo(
1509 0,
1510 0,
1511 new int[ModemActivityInfo.getNumTxPowerLevels()],
1512 0);
1513 mLastModemActivityInfo =
1514 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1515 }
1516
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001517 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001518 // Update the last modem activity info and the result of the request.
1519 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1520 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001521 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001522 } else {
1523 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001524 }
Kai Shi917fdc62022-11-28 14:01:02 -08001525 // This is needed to decouple ret from mLastModemActivityInfo
1526 // We don't want to return mLastModemActivityInfo which is updated
1527 // inside mergeModemActivityInfo()
1528 ret = new ModemActivityInfo(
1529 mLastModemActivityInfo.getTimestampMillis(),
1530 mLastModemActivityInfo.getSleepTimeMillis(),
1531 mLastModemActivityInfo.getIdleTimeMillis(),
1532 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001533
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001534 } else {
1535 if (ar.result == null) {
1536 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001537 error = TelephonyManager.ModemActivityInfoException
1538 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001539 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001540 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001541 error = TelephonyManager.ModemActivityInfoException
1542 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001543 } else {
1544 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001545 error = TelephonyManager.ModemActivityInfoException
1546 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001547 }
1548 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001549 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001550 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001551 bundle.putParcelable(
1552 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001553 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001554 } else {
1555 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1556 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001557 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001558 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001559 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001560 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001561
Meng Wang1a7c35a2016-05-05 20:56:15 -07001562 case CMD_SET_ALLOWED_CARRIERS:
1563 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001564 CarrierRestrictionRules argument =
1565 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001566 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001567 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001568 break;
1569
1570 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1571 ar = (AsyncResult) msg.obj;
1572 request = (MainThreadRequest) ar.userObj;
1573 if (ar.exception == null && ar.result != null) {
1574 request.result = ar.result;
1575 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001576 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1577 if (ar.exception instanceof CommandException) {
1578 loge("setAllowedCarriers: CommandException: " + ar.exception);
1579 CommandException.Error error =
1580 ((CommandException) (ar.exception)).getCommandError();
1581 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1582 request.result =
1583 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1584 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001585 } else {
1586 loge("setAllowedCarriers: Unknown exception");
1587 }
1588 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001589 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001590 break;
1591
1592 case CMD_GET_ALLOWED_CARRIERS:
1593 request = (MainThreadRequest) msg.obj;
1594 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001595 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001596 break;
1597
1598 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1599 ar = (AsyncResult) msg.obj;
1600 request = (MainThreadRequest) ar.userObj;
1601 if (ar.exception == null && ar.result != null) {
1602 request.result = ar.result;
1603 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001604 request.result = new IllegalStateException(
1605 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001606 if (ar.result == null) {
1607 loge("getAllowedCarriers: Empty response");
1608 } else if (ar.exception instanceof CommandException) {
1609 loge("getAllowedCarriers: CommandException: " +
1610 ar.exception);
1611 } else {
1612 loge("getAllowedCarriers: Unknown exception");
1613 }
1614 }
arunvoddud7401012022-12-15 16:08:12 +00001615 if (request.argument != null) {
1616 // This is for the implementation of carrierRestrictionStatus.
1617 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1618 Consumer<Integer> callback = callbackInfo.getConsumer();
1619 int callerCarrierId = callbackInfo.getCarrierId();
1620 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1621 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1622 CarrierRestrictionRules carrierRestrictionRules =
1623 (CarrierRestrictionRules) ar.result;
1624 int carrierId = -1;
1625 try {
1626 CarrierIdentifier carrierIdentifier =
1627 carrierRestrictionRules.getAllowedCarriers().get(0);
1628 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1629 carrierIdentifier);
1630 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1631 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1632 }
1633 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
1634 if (carrierId != -1 && callerCarrierId == carrierId && lockStatus
1635 == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) {
1636 lockStatus =
1637 TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
1638 }
1639 } else {
1640 Rlog.e(LOG_TAG,
1641 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1642 }
1643 callback.accept(lockStatus);
1644 } else {
1645 // This is for the implementation of getAllowedCarriers.
1646 notifyRequester(request);
1647 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001648 break;
1649
Nathan Haroldb3014052017-01-25 15:57:32 -08001650 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1651 ar = (AsyncResult) msg.obj;
1652 request = (MainThreadRequest) ar.userObj;
1653 if (ar.exception == null && ar.result != null) {
1654 request.result = ar.result;
1655 } else {
1656 request.result = new IllegalArgumentException(
1657 "Failed to retrieve Forbidden Plmns");
1658 if (ar.result == null) {
1659 loge("getForbiddenPlmns: Empty response");
1660 } else {
1661 loge("getForbiddenPlmns: Unknown exception");
1662 }
1663 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001664 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001665 break;
1666
1667 case CMD_GET_FORBIDDEN_PLMNS:
1668 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001669 uiccPort = getUiccPortFromRequest(request);
1670 if (uiccPort == null) {
1671 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001672 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001673 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001674 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001675 break;
1676 }
1677 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001678 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001679 if (uiccApp == null) {
1680 loge("getForbiddenPlmns() no app with specified type -- "
1681 + appType);
1682 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001683 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001684 break;
1685 } else {
1686 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1687 + " specified type -- " + appType);
1688 }
1689 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1690 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1691 onCompleted);
1692 break;
1693
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001694 case CMD_SWITCH_SLOTS:
1695 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001696 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001697 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001698 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001699 break;
1700
1701 case EVENT_SWITCH_SLOTS_DONE:
1702 ar = (AsyncResult) msg.obj;
1703 request = (MainThreadRequest) ar.userObj;
1704 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001705 notifyRequester(request);
1706 break;
1707 case CMD_GET_NETWORK_SELECTION_MODE:
1708 request = (MainThreadRequest) msg.obj;
1709 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1710 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1711 break;
1712
1713 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1714 ar = (AsyncResult) msg.obj;
1715 request = (MainThreadRequest) ar.userObj;
1716 if (ar.exception != null) {
1717 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1718 } else {
1719 int mode = ((int[]) ar.result)[0];
1720 if (mode == 0) {
1721 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1722 } else {
1723 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1724 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001725 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001726 notifyRequester(request);
1727 break;
1728 case CMD_GET_CDMA_ROAMING_MODE:
1729 request = (MainThreadRequest) msg.obj;
1730 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1731 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1732 break;
1733 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1734 ar = (AsyncResult) msg.obj;
1735 request = (MainThreadRequest) ar.userObj;
1736 if (ar.exception != null) {
1737 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1738 } else {
1739 request.result = ((int[]) ar.result)[0];
1740 }
1741 notifyRequester(request);
1742 break;
1743 case CMD_SET_CDMA_ROAMING_MODE:
1744 request = (MainThreadRequest) msg.obj;
1745 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1746 int mode = (int) request.argument;
1747 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1748 break;
1749 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1750 ar = (AsyncResult) msg.obj;
1751 request = (MainThreadRequest) ar.userObj;
1752 request.result = ar.exception == null;
1753 notifyRequester(request);
1754 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001755 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1756 request = (MainThreadRequest) msg.obj;
1757 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1758 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1759 break;
1760 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1761 ar = (AsyncResult) msg.obj;
1762 request = (MainThreadRequest) ar.userObj;
1763 if (ar.exception != null) {
1764 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1765 } else {
1766 request.result = ((int[]) ar.result)[0];
1767 }
1768 notifyRequester(request);
1769 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001770 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1771 request = (MainThreadRequest) msg.obj;
1772 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1773 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001774 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1775 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001776 break;
1777 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1778 ar = (AsyncResult) msg.obj;
1779 request = (MainThreadRequest) ar.userObj;
1780 request.result = ar.exception == null;
1781 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001782 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001783 case CMD_GET_ALL_CELL_INFO:
1784 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001785 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001786 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001787 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001788 case EVENT_GET_ALL_CELL_INFO_DONE:
1789 ar = (AsyncResult) msg.obj;
1790 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001791 // If a timeout occurs, the response will be null
1792 request.result = (ar.exception == null && ar.result != null)
1793 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001794 synchronized (request) {
1795 request.notifyAll();
1796 }
1797 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001798 case CMD_REQUEST_CELL_INFO_UPDATE:
1799 request = (MainThreadRequest) msg.obj;
1800 request.phone.requestCellInfoUpdate(request.workSource,
1801 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1802 break;
1803 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1804 ar = (AsyncResult) msg.obj;
1805 request = (MainThreadRequest) ar.userObj;
1806 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1807 try {
1808 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001809 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001810 cb.onError(
1811 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1812 ar.exception.getClass().getName(),
1813 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001814 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001815 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001816 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001817 } else {
1818 // use the result as returned
1819 cb.onCellInfo((List<CellInfo>) ar.result);
1820 }
1821 } catch (RemoteException re) {
1822 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1823 }
1824 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001825 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001826 request = (MainThreadRequest) msg.obj;
1827 WorkSource ws = (WorkSource) request.argument;
1828 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001829 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001830 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001831 }
1832 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001833 ar = (AsyncResult) msg.obj;
1834 request = (MainThreadRequest) ar.userObj;
1835 if (ar.exception == null) {
1836 request.result = ar.result;
1837 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001838 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001839 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001840 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001841 }
1842
1843 synchronized (request) {
1844 request.notifyAll();
1845 }
1846 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001847 }
chen xu6dac5ab2018-10-26 17:39:23 -07001848 case CMD_MODEM_REBOOT:
1849 request = (MainThreadRequest) msg.obj;
1850 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001851 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001852 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001853 case EVENT_CMD_MODEM_REBOOT_DONE:
1854 handleNullReturnEvent(msg, "rebootModem");
1855 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001856 case CMD_REQUEST_ENABLE_MODEM:
1857 request = (MainThreadRequest) msg.obj;
1858 boolean enable = (boolean) request.argument;
1859 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001860 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001861 PhoneConfigurationManager.getInstance()
1862 .enablePhone(request.phone, enable, onCompleted);
1863 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001864 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001865 ar = (AsyncResult) msg.obj;
1866 request = (MainThreadRequest) ar.userObj;
1867 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001868 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001869 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001870 if ((boolean) request.result) {
1871 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1872 updateModemStateMetrics();
1873 } else {
1874 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1875 + ar.exception);
1876 }
1877 notifyRequester(request);
1878 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001879 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001880 case CMD_GET_MODEM_STATUS:
1881 request = (MainThreadRequest) msg.obj;
1882 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1883 PhoneConfigurationManager.getInstance()
1884 .getPhoneStatusFromModem(request.phone, onCompleted);
1885 break;
1886 case EVENT_GET_MODEM_STATUS_DONE:
1887 ar = (AsyncResult) msg.obj;
1888 request = (MainThreadRequest) ar.userObj;
1889 int id = request.phone.getPhoneId();
1890 if (ar.exception == null && ar.result != null) {
1891 request.result = ar.result;
1892 //update the cache as modem status has changed
1893 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1894 (boolean) request.result);
1895 } else {
1896 // Return true if modem status cannot be retrieved. For most cases,
1897 // modem status is on. And for older version modems, GET_MODEM_STATUS
1898 // and disable modem are not supported. Modem is always on.
1899 // TODO: this should be fixed in R to support a third
1900 // status UNKNOWN b/131631629
1901 request.result = true;
1902 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1903 + ar.exception);
1904 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001905 notifyRequester(request);
1906 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001907 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1908 request = (MainThreadRequest) msg.obj;
1909 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1910 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1911 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1912 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1913 break;
1914 }
1915 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1916 ar = (AsyncResult) msg.obj;
1917 request = (MainThreadRequest) ar.userObj;
1918 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1919 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1920 args.second.accept(ar.exception == null);
1921 notifyRequester(request);
1922 break;
1923 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001924 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1925 request = (MainThreadRequest) msg.obj;
1926 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1927 Phone phone = getPhoneFromRequest(request);
1928 if (phone != null) {
1929 phone.getSystemSelectionChannels(onCompleted);
1930 } else {
1931 loge("getSystemSelectionChannels: No phone object");
1932 request.result = new ArrayList<RadioAccessSpecifier>();
1933 notifyRequester(request);
1934 }
1935 break;
1936 }
1937 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1938 ar = (AsyncResult) msg.obj;
1939 request = (MainThreadRequest) ar.userObj;
1940 if (ar.exception == null && ar.result != null) {
1941 request.result = ar.result;
1942 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001943 request.result = new IllegalStateException(
1944 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001945 if (ar.result == null) {
1946 loge("getSystemSelectionChannels: Empty response");
1947 } else {
1948 loge("getSystemSelectionChannels: Unknown exception");
1949 }
1950 }
1951 notifyRequester(request);
1952 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001953 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1954 ar = (AsyncResult) msg.obj;
1955 request = (MainThreadRequest) ar.userObj;
1956 if (ar.exception == null && ar.result != null) {
1957 request.result = ar.result;
1958 } else {
1959 request.result = -1;
1960 loge("Failed to set Forbidden Plmns");
1961 if (ar.result == null) {
1962 loge("setForbidenPlmns: Empty response");
1963 } else if (ar.exception != null) {
1964 loge("setForbiddenPlmns: Exception: " + ar.exception);
1965 request.result = -1;
1966 } else {
1967 loge("setForbiddenPlmns: Unknown exception");
1968 }
1969 }
1970 notifyRequester(request);
1971 break;
1972 case CMD_SET_FORBIDDEN_PLMNS:
1973 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001974 uiccPort = getUiccPortFromRequest(request);
1975 if (uiccPort == null) {
1976 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001977 request.result = -1;
1978 notifyRequester(request);
1979 break;
1980 }
1981 Pair<Integer, List<String>> setFplmnsArgs =
1982 (Pair<Integer, List<String>>) request.argument;
1983 appType = setFplmnsArgs.first;
1984 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001985 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001986 if (uiccApp == null) {
1987 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1988 request.result = -1;
1989 loge("Failed to get UICC App");
1990 notifyRequester(request);
1991 } else {
1992 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1993 ((SIMRecords) uiccApp.getIccRecords())
1994 .setForbiddenPlmns(onCompleted, fplmns);
1995 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001996 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001997 case CMD_ERASE_MODEM_CONFIG:
1998 request = (MainThreadRequest) msg.obj;
1999 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
2000 defaultPhone.eraseModemConfig(onCompleted);
2001 break;
2002 case EVENT_ERASE_MODEM_CONFIG_DONE:
2003 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07002004 break;
zoey chene02881a2019-12-30 16:11:23 +08002005
Kai Shif70f46f2021-03-03 13:59:46 -08002006 case CMD_ERASE_DATA_SHARED_PREFERENCES:
2007 request = (MainThreadRequest) msg.obj;
2008 request.result = defaultPhone.eraseDataInSharedPreferences();
2009 notifyRequester(request);
2010 break;
2011
zoey chene02881a2019-12-30 16:11:23 +08002012 case CMD_CHANGE_ICC_LOCK_PASSWORD:
2013 request = (MainThreadRequest) msg.obj;
2014 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
2015 Pair<String, String> changed = (Pair<String, String>) request.argument;
2016 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
2017 changed.first, changed.second, onCompleted);
2018 break;
2019 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
2020 ar = (AsyncResult) msg.obj;
2021 request = (MainThreadRequest) ar.userObj;
2022 if (ar.exception == null) {
2023 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002024 // If the operation is successful, update the PIN storage
2025 Pair<String, String> passwords = (Pair<String, String>) request.argument;
2026 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00002027 UiccController.getInstance().getPinStorage()
2028 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08002029 } else {
2030 request.result = msg.arg1;
2031 }
2032 notifyRequester(request);
2033 break;
2034
Michele Berionne5e411512020-11-13 02:36:59 +00002035 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002036 request = (MainThreadRequest) msg.obj;
2037 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2038 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2039 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2040 enabled.first, enabled.second, onCompleted);
2041 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002042 }
zoey chene02881a2019-12-30 16:11:23 +08002043 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2044 ar = (AsyncResult) msg.obj;
2045 request = (MainThreadRequest) ar.userObj;
2046 if (ar.exception == null) {
2047 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002048 // If the operation is successful, update the PIN storage
2049 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2050 int phoneId = getPhoneFromRequest(request).getPhoneId();
2051 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002052 UiccController.getInstance().getPinStorage()
2053 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002054 } else {
2055 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2056 }
zoey chene02881a2019-12-30 16:11:23 +08002057 } else {
2058 request.result = msg.arg1;
2059 }
Michele Berionne5e411512020-11-13 02:36:59 +00002060
2061
zoey chene02881a2019-12-30 16:11:23 +08002062 notifyRequester(request);
2063 break;
2064
Peter Wangdafb9ac2020-01-15 14:13:38 -08002065 case MSG_NOTIFY_USER_ACTIVITY:
2066 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002067 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002068 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2069 getDefaultPhone().getContext().sendBroadcastAsUser(
2070 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2071 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002072
2073 case CMD_SET_DATA_THROTTLING: {
2074 request = (MainThreadRequest) msg.obj;
2075 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2076 DataThrottlingRequest dataThrottlingRequest =
2077 (DataThrottlingRequest) request.argument;
2078 Phone phone = getPhoneFromRequest(request);
2079 if (phone != null) {
2080 phone.setDataThrottling(onCompleted,
2081 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2082 dataThrottlingRequest.getCompletionDurationMillis());
2083 } else {
2084 loge("setDataThrottling: No phone object");
2085 request.result =
2086 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2087 notifyRequester(request);
2088 }
2089
2090 break;
2091 }
2092 case EVENT_SET_DATA_THROTTLING_DONE:
2093 ar = (AsyncResult) msg.obj;
2094 request = (MainThreadRequest) ar.userObj;
2095
2096 if (ar.exception == null) {
2097 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2098 } else if (ar.exception instanceof CommandException) {
2099 loge("setDataThrottling: CommandException: " + ar.exception);
2100 CommandException.Error error =
2101 ((CommandException) (ar.exception)).getCommandError();
2102
2103 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2104 request.result = TelephonyManager
2105 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2106 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2107 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002108 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2109 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002110 } else {
2111 request.result =
2112 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2113 }
2114 } else {
2115 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2116 }
2117 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2118 notifyRequester(request);
2119 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002120
2121 case CMD_SET_SIM_POWER: {
2122 request = (MainThreadRequest) msg.obj;
2123 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2124 request = (MainThreadRequest) msg.obj;
2125 int stateToSet =
2126 ((Pair<Integer, IIntegerConsumer>)
2127 request.argument).first;
2128 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2129 break;
2130 }
2131 case EVENT_SET_SIM_POWER_DONE: {
2132 ar = (AsyncResult) msg.obj;
2133 request = (MainThreadRequest) ar.userObj;
2134 IIntegerConsumer callback =
2135 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2136 if (ar.exception != null) {
2137 loge("setSimPower exception: " + ar.exception);
2138 int errorCode = TelephonyManager.CallForwardingInfoCallback
2139 .RESULT_ERROR_UNKNOWN;
2140 if (ar.exception instanceof CommandException) {
2141 CommandException.Error error =
2142 ((CommandException) (ar.exception)).getCommandError();
2143 if (error == CommandException.Error.SIM_ERR) {
2144 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2145 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2146 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2147 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2148 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2149 } else {
2150 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2151 }
2152 }
2153 try {
2154 callback.accept(errorCode);
2155 } catch (RemoteException e) {
2156 // Ignore if the remote process is no longer available to call back.
2157 Log.w(LOG_TAG, "setSimPower: callback not available.");
2158 }
2159 } else {
2160 try {
2161 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2162 } catch (RemoteException e) {
2163 // Ignore if the remote process is no longer available to call back.
2164 Log.w(LOG_TAG, "setSimPower: callback not available.");
2165 }
2166 }
2167 break;
2168 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002169 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2170 request = (MainThreadRequest) msg.obj;
2171
2172 final Phone phone = getPhoneFromRequest(request);
2173 if (phone == null || phone.getServiceStateTracker() == null) {
2174 request.result = new IllegalStateException("Phone or SST is null");
2175 notifyRequester(request);
2176 break;
2177 }
2178
2179 Pair<Integer, SignalStrengthUpdateRequest> pair =
2180 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2181 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2182 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002183 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002184 request.subId, pair.first /*callingUid*/,
2185 pair.second /*request*/, onCompleted);
2186 break;
2187 }
2188 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2189 ar = (AsyncResult) msg.obj;
2190 request = (MainThreadRequest) ar.userObj;
2191 // request.result will be the exception of ar if present, true otherwise.
2192 // Be cautious not to leave result null which will wait() forever
2193 request.result = ar.exception != null ? ar.exception : true;
2194 notifyRequester(request);
2195 break;
2196 }
2197 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2198 request = (MainThreadRequest) msg.obj;
2199
2200 Phone phone = getPhoneFromRequest(request);
2201 if (phone == null || phone.getServiceStateTracker() == null) {
2202 request.result = new IllegalStateException("Phone or SST is null");
2203 notifyRequester(request);
2204 break;
2205 }
2206
2207 Pair<Integer, SignalStrengthUpdateRequest> pair =
2208 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2209 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2210 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002211 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002212 request.subId, pair.first /*callingUid*/,
2213 pair.second /*request*/, onCompleted);
2214 break;
2215 }
2216 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2217 ar = (AsyncResult) msg.obj;
2218 request = (MainThreadRequest) ar.userObj;
2219 request.result = ar.exception != null ? ar.exception : true;
2220 notifyRequester(request);
2221 break;
2222 }
Jordan Liu109698e2020-11-24 14:50:34 -08002223
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002224 case CMD_GET_SLICING_CONFIG: {
2225 request = (MainThreadRequest) msg.obj;
2226 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2227 request.phone.getSlicingConfig(onCompleted);
2228 break;
2229 }
2230 case EVENT_GET_SLICING_CONFIG_DONE: {
2231 ar = (AsyncResult) msg.obj;
2232 request = (MainThreadRequest) ar.userObj;
2233 ResultReceiver result = (ResultReceiver) request.argument;
2234
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002235 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002236 Bundle bundle = new Bundle();
2237 int resultCode = 0;
2238 if (ar.exception != null) {
2239 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2240 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002241 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002242 } else if (ar.result == null) {
2243 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002244 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002245 } else {
2246 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002247 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2248 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002249 }
2250
2251 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002252 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002253 }
2254 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2255 result.send(resultCode, bundle);
2256 notifyRequester(request);
2257 break;
2258 }
2259
Sarah Chin71b3a852022-09-28 15:54:19 -07002260 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002261 request = (MainThreadRequest) msg.obj;
2262 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002263 PurchasePremiumCapabilityArgument arg =
2264 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin46355ba2022-11-01 23:51:16 -07002265 SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability(
Sarah Chinb8218c22023-01-04 13:35:29 -08002266 arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002267 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002268 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002269
Sarah Chin71b3a852022-09-28 15:54:19 -07002270 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002271 ar = (AsyncResult) msg.obj;
2272 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002273 PurchasePremiumCapabilityArgument arg =
2274 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002275 try {
2276 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002277 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002278 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002279 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002280 + ", result= "
2281 + TelephonyManager.convertPurchaseResultToString(result));
2282 } catch (RemoteException e) {
2283 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002284 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002285 + " failed: " + e;
2286 if (DBG) log(logStr);
2287 AnomalyReporter.reportAnomaly(
2288 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2289 }
2290 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002291 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002292
Michele Berionne5e411512020-11-13 02:36:59 +00002293 case CMD_PREPARE_UNATTENDED_REBOOT:
2294 request = (MainThreadRequest) msg.obj;
2295 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002296 UiccController.getInstance().getPinStorage()
2297 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002298 notifyRequester(request);
2299 break;
2300
Sarah Chineccfbd12023-01-20 19:00:35 -08002301 case CMD_START_SATELLITE_POSITION_UPDATES: {
2302 request = (MainThreadRequest) msg.obj;
2303 onCompleted =
2304 obtainMessage(EVENT_START_SATELLITE_POSITION_UPDATES_DONE, request);
2305 Phone phone = getPhoneFromRequest(request);
2306 if (phone != null) {
2307 phone.startSatellitePositionUpdates(onCompleted);
2308 } else {
2309 loge("startSatellitePositionUpdates: No phone object");
2310 request.result = SatelliteManager.SATELLITE_SERVICE_REQUEST_FAILED;
2311 notifyRequester(request);
2312 }
2313 break;
2314 }
2315
2316 case EVENT_START_SATELLITE_POSITION_UPDATES_DONE: {
2317 ar = (AsyncResult) msg.obj;
2318 request = (MainThreadRequest) ar.userObj;
2319 if (ar.exception == null) {
2320 request.result = SatelliteManager.SATELLITE_SERVICE_SUCCESS;
2321 } else {
2322 request.result = SatelliteManager.SATELLITE_SERVICE_ERROR;
2323 if (ar.exception instanceof CommandException) {
2324 CommandException.Error error =
2325 ((CommandException) (ar.exception)).getCommandError();
2326 request.result = RILUtils.convertToSatelliteError(error);
2327 loge("startSatellitePositionUpdates CommandException: " + ar.exception);
2328 } else {
2329 loge("startSatellitePositionUpdates unknown exception:" + ar.exception);
2330 }
2331 }
2332 notifyRequester(request);
2333 break;
2334 }
2335
2336 case CMD_STOP_SATELLITE_POSITION_UPDATES: {
2337 request = (MainThreadRequest) msg.obj;
2338 onCompleted =
2339 obtainMessage(EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE, request);
2340 Phone phone = getPhoneFromRequest(request);
2341 if (phone != null) {
2342 phone.stopSatellitePositionUpdates(onCompleted);
2343 } else {
2344 loge("stopSatellitePositionUpdates: No phone object");
2345 request.result = SatelliteManager.SATELLITE_SERVICE_REQUEST_FAILED;
2346 notifyRequester(request);
2347 }
2348 break;
2349 }
2350
2351 case EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE: {
2352 ar = (AsyncResult) msg.obj;
2353 request = (MainThreadRequest) ar.userObj;
2354 if (ar.exception == null) {
2355 request.result = SatelliteManager.SATELLITE_SERVICE_SUCCESS;
2356 } else {
2357 request.result = SatelliteManager.SATELLITE_SERVICE_ERROR;
2358 if (ar.exception instanceof CommandException) {
2359 CommandException.Error error =
2360 ((CommandException) (ar.exception)).getCommandError();
2361 request.result = RILUtils.convertToSatelliteError(error);
2362 loge("stopSatellitePositionUpdates CommandException: " + ar.exception);
2363 } else {
2364 loge("stopSatellitePositionUpdates unknown exception:" + ar.exception);
2365 }
2366 }
2367 notifyRequester(request);
2368 break;
2369 }
2370
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002371 default:
2372 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2373 break;
2374 }
2375 }
Jake Hambye994d462014-02-03 13:10:13 -08002376
Pengquan Menga1bb6272018-09-06 09:59:22 -07002377 private void notifyRequester(MainThreadRequest request) {
2378 synchronized (request) {
2379 request.notifyAll();
2380 }
2381 }
2382
Jake Hambye994d462014-02-03 13:10:13 -08002383 private void handleNullReturnEvent(Message msg, String command) {
2384 AsyncResult ar = (AsyncResult) msg.obj;
2385 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2386 if (ar.exception == null) {
2387 request.result = true;
2388 } else {
2389 request.result = false;
2390 if (ar.exception instanceof CommandException) {
2391 loge(command + ": CommandException: " + ar.exception);
2392 } else {
2393 loge(command + ": Unknown exception");
2394 }
2395 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002396 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002397 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002398 }
2399
2400 /**
2401 * Posts the specified command to be executed on the main thread,
2402 * waits for the request to complete, and returns the result.
2403 * @see #sendRequestAsync
2404 */
2405 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002406 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2407 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002408 }
2409
2410 /**
2411 * Posts the specified command to be executed on the main thread,
2412 * waits for the request to complete, and returns the result.
2413 * @see #sendRequestAsync
2414 */
2415 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2416 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002417 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002418 }
2419
2420 /**
2421 * Posts the specified command to be executed on the main thread,
2422 * waits for the request to complete, and returns the result.
2423 * @see #sendRequestAsync
2424 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002425 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002426 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2427 }
2428
2429 /**
2430 * Posts the specified command to be executed on the main thread,
2431 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2432 * if not timeout or null otherwise.
2433 * @see #sendRequestAsync
2434 */
2435 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2436 long timeoutInMs) {
2437 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002438 }
2439
2440 /**
2441 * Posts the specified command to be executed on the main thread,
2442 * waits for the request to complete, and returns the result.
2443 * @see #sendRequestAsync
2444 */
Nathan Harold92bed182018-10-12 18:16:49 -07002445 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002446 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002447 }
2448
2449 /**
2450 * Posts the specified command to be executed on the main thread,
2451 * waits for the request to complete, and returns the result.
2452 * @see #sendRequestAsync
2453 */
2454 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002455 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2456 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002457 }
2458
2459 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002460 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2461 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2462 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002463 * @see #sendRequestAsync
2464 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002465 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2466 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002467 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2468 throw new RuntimeException("This method will deadlock if called from the main thread.");
2469 }
2470
Nathan Harold92bed182018-10-12 18:16:49 -07002471 MainThreadRequest request = null;
2472 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2473 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2474 } else if (phone != null) {
2475 request = new MainThreadRequest(argument, phone, workSource);
2476 } else {
2477 request = new MainThreadRequest(argument, subId, workSource);
2478 }
2479
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002480 Message msg = mMainThreadHandler.obtainMessage(command, request);
2481 msg.sendToTarget();
2482
Rambo Wang0f050d82021-02-12 11:43:36 -08002483
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002484 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002485 if (timeoutInMs >= 0) {
2486 // Wait for at least timeoutInMs before returning null request result
2487 long now = SystemClock.elapsedRealtime();
2488 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002489 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002490 try {
2491 request.wait(deadline - now);
2492 } catch (InterruptedException e) {
2493 // Do nothing, go back and check if request is completed or timeout
2494 } finally {
2495 now = SystemClock.elapsedRealtime();
2496 }
2497 }
2498 } else {
2499 // Wait for the request to complete
2500 while (request.result == null) {
2501 try {
2502 request.wait();
2503 } catch (InterruptedException e) {
2504 // Do nothing, go back and wait until the request is complete
2505 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002506 }
2507 }
2508 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002509 if (request.result == null) {
2510 Log.wtf(LOG_TAG,
2511 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2512 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002513 return request.result;
2514 }
2515
2516 /**
2517 * Asynchronous ("fire and forget") version of sendRequest():
2518 * Posts the specified command to be executed on the main thread, and
2519 * returns immediately.
2520 * @see #sendRequest
2521 */
2522 private void sendRequestAsync(int command) {
2523 mMainThreadHandler.sendEmptyMessage(command);
2524 }
2525
2526 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002527 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002528 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002529 */
2530 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002531 sendRequestAsync(command, argument, null, null);
2532 }
2533
2534 /**
2535 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2536 * @see {@link #sendRequest(int,Object)}
2537 */
2538 private void sendRequestAsync(
2539 int command, Object argument, Phone phone, WorkSource workSource) {
2540 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002541 Message msg = mMainThreadHandler.obtainMessage(command, request);
2542 msg.sendToTarget();
2543 }
2544
2545 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002546 * Initialize the singleton PhoneInterfaceManager instance.
2547 * This is only done once, at startup, from PhoneApp.onCreate().
2548 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002549 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002550 synchronized (PhoneInterfaceManager.class) {
2551 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002552 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002553 } else {
2554 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2555 }
2556 return sInstance;
2557 }
2558 }
2559
2560 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002561 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002562 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002563 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002564 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002565 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002566 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002567 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002568 mMainThreadHandler = new MainThreadHandler();
Jack Yue37dd262022-12-16 11:53:37 -08002569 if (!PhoneFactory.isSubscriptionManagerServiceEnabled()) {
2570 mSubscriptionController = SubscriptionController.getInstance();
2571 } else {
2572 mSubscriptionController = null;
2573 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002574 mTelephonySharedPreferences =
2575 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002576 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002577 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002578 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002579 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002580 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002581 publish();
arunvoddud7401012022-12-15 16:08:12 +00002582 CarrierAllowListInfo.loadInstance(mApp);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002583 }
2584
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002585 @VisibleForTesting
2586 public SharedPreferences getSharedPreferences() {
2587 return mTelephonySharedPreferences;
2588 }
2589
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002590 /**
2591 * Get the default phone for this device.
2592 */
2593 @VisibleForTesting
2594 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002595 Phone thePhone = getPhone(getDefaultSubscription());
2596 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2597 }
2598
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002599 private void publish() {
2600 if (DBG) log("publish: " + this);
2601
Peter Wangc035ce42020-01-08 21:00:22 -08002602 TelephonyFrameworkInitializer
2603 .getTelephonyServiceManager()
2604 .getTelephonyServiceRegisterer()
2605 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002606 }
2607
Stuart Scott584921c2015-01-15 17:10:34 -08002608 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002609 if (request.phone != null) {
2610 return request.phone;
2611 } else {
2612 return getPhoneFromSubId(request.subId);
2613 }
2614 }
2615
2616 private Phone getPhoneFromSubId(int subId) {
2617 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2618 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002619 }
2620
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002621 /**
2622 * Get phone object associated with a subscription.
2623 * Return default phone if phone object associated with subscription is null
2624 * @param subId - subscriptionId
2625 * @return phone object associated with a subscription or default phone if null.
2626 */
2627 private Phone getPhoneFromSubIdOrDefault(int subId) {
2628 Phone phone = getPhoneFromSubId(subId);
2629 if (phone == null) {
2630 phone = getDefaultPhone();
2631 }
2632 return phone;
2633 }
2634
Rambo Wange53e07d2022-05-10 13:01:13 -07002635 @Nullable
2636 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002637 Phone phone = getPhoneFromRequest(request);
2638 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002639 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002640 }
2641
Wink Saville36469e72014-06-11 15:17:00 -07002642 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002643 private Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002644 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002645 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002646
Kai Shif70f46f2021-03-03 13:59:46 -08002647 private void sendEraseModemConfig(@NonNull Phone phone) {
2648 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2649 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2650 }
2651
2652 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2653 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2654 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002655 }
2656
Peter Wang44b186e2020-01-13 23:33:09 -08002657 private boolean isImsAvailableOnDevice() {
2658 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2659 if (pm == null) {
2660 // For some reason package manger is not available.. This will fail internally anyway,
2661 // so do not throw error and allow.
2662 return true;
2663 }
2664 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2665 }
2666
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002667 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002668 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002669 }
2670
Wink Savilleb564aae2014-10-23 10:18:09 -07002671 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002672 if (DBG) log("dial: " + number);
2673 // No permission check needed here: This is just a wrapper around the
2674 // ACTION_DIAL intent, which is available to any app since it puts up
2675 // the UI before it does anything.
2676
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002677 final long identity = Binder.clearCallingIdentity();
2678 try {
2679 String url = createTelUrl(number);
2680 if (url == null) {
2681 return;
2682 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002683
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002684 // PENDING: should we just silently fail if phone is offhook or ringing?
2685 PhoneConstants.State state = mCM.getState(subId);
2686 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2687 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2688 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2689 mApp.startActivity(intent);
2690 }
2691 } finally {
2692 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002693 }
2694 }
2695
2696 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002697 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002698 }
2699
Wink Savilleb564aae2014-10-23 10:18:09 -07002700 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002701 if (DBG) log("call: " + number);
2702
2703 // This is just a wrapper around the ACTION_CALL intent, but we still
2704 // need to do a permission check since we're calling startActivity()
2705 // from the context of the phone app.
2706 enforceCallPermission();
2707
Jordan Liu1617b712019-07-10 15:06:26 -07002708 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002709 != AppOpsManager.MODE_ALLOWED) {
2710 return;
2711 }
2712
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002713 final long identity = Binder.clearCallingIdentity();
2714 try {
2715 String url = createTelUrl(number);
2716 if (url == null) {
2717 return;
2718 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002719
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002720 boolean isValid = false;
2721 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2722 if (slist != null) {
2723 for (SubscriptionInfo subInfoRecord : slist) {
2724 if (subInfoRecord.getSubscriptionId() == subId) {
2725 isValid = true;
2726 break;
2727 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002728 }
Wink Saville08874612014-08-31 19:19:58 -07002729 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002730 if (!isValid) {
2731 return;
2732 }
Wink Saville08874612014-08-31 19:19:58 -07002733
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002734 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2735 intent.putExtra(SUBSCRIPTION_KEY, subId);
2736 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2737 mApp.startActivity(intent);
2738 } finally {
2739 Binder.restoreCallingIdentity(identity);
2740 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002741 }
2742
Wink Savilleb564aae2014-10-23 10:18:09 -07002743 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002744 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002745 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2746 }
2747
Wink Savilleb564aae2014-10-23 10:18:09 -07002748 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002749 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002750 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2751 }
2752
Wink Savilleb564aae2014-10-23 10:18:09 -07002753 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002754 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002755
2756 final long identity = Binder.clearCallingIdentity();
2757 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002758 Phone phone = getPhone(subId);
2759 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002760 checkSimPin.start();
2761 return checkSimPin.unlockSim(null, pin);
2762 } finally {
2763 Binder.restoreCallingIdentity(identity);
2764 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002765 }
2766
Wink Savilleb564aae2014-10-23 10:18:09 -07002767 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002768 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002769
2770 final long identity = Binder.clearCallingIdentity();
2771 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002772 Phone phone = getPhone(subId);
2773 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002774 checkSimPuk.start();
2775 return checkSimPuk.unlockSim(puk, pin);
2776 } finally {
2777 Binder.restoreCallingIdentity(identity);
2778 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002779 }
2780
2781 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002782 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002783 * a synchronous one.
2784 */
2785 private static class UnlockSim extends Thread {
2786
2787 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002788 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002789
2790 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002791 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2792 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002793
2794 // For replies from SimCard interface
2795 private Handler mHandler;
2796
2797 // For async handler to identify request type
2798 private static final int SUPPLY_PIN_COMPLETE = 100;
2799
Michele Berionne5e411512020-11-13 02:36:59 +00002800 UnlockSim(int phoneId, IccCard simCard) {
2801 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002802 mSimCard = simCard;
2803 }
2804
2805 @Override
2806 public void run() {
2807 Looper.prepare();
2808 synchronized (UnlockSim.this) {
2809 mHandler = new Handler() {
2810 @Override
2811 public void handleMessage(Message msg) {
2812 AsyncResult ar = (AsyncResult) msg.obj;
2813 switch (msg.what) {
2814 case SUPPLY_PIN_COMPLETE:
2815 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2816 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002817 mRetryCount = msg.arg1;
2818 if (ar.exception != null) {
2819 if (ar.exception instanceof CommandException &&
2820 ((CommandException)(ar.exception)).getCommandError()
2821 == CommandException.Error.PASSWORD_INCORRECT) {
2822 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002823 } //When UiccCardApp dispose,handle message and return exception
2824 else if (ar.exception instanceof CommandException &&
2825 ((CommandException) (ar.exception)).getCommandError()
2826 == CommandException.Error.ABORTED) {
2827 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002828 } else {
2829 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2830 }
2831 } else {
2832 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2833 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002834 mDone = true;
2835 UnlockSim.this.notifyAll();
2836 }
2837 break;
2838 }
2839 }
2840 };
2841 UnlockSim.this.notifyAll();
2842 }
2843 Looper.loop();
2844 }
2845
2846 /*
2847 * Use PIN or PUK to unlock SIM card
2848 *
2849 * If PUK is null, unlock SIM card with PIN
2850 *
2851 * If PUK is not null, unlock SIM card with PUK and set PIN code
2852 */
Wink Saville9de0f752013-10-22 19:04:03 -07002853 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002854
2855 while (mHandler == null) {
2856 try {
2857 wait();
2858 } catch (InterruptedException e) {
2859 Thread.currentThread().interrupt();
2860 }
2861 }
2862 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2863
2864 if (puk == null) {
2865 mSimCard.supplyPin(pin, callback);
2866 } else {
2867 mSimCard.supplyPuk(puk, pin, callback);
2868 }
2869
2870 while (!mDone) {
2871 try {
2872 Log.d(LOG_TAG, "wait for done");
2873 wait();
2874 } catch (InterruptedException e) {
2875 // Restore the interrupted status
2876 Thread.currentThread().interrupt();
2877 }
2878 }
2879 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002880 int[] resultArray = new int[2];
2881 resultArray[0] = mResult;
2882 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002883
2884 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002885 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002886 }
2887
Wink Saville9de0f752013-10-22 19:04:03 -07002888 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002889 }
2890 }
2891
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002892 /**
2893 * This method has been removed due to privacy and stability concerns.
2894 */
2895 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002896 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002897 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2898 return;
Wink Saville36469e72014-06-11 15:17:00 -07002899 }
2900
Nathan Harold1f889d82020-06-04 17:05:26 -07002901 @Override
2902 public void updateServiceLocationWithPackageName(String callingPackage) {
2903 mApp.getSystemService(AppOpsManager.class)
2904 .checkPackage(Binder.getCallingUid(), callingPackage);
2905
Nathan Haroldf096d982020-11-18 17:18:06 -08002906 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002907 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2908 // Callers targeting S have no business invoking this method.
2909 return;
2910 }
2911
2912 LocationAccessPolicy.LocationPermissionResult locationResult =
2913 LocationAccessPolicy.checkLocationPermission(mApp,
2914 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2915 .setCallingPackage(callingPackage)
2916 .setCallingFeatureId(null)
2917 .setCallingPid(Binder.getCallingPid())
2918 .setCallingUid(Binder.getCallingUid())
2919 .setMethod("updateServiceLocation")
2920 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2921 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2922 .build());
2923 // Apps that lack location permission have no business calling this method;
2924 // however, because no permission was declared in the public API, denials must
2925 // all be "soft".
2926 switch (locationResult) {
2927 case DENIED_HARD: /* fall through */
2928 case DENIED_SOFT:
2929 return;
2930 }
2931
2932 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002933 final long identity = Binder.clearCallingIdentity();
2934 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002935 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002936 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002937 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002938 }
2939 } finally {
2940 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002941 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002942 }
2943
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002944 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002945 @Override
2946 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002947 return isRadioOnWithFeature(callingPackage, null);
2948 }
2949
2950
2951 @Override
2952 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2953 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2954 callingFeatureId);
2955 }
2956
2957 @Deprecated
2958 @Override
2959 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2960 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002961 }
2962
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002963 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002964 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2965 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002966 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002967 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002968 return false;
2969 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002970
2971 final long identity = Binder.clearCallingIdentity();
2972 try {
2973 return isRadioOnForSubscriber(subId);
2974 } finally {
2975 Binder.restoreCallingIdentity(identity);
2976 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002977 }
2978
2979 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002980 final long identity = Binder.clearCallingIdentity();
2981 try {
2982 final Phone phone = getPhone(subId);
2983 if (phone != null) {
2984 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2985 } else {
2986 return false;
2987 }
2988 } finally {
2989 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002990 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002991 }
2992
2993 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002994 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002995 }
Wink Saville36469e72014-06-11 15:17:00 -07002996
Wink Savilleb564aae2014-10-23 10:18:09 -07002997 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002998 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002999
3000 final long identity = Binder.clearCallingIdentity();
3001 try {
3002 final Phone phone = getPhone(subId);
3003 if (phone != null) {
3004 phone.setRadioPower(!isRadioOnForSubscriber(subId));
3005 }
3006 } finally {
3007 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003008 }
Wink Saville36469e72014-06-11 15:17:00 -07003009 }
3010
3011 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003012 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07003013 }
3014
Wink Savilleb564aae2014-10-23 10:18:09 -07003015 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07003016 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003017
3018 final long identity = Binder.clearCallingIdentity();
3019 try {
3020 final Phone phone = getPhone(subId);
3021 if (phone == null) {
3022 return false;
3023 }
3024 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
3025 toggleRadioOnOffForSubscriber(subId);
3026 }
3027 return true;
3028 } finally {
3029 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003030 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003031 }
Wink Saville36469e72014-06-11 15:17:00 -07003032
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003033 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08003034 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003035 /*
3036 * If any of the Radios are available, it will need to be
3037 * shutdown. So return true if any Radio is available.
3038 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003039 final long identity = Binder.clearCallingIdentity();
3040 try {
3041 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3042 Phone phone = PhoneFactory.getPhone(i);
3043 if (phone != null && phone.isRadioAvailable()) return true;
3044 }
3045 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
3046 return false;
3047 } finally {
3048 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003049 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003050 }
3051
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003052 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003053 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003054 enforceModifyPermission();
3055
3056 final long identity = Binder.clearCallingIdentity();
3057 try {
3058 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3059 logv("Shutting down Phone " + i);
3060 shutdownRadioUsingPhoneId(i);
3061 }
3062 } finally {
3063 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003064 }
3065 }
3066
3067 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003068 Phone phone = PhoneFactory.getPhone(phoneId);
3069 if (phone != null && phone.isRadioAvailable()) {
3070 phone.shutdownRadio();
3071 }
3072 }
3073
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003074 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07003075 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003076
Ling Ma83dc5ea2023-01-12 15:06:04 -08003077 if (!turnOn) {
3078 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3079 }
3080
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003081 final long identity = Binder.clearCallingIdentity();
3082 try {
3083 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3084 if (defaultPhone != null) {
3085 defaultPhone.setRadioPower(turnOn);
3086 return true;
3087 } else {
3088 loge("There's no default phone.");
3089 return false;
3090 }
3091 } finally {
3092 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003093 }
Wink Saville36469e72014-06-11 15:17:00 -07003094 }
3095
Wink Savilleb564aae2014-10-23 10:18:09 -07003096 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003097 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003098
Ling Ma83dc5ea2023-01-12 15:06:04 -08003099 if (!turnOn) {
3100 log("setRadioPowerForSubscriber off: subId=" + subId
3101 + ",callingPackage=" + getCurrentPackageName());
3102 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003103 final long identity = Binder.clearCallingIdentity();
3104 try {
3105 final Phone phone = getPhone(subId);
3106 if (phone != null) {
3107 phone.setRadioPower(turnOn);
3108 return true;
3109 } else {
3110 return false;
3111 }
3112 } finally {
3113 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003114 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003115 }
3116
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003117 /**
3118 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3119 * no reason to power it off. When any of the voters want to power it off, it will be turned
3120 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3121 * powering it off, and these radio off votes will be cleared.
3122 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3123 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3124 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3125 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3126 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3127 * check its vote.
3128 *
3129 * @param subId The subscription ID.
3130 * @param reason The reason for powering off radio.
3131 * @return true on success and false on failure.
3132 */
3133 public boolean requestRadioPowerOffForReason(int subId,
3134 @TelephonyManager.RadioPowerReason int reason) {
3135 enforceModifyPermission();
3136
Ling Ma83dc5ea2023-01-12 15:06:04 -08003137 log("requestRadioPowerOffForReason: subId=" + subId
3138 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003139 final long identity = Binder.clearCallingIdentity();
3140 try {
3141 final Phone phone = getPhone(subId);
3142 if (phone != null) {
3143 phone.setRadioPowerForReason(false, reason);
3144 return true;
3145 } else {
3146 return false;
3147 }
3148 } finally {
3149 Binder.restoreCallingIdentity(identity);
3150 }
3151 }
3152
3153 /**
3154 * Remove the vote on powering off the radio for a reason, as requested by
3155 * {@link requestRadioPowerOffForReason}.
3156 *
3157 * @param subId The subscription ID.
3158 * @param reason The reason for powering off radio.
3159 * @return true on success and false on failure.
3160 */
3161 public boolean clearRadioPowerOffForReason(int subId,
3162 @TelephonyManager.RadioPowerReason int reason) {
3163 enforceModifyPermission();
3164
3165 final long identity = Binder.clearCallingIdentity();
3166 try {
3167 final Phone phone = getPhone(subId);
3168 if (phone != null) {
3169 phone.setRadioPowerForReason(true, reason);
3170 return true;
3171 } else {
3172 return false;
3173 }
3174 } finally {
3175 Binder.restoreCallingIdentity(identity);
3176 }
3177 }
3178
3179 /**
3180 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3181 *
3182 * @param subId The subscription ID.
3183 * @param callingPackage The package making the call.
3184 * @param callingFeatureId The feature in the package.
3185 * @return List of reasons for powering off radio.
3186 */
3187 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3188 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3189
3190 final long identity = Binder.clearCallingIdentity();
3191 List result = new ArrayList();
3192 try {
3193 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3194 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3195 return result;
3196 }
3197
3198 final Phone phone = getPhone(subId);
3199 if (phone != null) {
3200 result.addAll(phone.getRadioPowerOffReasons());
3201 }
3202 } finally {
3203 Binder.restoreCallingIdentity(identity);
3204 }
3205 return result;
3206 }
3207
Wink Saville36469e72014-06-11 15:17:00 -07003208 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003209 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003210 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003211 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003212
3213 final long identity = Binder.clearCallingIdentity();
3214 try {
Jack Yu285100e2022-12-02 22:48:35 -08003215 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003216 final Phone phone = getPhone(subId);
3217 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003218 phone.getDataSettingsManager().setDataEnabled(
3219 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003220 return true;
3221 } else {
3222 return false;
3223 }
3224 } finally {
3225 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003226 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003227 }
3228
Wink Saville36469e72014-06-11 15:17:00 -07003229 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003230 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003231 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003232 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003233
3234 final long identity = Binder.clearCallingIdentity();
3235 try {
Jack Yu285100e2022-12-02 22:48:35 -08003236 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003237 final Phone phone = getPhone(subId);
3238 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003239 phone.getDataSettingsManager().setDataEnabled(
3240 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003241 return true;
3242 } else {
3243 return false;
3244 }
3245 } finally {
3246 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003247 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003248 }
3249
Sanket Padawe356d7632015-06-22 14:03:32 -07003250 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003251 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003252 final long identity = Binder.clearCallingIdentity();
3253 try {
3254 final Phone phone = getPhone(subId);
3255 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003256 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003257 } else {
3258 return false;
3259 }
3260 } finally {
3261 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003262 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003263 }
3264
3265 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003266 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003267 }
3268
pkanwarae03a6b2016-11-06 20:37:09 -08003269 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003270 enforceCallPermission();
3271
3272 final long identity = Binder.clearCallingIdentity();
3273 try {
3274 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3275 return;
3276 }
3277 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3278 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3279 } finally {
3280 Binder.restoreCallingIdentity(identity);
3281 }
pkanwar32d516d2016-10-14 19:37:38 -07003282 };
3283
Wink Savilleb564aae2014-10-23 10:18:09 -07003284 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003285 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003286
3287 final long identity = Binder.clearCallingIdentity();
3288 try {
3289 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3290 return false;
3291 }
3292 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3293 } finally {
3294 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003295 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003296 }
3297
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003298 /**
3299 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3300 * tag on getCallState Binder call.
3301 */
3302 @Deprecated
3303 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003304 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003305 if (CompatChanges.isChangeEnabled(
3306 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3307 Binder.getCallingUid())) {
3308 // Do not allow this API to be called on API version 31+, it should only be
3309 // called on old apps using this Binder call directly.
3310 throw new SecurityException("This method can only be used for applications "
3311 + "targeting API version 30 or less.");
3312 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003313 final long identity = Binder.clearCallingIdentity();
3314 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003315 Phone phone = getPhone(getDefaultSubscription());
3316 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3317 PhoneConstantConversions.convertCallState(phone.getState());
3318 } finally {
3319 Binder.restoreCallingIdentity(identity);
3320 }
3321 }
3322
3323 @Override
3324 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3325 if (CompatChanges.isChangeEnabled(
3326 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3327 Binder.getCallingUid())) {
3328 // Check READ_PHONE_STATE for API version 31+
3329 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3330 featureId, "getCallStateForSubscription")) {
3331 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3332 + "targeting API level 31+.");
3333 }
3334 }
3335 final long identity = Binder.clearCallingIdentity();
3336 try {
3337 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003338 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3339 PhoneConstantConversions.convertCallState(phone.getState());
3340 } finally {
3341 Binder.restoreCallingIdentity(identity);
3342 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003343 }
3344
Sanket Padawe356d7632015-06-22 14:03:32 -07003345 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003346 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003347 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003348 }
3349
3350 @Override
3351 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003352 final long identity = Binder.clearCallingIdentity();
3353 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003354 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003355 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003356 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003357 } else {
3358 return PhoneConstantConversions.convertDataState(
3359 PhoneConstants.DataState.DISCONNECTED);
3360 }
3361 } finally {
3362 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003363 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003364 }
3365
Sanket Padawe356d7632015-06-22 14:03:32 -07003366 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003367 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003368 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003369 }
3370
3371 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003372 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003373 final long identity = Binder.clearCallingIdentity();
3374 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003375 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003376 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003377 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003378 } else {
3379 return TelephonyManager.DATA_ACTIVITY_NONE;
3380 }
3381 } finally {
3382 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003383 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003384 }
3385
3386 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003387 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003388 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003389 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003390
3391 LocationAccessPolicy.LocationPermissionResult locationResult =
3392 LocationAccessPolicy.checkLocationPermission(mApp,
3393 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3394 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003395 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003396 .setCallingPid(Binder.getCallingPid())
3397 .setCallingUid(Binder.getCallingUid())
3398 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003399 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003400 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3401 .build());
3402 switch (locationResult) {
3403 case DENIED_HARD:
3404 throw new SecurityException("Not allowed to access cell location");
3405 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003406 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3407 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003408 }
3409
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003410 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003411 final long identity = Binder.clearCallingIdentity();
3412 try {
3413 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003414 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003415 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003416 } finally {
3417 Binder.restoreCallingIdentity(identity);
3418 }
Svetoslav64fad262015-04-14 14:35:21 -07003419 }
3420
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003421 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003422 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003423 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3424 // registered cell info, so return a NULL country instead.
3425 final long identity = Binder.clearCallingIdentity();
3426 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003427 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3428 // Get default phone in this case.
3429 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3430 }
Jack Yu285100e2022-12-02 22:48:35 -08003431 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003432 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003433 if (phone == null) return "";
3434 ServiceStateTracker sst = phone.getServiceStateTracker();
3435 if (sst == null) return "";
3436 LocaleTracker lt = sst.getLocaleTracker();
3437 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003438 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003439 } finally {
3440 Binder.restoreCallingIdentity(identity);
3441 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003442 }
3443
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003444 /**
3445 * This method was removed due to potential issues caused by performing partial
3446 * updates of service state, and lack of a credible use case.
3447 *
3448 * This has the ability to break the telephony implementation by disabling notification of
3449 * changes in device connectivity. DO NOT USE THIS!
3450 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003451 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003452 public void enableLocationUpdates() {
3453 mApp.enforceCallingOrSelfPermission(
3454 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003455 }
3456
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003457 /**
3458 * This method was removed due to potential issues caused by performing partial
3459 * updates of service state, and lack of a credible use case.
3460 *
3461 * This has the ability to break the telephony implementation by disabling notification of
3462 * changes in device connectivity. DO NOT USE THIS!
3463 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003464 @Override
3465 public void disableLocationUpdates() {
3466 mApp.enforceCallingOrSelfPermission(
3467 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003468 }
3469
3470 @Override
3471 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003472 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3473 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003474 try {
3475 mApp.getSystemService(AppOpsManager.class)
3476 .checkPackage(Binder.getCallingUid(), callingPackage);
3477 } catch (SecurityException e) {
3478 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3479 throw e;
3480 }
3481
Nathan Haroldf096d982020-11-18 17:18:06 -08003482 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003483 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3484 throw new SecurityException(
3485 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3486 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003487
Jordan Liu1617b712019-07-10 15:06:26 -07003488 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003489 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3490 return null;
3491 }
Svetoslav64fad262015-04-14 14:35:21 -07003492
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003493 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003494
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003495 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003496 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003497
Nathan Haroldf180aac2018-06-01 18:43:55 -07003498 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3499 for (CellInfo ci : info) {
3500 if (ci instanceof CellInfoGsm) {
3501 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3502 } else if (ci instanceof CellInfoWcdma) {
3503 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3504 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003505 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003506 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003507 }
3508
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003509 private List<CellInfo> getCachedCellInfo() {
3510 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3511 for (Phone phone : PhoneFactory.getPhones()) {
3512 List<CellInfo> info = phone.getAllCellInfo();
3513 if (info != null) cellInfos.addAll(info);
3514 }
3515 return cellInfos;
3516 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003517
3518 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003519 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003520 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003521 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003522
3523 LocationAccessPolicy.LocationPermissionResult locationResult =
3524 LocationAccessPolicy.checkLocationPermission(mApp,
3525 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3526 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003527 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003528 .setCallingPid(Binder.getCallingPid())
3529 .setCallingUid(Binder.getCallingUid())
3530 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003531 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003532 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3533 .build());
3534 switch (locationResult) {
3535 case DENIED_HARD:
3536 throw new SecurityException("Not allowed to access cell info");
3537 case DENIED_SOFT:
3538 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003539 }
3540
Nathan Haroldf096d982020-11-18 17:18:06 -08003541 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003542 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3543 return getCachedCellInfo();
3544 }
3545
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003546 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003547 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003548 final long identity = Binder.clearCallingIdentity();
3549 try {
3550 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3551 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003552 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003553 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003554 if (info != null) cellInfos.addAll(info);
3555 }
3556 return cellInfos;
3557 } finally {
3558 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003559 }
3560 }
3561
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003562 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003563 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3564 String callingFeatureId) {
3565 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3566 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003567 }
3568
3569 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003570 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3571 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003572 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003573 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003574 }
3575
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003576 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3577 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003578 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003579 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003580
3581 LocationAccessPolicy.LocationPermissionResult locationResult =
3582 LocationAccessPolicy.checkLocationPermission(mApp,
3583 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3584 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003585 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003586 .setCallingPid(Binder.getCallingPid())
3587 .setCallingUid(Binder.getCallingUid())
3588 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003589 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3590 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003591 .build());
3592 switch (locationResult) {
3593 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003594 if (TelephonyPermissions
3595 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003596 // Safetynet logging for b/154934934
3597 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3598 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003599 throw new SecurityException("Not allowed to access cell info");
3600 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003601 if (TelephonyPermissions
3602 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003603 // Safetynet logging for b/154934934
3604 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3605 }
Nathan Harold5320c422019-05-09 10:26:08 -07003606 try {
3607 cb.onCellInfo(new ArrayList<CellInfo>());
3608 } catch (RemoteException re) {
3609 // Drop without consequences
3610 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003611 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003612 }
3613
Nathan Harolda939a962019-05-09 10:13:47 -07003614
3615 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003616 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3617
3618 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3619 }
3620
3621 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003622 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003623 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003624 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003625
3626 final long identity = Binder.clearCallingIdentity();
3627 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003628 Phone phone = getPhone(subId);
3629 if (phone == null) {
3630 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3631 } else {
3632 phone.setCellInfoListRate(rateInMillis, workSource);
3633 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003634 } finally {
3635 Binder.restoreCallingIdentity(identity);
3636 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003637 }
3638
Shishir Agrawala9f32182016-04-12 12:00:16 -07003639 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003640 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003641 Phone phone = PhoneFactory.getPhone(slotIndex);
3642 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003643 return null;
3644 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003645 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003646 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003647 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003648 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003649 return null;
3650 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003651
3652 final long identity = Binder.clearCallingIdentity();
3653 try {
3654 return phone.getImei();
3655 } finally {
3656 Binder.restoreCallingIdentity(identity);
3657 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003658 }
3659
3660 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003661 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3662 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3663 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3664 callingFeatureId, "getPrimaryImei")) {
3665 throw new SecurityException("Caller does not have permission");
3666 }
3667 final long identity = Binder.clearCallingIdentity();
3668 try {
3669 for (Phone phone : PhoneFactory.getPhones()) {
3670 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3671 return phone.getImei();
3672 }
3673 }
3674 throw new UnsupportedOperationException("Operation not supported");
3675 } finally {
3676 Binder.restoreCallingIdentity(identity);
3677 }
3678 }
3679
3680 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003681 public String getTypeAllocationCodeForSlot(int slotIndex) {
3682 Phone phone = PhoneFactory.getPhone(slotIndex);
3683 String tac = null;
3684 if (phone != null) {
3685 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003686 try {
3687 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3688 } catch (IndexOutOfBoundsException e) {
3689 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3690 return null;
3691 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003692 }
3693 return tac;
3694 }
3695
3696 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003697 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003698 try {
3699 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3700 } catch (SecurityException se) {
3701 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3702 throw new SecurityException("Package " + callingPackage + " does not belong to "
3703 + Binder.getCallingUid());
3704 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003705 Phone phone = PhoneFactory.getPhone(slotIndex);
3706 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003707 return null;
3708 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003709
Jeff Davidson913390f2018-02-23 17:11:49 -08003710 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003711 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003712 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003713 return null;
3714 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003715
3716 final long identity = Binder.clearCallingIdentity();
3717 try {
3718 return phone.getMeid();
3719 } finally {
3720 Binder.restoreCallingIdentity(identity);
3721 }
Jack Yu2af8d712017-03-15 17:14:14 -07003722 }
3723
3724 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003725 public String getManufacturerCodeForSlot(int slotIndex) {
3726 Phone phone = PhoneFactory.getPhone(slotIndex);
3727 String manufacturerCode = null;
3728 if (phone != null) {
3729 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003730 try {
3731 manufacturerCode =
3732 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3733 } catch (IndexOutOfBoundsException e) {
3734 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3735 return null;
3736 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003737 }
3738 return manufacturerCode;
3739 }
3740
3741 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003742 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3743 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003744 Phone phone = PhoneFactory.getPhone(slotIndex);
3745 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003746 return null;
3747 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003748 int subId = phone.getSubId();
3749 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003750 mApp, subId, callingPackage, callingFeatureId,
3751 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003752 return null;
3753 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003754
3755 final long identity = Binder.clearCallingIdentity();
3756 try {
3757 return phone.getDeviceSvn();
3758 } finally {
3759 Binder.restoreCallingIdentity(identity);
3760 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003761 }
3762
fionaxu43304da2017-11-27 22:51:16 -08003763 @Override
3764 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003765 final long identity = Binder.clearCallingIdentity();
3766 try {
3767 final Phone phone = getPhone(subId);
3768 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3769 } finally {
3770 Binder.restoreCallingIdentity(identity);
3771 }
fionaxu43304da2017-11-27 22:51:16 -08003772 }
3773
3774 @Override
3775 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003776 final long identity = Binder.clearCallingIdentity();
3777 try {
3778 final Phone phone = getPhone(subId);
3779 return phone == null ? null : phone.getCarrierName();
3780 } finally {
3781 Binder.restoreCallingIdentity(identity);
3782 }
fionaxu43304da2017-11-27 22:51:16 -08003783 }
3784
calvinpanffe225e2018-11-01 19:43:06 +08003785 @Override
chen xu0026ca62019-03-06 15:28:50 -08003786 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003787 final long identity = Binder.clearCallingIdentity();
3788 try {
3789 final Phone phone = getPhone(subId);
3790 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003791 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003792 } finally {
3793 Binder.restoreCallingIdentity(identity);
3794 }
3795 }
3796
3797 @Override
chen xu0026ca62019-03-06 15:28:50 -08003798 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003799 final long identity = Binder.clearCallingIdentity();
3800 try {
3801 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003802 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003803 } finally {
3804 Binder.restoreCallingIdentity(identity);
3805 }
3806 }
3807
chen xu651eec72018-11-11 19:03:44 -08003808 @Override
chen xu864e11c2018-12-06 22:10:03 -08003809 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3810 if (!isSubscriptionMccMnc) {
3811 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3812 }
chen xu651eec72018-11-11 19:03:44 -08003813 final Phone phone = PhoneFactory.getPhone(slotIndex);
3814 if (phone == null) {
3815 return TelephonyManager.UNKNOWN_CARRIER_ID;
3816 }
3817 final long identity = Binder.clearCallingIdentity();
3818 try {
3819 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3820 } finally {
3821 Binder.restoreCallingIdentity(identity);
3822 }
3823 }
3824
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003825 //
3826 // Internal helper methods.
3827 //
3828
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003829 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003830 * Make sure the caller is the calling package itself
3831 *
3832 * @throws SecurityException if the caller is not the calling package
3833 */
3834 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3835 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003836 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3837 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003838 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003839 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003840 } catch (PackageManager.NameNotFoundException e) {
3841 // packageUid is -1
3842 }
3843 if (packageUid != callingUid) {
3844 throw new SecurityException(message + ": Package " + callingPackage
3845 + " does not belong to " + callingUid);
3846 }
3847 }
3848
3849 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003850 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3851 *
3852 * @throws SecurityException if the caller does not have the required permission
3853 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003854 @VisibleForTesting
3855 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003856 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3857 }
3858
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003859 /**
arunvoddud7401012022-12-15 16:08:12 +00003860 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003861 *
3862 * @throws SecurityException if the caller does not have the required permission
3863 */
3864 @VisibleForTesting
3865 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003866 enforceReadPermission(null);
3867 }
3868
3869 /**
3870 * Make sure the caller has the READ_PHONE_STATE permissions.
3871 *
3872 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3873 */
3874 @VisibleForTesting
3875 public void enforceReadPermission(String msg) {
3876 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003877 }
3878
Shuo Qian3b6ee772019-11-13 17:43:31 -08003879 private void enforceActiveEmergencySessionPermission() {
3880 mApp.enforceCallingOrSelfPermission(
3881 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3882 }
3883
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003884 /**
3885 * Make sure the caller has the CALL_PHONE permission.
3886 *
3887 * @throws SecurityException if the caller does not have the required permission
3888 */
3889 private void enforceCallPermission() {
3890 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3891 }
3892
paulhu5a773602019-08-23 19:17:33 +08003893 private void enforceSettingsPermission() {
3894 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003895 }
3896
Michele Berionne5e411512020-11-13 02:36:59 +00003897 private void enforceRebootPermission() {
3898 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3899 }
3900
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003901 private String createTelUrl(String number) {
3902 if (TextUtils.isEmpty(number)) {
3903 return null;
3904 }
3905
Jake Hambye994d462014-02-03 13:10:13 -08003906 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003907 }
3908
Ihab Awadf9e92732013-12-05 18:02:52 -08003909 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003910 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003911 }
3912
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003913 private static void logv(String msg) {
3914 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3915 }
3916
Ihab Awadf9e92732013-12-05 18:02:52 -08003917 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003918 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3919 }
3920
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003921 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003922 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003923 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003924 }
3925
Sanket Padawe356d7632015-06-22 14:03:32 -07003926 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003927 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003928 final long identity = Binder.clearCallingIdentity();
3929 try {
3930 final Phone phone = PhoneFactory.getPhone(slotIndex);
3931 if (phone == null) {
3932 return PhoneConstants.PHONE_TYPE_NONE;
3933 } else {
3934 return phone.getPhoneType();
3935 }
3936 } finally {
3937 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003938 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003939 }
3940
3941 /**
3942 * Returns the CDMA ERI icon index to display
3943 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003944 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003945 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3946 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3947 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003948 }
3949
Sanket Padawe356d7632015-06-22 14:03:32 -07003950 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003951 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3952 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003953 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003954 mApp, subId, callingPackage, callingFeatureId,
3955 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003956 return -1;
3957 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003958
3959 final long identity = Binder.clearCallingIdentity();
3960 try {
3961 final Phone phone = getPhone(subId);
3962 if (phone != null) {
3963 return phone.getCdmaEriIconIndex();
3964 } else {
3965 return -1;
3966 }
3967 } finally {
3968 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003969 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003970 }
3971
3972 /**
3973 * Returns the CDMA ERI icon mode,
3974 * 0 - ON
3975 * 1 - FLASHING
3976 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003977 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003978 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3979 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3980 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003981 }
3982
Sanket Padawe356d7632015-06-22 14:03:32 -07003983 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003984 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3985 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003986 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003987 mApp, subId, callingPackage, callingFeatureId,
3988 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003989 return -1;
3990 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003991
3992 final long identity = Binder.clearCallingIdentity();
3993 try {
3994 final Phone phone = getPhone(subId);
3995 if (phone != null) {
3996 return phone.getCdmaEriIconMode();
3997 } else {
3998 return -1;
3999 }
4000 } finally {
4001 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004002 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004003 }
4004
4005 /**
4006 * Returns the CDMA ERI text,
4007 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004008 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004009 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
4010 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4011 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004012 }
4013
Sanket Padawe356d7632015-06-22 14:03:32 -07004014 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004015 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4016 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004017 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004018 mApp, subId, callingPackage, callingFeatureId,
4019 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004020 return null;
4021 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004022
4023 final long identity = Binder.clearCallingIdentity();
4024 try {
4025 final Phone phone = getPhone(subId);
4026 if (phone != null) {
4027 return phone.getCdmaEriText();
4028 } else {
4029 return null;
4030 }
4031 } finally {
4032 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004033 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004034 }
4035
4036 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004037 * Returns the CDMA MDN.
4038 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004039 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004040 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004041 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4042 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004043
4044 final long identity = Binder.clearCallingIdentity();
4045 try {
4046 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004047 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004048 return phone.getLine1Number();
4049 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004050 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004051 return null;
4052 }
4053 } finally {
4054 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004055 }
4056 }
4057
4058 /**
4059 * Returns the CDMA MIN.
4060 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004061 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004062 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004063 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4064 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004065
4066 final long identity = Binder.clearCallingIdentity();
4067 try {
4068 final Phone phone = getPhone(subId);
4069 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4070 return phone.getCdmaMin();
4071 } else {
4072 return null;
4073 }
4074 } finally {
4075 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004076 }
4077 }
4078
Hall Liud892bec2018-11-30 14:51:45 -08004079 @Override
4080 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4081 INumberVerificationCallback callback, String callingPackage) {
4082 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4083 != PERMISSION_GRANTED) {
4084 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4085 }
4086 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4087
4088 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4089 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004090 throw new SecurityException("Calling package must be configured in the device config: "
4091 + "calling package: " + callingPackage
4092 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004093 }
4094
4095 if (range == null) {
4096 throw new NullPointerException("Range must be non-null");
4097 }
4098
4099 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004100 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004101
4102 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4103 }
4104
Junda Liuca05d5d2014-08-14 22:36:34 -07004105 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004106 * Returns true if CDMA provisioning needs to run.
4107 */
4108 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004109 final long identity = Binder.clearCallingIdentity();
4110 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004111 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004112 } finally {
4113 Binder.restoreCallingIdentity(identity);
4114 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004115 }
4116
4117 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004118 * Sets the voice mail number of a given subId.
4119 */
4120 @Override
4121 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004122 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4123 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004124
4125 final long identity = Binder.clearCallingIdentity();
4126 try {
4127 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4128 new Pair<String, String>(alphaTag, number), new Integer(subId));
4129 return success;
4130 } finally {
4131 Binder.restoreCallingIdentity(identity);
4132 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004133 }
4134
Ta-wei Yen87c49842016-05-13 21:19:52 -07004135 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004136 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4137 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004138 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4139 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004140 if (!TextUtils.equals(callingPackage, systemDialer)) {
4141 throw new SecurityException("caller must be system dialer");
4142 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004143
4144 final long identity = Binder.clearCallingIdentity();
4145 try {
4146 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4147 if (phoneAccountHandle == null) {
4148 return null;
4149 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004150 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004151 } finally {
4152 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004153 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004154 }
4155
4156 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004157 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4158 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004159 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004160 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004161 mApp, subId, callingPackage, callingFeatureId,
4162 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004163 return null;
4164 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004165
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004166 final long identity = Binder.clearCallingIdentity();
4167 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004168 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004169 } finally {
4170 Binder.restoreCallingIdentity(identity);
4171 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004172 }
4173
4174 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004175 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4176 VisualVoicemailSmsFilterSettings settings) {
4177 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004178
4179 final long identity = Binder.clearCallingIdentity();
4180 try {
4181 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004182 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004183 } finally {
4184 Binder.restoreCallingIdentity(identity);
4185 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004186 }
4187
4188 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004189 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4190 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004191
4192 final long identity = Binder.clearCallingIdentity();
4193 try {
4194 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004195 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004196 } finally {
4197 Binder.restoreCallingIdentity(identity);
4198 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004199 }
4200
4201 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004202 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4203 String callingPackage, int subId) {
4204 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004205
4206 final long identity = Binder.clearCallingIdentity();
4207 try {
4208 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004209 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004210 } finally {
4211 Binder.restoreCallingIdentity(identity);
4212 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004213 }
4214
4215 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004216 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004217 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004218
4219 final long identity = Binder.clearCallingIdentity();
4220 try {
4221 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004222 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004223 } finally {
4224 Binder.restoreCallingIdentity(identity);
4225 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004226 }
4227
4228 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004229 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4230 String callingAttributionTag, int subId, String number, int port, String text,
4231 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004232 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004233 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004234 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07004235 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004236 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4237 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004238 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004239
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004240 /**
fionaxu0152e512016-11-14 13:36:14 -08004241 * Sets the voice activation state of a given subId.
4242 */
4243 @Override
4244 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004245 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4246 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004247
4248 final long identity = Binder.clearCallingIdentity();
4249 try {
4250 final Phone phone = getPhone(subId);
4251 if (phone != null) {
4252 phone.setVoiceActivationState(activationState);
4253 } else {
4254 loge("setVoiceActivationState fails with invalid subId: " + subId);
4255 }
4256 } finally {
4257 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004258 }
4259 }
4260
4261 /**
4262 * Sets the data activation state of a given subId.
4263 */
4264 @Override
4265 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004266 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4267 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004268
4269 final long identity = Binder.clearCallingIdentity();
4270 try {
4271 final Phone phone = getPhone(subId);
4272 if (phone != null) {
4273 phone.setDataActivationState(activationState);
4274 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004275 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004276 }
4277 } finally {
4278 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004279 }
4280 }
4281
4282 /**
4283 * Returns the voice activation state of a given subId.
4284 */
4285 @Override
4286 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004287 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004288
fionaxu0152e512016-11-14 13:36:14 -08004289 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004290 final long identity = Binder.clearCallingIdentity();
4291 try {
4292 if (phone != null) {
4293 return phone.getVoiceActivationState();
4294 } else {
4295 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4296 }
4297 } finally {
4298 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004299 }
4300 }
4301
4302 /**
4303 * Returns the data activation state of a given subId.
4304 */
4305 @Override
4306 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004307 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004308
fionaxu0152e512016-11-14 13:36:14 -08004309 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004310 final long identity = Binder.clearCallingIdentity();
4311 try {
4312 if (phone != null) {
4313 return phone.getDataActivationState();
4314 } else {
4315 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4316 }
4317 } finally {
4318 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004319 }
4320 }
4321
4322 /**
Wink Saville36469e72014-06-11 15:17:00 -07004323 * Returns the unread count of voicemails for a subId
4324 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004325 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004326 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4327 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004328 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004329 mApp, subId, callingPackage, callingFeatureId,
4330 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004331 return 0;
4332 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004333 final long identity = Binder.clearCallingIdentity();
4334 try {
4335 final Phone phone = getPhone(subId);
4336 if (phone != null) {
4337 return phone.getVoiceMessageCount();
4338 } else {
4339 return 0;
4340 }
4341 } finally {
4342 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004343 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004344 }
4345
4346 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08004347 * returns true, if the device is in a state where both voice and data
4348 * are supported simultaneously. This can change based on location or network condition.
4349 */
4350 @Override
4351 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004352 final long identity = Binder.clearCallingIdentity();
4353 try {
4354 final Phone phone = getPhone(subId);
4355 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
4356 } finally {
4357 Binder.restoreCallingIdentity(identity);
4358 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004359 }
4360
4361 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004362 * Send the dialer code if called from the current default dialer or the caller has
4363 * carrier privilege.
4364 * @param inputCode The dialer code to send
4365 */
4366 @Override
4367 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004368 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004369 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004370 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4371 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004372 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004373 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004374 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004375 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004376
4377 final long identity = Binder.clearCallingIdentity();
4378 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004379 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004380 } finally {
4381 Binder.restoreCallingIdentity(identity);
4382 }
fionaxu235cc5e2017-03-06 22:25:57 -08004383 }
4384
Pengquan Menga1bb6272018-09-06 09:59:22 -07004385 @Override
4386 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004387 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07004388 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08004389 mApp, subId, "getNetworkSelectionMode");
4390 final long identity = Binder.clearCallingIdentity();
4391 try {
4392 if (!isActiveSubscription(subId)) {
4393 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4394 }
4395 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4396 } finally {
4397 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004398 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004399 }
4400
Brad Ebinger35c841c2018-10-01 10:40:55 -07004401 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004402 public boolean isInEmergencySmsMode() {
4403 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4404 final long identity = Binder.clearCallingIdentity();
4405 try {
4406 for (Phone phone : PhoneFactory.getPhones()) {
4407 if (phone.isInEmergencySmsMode()) {
4408 return true;
4409 }
4410 }
4411 } finally {
4412 Binder.restoreCallingIdentity(identity);
4413 }
4414 return false;
4415 }
4416
shilu366312e2019-12-17 09:28:10 -08004417 /**
4418 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4419 * @param subId The subscription to use to check the configuration.
4420 * @param c The callback that will be used to send the result.
4421 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004422 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004423 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4424 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004425 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004426 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004427
4428 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4429 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4430 "IMS not available on device.");
4431 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004432 final long token = Binder.clearCallingIdentity();
4433 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004434 int slotId = getSlotIndexOrException(subId);
4435 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004436
4437 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4438 if (controller != null) {
4439 ImsManager imsManager = controller.getImsManager(subId);
4440 if (imsManager != null) {
4441 imsManager.addRegistrationCallbackForSubscription(c, subId);
4442 } else {
4443 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4444 }
4445 } else {
4446 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4447 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004448 } catch (ImsException e) {
4449 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004450 } finally {
4451 Binder.restoreCallingIdentity(token);
4452 }
4453 }
4454
shilu366312e2019-12-17 09:28:10 -08004455 /**
4456 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4457 * @param subId The subscription to use to check the configuration.
4458 * @param c The callback that will be used to send the result.
4459 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004460 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004461 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004462 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004463 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004464 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4465 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4466 }
Meng Wangafbc5852019-09-19 17:37:13 -07004467 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004468
Meng Wangafbc5852019-09-19 17:37:13 -07004469 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004470 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4471 if (controller != null) {
4472 ImsManager imsManager = controller.getImsManager(subId);
4473 if (imsManager != null) {
4474 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4475 } else {
4476 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4477 + "is inactive, ignoring unregister.");
4478 // If the ImsManager is not valid, just return, since the callback
4479 // will already have been removed internally.
4480 }
4481 }
Meng Wangafbc5852019-09-19 17:37:13 -07004482 } finally {
4483 Binder.restoreCallingIdentity(token);
4484 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004485 }
4486
Brad Ebingera34a6c22019-10-22 17:36:18 -07004487 /**
4488 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4489 */
4490 @Override
4491 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4492 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4493 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4494 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4495 "IMS not available on device.");
4496 }
4497 final long token = Binder.clearCallingIdentity();
4498 try {
4499 Phone phone = getPhone(subId);
4500 if (phone == null) {
4501 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4502 + subId + "'");
4503 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4504 }
4505 phone.getImsRegistrationState(regState -> {
4506 try {
4507 consumer.accept((regState == null)
4508 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4509 } catch (RemoteException e) {
4510 // Ignore if the remote process is no longer available to call back.
4511 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4512 }
4513 });
4514 } finally {
4515 Binder.restoreCallingIdentity(token);
4516 }
4517 }
4518
4519 /**
4520 * Get the transport type for the IMS service registration state.
4521 */
4522 @Override
4523 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004524 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004525 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004526 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4527 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4528 "IMS not available on device.");
4529 }
4530 final long token = Binder.clearCallingIdentity();
4531 try {
4532 Phone phone = getPhone(subId);
4533 if (phone == null) {
4534 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4535 + subId + "'");
4536 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4537 }
4538 phone.getImsRegistrationTech(regTech -> {
4539 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4540 int regTechConverted = (regTech == null)
4541 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4542 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4543 regTechConverted);
4544 try {
4545 consumer.accept(regTechConverted);
4546 } catch (RemoteException e) {
4547 // Ignore if the remote process is no longer available to call back.
4548 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4549 }
4550 });
4551 } finally {
4552 Binder.restoreCallingIdentity(token);
4553 }
4554 }
4555
shilu366312e2019-12-17 09:28:10 -08004556 /**
4557 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4558 * @param subId The subscription to use to check the configuration.
4559 * @param c The callback that will be used to send the result.
4560 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004561 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004562 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4563 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004564 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004565 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004566 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4567 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4568 "IMS not available on device.");
4569 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004570 final long token = Binder.clearCallingIdentity();
4571 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004572 int slotId = getSlotIndexOrException(subId);
4573 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004574
4575 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4576 if (controller != null) {
4577 ImsManager imsManager = controller.getImsManager(subId);
4578 if (imsManager != null) {
4579 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4580 } else {
4581 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4582 }
4583 } else {
4584 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4585 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004586 } catch (ImsException e) {
4587 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004588 } finally {
4589 Binder.restoreCallingIdentity(token);
4590 }
4591 }
4592
shilu366312e2019-12-17 09:28:10 -08004593 /**
4594 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4595 * @param subId The subscription to use to check the configuration.
4596 * @param c The callback that will be used to send the result.
4597 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004598 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004599 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004600 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004601 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004602 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4603 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4604 }
Meng Wangafbc5852019-09-19 17:37:13 -07004605
4606 final long token = Binder.clearCallingIdentity();
4607 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004608 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4609 if (controller != null) {
4610 ImsManager imsManager = controller.getImsManager(subId);
4611 if (imsManager != null) {
4612 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4613 } else {
4614 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4615 + " is inactive, ignoring unregister.");
4616 // If the ImsManager is not valid, just return, since the callback
4617 // will already have been removed internally.
4618 }
4619 }
Meng Wangafbc5852019-09-19 17:37:13 -07004620 } finally {
4621 Binder.restoreCallingIdentity(token);
4622 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004623 }
4624
4625 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004626 public boolean isCapable(int subId, int capability, int regTech) {
4627 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004628 final long token = Binder.clearCallingIdentity();
4629 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004630 int slotId = getSlotIndexOrException(subId);
4631 verifyImsMmTelConfiguredOrThrow(slotId);
4632 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4633 } catch (com.android.ims.ImsException e) {
4634 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4635 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004636 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004637 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4638 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004639 } finally {
4640 Binder.restoreCallingIdentity(token);
4641 }
4642 }
4643
4644 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004645 public boolean isAvailable(int subId, int capability, int regTech) {
4646 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004647 final long token = Binder.clearCallingIdentity();
4648 try {
4649 Phone phone = getPhone(subId);
4650 if (phone == null) return false;
4651 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004652 } catch (com.android.ims.ImsException e) {
4653 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4654 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004655 } finally {
4656 Binder.restoreCallingIdentity(token);
4657 }
4658 }
4659
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004660 /**
4661 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4662 * subscription.
4663 * @param subId The subscription to use to check the configuration.
4664 * @param callback The callback that will be used to send the result.
4665 * @param capability The MmTelFeature capability that will be used to send the result.
4666 * @param transportType The transport type of the MmTelFeature capability.
4667 */
4668 @Override
4669 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4670 int transportType) {
4671 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004672 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4673 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4674 "IMS not available on device.");
4675 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004676 final long token = Binder.clearCallingIdentity();
4677 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004678 int slotId = getSlotIndex(subId);
4679 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4680 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4681 + subId + "'");
4682 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4683 }
4684 verifyImsMmTelConfiguredOrThrow(slotId);
4685 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4686 transportType, aBoolean -> {
4687 try {
4688 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4689 } catch (RemoteException e) {
4690 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4691 + "running. Ignore");
4692 }
4693 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004694 } catch (ImsException e) {
4695 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004696 } finally {
4697 Binder.restoreCallingIdentity(token);
4698 }
4699 }
4700
shilu366312e2019-12-17 09:28:10 -08004701 /**
4702 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4703 * @param subId The subscription to use to check the configuration.
4704 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004705 @Override
4706 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004707 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004708 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004709
Brad Ebinger35c841c2018-10-01 10:40:55 -07004710 final long token = Binder.clearCallingIdentity();
4711 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004712 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004713 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004714 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004715 } catch (ImsException e) {
4716 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004717 } finally {
4718 Binder.restoreCallingIdentity(token);
4719 }
4720 }
4721
4722 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004723 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004724 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004725 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004726 final long identity = Binder.clearCallingIdentity();
4727 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004728 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004729 // This setting doesn't require an active ImsService connection, so do not verify. The
4730 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004731 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004732 } catch (ImsException e) {
4733 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004734 } finally {
4735 Binder.restoreCallingIdentity(identity);
4736 }
4737 }
4738
shilu366312e2019-12-17 09:28:10 -08004739 /**
4740 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4741 * @param subId The subscription to use to check the configuration.
4742 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004743 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004744 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004745 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004746 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004747 final long identity = Binder.clearCallingIdentity();
4748 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004749 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004750 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004751 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004752 } catch (ImsException e) {
4753 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004754 } finally {
4755 Binder.restoreCallingIdentity(identity);
4756 }
4757 }
4758
4759 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004760 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004761 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004762 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004763 final long identity = Binder.clearCallingIdentity();
4764 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004765 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004766 // This setting doesn't require an active ImsService connection, so do not verify. The
4767 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004768 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004769 } catch (ImsException e) {
4770 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004771 } finally {
4772 Binder.restoreCallingIdentity(identity);
4773 }
4774 }
4775
shilu366312e2019-12-17 09:28:10 -08004776 /**
4777 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4778 * @param subId The subscription to use to check the configuration.
4779 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004780 @Override
4781 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004782 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004783 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004784 final long identity = Binder.clearCallingIdentity();
4785 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004786 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004787 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004788 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004789 } catch (ImsException e) {
4790 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004791 } finally {
4792 Binder.restoreCallingIdentity(identity);
4793 }
4794 }
4795
4796 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004797 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004798 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004799 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004800 final long identity = Binder.clearCallingIdentity();
4801 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004802 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004803 // This setting doesn't require an active ImsService connection, so do not verify. The
4804 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004805 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004806 } catch (ImsException e) {
4807 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004808 } finally {
4809 Binder.restoreCallingIdentity(identity);
4810 }
4811 }
4812
shilu366312e2019-12-17 09:28:10 -08004813 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004814 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4815 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4816 * @param subId The subscription to use to check the configuration.
4817 */
4818 @Override
4819 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004820 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004821 mApp, subId, "isCrossSimCallingEnabledByUser");
4822 final long identity = Binder.clearCallingIdentity();
4823 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004824 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004825 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004826 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004827 } catch (ImsException e) {
4828 throw new ServiceSpecificException(e.getCode());
4829 } finally {
4830 Binder.restoreCallingIdentity(identity);
4831 }
4832 }
4833
4834 /**
4835 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4836 * Requires MODIFY_PHONE_STATE permission.
4837 * @param subId The subscription to use to check the configuration.
4838 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4839 * false otherwise
4840 */
4841 @Override
4842 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4843 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4844 "setCrossSimCallingEnabled");
4845 final long identity = Binder.clearCallingIdentity();
4846 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004847 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004848 // This setting doesn't require an active ImsService connection, so do not verify. The
4849 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004850 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004851 } catch (ImsException e) {
4852 throw new ServiceSpecificException(e.getCode());
4853 } finally {
4854 Binder.restoreCallingIdentity(identity);
4855 }
4856 }
4857
4858 /**
shilu366312e2019-12-17 09:28:10 -08004859 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4860 * @param subId The subscription to use to check the configuration.
4861 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004862 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004863
Brad Ebinger35c841c2018-10-01 10:40:55 -07004864 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004865 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004866 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004867 final long identity = Binder.clearCallingIdentity();
4868 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004869 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004870 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004871 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004872 } catch (ImsException e) {
4873 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004874 } finally {
4875 Binder.restoreCallingIdentity(identity);
4876 }
4877 }
4878
4879 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004880 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004881 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004882 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004883 final long identity = Binder.clearCallingIdentity();
4884 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004885 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004886 // This setting doesn't require an active ImsService connection, so do not verify. The
4887 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004888 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004889 } catch (ImsException e) {
4890 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004891 } finally {
4892 Binder.restoreCallingIdentity(identity);
4893 }
4894 }
4895
4896 @Override
4897 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4898 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4899 "setVoWiFiNonPersistent");
4900 final long identity = Binder.clearCallingIdentity();
4901 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004902 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004903 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004904 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004905 } catch (ImsException e) {
4906 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004907 } finally {
4908 Binder.restoreCallingIdentity(identity);
4909 }
4910 }
4911
shilu366312e2019-12-17 09:28:10 -08004912 /**
4913 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4914 * @param subId The subscription to use to check the configuration.
4915 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004916 @Override
4917 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004918 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004919 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004920 final long identity = Binder.clearCallingIdentity();
4921 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004922 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004923 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004924 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004925 } catch (ImsException e) {
4926 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004927 } finally {
4928 Binder.restoreCallingIdentity(identity);
4929 }
4930 }
4931
4932 @Override
4933 public void setVoWiFiModeSetting(int subId, int mode) {
4934 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4935 "setVoWiFiModeSetting");
4936 final long identity = Binder.clearCallingIdentity();
4937 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004938 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004939 // This setting doesn't require an active ImsService connection, so do not verify. The
4940 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004941 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004942 } catch (ImsException e) {
4943 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004944 } finally {
4945 Binder.restoreCallingIdentity(identity);
4946 }
4947 }
4948
4949 @Override
4950 public int getVoWiFiRoamingModeSetting(int subId) {
4951 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4952 final long identity = Binder.clearCallingIdentity();
4953 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004954 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004955 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004956 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004957 } catch (ImsException e) {
4958 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004959 } finally {
4960 Binder.restoreCallingIdentity(identity);
4961 }
4962 }
4963
4964 @Override
4965 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4966 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4967 "setVoWiFiRoamingModeSetting");
4968 final long identity = Binder.clearCallingIdentity();
4969 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004970 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004971 // This setting doesn't require an active ImsService connection, so do not verify. The
4972 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004973 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004974 } catch (ImsException e) {
4975 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004976 } finally {
4977 Binder.restoreCallingIdentity(identity);
4978 }
4979 }
4980
4981 @Override
4982 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4983 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4984 "setRttCapabilityEnabled");
4985 final long identity = Binder.clearCallingIdentity();
4986 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004987 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004988 // This setting doesn't require an active ImsService connection, so do not verify. The
4989 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004990 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004991 } catch (ImsException e) {
4992 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004993 } finally {
4994 Binder.restoreCallingIdentity(identity);
4995 }
4996 }
4997
shilu366312e2019-12-17 09:28:10 -08004998 /**
4999 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5000 * @param subId The subscription to use to check the configuration.
5001 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005002 @Override
5003 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005004 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005005 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005006 final long identity = Binder.clearCallingIdentity();
5007 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005008 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005009 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005010 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005011 } catch (ImsException e) {
5012 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005013 } finally {
5014 Binder.restoreCallingIdentity(identity);
5015 }
5016 }
5017
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005018 @Override
5019 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5020 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005021
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005022 final long identity = Binder.clearCallingIdentity();
5023 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005024 if (!isImsAvailableOnDevice()) {
5025 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5026 "IMS not available on device.");
5027 }
5028 int slotId = getSlotIndexOrException(subId);
5029 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005030
5031 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5032 if (controller != null) {
5033 ImsManager imsManager = controller.getImsManager(subId);
5034 if (imsManager != null) {
5035 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5036 } else {
5037 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5038 }
5039 } else {
5040 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5041 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005042 } catch (ImsException e) {
5043 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005044 } finally {
5045 Binder.restoreCallingIdentity(identity);
5046 }
5047 }
5048
5049 @Override
5050 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5051 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005052
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005053 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005054 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5055 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5056 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005057 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005058 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5059 if (controller != null) {
5060 ImsManager imsManager = controller.getImsManager(subId);
5061 if (imsManager != null) {
5062 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5063 } else {
5064 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5065 + " is inactive, ignoring unregister.");
5066 // If the ImsManager is not valid, just return, since the callback will already
5067 // have been removed internally.
5068 }
5069 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005070 } finally {
5071 Binder.restoreCallingIdentity(identity);
5072 }
5073 }
5074
joonhunshincffb7fc2021-11-28 07:32:01 +00005075 @Override
5076 public void registerFeatureProvisioningChangedCallback(int subId,
5077 IFeatureProvisioningCallback callback) {
5078 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5079 mApp, subId, "registerFeatureProvisioningChangedCallback");
5080
5081 final long identity = Binder.clearCallingIdentity();
5082 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5083 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5084 }
5085
joonhunshin91bc1952022-04-29 08:47:15 +00005086 try {
5087 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5088 if (controller == null) {
5089 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5090 "Device does not support IMS");
5091 }
5092 controller.addFeatureProvisioningChangedCallback(subId, callback);
5093 } finally {
5094 Binder.restoreCallingIdentity(identity);
5095 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005096 }
5097
5098 @Override
5099 public void unregisterFeatureProvisioningChangedCallback(int subId,
5100 IFeatureProvisioningCallback callback) {
5101 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5102 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5103
5104 final long identity = Binder.clearCallingIdentity();
5105 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5106 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5107 }
5108
joonhunshin91bc1952022-04-29 08:47:15 +00005109 try {
5110 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5111 if (controller == null) {
5112 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5113 return;
5114 }
5115 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5116 } finally {
5117 Binder.restoreCallingIdentity(identity);
5118 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005119 }
allenwtsu99c623b2020-01-03 18:24:23 +08005120
5121 private void checkModifyPhoneStatePermission(int subId, String message) {
5122 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5123 message);
5124 }
5125
allenwtsu99c623b2020-01-03 18:24:23 +08005126 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005127 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005128 boolean isProvisioned) {
5129 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5130
5131 final long identity = Binder.clearCallingIdentity();
5132 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005133 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5134 if (controller == null) {
5135 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5136 return;
5137 }
5138 controller.setRcsProvisioningStatusForCapability(
5139 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005140 } finally {
5141 Binder.restoreCallingIdentity(identity);
5142 }
allenwtsu99c623b2020-01-03 18:24:23 +08005143 }
5144
5145
5146 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005147 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5148 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5149 mApp, subId, "getRcsProvisioningStatusForCapability");
5150
allenwtsu99c623b2020-01-03 18:24:23 +08005151 final long identity = Binder.clearCallingIdentity();
5152 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005153 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5154 if (controller == null) {
5155 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5156
5157 // device does not support IMS, this method will return true always.
5158 return true;
5159 }
5160 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005161 } finally {
5162 Binder.restoreCallingIdentity(identity);
5163 }
5164 }
5165
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005166 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005167 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5168 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005169 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005170
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005171 final long identity = Binder.clearCallingIdentity();
5172 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005173 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5174 if (controller == null) {
5175 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5176 return;
5177 }
5178 controller.setImsProvisioningStatusForCapability(
5179 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005180 } finally {
5181 Binder.restoreCallingIdentity(identity);
5182 }
5183 }
5184
5185 @Override
5186 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005187 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5188 mApp, subId, "getProvisioningStatusForCapability");
5189
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005190 final long identity = Binder.clearCallingIdentity();
5191 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005192 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5193 if (controller == null) {
5194 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005195
joonhunshin91bc1952022-04-29 08:47:15 +00005196 // device does not support IMS, this method will return true always.
5197 return true;
5198 }
5199 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005200 } finally {
5201 Binder.restoreCallingIdentity(identity);
5202 }
5203 }
5204
5205 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005206 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5207 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5208 mApp, subId, "isProvisioningRequiredForCapability");
5209
5210 final long identity = Binder.clearCallingIdentity();
5211 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005212 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5213 if (controller == null) {
5214 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5215
5216 // device does not support IMS, this method will return false
5217 return false;
5218 }
5219 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005220 } finally {
5221 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005222 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005223 }
5224
5225 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005226 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5227 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5228 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005229
joonhunshincffb7fc2021-11-28 07:32:01 +00005230 final long identity = Binder.clearCallingIdentity();
5231 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005232 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5233 if (controller == null) {
5234 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5235
5236 // device does not support IMS, this method will return false
5237 return false;
5238 }
5239 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005240 } finally {
5241 Binder.restoreCallingIdentity(identity);
5242 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005243 }
5244
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005245 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005246 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005247 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5248 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5249 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005250 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5251 mApp, subId, "getImsProvisioningInt");
5252
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005253 final long identity = Binder.clearCallingIdentity();
5254 try {
5255 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005256 int slotId = getSlotIndex(subId);
5257 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5258 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5259 + subId + "' for key:" + key);
5260 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5261 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005262
joonhunshin91bc1952022-04-29 08:47:15 +00005263 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5264 if (controller == null) {
5265 loge("getImsProvisioningInt: Device does not support IMS");
5266
5267 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5268 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5269 }
5270 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005271 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5272 return retVal;
5273 }
5274
calvinpanb5a34062021-02-08 19:59:36 +08005275 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005276 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005277 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5278 + subId + "' for key:" + key);
5279 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005280 } finally {
5281 Binder.restoreCallingIdentity(identity);
5282 }
5283 }
5284
5285 @Override
5286 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005287 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5288 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5289 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005290 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5291 mApp, subId, "getImsProvisioningString");
5292
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005293 final long identity = Binder.clearCallingIdentity();
5294 try {
5295 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005296 int slotId = getSlotIndex(subId);
5297 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5298 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5299 + subId + "' for key:" + key);
5300 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5301 }
calvinpanb5a34062021-02-08 19:59:36 +08005302 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005303 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005304 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5305 + subId + "' for key:" + key);
5306 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005307 } finally {
5308 Binder.restoreCallingIdentity(identity);
5309 }
5310 }
5311
5312 @Override
5313 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005314 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5315 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5316 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005317 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5318 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005319
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005320 final long identity = Binder.clearCallingIdentity();
5321 try {
5322 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005323 int slotId = getSlotIndex(subId);
5324 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5325 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5326 + subId + "' for key:" + key);
5327 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5328 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005329
joonhunshin91bc1952022-04-29 08:47:15 +00005330 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5331 if (controller == null) {
5332 loge("setImsProvisioningInt: Device does not support IMS");
5333
5334 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5335 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5336 }
5337 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005338 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5339 return retVal;
5340 }
5341
calvinpanb5a34062021-02-08 19:59:36 +08005342 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5343 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005344 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005345 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005346 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005347 } finally {
5348 Binder.restoreCallingIdentity(identity);
5349 }
5350 }
5351
5352 @Override
5353 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005354 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5355 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5356 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005357 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5358 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005359 final long identity = Binder.clearCallingIdentity();
5360 try {
5361 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005362 int slotId = getSlotIndex(subId);
5363 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5364 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5365 + subId + "' for key:" + key);
5366 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5367 }
calvinpanb5a34062021-02-08 19:59:36 +08005368 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5369 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005370 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005371 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005372 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005373 } finally {
5374 Binder.restoreCallingIdentity(identity);
5375 }
5376 }
5377
Brad Ebinger919631e2021-06-02 17:46:35 -07005378 /**
5379 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5380 * for the given slot ID or no ImsResolver instance has been created.
5381 * @param slotId The slot ID that the IMS service is created for.
5382 * @throws ImsException If there is no ImsService configured for this slot.
5383 */
5384 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5385 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5386 ImsFeature.FEATURE_MMTEL)) {
5387 throw new ImsException("This subscription does not support MMTEL over IMS",
5388 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5389 }
5390 }
5391
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005392 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005393 int slotId = SubscriptionManager.getSlotIndex(subId);
5394 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005395 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5396 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005397 }
5398 return slotId;
5399 }
5400
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005401 private int getSlotIndex(int subId) {
5402 int slotId = SubscriptionManager.getSlotIndex(subId);
5403 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5404 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5405 }
5406 return slotId;
5407 }
5408
Wink Saville36469e72014-06-11 15:17:00 -07005409 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005410 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005411 */
5412 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005413 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5414 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005415 try {
5416 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5417 } catch (SecurityException se) {
5418 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5419 throw new SecurityException("Package " + callingPackage + " does not belong to "
5420 + Binder.getCallingUid());
5421 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005422 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005423 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005424 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005425 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005426 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005427 mApp, subId, callingPackage, callingFeatureId,
5428 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005429 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5430 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005431
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005432 final long identity = Binder.clearCallingIdentity();
5433 try {
5434 final Phone phone = getPhone(subId);
5435 if (phone != null) {
5436 return phone.getServiceState().getDataNetworkType();
5437 } else {
5438 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5439 }
5440 } finally {
5441 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005442 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005443 }
5444
5445 /**
5446 * Returns the data network type
5447 */
5448 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005449 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005450 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005451 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005452 }
5453
5454 /**
5455 * Returns the data network type for a subId
5456 */
5457 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005458 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5459 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005460 String functionName = "getDataNetworkTypeForSubscriber";
5461 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5462 mApp, functionName)) {
5463 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5464 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5465 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5466 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005467 }
5468
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005469 final long identity = Binder.clearCallingIdentity();
5470 try {
5471 final Phone phone = getPhone(subId);
5472 if (phone != null) {
5473 return phone.getServiceState().getDataNetworkType();
5474 } else {
5475 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5476 }
5477 } finally {
5478 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005479 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005480 }
5481
5482 /**
Wink Saville36469e72014-06-11 15:17:00 -07005483 * Returns the Voice network type for a subId
5484 */
5485 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005486 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5487 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005488 String functionName = "getVoiceNetworkTypeForSubscriber";
5489 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5490 mApp, functionName)) {
5491 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5492 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5493 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5494 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005495 }
5496
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005497 final long identity = Binder.clearCallingIdentity();
5498 try {
5499 final Phone phone = getPhone(subId);
5500 if (phone != null) {
5501 return phone.getServiceState().getVoiceNetworkType();
5502 } else {
5503 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5504 }
5505 } finally {
5506 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005507 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005508 }
5509
5510 /**
5511 * @return true if a ICC card is present
5512 */
5513 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005514 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005515 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005516 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005517 }
5518
5519 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005520 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005521 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005522 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005523 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005524 final long identity = Binder.clearCallingIdentity();
5525 try {
5526 final Phone phone = PhoneFactory.getPhone(slotIndex);
5527 if (phone != null) {
5528 return phone.getIccCard().hasIccCard();
5529 } else {
5530 return false;
5531 }
5532 } finally {
5533 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005534 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005535 }
5536
5537 /**
5538 * Return if the current radio is LTE on CDMA. This
5539 * is a tri-state return value as for a period of time
5540 * the mode may be unknown.
5541 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005542 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005543 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005544 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005545 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005546 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005547 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5548 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5549 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005550 }
5551
Sanket Padawe356d7632015-06-22 14:03:32 -07005552 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005553 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5554 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005555 try {
5556 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5557 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005558 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5559 }
5560
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005561 final long identity = Binder.clearCallingIdentity();
5562 try {
5563 final Phone phone = getPhone(subId);
5564 if (phone == null) {
5565 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5566 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005567 return TelephonyProperties.lte_on_cdma_device()
5568 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005569 }
5570 } finally {
5571 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005572 }
Wink Saville36469e72014-06-11 15:17:00 -07005573 }
5574
Wink Saville36469e72014-06-11 15:17:00 -07005575 /**
5576 * {@hide}
5577 * Returns Default subId, 0 in the case of single standby.
5578 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005579 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005580 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005581 }
5582
Shishir Agrawala9f32182016-04-12 12:00:16 -07005583 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005584 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005585 }
5586
Wink Savilleb564aae2014-10-23 10:18:09 -07005587 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005588 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005589 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005590
Pengquan Menge92a50d2018-09-21 15:54:48 -07005591 private boolean isActiveSubscription(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08005592 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
5593 return SubscriptionManagerService.getInstance().isActiveSubId(subId,
5594 mApp.getOpPackageName(), mApp.getFeatureId());
5595 }
Pengquan Menge92a50d2018-09-21 15:54:48 -07005596 return mSubscriptionController.isActiveSubId(subId);
5597 }
5598
Ihab Awadf2177b72013-11-25 13:33:23 -08005599 /**
5600 * @see android.telephony.TelephonyManager.WifiCallingChoices
5601 */
5602 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005603 final long identity = Binder.clearCallingIdentity();
5604 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005605 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005606 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5607 getWhenToMakeWifiCallsDefaultPreference());
5608 } finally {
5609 Binder.restoreCallingIdentity(identity);
5610 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005611 }
5612
5613 /**
5614 * @see android.telephony.TelephonyManager.WifiCallingChoices
5615 */
5616 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005617 final long identity = Binder.clearCallingIdentity();
5618 try {
5619 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005620 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005621 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5622 } finally {
5623 Binder.restoreCallingIdentity(identity);
5624 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005625 }
5626
Sailesh Nepald1e68152013-12-12 19:08:02 -08005627 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005628 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005629 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005630 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005631
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005632 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5633 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5634 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005635 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005636 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5637 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005638 }
5639 return PhoneFactory.getPhone(phoneId);
5640 }
5641
Shishir Agrawal566b7612013-10-28 14:41:00 -07005642 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005643 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005644 @NonNull IccLogicalChannelRequest request) {
5645 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5646 /*message=*/ "iccOpenLogicalChannel");
5647
5648 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5649 // Verify that the callingPackage in the request belongs to the calling UID
5650 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5651
5652 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005653 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005654
Rambo Wanga1782702021-11-10 20:15:19 -08005655 private Phone getPhoneFromValidIccLogicalChannelRequest(
5656 @NonNull IccLogicalChannelRequest request, String message) {
5657 Phone phone;
5658 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5659 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5660 mApp, request.subId, message);
5661 phone = getPhoneFromSubId(request.subId);
5662 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5663 enforceModifyPermission();
5664 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5665 } else {
5666 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005667 }
Rambo Wanga1782702021-11-10 20:15:19 -08005668 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005669 }
5670
5671 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005672 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005673 final long identity = Binder.clearCallingIdentity();
5674 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005675 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005676 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005677 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5678 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005679 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5680 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005681 loge("The calling package is not allowed to access ISD-R.");
5682 throw new SecurityException(
5683 "The calling package is not allowed to access ISD-R.");
5684 }
Derek Tan740e1672017-06-27 14:56:27 -07005685 }
Derek Tan740e1672017-06-27 14:56:27 -07005686
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005687 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005688 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5689 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005690 return response;
5691 } finally {
5692 Binder.restoreCallingIdentity(identity);
5693 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005694 }
5695
5696 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005697 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5698 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5699 /*message=*/"iccCloseLogicalChannel");
5700
5701 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5702
5703 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005704 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005705
Rambo Wanga1782702021-11-10 20:15:19 -08005706 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5707 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005708 // before this feature is enabled, this API should only return false if
5709 // the operation fails instead of throwing runtime exception for
5710 // backward-compatibility.
5711 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5712 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005713 final long identity = Binder.clearCallingIdentity();
5714 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005715 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005716 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005717 }
Chen Xue9d737e2022-01-01 23:41:31 -08005718 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005719 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005720 Boolean success = false;
5721 if (result instanceof RuntimeException) {
5722 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005723 if (shouldThrowExceptionOnFailure) {
5724 throw (RuntimeException) result;
5725 } else {
5726 return false;
5727 }
Chen Xue9d737e2022-01-01 23:41:31 -08005728 } else if (result instanceof Boolean) {
5729 success = (Boolean) result;
5730 } else {
5731 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5732 }
Rambo Wanga1782702021-11-10 20:15:19 -08005733 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005734 return success;
5735 } finally {
5736 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005737 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005738 }
5739
5740 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005741 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005742 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005743 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5744 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005745 if (DBG) {
5746 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5747 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5748 + p3 + " data=" + data);
5749 }
5750 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5751 command, p1, p2, p3, data);
5752 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005753
Jordan Liu4c733742019-02-28 12:03:40 -08005754 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005755 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5756 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005757 enforceModifyPermission();
5758 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005759 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5760 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5761 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005762 }
5763 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005764 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5765 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005766 }
5767
5768 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5769 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005770 final long identity = Binder.clearCallingIdentity();
5771 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005772 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005773 return "";
5774 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005775
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005776 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005777 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5778 null /* workSource */);
5779 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005780
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005781 // Append the returned status code to the end of the response payload.
5782 String s = Integer.toHexString(
5783 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5784 if (response.payload != null) {
5785 s = IccUtils.bytesToHexString(response.payload) + s;
5786 }
5787 return s;
5788 } finally {
5789 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005790 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005791 }
Jake Hambye994d462014-02-03 13:10:13 -08005792
Evan Charltonc66da362014-05-16 14:06:40 -07005793 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005794 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5795 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005796 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5797 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005798 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005799 if (DBG) {
5800 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5801 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5802 }
5803 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5804 cla, command, p1, p2, p3, data);
5805 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005806
Jordan Liu4c733742019-02-28 12:03:40 -08005807 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005808 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5809 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005810 enforceModifyPermission();
5811 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5812 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005813 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5814 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5815 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005816 }
5817
5818 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005819 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5820 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005821 }
5822
5823 // open APDU basic channel assuming the caller has sufficient permissions
5824 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5825 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005826 final long identity = Binder.clearCallingIdentity();
5827 try {
5828 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5829 && TextUtils.equals(ISDR_AID, data)) {
5830 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005831 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5832 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005833 if (bestComponent == null
5834 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5835 loge("The calling package is not allowed to select ISD-R.");
5836 throw new SecurityException(
5837 "The calling package is not allowed to select ISD-R.");
5838 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005839 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005840
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005841 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005842 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5843 null /* workSource */);
5844 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005845
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005846 // Append the returned status code to the end of the response payload.
5847 String s = Integer.toHexString(
5848 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5849 if (response.payload != null) {
5850 s = IccUtils.bytesToHexString(response.payload) + s;
5851 }
5852 return s;
5853 } finally {
5854 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005855 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005856 }
5857
5858 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005859 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005860 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005861 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5862 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005863
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005864 final long identity = Binder.clearCallingIdentity();
5865 try {
5866 if (DBG) {
5867 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5868 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5869 }
5870
5871 IccIoResult response =
5872 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5873 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5874 subId);
5875
5876 if (DBG) {
5877 log("Exchange SIM_IO [R]" + response);
5878 }
5879
5880 byte[] result = null;
5881 int length = 2;
5882 if (response.payload != null) {
5883 length = 2 + response.payload.length;
5884 result = new byte[length];
5885 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5886 } else {
5887 result = new byte[length];
5888 }
5889
5890 result[length - 1] = (byte) response.sw2;
5891 result[length - 2] = (byte) response.sw1;
5892 return result;
5893 } finally {
5894 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005895 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005896 }
5897
Nathan Haroldb3014052017-01-25 15:57:32 -08005898 /**
5899 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5900 * on a particular subscription
5901 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005902 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5903 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005904 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005905 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005906 return null;
5907 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005908
5909 final long identity = Binder.clearCallingIdentity();
5910 try {
5911 if (appType != TelephonyManager.APPTYPE_USIM
5912 && appType != TelephonyManager.APPTYPE_SIM) {
5913 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5914 return null;
5915 }
5916 Object response = sendRequest(
5917 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5918 if (response instanceof String[]) {
5919 return (String[]) response;
5920 }
yincheng zhao2737e882019-09-06 17:06:54 -07005921 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005922 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005923 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005924 } finally {
5925 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005926 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005927 }
5928
yincheng zhao2737e882019-09-06 17:06:54 -07005929 /**
5930 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5931 * subscription.
5932 *
5933 * @param subId the id of the subscription.
5934 * @param appType the uicc app type, must be USIM or SIM.
5935 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5936 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005937 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005938 * @return number of fplmns that is successfully written to the SIM.
5939 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005940 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5941 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005942 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5943 mApp, subId, "setForbiddenPlmns");
5944
yincheng zhao2737e882019-09-06 17:06:54 -07005945 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5946 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5947 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5948 }
5949 if (fplmns == null) {
5950 throw new IllegalArgumentException("Fplmn List provided is null");
5951 }
5952 for (String fplmn : fplmns) {
5953 if (!CellIdentity.isValidPlmn(fplmn)) {
5954 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5955 }
5956 }
5957 final long identity = Binder.clearCallingIdentity();
5958 try {
5959 Object response = sendRequest(
5960 CMD_SET_FORBIDDEN_PLMNS,
5961 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5962 subId);
5963 return (int) response;
5964 } finally {
5965 Binder.restoreCallingIdentity(identity);
5966 }
5967 }
5968
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005969 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005970 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005971 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5972 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005973
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005974 final long identity = Binder.clearCallingIdentity();
5975 try {
5976 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5977 if (response.payload == null) {
5978 return "";
5979 }
Evan Charltonc66da362014-05-16 14:06:40 -07005980
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005981 // Append the returned status code to the end of the response payload.
5982 String s = Integer.toHexString(
5983 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5984 s = IccUtils.bytesToHexString(response.payload) + s;
5985 return s;
5986 } finally {
5987 Binder.restoreCallingIdentity(identity);
5988 }
Evan Charltonc66da362014-05-16 14:06:40 -07005989 }
5990
Jake Hambye994d462014-02-03 13:10:13 -08005991 /**
5992 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5993 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5994 *
5995 * @param itemID the ID of the item to read
5996 * @return the NV item as a String, or null on error.
5997 */
5998 @Override
5999 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006000 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006001 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6002 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006003
6004 final long identity = Binder.clearCallingIdentity();
6005 try {
6006 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006007 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006008 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6009 return value;
6010 } finally {
6011 Binder.restoreCallingIdentity(identity);
6012 }
Jake Hambye994d462014-02-03 13:10:13 -08006013 }
6014
6015 /**
6016 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6017 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6018 *
6019 * @param itemID the ID of the item to read
6020 * @param itemValue the value to write, as a String
6021 * @return true on success; false on any failure
6022 */
6023 @Override
6024 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006025 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006026 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6027 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006028
6029 final long identity = Binder.clearCallingIdentity();
6030 try {
6031 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6032 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006033 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006034 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6035 return success;
6036 } finally {
6037 Binder.restoreCallingIdentity(identity);
6038 }
Jake Hambye994d462014-02-03 13:10:13 -08006039 }
6040
6041 /**
6042 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6043 * Used for device configuration by some CDMA operators.
6044 *
6045 * @param preferredRoamingList byte array containing the new PRL
6046 * @return true on success; false on any failure
6047 */
6048 @Override
6049 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006050 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6051 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006052
6053 final long identity = Binder.clearCallingIdentity();
6054 try {
6055 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6056 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6057 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6058 return success;
6059 } finally {
6060 Binder.restoreCallingIdentity(identity);
6061 }
Jake Hambye994d462014-02-03 13:10:13 -08006062 }
6063
6064 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006065 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006066 * Used for device configuration by some CDMA operators.
6067 *
chen xu6dac5ab2018-10-26 17:39:23 -07006068 * @param slotIndex - device slot.
6069 *
Jake Hambye994d462014-02-03 13:10:13 -08006070 * @return true on success; false on any failure
6071 */
6072 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006073 public boolean resetModemConfig(int slotIndex) {
6074 Phone phone = PhoneFactory.getPhone(slotIndex);
6075 if (phone != null) {
6076 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6077 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006078
chen xu6dac5ab2018-10-26 17:39:23 -07006079 final long identity = Binder.clearCallingIdentity();
6080 try {
6081 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6082 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6083 return success;
6084 } finally {
6085 Binder.restoreCallingIdentity(identity);
6086 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006087 }
chen xu6dac5ab2018-10-26 17:39:23 -07006088 return false;
6089 }
6090
6091 /**
6092 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6093 *
6094 * @param slotIndex - device slot.
6095 *
6096 * @return true on success; false on any failure
6097 */
6098 @Override
6099 public boolean rebootModem(int slotIndex) {
6100 Phone phone = PhoneFactory.getPhone(slotIndex);
6101 if (phone != null) {
6102 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6103 mApp, phone.getSubId(), "rebootModem");
6104
6105 final long identity = Binder.clearCallingIdentity();
6106 try {
6107 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6108 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6109 return success;
6110 } finally {
6111 Binder.restoreCallingIdentity(identity);
6112 }
6113 }
6114 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006115 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006116
Brad Ebinger51f743a2017-01-23 13:50:20 -08006117 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006118 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6119 * {@link #disableIms(int)}.
6120 * @param slotIndex device slot.
6121 */
6122 public void resetIms(int slotIndex) {
6123 enforceModifyPermission();
6124
6125 final long identity = Binder.clearCallingIdentity();
6126 try {
6127 if (mImsResolver == null) {
6128 // may happen if the does not support IMS.
6129 return;
6130 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006131 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006132 } finally {
6133 Binder.restoreCallingIdentity(identity);
6134 }
6135 }
6136
6137 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006138 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6139 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006140 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006141 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006142 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006143
6144 final long identity = Binder.clearCallingIdentity();
6145 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006146 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006147 // may happen if the device does not support IMS.
6148 return;
6149 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006150 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006151 } finally {
6152 Binder.restoreCallingIdentity(identity);
6153 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006154 }
6155
6156 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006157 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6158 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006159 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006160 public void disableIms(int slotId) {
6161 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006162
6163 final long identity = Binder.clearCallingIdentity();
6164 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006165 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006166 // may happen if the device does not support IMS.
6167 return;
6168 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006169 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006170 } finally {
6171 Binder.restoreCallingIdentity(identity);
6172 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006173 }
6174
6175 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006176 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6177 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006178 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006179 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006180 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006181 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006182
6183 final long identity = Binder.clearCallingIdentity();
6184 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006185 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006186 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6187 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006188 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006189 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006190 } finally {
6191 Binder.restoreCallingIdentity(identity);
6192 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006193 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006194 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006195 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6196 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006197 @Override
6198 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006199 enforceModifyPermission();
6200
6201 final long identity = Binder.clearCallingIdentity();
6202 try {
6203 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006204 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006205 } finally {
6206 Binder.restoreCallingIdentity(identity);
6207 }
6208 }
6209
6210 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006211 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006212 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006213 */
6214 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6215 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006216
6217 final long identity = Binder.clearCallingIdentity();
6218 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006219 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006220 // may happen if the device does not support IMS.
6221 return null;
6222 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006223 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006224 } finally {
6225 Binder.restoreCallingIdentity(identity);
6226 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006227 }
6228
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006229 /**
6230 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006231 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006232 */
6233 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6234 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006235
6236 final long identity = Binder.clearCallingIdentity();
6237 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006238 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006239 // may happen if the device does not support IMS.
6240 return null;
6241 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006242 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006243 } finally {
6244 Binder.restoreCallingIdentity(identity);
6245 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006246 }
6247
Brad Ebinger884c07b2018-02-15 16:17:40 -08006248 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006249 * Sets the ImsService Package Name that Telephony will bind to.
6250 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006251 * @param slotIndex the slot ID that the ImsService should bind for.
6252 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006253 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006254 * @param featureTypes An integer array of feature types associated with a packageName.
6255 * @param packageName The name of the package that the current configuration will be replaced
6256 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006257 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006258 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006259 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6260 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006261 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006262 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006263 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006264
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006265 final long identity = Binder.clearCallingIdentity();
6266 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006267 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006268 // may happen if the device does not support IMS.
6269 return false;
6270 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006271 Map<Integer, String> featureConfig = new HashMap<>();
6272 for (int featureType : featureTypes) {
6273 featureConfig.put(featureType, packageName);
6274 }
6275 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6276 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006277 } finally {
6278 Binder.restoreCallingIdentity(identity);
6279 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006280 }
6281
6282 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006283 * Clears any carrier ImsService overrides for the slot index specified that were previously
6284 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6285 *
6286 * This should only be used for testing.
6287 *
6288 * @param slotIndex the slot ID that the ImsService should bind for.
6289 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6290 */
6291 @Override
6292 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006293 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6294 "clearCarrierImsServiceOverride");
6295 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006296 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006297
6298 final long identity = Binder.clearCallingIdentity();
6299 try {
6300 if (mImsResolver == null) {
6301 // may happen if the device does not support IMS.
6302 return false;
6303 }
6304 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6305 } finally {
6306 Binder.restoreCallingIdentity(identity);
6307 }
6308 }
6309
6310 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006311 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006312 *
6313 * @param slotId The slot that the ImsService is associated with.
6314 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6315 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006316 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006317 * @return the package name of the ImsService configuration.
6318 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006319 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6320 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006321 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006322 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6323 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006324
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006325 final long identity = Binder.clearCallingIdentity();
6326 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006327 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006328 // may happen if the device does not support IMS.
6329 return "";
6330 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006331 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006332 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6333 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006334 } finally {
6335 Binder.restoreCallingIdentity(identity);
6336 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006337 }
6338
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006339 /**
6340 * Get the MmTelFeature state associated with the requested subscription id.
6341 * @param subId The subscription that the MmTelFeature is associated with.
6342 * @param callback A callback with an integer containing the
6343 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6344 */
6345 @Override
6346 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6347 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006348 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6349 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6350 "IMS not available on device.");
6351 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006352 final long token = Binder.clearCallingIdentity();
6353 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006354 int slotId = getSlotIndex(subId);
6355 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6356 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6357 + subId + "'");
6358 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6359 }
6360 verifyImsMmTelConfiguredOrThrow(slotId);
6361 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6362 try {
6363 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6364 } catch (RemoteException e) {
6365 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6366 + "Ignore");
6367 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006368 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006369 } catch (ImsException e) {
6370 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006371 } finally {
6372 Binder.restoreCallingIdentity(token);
6373 }
6374 }
6375
Daniel Brightbb5840b2021-01-12 15:48:18 -08006376 /**
6377 * Sets the ims registration state on all valid {@link Phone}s.
6378 */
6379 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006380 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006381
6382 final long identity = Binder.clearCallingIdentity();
6383 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006384 // NOTE: Before S, this method only set the default phone.
6385 for (final Phone phone : PhoneFactory.getPhones()) {
6386 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6387 phone.setImsRegistrationState(registered);
6388 }
6389 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006390 } finally {
6391 Binder.restoreCallingIdentity(identity);
6392 }
Wink Saville36469e72014-06-11 15:17:00 -07006393 }
6394
6395 /**
Stuart Scott54788802015-03-30 13:18:01 -07006396 * Set the network selection mode to automatic.
6397 *
6398 */
6399 @Override
6400 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006401 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6402 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006403
6404 final long identity = Binder.clearCallingIdentity();
6405 try {
shilufc958392020-01-20 11:36:01 -08006406 if (!isActiveSubscription(subId)) {
6407 return;
6408 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006409 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006410 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6411 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006412 } finally {
6413 Binder.restoreCallingIdentity(identity);
6414 }
Stuart Scott54788802015-03-30 13:18:01 -07006415 }
6416
Jack Yud10cdd42020-09-28 20:28:01 -07006417 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006418 * Ask the radio to connect to the input network and change selection mode to manual.
6419 *
6420 * @param subId the id of the subscription.
6421 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6422 * the operator to attach to.
6423 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6424 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6425 * normal network selection next time.
6426 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006427 */
6428 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006429 public boolean setNetworkSelectionModeManual(
6430 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006431 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6432 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006433
Jack Yu285100e2022-12-02 22:48:35 -08006434 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006435 if (!isActiveSubscription(subId)) {
6436 return false;
6437 }
6438
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006439 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006440 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006441 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006442 if (DBG) {
6443 log("setNetworkSelectionModeManual: subId: " + subId
6444 + " operator: " + operatorInfo);
6445 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006446 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6447 } finally {
6448 Binder.restoreCallingIdentity(identity);
6449 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006450 }
shilu84f6e8b2019-12-19 13:58:01 -08006451 /**
6452 * Get the manual network selection
6453 *
6454 * @param subId the id of the subscription.
6455 *
6456 * @return the previously saved user selected PLMN
6457 */
6458 @Override
6459 public String getManualNetworkSelectionPlmn(int subId) {
6460 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006461 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006462 mApp, subId, "getManualNetworkSelectionPlmn");
6463
6464 final long identity = Binder.clearCallingIdentity();
6465 try {
6466 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006467 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006468 }
6469
6470 final Phone phone = getPhone(subId);
6471 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006472 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006473 }
6474 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6475 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6476 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6477 } finally {
6478 Binder.restoreCallingIdentity(identity);
6479 }
6480 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006481
6482 /**
6483 * Scans for available networks.
6484 */
6485 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006486 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6487 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006488 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6489 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006490 LocationAccessPolicy.LocationPermissionResult locationResult =
6491 LocationAccessPolicy.checkLocationPermission(mApp,
6492 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6493 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006494 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006495 .setCallingPid(Binder.getCallingPid())
6496 .setCallingUid(Binder.getCallingUid())
6497 .setMethod("getCellNetworkScanResults")
6498 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006499 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6500 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006501 .build());
6502 switch (locationResult) {
6503 case DENIED_HARD:
6504 throw new SecurityException("Not allowed to access scan results -- location");
6505 case DENIED_SOFT:
6506 return null;
6507 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006508
Pengquan Menga1bb6272018-09-06 09:59:22 -07006509 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006510 try {
6511 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006512 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006513 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006514 } finally {
6515 Binder.restoreCallingIdentity(identity);
6516 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006517 }
6518
6519 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006520 * Get the call forwarding info, given the call forwarding reason.
6521 */
6522 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006523 public void getCallForwarding(int subId, int callForwardingReason,
6524 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006525 enforceReadPrivilegedPermission("getCallForwarding");
6526 long identity = Binder.clearCallingIdentity();
6527 try {
6528 if (DBG) {
6529 log("getCallForwarding: subId " + subId
6530 + " callForwardingReason" + callForwardingReason);
6531 }
Hall Liu27d24262020-09-18 19:04:59 -07006532
6533 Phone phone = getPhone(subId);
6534 if (phone == null) {
6535 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006536 callback.onError(
6537 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006538 } catch (RemoteException e) {
6539 // ignore
6540 }
6541 return;
6542 }
6543
6544 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6545 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6546 @Override
6547 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6548 try {
6549 callback.onCallForwardingInfoAvailable(info);
6550 } catch (RemoteException e) {
6551 // ignore
6552 }
6553 }
6554
6555 @Override
6556 public void onError(int error) {
6557 try {
6558 callback.onError(error);
6559 } catch (RemoteException e) {
6560 // ignore
6561 }
6562 }
6563 });
6564 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006565 } finally {
6566 Binder.restoreCallingIdentity(identity);
6567 }
6568 }
6569
6570 /**
6571 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6572 * reason, the number to forward, and the timeout before the forwarding is attempted.
6573 */
6574 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006575 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6576 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006577 enforceModifyPermission();
6578 long identity = Binder.clearCallingIdentity();
6579 try {
6580 if (DBG) {
6581 log("setCallForwarding: subId " + subId
6582 + " callForwardingInfo" + callForwardingInfo);
6583 }
Hall Liu27d24262020-09-18 19:04:59 -07006584
6585 Phone phone = getPhone(subId);
6586 if (phone == null) {
6587 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006588 callback.accept(
6589 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006590 } catch (RemoteException e) {
6591 // ignore
6592 }
6593 return;
6594 }
6595
6596 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6597 FunctionalUtils.ignoreRemoteException(callback::accept));
6598
6599 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006600 } finally {
6601 Binder.restoreCallingIdentity(identity);
6602 }
6603 }
6604
6605 /**
Hall Liu27d24262020-09-18 19:04:59 -07006606 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006607 */
6608 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006609 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006610 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006611 long identity = Binder.clearCallingIdentity();
6612 try {
Hall Liu27d24262020-09-18 19:04:59 -07006613 Phone phone = getPhone(subId);
6614 if (phone == null) {
6615 try {
6616 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6617 } catch (RemoteException e) {
6618 // ignore
6619 }
6620 return;
6621 }
SongFerngWang0e767992021-03-31 22:08:45 +08006622 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6623 PersistableBundle c = configManager.getConfigForSubId(subId);
6624 boolean requireUssd = c.getBoolean(
6625 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006626
Shuo Qian4a594052020-01-23 11:59:30 -08006627 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006628 if (requireUssd) {
6629 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6630 getSubscriptionCarrierId(subId));
6631 String newUssdCommand = "";
6632 try {
6633 newUssdCommand = carrierXmlParser.getFeature(
6634 CarrierXmlParser.FEATURE_CALL_WAITING)
6635 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6636 } catch (NullPointerException e) {
6637 loge("Failed to generate USSD number" + e);
6638 }
6639 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6640 mMainThreadHandler, callback, carrierXmlParser,
6641 CarrierXmlParser.SsEntry.SSAction.QUERY);
6642 final String ussdCommand = newUssdCommand;
6643 Executors.newSingleThreadExecutor().execute(() -> {
6644 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6645 });
6646 } else {
6647 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6648 callback::accept);
6649 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6650 }
Shuo Qian4a594052020-01-23 11:59:30 -08006651 } finally {
6652 Binder.restoreCallingIdentity(identity);
6653 }
6654 }
6655
6656 /**
Hall Liu27d24262020-09-18 19:04:59 -07006657 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006658 */
6659 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006660 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006661 enforceModifyPermission();
6662 long identity = Binder.clearCallingIdentity();
6663 try {
Hall Liu27d24262020-09-18 19:04:59 -07006664 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6665
6666 Phone phone = getPhone(subId);
6667 if (phone == null) {
6668 try {
6669 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6670 } catch (RemoteException e) {
6671 // ignore
6672 }
6673 return;
6674 }
6675
SongFerngWang0e767992021-03-31 22:08:45 +08006676 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6677 PersistableBundle c = configManager.getConfigForSubId(subId);
6678 boolean requireUssd = c.getBoolean(
6679 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006680
SongFerngWang0e767992021-03-31 22:08:45 +08006681 if (DBG) log("getCallWaitingStatus: subId " + subId);
6682 if (requireUssd) {
6683 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6684 getSubscriptionCarrierId(subId));
6685 CarrierXmlParser.SsEntry.SSAction ssAction =
6686 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6687 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6688 String newUssdCommand = "";
6689 try {
6690 newUssdCommand = carrierXmlParser.getFeature(
6691 CarrierXmlParser.FEATURE_CALL_WAITING)
6692 .makeCommand(ssAction, null);
6693 } catch (NullPointerException e) {
6694 loge("Failed to generate USSD number" + e);
6695 }
6696 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6697 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6698 final String ussdCommand = newUssdCommand;
6699 Executors.newSingleThreadExecutor().execute(() -> {
6700 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6701 });
6702 } else {
6703 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6704 FunctionalUtils.ignoreRemoteException(callback::accept));
6705
6706 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6707 }
Shuo Qian4a594052020-01-23 11:59:30 -08006708 } finally {
6709 Binder.restoreCallingIdentity(identity);
6710 }
6711 }
6712
6713 /**
yinxub1bed742017-04-17 11:45:04 -07006714 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006715 *
yinxub1bed742017-04-17 11:45:04 -07006716 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006717 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6718 * location related information which will be sent if the caller already possess
6719 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006720 * @param request contains the radio access networks with bands/channels to scan
6721 * @param messenger callback messenger for scan results or errors
6722 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006723 * @return the id of the requested scan which can be used to stop the scan.
6724 */
6725 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006726 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6727 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006728 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006729 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6730 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006731 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006732 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6733 if (!renounceFineLocationAccess) {
6734 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6735 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6736 .setCallingPackage(callingPackage)
6737 .setCallingFeatureId(callingFeatureId)
6738 .setCallingPid(Binder.getCallingPid())
6739 .setCallingUid(Binder.getCallingUid())
6740 .setMethod("requestNetworkScan")
6741 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6742 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6743 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6744 .build());
6745 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006746 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006747 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6748 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006749 if (e != null) {
6750 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6751 throw e;
6752 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006753 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006754 return TelephonyScanManager.INVALID_SCAN_ID;
6755 }
6756 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006757 }
Hall Liu912dfd32019-04-25 14:02:26 -07006758 int callingUid = Binder.getCallingUid();
6759 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006760 final long identity = Binder.clearCallingIdentity();
6761 try {
6762 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006763 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006764 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006765 } finally {
6766 Binder.restoreCallingIdentity(identity);
6767 }
yinxu504e1392017-04-12 16:03:22 -07006768 }
6769
Hall Liub2ac8ef2019-02-28 15:56:23 -08006770 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006771 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00006772 boolean hasCarrierPriv;
6773 final long identity = Binder.clearCallingIdentity();
6774 try {
6775 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6776 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6777 } finally {
6778 Binder.restoreCallingIdentity(identity);
6779 }
Hall Liu558027f2019-05-15 19:14:05 -07006780 boolean hasNetworkScanPermission =
6781 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6782 == PERMISSION_GRANTED;
6783
6784 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6785 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6786 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006787 }
6788
6789 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6790 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006791 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6792 return new SecurityException("Specific channels must not be"
6793 + " scanned without location access.");
6794 }
6795 }
6796 }
6797
Hall Liub2ac8ef2019-02-28 15:56:23 -08006798 return null;
6799 }
6800
yinxu504e1392017-04-12 16:03:22 -07006801 /**
6802 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006803 *
6804 * @param subId id of the subscription
6805 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006806 */
6807 @Override
6808 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006809 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6810 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006811
Hall Liu912dfd32019-04-25 14:02:26 -07006812 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006813 final long identity = Binder.clearCallingIdentity();
6814 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006815 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006816 } finally {
6817 Binder.restoreCallingIdentity(identity);
6818 }
yinxu504e1392017-04-12 16:03:22 -07006819 }
6820
6821 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006822 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006823 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006824 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006825 */
6826 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006827 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006828 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006829 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006830 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006831
6832 final long identity = Binder.clearCallingIdentity();
6833 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006834 if (DBG) log("getAllowedNetworkTypesBitmask");
6835 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6836 int networkTypesBitmask = (result != null ? result[0] : -1);
6837 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6838 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006839 } finally {
6840 Binder.restoreCallingIdentity(identity);
6841 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006842 }
6843
6844 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006845 * Get the allowed network types for certain reason.
6846 *
6847 * @param subId the id of the subscription.
6848 * @param reason the reason the allowed network type change is taking place
6849 * @return the allowed network types.
6850 */
6851 @Override
6852 public long getAllowedNetworkTypesForReason(int subId,
6853 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006854 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006855 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006856 final long identity = Binder.clearCallingIdentity();
6857 try {
6858 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6859 } finally {
6860 Binder.restoreCallingIdentity(identity);
6861 }
6862 }
6863
6864 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006865 * Enable/Disable E-UTRA-NR Dual Connectivity
6866 * @param subId subscription id of the sim card
6867 * @param nrDualConnectivityState expected NR dual connectivity state
6868 * This can be passed following states
6869 * <ol>
6870 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6871 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6872 * <li>Disable NR dual connectivity and force secondary cell to be released
6873 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6874 * </ol>
6875 * @return operation result.
6876 */
6877 @Override
6878 public int setNrDualConnectivityState(int subId,
6879 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6880 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6881 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006882 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006883 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6884 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6885 }
6886
Sooraj Sasindran37444802020-08-11 10:40:43 -07006887 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6888 final long identity = Binder.clearCallingIdentity();
6889 try {
6890 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6891 nrDualConnectivityState, subId,
6892 workSource);
6893 if (DBG) log("enableNRDualConnectivity result: " + result);
6894 return result;
6895 } finally {
6896 Binder.restoreCallingIdentity(identity);
6897 }
6898 }
6899
6900 /**
6901 * Is E-UTRA-NR Dual Connectivity enabled
6902 * @return true if dual connectivity is enabled else false
6903 */
6904 @Override
6905 public boolean isNrDualConnectivityEnabled(int subId) {
6906 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006907 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006908 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006909 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006910 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6911 return false;
6912 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006913 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6914 final long identity = Binder.clearCallingIdentity();
6915 try {
6916 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6917 null, subId, workSource);
6918 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6919 return isEnabled;
6920 } finally {
6921 Binder.restoreCallingIdentity(identity);
6922 }
6923 }
6924
6925 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006926 * Set the allowed network types of the device and
6927 * provide the reason triggering the allowed network change.
6928 *
6929 * @param subId the id of the subscription.
6930 * @param reason the reason the allowed network type change is taking place
6931 * @param allowedNetworkTypes the allowed network types.
6932 * @return true on success; false on any failure.
6933 */
6934 @Override
6935 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006936 @TelephonyManager.AllowedNetworkTypesReason int reason,
6937 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006938 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6939 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006940 // If the caller only has carrier privileges, then they should not be able to override
6941 // any network types which were set for security reasons.
6942 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6943 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00006944 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006945 throw new SecurityException(
6946 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00006947 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006948 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006949 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006950 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08006951 return false;
6952 }
6953 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6954 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006955 return false;
6956 }
6957
Jack Yu5b494332023-01-23 18:18:04 +00006958 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
6959 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006960
Jack Yue37dd262022-12-16 11:53:37 -08006961 Phone phone = getPhone(subId);
6962 if (phone == null) {
6963 return false;
6964 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006965
Jack Yue37dd262022-12-16 11:53:37 -08006966 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006967 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006968 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006969 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006970
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006971 final long identity = Binder.clearCallingIdentity();
6972 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006973 Boolean success = (Boolean) sendRequest(
6974 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6975 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6976
6977 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6978 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006979 } finally {
6980 Binder.restoreCallingIdentity(identity);
6981 }
6982 }
6983
6984 /**
Miaoa84611c2019-03-15 09:21:10 +08006985 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006986 *
Miaoa84611c2019-03-15 09:21:10 +08006987 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006988 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006989 * @hide
6990 */
6991 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006992 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006993 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006994 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006995 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006996 try {
Miaoa84611c2019-03-15 09:21:10 +08006997 if (phone != null) {
6998 return phone.hasMatchedTetherApnSetting();
6999 } else {
7000 return false;
7001 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007002 } finally {
7003 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007004 }
Junda Liu475951f2014-11-07 16:45:03 -08007005 }
7006
7007 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007008 * Get the user enabled state of Mobile Data.
7009 *
7010 * TODO: remove and use isUserDataEnabled.
7011 * This can't be removed now because some vendor codes
7012 * calls through ITelephony directly while they should
7013 * use TelephonyManager.
7014 *
7015 * @return true on enabled
7016 */
7017 @Override
7018 public boolean getDataEnabled(int subId) {
7019 return isUserDataEnabled(subId);
7020 }
7021
7022 /**
7023 * Get whether mobile data is enabled per user setting.
7024 *
7025 * There are other factors deciding whether mobile data is actually enabled, but they are
7026 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007027 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007028 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7029 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007030 *
7031 * @return {@code true} if data is enabled else {@code false}
7032 */
7033 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007034 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007035 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007036 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007037 try {
7038 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7039 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007040 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007041 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7042 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007043 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007044 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007045 mApp, subId, functionName);
7046
Robert Greenwalt646120a2014-05-23 11:54:03 -07007047 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007048
7049 final long identity = Binder.clearCallingIdentity();
7050 try {
Jack Yu285100e2022-12-02 22:48:35 -08007051 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007052 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7053 Phone phone = PhoneFactory.getPhone(phoneId);
7054 if (phone != null) {
7055 boolean retVal = phone.isUserDataEnabled();
7056 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7057 return retVal;
7058 } else {
7059 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7060 return false;
7061 }
7062 } finally {
7063 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007064 }
7065 }
7066
7067 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007068 * Checks if the device is capable of mobile data by considering whether whether the
7069 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7070 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007071 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007072 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007073 */
7074 @Override
7075 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007076 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007077 try {
7078 try {
7079 mApp.enforceCallingOrSelfPermission(
7080 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007081 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007082 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007083 try {
7084 mApp.enforceCallingOrSelfPermission(
7085 android.Manifest.permission.READ_PHONE_STATE,
7086 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007087 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007088 mApp.enforceCallingOrSelfPermission(
7089 permission.READ_BASIC_PHONE_STATE, functionName);
7090 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007091 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007092 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007093 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007094 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007095
7096 final long identity = Binder.clearCallingIdentity();
7097 try {
Jack Yu285100e2022-12-02 22:48:35 -08007098 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007099 Phone phone = PhoneFactory.getPhone(phoneId);
7100 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007101 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007102 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007103 return retVal;
7104 } else {
7105 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7106 return false;
7107 }
7108 } finally {
7109 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007110 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007111 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007112
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007113 /**
7114 * Check if data is enabled for a specific reason
7115 * @param subId Subscription index
7116 * @param reason the reason the data enable change is taking place
7117 * @return {@code true} if the overall data is enabled; {@code false} if not.
7118 */
7119 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007120 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007121 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007122 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007123 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007124 try {
7125 mApp.enforceCallingOrSelfPermission(
7126 android.Manifest.permission.ACCESS_NETWORK_STATE,
7127 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007128 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007129 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7130 functionName);
7131 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007132 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007133 try {
7134 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007135 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007136 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007137 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007138 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007139 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007140 }
7141
7142
7143 final long identity = Binder.clearCallingIdentity();
7144 try {
Jack Yu285100e2022-12-02 22:48:35 -08007145 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007146 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007147 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007148 + " reason=" + reason);
7149 }
7150 Phone phone = PhoneFactory.getPhone(phoneId);
7151 if (phone != null) {
7152 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007153 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007154 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007155 return retVal;
7156 } else {
7157 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007158 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007159 + subId + " retVal=false");
7160 }
7161 return false;
7162 }
7163 } finally {
7164 Binder.restoreCallingIdentity(identity);
7165 }
7166 }
7167
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007168 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007169 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007170 // No permission needed; this only lets the caller inspect their own status.
7171 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007172 }
Junda Liu29340342014-07-10 15:23:27 -07007173
7174 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007175 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007176 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007177 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7178 }
7179
7180 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7181 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007182 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007183 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007184 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7185 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007186 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7187 if (cpt == null) {
7188 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007189 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7190 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007191 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007192 }
7193
7194 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007195 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007196 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07007197 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007198 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007199 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007200 Phone phone = getPhone(subId);
7201 if (phone == null) {
7202 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7203 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7204 }
7205 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7206 if (cpt == null) {
7207 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007208 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7209 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007210 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007211 }
7212
7213 @Override
7214 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007215 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08007216 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7217 }
7218
7219 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007220 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007221 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007222 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007223 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007224 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7225 Phone phone = PhoneFactory.getPhone(phoneId);
7226 if (phone == null) {
7227 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007228 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007229 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7230 if (cpt == null) {
7231 continue;
7232 }
7233 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007234 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7235 break;
7236 }
7237 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007238 return result;
Junda Liu29340342014-07-10 15:23:27 -07007239 }
Derek Tan89e89d42014-07-08 17:00:10 -07007240
7241 @Override
Junda Liue64de782015-04-16 17:19:16 -07007242 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007243 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00007244 Phone phone = PhoneFactory.getPhone(phoneId);
7245 if (phone == null) {
7246 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007247 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007248 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7249 if (cpt == null) {
7250 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007251 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007252 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007253 }
7254
Amith Yamasani6e118872016-02-19 12:53:51 -08007255 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007256 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007257 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007258 Phone phone = PhoneFactory.getPhone(phoneId);
7259 if (phone == null) {
7260 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007261 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007262 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7263 if (cpt == null) {
7264 return Collections.emptyList();
7265 }
7266 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007267 }
7268
chen xuf7e9fe82019-05-09 19:31:02 -07007269 @Override
7270 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007271 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007272 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007273 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007274 try {
7275 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7276 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7277 }
7278 } finally {
7279 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007280 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007281 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007282 }
7283
Rambo Wang6812ffb2022-03-15 16:54:17 -07007284 @Override
7285 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7286 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7287
7288 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7289 if (phone == null) {
7290 return null;
7291 }
7292 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7293 if (cpt == null) {
7294 return null;
7295 }
7296 return cpt.getCarrierServicePackageName();
7297 }
7298
Wink Savilleb564aae2014-10-23 10:18:09 -07007299 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007300 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007301 UiccPort port = phone == null ? null : phone.getUiccPort();
7302 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007303 return null;
7304 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007305 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007306 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007307 return null;
7308 }
7309 return iccId;
7310 }
7311
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007312 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007313 public void setCallComposerStatus(int subId, int status) {
7314 enforceModifyPermission();
7315
7316 final long identity = Binder.clearCallingIdentity();
7317 try {
7318 Phone phone = getPhone(subId);
7319 if (phone != null) {
7320 Phone defaultPhone = phone.getImsPhone();
7321 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7322 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7323 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007324 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7325 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007326 }
7327 }
Shuo Qian284ae752020-12-22 19:10:14 -08007328 } catch (ImsException e) {
7329 throw new ServiceSpecificException(e.getCode());
7330 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007331 Binder.restoreCallingIdentity(identity);
7332 }
7333 }
7334
7335 @Override
7336 public int getCallComposerStatus(int subId) {
7337 enforceReadPrivilegedPermission("getCallComposerStatus");
7338
7339 final long identity = Binder.clearCallingIdentity();
7340 try {
7341 Phone phone = getPhone(subId);
7342 if (phone != null) {
7343 Phone defaultPhone = phone.getImsPhone();
7344 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7345 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7346 return imsPhone.getCallComposerStatus();
7347 }
7348 }
7349 } finally {
7350 Binder.restoreCallingIdentity(identity);
7351 }
7352 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7353 }
7354
7355 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007356 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7357 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007358 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007359 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007360
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007361 final long identity = Binder.clearCallingIdentity();
7362 try {
7363 final String iccId = getIccId(subId);
7364 final Phone phone = getPhone(subId);
7365 if (phone == null) {
7366 return false;
7367 }
7368 final String subscriberId = phone.getSubscriberId();
7369
7370 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007371 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007372 + subscriberId + " to " + number);
7373 }
7374
7375 if (TextUtils.isEmpty(iccId)) {
7376 return false;
7377 }
7378
7379 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7380
7381 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7382 if (alphaTag == null) {
7383 editor.remove(alphaTagPrefKey);
7384 } else {
7385 editor.putString(alphaTagPrefKey, alphaTag);
7386 }
7387
7388 // Record both the line number and IMSI for this ICCID, since we need to
7389 // track all merged IMSIs based on line number
7390 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7391 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7392 if (number == null) {
7393 editor.remove(numberPrefKey);
7394 editor.remove(subscriberPrefKey);
7395 } else {
7396 editor.putString(numberPrefKey, number);
7397 editor.putString(subscriberPrefKey, subscriberId);
7398 }
7399
7400 editor.commit();
7401 return true;
7402 } finally {
7403 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007404 }
Derek Tan7226c842014-07-02 17:42:23 -07007405 }
7406
7407 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007408 public String getLine1NumberForDisplay(int subId, String callingPackage,
7409 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007410 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007411 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007412 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007413 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007414 return null;
7415 }
Derek Tan97ebb422014-09-05 16:55:38 -07007416
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007417 final long identity = Binder.clearCallingIdentity();
7418 try {
7419 String iccId = getIccId(subId);
7420 if (iccId != null) {
7421 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7422 if (DBG_MERGE) {
7423 log("getLine1NumberForDisplay returning "
7424 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7425 }
7426 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007427 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007428 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7429 return null;
7430 } finally {
7431 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007432 }
Derek Tan7226c842014-07-02 17:42:23 -07007433 }
7434
7435 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007436 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7437 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007438 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007439 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007440 return null;
7441 }
Derek Tan97ebb422014-09-05 16:55:38 -07007442
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007443 final long identity = Binder.clearCallingIdentity();
7444 try {
7445 String iccId = getIccId(subId);
7446 if (iccId != null) {
7447 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7448 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7449 }
7450 return null;
7451 } finally {
7452 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007453 }
Derek Tan7226c842014-07-02 17:42:23 -07007454 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007455
7456 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007457 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7458 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007459 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7460 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007461 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007462 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007463 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007464 return null;
7465 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007466
Jordan Liub49b04b2019-05-06 14:45:15 -07007467 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7468 // the process, where TelephonyManager was instantiated.
7469 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007470 final long identity = Binder.clearCallingIdentity();
7471 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007472 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007473 final TelephonyManager tele = TelephonyManager.from(context);
7474 final SubscriptionManager sub = SubscriptionManager.from(context);
7475
7476 // Figure out what subscribers are currently active
7477 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007478
Jordan Liub49b04b2019-05-06 14:45:15 -07007479 // Only consider subs which match the current subId
7480 // This logic can be simplified. See b/131189269 for progress.
7481 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007482 activeSubscriberIds.add(tele.getSubscriberId(subId));
7483 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007484
7485 // First pass, find a number override for an active subscriber
7486 String mergeNumber = null;
7487 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7488 for (String key : prefs.keySet()) {
7489 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7490 final String subscriberId = (String) prefs.get(key);
7491 if (activeSubscriberIds.contains(subscriberId)) {
7492 final String iccId = key.substring(
7493 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7494 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7495 mergeNumber = (String) prefs.get(numberKey);
7496 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007497 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007498 + " for active subscriber " + subscriberId);
7499 }
7500 if (!TextUtils.isEmpty(mergeNumber)) {
7501 break;
7502 }
7503 }
7504 }
7505 }
7506
7507 // Shortcut when no active merged subscribers
7508 if (TextUtils.isEmpty(mergeNumber)) {
7509 return null;
7510 }
7511
7512 // Second pass, find all subscribers under that line override
7513 final ArraySet<String> result = new ArraySet<>();
7514 for (String key : prefs.keySet()) {
7515 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7516 final String number = (String) prefs.get(key);
7517 if (mergeNumber.equals(number)) {
7518 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7519 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7520 final String subscriberId = (String) prefs.get(subscriberKey);
7521 if (!TextUtils.isEmpty(subscriberId)) {
7522 result.add(subscriberId);
7523 }
7524 }
7525 }
7526 }
7527
7528 final String[] resultArray = result.toArray(new String[result.size()]);
7529 Arrays.sort(resultArray);
7530 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007531 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007532 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7533 }
7534 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007535 } finally {
7536 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007537 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007538 }
7539
7540 @Override
zoey chen38003472019-12-13 17:16:31 +08007541 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7542 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007543
7544 final long identity = Binder.clearCallingIdentity();
7545 try {
7546 final TelephonyManager telephonyManager = mApp.getSystemService(
7547 TelephonyManager.class);
7548 String subscriberId = telephonyManager.getSubscriberId(subId);
7549 if (subscriberId == null) {
7550 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007551 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007552 + subId);
7553 }
7554 return null;
7555 }
7556
Jack Yu285100e2022-12-02 22:48:35 -08007557 ParcelUuid groupUuid;
7558 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7559 final SubscriptionInfo info = SubscriptionManagerService.getInstance()
7560 .getSubscriptionInfo(subId);
7561 groupUuid = info.getGroupUuid();
7562 } else {
7563 final SubscriptionInfo info = mSubscriptionController
7564 .getSubscriptionInfo(subId);
7565 groupUuid = info.getGroupUuid();
7566 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007567 // If it doesn't belong to any group, return just subscriberId of itself.
7568 if (groupUuid == null) {
7569 return new String[]{subscriberId};
7570 }
7571
7572 // Get all subscriberIds from the group.
7573 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu285100e2022-12-02 22:48:35 -08007574 List<SubscriptionInfo> groupInfos;
7575 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7576 groupInfos = SubscriptionManagerService.getInstance()
7577 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7578 mApp.getAttributionTag());
7579 } else {
7580 groupInfos = mSubscriptionController
7581 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7582 mApp.getAttributionTag());
7583 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007584 for (SubscriptionInfo subInfo : groupInfos) {
7585 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7586 if (subscriberId != null) {
7587 mergedSubscriberIds.add(subscriberId);
7588 }
7589 }
7590
7591 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7592 } finally {
7593 Binder.restoreCallingIdentity(identity);
7594
7595 }
7596 }
7597
7598 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007599 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007600 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007601 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007602
7603 final long identity = Binder.clearCallingIdentity();
7604 try {
7605 final Phone phone = getPhone(subId);
7606 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7607 } finally {
7608 Binder.restoreCallingIdentity(identity);
7609 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007610 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007611
7612 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007613 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007614 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7615 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007616 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7617 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007618
7619 final long identity = Binder.clearCallingIdentity();
7620 try {
7621 final Phone phone = getPhone(subId);
7622 if (phone == null) {
7623 return false;
7624 }
7625 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7626 cdmaNonRoamingList);
7627 } finally {
7628 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007629 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007630 }
7631
7632 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007633 @Deprecated
7634 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7635 enforceModifyPermission();
7636
7637 int returnValue = 0;
7638 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007639 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007640 if(result.exception == null) {
7641 if (result.result != null) {
7642 byte[] responseData = (byte[])(result.result);
7643 if(responseData.length > oemResp.length) {
7644 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7645 responseData.length + "bytes. Buffer Size is " +
7646 oemResp.length + "bytes.");
7647 }
7648 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7649 returnValue = responseData.length;
7650 }
7651 } else {
7652 CommandException ex = (CommandException) result.exception;
7653 returnValue = ex.getCommandError().ordinal();
7654 if(returnValue > 0) returnValue *= -1;
7655 }
7656 } catch (RuntimeException e) {
7657 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7658 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7659 if(returnValue > 0) returnValue *= -1;
7660 }
7661
7662 return returnValue;
7663 }
7664
7665 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007666 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007667 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007668 try {
7669 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007670 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007671 mApp, phone.getSubId(), "getRadioAccessFamily");
7672 } catch (SecurityException e) {
7673 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7674 throw e;
7675 }
chen xub97461a2018-10-26 14:17:57 -07007676 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007677 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007678 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007679 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007680 final long identity = Binder.clearCallingIdentity();
7681 try {
chen xub97461a2018-10-26 14:17:57 -07007682 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007683 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007684 mApp, phone.getSubId(), "getRadioAccessFamily");
7685 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007686 } finally {
7687 Binder.restoreCallingIdentity(identity);
7688 }
chen xub97461a2018-10-26 14:17:57 -07007689 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007690 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007691
7692 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007693 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007694 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007695 try {
7696 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7697 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007698 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007699 }
7700 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007701 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007702 }
7703 RoleManager rm = mApp.getSystemService(RoleManager.class);
7704 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7705 if (!dialerRoleHolders.contains(callingPackage)) {
7706 throw new SecurityException("App must be the dialer role holder to"
7707 + " upload a call composer pic");
7708 }
7709
7710 Executors.newSingleThreadExecutor().execute(() -> {
7711 ByteArrayOutputStream output = new ByteArrayOutputStream(
7712 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7713 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7714 boolean readUntilEnd = false;
7715 int totalBytesRead = 0;
7716 byte[] buffer = new byte[16 * 1024];
7717 while (true) {
7718 int numRead;
7719 try {
7720 numRead = input.read(buffer);
7721 } catch (IOException e) {
7722 try {
7723 fd.checkError();
7724 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7725 null);
7726 } catch (IOException e1) {
7727 // This means that the other side closed explicitly with an error. If this
7728 // happens, log and ignore.
7729 loge("Remote end of call composer picture pipe closed: " + e1);
7730 }
7731 break;
7732 }
7733 if (numRead == -1) {
7734 readUntilEnd = true;
7735 break;
7736 }
7737 totalBytesRead += numRead;
7738 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7739 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7740 try {
7741 input.close();
7742 } catch (IOException e) {
7743 // ignore
7744 }
7745 break;
7746 }
7747 output.write(buffer, 0, numRead);
7748 }
7749 // Generally, the remote end will close the file descriptors. The only case where we
7750 // close is above, where the picture size is too big.
7751
7752 try {
7753 fd.checkError();
7754 } catch (IOException e) {
7755 loge("Remote end for call composer closed with an error: " + e);
7756 return;
7757 }
7758
Hall Liuaa4211e2021-01-20 15:43:39 -08007759 if (!readUntilEnd) {
7760 loge("Did not finish reading entire image; aborting");
7761 return;
7762 }
Hall Liu82694d52020-12-11 18:22:04 -08007763
Hall Liuaa4211e2021-01-20 15:43:39 -08007764 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7765 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7766 new CallComposerPictureTransfer.Factory() {},
7767 imageData,
7768 (result) -> {
7769 if (result.first != null) {
7770 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7771 Bundle outputResult = new Bundle();
7772 outputResult.putParcelable(
7773 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7774 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7775 outputResult);
7776 } else {
7777 callback.send(result.second, null);
7778 }
7779 }
7780 );
Hall Liu82694d52020-12-11 18:22:04 -08007781 });
7782 }
7783
7784 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007785 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007786 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007787 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007788
7789 final long identity = Binder.clearCallingIdentity();
7790 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007791 ImsManager.getInstance(defaultPhone.getContext(),
7792 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007793 } finally {
7794 Binder.restoreCallingIdentity(identity);
7795 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007796 }
7797
7798 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007799 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007800 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007801 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7802 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007803 return false;
7804 }
Svet Ganovb320e182015-04-16 12:30:10 -07007805
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007806 final long identity = Binder.clearCallingIdentity();
7807 try {
7808 // Check the user preference and the system-level IMS setting. Even if the user has
7809 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7810 // In the long run, we may instead need to check if there exists a connection service
7811 // which can support video calling.
7812 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007813 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007814 return imsManager.isVtEnabledByPlatform()
7815 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7816 && imsManager.isVtEnabledByUser();
7817 } finally {
7818 Binder.restoreCallingIdentity(identity);
7819 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007820 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007821
Andrew Leea1239f22015-03-02 17:44:07 -08007822 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007823 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7824 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007825 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007826 mApp, subId, callingPackage, callingFeatureId,
7827 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007828 return false;
7829 }
7830
7831 final long identity = Binder.clearCallingIdentity();
7832 try {
7833 CarrierConfigManager configManager =
7834 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007835 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007836 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7837 } finally {
7838 Binder.restoreCallingIdentity(identity);
7839 }
Andrew Leea1239f22015-03-02 17:44:07 -08007840 }
7841
7842 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007843 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007844 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007845 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007846 return false;
7847 }
7848
7849 final long identity = Binder.clearCallingIdentity();
7850 try {
7851 CarrierConfigManager configManager =
7852 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007853 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007854 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7855 } finally {
7856 Binder.restoreCallingIdentity(identity);
7857 }
Andrew Leea1239f22015-03-02 17:44:07 -08007858 }
7859
Andrew Lee9431b832015-03-09 18:46:45 -07007860 @Override
7861 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007862 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007863 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007864 }
7865
7866 @Override
7867 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007868 final long identity = Binder.clearCallingIdentity();
7869 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007870 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007871 } finally {
7872 Binder.restoreCallingIdentity(identity);
7873 }
Andrew Lee9431b832015-03-09 18:46:45 -07007874 }
7875
Hall Liuf6668912018-10-31 17:05:23 -07007876 /**
7877 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7878 * support for the feature and device firmware support.
7879 *
7880 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7881 */
7882 @Override
7883 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007884 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007885 final Phone phone = getPhone(subscriptionId);
7886 if (phone == null) {
7887 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7888 return false;
7889 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007890 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007891 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007892 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7893 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007894 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007895 return isCarrierSupported && isDeviceSupported;
7896 } finally {
7897 Binder.restoreCallingIdentity(identity);
7898 }
Hall Liu98187582018-01-22 19:15:32 -08007899 }
7900
Hall Liuf6668912018-10-31 17:05:23 -07007901 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007902 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7903 * RTT setting, will return true if the device and carrier both support RTT.
7904 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007905 */
7906 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007907 final long identity = Binder.clearCallingIdentity();
7908 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007909 boolean isRttSupported = isRttSupported(subscriptionId);
7910 boolean isUserRttSettingOn = Settings.Secure.getInt(
7911 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7912 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7913 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7914 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007915 } finally {
7916 Binder.restoreCallingIdentity(identity);
7917 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007918 }
7919
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007920 @Deprecated
7921 @Override
7922 public String getDeviceId(String callingPackage) {
7923 return getDeviceIdWithFeature(callingPackage, null);
7924 }
7925
Sanket Padawe7310cc72015-01-14 09:53:20 -08007926 /**
7927 * Returns the unique device ID of phone, for example, the IMEI for
7928 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7929 *
7930 * <p>Requires Permission:
7931 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7932 */
7933 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007934 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007935 try {
7936 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7937 } catch (SecurityException se) {
7938 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7939 throw new SecurityException("Package " + callingPackage + " does not belong to "
7940 + Binder.getCallingUid());
7941 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007942 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007943 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007944 return null;
7945 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007946 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007947 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007948 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007949 return null;
7950 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007951
7952 final long identity = Binder.clearCallingIdentity();
7953 try {
7954 return phone.getDeviceId();
7955 } finally {
7956 Binder.restoreCallingIdentity(identity);
7957 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007958 }
7959
Ping Sunc67b7c22016-03-02 19:16:45 +08007960 /**
7961 * {@hide}
7962 * Returns the IMS Registration Status on a particular subid
7963 *
7964 * @param subId
7965 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007966 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007967 Phone phone = getPhone(subId);
7968 if (phone != null) {
7969 return phone.isImsRegistered();
7970 } else {
7971 return false;
7972 }
7973 }
7974
Santos Cordon7a1885b2015-02-03 11:15:19 -08007975 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007976 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007977 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007978 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007979 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007980 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7981 }
7982 final long identity = Binder.clearCallingIdentity();
7983 try {
7984 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7985 } finally {
7986 Binder.restoreCallingIdentity(identity);
7987 }
7988 }
7989
7990 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007991 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007992 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007993 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007994 mApp,
7995 subscriptionId,
7996 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007997 final long identity = Binder.clearCallingIdentity();
7998 try {
7999 Phone phone = getPhone(subscriptionId);
8000 if (phone == null) {
8001 return null;
8002 }
8003 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8004 } finally {
8005 Binder.restoreCallingIdentity(identity);
8006 }
8007 }
8008
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008009 /**
8010 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008011 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008012 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008013 final long identity = Binder.clearCallingIdentity();
8014 try {
8015 Phone phone = getPhone(subId);
8016 if (phone != null) {
8017 return phone.isWifiCallingEnabled();
8018 } else {
8019 return false;
8020 }
8021 } finally {
8022 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008023 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008024 }
8025
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008026 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008027 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008028 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008029 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008030 final long identity = Binder.clearCallingIdentity();
8031 try {
8032 Phone phone = getPhone(subId);
8033 if (phone != null) {
8034 return phone.isVideoEnabled();
8035 } else {
8036 return false;
8037 }
8038 } finally {
8039 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008040 }
8041 }
8042
8043 /**
8044 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8045 * defined in {@link ImsRegistrationImplBase}.
8046 */
8047 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008048 final long identity = Binder.clearCallingIdentity();
8049 try {
8050 Phone phone = getPhone(subId);
8051 if (phone != null) {
8052 return phone.getImsRegistrationTech();
8053 } else {
8054 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8055 }
8056 } finally {
8057 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008058 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008059 }
8060
Stuart Scott8eef64f2015-04-08 15:13:54 -07008061 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008062 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008063 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07008064 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8065 return;
8066 }
Kai Shif70f46f2021-03-03 13:59:46 -08008067 Phone defaultPhone = getDefaultPhone();
8068 if (defaultPhone != null) {
8069 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8070 mApp, getDefaultPhone().getSubId(), "factoryReset");
8071 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008072 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008073
Svet Ganovcc087f82015-05-12 20:35:54 -07008074 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008075 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8076 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008077 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008078 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008079 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008080 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008081 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008082 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08008083 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008084 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008085 // There has been issues when Sms raw table somehow stores orphan
8086 // fragments. They lead to garbled message when new fragments come
8087 // in and combined with those stale ones. In case this happens again,
8088 // user can reset all network settings which will clean up this table.
8089 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008090 // Clean up IMS settings as well here.
8091 int slotId = getSlotIndex(subId);
8092 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8093 ImsManager.getInstance(mApp, slotId).factoryReset();
8094 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008095
Kai Shif70f46f2021-03-03 13:59:46 -08008096 if (defaultPhone == null) {
8097 return;
8098 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008099 // Erase modem config if erase modem on network setting is enabled.
8100 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8101 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8102 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008103 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008104 }
Kai Shif70f46f2021-03-03 13:59:46 -08008105
8106 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008107 } finally {
8108 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008109 }
8110 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008111
SongFerngWangfd89b102021-05-27 22:44:54 +08008112 @VisibleForTesting
8113 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8114 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8115 return;
8116 }
8117 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8118 RILConstants.PREFERRED_NETWORK_MODE);
8119 SubscriptionManager.setSubscriptionProperty(subId,
8120 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8121 "user=" + defaultNetworkType);
8122 phone.loadAllowedNetworksFromSubscriptionDatabase();
8123 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8124 defaultNetworkType, null);
8125 }
8126
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008127 private void cleanUpSmsRawTable(Context context) {
8128 ContentResolver resolver = context.getContentResolver();
8129 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8130 resolver.delete(uri, null, null);
8131 }
8132
Narayan Kamath1c496c22015-04-16 14:40:19 +01008133 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008134 public String getSimLocaleForSubscriber(int subId) {
8135 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
8136 final Phone phone = getPhone(subId);
8137 if (phone == null) {
8138 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008139 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008140 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008141 final long identity = Binder.clearCallingIdentity();
8142 try {
Jack Yu285100e2022-12-02 22:48:35 -08008143 SubscriptionInfo info;
8144 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
8145 info = SubscriptionManagerService.getInstance().getActiveSubscriptionInfo(subId,
8146 phone.getContext().getOpPackageName(),
8147 phone.getContext().getAttributionTag());
8148 if (info == null) {
8149 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8150 return null;
8151 }
8152 } else {
8153 info = mSubscriptionController.getActiveSubscriptionInfo(subId,
8154 phone.getContext().getOpPackageName(),
8155 phone.getContext().getAttributionTag());
8156 if (info == null) {
8157 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8158 return null;
8159 }
chen xu6291c472019-02-04 12:55:53 -08008160 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008161 // Try and fetch the locale from the carrier properties or from the SIM language
8162 // preferences (EF-PL and EF-LI)...
8163 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008164 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008165 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8166 if (localeFromDefaultSim != null) {
8167 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8168 if (DBG) log("Using locale from subId: " + subId + " locale: "
8169 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008170 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008171 } else {
8172 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008173 }
8174 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008175
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008176 // The SIM language preferences only store a language (e.g. fr = French), not an
8177 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8178 // the SIM and carrier preferences does not include a country we add the country
8179 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008180 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008181 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008182 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008183 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008184 }
8185
8186 if (DBG) log("No locale found - returning null");
8187 return null;
8188 } finally {
8189 Binder.restoreCallingIdentity(identity);
8190 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008191 }
8192
tom hsu0b59d292022-09-29 23:49:21 +08008193 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008194 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008195 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008196 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008197 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008198 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8199 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008200 Locale.forLanguageTag(localeTag).getCountry())) {
8201 return localeTag;
8202 }
8203 }
8204 return inputLocale.toLanguageTag();
8205 }
8206
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008207 /**
8208 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8209 */
8210 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu285100e2022-12-02 22:48:35 -08008211 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
8212 return SubscriptionManagerService.getInstance().getActiveSubscriptionInfoList(
8213 mApp.getOpPackageName(), mApp.getAttributionTag());
8214 }
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008215 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08008216 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01008217 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008218
Gary Jian3aa9a762022-01-24 16:41:19 +08008219 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8220 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008221
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008222 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008223 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8224 * representing the state of the modem.
8225 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008226 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8227 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008228 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008229 */
8230 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008231 public void requestModemActivityInfo(ResultReceiver result) {
8232 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008233 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008234
8235 final long identity = Binder.clearCallingIdentity();
8236 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008237 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008238 } finally {
8239 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008240 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008241 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008242
Gary Jian76280a42022-12-07 16:18:33 +08008243 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008244 // less than total activity duration.
8245 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8246 if (info == null) {
8247 return false;
8248 }
8249 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008250 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008251 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8252
Hall Liu49656c02020-10-09 19:00:11 -07008253 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8254
Siddharth Rayb8114062018-06-17 15:02:38 -07008255 return (info.isValid()
8256 && (info.getSleepTimeMillis() <= activityDurationMs)
Gary Jian76280a42022-12-07 16:18:33 +08008257 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008258 }
8259
Gary Jian3aa9a762022-01-24 16:41:19 +08008260 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8261 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8262 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8263 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8264
8265 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8266 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8267 }
8268
8269 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8270 mLastModemActivityInfo.setReceiveTimeMillis(
8271 rat,
8272 freq,
8273 info.getReceiveTimeMillis(rat, freq)
8274 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8275 }
8276
8277 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8278 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8279 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8280 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8281
8282 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8283 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8284 }
8285 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8286 mLastModemActivityInfo.setReceiveTimeMillis(
8287 rat,
8288 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8289 }
8290
8291 /**
8292 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8293 * @param info recent ModemActivityInfo
8294 */
8295 private void mergeModemActivityInfo(ModemActivityInfo info) {
8296 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008297 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008298 boolean matched;
8299 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8300 matched = false;
8301 int rat = info.getSpecificInfoRat(i);
8302 int freq = info.getSpecificInfoFrequencyRange(i);
8303 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8304 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8305 //if it already exists
8306 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8307 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8308 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8309 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8310 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8311 updateLastModemActivityInfo(info, rat, freq);
8312 matched = true;
8313 }
8314 } else {
8315 updateLastModemActivityInfo(info, rat);
8316 matched = true;
8317 }
8318 }
8319 }
8320
8321 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008322 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008323 new ActivityStatsTechSpecificInfo(
8324 rat,
8325 freq,
8326 info.getTransmitTimeMillis(rat, freq),
8327 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008328 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008329 }
8330 }
8331 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8332 mLastModemActivitySpecificInfo =
8333 new ActivityStatsTechSpecificInfo[merged.size()];
8334 merged.toArray(mLastModemActivitySpecificInfo);
8335
8336 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8337 mLastModemActivityInfo.setSleepTimeMillis(
8338 info.getSleepTimeMillis()
8339 + mLastModemActivityInfo.getSleepTimeMillis());
8340 mLastModemActivityInfo.setIdleTimeMillis(
8341 info.getIdleTimeMillis()
8342 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008343
8344 mLastModemActivityInfo =
8345 new ModemActivityInfo(
8346 mLastModemActivityInfo.getTimestampMillis(),
8347 mLastModemActivityInfo.getSleepTimeMillis(),
8348 mLastModemActivityInfo.getIdleTimeMillis(),
8349 mLastModemActivitySpecificInfo);
8350 }
8351
8352 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8353 ActivityStatsTechSpecificInfo[] info) {
8354 int infoSize = info.length;
8355 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8356 for (int i = 0; i < infoSize; i++) {
8357 ret[i] = new ActivityStatsTechSpecificInfo(
8358 info[i].getRat(), info[i].getFrequencyRange(),
8359 info[i].getTransmitTimeMillis(),
8360 (int) info[i].getReceiveTimeMillis());
8361 }
8362 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008363 }
8364
Jack Yu85bd38a2015-11-09 11:34:32 -08008365 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008366 * Returns the service state information on specified subscription.
8367 */
8368 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008369 public ServiceState getServiceStateForSubscriber(int subId,
8370 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8371 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008372 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008373 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008374 return null;
8375 }
8376
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008377 boolean hasFinePermission = false;
8378 boolean hasCoarsePermission = false;
8379 if (!renounceFineLocationAccess) {
8380 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8381 LocationAccessPolicy.checkLocationPermission(mApp,
8382 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8383 .setCallingPackage(callingPackage)
8384 .setCallingFeatureId(callingFeatureId)
8385 .setCallingPid(Binder.getCallingPid())
8386 .setCallingUid(Binder.getCallingUid())
8387 .setMethod("getServiceStateForSubscriber")
8388 .setLogAsInfo(true)
8389 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8390 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8391 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8392 .build());
8393 hasFinePermission =
8394 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8395 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008396
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008397 if (!renounceCoarseLocationAccess) {
8398 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8399 LocationAccessPolicy.checkLocationPermission(mApp,
8400 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8401 .setCallingPackage(callingPackage)
8402 .setCallingFeatureId(callingFeatureId)
8403 .setCallingPid(Binder.getCallingPid())
8404 .setCallingUid(Binder.getCallingUid())
8405 .setMethod("getServiceStateForSubscriber")
8406 .setLogAsInfo(true)
8407 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8408 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8409 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8410 .build());
8411 hasCoarsePermission =
8412 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8413 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008414
Jack Yu479f40e2020-10-27 21:29:25 -07008415 final Phone phone = getPhone(subId);
8416 if (phone == null) {
8417 return null;
8418 }
8419
Jordan Liu0f2bc442020-11-18 16:47:37 -08008420 final long identity = Binder.clearCallingIdentity();
8421
Jack Yu479f40e2020-10-27 21:29:25 -07008422 boolean isCallingPackageDataService = phone.getDataServicePackages()
8423 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008424 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008425 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu285100e2022-12-02 22:48:35 -08008426 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
8427 SubscriptionInfoInternal subInfo = SubscriptionManagerService.getInstance()
8428 .getSubscriptionInfoInternal(subId);
8429 if (subInfo == null || !subInfo.isActive()) {
8430 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8431 + "subId=" + subId);
8432 return null;
8433 }
8434 } else {
8435 if (!mSubscriptionController.isActiveSubId(subId, callingPackage,
8436 callingFeatureId)) {
8437 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8438 + "subId=" + subId);
8439 return null;
8440 }
Jordan Liuc437b192020-08-17 10:59:12 -07008441 }
8442
Hall Liuf19c44f2018-11-27 14:38:17 -08008443 ServiceState ss = phone.getServiceState();
8444
8445 // Scrub out the location info in ServiceState depending on what level of access
8446 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008447 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008448 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8449 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008450 } finally {
8451 Binder.restoreCallingIdentity(identity);
8452 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008453 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008454
8455 /**
8456 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8457 *
8458 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8459 * voicemail ringtone.
8460 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8461 * PhoneAccount.
8462 */
8463 @Override
8464 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008465 final long identity = Binder.clearCallingIdentity();
8466 try {
8467 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8468 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008469 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008470 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008471
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008472 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8473 } finally {
8474 Binder.restoreCallingIdentity(identity);
8475 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008476 }
8477
8478 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008479 * Sets the per-account voicemail ringtone.
8480 *
8481 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8482 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8483 *
8484 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8485 * voicemail ringtone.
8486 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8487 * PhoneAccount.
8488 */
8489 @Override
8490 public void setVoicemailRingtoneUri(String callingPackage,
8491 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008492 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008493 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008494 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8495 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008496 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8497 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8498 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008499 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008500
8501 final long identity = Binder.clearCallingIdentity();
8502 try {
8503 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8504 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008505 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008506 }
8507 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8508 } finally {
8509 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008510 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008511 }
8512
8513 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008514 * Returns whether vibration is set for voicemail notification in Phone settings.
8515 *
8516 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8517 * voicemail vibration setting.
8518 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8519 */
8520 @Override
8521 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008522 final long identity = Binder.clearCallingIdentity();
8523 try {
8524 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8525 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008526 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008527 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008528
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008529 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8530 } finally {
8531 Binder.restoreCallingIdentity(identity);
8532 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008533 }
8534
Youhan Wange64578a2016-05-02 15:32:42 -07008535 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008536 * Sets the per-account voicemail vibration.
8537 *
8538 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8539 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8540 *
8541 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8542 * voicemail vibration setting.
8543 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8544 * specific PhoneAccount.
8545 */
8546 @Override
8547 public void setVoicemailVibrationEnabled(String callingPackage,
8548 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008549 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008550 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008551 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8552 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008553 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8554 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8555 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008556 }
8557
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008558 final long identity = Binder.clearCallingIdentity();
8559 try {
8560 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8561 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008562 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008563 }
8564 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8565 } finally {
8566 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008567 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008568 }
8569
8570 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008571 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8572 *
8573 * @throws SecurityException if the caller does not have the required permission
8574 */
arunvoddud7401012022-12-15 16:08:12 +00008575 @VisibleForTesting
8576 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008577 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008578 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008579 }
8580
8581 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008582 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8583 * permission.
8584 *
8585 * @throws SecurityException if the caller does not have the required permission
8586 */
8587 private void enforceSendSmsPermission() {
8588 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8589 }
8590
8591 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00008592 * Make sure either called from same process as self (phone) or IPC caller has interact across
8593 * users permission.
8594 *
8595 * @throws SecurityException if the caller does not have the required permission
8596 */
8597 private void enforceInteractAcrossUsersPermission(String message) {
8598 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
8599 }
8600
8601 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008602 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008603 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008604 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008605 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008606 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008607 final long identity = Binder.clearCallingIdentity();
8608 try {
8609 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008610 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008611 if (componentName == null) {
8612 throw new SecurityException(
8613 "Caller not current active visual voicemail package[null]");
8614 }
8615 String vvmPackage = componentName.getPackageName();
8616 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008617 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008618 }
8619 } finally {
8620 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008621 }
8622 }
8623
8624 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008625 * Return the application ID for the app type.
8626 *
8627 * @param subId the subscription ID that this request applies to.
8628 * @param appType the uicc app type.
8629 * @return Application ID for specificied app type, or null if no uicc.
8630 */
8631 @Override
8632 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008633 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008634 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008635
8636 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008637 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008638 if (phone == null) {
8639 return null;
8640 }
8641 String aid = null;
8642 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008643 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008644 .getApplicationByType(appType).getAid();
8645 } catch (Exception e) {
8646 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8647 }
8648 return aid;
8649 } finally {
8650 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008651 }
Youhan Wange64578a2016-05-02 15:32:42 -07008652 }
8653
Youhan Wang4001d252016-05-11 10:29:41 -07008654 /**
8655 * Return the Electronic Serial Number.
8656 *
8657 * @param subId the subscription ID that this request applies to.
8658 * @return ESN or null if error.
8659 */
8660 @Override
8661 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008662 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008663 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008664
8665 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008666 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008667 if (phone == null) {
8668 return null;
8669 }
8670 String esn = null;
8671 try {
8672 esn = phone.getEsn();
8673 } catch (Exception e) {
8674 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8675 }
8676 return esn;
8677 } finally {
8678 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008679 }
Youhan Wang4001d252016-05-11 10:29:41 -07008680 }
8681
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008682 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008683 * Return the Preferred Roaming List Version.
8684 *
8685 * @param subId the subscription ID that this request applies to.
8686 * @return PRLVersion or null if error.
8687 */
8688 @Override
8689 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008690 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008691 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008692
8693 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008694 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008695 if (phone == null) {
8696 return null;
8697 }
8698 String cdmaPrlVersion = null;
8699 try {
8700 cdmaPrlVersion = phone.getCdmaPrlVersion();
8701 } catch (Exception e) {
8702 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8703 }
8704 return cdmaPrlVersion;
8705 } finally {
8706 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008707 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008708 }
8709
8710 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008711 * Get snapshot of Telephony histograms
8712 * @return List of Telephony histograms
8713 * @hide
8714 */
8715 @Override
8716 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008717 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8718 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008719
8720 final long identity = Binder.clearCallingIdentity();
8721 try {
8722 return RIL.getTelephonyRILTimingHistograms();
8723 } finally {
8724 Binder.restoreCallingIdentity(identity);
8725 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008726 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008727
8728 /**
8729 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008730 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8731 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008732 * Require system privileges. In the future we may add this to carrier APIs.
8733 *
Michele Berionne482f8202018-11-27 18:57:59 -08008734 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008735 */
8736 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008737 @TelephonyManager.SetCarrierRestrictionResult
8738 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008739 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008740 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008741
Michele Berionne482f8202018-11-27 18:57:59 -08008742 if (carrierRestrictionRules == null) {
8743 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008744 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008745
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008746 final long identity = Binder.clearCallingIdentity();
8747 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008748 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008749 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008750 } finally {
8751 Binder.restoreCallingIdentity(identity);
8752 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008753 }
8754
8755 /**
8756 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008757 * Get the allowed carrier list and the excluded carrier list, including the priority between
8758 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008759 * Require system privileges. In the future we may add this to carrier APIs.
8760 *
Michele Berionne482f8202018-11-27 18:57:59 -08008761 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008762 */
8763 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008764 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008765 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008766 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008767
8768 final long identity = Binder.clearCallingIdentity();
8769 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008770 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8771 if (response instanceof CarrierRestrictionRules) {
8772 return (CarrierRestrictionRules) response;
8773 }
8774 // Response is an Exception of some kind,
8775 // which is signalled to the user as a NULL retval
8776 return null;
8777 } catch (Exception e) {
8778 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8779 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008780 } finally {
8781 Binder.restoreCallingIdentity(identity);
8782 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008783 }
8784
fionaxu59545b42016-05-25 15:53:37 -07008785 /**
arunvoddud7401012022-12-15 16:08:12 +00008786 * Fetches the carrier restriction status of the device and sends the status to the caller
8787 * through the callback.
8788 *
8789 * @param callback The callback that will be used to send the result.
8790 * @throws SecurityException if the caller does not have the required permission/privileges or
8791 * the caller is not allowlisted.
8792 */
8793 @Override
8794 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
8795 enforceReadPermission("getCarrierRestrictionStatus");
8796 int carrierId = validateCallerAndGetCarrierId(packageName);
8797 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
8798 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
8799 throw new SecurityException("Not an authorized caller");
8800 }
8801 final long identity = Binder.clearCallingIdentity();
8802 try {
8803 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
8804 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
8805 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
8806 } finally {
8807 Binder.restoreCallingIdentity(identity);
8808 }
8809 }
8810
8811 @VisibleForTesting
8812 public int validateCallerAndGetCarrierId(String packageName) {
8813 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
8814 return allowListInfo.validateCallerAndGetCarrierId(packageName);
8815 }
8816
8817 /**
fionaxu59545b42016-05-25 15:53:37 -07008818 * Action set from carrier signalling broadcast receivers to enable/disable radio
8819 * @param subId the subscription ID that this action applies to.
8820 * @param enabled control enable or disable radio.
8821 * {@hide}
8822 */
8823 @Override
8824 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8825 enforceModifyPermission();
8826 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008827
8828 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008829 if (phone == null) {
8830 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8831 return;
8832 }
8833 try {
8834 phone.carrierActionSetRadioEnabled(enabled);
8835 } catch (Exception e) {
8836 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008837 } finally {
8838 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008839 }
8840 }
8841
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008842 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008843 * Enable or disable Voice over NR (VoNR)
8844 * @param subId the subscription ID that this action applies to.
8845 * @param enabled enable or disable VoNR.
8846 * @return operation result.
8847 */
8848 @Override
8849 public int setVoNrEnabled(int subId, boolean enabled) {
8850 enforceModifyPermission();
8851 final Phone phone = getPhone(subId);
8852
8853 final long identity = Binder.clearCallingIdentity();
8854 if (phone == null) {
8855 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8856 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8857 }
8858
8859 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8860 try {
8861 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8862 workSource);
8863 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008864
8865 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8866 if (DBG) {
8867 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8868 }
8869 SubscriptionManager.setSubscriptionProperty(
8870 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8871 (enabled ? "1" : "0"));
8872 }
8873
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008874 return result;
8875 } finally {
8876 Binder.restoreCallingIdentity(identity);
8877 }
8878 }
8879
8880 /**
8881 * Is voice over NR enabled
8882 * @return true if VoNR is enabled else false
8883 */
8884 @Override
8885 public boolean isVoNrEnabled(int subId) {
8886 enforceReadPrivilegedPermission("isVoNrEnabled");
8887 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8888 final long identity = Binder.clearCallingIdentity();
8889 try {
8890 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8891 null, subId, workSource);
8892 if (DBG) log("isVoNrEnabled: " + isEnabled);
8893 return isEnabled;
8894 } finally {
8895 Binder.restoreCallingIdentity(identity);
8896 }
8897 }
8898
8899 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008900 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8901 * network status based on which carrier apps could apply actions accordingly,
8902 * enable/disable default url handler for example.
8903 *
8904 * @param subId the subscription ID that this action applies to.
8905 * @param report control start/stop reporting the default network status.
8906 * {@hide}
8907 */
8908 @Override
8909 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8910 enforceModifyPermission();
8911 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008912
8913 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008914 if (phone == null) {
8915 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8916 return;
8917 }
8918 try {
8919 phone.carrierActionReportDefaultNetworkStatus(report);
8920 } catch (Exception e) {
8921 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008922 } finally {
8923 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008924 }
8925 }
8926
8927 /**
fionaxud9622282017-07-17 17:51:30 -07008928 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8929 * @param subId the subscription ID that this action applies to.
8930 * {@hide}
8931 */
8932 @Override
8933 public void carrierActionResetAll(int subId) {
8934 enforceModifyPermission();
8935 final Phone phone = getPhone(subId);
8936 if (phone == null) {
8937 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8938 return;
8939 }
8940 try {
8941 phone.carrierActionResetAll();
8942 } catch (Exception e) {
8943 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8944 }
8945 }
8946
8947 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008948 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8949 * bug report is being generated.
8950 */
8951 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008952 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008953 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8954 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008955 writer.println("Permission Denial: can't dump Phone from pid="
8956 + Binder.getCallingPid()
8957 + ", uid=" + Binder.getCallingUid()
8958 + "without permission "
8959 + android.Manifest.permission.DUMP);
8960 return;
8961 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008962 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008963 }
Jack Yueb89b242016-06-22 13:27:47 -07008964
Brad Ebingerdac2f002018-04-03 15:17:52 -07008965 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008966 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8967 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8968 @NonNull String[] args) {
8969 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8970 this, in.getFileDescriptor(), out.getFileDescriptor(),
8971 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008972 }
8973
Jack Yueb89b242016-06-22 13:27:47 -07008974 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008975 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008976 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008977 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008978 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008979 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008980 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008981 */
8982 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008983 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008984 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008985 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8986 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8987 try {
8988 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008989 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008990 } catch (SecurityException se) {
8991 enforceModifyPermission();
8992 }
8993 } else {
8994 enforceModifyPermission();
8995 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008996
8997 final long identity = Binder.clearCallingIdentity();
8998 try {
8999 Phone phone = getPhone(subId);
9000 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009001 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9002 phone.carrierActionSetMeteredApnsEnabled(enabled);
9003 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07009004 phone.getDataSettingsManager().setDataEnabled(
9005 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009006 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009007 }
9008 } finally {
9009 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009010 }
9011 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009012
9013 /**
9014 * Get Client request stats
9015 * @return List of Client Request Stats
9016 * @hide
9017 */
9018 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009019 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9020 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009021 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009022 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009023 return null;
9024 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009025 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009026
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009027 final long identity = Binder.clearCallingIdentity();
9028 try {
9029 if (phone != null) {
9030 return phone.getClientRequestStats();
9031 }
9032
9033 return null;
9034 } finally {
9035 Binder.restoreCallingIdentity(identity);
9036 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009037 }
9038
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009039 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009040 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009041 if (uid == Process.ROOT_UID && packageName == null) {
9042 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9043 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9044 // exception. ROOT_UID seems not to have a valid package name returned by
9045 // PackageManager, so just fake it here to avoid issues when running telephony shell
9046 // commands that plumb through the RIL as root, like so:
9047 // $ adb root
9048 // $ adb shell cmd phone ...
9049 packageName = "root";
9050 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009051 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009052 }
Jack Yueb4124c2017-02-16 15:32:43 -08009053
9054 /**
Grace Chen70990072017-03-24 17:21:30 -07009055 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009056 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009057 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009058 * @param state State of SIM (power down, power up, pass through)
9059 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9060 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9061 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009062 *
9063 **/
9064 @Override
Grace Chen70990072017-03-24 17:21:30 -07009065 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009066 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009067 Phone phone = PhoneFactory.getPhone(slotIndex);
9068
vagdeviaf9a5b92018-08-15 16:01:53 -07009069 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9070
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009071 final long identity = Binder.clearCallingIdentity();
9072 try {
9073 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009074 phone.setSimPowerState(state, null, workSource);
9075 }
9076 } finally {
9077 Binder.restoreCallingIdentity(identity);
9078 }
9079 }
9080
9081 /**
9082 * Set SIM card power state.
9083 *
9084 * @param slotIndex SIM slot id.
9085 * @param state State of SIM (power down, power up, pass through)
9086 * @param callback callback to trigger after success or failure
9087 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9088 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9089 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9090 *
9091 **/
9092 @Override
9093 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9094 IIntegerConsumer callback) {
9095 enforceModifyPermission();
9096 Phone phone = PhoneFactory.getPhone(slotIndex);
9097
9098 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9099
9100 final long identity = Binder.clearCallingIdentity();
9101 try {
9102 if (phone != null) {
9103 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9104 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009105 }
9106 } finally {
9107 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009108 }
9109 }
Shuo Qiandd210312017-04-12 22:11:33 +00009110
Tyler Gunn65d45c22017-06-05 11:22:26 -07009111 private boolean isUssdApiAllowed(int subId) {
9112 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009113 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009114 if (configManager == null) {
9115 return false;
9116 }
9117 PersistableBundle pb = configManager.getConfigForSubId(subId);
9118 if (pb == null) {
9119 return false;
9120 }
9121 return pb.getBoolean(
9122 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9123 }
9124
Shuo Qiandd210312017-04-12 22:11:33 +00009125 /**
9126 * Check if phone is in emergency callback mode
9127 * @return true if phone is in emergency callback mode
9128 * @param subId sub id
9129 */
goneil9c5f4872017-12-05 14:07:56 -08009130 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009131 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009132 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00009133 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009134
9135 final long identity = Binder.clearCallingIdentity();
9136 try {
9137 if (phone != null) {
9138 return phone.isInEcm();
9139 } else {
9140 return false;
9141 }
9142 } finally {
9143 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009144 }
9145 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009146
9147 /**
9148 * Get the current signal strength information for the given subscription.
9149 * Because this information is not updated when the device is in a low power state
9150 * it should not be relied-upon to be current.
9151 * @param subId Subscription index
9152 * @return the most recent cached signal strength info from the modem
9153 */
9154 @Override
9155 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009156 final long identity = Binder.clearCallingIdentity();
9157 try {
9158 Phone p = getPhone(subId);
9159 if (p == null) {
9160 return null;
9161 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009162
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009163 return p.getSignalStrength();
9164 } finally {
9165 Binder.restoreCallingIdentity(identity);
9166 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009167 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009168
Pengquan Meng77b7f132018-08-22 14:49:57 -07009169 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009170 * Get the current modem radio state for the given slot.
9171 * @param slotIndex slot index.
9172 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009173 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009174 * @return the current radio power state from the modem
9175 */
9176 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009177 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009178 Phone phone = PhoneFactory.getPhone(slotIndex);
9179 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009180 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9181 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009182 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9183 }
9184
9185 final long identity = Binder.clearCallingIdentity();
9186 try {
9187 return phone.getRadioPowerState();
9188 } finally {
9189 Binder.restoreCallingIdentity(identity);
9190 }
9191 }
9192 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9193 }
9194
9195 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009196 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9197 *
9198 * <p>Requires one of the following permissions:
9199 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009200 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009201 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9202 * privileges.
9203 *
9204 * @param subId subscription id
9205 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9206 * {@code false}.
9207 */
9208 @Override
9209 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009210 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009211 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009212 try {
9213 mApp.enforceCallingOrSelfPermission(
9214 android.Manifest.permission.ACCESS_NETWORK_STATE,
9215 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009216 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009217 mApp.enforceCallingOrSelfPermission(
9218 permission.READ_BASIC_PHONE_STATE, functionName);
9219 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009220 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009221 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009222 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009223 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009224
Pengquan Menga1bb6272018-09-06 09:59:22 -07009225 boolean isEnabled = false;
9226 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009227 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009228 Phone phone = getPhone(subId);
9229 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009230 } finally {
9231 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009232 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009233 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009234 }
9235
9236
9237 /**
9238 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9239 *
9240 * <p> Requires permission:
9241 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9242 * privileges.
9243 *
9244 * @param subId subscription id
9245 * @param isEnabled {@code true} means enable, {@code false} means disable.
9246 */
9247 @Override
9248 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009249 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9250 mApp, subId, "setDataRoamingEnabled");
9251
Pengquan Menga1bb6272018-09-06 09:59:22 -07009252 final long identity = Binder.clearCallingIdentity();
9253 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009254 Phone phone = getPhone(subId);
9255 if (phone != null) {
9256 phone.setDataRoamingEnabled(isEnabled);
9257 }
9258 } finally {
9259 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009260 }
9261 }
9262
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009263 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009264 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009265 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009266 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07009267 mApp, subId, "isManualNetworkSelectionAllowed");
9268
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009269 boolean isAllowed = true;
9270 final long identity = Binder.clearCallingIdentity();
9271 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009272 Phone phone = getPhone(subId);
9273 if (phone != null) {
9274 isAllowed = phone.isCspPlmnEnabled();
9275 }
9276 } finally {
9277 Binder.restoreCallingIdentity(identity);
9278 }
9279 return isAllowed;
9280 }
9281
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009282 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9283 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009284 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009285 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009286 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009287 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9288 if (phone == null) {
9289 return false;
9290 }
9291 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9292 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9293 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009294 }
9295
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009296 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009297 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009298 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009299 mApp.getSystemService(AppOpsManager.class)
9300 .checkPackage(Binder.getCallingUid(), callingPackage);
9301
Jordan Liu1e142fc2019-04-22 15:10:43 -07009302 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009303 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009304 try {
9305 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009306 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009307 } catch (SecurityException e) {
9308 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9309 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009310 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08009311 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009312 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009313 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009314 }
sandeepjsb6c87872021-09-27 15:34:44 +00009315 // checking compatibility, if calling app's target SDK is T and beyond.
9316 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9317 Binder.getCallingUid())) {
9318 isIccIdAccessRestricted = true;
9319 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009320 final long identity = Binder.clearCallingIdentity();
9321 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009322 UiccController uiccController = UiccController.getInstance();
9323 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009324 if (hasReadPermission) {
9325 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009326 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009327
9328 // Remove private info if the caller doesn't have access
9329 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9330 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009331 //setting the value after compatibility check
9332 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009333 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9334 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009335 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009336 if (card == null) {
9337 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009338 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009339 continue;
9340 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009341 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9342 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009343 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009344 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009345 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009346 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9347 for (UiccPortInfo portInfo : portInfos) {
9348 UiccPort port = uiccController.getUiccPortForSlot(
9349 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9350 if (port == null) {
9351 // assume no access if port is null
9352 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9353 continue;
9354 }
9355 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9356 uiccPortInfos.add(portInfo);
9357 } else {
9358 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9359 }
9360 }
9361 filteredInfos.add(new UiccCardInfo(
9362 cardInfo.isEuicc(),
9363 cardInfo.getCardId(),
9364 null,
9365 cardInfo.getPhysicalSlotIndex(),
9366 cardInfo.isRemovable(),
9367 cardInfo.isMultipleEnabledProfilesSupported(),
9368 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009369 }
9370 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009371 } finally {
9372 Binder.restoreCallingIdentity(identity);
9373 }
9374 }
9375
sandeepjsb6c87872021-09-27 15:34:44 +00009376 /**
9377 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9378 * generally private and require carrier privileges to view.
9379 *
9380 * @hide
9381 */
9382 @NonNull
9383 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9384 List<UiccPortInfo> portinfo = new ArrayList<>();
9385 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9386 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9387 }
9388 return new UiccCardInfo(
9389 cardInfo.isEuicc(),
9390 cardInfo.getCardId(),
9391 null,
9392 cardInfo.getPhysicalSlotIndex(),
9393 cardInfo.isRemovable(),
9394 cardInfo.isMultipleEnabledProfilesSupported(),
9395 portinfo
9396 );
9397 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009398
sandeepjsb6c87872021-09-27 15:34:44 +00009399 /**
9400 * @hide
9401 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9402 * These values are generally private and require carrier privileges to view.
9403 */
9404 @NonNull
9405 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9406 return new UiccPortInfo(
9407 UiccPortInfo.ICCID_REDACTED,
9408 portInfo.getPortIndex(),
9409 portInfo.getLogicalSlotIndex(),
9410 portInfo.isActive()
9411 );
9412 }
9413 @Override
9414 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009415 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009416 mApp.getSystemService(AppOpsManager.class)
9417 .checkPackage(Binder.getCallingUid(), callingPackage);
9418
sandeepjsb6c87872021-09-27 15:34:44 +00009419 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009420
Aman Guptaf3c90b32022-03-17 04:54:16 +00009421 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9422 // we are reading iccId which is PII data.
9423 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009424
9425 // checking compatibility, if calling app's target SDK is T and beyond.
9426 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9427 Binder.getCallingUid())) {
9428 isLogicalSlotAccessRestricted = true;
9429 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009430 final long identity = Binder.clearCallingIdentity();
9431 try {
9432 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009433 if (slots == null || slots.length == 0) {
9434 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009435 return null;
9436 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009437 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9438 for (int i = 0; i < slots.length; i++) {
9439 UiccSlot slot = slots[i];
9440 if (slot == null) {
9441 continue;
9442 }
9443
Jordan Liu7be7e652019-05-06 18:55:02 +00009444 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009445 UiccCard card = slot.getUiccCard();
9446 if (card != null) {
9447 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009448 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009449 cardId = slot.getEid();
9450 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009451 // If cardId is null, use iccId of default port as cardId.
9452 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009453 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009454 }
9455
Jordan Liu857451f2019-05-09 16:35:35 -07009456 if (cardId != null) {
9457 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9458 // if cardId is an EID, it's all digits so this is fine
9459 cardId = IccUtils.stripTrailingFs(cardId);
9460 }
9461
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009462 int cardState = 0;
9463 switch (slot.getCardState()) {
9464 case CARDSTATE_ABSENT:
9465 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9466 break;
9467 case CARDSTATE_PRESENT:
9468 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9469 break;
9470 case CARDSTATE_ERROR:
9471 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9472 break;
9473 case CARDSTATE_RESTRICTED:
9474 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9475 break;
9476 default:
9477 break;
9478
9479 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009480 List<UiccPortInfo> portInfos = new ArrayList<>();
9481 int[] portIndexes = slot.getPortList();
9482 for (int portIdx : portIndexes) {
9483 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009484 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009485 portInfos.add(new UiccPortInfo(iccId, portIdx,
9486 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009487 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009488 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009489 slot.isEuicc(),
9490 cardId,
9491 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009492 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009493 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009494 //setting the value after compatibility check
9495 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009496 }
9497 return infos;
9498 } finally {
9499 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009500 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009501 }
9502
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009503 /* Returns null if doesn't have read permission or carrier privilege access. */
9504 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9505 boolean hasReadPermission) {
9506 String iccId = slot.getIccId(portIndex);
9507 if (hasReadPermission) { // if has read permission
9508 return iccId;
9509 } else {
9510 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9511 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9512 // if no read permission, checking carrier privilege access
9513 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9514 return iccId;
9515 }
9516 }
9517 }
9518 // No read permission or carrier privilege access.
9519 return UiccPortInfo.ICCID_REDACTED;
9520 }
9521
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009522 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009523 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009524 public boolean switchSlots(int[] physicalSlots) {
9525 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009526
9527 final long identity = Binder.clearCallingIdentity();
9528 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009529 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9530 for (int i = 0; i < physicalSlots.length; i++) {
9531 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9532 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9533 physicalSlots[i], i));
9534 }
9535 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009536 } finally {
9537 Binder.restoreCallingIdentity(identity);
9538 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009539 }
Jack Yu4c988042018-02-27 15:30:01 -08009540
9541 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009542 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9543 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9544 enforceModifyPermission();
9545
9546 final long identity = Binder.clearCallingIdentity();
9547 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009548 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009549 } finally {
9550 Binder.restoreCallingIdentity(identity);
9551 }
9552 }
9553
9554 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009555 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009556 final long identity = Binder.clearCallingIdentity();
9557 try {
9558 return UiccController.getInstance().getCardIdForDefaultEuicc();
9559 } finally {
9560 Binder.restoreCallingIdentity(identity);
9561 }
9562 }
9563
Pengquan Meng85728fb2018-03-12 16:31:21 -07009564 /**
goneil47ffb6e2018-04-06 15:40:58 -07009565 * A test API to reload the UICC profile.
9566 *
9567 * <p>Requires that the calling app has permission
9568 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9569 * @hide
9570 */
9571 @Override
9572 public void refreshUiccProfile(int subId) {
9573 enforceModifyPermission();
9574
9575 final long identity = Binder.clearCallingIdentity();
9576 try {
9577 Phone phone = getPhone(subId);
9578 if (phone == null) {
9579 return;
9580 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009581 UiccPort uiccPort = phone.getUiccPort();
9582 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009583 return;
9584 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009585 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009586 if (uiccProfile == null) {
9587 return;
9588 }
9589 uiccProfile.refresh();
9590 } finally {
9591 Binder.restoreCallingIdentity(identity);
9592 }
9593 }
9594
9595 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009596 * Returns false if the mobile data is disabled by default, otherwise return true.
9597 */
9598 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009599 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009600 }
9601
9602 /**
9603 * Returns true if the data roaming is enabled by default, i.e the system property
9604 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9605 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9606 */
9607 private boolean getDefaultDataRoamingEnabled(int subId) {
9608 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009609 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009610 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009611 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9612 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9613 return isDataRoamingEnabled;
9614 }
9615
9616 /**
9617 * Returns the default network type for the given {@code subId}, if the default network type is
9618 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9619 */
9620 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009621 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -08009622 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +09009623 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9624 return list.get(phoneId);
9625 }
9626 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009627 }
fionaxua13278b2018-03-21 00:08:13 -07009628
9629 @Override
9630 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009631 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009632 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009633
9634 final long identity = Binder.clearCallingIdentity();
9635 try {
9636 final Phone phone = getPhone(subId);
9637 if (phone == null) {
9638 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9639 return;
9640 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009641 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9642 if (cpt != null) {
9643 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9644 }
9645 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009646 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9647 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009648 if (carrierPrivilegeRules == null) {
9649 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9650 } else {
9651 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9652 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009653 } finally {
9654 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009655 }
fionaxua13278b2018-03-21 00:08:13 -07009656 }
9657
9658 @Override
9659 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009660 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009661
9662 final long identity = Binder.clearCallingIdentity();
9663 try {
9664 final Phone phone = getPhone(subId);
9665 if (phone == null) {
9666 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9667 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9668 }
9669 return phone.getCarrierIdListVersion();
9670 } finally {
9671 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009672 }
fionaxua13278b2018-03-21 00:08:13 -07009673 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009674
9675 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009676 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9677 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009678 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009679 mApp, subId, callingPackage, callingFeatureId,
9680 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009681 return -1;
9682 }
9683
9684 final long identity = Binder.clearCallingIdentity();
9685 try {
9686 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9687 } finally {
9688 Binder.restoreCallingIdentity(identity);
9689 }
9690 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009691
9692 @Override
9693 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009694 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009695 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009696 mApp, subId, "getCdmaRoamingMode");
9697
9698 final long identity = Binder.clearCallingIdentity();
9699 try {
9700 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9701 } finally {
9702 Binder.restoreCallingIdentity(identity);
9703 }
9704 }
9705
9706 @Override
9707 public boolean setCdmaRoamingMode(int subId, int mode) {
9708 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9709 mApp, subId, "setCdmaRoamingMode");
9710
9711 final long identity = Binder.clearCallingIdentity();
9712 try {
9713 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9714 } finally {
9715 Binder.restoreCallingIdentity(identity);
9716 }
9717 }
9718
9719 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009720 public int getCdmaSubscriptionMode(int subId) {
9721 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009722 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009723 mApp, subId, "getCdmaSubscriptionMode");
9724
9725 final long identity = Binder.clearCallingIdentity();
9726 try {
9727 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9728 } finally {
9729 Binder.restoreCallingIdentity(identity);
9730 }
9731 }
9732
9733 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009734 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9735 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9736 mApp, subId, "setCdmaSubscriptionMode");
9737
9738 final long identity = Binder.clearCallingIdentity();
9739 try {
9740 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9741 } finally {
9742 Binder.restoreCallingIdentity(identity);
9743 }
9744 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009745
sqianc5eccab2018-10-19 18:46:41 -07009746 @Override
sqian8c685422019-02-22 15:55:18 -08009747 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009748 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009749 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009750 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9751 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009752 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9753 }
9754 final long identity = Binder.clearCallingIdentity();
9755 try {
sqian854d44b2018-12-12 16:48:18 -08009756 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9757 for (Phone phone: PhoneFactory.getPhones()) {
9758 if (phone.getEmergencyNumberTracker() != null
9759 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9760 emergencyNumberListInternal.put(
9761 phone.getSubId(),
9762 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9763 }
sqian11b7a0e2018-12-05 18:48:28 -08009764 }
sqian854d44b2018-12-12 16:48:18 -08009765 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009766 } finally {
9767 Binder.restoreCallingIdentity(identity);
9768 }
sqianc5eccab2018-10-19 18:46:41 -07009769 }
9770
9771 @Override
sqian8c685422019-02-22 15:55:18 -08009772 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009773 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009774 if (!exactMatch) {
9775 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009776 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009777 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009778 }
9779 final long identity = Binder.clearCallingIdentity();
9780 try {
sqian854d44b2018-12-12 16:48:18 -08009781 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009782 //Note: we ignore passed in param exactMatch. We can remove it once
9783 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009784 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009785 && phone.getEmergencyNumberTracker()
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009786 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009787 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009788 }
sqian11b7a0e2018-12-05 18:48:28 -08009789 }
9790 return false;
9791 } finally {
9792 Binder.restoreCallingIdentity(identity);
9793 }
9794 }
9795
sqianf4ca7ed2019-01-15 18:32:07 -08009796 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009797 * Start emergency callback mode for GsmCdmaPhone for testing.
9798 */
9799 @Override
9800 public void startEmergencyCallbackMode() {
9801 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9802 "startEmergencyCallbackMode");
9803 enforceModifyPermission();
9804 final long identity = Binder.clearCallingIdentity();
9805 try {
9806 for (Phone phone : PhoneFactory.getPhones()) {
9807 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9808 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9809 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9810 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9811 gsmCdmaPhone.obtainMessage(
9812 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9813 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9814 }
9815 }
9816 } finally {
9817 Binder.restoreCallingIdentity(identity);
9818 }
9819 }
9820
9821 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009822 * Update emergency number list for test mode.
9823 */
9824 @Override
9825 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9826 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9827 "updateEmergencyNumberListTestMode");
9828
9829 final long identity = Binder.clearCallingIdentity();
9830 try {
9831 for (Phone phone: PhoneFactory.getPhones()) {
9832 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9833 if (tracker != null) {
9834 tracker.executeEmergencyNumberTestModeCommand(action, num);
9835 }
9836 }
9837 } finally {
9838 Binder.restoreCallingIdentity(identity);
9839 }
9840 }
9841
9842 /**
9843 * Get the full emergency number list for test mode.
9844 */
9845 @Override
9846 public List<String> getEmergencyNumberListTestMode() {
9847 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9848 "getEmergencyNumberListTestMode");
9849
9850 final long identity = Binder.clearCallingIdentity();
9851 try {
9852 Set<String> emergencyNumbers = new HashSet<>();
9853 for (Phone phone: PhoneFactory.getPhones()) {
9854 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9855 if (tracker != null) {
9856 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9857 emergencyNumbers.add(num.getNumber());
9858 }
9859 }
9860 }
9861 return new ArrayList<>(emergencyNumbers);
9862 } finally {
9863 Binder.restoreCallingIdentity(identity);
9864 }
9865 }
9866
chen xud6b45bd2018-10-30 22:27:10 -07009867 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009868 public int getEmergencyNumberDbVersion(int subId) {
9869 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9870
9871 final long identity = Binder.clearCallingIdentity();
9872 try {
9873 final Phone phone = getPhone(subId);
9874 if (phone == null) {
9875 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9876 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9877 }
9878 return phone.getEmergencyNumberDbVersion();
9879 } finally {
9880 Binder.restoreCallingIdentity(identity);
9881 }
9882 }
9883
9884 @Override
9885 public void notifyOtaEmergencyNumberDbInstalled() {
9886 enforceModifyPermission();
9887
9888 final long identity = Binder.clearCallingIdentity();
9889 try {
9890 for (Phone phone: PhoneFactory.getPhones()) {
9891 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9892 if (tracker != null) {
9893 tracker.updateOtaEmergencyNumberDatabase();
9894 }
9895 }
9896 } finally {
9897 Binder.restoreCallingIdentity(identity);
9898 }
9899 }
9900
9901 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009902 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009903 enforceActiveEmergencySessionPermission();
9904
9905 final long identity = Binder.clearCallingIdentity();
9906 try {
9907 for (Phone phone: PhoneFactory.getPhones()) {
9908 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9909 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009910 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9911 }
9912 }
9913 } finally {
9914 Binder.restoreCallingIdentity(identity);
9915 }
9916 }
9917
9918 @Override
9919 public void resetOtaEmergencyNumberDbFilePath() {
9920 enforceActiveEmergencySessionPermission();
9921
9922 final long identity = Binder.clearCallingIdentity();
9923 try {
9924 for (Phone phone: PhoneFactory.getPhones()) {
9925 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9926 if (tracker != null) {
9927 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009928 }
9929 }
9930 } finally {
9931 Binder.restoreCallingIdentity(identity);
9932 }
9933 }
9934
9935 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009936 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9937 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9938 Phone phone = getPhone(subId);
9939 if (phone == null) {
9940 return null;
9941 }
9942 final long identity = Binder.clearCallingIdentity();
9943 try {
9944 UiccProfile profile = UiccController.getInstance()
9945 .getUiccProfileForPhone(phone.getPhoneId());
9946 if (profile != null) {
9947 return profile.getCertsFromCarrierPrivilegeAccessRules();
9948 }
9949 } finally {
9950 Binder.restoreCallingIdentity(identity);
9951 }
9952 return null;
9953 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009954
9955 /**
9956 * Enable or disable a modem stack.
9957 */
9958 @Override
9959 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9960 enforceModifyPermission();
9961
9962 final long identity = Binder.clearCallingIdentity();
9963 try {
9964 Phone phone = PhoneFactory.getPhone(slotIndex);
9965 if (phone == null) {
9966 return false;
9967 } else {
9968 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9969 }
9970 } finally {
9971 Binder.restoreCallingIdentity(identity);
9972 }
9973 }
Michelecea4cf22018-12-21 15:00:11 -08009974
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009975 /**
9976 * Whether a modem stack is enabled or not.
9977 */
9978 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009979 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9980 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009981 Phone phone = PhoneFactory.getPhone(slotIndex);
9982 if (phone == null) return false;
9983
9984 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009985 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9986 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009987 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9988 }
9989
9990 final long identity = Binder.clearCallingIdentity();
9991 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009992 try {
9993 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9994 } catch (NoSuchElementException ex) {
9995 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9996 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009997 } finally {
9998 Binder.restoreCallingIdentity(identity);
9999 }
10000 }
10001
Michelecea4cf22018-12-21 15:00:11 -080010002 @Override
Michele0ea7d782019-03-19 14:58:42 -070010003 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010004 enforceModifyPermission();
10005
10006 final long identity = Binder.clearCallingIdentity();
10007 try {
10008 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010009 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010010 .commit();
10011 } finally {
10012 Binder.restoreCallingIdentity(identity);
10013 }
10014 }
10015
10016 @Override
Michele0ea7d782019-03-19 14:58:42 -070010017 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010018 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010019 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010020 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10021 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010022 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010023 }
Michelecea4cf22018-12-21 15:00:11 -080010024
10025 final long identity = Binder.clearCallingIdentity();
10026 try {
Michele0ea7d782019-03-19 14:58:42 -070010027 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010028 } finally {
10029 Binder.restoreCallingIdentity(identity);
10030 }
10031 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010032
Michele0ea7d782019-03-19 14:58:42 -070010033 @TelephonyManager.IsMultiSimSupportedResult
10034 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010035 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10036 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10037 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010038 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10039 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010040 }
10041 // Check if the hardware supports multisim functionality. If usage of multisim is not
10042 // supported by the modem, indicate that it is restricted.
10043 PhoneCapability staticCapability =
10044 mPhoneConfigurationManager.getStaticPhoneCapability();
10045 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010046 loge("isMultiSimSupportedInternal: no static configuration available");
10047 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010048 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010049 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010050 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10051 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010052 }
10053 // Check if support of multiple SIMs is restricted by carrier
10054 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010055 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010056 }
10057
Michele0ea7d782019-03-19 14:58:42 -070010058 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010059 }
10060
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010061 /**
10062 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010063 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10064 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10065 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010066 * @param numOfSims number of active sims we want to switch to
10067 */
10068 @Override
10069 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010070 if (numOfSims == 1) {
10071 enforceModifyPermission();
10072 } else {
10073 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10074 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10075 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010076 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010077
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010078 try {
Michele30b57b22019-03-01 12:01:14 -080010079 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010080 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010081 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10082 return;
10083 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010084 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10085 } finally {
10086 Binder.restoreCallingIdentity(identity);
10087 }
10088 }
10089
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010090 @Override
10091 public boolean isApplicationOnUicc(int subId, int appType) {
10092 enforceReadPrivilegedPermission("isApplicationOnUicc");
10093 Phone phone = getPhone(subId);
10094 if (phone == null) {
10095 return false;
10096 }
10097 final long identity = Binder.clearCallingIdentity();
10098 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010099 UiccPort uiccPort = phone.getUiccPort();
10100 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010101 return false;
10102 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010103 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010104 if (uiccProfile == null) {
10105 return false;
10106 }
10107 if (TelephonyManager.APPTYPE_SIM <= appType
10108 && appType <= TelephonyManager.APPTYPE_ISIM) {
10109 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10110 }
10111 return false;
10112 } finally {
10113 Binder.restoreCallingIdentity(identity);
10114 }
10115 }
10116
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010117 /**
chen xub4baa772019-04-03 10:23:41 -070010118 * Get whether making changes to modem configurations will trigger reboot.
10119 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010120 */
10121 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010122 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10123 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010124 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010125 mApp, subId, callingPackage, callingFeatureId,
10126 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010127 return false;
10128 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010129 final long identity = Binder.clearCallingIdentity();
10130 try {
10131 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10132 } finally {
10133 Binder.restoreCallingIdentity(identity);
10134 }
10135 }
10136
Nathan Harold29f5f052019-02-15 13:41:57 -080010137 private void updateModemStateMetrics() {
10138 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10139 // TODO: check the state for each modem if the api is ready.
10140 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10141 }
10142
Pengquan Meng3889a572019-01-23 11:16:29 -080010143 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010144 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010145 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010146 // Verify that the callingPackage belongs to the calling UID
10147 mApp.getSystemService(AppOpsManager.class)
10148 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -080010149 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010150 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010151 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010152 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10153 if (slotInfos != null) {
10154 for (int i = 0; i < slotInfos.length; i++) {
10155 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10156 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10157 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10158 portInfo.getLogicalSlotIndex()));
10159 }
10160 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010161 }
10162 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010163 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010164 } finally {
10165 Binder.restoreCallingIdentity(identity);
10166 }
10167 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010168
10169 /**
10170 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010171 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010172 */
jimsunf9ec1622022-09-13 21:18:43 +080010173 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010174 @Override
10175 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010176 return getHalVersion(HAL_SERVICE_RADIO);
10177 }
10178
10179 /**
10180 * Get the HAL Version of a specific service
10181 */
10182 @Override
10183 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010184 Phone phone = getDefaultPhone();
10185 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010186 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010187 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10188 return hv.major * 100 + hv.minor;
10189 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010190
10191 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010192 * Get the current calling package name.
10193 * @return the current calling package name
10194 */
10195 @Override
10196 public String getCurrentPackageName() {
10197 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
10198 }
10199
10200 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010201 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10202 * corresponding network requests on a subId.
10203 *
10204 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010205 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010206 * 2) APN is un-metered for this subscription, or
10207 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010208 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010209 *
10210 * @return whether data is allowed for a apn type.
10211 *
10212 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010213 */
10214 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010215 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010216 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10217 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010218
10219 // Now that all security checks passes, perform the operation as ourselves.
10220 final long identity = Binder.clearCallingIdentity();
10221 try {
10222 Phone phone = getPhone(subId);
10223 if (phone == null) return false;
10224
Jack Yu27422a52022-03-21 10:38:05 -070010225 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010226 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010227 isMetered = phone.getDataNetworkController().getDataConfigManager()
10228 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10229 phone.getServiceState().getDataRoaming());
10230 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010231 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010232 } finally {
10233 Binder.restoreCallingIdentity(identity);
10234 }
10235 }
10236
10237 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010238 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010239 enforceReadPrivilegedPermission("isApnMetered");
10240
10241 // Now that all security checks passes, perform the operation as ourselves.
10242 final long identity = Binder.clearCallingIdentity();
10243 try {
10244 Phone phone = getPhone(subId);
10245 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010246 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10247 DataUtils.apnTypeToNetworkCapability(apnType),
10248 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010249 } finally {
10250 Binder.restoreCallingIdentity(identity);
10251 }
10252 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010253
10254 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010255 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10256 int subscriptionId, IBooleanConsumer resultCallback) {
10257 enforceModifyPermission();
10258 long token = Binder.clearCallingIdentity();
10259 try {
10260 Phone phone = getPhone(subscriptionId);
10261 if (phone == null) {
10262 try {
10263 if (resultCallback != null) {
10264 resultCallback.accept(false);
10265 }
10266 } catch (RemoteException e) {
10267 // ignore
10268 }
10269 return;
10270 }
10271 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10272 Pair.create(specifiers, (x) -> {
10273 try {
10274 if (resultCallback != null) {
10275 resultCallback.accept(x);
10276 }
10277 } catch (RemoteException e) {
10278 // ignore
10279 }
10280 });
10281 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10282 } finally {
10283 Binder.restoreCallingIdentity(token);
10284 }
10285 }
10286
10287 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010288 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10289 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010290 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010291 mApp, subId, "getSystemSelectionChannels");
10292 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10293 final long identity = Binder.clearCallingIdentity();
10294 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010295 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10296 if (result instanceof IllegalStateException) {
10297 throw (IllegalStateException) result;
10298 }
10299 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010300 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10301 return specifiers;
10302 } finally {
10303 Binder.restoreCallingIdentity(identity);
10304 }
10305 }
10306
10307 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010308 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010309 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010310 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010311 }
10312
10313 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010314 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10315 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010316 if (callingPackage == null) {
10317 callingPackage = getCurrentPackageName();
10318 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010319 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10320 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010321 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10322 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010323 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10324 }
10325 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10326 Intent intent = new Intent();
10327 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10328 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10329 // Bring up choose default SMS subscription dialog right now
10330 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10331 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10332 mApp.startActivity(intent);
10333 }
chen xud5ca2d52019-05-28 15:20:57 -070010334
10335 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010336 public void showSwitchToManagedProfileDialog() {
10337 enforceModifyPermission();
10338
10339 Intent intent = new Intent();
10340 intent.setClass(mApp, ErrorDialogActivity.class);
10341 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10342 mApp.startActivity(intent);
10343 }
10344
10345 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010346 public String getMmsUAProfUrl(int subId) {
10347 //TODO investigate if this API should require proper permission check in R b/133791609
10348 final long identity = Binder.clearCallingIdentity();
10349 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010350 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10351 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10352 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10353 return carrierUAProfUrl;
10354 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010355 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10356 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010357 } finally {
10358 Binder.restoreCallingIdentity(identity);
10359 }
10360 }
10361
10362 @Override
10363 public String getMmsUserAgent(int subId) {
10364 //TODO investigate if this API should require proper permission check in R b/133791609
10365 final long identity = Binder.clearCallingIdentity();
10366 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010367 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10368 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10369 if (!TextUtils.isEmpty(carrierUserAgent)) {
10370 return carrierUserAgent;
10371 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010372 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10373 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010374 } finally {
10375 Binder.restoreCallingIdentity(identity);
10376 }
10377 }
Jack Yub07d4972019-05-28 16:12:25 -070010378
10379 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010380 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10381 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010382
Jack Yub07d4972019-05-28 16:12:25 -070010383 final long identity = Binder.clearCallingIdentity();
10384 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010385 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010386 if (phone == null) return false;
10387
Ling Maf188d502022-09-16 15:22:36 -070010388 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010389 } finally {
10390 Binder.restoreCallingIdentity(identity);
10391 }
10392 }
10393
10394 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010395 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010396 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010397 enforceModifyPermission();
10398
changbettyd5c246e2019-12-24 15:40:37 +080010399 final long identity = Binder.clearCallingIdentity();
10400 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010401 Phone phone = getPhone(subscriptionId);
10402 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010403
Ling Maf188d502022-09-16 15:22:36 -070010404 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010405 } finally {
10406 Binder.restoreCallingIdentity(identity);
10407 }
10408 }
10409
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010410 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010411 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010412 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10413 * otherwise.
10414 */
10415 @Override
10416 public void setCepEnabled(boolean isCepEnabled) {
10417 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10418
10419 final long identity = Binder.clearCallingIdentity();
10420 try {
10421 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10422 for (Phone phone : PhoneFactory.getPhones()) {
10423 Phone defaultPhone = phone.getImsPhone();
10424 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10425 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10426 ImsPhoneCallTracker imsPhoneCallTracker =
10427 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10428 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10429 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10430 + imsPhone.getMsisdn());
10431 }
10432 }
10433 } finally {
10434 Binder.restoreCallingIdentity(identity);
10435 }
10436 }
allenwtsu46dcc572020-01-08 18:24:03 +080010437
10438 /**
10439 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10440 *
10441 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10442 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10443 * before being read.
10444 */
10445 @Override
10446 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10447 isCompressed) {
10448 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10449 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010450 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10451 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10452 }
10453 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010454 // ProvisioningManager can not handle ServiceSpecificException.
10455 // Throw the IllegalStateException and annotate ProvisioningManager.
10456 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010457 }
10458
10459 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010460 try {
Hui Wang761a6682020-10-31 05:12:53 +000010461 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10462 } finally {
10463 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010464 }
10465 }
zoey chene02881a2019-12-30 16:11:23 +080010466
10467 @Override
10468 public boolean isIccLockEnabled(int subId) {
10469 enforceReadPrivilegedPermission("isIccLockEnabled");
10470
10471 // Now that all security checks passes, perform the operation as ourselves.
10472 final long identity = Binder.clearCallingIdentity();
10473 try {
10474 Phone phone = getPhone(subId);
10475 if (phone != null && phone.getIccCard() != null) {
10476 return phone.getIccCard().getIccLockEnabled();
10477 } else {
10478 return false;
10479 }
10480 } finally {
10481 Binder.restoreCallingIdentity(identity);
10482 }
10483 }
10484
10485 /**
10486 * Set the ICC pin lock enabled or disabled.
10487 *
10488 * @return an integer representing the status of IccLock enabled or disabled in the following
10489 * three cases:
10490 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10491 * successfully.
10492 * - Positive number and zero for remaining password attempts.
10493 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10494 *
10495 */
10496 @Override
10497 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10498 enforceModifyPermission();
10499
10500 Phone phone = getPhone(subId);
10501 if (phone == null) {
10502 return 0;
10503 }
10504 // Now that all security checks passes, perform the operation as ourselves.
10505 final long identity = Binder.clearCallingIdentity();
10506 try {
10507 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10508 new Pair<Boolean, String>(enabled, password), phone, null);
10509 return attemptsRemaining;
10510
10511 } catch (Exception e) {
10512 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10513 } finally {
10514 Binder.restoreCallingIdentity(identity);
10515 }
10516 return 0;
10517 }
10518
10519 /**
10520 * Change the ICC password used in ICC pin lock.
10521 *
10522 * @return an integer representing the status of IccLock changed in the following three cases:
10523 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10524 * - Positive number and zero for remaining password attempts.
10525 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10526 *
10527 */
10528 @Override
10529 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10530 enforceModifyPermission();
10531
10532 Phone phone = getPhone(subId);
10533 if (phone == null) {
10534 return 0;
10535 }
10536 // Now that all security checks passes, perform the operation as ourselves.
10537 final long identity = Binder.clearCallingIdentity();
10538 try {
10539 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10540 new Pair<String, String>(oldPassword, newPassword), phone, null);
10541 return attemptsRemaining;
10542
10543 } catch (Exception e) {
10544 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10545 } finally {
10546 Binder.restoreCallingIdentity(identity);
10547 }
10548 return 0;
10549 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010550
10551 /**
10552 * Request for receiving user activity notification
10553 */
10554 @Override
10555 public void requestUserActivityNotification() {
10556 if (!mNotifyUserActivity.get()
10557 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10558 mNotifyUserActivity.set(true);
10559 }
10560 }
10561
10562 /**
10563 * Called when userActivity is signalled in the power manager.
10564 * This is safe to call from any thread, with any window manager locks held or not.
10565 */
10566 @Override
10567 public void userActivity() {
10568 // ***************************************
10569 // * Inherited from PhoneWindowManager *
10570 // ***************************************
10571 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10572 // WITH ITS LOCKS HELD.
10573 //
10574 // This code must be VERY careful about the locks
10575 // it acquires.
10576 // In fact, the current code acquires way too many,
10577 // and probably has lurking deadlocks.
10578
10579 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10580 throw new SecurityException("Only the OS may call notifyUserActivity()");
10581 }
10582
10583 if (mNotifyUserActivity.getAndSet(false)) {
10584 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10585 USER_ACTIVITY_NOTIFICATION_DELAY);
10586 }
10587 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010588
10589 @Override
10590 public boolean canConnectTo5GInDsdsMode() {
10591 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10592 }
Jack Yud10cdd42020-09-28 20:28:01 -070010593
10594 @Override
10595 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10596 String callingFeatureId) {
10597 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10598 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10599 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10600 }
10601
10602 Phone phone = getPhone(subId);
10603 if (phone == null) {
10604 throw new RuntimeException("phone is not available");
10605 }
10606 // Now that all security checks passes, perform the operation as ourselves.
10607 final long identity = Binder.clearCallingIdentity();
10608 try {
10609 return phone.getEquivalentHomePlmns();
10610 } finally {
10611 Binder.restoreCallingIdentity(identity);
10612 }
10613 }
Daniel Bright59e67312020-11-13 11:49:37 -080010614
10615 @Override
10616 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010617 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10618 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010619 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010620 if (radioInterfaceCapabilities == null) {
10621 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010622 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010623 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010624 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010625
Hui Wang641e81c2020-10-12 12:14:23 -070010626 @Override
10627 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10628 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010629 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10630 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10631 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10632 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10633 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010634 if (DBG) {
10635 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10636 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10637 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10638 }
10639
10640 if (!SubscriptionManager.isValidSubscriptionId(subId)
10641 || appType < TelephonyManager.APPTYPE_UNKNOWN
10642 || appType > TelephonyManager.APPTYPE_ISIM
10643 || nafUrl == null || securityProtocol == null || callback == null) {
10644 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10645 if (callback != null) {
10646 try {
10647 callback.onAuthenticationFailure(
10648 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10649 } catch (RemoteException exception) {
10650 log("Fail to notify onAuthenticationFailure due to " + exception);
10651 }
10652 return;
10653 }
10654 }
10655
10656 final long token = Binder.clearCallingIdentity();
10657 try {
10658 getGbaManager(subId).bootstrapAuthenticationRequest(
10659 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10660 forceBootStrapping, callback));
10661 } finally {
10662 Binder.restoreCallingIdentity(token);
10663 }
10664 }
10665
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010666 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010667 * Attempts to set the radio power state for all phones for thermal reason.
10668 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010669 * requested radio power state will actually be set. See {@link
10670 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10671 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010672 * @param enable {@code true} if trying to turn radio on.
10673 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10674 * false}.
10675 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010676 private boolean setRadioPowerForThermal(boolean enable) {
10677 boolean isPhoneAvailable = false;
10678 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10679 Phone phone = PhoneFactory.getPhone(i);
10680 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010681 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010682 isPhoneAvailable = true;
10683 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010684 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010685
10686 // return true if successfully informed the phone object about the thermal radio power
10687 // request.
10688 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010689 }
10690
10691 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010692 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010693 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10694 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10695 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10696 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10697 throw new IllegalArgumentException("modem does not support data throttling");
10698 }
10699
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010700 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10701 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010702 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010703 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10704 }
10705
Sarah Chinecc78c42022-03-31 21:16:48 -070010706 setDataEnabledForReason(
10707 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010708
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010709 if (isDataThrottlingSupported) {
10710 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010711 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010712 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10713 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10714 } else if (thermalMitigationResult
10715 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010716 log("Modem likely does not support data throttling on secondary carrier. Data " +
10717 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10718 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010719 }
10720 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010721 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010722
10723 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010724 }
10725
Jack Nudelman644b91a2021-03-12 14:09:48 -080010726 private static List<String> getThermalMitigationAllowlist(Context context) {
10727 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10728 for (String pckg : context.getResources()
10729 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10730 sThermalMitigationAllowlistedPackages.add(pckg);
10731 }
10732 }
10733
10734 return sThermalMitigationAllowlistedPackages;
10735 }
10736
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010737 private boolean isAnyPhoneInEmergencyState() {
10738 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10739 if (tm.isInEmergencyCall()) {
10740 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10741 return true;
10742 }
10743 for (Phone phone : PhoneFactory.getPhones()) {
10744 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10745 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10746 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10747 + phone.isInEcm());
10748 return true;
10749 }
10750 }
10751
10752 return false;
10753 }
10754
Jack Nudelman644b91a2021-03-12 14:09:48 -080010755 /**
10756 * Used by shell commands to add an authorized package name for thermal mitigation.
10757 * @param packageName name of package to be allowlisted
10758 * @param context
10759 */
10760 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10761 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10762 sThermalMitigationAllowlistedPackages.add(packageName);
10763 }
10764
10765 /**
10766 * Used by shell commands to remove an authorized package name for thermal mitigation.
10767 * @param packageName name of package to remove from allowlist
10768 * @param context
10769 */
10770 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10771 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10772 sThermalMitigationAllowlistedPackages.remove(packageName);
10773 }
10774
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010775 /**
10776 * Thermal mitigation request to control functionalities at modem.
10777 *
10778 * @param subId the id of the subscription.
10779 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010780 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010781 *
10782 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10783 */
10784 @Override
10785 @ThermalMitigationResult
10786 public int sendThermalMitigationRequest(
10787 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010788 ThermalMitigationRequest thermalMitigationRequest,
10789 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010790 enforceModifyPermission();
10791
Jack Nudelman644b91a2021-03-12 14:09:48 -080010792 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10793 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10794 .contains(callingPackage)) {
10795 throw new SecurityException("Calling package must be configured in the device config. "
10796 + "calling package: " + callingPackage);
10797 }
10798
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010799 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10800 final long identity = Binder.clearCallingIdentity();
10801
10802 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10803 try {
10804 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10805 switch (thermalMitigationAction) {
10806 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10807 thermalMitigationResult =
10808 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010809 thermalMitigationRequest.getDataThrottlingRequest(),
10810 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010811 break;
10812 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10813 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10814 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10815 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10816 }
10817
10818 // Ensure that radio is on. If not able to power on due to phone being
10819 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010820 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010821 thermalMitigationResult =
10822 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10823 break;
10824 }
10825
10826 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010827 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010828 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10829 break;
10830 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10831 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10832 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10833 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10834 }
10835
10836 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10837 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010838 Phone phone = getPhone(subId);
10839 if (phone == null) {
10840 thermalMitigationResult =
10841 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10842 break;
10843 }
10844
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010845 TelephonyConnectionService service =
10846 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010847 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010848 Log.e(LOG_TAG, "An emergency call is pending");
10849 thermalMitigationResult =
10850 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10851 break;
10852 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010853 thermalMitigationResult =
10854 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10855 break;
10856 }
10857 } else {
10858 thermalMitigationResult =
10859 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10860 break;
10861 }
10862
10863 // Turn radio off. If not able to power off due to phone being unavailable,
10864 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010865 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010866 thermalMitigationResult =
10867 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10868 break;
10869 }
10870 thermalMitigationResult =
10871 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10872 break;
10873 default:
10874 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10875 + "not exist. Requested action: " + thermalMitigationAction);
10876 }
10877 } catch (IllegalArgumentException e) {
10878 throw e;
10879 } catch (Exception e) {
10880 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10881 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10882 } finally {
10883 Binder.restoreCallingIdentity(identity);
10884 }
10885
10886 if (DBG) {
10887 log("thermalMitigationRequest returning with thermalMitigationResult: "
10888 + thermalMitigationResult);
10889 }
10890
10891 return thermalMitigationResult;
10892 }
Hui Wang641e81c2020-10-12 12:14:23 -070010893
10894 /**
10895 * Set the GbaService Package Name that Telephony will bind to.
10896 *
10897 * @param subId The sim that the GbaService is associated with.
10898 * @param packageName The name of the package to be replaced with.
10899 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10900 */
10901 @Override
10902 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10903 enforceModifyPermission();
10904
10905 final long identity = Binder.clearCallingIdentity();
10906 try {
10907 return getGbaManager(subId).overrideServicePackage(packageName);
10908 } finally {
10909 Binder.restoreCallingIdentity(identity);
10910 }
10911 }
10912
10913 /**
10914 * Return the package name of the currently bound GbaService.
10915 *
10916 * @param subId The sim that the GbaService is associated with.
10917 * @return the package name of the GbaService configuration, null if GBA is not supported.
10918 */
10919 @Override
10920 public String getBoundGbaService(int subId) {
10921 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10922
10923 final long identity = Binder.clearCallingIdentity();
10924 try {
10925 return getGbaManager(subId).getServicePackage();
10926 } finally {
10927 Binder.restoreCallingIdentity(identity);
10928 }
10929 }
10930
10931 /**
10932 * Set the release time for telephony to unbind GbaService.
10933 *
10934 * @param subId The sim that the GbaService is associated with.
10935 * @param interval The release time to unbind GbaService by millisecond.
10936 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10937 */
10938 @Override
10939 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10940 enforceModifyPermission();
10941
10942 final long identity = Binder.clearCallingIdentity();
10943 try {
10944 return getGbaManager(subId).overrideReleaseTime(interval);
10945 } finally {
10946 Binder.restoreCallingIdentity(identity);
10947 }
10948 }
10949
10950 /**
10951 * Return the release time for telephony to unbind GbaService.
10952 *
10953 * @param subId The sim that the GbaService is associated with.
10954 * @return The release time to unbind GbaService by millisecond.
10955 */
10956 @Override
10957 public int getGbaReleaseTime(int subId) {
10958 enforceReadPrivilegedPermission("getGbaReleaseTime");
10959
10960 final long identity = Binder.clearCallingIdentity();
10961 try {
10962 return getGbaManager(subId).getReleaseTime();
10963 } finally {
10964 Binder.restoreCallingIdentity(identity);
10965 }
10966 }
10967
10968 private GbaManager getGbaManager(int subId) {
10969 GbaManager instance = GbaManager.getInstance(subId);
10970 if (instance == null) {
10971 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10972 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10973 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10974 }
10975 return instance;
10976 }
Hui Wang761a6682020-10-31 05:12:53 +000010977
10978 /**
10979 * indicate whether the device and the carrier can support
10980 * RCS VoLTE single registration.
10981 */
10982 @Override
10983 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010984 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10985 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10986 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10987 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010988
10989 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10990 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10991 }
10992
10993 final long identity = Binder.clearCallingIdentity();
10994 try {
10995 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10996 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010997 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10998 if (isCapable != null) {
10999 return isCapable;
11000 }
Hui Wang761a6682020-10-31 05:12:53 +000011001 }
Hui Wang67af90e2021-06-04 16:57:15 -070011002 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11003 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011004 } finally {
11005 Binder.restoreCallingIdentity(identity);
11006 }
11007 }
11008
11009 /**
11010 * Register RCS provisioning callback.
11011 */
11012 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011013 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011014 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011015 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011016 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011017 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11018 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011019
11020 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11021 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11022 }
11023 if (!isImsAvailableOnDevice()) {
11024 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11025 "IMS not available on device.");
11026 }
11027
11028 final long identity = Binder.clearCallingIdentity();
11029 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011030 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011031 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011032 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11033 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011034 }
Hui Wang761a6682020-10-31 05:12:53 +000011035 } finally {
11036 Binder.restoreCallingIdentity(identity);
11037 }
11038 }
11039
11040 /**
11041 * Unregister RCS provisioning callback.
11042 */
11043 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011044 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011045 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011046 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011047 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011048 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11049 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011050
11051 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11052 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11053 }
11054 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000011055 // operation failed silently
11056 Rlog.w(LOG_TAG, "IMS not available on device.");
11057 return;
Hui Wang761a6682020-10-31 05:12:53 +000011058 }
11059
11060 final long identity = Binder.clearCallingIdentity();
11061 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011062 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011063 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011064 } finally {
11065 Binder.restoreCallingIdentity(identity);
11066 }
11067 }
11068
11069 /**
11070 * trigger RCS reconfiguration.
11071 */
11072 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011073 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11074 "triggerRcsReconfiguration",
11075 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011076
11077 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11078 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11079 }
11080 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000011081 // ProvisioningManager can not handle ServiceSpecificException.
11082 // Throw the IllegalStateException and annotate ProvisioningManager.
11083 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000011084 }
11085
11086 final long identity = Binder.clearCallingIdentity();
11087 try {
11088 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11089 } finally {
11090 Binder.restoreCallingIdentity(identity);
11091 }
11092 }
11093
11094 /**
11095 * Provide the client configuration parameters of the RCS application.
11096 */
11097 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011098 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11099 "setRcsClientConfiguration",
11100 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011101
11102 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11103 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11104 }
11105 if (!isImsAvailableOnDevice()) {
11106 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11107 "IMS not available on device.");
11108 }
11109
11110 final long identity = Binder.clearCallingIdentity();
11111
11112 try {
11113 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11114 if (configBinder == null) {
11115 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011116 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11117 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011118 } else {
11119 configBinder.setRcsClientConfiguration(rcc);
11120 }
joonhunshin3e154242021-09-17 06:33:39 +000011121
11122 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11123 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011124 } catch (RemoteException e) {
11125 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011126 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11127 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011128 } finally {
11129 Binder.restoreCallingIdentity(identity);
11130 }
11131 }
11132
11133 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011134 * Enables or disables the test mode for RCS VoLTE single registration.
11135 */
11136 @Override
11137 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11138 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11139 "setRcsSingleRegistrationTestModeEnabled");
11140
11141 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11142 }
11143
11144 /**
11145 * Gets the test mode for RCS VoLTE single registration.
11146 */
11147 @Override
11148 public boolean getRcsSingleRegistrationTestModeEnabled() {
11149 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11150 "getRcsSingleRegistrationTestModeEnabled");
11151
11152 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11153 }
11154
11155 /**
Hui Wang761a6682020-10-31 05:12:53 +000011156 * Overrides the config of RCS VoLTE single registration enabled for the device.
11157 */
11158 @Override
11159 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11160 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11161 "setDeviceSingleRegistrationEnabledOverride");
11162 enforceModifyPermission();
11163
11164 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11165 : Boolean.parseBoolean(enabledStr);
11166 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011167 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011168 }
11169
11170 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011171 * Sends a device to device communication message. Only usable via shell.
11172 * @param message message to send.
11173 * @param value message value.
11174 */
11175 @Override
11176 public void sendDeviceToDeviceMessage(int message, int value) {
11177 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011178 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011179 enforceModifyPermission();
11180
11181 final long identity = Binder.clearCallingIdentity();
11182 try {
11183 TelephonyConnectionService service =
11184 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11185 if (service == null) {
11186 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11187 return;
11188 }
11189 service.sendTestDeviceToDeviceMessage(message, value);
11190 } finally {
11191 Binder.restoreCallingIdentity(identity);
11192 }
11193 }
11194
Tyler Gunnbabbda02021-02-10 11:05:02 -080011195 /**
11196 * Sets the specified device to device transport active.
11197 * @param transport The transport to set active.
11198 */
11199 @Override
11200 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11201 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11202 "setActiveDeviceToDeviceTransport");
11203 enforceModifyPermission();
11204
11205 final long identity = Binder.clearCallingIdentity();
11206 try {
11207 TelephonyConnectionService service =
11208 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11209 if (service == null) {
11210 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11211 return;
11212 }
11213 service.setActiveDeviceToDeviceTransport(transport);
11214 } finally {
11215 Binder.restoreCallingIdentity(identity);
11216 }
11217 }
Tyler Gunn92479152021-01-20 16:30:10 -080011218
Tyler Gunnd4339262021-05-03 14:46:49 -070011219 @Override
11220 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11221 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11222 "setDeviceToDeviceForceEnabled");
11223
11224 final long identity = Binder.clearCallingIdentity();
11225 try {
11226 Arrays.stream(PhoneFactory.getPhones()).forEach(
11227 p -> {
11228 Phone thePhone = p.getImsPhone();
11229 if (thePhone != null && thePhone instanceof ImsPhone) {
11230 ImsPhone imsPhone = (ImsPhone) thePhone;
11231 CallTracker tracker = imsPhone.getCallTracker();
11232 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11233 ImsPhoneCallTracker imsPhoneCallTracker =
11234 (ImsPhoneCallTracker) tracker;
11235 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11236 }
11237 }
11238 }
11239 );
11240 } finally {
11241 Binder.restoreCallingIdentity(identity);
11242 }
11243 }
11244
Tyler Gunn92479152021-01-20 16:30:10 -080011245 /**
Hui Wang761a6682020-10-31 05:12:53 +000011246 * Gets the config of RCS VoLTE single registration enabled for the device.
11247 */
11248 @Override
11249 public boolean getDeviceSingleRegistrationEnabled() {
11250 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11251 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11252 }
11253
11254 /**
11255 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11256 */
11257 @Override
11258 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11259 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11260 "setCarrierSingleRegistrationEnabledOverride");
11261 enforceModifyPermission();
11262
11263 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11264 : Boolean.parseBoolean(enabledStr);
11265 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11266 subId, enabled);
11267 }
11268
11269 /**
11270 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11271 */
11272 @Override
11273 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11274 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11275 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11276 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011277
11278 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011279 * Overrides the ims feature validation result
11280 */
11281 @Override
11282 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11283 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11284 "setImsFeatureValidationOverride");
11285
11286 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11287 : Boolean.parseBoolean(enabledStr);
11288 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11289 subId, enabled);
11290 }
11291
11292 /**
11293 * Gets the ims feature validation override value
11294 */
11295 @Override
11296 public boolean getImsFeatureValidationOverride(int subId) {
11297 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11298 "getImsFeatureValidationOverride");
11299 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11300 }
11301
11302 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011303 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11304 * their mobile plan.
11305 */
11306 @Override
11307 public String getMobileProvisioningUrl() {
11308 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11309 final long identity = Binder.clearCallingIdentity();
11310 try {
11311 return getDefaultPhone().getMobileProvisioningUrl();
11312 } finally {
11313 Binder.restoreCallingIdentity(identity);
11314 }
11315 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011316
James.cf Linbcdf8b32021-01-14 16:44:13 +080011317 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011318 * Get the EAB contact from the EAB database.
11319 */
11320 @Override
11321 public String getContactFromEab(String contact) {
11322 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11323 enforceModifyPermission();
11324 final long identity = Binder.clearCallingIdentity();
11325 try {
11326 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11327 } finally {
11328 Binder.restoreCallingIdentity(identity);
11329 }
11330 }
11331
11332 /**
Calvin Pana1434322021-07-01 19:27:01 +080011333 * Get the EAB capability from the EAB database.
11334 */
11335 @Override
11336 public String getCapabilityFromEab(String contact) {
11337 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11338 enforceModifyPermission();
11339 final long identity = Binder.clearCallingIdentity();
11340 try {
11341 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11342 } finally {
11343 Binder.restoreCallingIdentity(identity);
11344 }
11345 }
11346
11347 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011348 * Remove the EAB contacts from the EAB database.
11349 */
11350 @Override
11351 public int removeContactFromEab(int subId, String contacts) {
11352 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11353 enforceModifyPermission();
11354 final long identity = Binder.clearCallingIdentity();
11355 try {
11356 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11357 } finally {
11358 Binder.restoreCallingIdentity(identity);
11359 }
11360 }
11361
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011362 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011363 public boolean getDeviceUceEnabled() {
11364 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11365 final long identity = Binder.clearCallingIdentity();
11366 try {
11367 return mApp.getDeviceUceEnabled();
11368 } finally {
11369 Binder.restoreCallingIdentity(identity);
11370 }
11371 }
11372
11373 @Override
11374 public void setDeviceUceEnabled(boolean isEnabled) {
11375 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11376 final long identity = Binder.clearCallingIdentity();
11377 try {
11378 mApp.setDeviceUceEnabled(isEnabled);
11379 } finally {
11380 Binder.restoreCallingIdentity(identity);
11381 }
11382 }
11383
Brad Ebinger14d467f2021-02-12 06:18:28 +000011384 /**
11385 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11386 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11387 */
11388 // Used for SHELL command only right now.
11389 @Override
11390 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11391 List<String> featureTags) {
11392 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11393 "addUceRegistrationOverrideShell");
11394 final long identity = Binder.clearCallingIdentity();
11395 try {
11396 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11397 new ArraySet<>(featureTags));
11398 } catch (ImsException e) {
11399 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11400 } finally {
11401 Binder.restoreCallingIdentity(identity);
11402 }
11403 }
11404
11405 /**
11406 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11407 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11408 */
11409 // Used for SHELL command only right now.
11410 @Override
11411 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11412 List<String> featureTags) {
11413 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11414 "removeUceRegistrationOverrideShell");
11415 final long identity = Binder.clearCallingIdentity();
11416 try {
11417 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11418 new ArraySet<>(featureTags));
11419 } catch (ImsException e) {
11420 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11421 } finally {
11422 Binder.restoreCallingIdentity(identity);
11423 }
11424 }
11425
11426 /**
11427 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11428 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11429 */
11430 // Used for SHELL command only right now.
11431 @Override
11432 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11433 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11434 "clearUceRegistrationOverrideShell");
11435 final long identity = Binder.clearCallingIdentity();
11436 try {
11437 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11438 } catch (ImsException e) {
11439 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11440 } finally {
11441 Binder.restoreCallingIdentity(identity);
11442 }
11443 }
11444
11445 /**
11446 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11447 */
11448 // Used for SHELL command only right now.
11449 @Override
11450 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11451 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11452 "getLatestRcsContactUceCapabilityShell");
11453 final long identity = Binder.clearCallingIdentity();
11454 try {
11455 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11456 } catch (ImsException e) {
11457 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11458 } finally {
11459 Binder.restoreCallingIdentity(identity);
11460 }
11461 }
11462
11463 /**
11464 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11465 * device does not have an active PUBLISH.
11466 */
11467 // Used for SHELL command only right now.
11468 @Override
11469 public String getLastUcePidfXmlShell(int subId) {
11470 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11471 final long identity = Binder.clearCallingIdentity();
11472 try {
11473 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11474 } catch (ImsException e) {
11475 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11476 } finally {
11477 Binder.restoreCallingIdentity(identity);
11478 }
11479 }
11480
James.cf Line8713a42021-04-29 16:04:26 +080011481 /**
11482 * Remove UCE requests cannot be sent to the network status.
11483 */
11484 // Used for SHELL command only right now.
11485 @Override
11486 public boolean removeUceRequestDisallowedStatus(int subId) {
11487 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11488 final long identity = Binder.clearCallingIdentity();
11489 try {
11490 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11491 } catch (ImsException e) {
11492 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11493 } finally {
11494 Binder.restoreCallingIdentity(identity);
11495 }
11496 }
11497
James.cf Lin18bb9002021-05-25 01:37:38 +080011498 /**
11499 * Remove UCE requests cannot be sent to the network status.
11500 */
11501 // Used for SHELL command only.
11502 @Override
11503 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11504 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11505 final long identity = Binder.clearCallingIdentity();
11506 try {
11507 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11508 } catch (ImsException e) {
11509 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11510 } finally {
11511 Binder.restoreCallingIdentity(identity);
11512 }
11513 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011514
James.cf Lin4b784aa2021-01-31 03:25:15 +080011515 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011516 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11517 String callingPackage) {
11518 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11519 mApp, subId, "setSignalStrengthUpdateRequest");
11520
11521 final int callingUid = Binder.getCallingUid();
11522 // Verify that tha callingPackage belongs to the calling UID
11523 mApp.getSystemService(AppOpsManager.class)
11524 .checkPackage(callingUid, callingPackage);
11525
Rambo Wang3607f502021-02-01 21:51:40 -080011526 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011527
11528 final long identity = Binder.clearCallingIdentity();
11529 try {
11530 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11531 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11532
11533 if (result instanceof IllegalStateException) {
11534 throw (IllegalStateException) result;
11535 }
11536 } finally {
11537 Binder.restoreCallingIdentity(identity);
11538 }
11539 }
11540
11541 @Override
11542 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11543 String callingPackage) {
11544 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11545 mApp, subId, "clearSignalStrengthUpdateRequest");
11546
11547 final int callingUid = Binder.getCallingUid();
11548 // Verify that tha callingPackage belongs to the calling UID
11549 mApp.getSystemService(AppOpsManager.class)
11550 .checkPackage(callingUid, callingPackage);
11551
11552 final long identity = Binder.clearCallingIdentity();
11553 try {
11554 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11555 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11556
11557 if (result instanceof IllegalStateException) {
11558 throw (IllegalStateException) result;
11559 }
11560 } finally {
11561 Binder.restoreCallingIdentity(identity);
11562 }
11563 }
11564
Rambo Wang3607f502021-02-01 21:51:40 -080011565 private static void validateSignalStrengthUpdateRequest(Context context,
11566 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011567 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11568 // phone/system process do not have further restriction on request
11569 return;
11570 }
11571
11572 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011573 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011574 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011575 context.enforceCallingOrSelfPermission(
11576 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11577 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011578 }
11579
11580 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000011581 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011582 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011583 || info.isEnabled()) {
11584 throw new IllegalArgumentException(
11585 "Only system can set hide fields in SignalThresholdInfo");
11586 }
11587
11588 // Thresholds length for each RAN need in range. This has been validated in
11589 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11590 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11591 final int[] thresholds = info.getThresholds();
11592 Objects.requireNonNull(thresholds);
11593 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11594 || thresholds.length
11595 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11596 throw new IllegalArgumentException(
11597 "thresholds length is out of range: " + thresholds.length);
11598 }
11599 }
11600 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011601
11602 /**
11603 * Gets the current phone capability.
11604 *
11605 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11606 * @return the PhoneCapability which describes the data connection capability of modem.
11607 * It's used to evaluate possible phone config change, for example from single
11608 * SIM device to multi-SIM device.
11609 */
11610 @Override
11611 public PhoneCapability getPhoneCapability() {
11612 enforceReadPrivilegedPermission("getPhoneCapability");
11613 final long identity = Binder.clearCallingIdentity();
11614 try {
11615 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11616 } finally {
11617 Binder.restoreCallingIdentity(identity);
11618 }
11619 }
Michele Berionne5e411512020-11-13 02:36:59 +000011620
11621 /**
11622 * Prepare TelephonyManager for an unattended reboot. The reboot is
11623 * required to be done shortly after the API is invoked.
11624 */
11625 @Override
11626 @TelephonyManager.PrepareUnattendedRebootResult
11627 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011628 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011629 enforceRebootPermission();
11630
11631 final long identity = Binder.clearCallingIdentity();
11632 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011633 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011634 } finally {
11635 Binder.restoreCallingIdentity(identity);
11636 }
11637 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011638
11639 /**
11640 * Request to get the current slicing configuration including URSP rules and
11641 * NSSAIs (configured, allowed and rejected).
11642 *
11643 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11644 */
11645 @Override
11646 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011647 TelephonyPermissions
11648 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11649 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011650
11651 final long identity = Binder.clearCallingIdentity();
11652 try {
11653 Phone phone = getDefaultPhone();
11654 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11655 } finally {
11656 Binder.restoreCallingIdentity(identity);
11657 }
11658 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011659
11660 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011661 * Check whether the given premium capability is available for purchase from the carrier.
11662 *
11663 * @param capability The premium capability to check.
11664 * @param subId The subId to check the premium capability for.
11665 *
11666 * @return Whether the given premium capability is available to purchase.
11667 */
11668 @Override
11669 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11670 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11671 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11672 log("Premium capability "
11673 + TelephonyManager.convertPremiumCapabilityToString(capability)
11674 + " is not available for purchase due to missing permissions.");
11675 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11676 + "permission READ_BASIC_PHONE_STATE.");
11677 }
11678
11679 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080011680 if (phone == null) {
11681 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
11682 return false;
11683 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070011684 final long identity = Binder.clearCallingIdentity();
11685 try {
Sarah Chin46355ba2022-11-01 23:51:16 -070011686 return SlicePurchaseController.getInstance(phone)
Sarah Chin2ec39f62022-08-31 17:03:26 -070011687 .isPremiumCapabilityAvailableForPurchase(capability);
11688 } finally {
11689 Binder.restoreCallingIdentity(identity);
11690 }
11691 }
11692
11693 /**
11694 * Purchase the given premium capability from the carrier.
11695 *
11696 * @param capability The premium capability to purchase.
11697 * @param callback The result of the purchase request.
11698 * @param subId The subId to purchase the premium capability for.
11699 */
11700 @Override
11701 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11702 log("purchasePremiumCapability: capability="
11703 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11704 + getCurrentPackageName());
11705
11706 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11707 mApp, "purchasePremiumCapability")) {
11708 log("purchasePremiumCapability "
11709 + TelephonyManager.convertPremiumCapabilityToString(capability)
11710 + " failed due to missing permissions.");
11711 throw new SecurityException("purchasePremiumCapability requires permission "
11712 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080011713 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
11714 mApp, "purchasePremiumCapability")) {
11715 log("purchasePremiumCapability "
11716 + TelephonyManager.convertPremiumCapabilityToString(capability)
11717 + " failed due to missing permissions.");
11718 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070011719 }
11720
11721 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080011722 if (phone == null) {
11723 try {
11724 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
11725 callback.accept(result);
11726 loge("purchasePremiumCapability: phone is null, subId=" + subId);
11727 } catch (RemoteException e) {
11728 String logStr = "Purchase premium capability "
11729 + TelephonyManager.convertPremiumCapabilityToString(capability)
11730 + " failed due to RemoteException handling null phone: " + e;
11731 if (DBG) log(logStr);
11732 AnomalyReporter.reportAnomaly(
11733 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11734 }
11735 return;
11736 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011737
11738 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070011739 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011740 callingProcess = mApp.getPackageManager().getApplicationInfo(
11741 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070011742 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011743 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070011744 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011745
11746 boolean isVisible = false;
11747 ActivityManager am = mApp.getSystemService(ActivityManager.class);
11748 if (am != null) {
11749 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
11750 if (processes != null) {
11751 for (ActivityManager.RunningAppProcessInfo process : processes) {
11752 log("purchasePremiumCapability: process " + process.processName
11753 + "has importance " + process.importance);
11754 if (process.processName.equals(callingProcess) && process.importance
11755 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
11756 isVisible = true;
11757 break;
11758 }
11759 }
11760 }
11761 }
11762
11763 if (!isVisible) {
11764 try {
11765 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
11766 callback.accept(result);
11767 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
11768 } catch (RemoteException e) {
11769 String logStr = "Purchase premium capability "
11770 + TelephonyManager.convertPremiumCapabilityToString(capability)
11771 + " failed due to RemoteException handling background application: " + e;
11772 if (DBG) log(logStr);
11773 AnomalyReporter.reportAnomaly(
11774 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11775 }
11776 return;
11777 }
11778
Sarah Chin71b3a852022-09-28 15:54:19 -070011779 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080011780 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011781 }
11782
11783 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011784 * Register an IMS connection state callback
11785 */
11786 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011787 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11788 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011789 if (feature == ImsFeature.FEATURE_MMTEL) {
11790 // ImsMmTelManager
11791 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11792 TelephonyPermissions
11793 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11794 mApp, subId, "registerImsStateCallback");
11795 } else if (feature == ImsFeature.FEATURE_RCS) {
11796 // ImsRcsManager or SipDelegateManager
11797 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11798 Binder.getCallingUid(), "registerImsStateCallback",
11799 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11800 Manifest.permission.READ_PRECISE_PHONE_STATE,
11801 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11802 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11803 }
11804
11805 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11806 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11807 "IMS not available on device.");
11808 }
11809
11810 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11811 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11812 }
11813
11814 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11815 if (controller == null) {
11816 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11817 "IMS not available on device.");
11818 }
11819
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011820 if (callingPackage == null) {
11821 callingPackage = getCurrentPackageName();
11822 }
11823
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011824 final long token = Binder.clearCallingIdentity();
11825 try {
11826 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011827 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011828 } catch (ImsException e) {
11829 throw new ServiceSpecificException(e.getCode());
11830 } finally {
11831 Binder.restoreCallingIdentity(token);
11832 }
11833 }
11834
11835 /**
11836 * Unregister an IMS connection state callback
11837 */
11838 @Override
11839 public void unregisterImsStateCallback(IImsStateCallback cb) {
11840 final long token = Binder.clearCallingIdentity();
11841 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11842 if (controller == null) {
11843 return;
11844 }
11845 try {
11846 controller.unregisterImsStateCallback(cb);
11847 } finally {
11848 Binder.restoreCallingIdentity(token);
11849 }
11850 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011851
11852 /**
11853 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11854 *
11855 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11856 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11857 * SecurityException.
11858 * If there is current registered network this value will be same as the registered cell
11859 * identity. If the device goes out of service the previous cell identity is cached and
11860 * will be returned. If the cache age of the Cell identity is more than 24 hours
11861 * it will be cleared and null will be returned.
11862 *
11863 */
11864 @Override
11865 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11866 String callingFeatureId) {
11867 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11868 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11869 LocationAccessPolicy.checkLocationPermission(mApp,
11870 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11871 .setCallingPackage(callingPackage)
11872 .setCallingFeatureId(callingFeatureId)
11873 .setCallingPid(Binder.getCallingPid())
11874 .setCallingUid(Binder.getCallingUid())
11875 .setMethod("getLastKnownCellIdentity")
11876 .setLogAsInfo(true)
11877 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11878 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11879 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11880 .build());
11881
11882 boolean hasFinePermission =
11883 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11884 if (!hasFinePermission
11885 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11886 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011887 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011888 }
11889
11890 final long identity = Binder.clearCallingIdentity();
11891 try {
11892 Phone phone = getPhone(subId);
11893 if (phone == null) return null;
11894 ServiceStateTracker sst = phone.getServiceStateTracker();
11895 if (sst == null) return null;
11896 return sst.getLastKnownCellIdentity();
11897 } finally {
11898 Binder.restoreCallingIdentity(identity);
11899 }
11900 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011901
jimsun3b9ccac2021-10-26 15:01:23 +080011902 /**
11903 * Sets the modem service class Name that Telephony will bind to.
11904 *
11905 * @param serviceName The class name of the modem service.
11906 * @return true if the operation is succeed, otherwise false.
11907 */
11908 public boolean setModemService(String serviceName) {
11909 Log.d(LOG_TAG, "setModemService - " + serviceName);
11910 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11911 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11912 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11913 "setModemService");
11914 return mPhoneConfigurationManager.setModemService(serviceName);
11915 }
11916
11917 /**
11918 * Return the class name of the currently bounded modem service.
11919 *
11920 * @return the class name of the modem service.
11921 */
11922 public String getModemService() {
11923 String result;
11924 Log.d(LOG_TAG, "getModemService");
11925 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11926 TelephonyPermissions
11927 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11928 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11929 "getModemService");
11930 result = mPhoneConfigurationManager.getModemService();
11931 Log.d(LOG_TAG, "result = " + result);
11932 return result;
11933 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011934
11935 @Override
11936 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11937 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11938 mApp.enforceCallingOrSelfPermission(
11939 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11940 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11941
11942 final long identity = Binder.clearCallingIdentity();
11943 try {
11944 Phone phone = getPhone(subId);
11945 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080011946 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
11947 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011948 phone.setVoiceServiceStateOverride(hasService);
11949 } finally {
11950 Binder.restoreCallingIdentity(identity);
11951 }
11952 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011953
11954 /**
11955 * set removable eSIM as default eUICC.
11956 *
11957 * @hide
11958 */
11959 @Override
11960 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11961 enforceModifyPermission();
11962 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11963
11964 final long identity = Binder.clearCallingIdentity();
11965 try {
11966 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11967 } finally {
11968 Binder.restoreCallingIdentity(identity);
11969 }
11970 }
11971
11972 /**
11973 * Returns whether the removable eSIM is default eUICC or not.
11974 *
11975 * @hide
11976 */
11977 @Override
11978 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11979 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11980 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11981
11982 final long identity = Binder.clearCallingIdentity();
11983 try {
11984 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11985 } finally {
11986 Binder.restoreCallingIdentity(identity);
11987 }
11988 }
11989
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011990 /**
11991 * Get the component name of the default app to direct respond-via-message intent for the
11992 * user associated with this subscription, update the cache if there is no respond-via-message
11993 * application currently configured for this user.
11994 * @return component name of the app and class to direct Respond Via Message intent to, or
11995 * {@code null} if the functionality is not supported.
11996 * @hide
11997 */
11998 @Override
11999 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12000 boolean updateIfNeeded) {
12001 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012002
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012003 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12004
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012005 UserHandle userHandle = null;
12006 final long identity = Binder.clearCallingIdentity();
12007 try {
12008 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12009 } finally {
12010 Binder.restoreCallingIdentity(identity);
12011 }
12012 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12013 updateIfNeeded, userHandle);
12014 }
Jack Yuf5badd92022-12-08 00:50:53 -080012015
12016 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012017 * Set whether the device is able to connect with null ciphering or integrity
12018 * algorithms. This is a global setting and will apply to all active subscriptions
12019 * and all new subscriptions after this.
12020 *
12021 * @param enabled when true, null cipher and integrity algorithms are allowed.
12022 * @hide
12023 */
12024 @Override
12025 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12026 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12027 enforceModifyPermission();
12028 checkForNullCipherAndIntegritySupport();
12029
12030 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12031 // for listening to these preference changes and applying them immediately.
12032 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12033 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12034 editor.apply();
12035
12036 for (Phone phone: PhoneFactory.getPhones()) {
12037 phone.handleNullCipherEnabledChange();
12038 }
12039 }
12040
12041
12042 /**
12043 * Get whether the device is able to connect with null ciphering or integrity
12044 * algorithms. Note that this retrieves the phone-global preference and not
12045 * the state of the radio.
12046 *
12047 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12048 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12049 * version for this feature.
12050 * @hide
12051 */
12052 @Override
12053 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12054 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12055 enforceReadPermission();
12056 checkForNullCipherAndIntegritySupport();
12057 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12058 }
12059
12060 private void checkForNullCipherAndIntegritySupport() {
12061 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12062 throw new UnsupportedOperationException(
12063 "Null cipher and integrity operations require HAL 2.1 or above");
12064 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012065 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12066 throw new UnsupportedOperationException(
12067 "Null cipher and integrity operations unsupported by modem");
12068 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012069 }
12070
12071 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012072 * Get the SIM state for the slot index.
12073 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12074 *
12075 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12076 */
12077 @Override
12078 @SimState
12079 public int getSimStateForSlotIndex(int slotIndex) {
12080 IccCardConstants.State simState;
12081 if (slotIndex < 0) {
12082 simState = IccCardConstants.State.UNKNOWN;
12083 } else {
12084 Phone phone = null;
12085 try {
12086 phone = PhoneFactory.getPhone(slotIndex);
12087 } catch (IllegalStateException e) {
12088 // ignore
12089 }
12090 if (phone == null) {
12091 simState = IccCardConstants.State.UNKNOWN;
12092 } else {
12093 IccCard icc = phone.getIccCard();
12094 if (icc == null) {
12095 simState = IccCardConstants.State.UNKNOWN;
12096 } else {
12097 simState = icc.getState();
12098 }
12099 }
12100 }
12101 return simState.ordinal();
12102 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012103
12104 /**
12105 * Get current cell broadcast ranges.
12106 */
12107 @Override
12108 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12109 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12110 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12111 "getCellBroadcastIdRanges");
12112 final long identity = Binder.clearCallingIdentity();
12113 try {
12114 return getPhone(subId).getCellBroadcastIdRanges();
12115 } finally {
12116 Binder.restoreCallingIdentity(identity);
12117 }
12118 }
12119
12120 /**
12121 * Set reception of cell broadcast messages with the list of the given ranges
12122 *
12123 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12124 */
12125 @Override
12126 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12127 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12128 @Nullable IIntegerConsumer callback) {
12129 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12130 "setCellBroadcastIdRanges");
12131 final long identity = Binder.clearCallingIdentity();
12132 try {
12133 Phone phone = getPhoneFromSubId(subId);
12134 if (DBG) {
12135 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12136 }
12137 phone.setCellBroadcastIdRanges(ranges, result -> {
12138 if (callback != null) {
12139 try {
12140 callback.accept(result);
12141 } catch (RemoteException e) {
12142 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12143 }
12144 }
12145 });
12146 } finally {
12147 Binder.restoreCallingIdentity(identity);
12148 }
12149 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012150
12151 /**
12152 * Returns whether the device supports the domain selection service.
12153 *
12154 * @return {@code true} if the device supports the domain selection service.
12155 */
12156 @Override
12157 public boolean isDomainSelectionSupported() {
12158 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12159 "isDomainSelectionSupported");
12160
12161 final long identity = Binder.clearCallingIdentity();
12162 try {
12163 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12164 } finally {
12165 Binder.restoreCallingIdentity(identity);
12166 }
12167 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012168
12169 /**
Sarah Chineccfbd12023-01-20 19:00:35 -080012170 * Start receiving satellite position updates.
12171 * This can be called by the pointing UI when the user starts pointing to the satellite.
12172 * Modem should continue to report the pointing input as the device or satellite moves.
12173 *
12174 * @param subId The subId to start satellite position updates for.
12175 * @param callbackId The callback ID associating the public SatellitePositionUpdateCallback to
12176 * the internal ISatellitePositionUpdateCallback below.
12177 * @param callback The callback to notify of changes in satellite position.
12178 * @return The result of the operation.
12179 */
12180 @Override
12181 @SatelliteManager.SatelliteServiceResult public int startSatellitePositionUpdates(int subId,
12182 int callbackId, @NonNull ISatellitePositionUpdateCallback callback) {
12183 // TODO: check for SATELLITE_COMMUNICATION permission
12184 Phone phone = getPhone(subId);
12185 if (phone == null) {
12186 loge("startSatellitePositionUpdates called with invalid subId: " + subId
12187 + ". Retrying with default phone.");
12188 phone = getDefaultPhone();
12189 if (phone == null) {
12190 loge("startSatellitePositionUpdates failed with no phone object.");
12191 return SatelliteManager.SATELLITE_SERVICE_REQUEST_FAILED;
12192 }
12193 }
12194
12195 if (mSatellitePositionUpdateHandlers.containsKey(callbackId)) {
12196 log("startSatellitePositionUpdates: callback already registered: " + callbackId);
12197 return SatelliteManager.SATELLITE_SERVICE_SUCCESS;
12198 }
12199
12200 SatellitePositionUpdateHandler handler =
12201 new SatellitePositionUpdateHandler(callback, Looper.getMainLooper());
12202 phone.registerForSatellitePointingInfoChanged(handler,
12203 SatellitePositionUpdateHandler.EVENT_POSITION_UPDATE, null);
12204 phone.registerForSatelliteMessagesTransferComplete(handler,
12205 SatellitePositionUpdateHandler.EVENT_MESSAGE_TRANSFER_STATE_UPDATE, null);
12206 mSatellitePositionUpdateHandlers.put(callbackId, handler);
12207
12208 int result = (int) sendRequest(CMD_START_SATELLITE_POSITION_UPDATES, null, subId);
12209 if (DBG) log("startSatellitePositionUpdates result: " + result);
12210 return result;
12211 }
12212
12213 /**
12214 * Stop receiving satellite position updates.
12215 * This can be called by the pointing UI when the user stops pointing to the satellite.
12216 *
12217 * @param subId The subId to stop satellite position updates for.
12218 * @param callbackId The ID of the callback that was passed in {@link
12219 * #startSatellitePositionUpdates(int, int, ISatellitePositionUpdateCallback)}
12220 * @return The result of the operation.
12221 */
12222 @Override
12223 @SatelliteManager.SatelliteServiceResult public int stopSatellitePositionUpdates(int subId,
12224 int callbackId) {
12225 // TODO: check for SATELLITE_COMMUNICATION permission
12226 Phone phone = getPhone(subId);
12227 if (phone == null) {
12228 loge("stopSatellitePositionUpdates called with invalid subId: " + subId
12229 + ". Retrying with default phone.");
12230 phone = getDefaultPhone();
12231 if (phone == null) {
12232 loge("stopSatellitePositionUpdates failed with no phone object.");
12233 return SatelliteManager.SATELLITE_SERVICE_REQUEST_FAILED;
12234 }
12235 }
12236
12237 SatellitePositionUpdateHandler handler =
12238 mSatellitePositionUpdateHandlers.remove(callbackId);
12239 if (handler == null) {
12240 loge("stopSatellitePositionUpdates: No SatellitePositionArgument");
12241 return SatelliteManager.SATELLITE_SERVICE_REQUEST_FAILED;
12242 } else {
12243 phone.unregisterForSatellitePointingInfoChanged(handler);
12244 phone.unregisterForSatelliteMessagesTransferComplete(handler);
12245 }
12246
12247 if (!mSatellitePositionUpdateHandlers.isEmpty()) {
12248 log("stopSatellitePositionUpdates: other listeners still exist.");
12249 return SatelliteManager.SATELLITE_SERVICE_SUCCESS;
12250 }
12251
12252 int result = (int) sendRequest(CMD_STOP_SATELLITE_POSITION_UPDATES, null, subId);
12253 if (DBG) log("stopSatellitePositionUpdates result: " + result);
12254 return result;
12255 }
12256
12257 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000012258 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
12259 *
12260 * <p>This method behaves in one of the following ways:
12261 * <ul>
12262 * <li>return true : if the calling package has the appop permission {@link
12263 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
12264 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
12265 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
12266 * Owner device identifier access check, or the calling package has carrier privileges</>
12267 * <li>throw SecurityException: if the caller does not meet any of the requirements.
12268 * </ul>
12269 */
12270 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
12271 String callingPackage, @Nullable String callingFeatureId, String message) {
12272 for (Phone phone : PhoneFactory.getPhones()) {
12273 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
12274 phone.getSubId(), callingPackage, callingFeatureId, message)) {
12275 return true;
12276 }
12277 }
12278 return false;
12279 }
arunvoddud7401012022-12-15 16:08:12 +000012280
12281 /**
12282 * Class binds the consumer[callback] and carrierId.
12283 */
12284 private static class CallerCallbackInfo {
12285 private final Consumer<Integer> mConsumer;
12286 private final int mCarrierId;
12287
12288 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
12289 mConsumer = consumer;
12290 mCarrierId = carrierId;
12291 }
12292
12293 public Consumer<Integer> getConsumer() {
12294 return mConsumer;
12295 }
12296
12297 public int getCarrierId() {
12298 return mCarrierId;
12299 }
12300 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012301}