blob: 7b5cf81e2641872dc5fb732cfe678ea2f5c953a4 [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;
jimsunf9ec1622022-09-13 21:18:43 +080020import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO;
Hall Liud892bec2018-11-30 14:51:45 -080021
Shuo Qianccbaf742021-02-22 18:32:21 -080022import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
23import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070024import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070025import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000026import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070027
Brad Ebinger34c09a52021-02-17 23:23:21 +000028import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080029import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080030import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070031import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000032import android.annotation.RequiresPermission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070033import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080034import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070035import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000036import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080037import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000038import android.compat.annotation.ChangeId;
39import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070040import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070041import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.content.Context;
43import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070044import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070045import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070046import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.net.Uri;
48import android.os.AsyncResult;
49import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080050import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070051import android.os.Bundle;
52import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070053import android.os.IBinder;
tom hsu0b59d292022-09-29 23:49:21 +080054import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.Looper;
56import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070057import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080058import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070059import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070060import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080061import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080062import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070063import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070064import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080065import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070066import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070067import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070068import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070069import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070070import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080071import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070072import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090073import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080074import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080075import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070076import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080077import android.telephony.AccessNetworkConstants;
78import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070079import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070080import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080081import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070082import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080083import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070084import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080085import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070086import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080087import android.telephony.CellIdentityCdma;
88import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070089import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070090import android.telephony.CellInfoGsm;
91import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070092import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080093import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070094import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070095import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070096import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080097import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070098import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080099import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -0700100import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800101import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800102import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700103import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800104import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700105import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800106import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800107import android.telephony.SignalStrengthUpdateRequest;
108import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800109import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800110import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800111import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700112import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700113import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800114import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800115import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800116import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000117import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000118import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000119import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700120import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700121import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800122import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800123import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700124import android.telephony.gba.GbaAuthRequest;
125import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700126import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800127import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000128import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000129import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700130import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000131import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700132import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800133import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700134import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800135import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700136import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000137import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700138import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800139import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800140import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700141import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800142import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700143import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700144import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800145import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800146
Andrew Lee312e8172014-10-23 17:01:36 -0700147import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800148import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800149import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800150import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800151import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700152import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700153import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700154import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800155import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800156import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700157import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700158import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800159import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700160import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800161import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800162import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800163import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700164import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000165import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700166import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800167import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700168import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800169import com.android.internal.telephony.IccCard;
Rambo Wanga1782702021-11-10 20:15:19 -0800170import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700171import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700172import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700173import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700174import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700175import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800176import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700177import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700178import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700179import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700180import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800181import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800182import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700183import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700184import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700185import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800186import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800187import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800188import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700189import com.android.internal.telephony.data.DataUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800190import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700191import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800192import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700193import com.android.internal.telephony.imsphone.ImsPhone;
194import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000195import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800196import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700197import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700198import com.android.internal.telephony.uicc.IccIoResult;
199import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800200import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700201import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800202import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700203import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000204import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800205import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000206import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800207import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700208import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700209import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800210import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800211import com.android.phone.callcomposer.CallComposerPictureManager;
212import com.android.phone.callcomposer.CallComposerPictureTransfer;
213import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700214import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700215import com.android.phone.slice.SlicePurchaseController;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700216import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800217import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700218import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700219import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800220import com.android.services.telephony.TelecomAccountRegistry;
221import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800222import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800223
Hall Liu82694d52020-12-11 18:22:04 -0800224import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700225import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800226import java.io.IOException;
227import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700228import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700229import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800230import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000231import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800232import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800233import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800234import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800235import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100236import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800237import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700238import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800239import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800240import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700241import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800242import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800243import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800244import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700245
246/**
247 * Implementation of the ITelephony interface.
248 */
Santos Cordon117fee72014-05-16 17:56:12 -0700249public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700250 private static final String LOG_TAG = "PhoneInterfaceManager";
251 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
252 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800253 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700254
255 // Message codes used with mMainThreadHandler
256 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700257 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
258 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700259 private static final int CMD_OPEN_CHANNEL = 9;
260 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
261 private static final int CMD_CLOSE_CHANNEL = 11;
262 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800263 private static final int CMD_NV_READ_ITEM = 13;
264 private static final int EVENT_NV_READ_ITEM_DONE = 14;
265 private static final int CMD_NV_WRITE_ITEM = 15;
266 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
267 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
268 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700269 private static final int CMD_RESET_MODEM_CONFIG = 19;
270 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800271 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
272 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800273 private static final int CMD_SEND_ENVELOPE = 25;
274 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000275 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
276 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700277 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
278 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
279 private static final int CMD_EXCHANGE_SIM_IO = 31;
280 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800281 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
282 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700283 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
284 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700285 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
286 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700287 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
288 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
289 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
290 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700291 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
292 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
293 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
294 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700295 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800296 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
297 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000298 private static final int CMD_SWITCH_SLOTS = 50;
299 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700300 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
301 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
302 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
303 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
304 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
305 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
306 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
307 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700308 private static final int CMD_GET_ALL_CELL_INFO = 60;
309 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
310 private static final int CMD_GET_CELL_LOCATION = 62;
311 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700312 private static final int CMD_MODEM_REBOOT = 64;
313 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700314 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
315 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800316 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
317 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700318 private static final int CMD_GET_MODEM_STATUS = 70;
319 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700320 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
321 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700322 private static final int CMD_ERASE_MODEM_CONFIG = 74;
323 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800324 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
325 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
326 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
327 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800328 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
329 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800330 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800331 private static final int CMD_GET_CALL_FORWARDING = 83;
332 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
333 private static final int CMD_SET_CALL_FORWARDING = 85;
334 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
335 private static final int CMD_GET_CALL_WAITING = 87;
336 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
337 private static final int CMD_SET_CALL_WAITING = 89;
338 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700339 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
340 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
341 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
342 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700343 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
344 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800345 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
346 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800347 private static final int CMD_SET_DATA_THROTTLING = 99;
348 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800349 private static final int CMD_SET_SIM_POWER = 101;
350 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800351 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
352 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
353 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
354 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800355 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
356 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000357 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800358 private static final int CMD_GET_SLICING_CONFIG = 110;
359 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800360 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700361 private static final int CMD_ENABLE_VONR = 113;
362 private static final int EVENT_ENABLE_VONR_DONE = 114;
363 private static final int CMD_IS_VONR_ENABLED = 115;
364 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700365 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
366 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700367
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800368 // Parameters of select command.
369 private static final int SELECT_COMMAND = 0xA4;
370 private static final int SELECT_P1 = 0x04;
371 private static final int SELECT_P2 = 0;
372 private static final int SELECT_P3 = 0x10;
373
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700374 /** The singleton instance. */
375 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800376 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700377
Wink Saville3ab207e2014-11-20 13:07:20 -0800378 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800379 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800380 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700381 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800382 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700383 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800384 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800385 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800386 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700387 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800388 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Gil Cukierman6dac5eb2022-09-19 16:09:04 +0000389 private final Telephony2gUpdater mTelephony2gUpdater;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700390
Peter Wangdafb9ac2020-01-15 14:13:38 -0800391 /** User Activity */
392 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800393 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
394
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700395 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
396
Derek Tan97ebb422014-09-05 16:55:38 -0700397 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
398 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800399 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800400 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700401
Michelecea4cf22018-12-21 15:00:11 -0800402 // String to store multi SIM allowed
403 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
404
Derek Tan740e1672017-06-27 14:56:27 -0700405 // The AID of ISD-R.
406 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
407
yinxub1bed742017-04-17 11:45:04 -0700408 private NetworkScanRequestTracker mNetworkScanRequestTracker;
409
David Kelly5e06a7f2018-03-12 14:10:59 +0000410 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
411 private static final int MANUFACTURER_CODE_LENGTH = 8;
412
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800413 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800414 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800415
Sarah Chin2ec39f62022-08-31 17:03:26 -0700416 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
417 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
418
Derek Tan89e89d42014-07-08 17:00:10 -0700419 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700420 * Experiment flag to enable erase modem config on reset network, default value is false
421 */
422 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
423 "reset_network_erase_modem_config_enabled";
424
Rambo Wang0f050d82021-02-12 11:43:36 -0800425 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800426
sandeepjsb6c87872021-09-27 15:34:44 +0000427 /**
428 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
429 * one ICCID active at the same time.
430 * Apps should use below API signatures if targeting SDK is T and beyond.
431 *
432 * @hide
433 */
434 @ChangeId
435 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
436 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800437
Naina Nallurid63128d2019-09-17 14:10:30 -0700438 /**
Chen Xu540470b2021-12-14 17:15:47 -0800439 * Apps targeting on Android T and beyond will get exception whenever icc close channel
440 * operation fails.
441 */
442 @ChangeId
443 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
444 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
445
446 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700447 * A request object to use for transmitting data to an ICC.
448 */
449 private static final class IccAPDUArgument {
450 public int channel, cla, command, p1, p2, p3;
451 public String data;
452
453 public IccAPDUArgument(int channel, int cla, int command,
454 int p1, int p2, int p3, String data) {
455 this.channel = channel;
456 this.cla = cla;
457 this.command = command;
458 this.p1 = p1;
459 this.p2 = p2;
460 this.p3 = p3;
461 this.data = data;
462 }
463 }
464
465 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700466 * A request object to use for transmitting data to an ICC.
467 */
468 private static final class ManualNetworkSelectionArgument {
469 public OperatorInfo operatorInfo;
470 public boolean persistSelection;
471
472 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
473 this.operatorInfo = operatorInfo;
474 this.persistSelection = persistSelection;
475 }
476 }
477
Sarah Chin71b3a852022-09-28 15:54:19 -0700478 private static final class PurchasePremiumCapabilityArgument {
479 public @TelephonyManager.PremiumCapability int capability;
480 public @NonNull String appName;
481 public @NonNull IIntegerConsumer callback;
482
483 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
484 @NonNull String appName, @NonNull IIntegerConsumer callback) {
485 this.capability = capability;
486 this.appName = appName;
487 this.callback = callback;
488 }
489 }
490
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700491 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700492 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
493 * request after sending. The main thread will notify the request when it is complete.
494 */
495 private static final class MainThreadRequest {
496 /** The argument to use for the request */
497 public Object argument;
498 /** The result of the request that is run on the main thread */
499 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800500 // The subscriber id that this request applies to. Defaults to
501 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
502 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700503
Nathan Harold92bed182018-10-12 18:16:49 -0700504 // In cases where subId is unavailable, the caller needs to specify the phone.
505 public Phone phone;
506
vagdeviaf9a5b92018-08-15 16:01:53 -0700507 public WorkSource workSource;
508
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700509 public MainThreadRequest(Object argument) {
510 this.argument = argument;
511 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800512
Nathan Harold92bed182018-10-12 18:16:49 -0700513 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
514 this.argument = argument;
515 if (phone != null) {
516 this.phone = phone;
517 }
518 this.workSource = workSource;
519 }
520
vagdeviaf9a5b92018-08-15 16:01:53 -0700521 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800522 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800523 if (subId != null) {
524 this.subId = subId;
525 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700526 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800527 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700528 }
529
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800530 private static final class IncomingThirdPartyCallArgs {
531 public final ComponentName component;
532 public final String callId;
533 public final String callerDisplayName;
534
535 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
536 String callerDisplayName) {
537 this.component = component;
538 this.callId = callId;
539 this.callerDisplayName = callerDisplayName;
540 }
541 }
542
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700543 /**
544 * A handler that processes messages on the main thread in the phone process. Since many
545 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
546 * inbound binder threads to the main thread in the phone process. The Binder thread
547 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
548 * on, which will be notified when the operation completes and will contain the result of the
549 * request.
550 *
551 * <p>If a MainThreadRequest object is provided in the msg.obj field,
552 * note that request.result must be set to something non-null for the calling thread to
553 * unblock.
554 */
555 private final class MainThreadHandler extends Handler {
556 @Override
557 public void handleMessage(Message msg) {
558 MainThreadRequest request;
559 Message onCompleted;
560 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000561 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700562 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800563 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700564
565 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700566 case CMD_HANDLE_USSD_REQUEST: {
567 request = (MainThreadRequest) msg.obj;
568 final Phone phone = getPhoneFromRequest(request);
569 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800570 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700571 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700572
Pengquan Menga1bb6272018-09-06 09:59:22 -0700573 if (!isUssdApiAllowed(request.subId)) {
574 // Carrier does not support use of this API, return failure.
575 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
576 UssdResponse response = new UssdResponse(ussdRequest, null);
577 Bundle returnData = new Bundle();
578 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
579 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700580
Pengquan Menga1bb6272018-09-06 09:59:22 -0700581 request.result = true;
582 notifyRequester(request);
583 return;
584 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700585
Pengquan Menga1bb6272018-09-06 09:59:22 -0700586 try {
587 request.result = phone != null
588 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
589 } catch (CallStateException cse) {
590 request.result = false;
591 }
592 // Wake up the requesting thread
593 notifyRequester(request);
594 break;
pkanwar32d516d2016-10-14 19:37:38 -0700595 }
596
Yorke Lee716f67e2015-06-17 15:39:16 -0700597 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700598 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700599 final Phone phone = getPhoneFromRequest(request);
600 request.result = phone != null ?
601 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
602 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700603 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700604 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700605 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700606 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700607
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700608 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700609 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700610 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000611 uiccPort = getUiccPortFromRequest(request);
612 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700613 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800614 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700615 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700616 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700617 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800618 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000619 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800620 iccArgument.channel, iccArgument.cla, iccArgument.command,
621 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
622 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700623 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700624 break;
625
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700626 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700627 ar = (AsyncResult) msg.obj;
628 request = (MainThreadRequest) ar.userObj;
629 if (ar.exception == null && ar.result != null) {
630 request.result = ar.result;
631 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800632 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700633 if (ar.result == null) {
634 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800635 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700636 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800637 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700638 } else {
639 loge("iccTransmitApduLogicalChannel: Unknown exception");
640 }
641 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700642 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700643 break;
644
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700645 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
646 request = (MainThreadRequest) msg.obj;
647 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000648 uiccPort = getUiccPortFromRequest(request);
649 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700650 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800651 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700652 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700653 } else {
654 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800655 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000656 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800657 iccArgument.cla, iccArgument.command, iccArgument.p1,
658 iccArgument.p2,
659 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700660 }
661 break;
662
663 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
664 ar = (AsyncResult) msg.obj;
665 request = (MainThreadRequest) ar.userObj;
666 if (ar.exception == null && ar.result != null) {
667 request.result = ar.result;
668 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800669 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700670 if (ar.result == null) {
671 loge("iccTransmitApduBasicChannel: Empty response");
672 } else if (ar.exception instanceof CommandException) {
673 loge("iccTransmitApduBasicChannel: CommandException: " +
674 ar.exception);
675 } else {
676 loge("iccTransmitApduBasicChannel: Unknown exception");
677 }
678 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700679 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700680 break;
681
682 case CMD_EXCHANGE_SIM_IO:
683 request = (MainThreadRequest) msg.obj;
684 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000685 uiccPort = getUiccPortFromRequest(request);
686 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700687 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800688 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700689 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700690 } else {
691 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
692 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000693 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700694 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
695 iccArgument.data, onCompleted);
696 }
697 break;
698
699 case EVENT_EXCHANGE_SIM_IO_DONE:
700 ar = (AsyncResult) msg.obj;
701 request = (MainThreadRequest) ar.userObj;
702 if (ar.exception == null && ar.result != null) {
703 request.result = ar.result;
704 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800705 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700706 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700707 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700708 break;
709
Derek Tan4d5e5c12014-02-04 11:54:58 -0800710 case CMD_SEND_ENVELOPE:
711 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000712 uiccPort = getUiccPortFromRequest(request);
713 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700714 loge("sendEnvelopeWithStatus: 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 Agrawaleb8771e2014-07-22 11:24:08 -0700717 } else {
718 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800719 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700720 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800721 break;
722
723 case EVENT_SEND_ENVELOPE_DONE:
724 ar = (AsyncResult) msg.obj;
725 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700726 if (ar.exception == null && ar.result != null) {
727 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800728 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800729 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700730 if (ar.result == null) {
731 loge("sendEnvelopeWithStatus: Empty response");
732 } else if (ar.exception instanceof CommandException) {
733 loge("sendEnvelopeWithStatus: CommandException: " +
734 ar.exception);
735 } else {
736 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
737 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800738 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700739 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800740 break;
741
Shishir Agrawal566b7612013-10-28 14:41:00 -0700742 case CMD_OPEN_CHANNEL:
743 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000744 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800745 IccLogicalChannelRequest openChannelRequest =
746 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000747 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700748 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800749 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800750 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700751 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700752 } else {
753 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800754 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
755 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700756 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700757 break;
758
759 case EVENT_OPEN_CHANNEL_DONE:
760 ar = (AsyncResult) msg.obj;
761 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700762 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700763 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700764 int[] result = (int[]) ar.result;
765 int channelId = result[0];
766 byte[] selectResponse = null;
767 if (result.length > 1) {
768 selectResponse = new byte[result.length - 1];
769 for (int i = 1; i < result.length; ++i) {
770 selectResponse[i - 1] = (byte) result[i];
771 }
772 }
773 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800774 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800775
776 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700777 if (uiccPort == null) {
778 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
779 } else {
780 IccLogicalChannelRequest channelRequest =
781 (IccLogicalChannelRequest) request.argument;
782 channelRequest.channel = channelId;
783 uiccPort.onLogicalChannelOpened(channelRequest);
784 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700785 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700786 if (ar.result == null) {
787 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700788 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700789 if (ar.exception != null) {
790 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
791 }
792
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700793 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700794 if (ar.exception instanceof CommandException) {
795 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800796 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700797 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700798 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700799 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700800 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700801 }
802 }
803 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800804 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700805 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700806 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700807 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700808 break;
809
810 case CMD_CLOSE_CHANNEL:
811 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000812 uiccPort = getUiccPortFromRequest(request);
813 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700814 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800815 request.result = new IllegalArgumentException(
Chen Xue9d737e2022-01-01 23:41:31 -0800816 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800817 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700818 } else {
819 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000820 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700821 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700822 break;
823
824 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800825 ar = (AsyncResult) msg.obj;
826 request = (MainThreadRequest) ar.userObj;
827 if (ar.exception == null) {
828 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800829 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700830 if (uiccPort == null) {
831 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
832 } else {
833 final int channelId = (Integer) request.argument;
834 uiccPort.onLogicalChannelClosed(channelId);
835 }
Chen Xu540470b2021-12-14 17:15:47 -0800836 } else {
837 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800838 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800839 if (ar.exception instanceof CommandException) {
840 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
841 CommandException.Error error =
842 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800843 if (error == CommandException.Error.INVALID_ARGUMENTS) {
844 // should only throw exceptions from the binder threads.
845 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800846 "iccCloseLogicalChannel: invalid argument ");
847 }
848 } else {
849 loge("iccCloseLogicalChannel: Unknown exception");
850 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800851 request.result = (exception != null) ? exception :
852 new IllegalStateException(
853 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800854 }
855 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800856 break;
857
858 case CMD_NV_READ_ITEM:
859 request = (MainThreadRequest) msg.obj;
860 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800861 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
862 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800863 break;
864
865 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700866 ar = (AsyncResult) msg.obj;
867 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800868 if (ar.exception == null && ar.result != null) {
869 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700870 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800871 request.result = "";
872 if (ar.result == null) {
873 loge("nvReadItem: Empty response");
874 } else if (ar.exception instanceof CommandException) {
875 loge("nvReadItem: CommandException: " +
876 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700877 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800878 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700879 }
880 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700881 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700882 break;
883
Jake Hambye994d462014-02-03 13:10:13 -0800884 case CMD_NV_WRITE_ITEM:
885 request = (MainThreadRequest) msg.obj;
886 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
887 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800888 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700889 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800890 break;
891
892 case EVENT_NV_WRITE_ITEM_DONE:
893 handleNullReturnEvent(msg, "nvWriteItem");
894 break;
895
896 case CMD_NV_WRITE_CDMA_PRL:
897 request = (MainThreadRequest) msg.obj;
898 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800899 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800900 break;
901
902 case EVENT_NV_WRITE_CDMA_PRL_DONE:
903 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
904 break;
905
chen xu6dac5ab2018-10-26 17:39:23 -0700906 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800907 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700908 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800909 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800910 break;
911
chen xu6dac5ab2018-10-26 17:39:23 -0700912 case EVENT_RESET_MODEM_CONFIG_DONE:
913 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800914 break;
915
Sooraj Sasindran37444802020-08-11 10:40:43 -0700916 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
917 request = (MainThreadRequest) msg.obj;
918 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
919 request);
920 Phone phone = getPhoneFromRequest(request);
921 if (phone != null) {
922 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
923 } else {
924 loge("isNRDualConnectivityEnabled: No phone object");
925 request.result = false;
926 notifyRequester(request);
927 }
928 break;
929 }
930
931 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
932 ar = (AsyncResult) msg.obj;
933 request = (MainThreadRequest) ar.userObj;
934 if (ar.exception == null && ar.result != null) {
935 request.result = ar.result;
936 } else {
937 // request.result must be set to something non-null
938 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700939 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700940 request.result = ar.result;
941 } else {
942 request.result = false;
943 }
944 if (ar.result == null) {
945 loge("isNRDualConnectivityEnabled: Empty response");
946 } else if (ar.exception instanceof CommandException) {
947 loge("isNRDualConnectivityEnabled: CommandException: "
948 + ar.exception);
949 } else {
950 loge("isNRDualConnectivityEnabled: Unknown exception");
951 }
952 }
953 notifyRequester(request);
954 break;
955
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700956 case CMD_IS_VONR_ENABLED: {
957 request = (MainThreadRequest) msg.obj;
958 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
959 request);
960 Phone phone = getPhoneFromRequest(request);
961 if (phone != null) {
962 phone.isVoNrEnabled(onCompleted, request.workSource);
963 } else {
964 loge("isVoNrEnabled: No phone object");
965 request.result = false;
966 notifyRequester(request);
967 }
968 break;
969 }
970
971 case EVENT_IS_VONR_ENABLED_DONE:
972 ar = (AsyncResult) msg.obj;
973 request = (MainThreadRequest) ar.userObj;
974 if (ar.exception == null && ar.result != null) {
975 request.result = ar.result;
976 } else {
977 // request.result must be set to something non-null
978 // for the calling thread to unblock
979 if (ar.result != null) {
980 request.result = ar.result;
981 } else {
982 request.result = false;
983 }
984 if (ar.result == null) {
985 loge("isVoNrEnabled: Empty response");
986 } else if (ar.exception instanceof CommandException) {
987 loge("isVoNrEnabled: CommandException: "
988 + ar.exception);
989 } else {
990 loge("isVoNrEnabled: Unknown exception");
991 }
992 }
993 notifyRequester(request);
994 break;
995
Sooraj Sasindran37444802020-08-11 10:40:43 -0700996 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
997 request = (MainThreadRequest) msg.obj;
998 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
999 Phone phone = getPhoneFromRequest(request);
1000 if (phone != null) {
1001 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1002 request.workSource);
1003 } else {
1004 loge("enableNrDualConnectivity: No phone object");
1005 request.result =
1006 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1007 notifyRequester(request);
1008 }
1009 break;
1010 }
1011
1012 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1013 ar = (AsyncResult) msg.obj;
1014 request = (MainThreadRequest) ar.userObj;
1015 if (ar.exception == null) {
1016 request.result =
1017 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1018 } else {
1019 request.result =
1020 TelephonyManager
1021 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1022 if (ar.exception instanceof CommandException) {
1023 CommandException.Error error =
1024 ((CommandException) (ar.exception)).getCommandError();
1025 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1026 request.result =
1027 TelephonyManager
1028 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001029 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1030 request.result =
1031 TelephonyManager
1032 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001033 }
1034 loge("enableNrDualConnectivity" + ": CommandException: "
1035 + ar.exception);
1036 } else {
1037 loge("enableNrDualConnectivity" + ": Unknown exception");
1038 }
1039 }
1040 notifyRequester(request);
1041 break;
1042 }
1043
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001044 case CMD_ENABLE_VONR: {
1045 request = (MainThreadRequest) msg.obj;
1046 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1047 Phone phone = getPhoneFromRequest(request);
1048 if (phone != null) {
1049 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1050 request.workSource);
1051 } else {
1052 loge("setVoNrEnabled: No phone object");
1053 request.result =
1054 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1055 notifyRequester(request);
1056 }
1057 break;
1058 }
1059
1060 case EVENT_ENABLE_VONR_DONE: {
1061 ar = (AsyncResult) msg.obj;
1062 request = (MainThreadRequest) ar.userObj;
1063 if (ar.exception == null) {
1064 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1065 } else {
1066 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1067 if (ar.exception instanceof CommandException) {
1068 CommandException.Error error =
1069 ((CommandException) (ar.exception)).getCommandError();
1070 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1071 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1072 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1073 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1074 } else {
1075 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1076 }
1077 loge("setVoNrEnabled" + ": CommandException: "
1078 + ar.exception);
1079 } else {
1080 loge("setVoNrEnabled" + ": Unknown exception");
1081 }
1082 }
1083 notifyRequester(request);
1084 break;
1085 }
1086
SongFerngWang3ef3e072020-12-21 16:41:52 +08001087 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001088 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001089 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1090 request);
1091 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001092 break;
1093
SongFerngWang3ef3e072020-12-21 16:41:52 +08001094 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001095 ar = (AsyncResult) msg.obj;
1096 request = (MainThreadRequest) ar.userObj;
1097 if (ar.exception == null && ar.result != null) {
1098 request.result = ar.result; // Integer
1099 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301100 // request.result must be set to something non-null
1101 // for the calling thread to unblock
1102 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001103 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001104 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001105 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001106 loge("getAllowedNetworkTypesBitmask: CommandException: "
1107 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001108 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001109 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001110 }
1111 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001112 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001113 break;
1114
SongFerngWang3ef3e072020-12-21 16:41:52 +08001115 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001116 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001117 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1118 request);
1119 Pair<Integer, Long> reasonWithNetworkTypes =
1120 (Pair<Integer, Long>) request.argument;
1121 getPhoneFromRequest(request).setAllowedNetworkTypes(
1122 reasonWithNetworkTypes.first,
1123 reasonWithNetworkTypes.second,
1124 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001125 break;
1126
SongFerngWang3ef3e072020-12-21 16:41:52 +08001127 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1128 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001129 break;
1130
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001131 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1132 request = (MainThreadRequest)msg.obj;
1133 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001134 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001135 break;
1136
1137 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1138 ar = (AsyncResult)msg.obj;
1139 request = (MainThreadRequest)ar.userObj;
1140 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001141 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001142 break;
1143
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001144 case CMD_SET_VOICEMAIL_NUMBER:
1145 request = (MainThreadRequest) msg.obj;
1146 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1147 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001148 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1149 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001150 break;
1151
1152 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1153 handleNullReturnEvent(msg, "setVoicemailNumber");
1154 break;
1155
Stuart Scott54788802015-03-30 13:18:01 -07001156 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1157 request = (MainThreadRequest) msg.obj;
1158 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1159 request);
1160 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1161 break;
1162
1163 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1164 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1165 break;
1166
Shishir Agrawal302c8692015-06-19 13:49:39 -07001167 case CMD_PERFORM_NETWORK_SCAN:
1168 request = (MainThreadRequest) msg.obj;
1169 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1170 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1171 break;
1172
Hall Liu27d24262020-09-18 19:04:59 -07001173 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001174 request = (MainThreadRequest) msg.obj;
1175 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001176 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1177 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1178 request.argument;
1179 int callForwardingReason = args.first;
1180 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001181 break;
Hall Liu27d24262020-09-18 19:04:59 -07001182 }
1183 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001184 ar = (AsyncResult) msg.obj;
1185 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001186 TelephonyManager.CallForwardingInfoCallback callback =
1187 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1188 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001189 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001190 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001191 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1192 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1193 // Service Class is a bit mask per 3gpp 27.007. Search for
1194 // any service for voice call.
1195 if ((callForwardInfo.serviceClass
1196 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001197 callForwardingInfo = new CallForwardingInfo(
1198 callForwardInfo.status
1199 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001200 callForwardInfo.reason,
1201 callForwardInfo.number,
1202 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001203 break;
1204 }
1205 }
1206 // Didn't find a call forward info for voice call.
1207 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001208 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1209 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001210 }
Hall Liu27d24262020-09-18 19:04:59 -07001211 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001212 } else {
1213 if (ar.result == null) {
1214 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1215 }
1216 if (ar.exception != null) {
1217 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1218 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001219 int errorCode = TelephonyManager
1220 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001221 if (ar.exception instanceof CommandException) {
1222 CommandException.Error error =
1223 ((CommandException) (ar.exception)).getCommandError();
1224 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001225 errorCode = TelephonyManager
1226 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001227 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001228 errorCode = TelephonyManager
1229 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001230 }
1231 }
Hall Liu27d24262020-09-18 19:04:59 -07001232 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001233 }
Shuo Qian4a594052020-01-23 11:59:30 -08001234 break;
Hall Liu27d24262020-09-18 19:04:59 -07001235 }
Shuo Qian4a594052020-01-23 11:59:30 -08001236
Hall Liu27d24262020-09-18 19:04:59 -07001237 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001238 request = (MainThreadRequest) msg.obj;
1239 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001240 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001241 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001242 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1243 request.argument).first;
1244 request.phone.setCallForwardingOption(
1245 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001246 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001247 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001248 callForwardingInfoToSet.getReason(),
1249 callForwardingInfoToSet.getNumber(),
1250 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1251 break;
Hall Liu27d24262020-09-18 19:04:59 -07001252 }
Shuo Qian4a594052020-01-23 11:59:30 -08001253
Hall Liu27d24262020-09-18 19:04:59 -07001254 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001255 ar = (AsyncResult) msg.obj;
1256 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001257 Consumer<Integer> callback =
1258 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1259 request.argument).second;
1260 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001261 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001262 int errorCode = TelephonyManager.CallForwardingInfoCallback
1263 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001264 if (ar.exception instanceof CommandException) {
1265 CommandException.Error error =
1266 ((CommandException) (ar.exception)).getCommandError();
1267 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001268 errorCode = TelephonyManager.CallForwardingInfoCallback
1269 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001270 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001271 errorCode = TelephonyManager.CallForwardingInfoCallback
1272 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001273 }
1274 }
1275 callback.accept(errorCode);
1276 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001277 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001278 }
Shuo Qian4a594052020-01-23 11:59:30 -08001279 break;
Hall Liu27d24262020-09-18 19:04:59 -07001280 }
Shuo Qian4a594052020-01-23 11:59:30 -08001281
Hall Liu27d24262020-09-18 19:04:59 -07001282 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001283 request = (MainThreadRequest) msg.obj;
1284 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1285 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1286 break;
Hall Liu27d24262020-09-18 19:04:59 -07001287 }
Shuo Qian4a594052020-01-23 11:59:30 -08001288
Hall Liu27d24262020-09-18 19:04:59 -07001289 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001290 ar = (AsyncResult) msg.obj;
1291 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001292 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001293 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001294 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001295 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001296 // Service Class is a bit mask per 3gpp 27.007.
1297 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001298 if (callForwardResults.length > 1
1299 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001300 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001301 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001302 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1303 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001304 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001305 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001306 }
1307 } else {
1308 if (ar.result == null) {
1309 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1310 }
1311 if (ar.exception != null) {
1312 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1313 }
1314 if (ar.exception instanceof CommandException) {
1315 CommandException.Error error =
1316 ((CommandException) (ar.exception)).getCommandError();
1317 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001318 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001319 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001320 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1321 callWaitingStatus =
1322 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001323 }
1324 }
1325 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001326 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001327 break;
Hall Liu27d24262020-09-18 19:04:59 -07001328 }
Shuo Qian4a594052020-01-23 11:59:30 -08001329
Hall Liu27d24262020-09-18 19:04:59 -07001330 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001331 request = (MainThreadRequest) msg.obj;
1332 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001333 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1334 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001335 break;
Hall Liu27d24262020-09-18 19:04:59 -07001336 }
Shuo Qian4a594052020-01-23 11:59:30 -08001337
Hall Liu27d24262020-09-18 19:04:59 -07001338 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001339 ar = (AsyncResult) msg.obj;
1340 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001341 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1342 Consumer<Integer> callback =
1343 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1344 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001345 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001346 if (ar.exception instanceof CommandException) {
1347 CommandException.Error error =
1348 ((CommandException) (ar.exception)).getCommandError();
1349 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1350 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001351 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1352 callback.accept(
1353 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001354 } else {
1355 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1356 }
1357 } else {
1358 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1359 }
1360 } else {
1361 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1362 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001363 }
Shuo Qian4a594052020-01-23 11:59:30 -08001364 break;
Hall Liu27d24262020-09-18 19:04:59 -07001365 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001366 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1367 ar = (AsyncResult) msg.obj;
1368 request = (MainThreadRequest) ar.userObj;
1369 CellNetworkScanResult cellScanResult;
1370 if (ar.exception == null && ar.result != null) {
1371 cellScanResult = new CellNetworkScanResult(
1372 CellNetworkScanResult.STATUS_SUCCESS,
1373 (List<OperatorInfo>) ar.result);
1374 } else {
1375 if (ar.result == null) {
1376 loge("getCellNetworkScanResults: Empty response");
1377 }
1378 if (ar.exception != null) {
1379 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1380 }
1381 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1382 if (ar.exception instanceof CommandException) {
1383 CommandException.Error error =
1384 ((CommandException) (ar.exception)).getCommandError();
1385 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1386 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1387 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1388 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1389 }
1390 }
1391 cellScanResult = new CellNetworkScanResult(errorCode, null);
1392 }
1393 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001394 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001395 break;
1396
1397 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1398 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001399 ManualNetworkSelectionArgument selArg =
1400 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001401 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1402 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001403 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1404 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001405 break;
1406
1407 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001408 ar = (AsyncResult) msg.obj;
1409 request = (MainThreadRequest) ar.userObj;
1410 if (ar.exception == null) {
1411 request.result = true;
1412 } else {
1413 request.result = false;
1414 loge("setNetworkSelectionModeManual " + ar.exception);
1415 }
1416 notifyRequester(request);
1417 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001418 break;
1419
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001420 case CMD_GET_MODEM_ACTIVITY_INFO:
1421 request = (MainThreadRequest) msg.obj;
1422 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001423 if (defaultPhone != null) {
1424 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001425 } else {
1426 ResultReceiver result = (ResultReceiver) request.argument;
1427 Bundle bundle = new Bundle();
1428 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001429 new ModemActivityInfo(0, 0, 0,
1430 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001431 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001432 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001433 break;
1434
Hall Liud0f208c2020-10-14 16:54:44 -07001435 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001436 ar = (AsyncResult) msg.obj;
1437 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001438 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001439 int error = 0;
Gary Jian3aa9a762022-01-24 16:41:19 +08001440 if (mLastModemActivityInfo == null) {
1441 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1442 mLastModemActivitySpecificInfo[0] =
1443 new ActivityStatsTechSpecificInfo(
1444 0,
1445 0,
1446 new int[ModemActivityInfo.getNumTxPowerLevels()],
1447 0);
1448 mLastModemActivityInfo =
1449 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1450 }
1451
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001452 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001453 // Update the last modem activity info and the result of the request.
1454 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1455 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001456 mergeModemActivityInfo(info);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001457 }
Gary Jian3aa9a762022-01-24 16:41:19 +08001458 mLastModemActivityInfo =
1459 new ModemActivityInfo(
1460 mLastModemActivityInfo.getTimestampMillis(),
1461 mLastModemActivityInfo.getSleepTimeMillis(),
1462 mLastModemActivityInfo.getIdleTimeMillis(),
1463 mLastModemActivitySpecificInfo);
1464
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001465 } else {
1466 if (ar.result == null) {
1467 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001468 error = TelephonyManager.ModemActivityInfoException
1469 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001470 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001471 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001472 error = TelephonyManager.ModemActivityInfoException
1473 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001474 } else {
1475 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001476 error = TelephonyManager.ModemActivityInfoException
1477 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001478 }
1479 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001480 Bundle bundle = new Bundle();
Gary Jian3aa9a762022-01-24 16:41:19 +08001481 if (mLastModemActivityInfo != null) {
1482 bundle.putParcelable(
1483 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1484 mLastModemActivityInfo);
Hall Liud0f208c2020-10-14 16:54:44 -07001485 } else {
1486 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1487 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001488 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001489 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001490 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001491 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001492
Meng Wang1a7c35a2016-05-05 20:56:15 -07001493 case CMD_SET_ALLOWED_CARRIERS:
1494 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001495 CarrierRestrictionRules argument =
1496 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001497 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001498 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001499 break;
1500
1501 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1502 ar = (AsyncResult) msg.obj;
1503 request = (MainThreadRequest) ar.userObj;
1504 if (ar.exception == null && ar.result != null) {
1505 request.result = ar.result;
1506 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001507 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1508 if (ar.exception instanceof CommandException) {
1509 loge("setAllowedCarriers: CommandException: " + ar.exception);
1510 CommandException.Error error =
1511 ((CommandException) (ar.exception)).getCommandError();
1512 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1513 request.result =
1514 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1515 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001516 } else {
1517 loge("setAllowedCarriers: Unknown exception");
1518 }
1519 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001520 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001521 break;
1522
1523 case CMD_GET_ALLOWED_CARRIERS:
1524 request = (MainThreadRequest) msg.obj;
1525 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001526 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001527 break;
1528
1529 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1530 ar = (AsyncResult) msg.obj;
1531 request = (MainThreadRequest) ar.userObj;
1532 if (ar.exception == null && ar.result != null) {
1533 request.result = ar.result;
1534 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001535 request.result = new IllegalStateException(
1536 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001537 if (ar.result == null) {
1538 loge("getAllowedCarriers: Empty response");
1539 } else if (ar.exception instanceof CommandException) {
1540 loge("getAllowedCarriers: CommandException: " +
1541 ar.exception);
1542 } else {
1543 loge("getAllowedCarriers: Unknown exception");
1544 }
1545 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001546 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001547 break;
1548
Nathan Haroldb3014052017-01-25 15:57:32 -08001549 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1550 ar = (AsyncResult) msg.obj;
1551 request = (MainThreadRequest) ar.userObj;
1552 if (ar.exception == null && ar.result != null) {
1553 request.result = ar.result;
1554 } else {
1555 request.result = new IllegalArgumentException(
1556 "Failed to retrieve Forbidden Plmns");
1557 if (ar.result == null) {
1558 loge("getForbiddenPlmns: Empty response");
1559 } else {
1560 loge("getForbiddenPlmns: Unknown exception");
1561 }
1562 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001563 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001564 break;
1565
1566 case CMD_GET_FORBIDDEN_PLMNS:
1567 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001568 uiccPort = getUiccPortFromRequest(request);
1569 if (uiccPort == null) {
1570 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001571 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001572 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001573 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001574 break;
1575 }
1576 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001577 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001578 if (uiccApp == null) {
1579 loge("getForbiddenPlmns() no app with specified type -- "
1580 + appType);
1581 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001582 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001583 break;
1584 } else {
1585 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1586 + " specified type -- " + appType);
1587 }
1588 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1589 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1590 onCompleted);
1591 break;
1592
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001593 case CMD_SWITCH_SLOTS:
1594 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001595 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001596 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001597 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001598 break;
1599
1600 case EVENT_SWITCH_SLOTS_DONE:
1601 ar = (AsyncResult) msg.obj;
1602 request = (MainThreadRequest) ar.userObj;
1603 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001604 notifyRequester(request);
1605 break;
1606 case CMD_GET_NETWORK_SELECTION_MODE:
1607 request = (MainThreadRequest) msg.obj;
1608 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1609 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1610 break;
1611
1612 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1613 ar = (AsyncResult) msg.obj;
1614 request = (MainThreadRequest) ar.userObj;
1615 if (ar.exception != null) {
1616 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1617 } else {
1618 int mode = ((int[]) ar.result)[0];
1619 if (mode == 0) {
1620 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1621 } else {
1622 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1623 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001624 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001625 notifyRequester(request);
1626 break;
1627 case CMD_GET_CDMA_ROAMING_MODE:
1628 request = (MainThreadRequest) msg.obj;
1629 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1630 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1631 break;
1632 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1633 ar = (AsyncResult) msg.obj;
1634 request = (MainThreadRequest) ar.userObj;
1635 if (ar.exception != null) {
1636 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1637 } else {
1638 request.result = ((int[]) ar.result)[0];
1639 }
1640 notifyRequester(request);
1641 break;
1642 case CMD_SET_CDMA_ROAMING_MODE:
1643 request = (MainThreadRequest) msg.obj;
1644 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1645 int mode = (int) request.argument;
1646 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1647 break;
1648 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1649 ar = (AsyncResult) msg.obj;
1650 request = (MainThreadRequest) ar.userObj;
1651 request.result = ar.exception == null;
1652 notifyRequester(request);
1653 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001654 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1655 request = (MainThreadRequest) msg.obj;
1656 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1657 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1658 break;
1659 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1660 ar = (AsyncResult) msg.obj;
1661 request = (MainThreadRequest) ar.userObj;
1662 if (ar.exception != null) {
1663 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1664 } else {
1665 request.result = ((int[]) ar.result)[0];
1666 }
1667 notifyRequester(request);
1668 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001669 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1670 request = (MainThreadRequest) msg.obj;
1671 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1672 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001673 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1674 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001675 break;
1676 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1677 ar = (AsyncResult) msg.obj;
1678 request = (MainThreadRequest) ar.userObj;
1679 request.result = ar.exception == null;
1680 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001681 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001682 case CMD_GET_ALL_CELL_INFO:
1683 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001684 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001685 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001686 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001687 case EVENT_GET_ALL_CELL_INFO_DONE:
1688 ar = (AsyncResult) msg.obj;
1689 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001690 // If a timeout occurs, the response will be null
1691 request.result = (ar.exception == null && ar.result != null)
1692 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001693 synchronized (request) {
1694 request.notifyAll();
1695 }
1696 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001697 case CMD_REQUEST_CELL_INFO_UPDATE:
1698 request = (MainThreadRequest) msg.obj;
1699 request.phone.requestCellInfoUpdate(request.workSource,
1700 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1701 break;
1702 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1703 ar = (AsyncResult) msg.obj;
1704 request = (MainThreadRequest) ar.userObj;
1705 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1706 try {
1707 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001708 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001709 cb.onError(
1710 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1711 ar.exception.getClass().getName(),
1712 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001713 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001714 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001715 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001716 } else {
1717 // use the result as returned
1718 cb.onCellInfo((List<CellInfo>) ar.result);
1719 }
1720 } catch (RemoteException re) {
1721 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1722 }
1723 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001724 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001725 request = (MainThreadRequest) msg.obj;
1726 WorkSource ws = (WorkSource) request.argument;
1727 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001728 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001729 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001730 }
1731 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001732 ar = (AsyncResult) msg.obj;
1733 request = (MainThreadRequest) ar.userObj;
1734 if (ar.exception == null) {
1735 request.result = ar.result;
1736 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001737 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001738 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001739 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001740 }
1741
1742 synchronized (request) {
1743 request.notifyAll();
1744 }
1745 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001746 }
chen xu6dac5ab2018-10-26 17:39:23 -07001747 case CMD_MODEM_REBOOT:
1748 request = (MainThreadRequest) msg.obj;
1749 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001750 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001751 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001752 case EVENT_CMD_MODEM_REBOOT_DONE:
1753 handleNullReturnEvent(msg, "rebootModem");
1754 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001755 case CMD_REQUEST_ENABLE_MODEM:
1756 request = (MainThreadRequest) msg.obj;
1757 boolean enable = (boolean) request.argument;
1758 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001759 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001760 PhoneConfigurationManager.getInstance()
1761 .enablePhone(request.phone, enable, onCompleted);
1762 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001763 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001764 ar = (AsyncResult) msg.obj;
1765 request = (MainThreadRequest) ar.userObj;
1766 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001767 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001768 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001769 if ((boolean) request.result) {
1770 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1771 updateModemStateMetrics();
1772 } else {
1773 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1774 + ar.exception);
1775 }
1776 notifyRequester(request);
1777 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001778 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001779 case CMD_GET_MODEM_STATUS:
1780 request = (MainThreadRequest) msg.obj;
1781 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1782 PhoneConfigurationManager.getInstance()
1783 .getPhoneStatusFromModem(request.phone, onCompleted);
1784 break;
1785 case EVENT_GET_MODEM_STATUS_DONE:
1786 ar = (AsyncResult) msg.obj;
1787 request = (MainThreadRequest) ar.userObj;
1788 int id = request.phone.getPhoneId();
1789 if (ar.exception == null && ar.result != null) {
1790 request.result = ar.result;
1791 //update the cache as modem status has changed
1792 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1793 (boolean) request.result);
1794 } else {
1795 // Return true if modem status cannot be retrieved. For most cases,
1796 // modem status is on. And for older version modems, GET_MODEM_STATUS
1797 // and disable modem are not supported. Modem is always on.
1798 // TODO: this should be fixed in R to support a third
1799 // status UNKNOWN b/131631629
1800 request.result = true;
1801 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1802 + ar.exception);
1803 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001804 notifyRequester(request);
1805 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001806 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1807 request = (MainThreadRequest) msg.obj;
1808 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1809 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1810 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1811 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1812 break;
1813 }
1814 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1815 ar = (AsyncResult) msg.obj;
1816 request = (MainThreadRequest) ar.userObj;
1817 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1818 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1819 args.second.accept(ar.exception == null);
1820 notifyRequester(request);
1821 break;
1822 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001823 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1824 request = (MainThreadRequest) msg.obj;
1825 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1826 Phone phone = getPhoneFromRequest(request);
1827 if (phone != null) {
1828 phone.getSystemSelectionChannels(onCompleted);
1829 } else {
1830 loge("getSystemSelectionChannels: No phone object");
1831 request.result = new ArrayList<RadioAccessSpecifier>();
1832 notifyRequester(request);
1833 }
1834 break;
1835 }
1836 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1837 ar = (AsyncResult) msg.obj;
1838 request = (MainThreadRequest) ar.userObj;
1839 if (ar.exception == null && ar.result != null) {
1840 request.result = ar.result;
1841 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001842 request.result = new IllegalStateException(
1843 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001844 if (ar.result == null) {
1845 loge("getSystemSelectionChannels: Empty response");
1846 } else {
1847 loge("getSystemSelectionChannels: Unknown exception");
1848 }
1849 }
1850 notifyRequester(request);
1851 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001852 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1853 ar = (AsyncResult) msg.obj;
1854 request = (MainThreadRequest) ar.userObj;
1855 if (ar.exception == null && ar.result != null) {
1856 request.result = ar.result;
1857 } else {
1858 request.result = -1;
1859 loge("Failed to set Forbidden Plmns");
1860 if (ar.result == null) {
1861 loge("setForbidenPlmns: Empty response");
1862 } else if (ar.exception != null) {
1863 loge("setForbiddenPlmns: Exception: " + ar.exception);
1864 request.result = -1;
1865 } else {
1866 loge("setForbiddenPlmns: Unknown exception");
1867 }
1868 }
1869 notifyRequester(request);
1870 break;
1871 case CMD_SET_FORBIDDEN_PLMNS:
1872 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001873 uiccPort = getUiccPortFromRequest(request);
1874 if (uiccPort == null) {
1875 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001876 request.result = -1;
1877 notifyRequester(request);
1878 break;
1879 }
1880 Pair<Integer, List<String>> setFplmnsArgs =
1881 (Pair<Integer, List<String>>) request.argument;
1882 appType = setFplmnsArgs.first;
1883 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001884 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001885 if (uiccApp == null) {
1886 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1887 request.result = -1;
1888 loge("Failed to get UICC App");
1889 notifyRequester(request);
1890 } else {
1891 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1892 ((SIMRecords) uiccApp.getIccRecords())
1893 .setForbiddenPlmns(onCompleted, fplmns);
1894 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001895 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001896 case CMD_ERASE_MODEM_CONFIG:
1897 request = (MainThreadRequest) msg.obj;
1898 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1899 defaultPhone.eraseModemConfig(onCompleted);
1900 break;
1901 case EVENT_ERASE_MODEM_CONFIG_DONE:
1902 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001903 break;
zoey chene02881a2019-12-30 16:11:23 +08001904
Kai Shif70f46f2021-03-03 13:59:46 -08001905 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1906 request = (MainThreadRequest) msg.obj;
1907 request.result = defaultPhone.eraseDataInSharedPreferences();
1908 notifyRequester(request);
1909 break;
1910
zoey chene02881a2019-12-30 16:11:23 +08001911 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1912 request = (MainThreadRequest) msg.obj;
1913 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1914 Pair<String, String> changed = (Pair<String, String>) request.argument;
1915 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1916 changed.first, changed.second, onCompleted);
1917 break;
1918 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1919 ar = (AsyncResult) msg.obj;
1920 request = (MainThreadRequest) ar.userObj;
1921 if (ar.exception == null) {
1922 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001923 // If the operation is successful, update the PIN storage
1924 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1925 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001926 UiccController.getInstance().getPinStorage()
1927 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001928 } else {
1929 request.result = msg.arg1;
1930 }
1931 notifyRequester(request);
1932 break;
1933
Michele Berionne5e411512020-11-13 02:36:59 +00001934 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001935 request = (MainThreadRequest) msg.obj;
1936 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1937 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1938 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1939 enabled.first, enabled.second, onCompleted);
1940 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001941 }
zoey chene02881a2019-12-30 16:11:23 +08001942 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1943 ar = (AsyncResult) msg.obj;
1944 request = (MainThreadRequest) ar.userObj;
1945 if (ar.exception == null) {
1946 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001947 // If the operation is successful, update the PIN storage
1948 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1949 int phoneId = getPhoneFromRequest(request).getPhoneId();
1950 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001951 UiccController.getInstance().getPinStorage()
1952 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001953 } else {
1954 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1955 }
zoey chene02881a2019-12-30 16:11:23 +08001956 } else {
1957 request.result = msg.arg1;
1958 }
Michele Berionne5e411512020-11-13 02:36:59 +00001959
1960
zoey chene02881a2019-12-30 16:11:23 +08001961 notifyRequester(request);
1962 break;
1963
Peter Wangdafb9ac2020-01-15 14:13:38 -08001964 case MSG_NOTIFY_USER_ACTIVITY:
1965 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001966 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001967 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1968 getDefaultPhone().getContext().sendBroadcastAsUser(
1969 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1970 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001971
1972 case CMD_SET_DATA_THROTTLING: {
1973 request = (MainThreadRequest) msg.obj;
1974 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1975 DataThrottlingRequest dataThrottlingRequest =
1976 (DataThrottlingRequest) request.argument;
1977 Phone phone = getPhoneFromRequest(request);
1978 if (phone != null) {
1979 phone.setDataThrottling(onCompleted,
1980 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1981 dataThrottlingRequest.getCompletionDurationMillis());
1982 } else {
1983 loge("setDataThrottling: No phone object");
1984 request.result =
1985 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1986 notifyRequester(request);
1987 }
1988
1989 break;
1990 }
1991 case EVENT_SET_DATA_THROTTLING_DONE:
1992 ar = (AsyncResult) msg.obj;
1993 request = (MainThreadRequest) ar.userObj;
1994
1995 if (ar.exception == null) {
1996 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1997 } else if (ar.exception instanceof CommandException) {
1998 loge("setDataThrottling: CommandException: " + ar.exception);
1999 CommandException.Error error =
2000 ((CommandException) (ar.exception)).getCommandError();
2001
2002 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2003 request.result = TelephonyManager
2004 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2005 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2006 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002007 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2008 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002009 } else {
2010 request.result =
2011 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2012 }
2013 } else {
2014 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2015 }
2016 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2017 notifyRequester(request);
2018 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002019
2020 case CMD_SET_SIM_POWER: {
2021 request = (MainThreadRequest) msg.obj;
2022 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2023 request = (MainThreadRequest) msg.obj;
2024 int stateToSet =
2025 ((Pair<Integer, IIntegerConsumer>)
2026 request.argument).first;
2027 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2028 break;
2029 }
2030 case EVENT_SET_SIM_POWER_DONE: {
2031 ar = (AsyncResult) msg.obj;
2032 request = (MainThreadRequest) ar.userObj;
2033 IIntegerConsumer callback =
2034 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2035 if (ar.exception != null) {
2036 loge("setSimPower exception: " + ar.exception);
2037 int errorCode = TelephonyManager.CallForwardingInfoCallback
2038 .RESULT_ERROR_UNKNOWN;
2039 if (ar.exception instanceof CommandException) {
2040 CommandException.Error error =
2041 ((CommandException) (ar.exception)).getCommandError();
2042 if (error == CommandException.Error.SIM_ERR) {
2043 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2044 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2045 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2046 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2047 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2048 } else {
2049 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2050 }
2051 }
2052 try {
2053 callback.accept(errorCode);
2054 } catch (RemoteException e) {
2055 // Ignore if the remote process is no longer available to call back.
2056 Log.w(LOG_TAG, "setSimPower: callback not available.");
2057 }
2058 } else {
2059 try {
2060 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2061 } catch (RemoteException e) {
2062 // Ignore if the remote process is no longer available to call back.
2063 Log.w(LOG_TAG, "setSimPower: callback not available.");
2064 }
2065 }
2066 break;
2067 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002068 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2069 request = (MainThreadRequest) msg.obj;
2070
2071 final Phone phone = getPhoneFromRequest(request);
2072 if (phone == null || phone.getServiceStateTracker() == null) {
2073 request.result = new IllegalStateException("Phone or SST is null");
2074 notifyRequester(request);
2075 break;
2076 }
2077
2078 Pair<Integer, SignalStrengthUpdateRequest> pair =
2079 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2080 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2081 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002082 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002083 request.subId, pair.first /*callingUid*/,
2084 pair.second /*request*/, onCompleted);
2085 break;
2086 }
2087 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2088 ar = (AsyncResult) msg.obj;
2089 request = (MainThreadRequest) ar.userObj;
2090 // request.result will be the exception of ar if present, true otherwise.
2091 // Be cautious not to leave result null which will wait() forever
2092 request.result = ar.exception != null ? ar.exception : true;
2093 notifyRequester(request);
2094 break;
2095 }
2096 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2097 request = (MainThreadRequest) msg.obj;
2098
2099 Phone phone = getPhoneFromRequest(request);
2100 if (phone == null || phone.getServiceStateTracker() == null) {
2101 request.result = new IllegalStateException("Phone or SST is null");
2102 notifyRequester(request);
2103 break;
2104 }
2105
2106 Pair<Integer, SignalStrengthUpdateRequest> pair =
2107 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2108 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2109 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002110 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002111 request.subId, pair.first /*callingUid*/,
2112 pair.second /*request*/, onCompleted);
2113 break;
2114 }
2115 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2116 ar = (AsyncResult) msg.obj;
2117 request = (MainThreadRequest) ar.userObj;
2118 request.result = ar.exception != null ? ar.exception : true;
2119 notifyRequester(request);
2120 break;
2121 }
Jordan Liu109698e2020-11-24 14:50:34 -08002122
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002123 case CMD_GET_SLICING_CONFIG: {
2124 request = (MainThreadRequest) msg.obj;
2125 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2126 request.phone.getSlicingConfig(onCompleted);
2127 break;
2128 }
2129 case EVENT_GET_SLICING_CONFIG_DONE: {
2130 ar = (AsyncResult) msg.obj;
2131 request = (MainThreadRequest) ar.userObj;
2132 ResultReceiver result = (ResultReceiver) request.argument;
2133
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002134 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002135 Bundle bundle = new Bundle();
2136 int resultCode = 0;
2137 if (ar.exception != null) {
2138 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2139 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002140 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002141 } else if (ar.result == null) {
2142 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002143 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002144 } else {
2145 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002146 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2147 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002148 }
2149
2150 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002151 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002152 }
2153 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2154 result.send(resultCode, bundle);
2155 notifyRequester(request);
2156 break;
2157 }
2158
Sarah Chin71b3a852022-09-28 15:54:19 -07002159 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002160 request = (MainThreadRequest) msg.obj;
2161 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002162 PurchasePremiumCapabilityArgument arg =
2163 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin46355ba2022-11-01 23:51:16 -07002164 SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability(
Sarah Chin71b3a852022-09-28 15:54:19 -07002165 arg.capability, arg.appName, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002166 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002167 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002168
Sarah Chin71b3a852022-09-28 15:54:19 -07002169 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002170 ar = (AsyncResult) msg.obj;
2171 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002172 PurchasePremiumCapabilityArgument arg =
2173 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002174 try {
2175 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002176 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002177 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002178 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002179 + ", result= "
2180 + TelephonyManager.convertPurchaseResultToString(result));
2181 } catch (RemoteException e) {
2182 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002183 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002184 + " failed: " + e;
2185 if (DBG) log(logStr);
2186 AnomalyReporter.reportAnomaly(
2187 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2188 }
2189 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002190 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002191
Michele Berionne5e411512020-11-13 02:36:59 +00002192 case CMD_PREPARE_UNATTENDED_REBOOT:
2193 request = (MainThreadRequest) msg.obj;
2194 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002195 UiccController.getInstance().getPinStorage()
2196 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002197 notifyRequester(request);
2198 break;
2199
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002200 default:
2201 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2202 break;
2203 }
2204 }
Jake Hambye994d462014-02-03 13:10:13 -08002205
Pengquan Menga1bb6272018-09-06 09:59:22 -07002206 private void notifyRequester(MainThreadRequest request) {
2207 synchronized (request) {
2208 request.notifyAll();
2209 }
2210 }
2211
Jake Hambye994d462014-02-03 13:10:13 -08002212 private void handleNullReturnEvent(Message msg, String command) {
2213 AsyncResult ar = (AsyncResult) msg.obj;
2214 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2215 if (ar.exception == null) {
2216 request.result = true;
2217 } else {
2218 request.result = false;
2219 if (ar.exception instanceof CommandException) {
2220 loge(command + ": CommandException: " + ar.exception);
2221 } else {
2222 loge(command + ": Unknown exception");
2223 }
2224 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002225 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002226 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002227 }
2228
2229 /**
2230 * Posts the specified command to be executed on the main thread,
2231 * waits for the request to complete, and returns the result.
2232 * @see #sendRequestAsync
2233 */
2234 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002235 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2236 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002237 }
2238
2239 /**
2240 * Posts the specified command to be executed on the main thread,
2241 * waits for the request to complete, and returns the result.
2242 * @see #sendRequestAsync
2243 */
2244 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2245 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002246 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002247 }
2248
2249 /**
2250 * Posts the specified command to be executed on the main thread,
2251 * waits for the request to complete, and returns the result.
2252 * @see #sendRequestAsync
2253 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002254 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002255 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2256 }
2257
2258 /**
2259 * Posts the specified command to be executed on the main thread,
2260 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2261 * if not timeout or null otherwise.
2262 * @see #sendRequestAsync
2263 */
2264 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2265 long timeoutInMs) {
2266 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002267 }
2268
2269 /**
2270 * Posts the specified command to be executed on the main thread,
2271 * waits for the request to complete, and returns the result.
2272 * @see #sendRequestAsync
2273 */
Nathan Harold92bed182018-10-12 18:16:49 -07002274 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002275 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002276 }
2277
2278 /**
2279 * Posts the specified command to be executed on the main thread,
2280 * waits for the request to complete, and returns the result.
2281 * @see #sendRequestAsync
2282 */
2283 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002284 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2285 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002286 }
2287
2288 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002289 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2290 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2291 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002292 * @see #sendRequestAsync
2293 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002294 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2295 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002296 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2297 throw new RuntimeException("This method will deadlock if called from the main thread.");
2298 }
2299
Nathan Harold92bed182018-10-12 18:16:49 -07002300 MainThreadRequest request = null;
2301 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2302 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2303 } else if (phone != null) {
2304 request = new MainThreadRequest(argument, phone, workSource);
2305 } else {
2306 request = new MainThreadRequest(argument, subId, workSource);
2307 }
2308
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002309 Message msg = mMainThreadHandler.obtainMessage(command, request);
2310 msg.sendToTarget();
2311
Rambo Wang0f050d82021-02-12 11:43:36 -08002312
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002313 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002314 if (timeoutInMs >= 0) {
2315 // Wait for at least timeoutInMs before returning null request result
2316 long now = SystemClock.elapsedRealtime();
2317 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002318 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002319 try {
2320 request.wait(deadline - now);
2321 } catch (InterruptedException e) {
2322 // Do nothing, go back and check if request is completed or timeout
2323 } finally {
2324 now = SystemClock.elapsedRealtime();
2325 }
2326 }
2327 } else {
2328 // Wait for the request to complete
2329 while (request.result == null) {
2330 try {
2331 request.wait();
2332 } catch (InterruptedException e) {
2333 // Do nothing, go back and wait until the request is complete
2334 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002335 }
2336 }
2337 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002338 if (request.result == null) {
2339 Log.wtf(LOG_TAG,
2340 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2341 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002342 return request.result;
2343 }
2344
2345 /**
2346 * Asynchronous ("fire and forget") version of sendRequest():
2347 * Posts the specified command to be executed on the main thread, and
2348 * returns immediately.
2349 * @see #sendRequest
2350 */
2351 private void sendRequestAsync(int command) {
2352 mMainThreadHandler.sendEmptyMessage(command);
2353 }
2354
2355 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002356 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002357 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002358 */
2359 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002360 sendRequestAsync(command, argument, null, null);
2361 }
2362
2363 /**
2364 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2365 * @see {@link #sendRequest(int,Object)}
2366 */
2367 private void sendRequestAsync(
2368 int command, Object argument, Phone phone, WorkSource workSource) {
2369 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002370 Message msg = mMainThreadHandler.obtainMessage(command, request);
2371 msg.sendToTarget();
2372 }
2373
2374 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002375 * Initialize the singleton PhoneInterfaceManager instance.
2376 * This is only done once, at startup, from PhoneApp.onCreate().
2377 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002378 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002379 synchronized (PhoneInterfaceManager.class) {
2380 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002381 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002382 } else {
2383 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2384 }
2385 return sInstance;
2386 }
2387 }
2388
2389 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002390 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002391 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002392 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002393 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002394 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002395 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002396 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002397 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002398 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002399 mTelephonySharedPreferences =
2400 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002401 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002402 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002403 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002404 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002405 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Gil Cukierman6dac5eb2022-09-19 16:09:04 +00002406 mTelephony2gUpdater = new Telephony2gUpdater(
2407 Executors.newSingleThreadExecutor(), mApp);
2408 mTelephony2gUpdater.init();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002409 publish();
2410 }
2411
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002412 private Phone getDefaultPhone() {
2413 Phone thePhone = getPhone(getDefaultSubscription());
2414 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2415 }
2416
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002417 private void publish() {
2418 if (DBG) log("publish: " + this);
2419
Peter Wangc035ce42020-01-08 21:00:22 -08002420 TelephonyFrameworkInitializer
2421 .getTelephonyServiceManager()
2422 .getTelephonyServiceRegisterer()
2423 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002424 }
2425
Stuart Scott584921c2015-01-15 17:10:34 -08002426 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002427 if (request.phone != null) {
2428 return request.phone;
2429 } else {
2430 return getPhoneFromSubId(request.subId);
2431 }
2432 }
2433
2434 private Phone getPhoneFromSubId(int subId) {
2435 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2436 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002437 }
2438
Rambo Wange53e07d2022-05-10 13:01:13 -07002439 @Nullable
2440 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002441 Phone phone = getPhoneFromRequest(request);
2442 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002443 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002444 }
2445
Wink Saville36469e72014-06-11 15:17:00 -07002446 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002447 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002448 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002449 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002450
Kai Shif70f46f2021-03-03 13:59:46 -08002451 private void sendEraseModemConfig(@NonNull Phone phone) {
2452 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2453 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2454 }
2455
2456 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2457 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2458 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002459 }
2460
Peter Wang44b186e2020-01-13 23:33:09 -08002461 private boolean isImsAvailableOnDevice() {
2462 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2463 if (pm == null) {
2464 // For some reason package manger is not available.. This will fail internally anyway,
2465 // so do not throw error and allow.
2466 return true;
2467 }
2468 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2469 }
2470
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002471 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002472 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002473 }
2474
Wink Savilleb564aae2014-10-23 10:18:09 -07002475 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002476 if (DBG) log("dial: " + number);
2477 // No permission check needed here: This is just a wrapper around the
2478 // ACTION_DIAL intent, which is available to any app since it puts up
2479 // the UI before it does anything.
2480
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002481 final long identity = Binder.clearCallingIdentity();
2482 try {
2483 String url = createTelUrl(number);
2484 if (url == null) {
2485 return;
2486 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002487
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002488 // PENDING: should we just silently fail if phone is offhook or ringing?
2489 PhoneConstants.State state = mCM.getState(subId);
2490 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2491 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2492 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2493 mApp.startActivity(intent);
2494 }
2495 } finally {
2496 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002497 }
2498 }
2499
2500 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002501 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002502 }
2503
Wink Savilleb564aae2014-10-23 10:18:09 -07002504 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002505 if (DBG) log("call: " + number);
2506
2507 // This is just a wrapper around the ACTION_CALL intent, but we still
2508 // need to do a permission check since we're calling startActivity()
2509 // from the context of the phone app.
2510 enforceCallPermission();
2511
Jordan Liu1617b712019-07-10 15:06:26 -07002512 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002513 != AppOpsManager.MODE_ALLOWED) {
2514 return;
2515 }
2516
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002517 final long identity = Binder.clearCallingIdentity();
2518 try {
2519 String url = createTelUrl(number);
2520 if (url == null) {
2521 return;
2522 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002523
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002524 boolean isValid = false;
2525 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2526 if (slist != null) {
2527 for (SubscriptionInfo subInfoRecord : slist) {
2528 if (subInfoRecord.getSubscriptionId() == subId) {
2529 isValid = true;
2530 break;
2531 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002532 }
Wink Saville08874612014-08-31 19:19:58 -07002533 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002534 if (!isValid) {
2535 return;
2536 }
Wink Saville08874612014-08-31 19:19:58 -07002537
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002538 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2539 intent.putExtra(SUBSCRIPTION_KEY, subId);
2540 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2541 mApp.startActivity(intent);
2542 } finally {
2543 Binder.restoreCallingIdentity(identity);
2544 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002545 }
2546
Wink Savilleb564aae2014-10-23 10:18:09 -07002547 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002548 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002549 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2550 }
2551
Wink Savilleb564aae2014-10-23 10:18:09 -07002552 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002553 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002554 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2555 }
2556
Wink Savilleb564aae2014-10-23 10:18:09 -07002557 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002558 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002559
2560 final long identity = Binder.clearCallingIdentity();
2561 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002562 Phone phone = getPhone(subId);
2563 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002564 checkSimPin.start();
2565 return checkSimPin.unlockSim(null, pin);
2566 } finally {
2567 Binder.restoreCallingIdentity(identity);
2568 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002569 }
2570
Wink Savilleb564aae2014-10-23 10:18:09 -07002571 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002572 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002573
2574 final long identity = Binder.clearCallingIdentity();
2575 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002576 Phone phone = getPhone(subId);
2577 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002578 checkSimPuk.start();
2579 return checkSimPuk.unlockSim(puk, pin);
2580 } finally {
2581 Binder.restoreCallingIdentity(identity);
2582 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002583 }
2584
2585 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002586 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002587 * a synchronous one.
2588 */
2589 private static class UnlockSim extends Thread {
2590
2591 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002592 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002593
2594 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002595 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2596 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002597
2598 // For replies from SimCard interface
2599 private Handler mHandler;
2600
2601 // For async handler to identify request type
2602 private static final int SUPPLY_PIN_COMPLETE = 100;
2603
Michele Berionne5e411512020-11-13 02:36:59 +00002604 UnlockSim(int phoneId, IccCard simCard) {
2605 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002606 mSimCard = simCard;
2607 }
2608
2609 @Override
2610 public void run() {
2611 Looper.prepare();
2612 synchronized (UnlockSim.this) {
2613 mHandler = new Handler() {
2614 @Override
2615 public void handleMessage(Message msg) {
2616 AsyncResult ar = (AsyncResult) msg.obj;
2617 switch (msg.what) {
2618 case SUPPLY_PIN_COMPLETE:
2619 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2620 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002621 mRetryCount = msg.arg1;
2622 if (ar.exception != null) {
2623 if (ar.exception instanceof CommandException &&
2624 ((CommandException)(ar.exception)).getCommandError()
2625 == CommandException.Error.PASSWORD_INCORRECT) {
2626 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002627 } //When UiccCardApp dispose,handle message and return exception
2628 else if (ar.exception instanceof CommandException &&
2629 ((CommandException) (ar.exception)).getCommandError()
2630 == CommandException.Error.ABORTED) {
2631 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002632 } else {
2633 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2634 }
2635 } else {
2636 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2637 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002638 mDone = true;
2639 UnlockSim.this.notifyAll();
2640 }
2641 break;
2642 }
2643 }
2644 };
2645 UnlockSim.this.notifyAll();
2646 }
2647 Looper.loop();
2648 }
2649
2650 /*
2651 * Use PIN or PUK to unlock SIM card
2652 *
2653 * If PUK is null, unlock SIM card with PIN
2654 *
2655 * If PUK is not null, unlock SIM card with PUK and set PIN code
2656 */
Wink Saville9de0f752013-10-22 19:04:03 -07002657 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002658
2659 while (mHandler == null) {
2660 try {
2661 wait();
2662 } catch (InterruptedException e) {
2663 Thread.currentThread().interrupt();
2664 }
2665 }
2666 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2667
2668 if (puk == null) {
2669 mSimCard.supplyPin(pin, callback);
2670 } else {
2671 mSimCard.supplyPuk(puk, pin, callback);
2672 }
2673
2674 while (!mDone) {
2675 try {
2676 Log.d(LOG_TAG, "wait for done");
2677 wait();
2678 } catch (InterruptedException e) {
2679 // Restore the interrupted status
2680 Thread.currentThread().interrupt();
2681 }
2682 }
2683 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002684 int[] resultArray = new int[2];
2685 resultArray[0] = mResult;
2686 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002687
2688 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002689 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002690 }
2691
Wink Saville9de0f752013-10-22 19:04:03 -07002692 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002693 }
2694 }
2695
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002696 /**
2697 * This method has been removed due to privacy and stability concerns.
2698 */
2699 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002700 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002701 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2702 return;
Wink Saville36469e72014-06-11 15:17:00 -07002703 }
2704
Nathan Harold1f889d82020-06-04 17:05:26 -07002705 @Override
2706 public void updateServiceLocationWithPackageName(String callingPackage) {
2707 mApp.getSystemService(AppOpsManager.class)
2708 .checkPackage(Binder.getCallingUid(), callingPackage);
2709
Nathan Haroldf096d982020-11-18 17:18:06 -08002710 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002711 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2712 // Callers targeting S have no business invoking this method.
2713 return;
2714 }
2715
2716 LocationAccessPolicy.LocationPermissionResult locationResult =
2717 LocationAccessPolicy.checkLocationPermission(mApp,
2718 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2719 .setCallingPackage(callingPackage)
2720 .setCallingFeatureId(null)
2721 .setCallingPid(Binder.getCallingPid())
2722 .setCallingUid(Binder.getCallingUid())
2723 .setMethod("updateServiceLocation")
2724 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2725 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2726 .build());
2727 // Apps that lack location permission have no business calling this method;
2728 // however, because no permission was declared in the public API, denials must
2729 // all be "soft".
2730 switch (locationResult) {
2731 case DENIED_HARD: /* fall through */
2732 case DENIED_SOFT:
2733 return;
2734 }
2735
2736 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002737 final long identity = Binder.clearCallingIdentity();
2738 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002739 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002740 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002741 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002742 }
2743 } finally {
2744 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002745 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002746 }
2747
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002748 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002749 @Override
2750 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002751 return isRadioOnWithFeature(callingPackage, null);
2752 }
2753
2754
2755 @Override
2756 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2757 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2758 callingFeatureId);
2759 }
2760
2761 @Deprecated
2762 @Override
2763 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2764 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002765 }
2766
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002767 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002768 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2769 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002770 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002771 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002772 return false;
2773 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002774
2775 final long identity = Binder.clearCallingIdentity();
2776 try {
2777 return isRadioOnForSubscriber(subId);
2778 } finally {
2779 Binder.restoreCallingIdentity(identity);
2780 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002781 }
2782
2783 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002784 final long identity = Binder.clearCallingIdentity();
2785 try {
2786 final Phone phone = getPhone(subId);
2787 if (phone != null) {
2788 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2789 } else {
2790 return false;
2791 }
2792 } finally {
2793 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002794 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002795 }
2796
2797 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002798 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002799 }
Wink Saville36469e72014-06-11 15:17:00 -07002800
Wink Savilleb564aae2014-10-23 10:18:09 -07002801 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002802 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002803
2804 final long identity = Binder.clearCallingIdentity();
2805 try {
2806 final Phone phone = getPhone(subId);
2807 if (phone != null) {
2808 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2809 }
2810 } finally {
2811 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002812 }
Wink Saville36469e72014-06-11 15:17:00 -07002813 }
2814
2815 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002816 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002817 }
2818
Wink Savilleb564aae2014-10-23 10:18:09 -07002819 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002820 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002821
2822 final long identity = Binder.clearCallingIdentity();
2823 try {
2824 final Phone phone = getPhone(subId);
2825 if (phone == null) {
2826 return false;
2827 }
2828 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2829 toggleRadioOnOffForSubscriber(subId);
2830 }
2831 return true;
2832 } finally {
2833 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002834 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002835 }
Wink Saville36469e72014-06-11 15:17:00 -07002836
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002837 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002838 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002839 /*
2840 * If any of the Radios are available, it will need to be
2841 * shutdown. So return true if any Radio is available.
2842 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002843 final long identity = Binder.clearCallingIdentity();
2844 try {
2845 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2846 Phone phone = PhoneFactory.getPhone(i);
2847 if (phone != null && phone.isRadioAvailable()) return true;
2848 }
2849 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2850 return false;
2851 } finally {
2852 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002853 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002854 }
2855
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002856 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002857 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002858 enforceModifyPermission();
2859
2860 final long identity = Binder.clearCallingIdentity();
2861 try {
2862 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2863 logv("Shutting down Phone " + i);
2864 shutdownRadioUsingPhoneId(i);
2865 }
2866 } finally {
2867 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002868 }
2869 }
2870
2871 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002872 Phone phone = PhoneFactory.getPhone(phoneId);
2873 if (phone != null && phone.isRadioAvailable()) {
2874 phone.shutdownRadio();
2875 }
2876 }
2877
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002878 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002879 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002880
2881 final long identity = Binder.clearCallingIdentity();
2882 try {
2883 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2884 if (defaultPhone != null) {
2885 defaultPhone.setRadioPower(turnOn);
2886 return true;
2887 } else {
2888 loge("There's no default phone.");
2889 return false;
2890 }
2891 } finally {
2892 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002893 }
Wink Saville36469e72014-06-11 15:17:00 -07002894 }
2895
Wink Savilleb564aae2014-10-23 10:18:09 -07002896 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002897 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002898
2899 final long identity = Binder.clearCallingIdentity();
2900 try {
2901 final Phone phone = getPhone(subId);
2902 if (phone != null) {
2903 phone.setRadioPower(turnOn);
2904 return true;
2905 } else {
2906 return false;
2907 }
2908 } finally {
2909 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002910 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002911 }
2912
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00002913 /**
2914 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
2915 * no reason to power it off. When any of the voters want to power it off, it will be turned
2916 * off. In case of emergency, the radio will be turned on even if there are some reasons for
2917 * powering it off, and these radio off votes will be cleared.
2918 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
2919 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
2920 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
2921 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
2922 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
2923 * check its vote.
2924 *
2925 * @param subId The subscription ID.
2926 * @param reason The reason for powering off radio.
2927 * @return true on success and false on failure.
2928 */
2929 public boolean requestRadioPowerOffForReason(int subId,
2930 @TelephonyManager.RadioPowerReason int reason) {
2931 enforceModifyPermission();
2932
2933 final long identity = Binder.clearCallingIdentity();
2934 try {
2935 final Phone phone = getPhone(subId);
2936 if (phone != null) {
2937 phone.setRadioPowerForReason(false, reason);
2938 return true;
2939 } else {
2940 return false;
2941 }
2942 } finally {
2943 Binder.restoreCallingIdentity(identity);
2944 }
2945 }
2946
2947 /**
2948 * Remove the vote on powering off the radio for a reason, as requested by
2949 * {@link requestRadioPowerOffForReason}.
2950 *
2951 * @param subId The subscription ID.
2952 * @param reason The reason for powering off radio.
2953 * @return true on success and false on failure.
2954 */
2955 public boolean clearRadioPowerOffForReason(int subId,
2956 @TelephonyManager.RadioPowerReason int reason) {
2957 enforceModifyPermission();
2958
2959 final long identity = Binder.clearCallingIdentity();
2960 try {
2961 final Phone phone = getPhone(subId);
2962 if (phone != null) {
2963 phone.setRadioPowerForReason(true, reason);
2964 return true;
2965 } else {
2966 return false;
2967 }
2968 } finally {
2969 Binder.restoreCallingIdentity(identity);
2970 }
2971 }
2972
2973 /**
2974 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
2975 *
2976 * @param subId The subscription ID.
2977 * @param callingPackage The package making the call.
2978 * @param callingFeatureId The feature in the package.
2979 * @return List of reasons for powering off radio.
2980 */
2981 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
2982 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
2983
2984 final long identity = Binder.clearCallingIdentity();
2985 List result = new ArrayList();
2986 try {
2987 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
2988 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
2989 return result;
2990 }
2991
2992 final Phone phone = getPhone(subId);
2993 if (phone != null) {
2994 result.addAll(phone.getRadioPowerOffReasons());
2995 }
2996 } finally {
2997 Binder.restoreCallingIdentity(identity);
2998 }
2999 return result;
3000 }
3001
Wink Saville36469e72014-06-11 15:17:00 -07003002 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003003 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003004 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003005 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003006
3007 final long identity = Binder.clearCallingIdentity();
3008 try {
3009 int subId = mSubscriptionController.getDefaultDataSubId();
3010 final Phone phone = getPhone(subId);
3011 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003012 phone.getDataSettingsManager().setDataEnabled(
3013 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003014 return true;
3015 } else {
3016 return false;
3017 }
3018 } finally {
3019 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003020 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003021 }
3022
Wink Saville36469e72014-06-11 15:17:00 -07003023 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003024 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003025 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003026 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003027
3028 final long identity = Binder.clearCallingIdentity();
3029 try {
3030 int subId = mSubscriptionController.getDefaultDataSubId();
3031 final Phone phone = getPhone(subId);
3032 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003033 phone.getDataSettingsManager().setDataEnabled(
3034 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003035 return true;
3036 } else {
3037 return false;
3038 }
3039 } finally {
3040 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003041 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003042 }
3043
Sanket Padawe356d7632015-06-22 14:03:32 -07003044 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003045 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003046 final long identity = Binder.clearCallingIdentity();
3047 try {
3048 final Phone phone = getPhone(subId);
3049 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003050 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003051 } else {
3052 return false;
3053 }
3054 } finally {
3055 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003056 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003057 }
3058
3059 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003060 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003061 }
3062
pkanwarae03a6b2016-11-06 20:37:09 -08003063 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003064 enforceCallPermission();
3065
3066 final long identity = Binder.clearCallingIdentity();
3067 try {
3068 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3069 return;
3070 }
3071 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3072 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3073 } finally {
3074 Binder.restoreCallingIdentity(identity);
3075 }
pkanwar32d516d2016-10-14 19:37:38 -07003076 };
3077
Wink Savilleb564aae2014-10-23 10:18:09 -07003078 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003079 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003080
3081 final long identity = Binder.clearCallingIdentity();
3082 try {
3083 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3084 return false;
3085 }
3086 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3087 } finally {
3088 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003089 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003090 }
3091
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003092 /**
3093 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3094 * tag on getCallState Binder call.
3095 */
3096 @Deprecated
3097 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003098 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003099 if (CompatChanges.isChangeEnabled(
3100 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3101 Binder.getCallingUid())) {
3102 // Do not allow this API to be called on API version 31+, it should only be
3103 // called on old apps using this Binder call directly.
3104 throw new SecurityException("This method can only be used for applications "
3105 + "targeting API version 30 or less.");
3106 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003107 final long identity = Binder.clearCallingIdentity();
3108 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003109 Phone phone = getPhone(getDefaultSubscription());
3110 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3111 PhoneConstantConversions.convertCallState(phone.getState());
3112 } finally {
3113 Binder.restoreCallingIdentity(identity);
3114 }
3115 }
3116
3117 @Override
3118 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3119 if (CompatChanges.isChangeEnabled(
3120 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3121 Binder.getCallingUid())) {
3122 // Check READ_PHONE_STATE for API version 31+
3123 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3124 featureId, "getCallStateForSubscription")) {
3125 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3126 + "targeting API level 31+.");
3127 }
3128 }
3129 final long identity = Binder.clearCallingIdentity();
3130 try {
3131 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003132 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3133 PhoneConstantConversions.convertCallState(phone.getState());
3134 } finally {
3135 Binder.restoreCallingIdentity(identity);
3136 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003137 }
3138
Sanket Padawe356d7632015-06-22 14:03:32 -07003139 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003140 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003141 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
3142 }
3143
3144 @Override
3145 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003146 final long identity = Binder.clearCallingIdentity();
3147 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003148 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003149 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003150 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003151 } else {
3152 return PhoneConstantConversions.convertDataState(
3153 PhoneConstants.DataState.DISCONNECTED);
3154 }
3155 } finally {
3156 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003157 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003158 }
3159
Sanket Padawe356d7632015-06-22 14:03:32 -07003160 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003161 public @DataActivityType int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003162 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
3163 }
3164
3165 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003166 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003167 final long identity = Binder.clearCallingIdentity();
3168 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003169 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003170 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003171 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003172 } else {
3173 return TelephonyManager.DATA_ACTIVITY_NONE;
3174 }
3175 } finally {
3176 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003177 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003178 }
3179
3180 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003181 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003182 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003183 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003184
3185 LocationAccessPolicy.LocationPermissionResult locationResult =
3186 LocationAccessPolicy.checkLocationPermission(mApp,
3187 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3188 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003189 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003190 .setCallingPid(Binder.getCallingPid())
3191 .setCallingUid(Binder.getCallingUid())
3192 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003193 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003194 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3195 .build());
3196 switch (locationResult) {
3197 case DENIED_HARD:
3198 throw new SecurityException("Not allowed to access cell location");
3199 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003200 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3201 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003202 }
3203
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003204 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003205 final long identity = Binder.clearCallingIdentity();
3206 try {
3207 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003208 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003209 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003210 } finally {
3211 Binder.restoreCallingIdentity(identity);
3212 }
Svetoslav64fad262015-04-14 14:35:21 -07003213 }
3214
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003215 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003216 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003217 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3218 // registered cell info, so return a NULL country instead.
3219 final long identity = Binder.clearCallingIdentity();
3220 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003221 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3222 // Get default phone in this case.
3223 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3224 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003225 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003226 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003227 if (phone == null) return "";
3228 ServiceStateTracker sst = phone.getServiceStateTracker();
3229 if (sst == null) return "";
3230 LocaleTracker lt = sst.getLocaleTracker();
3231 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003232 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003233 } finally {
3234 Binder.restoreCallingIdentity(identity);
3235 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003236 }
3237
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003238 /**
3239 * This method was removed due to potential issues caused by performing partial
3240 * updates of service state, and lack of a credible use case.
3241 *
3242 * This has the ability to break the telephony implementation by disabling notification of
3243 * changes in device connectivity. DO NOT USE THIS!
3244 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003245 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003246 public void enableLocationUpdates() {
3247 mApp.enforceCallingOrSelfPermission(
3248 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003249 }
3250
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003251 /**
3252 * This method was removed due to potential issues caused by performing partial
3253 * updates of service state, and lack of a credible use case.
3254 *
3255 * This has the ability to break the telephony implementation by disabling notification of
3256 * changes in device connectivity. DO NOT USE THIS!
3257 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003258 @Override
3259 public void disableLocationUpdates() {
3260 mApp.enforceCallingOrSelfPermission(
3261 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003262 }
3263
3264 @Override
3265 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003266 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3267 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003268 try {
3269 mApp.getSystemService(AppOpsManager.class)
3270 .checkPackage(Binder.getCallingUid(), callingPackage);
3271 } catch (SecurityException e) {
3272 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3273 throw e;
3274 }
3275
Nathan Haroldf096d982020-11-18 17:18:06 -08003276 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003277 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3278 throw new SecurityException(
3279 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3280 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003281
Jordan Liu1617b712019-07-10 15:06:26 -07003282 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003283 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3284 return null;
3285 }
Svetoslav64fad262015-04-14 14:35:21 -07003286
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003287 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003288
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003289 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003290 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003291
Nathan Haroldf180aac2018-06-01 18:43:55 -07003292 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3293 for (CellInfo ci : info) {
3294 if (ci instanceof CellInfoGsm) {
3295 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3296 } else if (ci instanceof CellInfoWcdma) {
3297 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3298 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003299 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003300 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003301 }
3302
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003303 private List<CellInfo> getCachedCellInfo() {
3304 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3305 for (Phone phone : PhoneFactory.getPhones()) {
3306 List<CellInfo> info = phone.getAllCellInfo();
3307 if (info != null) cellInfos.addAll(info);
3308 }
3309 return cellInfos;
3310 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003311
3312 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003313 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003314 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003315 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003316
3317 LocationAccessPolicy.LocationPermissionResult locationResult =
3318 LocationAccessPolicy.checkLocationPermission(mApp,
3319 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3320 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003321 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003322 .setCallingPid(Binder.getCallingPid())
3323 .setCallingUid(Binder.getCallingUid())
3324 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003325 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003326 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3327 .build());
3328 switch (locationResult) {
3329 case DENIED_HARD:
3330 throw new SecurityException("Not allowed to access cell info");
3331 case DENIED_SOFT:
3332 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003333 }
3334
Nathan Haroldf096d982020-11-18 17:18:06 -08003335 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003336 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3337 return getCachedCellInfo();
3338 }
3339
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003340 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003341 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003342 final long identity = Binder.clearCallingIdentity();
3343 try {
3344 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3345 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003346 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003347 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003348 if (info != null) cellInfos.addAll(info);
3349 }
3350 return cellInfos;
3351 } finally {
3352 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003353 }
3354 }
3355
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003356 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003357 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3358 String callingFeatureId) {
3359 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3360 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003361 }
3362
3363 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003364 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3365 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003366 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003367 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003368 }
3369
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003370 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3371 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003372 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003373 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003374
3375 LocationAccessPolicy.LocationPermissionResult locationResult =
3376 LocationAccessPolicy.checkLocationPermission(mApp,
3377 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3378 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003379 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003380 .setCallingPid(Binder.getCallingPid())
3381 .setCallingUid(Binder.getCallingUid())
3382 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003383 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3384 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003385 .build());
3386 switch (locationResult) {
3387 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003388 if (TelephonyPermissions
3389 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003390 // Safetynet logging for b/154934934
3391 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3392 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003393 throw new SecurityException("Not allowed to access cell info");
3394 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003395 if (TelephonyPermissions
3396 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003397 // Safetynet logging for b/154934934
3398 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3399 }
Nathan Harold5320c422019-05-09 10:26:08 -07003400 try {
3401 cb.onCellInfo(new ArrayList<CellInfo>());
3402 } catch (RemoteException re) {
3403 // Drop without consequences
3404 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003405 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003406 }
3407
Nathan Harolda939a962019-05-09 10:13:47 -07003408
3409 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003410 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3411
3412 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3413 }
3414
3415 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003416 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003417 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003418 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003419
3420 final long identity = Binder.clearCallingIdentity();
3421 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003422 Phone phone = getPhone(subId);
3423 if (phone == null) {
3424 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3425 } else {
3426 phone.setCellInfoListRate(rateInMillis, workSource);
3427 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003428 } finally {
3429 Binder.restoreCallingIdentity(identity);
3430 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003431 }
3432
Shishir Agrawala9f32182016-04-12 12:00:16 -07003433 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003434 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003435 Phone phone = PhoneFactory.getPhone(slotIndex);
3436 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003437 return null;
3438 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003439 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003440 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003441 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003442 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003443 return null;
3444 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003445
3446 final long identity = Binder.clearCallingIdentity();
3447 try {
3448 return phone.getImei();
3449 } finally {
3450 Binder.restoreCallingIdentity(identity);
3451 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003452 }
3453
3454 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003455 public String getTypeAllocationCodeForSlot(int slotIndex) {
3456 Phone phone = PhoneFactory.getPhone(slotIndex);
3457 String tac = null;
3458 if (phone != null) {
3459 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003460 try {
3461 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3462 } catch (IndexOutOfBoundsException e) {
3463 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3464 return null;
3465 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003466 }
3467 return tac;
3468 }
3469
3470 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003471 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003472 try {
3473 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3474 } catch (SecurityException se) {
3475 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3476 throw new SecurityException("Package " + callingPackage + " does not belong to "
3477 + Binder.getCallingUid());
3478 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003479 Phone phone = PhoneFactory.getPhone(slotIndex);
3480 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003481 return null;
3482 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003483
Jeff Davidson913390f2018-02-23 17:11:49 -08003484 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003485 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003486 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003487 return null;
3488 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003489
3490 final long identity = Binder.clearCallingIdentity();
3491 try {
3492 return phone.getMeid();
3493 } finally {
3494 Binder.restoreCallingIdentity(identity);
3495 }
Jack Yu2af8d712017-03-15 17:14:14 -07003496 }
3497
3498 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003499 public String getManufacturerCodeForSlot(int slotIndex) {
3500 Phone phone = PhoneFactory.getPhone(slotIndex);
3501 String manufacturerCode = null;
3502 if (phone != null) {
3503 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003504 try {
3505 manufacturerCode =
3506 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3507 } catch (IndexOutOfBoundsException e) {
3508 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3509 return null;
3510 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003511 }
3512 return manufacturerCode;
3513 }
3514
3515 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003516 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3517 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003518 Phone phone = PhoneFactory.getPhone(slotIndex);
3519 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003520 return null;
3521 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003522 int subId = phone.getSubId();
3523 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003524 mApp, subId, callingPackage, callingFeatureId,
3525 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003526 return null;
3527 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003528
3529 final long identity = Binder.clearCallingIdentity();
3530 try {
3531 return phone.getDeviceSvn();
3532 } finally {
3533 Binder.restoreCallingIdentity(identity);
3534 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003535 }
3536
fionaxu43304da2017-11-27 22:51:16 -08003537 @Override
3538 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003539 final long identity = Binder.clearCallingIdentity();
3540 try {
3541 final Phone phone = getPhone(subId);
3542 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3543 } finally {
3544 Binder.restoreCallingIdentity(identity);
3545 }
fionaxu43304da2017-11-27 22:51:16 -08003546 }
3547
3548 @Override
3549 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003550 final long identity = Binder.clearCallingIdentity();
3551 try {
3552 final Phone phone = getPhone(subId);
3553 return phone == null ? null : phone.getCarrierName();
3554 } finally {
3555 Binder.restoreCallingIdentity(identity);
3556 }
fionaxu43304da2017-11-27 22:51:16 -08003557 }
3558
calvinpanffe225e2018-11-01 19:43:06 +08003559 @Override
chen xu0026ca62019-03-06 15:28:50 -08003560 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003561 final long identity = Binder.clearCallingIdentity();
3562 try {
3563 final Phone phone = getPhone(subId);
3564 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003565 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003566 } finally {
3567 Binder.restoreCallingIdentity(identity);
3568 }
3569 }
3570
3571 @Override
chen xu0026ca62019-03-06 15:28:50 -08003572 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003573 final long identity = Binder.clearCallingIdentity();
3574 try {
3575 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003576 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003577 } finally {
3578 Binder.restoreCallingIdentity(identity);
3579 }
3580 }
3581
chen xu651eec72018-11-11 19:03:44 -08003582 @Override
chen xu864e11c2018-12-06 22:10:03 -08003583 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3584 if (!isSubscriptionMccMnc) {
3585 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3586 }
chen xu651eec72018-11-11 19:03:44 -08003587 final Phone phone = PhoneFactory.getPhone(slotIndex);
3588 if (phone == null) {
3589 return TelephonyManager.UNKNOWN_CARRIER_ID;
3590 }
3591 final long identity = Binder.clearCallingIdentity();
3592 try {
3593 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3594 } finally {
3595 Binder.restoreCallingIdentity(identity);
3596 }
3597 }
3598
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003599 //
3600 // Internal helper methods.
3601 //
3602
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003603 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003604 * Make sure the caller is the calling package itself
3605 *
3606 * @throws SecurityException if the caller is not the calling package
3607 */
3608 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3609 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003610 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3611 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003612 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003613 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003614 } catch (PackageManager.NameNotFoundException e) {
3615 // packageUid is -1
3616 }
3617 if (packageUid != callingUid) {
3618 throw new SecurityException(message + ": Package " + callingPackage
3619 + " does not belong to " + callingUid);
3620 }
3621 }
3622
3623 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003624 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3625 *
3626 * @throws SecurityException if the caller does not have the required permission
3627 */
3628 private void enforceModifyPermission() {
3629 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3630 }
3631
Shuo Qian3b6ee772019-11-13 17:43:31 -08003632 private void enforceActiveEmergencySessionPermission() {
3633 mApp.enforceCallingOrSelfPermission(
3634 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3635 }
3636
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003637 /**
3638 * Make sure the caller has the CALL_PHONE permission.
3639 *
3640 * @throws SecurityException if the caller does not have the required permission
3641 */
3642 private void enforceCallPermission() {
3643 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3644 }
3645
paulhu5a773602019-08-23 19:17:33 +08003646 private void enforceSettingsPermission() {
3647 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003648 }
3649
Michele Berionne5e411512020-11-13 02:36:59 +00003650 private void enforceRebootPermission() {
3651 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3652 }
3653
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003654 private String createTelUrl(String number) {
3655 if (TextUtils.isEmpty(number)) {
3656 return null;
3657 }
3658
Jake Hambye994d462014-02-03 13:10:13 -08003659 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003660 }
3661
Ihab Awadf9e92732013-12-05 18:02:52 -08003662 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003663 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3664 }
3665
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003666 private static void logv(String msg) {
3667 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3668 }
3669
Ihab Awadf9e92732013-12-05 18:02:52 -08003670 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003671 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3672 }
3673
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003674 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003675 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003676 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003677 }
3678
Sanket Padawe356d7632015-06-22 14:03:32 -07003679 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003680 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003681 final long identity = Binder.clearCallingIdentity();
3682 try {
3683 final Phone phone = PhoneFactory.getPhone(slotIndex);
3684 if (phone == null) {
3685 return PhoneConstants.PHONE_TYPE_NONE;
3686 } else {
3687 return phone.getPhoneType();
3688 }
3689 } finally {
3690 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003691 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003692 }
3693
3694 /**
3695 * Returns the CDMA ERI icon index to display
3696 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003697 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003698 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3699 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3700 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003701 }
3702
Sanket Padawe356d7632015-06-22 14:03:32 -07003703 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003704 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3705 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003706 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003707 mApp, subId, callingPackage, callingFeatureId,
3708 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003709 return -1;
3710 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003711
3712 final long identity = Binder.clearCallingIdentity();
3713 try {
3714 final Phone phone = getPhone(subId);
3715 if (phone != null) {
3716 return phone.getCdmaEriIconIndex();
3717 } else {
3718 return -1;
3719 }
3720 } finally {
3721 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003722 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003723 }
3724
3725 /**
3726 * Returns the CDMA ERI icon mode,
3727 * 0 - ON
3728 * 1 - FLASHING
3729 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003730 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003731 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3732 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3733 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003734 }
3735
Sanket Padawe356d7632015-06-22 14:03:32 -07003736 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003737 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3738 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003739 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003740 mApp, subId, callingPackage, callingFeatureId,
3741 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003742 return -1;
3743 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003744
3745 final long identity = Binder.clearCallingIdentity();
3746 try {
3747 final Phone phone = getPhone(subId);
3748 if (phone != null) {
3749 return phone.getCdmaEriIconMode();
3750 } else {
3751 return -1;
3752 }
3753 } finally {
3754 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003755 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003756 }
3757
3758 /**
3759 * Returns the CDMA ERI text,
3760 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003761 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003762 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3763 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3764 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003765 }
3766
Sanket Padawe356d7632015-06-22 14:03:32 -07003767 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003768 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3769 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003770 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003771 mApp, subId, callingPackage, callingFeatureId,
3772 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003773 return null;
3774 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003775
3776 final long identity = Binder.clearCallingIdentity();
3777 try {
3778 final Phone phone = getPhone(subId);
3779 if (phone != null) {
3780 return phone.getCdmaEriText();
3781 } else {
3782 return null;
3783 }
3784 } finally {
3785 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003786 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003787 }
3788
3789 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003790 * Returns the CDMA MDN.
3791 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003792 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003793 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003794 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3795 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003796
3797 final long identity = Binder.clearCallingIdentity();
3798 try {
3799 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003800 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003801 return phone.getLine1Number();
3802 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003803 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003804 return null;
3805 }
3806 } finally {
3807 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003808 }
3809 }
3810
3811 /**
3812 * Returns the CDMA MIN.
3813 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003814 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003815 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003816 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3817 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003818
3819 final long identity = Binder.clearCallingIdentity();
3820 try {
3821 final Phone phone = getPhone(subId);
3822 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3823 return phone.getCdmaMin();
3824 } else {
3825 return null;
3826 }
3827 } finally {
3828 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003829 }
3830 }
3831
Hall Liud892bec2018-11-30 14:51:45 -08003832 @Override
3833 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3834 INumberVerificationCallback callback, String callingPackage) {
3835 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3836 != PERMISSION_GRANTED) {
3837 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3838 }
3839 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3840
3841 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3842 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003843 throw new SecurityException("Calling package must be configured in the device config: "
3844 + "calling package: " + callingPackage
3845 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003846 }
3847
3848 if (range == null) {
3849 throw new NullPointerException("Range must be non-null");
3850 }
3851
3852 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003853 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003854
3855 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3856 }
3857
Junda Liuca05d5d2014-08-14 22:36:34 -07003858 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003859 * Returns true if CDMA provisioning needs to run.
3860 */
3861 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003862 final long identity = Binder.clearCallingIdentity();
3863 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003864 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003865 } finally {
3866 Binder.restoreCallingIdentity(identity);
3867 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003868 }
3869
3870 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003871 * Sets the voice mail number of a given subId.
3872 */
3873 @Override
3874 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003875 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3876 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003877
3878 final long identity = Binder.clearCallingIdentity();
3879 try {
3880 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3881 new Pair<String, String>(alphaTag, number), new Integer(subId));
3882 return success;
3883 } finally {
3884 Binder.restoreCallingIdentity(identity);
3885 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003886 }
3887
Ta-wei Yen87c49842016-05-13 21:19:52 -07003888 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003889 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3890 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003891 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3892 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003893 if (!TextUtils.equals(callingPackage, systemDialer)) {
3894 throw new SecurityException("caller must be system dialer");
3895 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003896
3897 final long identity = Binder.clearCallingIdentity();
3898 try {
3899 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3900 if (phoneAccountHandle == null) {
3901 return null;
3902 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003903 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003904 } finally {
3905 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003906 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003907 }
3908
3909 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003910 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3911 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003912 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003913 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003914 mApp, subId, callingPackage, callingFeatureId,
3915 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003916 return null;
3917 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003918
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003919 final long identity = Binder.clearCallingIdentity();
3920 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003921 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003922 } finally {
3923 Binder.restoreCallingIdentity(identity);
3924 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003925 }
3926
3927 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003928 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3929 VisualVoicemailSmsFilterSettings settings) {
3930 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003931
3932 final long identity = Binder.clearCallingIdentity();
3933 try {
3934 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003935 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003936 } finally {
3937 Binder.restoreCallingIdentity(identity);
3938 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003939 }
3940
3941 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003942 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3943 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003944
3945 final long identity = Binder.clearCallingIdentity();
3946 try {
3947 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003948 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003949 } finally {
3950 Binder.restoreCallingIdentity(identity);
3951 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003952 }
3953
3954 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003955 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3956 String callingPackage, int subId) {
3957 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003958
3959 final long identity = Binder.clearCallingIdentity();
3960 try {
3961 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003962 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003963 } finally {
3964 Binder.restoreCallingIdentity(identity);
3965 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003966 }
3967
3968 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003969 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003970 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003971
3972 final long identity = Binder.clearCallingIdentity();
3973 try {
3974 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003975 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003976 } finally {
3977 Binder.restoreCallingIdentity(identity);
3978 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003979 }
3980
3981 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003982 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3983 String callingAttributionTag, int subId, String number, int port, String text,
3984 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003985 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003986 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003987 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003988 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003989 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3990 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003991 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003992
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003993 /**
fionaxu0152e512016-11-14 13:36:14 -08003994 * Sets the voice activation state of a given subId.
3995 */
3996 @Override
3997 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003998 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3999 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004000
4001 final long identity = Binder.clearCallingIdentity();
4002 try {
4003 final Phone phone = getPhone(subId);
4004 if (phone != null) {
4005 phone.setVoiceActivationState(activationState);
4006 } else {
4007 loge("setVoiceActivationState fails with invalid subId: " + subId);
4008 }
4009 } finally {
4010 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004011 }
4012 }
4013
4014 /**
4015 * Sets the data activation state of a given subId.
4016 */
4017 @Override
4018 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004019 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4020 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004021
4022 final long identity = Binder.clearCallingIdentity();
4023 try {
4024 final Phone phone = getPhone(subId);
4025 if (phone != null) {
4026 phone.setDataActivationState(activationState);
4027 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004028 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004029 }
4030 } finally {
4031 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004032 }
4033 }
4034
4035 /**
4036 * Returns the voice activation state of a given subId.
4037 */
4038 @Override
4039 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004040 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004041
fionaxu0152e512016-11-14 13:36:14 -08004042 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004043 final long identity = Binder.clearCallingIdentity();
4044 try {
4045 if (phone != null) {
4046 return phone.getVoiceActivationState();
4047 } else {
4048 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4049 }
4050 } finally {
4051 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004052 }
4053 }
4054
4055 /**
4056 * Returns the data activation state of a given subId.
4057 */
4058 @Override
4059 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004060 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004061
fionaxu0152e512016-11-14 13:36:14 -08004062 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004063 final long identity = Binder.clearCallingIdentity();
4064 try {
4065 if (phone != null) {
4066 return phone.getDataActivationState();
4067 } else {
4068 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4069 }
4070 } finally {
4071 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004072 }
4073 }
4074
4075 /**
Wink Saville36469e72014-06-11 15:17:00 -07004076 * Returns the unread count of voicemails for a subId
4077 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004078 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004079 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4080 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004081 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004082 mApp, subId, callingPackage, callingFeatureId,
4083 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004084 return 0;
4085 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004086 final long identity = Binder.clearCallingIdentity();
4087 try {
4088 final Phone phone = getPhone(subId);
4089 if (phone != null) {
4090 return phone.getVoiceMessageCount();
4091 } else {
4092 return 0;
4093 }
4094 } finally {
4095 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004096 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004097 }
4098
4099 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08004100 * returns true, if the device is in a state where both voice and data
4101 * are supported simultaneously. This can change based on location or network condition.
4102 */
4103 @Override
4104 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004105 final long identity = Binder.clearCallingIdentity();
4106 try {
4107 final Phone phone = getPhone(subId);
4108 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
4109 } finally {
4110 Binder.restoreCallingIdentity(identity);
4111 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004112 }
4113
4114 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004115 * Send the dialer code if called from the current default dialer or the caller has
4116 * carrier privilege.
4117 * @param inputCode The dialer code to send
4118 */
4119 @Override
4120 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004121 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004122 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004123 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4124 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004125 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004126 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004127 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004128 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004129
4130 final long identity = Binder.clearCallingIdentity();
4131 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004132 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004133 } finally {
4134 Binder.restoreCallingIdentity(identity);
4135 }
fionaxu235cc5e2017-03-06 22:25:57 -08004136 }
4137
Pengquan Menga1bb6272018-09-06 09:59:22 -07004138 @Override
4139 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004140 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07004141 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08004142 mApp, subId, "getNetworkSelectionMode");
4143 final long identity = Binder.clearCallingIdentity();
4144 try {
4145 if (!isActiveSubscription(subId)) {
4146 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4147 }
4148 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4149 } finally {
4150 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004151 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004152 }
4153
Brad Ebinger35c841c2018-10-01 10:40:55 -07004154 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004155 public boolean isInEmergencySmsMode() {
4156 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4157 final long identity = Binder.clearCallingIdentity();
4158 try {
4159 for (Phone phone : PhoneFactory.getPhones()) {
4160 if (phone.isInEmergencySmsMode()) {
4161 return true;
4162 }
4163 }
4164 } finally {
4165 Binder.restoreCallingIdentity(identity);
4166 }
4167 return false;
4168 }
4169
shilu366312e2019-12-17 09:28:10 -08004170 /**
4171 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4172 * @param subId The subscription to use to check the configuration.
4173 * @param c The callback that will be used to send the result.
4174 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004175 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004176 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4177 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004178 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004179 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004180
4181 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4182 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4183 "IMS not available on device.");
4184 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004185 final long token = Binder.clearCallingIdentity();
4186 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004187 int slotId = getSlotIndexOrException(subId);
4188 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004189
4190 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4191 if (controller != null) {
4192 ImsManager imsManager = controller.getImsManager(subId);
4193 if (imsManager != null) {
4194 imsManager.addRegistrationCallbackForSubscription(c, subId);
4195 } else {
4196 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4197 }
4198 } else {
4199 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4200 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004201 } catch (ImsException e) {
4202 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004203 } finally {
4204 Binder.restoreCallingIdentity(token);
4205 }
4206 }
4207
shilu366312e2019-12-17 09:28:10 -08004208 /**
4209 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4210 * @param subId The subscription to use to check the configuration.
4211 * @param c The callback that will be used to send the result.
4212 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004213 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004214 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004215 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004216 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004217 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4218 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4219 }
Meng Wangafbc5852019-09-19 17:37:13 -07004220 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004221
Meng Wangafbc5852019-09-19 17:37:13 -07004222 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004223 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4224 if (controller != null) {
4225 ImsManager imsManager = controller.getImsManager(subId);
4226 if (imsManager != null) {
4227 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4228 } else {
4229 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4230 + "is inactive, ignoring unregister.");
4231 // If the ImsManager is not valid, just return, since the callback
4232 // will already have been removed internally.
4233 }
4234 }
Meng Wangafbc5852019-09-19 17:37:13 -07004235 } finally {
4236 Binder.restoreCallingIdentity(token);
4237 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004238 }
4239
Brad Ebingera34a6c22019-10-22 17:36:18 -07004240 /**
4241 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4242 */
4243 @Override
4244 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4245 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4246 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4247 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4248 "IMS not available on device.");
4249 }
4250 final long token = Binder.clearCallingIdentity();
4251 try {
4252 Phone phone = getPhone(subId);
4253 if (phone == null) {
4254 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4255 + subId + "'");
4256 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4257 }
4258 phone.getImsRegistrationState(regState -> {
4259 try {
4260 consumer.accept((regState == null)
4261 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4262 } catch (RemoteException e) {
4263 // Ignore if the remote process is no longer available to call back.
4264 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4265 }
4266 });
4267 } finally {
4268 Binder.restoreCallingIdentity(token);
4269 }
4270 }
4271
4272 /**
4273 * Get the transport type for the IMS service registration state.
4274 */
4275 @Override
4276 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004277 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004278 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004279 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4280 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4281 "IMS not available on device.");
4282 }
4283 final long token = Binder.clearCallingIdentity();
4284 try {
4285 Phone phone = getPhone(subId);
4286 if (phone == null) {
4287 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4288 + subId + "'");
4289 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4290 }
4291 phone.getImsRegistrationTech(regTech -> {
4292 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4293 int regTechConverted = (regTech == null)
4294 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4295 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4296 regTechConverted);
4297 try {
4298 consumer.accept(regTechConverted);
4299 } catch (RemoteException e) {
4300 // Ignore if the remote process is no longer available to call back.
4301 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4302 }
4303 });
4304 } finally {
4305 Binder.restoreCallingIdentity(token);
4306 }
4307 }
4308
shilu366312e2019-12-17 09:28:10 -08004309 /**
4310 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4311 * @param subId The subscription to use to check the configuration.
4312 * @param c The callback that will be used to send the result.
4313 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004314 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004315 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4316 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004317 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004318 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004319 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4320 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4321 "IMS not available on device.");
4322 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004323 final long token = Binder.clearCallingIdentity();
4324 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004325 int slotId = getSlotIndexOrException(subId);
4326 verifyImsMmTelConfiguredOrThrow(slotId);
4327 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004328 } catch (ImsException e) {
4329 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004330 } finally {
4331 Binder.restoreCallingIdentity(token);
4332 }
4333 }
4334
shilu366312e2019-12-17 09:28:10 -08004335 /**
4336 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4337 * @param subId The subscription to use to check the configuration.
4338 * @param c The callback that will be used to send the result.
4339 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004340 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004341 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004342 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004343 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004344 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4345 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4346 }
Meng Wangafbc5852019-09-19 17:37:13 -07004347
4348 final long token = Binder.clearCallingIdentity();
4349 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004350 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004351 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004352 } catch (ImsException e) {
4353 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4354 + "is inactive, ignoring unregister.");
4355 // If the subscription is no longer active, just return, since the callback
4356 // will already have been removed internally.
4357 } finally {
4358 Binder.restoreCallingIdentity(token);
4359 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004360 }
4361
4362 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004363 public boolean isCapable(int subId, int capability, int regTech) {
4364 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004365 final long token = Binder.clearCallingIdentity();
4366 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004367 int slotId = getSlotIndexOrException(subId);
4368 verifyImsMmTelConfiguredOrThrow(slotId);
4369 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4370 } catch (com.android.ims.ImsException e) {
4371 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4372 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004373 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004374 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4375 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004376 } finally {
4377 Binder.restoreCallingIdentity(token);
4378 }
4379 }
4380
4381 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004382 public boolean isAvailable(int subId, int capability, int regTech) {
4383 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004384 final long token = Binder.clearCallingIdentity();
4385 try {
4386 Phone phone = getPhone(subId);
4387 if (phone == null) return false;
4388 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004389 } catch (com.android.ims.ImsException e) {
4390 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4391 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004392 } finally {
4393 Binder.restoreCallingIdentity(token);
4394 }
4395 }
4396
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004397 /**
4398 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4399 * subscription.
4400 * @param subId The subscription to use to check the configuration.
4401 * @param callback The callback that will be used to send the result.
4402 * @param capability The MmTelFeature capability that will be used to send the result.
4403 * @param transportType The transport type of the MmTelFeature capability.
4404 */
4405 @Override
4406 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4407 int transportType) {
4408 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004409 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4410 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4411 "IMS not available on device.");
4412 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004413 final long token = Binder.clearCallingIdentity();
4414 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004415 int slotId = getSlotIndex(subId);
4416 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4417 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4418 + subId + "'");
4419 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4420 }
4421 verifyImsMmTelConfiguredOrThrow(slotId);
4422 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4423 transportType, aBoolean -> {
4424 try {
4425 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4426 } catch (RemoteException e) {
4427 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4428 + "running. Ignore");
4429 }
4430 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004431 } catch (ImsException e) {
4432 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004433 } finally {
4434 Binder.restoreCallingIdentity(token);
4435 }
4436 }
4437
shilu366312e2019-12-17 09:28:10 -08004438 /**
4439 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4440 * @param subId The subscription to use to check the configuration.
4441 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004442 @Override
4443 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004444 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004445 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004446
Brad Ebinger35c841c2018-10-01 10:40:55 -07004447 final long token = Binder.clearCallingIdentity();
4448 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004449 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004450 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004451 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004452 } catch (ImsException e) {
4453 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004454 } finally {
4455 Binder.restoreCallingIdentity(token);
4456 }
4457 }
4458
4459 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004460 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004461 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004462 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004463 final long identity = Binder.clearCallingIdentity();
4464 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004465 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004466 // This setting doesn't require an active ImsService connection, so do not verify. The
4467 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004468 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004469 } catch (ImsException e) {
4470 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004471 } finally {
4472 Binder.restoreCallingIdentity(identity);
4473 }
4474 }
4475
shilu366312e2019-12-17 09:28:10 -08004476 /**
4477 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4478 * @param subId The subscription to use to check the configuration.
4479 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004480 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004481 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004482 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004483 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004484 final long identity = Binder.clearCallingIdentity();
4485 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004486 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004487 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004488 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004489 } catch (ImsException e) {
4490 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004491 } finally {
4492 Binder.restoreCallingIdentity(identity);
4493 }
4494 }
4495
4496 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004497 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004498 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004499 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004500 final long identity = Binder.clearCallingIdentity();
4501 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004502 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004503 // This setting doesn't require an active ImsService connection, so do not verify. The
4504 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004505 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004506 } catch (ImsException e) {
4507 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004508 } finally {
4509 Binder.restoreCallingIdentity(identity);
4510 }
4511 }
4512
shilu366312e2019-12-17 09:28:10 -08004513 /**
4514 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4515 * @param subId The subscription to use to check the configuration.
4516 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004517 @Override
4518 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004519 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004520 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004521 final long identity = Binder.clearCallingIdentity();
4522 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004523 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004524 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004525 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004526 } catch (ImsException e) {
4527 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004528 } finally {
4529 Binder.restoreCallingIdentity(identity);
4530 }
4531 }
4532
4533 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004534 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004535 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004536 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004537 final long identity = Binder.clearCallingIdentity();
4538 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004539 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004540 // This setting doesn't require an active ImsService connection, so do not verify. The
4541 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004542 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004543 } catch (ImsException e) {
4544 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004545 } finally {
4546 Binder.restoreCallingIdentity(identity);
4547 }
4548 }
4549
shilu366312e2019-12-17 09:28:10 -08004550 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004551 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4552 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4553 * @param subId The subscription to use to check the configuration.
4554 */
4555 @Override
4556 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004557 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004558 mApp, subId, "isCrossSimCallingEnabledByUser");
4559 final long identity = Binder.clearCallingIdentity();
4560 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004561 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004562 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004563 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004564 } catch (ImsException e) {
4565 throw new ServiceSpecificException(e.getCode());
4566 } finally {
4567 Binder.restoreCallingIdentity(identity);
4568 }
4569 }
4570
4571 /**
4572 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4573 * Requires MODIFY_PHONE_STATE permission.
4574 * @param subId The subscription to use to check the configuration.
4575 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4576 * false otherwise
4577 */
4578 @Override
4579 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4580 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4581 "setCrossSimCallingEnabled");
4582 final long identity = Binder.clearCallingIdentity();
4583 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004584 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004585 // This setting doesn't require an active ImsService connection, so do not verify. The
4586 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004587 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004588 } catch (ImsException e) {
4589 throw new ServiceSpecificException(e.getCode());
4590 } finally {
4591 Binder.restoreCallingIdentity(identity);
4592 }
4593 }
4594
4595 /**
shilu366312e2019-12-17 09:28:10 -08004596 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4597 * @param subId The subscription to use to check the configuration.
4598 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004599 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004600
Brad Ebinger35c841c2018-10-01 10:40:55 -07004601 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004602 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004603 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004604 final long identity = Binder.clearCallingIdentity();
4605 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004606 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004607 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004608 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004609 } catch (ImsException e) {
4610 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004611 } finally {
4612 Binder.restoreCallingIdentity(identity);
4613 }
4614 }
4615
4616 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004617 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004618 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004619 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004620 final long identity = Binder.clearCallingIdentity();
4621 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004622 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004623 // This setting doesn't require an active ImsService connection, so do not verify. The
4624 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004625 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004626 } catch (ImsException e) {
4627 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004628 } finally {
4629 Binder.restoreCallingIdentity(identity);
4630 }
4631 }
4632
4633 @Override
4634 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4635 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4636 "setVoWiFiNonPersistent");
4637 final long identity = Binder.clearCallingIdentity();
4638 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004639 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004640 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004641 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004642 } catch (ImsException e) {
4643 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004644 } finally {
4645 Binder.restoreCallingIdentity(identity);
4646 }
4647 }
4648
shilu366312e2019-12-17 09:28:10 -08004649 /**
4650 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4651 * @param subId The subscription to use to check the configuration.
4652 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004653 @Override
4654 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004655 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004656 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004657 final long identity = Binder.clearCallingIdentity();
4658 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004659 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004660 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004661 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004662 } catch (ImsException e) {
4663 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004664 } finally {
4665 Binder.restoreCallingIdentity(identity);
4666 }
4667 }
4668
4669 @Override
4670 public void setVoWiFiModeSetting(int subId, int mode) {
4671 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4672 "setVoWiFiModeSetting");
4673 final long identity = Binder.clearCallingIdentity();
4674 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004675 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004676 // This setting doesn't require an active ImsService connection, so do not verify. The
4677 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004678 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004679 } catch (ImsException e) {
4680 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004681 } finally {
4682 Binder.restoreCallingIdentity(identity);
4683 }
4684 }
4685
4686 @Override
4687 public int getVoWiFiRoamingModeSetting(int subId) {
4688 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4689 final long identity = Binder.clearCallingIdentity();
4690 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004691 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004692 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004693 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004694 } catch (ImsException e) {
4695 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004696 } finally {
4697 Binder.restoreCallingIdentity(identity);
4698 }
4699 }
4700
4701 @Override
4702 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4703 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4704 "setVoWiFiRoamingModeSetting");
4705 final long identity = Binder.clearCallingIdentity();
4706 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004707 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004708 // This setting doesn't require an active ImsService connection, so do not verify. The
4709 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004710 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004711 } catch (ImsException e) {
4712 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004713 } finally {
4714 Binder.restoreCallingIdentity(identity);
4715 }
4716 }
4717
4718 @Override
4719 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4720 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4721 "setRttCapabilityEnabled");
4722 final long identity = Binder.clearCallingIdentity();
4723 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004724 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004725 // This setting doesn't require an active ImsService connection, so do not verify. The
4726 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004727 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004728 } catch (ImsException e) {
4729 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004730 } finally {
4731 Binder.restoreCallingIdentity(identity);
4732 }
4733 }
4734
shilu366312e2019-12-17 09:28:10 -08004735 /**
4736 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4737 * @param subId The subscription to use to check the configuration.
4738 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004739 @Override
4740 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004741 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004742 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004743 final long identity = Binder.clearCallingIdentity();
4744 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004745 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004746 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004747 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004748 } catch (ImsException e) {
4749 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004750 } finally {
4751 Binder.restoreCallingIdentity(identity);
4752 }
4753 }
4754
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004755 @Override
4756 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4757 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004758
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004759 final long identity = Binder.clearCallingIdentity();
4760 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004761 if (!isImsAvailableOnDevice()) {
4762 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4763 "IMS not available on device.");
4764 }
4765 int slotId = getSlotIndexOrException(subId);
4766 verifyImsMmTelConfiguredOrThrow(slotId);
4767 ImsManager.getInstance(mApp, slotId)
4768 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004769 } catch (ImsException e) {
4770 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004771 } finally {
4772 Binder.restoreCallingIdentity(identity);
4773 }
4774 }
4775
4776 @Override
4777 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4778 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004779
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004780 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004781 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4782 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4783 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004784 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004785 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004786 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004787 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004788 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4789 + "is inactive, ignoring unregister.");
4790 // If the subscription is no longer active, just return, since the callback will already
4791 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004792 } finally {
4793 Binder.restoreCallingIdentity(identity);
4794 }
4795 }
4796
joonhunshincffb7fc2021-11-28 07:32:01 +00004797 @Override
4798 public void registerFeatureProvisioningChangedCallback(int subId,
4799 IFeatureProvisioningCallback callback) {
4800 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4801 mApp, subId, "registerFeatureProvisioningChangedCallback");
4802
4803 final long identity = Binder.clearCallingIdentity();
4804 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4805 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4806 }
4807
joonhunshin91bc1952022-04-29 08:47:15 +00004808 try {
4809 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4810 if (controller == null) {
4811 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4812 "Device does not support IMS");
4813 }
4814 controller.addFeatureProvisioningChangedCallback(subId, callback);
4815 } finally {
4816 Binder.restoreCallingIdentity(identity);
4817 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004818 }
4819
4820 @Override
4821 public void unregisterFeatureProvisioningChangedCallback(int subId,
4822 IFeatureProvisioningCallback callback) {
4823 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4824 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4825
4826 final long identity = Binder.clearCallingIdentity();
4827 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4828 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4829 }
4830
joonhunshin91bc1952022-04-29 08:47:15 +00004831 try {
4832 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4833 if (controller == null) {
4834 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
4835 return;
4836 }
4837 controller.removeFeatureProvisioningChangedCallback(subId, callback);
4838 } finally {
4839 Binder.restoreCallingIdentity(identity);
4840 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004841 }
allenwtsu99c623b2020-01-03 18:24:23 +08004842
4843 private void checkModifyPhoneStatePermission(int subId, String message) {
4844 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4845 message);
4846 }
4847
allenwtsu99c623b2020-01-03 18:24:23 +08004848 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004849 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004850 boolean isProvisioned) {
4851 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4852
4853 final long identity = Binder.clearCallingIdentity();
4854 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004855 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4856 if (controller == null) {
4857 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
4858 return;
4859 }
4860 controller.setRcsProvisioningStatusForCapability(
4861 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08004862 } finally {
4863 Binder.restoreCallingIdentity(identity);
4864 }
allenwtsu99c623b2020-01-03 18:24:23 +08004865 }
4866
4867
4868 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004869 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4870 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4871 mApp, subId, "getRcsProvisioningStatusForCapability");
4872
allenwtsu99c623b2020-01-03 18:24:23 +08004873 final long identity = Binder.clearCallingIdentity();
4874 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004875 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4876 if (controller == null) {
4877 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
4878
4879 // device does not support IMS, this method will return true always.
4880 return true;
4881 }
4882 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004883 } finally {
4884 Binder.restoreCallingIdentity(identity);
4885 }
4886 }
4887
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004888 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004889 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4890 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004891 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004892
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004893 final long identity = Binder.clearCallingIdentity();
4894 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004895 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4896 if (controller == null) {
4897 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
4898 return;
4899 }
4900 controller.setImsProvisioningStatusForCapability(
4901 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004902 } finally {
4903 Binder.restoreCallingIdentity(identity);
4904 }
4905 }
4906
4907 @Override
4908 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00004909 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4910 mApp, subId, "getProvisioningStatusForCapability");
4911
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004912 final long identity = Binder.clearCallingIdentity();
4913 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004914 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4915 if (controller == null) {
4916 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004917
joonhunshin91bc1952022-04-29 08:47:15 +00004918 // device does not support IMS, this method will return true always.
4919 return true;
4920 }
4921 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004922 } finally {
4923 Binder.restoreCallingIdentity(identity);
4924 }
4925 }
4926
4927 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004928 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4929 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4930 mApp, subId, "isProvisioningRequiredForCapability");
4931
4932 final long identity = Binder.clearCallingIdentity();
4933 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004934 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4935 if (controller == null) {
4936 loge("isProvisioningRequiredForCapability: Device does not support IMS");
4937
4938 // device does not support IMS, this method will return false
4939 return false;
4940 }
4941 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004942 } finally {
4943 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004944 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004945 }
4946
4947 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004948 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4949 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4950 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004951
joonhunshincffb7fc2021-11-28 07:32:01 +00004952 final long identity = Binder.clearCallingIdentity();
4953 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004954 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4955 if (controller == null) {
4956 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
4957
4958 // device does not support IMS, this method will return false
4959 return false;
4960 }
4961 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004962 } finally {
4963 Binder.restoreCallingIdentity(identity);
4964 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004965 }
4966
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004967 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004968 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004969 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4970 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4971 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004972 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4973 mApp, subId, "getImsProvisioningInt");
4974
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004975 final long identity = Binder.clearCallingIdentity();
4976 try {
4977 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004978 int slotId = getSlotIndex(subId);
4979 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4980 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4981 + subId + "' for key:" + key);
4982 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4983 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004984
joonhunshin91bc1952022-04-29 08:47:15 +00004985 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4986 if (controller == null) {
4987 loge("getImsProvisioningInt: Device does not support IMS");
4988
4989 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
4990 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4991 }
4992 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00004993 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4994 return retVal;
4995 }
4996
calvinpanb5a34062021-02-08 19:59:36 +08004997 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004998 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004999 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5000 + subId + "' for key:" + key);
5001 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005002 } finally {
5003 Binder.restoreCallingIdentity(identity);
5004 }
5005 }
5006
5007 @Override
5008 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005009 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5010 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5011 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005012 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5013 mApp, subId, "getImsProvisioningString");
5014
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005015 final long identity = Binder.clearCallingIdentity();
5016 try {
5017 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005018 int slotId = getSlotIndex(subId);
5019 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5020 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5021 + subId + "' for key:" + key);
5022 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5023 }
calvinpanb5a34062021-02-08 19:59:36 +08005024 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005025 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005026 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5027 + subId + "' for key:" + key);
5028 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005029 } finally {
5030 Binder.restoreCallingIdentity(identity);
5031 }
5032 }
5033
5034 @Override
5035 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005036 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5037 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5038 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005039 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5040 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005041
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005042 final long identity = Binder.clearCallingIdentity();
5043 try {
5044 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005045 int slotId = getSlotIndex(subId);
5046 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5047 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5048 + subId + "' for key:" + key);
5049 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5050 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005051
joonhunshin91bc1952022-04-29 08:47:15 +00005052 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5053 if (controller == null) {
5054 loge("setImsProvisioningInt: Device does not support IMS");
5055
5056 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5057 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5058 }
5059 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005060 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5061 return retVal;
5062 }
5063
calvinpanb5a34062021-02-08 19:59:36 +08005064 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5065 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005066 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005067 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005068 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005069 } finally {
5070 Binder.restoreCallingIdentity(identity);
5071 }
5072 }
5073
5074 @Override
5075 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005076 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5077 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5078 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005079 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5080 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005081 final long identity = Binder.clearCallingIdentity();
5082 try {
5083 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005084 int slotId = getSlotIndex(subId);
5085 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5086 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5087 + subId + "' for key:" + key);
5088 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5089 }
calvinpanb5a34062021-02-08 19:59:36 +08005090 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5091 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005092 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005093 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005094 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005095 } finally {
5096 Binder.restoreCallingIdentity(identity);
5097 }
5098 }
5099
Brad Ebinger919631e2021-06-02 17:46:35 -07005100 /**
5101 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5102 * for the given slot ID or no ImsResolver instance has been created.
5103 * @param slotId The slot ID that the IMS service is created for.
5104 * @throws ImsException If there is no ImsService configured for this slot.
5105 */
5106 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5107 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5108 ImsFeature.FEATURE_MMTEL)) {
5109 throw new ImsException("This subscription does not support MMTEL over IMS",
5110 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5111 }
5112 }
5113
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005114 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005115 int slotId = SubscriptionManager.getSlotIndex(subId);
5116 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005117 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5118 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005119 }
5120 return slotId;
5121 }
5122
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005123 private int getSlotIndex(int subId) {
5124 int slotId = SubscriptionManager.getSlotIndex(subId);
5125 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5126 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5127 }
5128 return slotId;
5129 }
5130
Wink Saville36469e72014-06-11 15:17:00 -07005131 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005132 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005133 */
5134 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005135 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5136 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005137 try {
5138 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5139 } catch (SecurityException se) {
5140 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5141 throw new SecurityException("Package " + callingPackage + " does not belong to "
5142 + Binder.getCallingUid());
5143 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005144 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005145 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005146 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005147 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005148 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005149 mApp, subId, callingPackage, callingFeatureId,
5150 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005151 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5152 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005153
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005154 final long identity = Binder.clearCallingIdentity();
5155 try {
5156 final Phone phone = getPhone(subId);
5157 if (phone != null) {
5158 return phone.getServiceState().getDataNetworkType();
5159 } else {
5160 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5161 }
5162 } finally {
5163 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005164 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005165 }
5166
5167 /**
5168 * Returns the data network type
5169 */
5170 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005171 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005172 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5173 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005174 }
5175
5176 /**
5177 * Returns the data network type for a subId
5178 */
5179 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005180 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5181 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005182 String functionName = "getDataNetworkTypeForSubscriber";
5183 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5184 mApp, functionName)) {
5185 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5186 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5187 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5188 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005189 }
5190
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005191 final long identity = Binder.clearCallingIdentity();
5192 try {
5193 final Phone phone = getPhone(subId);
5194 if (phone != null) {
5195 return phone.getServiceState().getDataNetworkType();
5196 } else {
5197 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5198 }
5199 } finally {
5200 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005201 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005202 }
5203
5204 /**
Wink Saville36469e72014-06-11 15:17:00 -07005205 * Returns the Voice network type for a subId
5206 */
5207 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005208 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5209 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005210 String functionName = "getVoiceNetworkTypeForSubscriber";
5211 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5212 mApp, functionName)) {
5213 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5214 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5215 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5216 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005217 }
5218
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005219 final long identity = Binder.clearCallingIdentity();
5220 try {
5221 final Phone phone = getPhone(subId);
5222 if (phone != null) {
5223 return phone.getServiceState().getVoiceNetworkType();
5224 } else {
5225 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5226 }
5227 } finally {
5228 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005229 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005230 }
5231
5232 /**
5233 * @return true if a ICC card is present
5234 */
5235 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005236 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005237 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5238 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005239 }
5240
5241 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005242 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005243 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005244 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005245 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005246 final long identity = Binder.clearCallingIdentity();
5247 try {
5248 final Phone phone = PhoneFactory.getPhone(slotIndex);
5249 if (phone != null) {
5250 return phone.getIccCard().hasIccCard();
5251 } else {
5252 return false;
5253 }
5254 } finally {
5255 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005256 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005257 }
5258
5259 /**
5260 * Return if the current radio is LTE on CDMA. This
5261 * is a tri-state return value as for a period of time
5262 * the mode may be unknown.
5263 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005264 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005265 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005266 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005267 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005268 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005269 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5270 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5271 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005272 }
5273
Sanket Padawe356d7632015-06-22 14:03:32 -07005274 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005275 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5276 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005277 try {
5278 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5279 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005280 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5281 }
5282
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005283 final long identity = Binder.clearCallingIdentity();
5284 try {
5285 final Phone phone = getPhone(subId);
5286 if (phone == null) {
5287 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5288 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005289 return TelephonyProperties.lte_on_cdma_device()
5290 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005291 }
5292 } finally {
5293 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005294 }
Wink Saville36469e72014-06-11 15:17:00 -07005295 }
5296
Wink Saville36469e72014-06-11 15:17:00 -07005297 /**
5298 * {@hide}
5299 * Returns Default subId, 0 in the case of single standby.
5300 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005301 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005302 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005303 }
5304
Shishir Agrawala9f32182016-04-12 12:00:16 -07005305 private int getSlotForDefaultSubscription() {
5306 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5307 }
5308
Wink Savilleb564aae2014-10-23 10:18:09 -07005309 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005310 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005311 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005312
Pengquan Menge92a50d2018-09-21 15:54:48 -07005313 private boolean isActiveSubscription(int subId) {
5314 return mSubscriptionController.isActiveSubId(subId);
5315 }
5316
Ihab Awadf2177b72013-11-25 13:33:23 -08005317 /**
5318 * @see android.telephony.TelephonyManager.WifiCallingChoices
5319 */
5320 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005321 final long identity = Binder.clearCallingIdentity();
5322 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005323 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005324 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5325 getWhenToMakeWifiCallsDefaultPreference());
5326 } finally {
5327 Binder.restoreCallingIdentity(identity);
5328 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005329 }
5330
5331 /**
5332 * @see android.telephony.TelephonyManager.WifiCallingChoices
5333 */
5334 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005335 final long identity = Binder.clearCallingIdentity();
5336 try {
5337 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005338 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005339 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5340 } finally {
5341 Binder.restoreCallingIdentity(identity);
5342 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005343 }
5344
Sailesh Nepald1e68152013-12-12 19:08:02 -08005345 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005346 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005347 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005348 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005349
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005350 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5351 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5352 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005353 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005354 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5355 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005356 }
5357 return PhoneFactory.getPhone(phoneId);
5358 }
5359
Shishir Agrawal566b7612013-10-28 14:41:00 -07005360 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005361 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005362 @NonNull IccLogicalChannelRequest request) {
5363 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5364 /*message=*/ "iccOpenLogicalChannel");
5365
5366 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5367 // Verify that the callingPackage in the request belongs to the calling UID
5368 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5369
5370 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005371 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005372
Rambo Wanga1782702021-11-10 20:15:19 -08005373 private Phone getPhoneFromValidIccLogicalChannelRequest(
5374 @NonNull IccLogicalChannelRequest request, String message) {
5375 Phone phone;
5376 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5377 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5378 mApp, request.subId, message);
5379 phone = getPhoneFromSubId(request.subId);
5380 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5381 enforceModifyPermission();
5382 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5383 } else {
5384 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005385 }
Rambo Wanga1782702021-11-10 20:15:19 -08005386 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005387 }
5388
5389 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005390 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005391 final long identity = Binder.clearCallingIdentity();
5392 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005393 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005394 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005395 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5396 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005397 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5398 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005399 loge("The calling package is not allowed to access ISD-R.");
5400 throw new SecurityException(
5401 "The calling package is not allowed to access ISD-R.");
5402 }
Derek Tan740e1672017-06-27 14:56:27 -07005403 }
Derek Tan740e1672017-06-27 14:56:27 -07005404
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005405 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005406 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5407 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005408 return response;
5409 } finally {
5410 Binder.restoreCallingIdentity(identity);
5411 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005412 }
5413
5414 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005415 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5416 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5417 /*message=*/"iccCloseLogicalChannel");
5418
5419 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5420
5421 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005422 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005423
Rambo Wanga1782702021-11-10 20:15:19 -08005424 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5425 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005426 // before this feature is enabled, this API should only return false if
5427 // the operation fails instead of throwing runtime exception for
5428 // backward-compatibility.
5429 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5430 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005431 final long identity = Binder.clearCallingIdentity();
5432 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005433 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005434 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005435 }
Chen Xue9d737e2022-01-01 23:41:31 -08005436 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005437 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005438 Boolean success = false;
5439 if (result instanceof RuntimeException) {
5440 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005441 if (shouldThrowExceptionOnFailure) {
5442 throw (RuntimeException) result;
5443 } else {
5444 return false;
5445 }
Chen Xue9d737e2022-01-01 23:41:31 -08005446 } else if (result instanceof Boolean) {
5447 success = (Boolean) result;
5448 } else {
5449 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5450 }
Rambo Wanga1782702021-11-10 20:15:19 -08005451 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005452 return success;
5453 } finally {
5454 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005455 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005456 }
5457
5458 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005459 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005460 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005461 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5462 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005463 if (DBG) {
5464 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5465 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5466 + p3 + " data=" + data);
5467 }
5468 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5469 command, p1, p2, p3, data);
5470 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005471
Jordan Liu4c733742019-02-28 12:03:40 -08005472 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005473 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5474 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005475 enforceModifyPermission();
5476 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005477 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5478 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5479 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005480 }
5481 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005482 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5483 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005484 }
5485
5486 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5487 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005488 final long identity = Binder.clearCallingIdentity();
5489 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005490 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005491 return "";
5492 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005493
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005494 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005495 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5496 null /* workSource */);
5497 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005498
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005499 // Append the returned status code to the end of the response payload.
5500 String s = Integer.toHexString(
5501 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5502 if (response.payload != null) {
5503 s = IccUtils.bytesToHexString(response.payload) + s;
5504 }
5505 return s;
5506 } finally {
5507 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005508 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005509 }
Jake Hambye994d462014-02-03 13:10:13 -08005510
Evan Charltonc66da362014-05-16 14:06:40 -07005511 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005512 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5513 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005514 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5515 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005516 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005517 if (DBG) {
5518 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5519 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5520 }
5521 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5522 cla, command, p1, p2, p3, data);
5523 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005524
Jordan Liu4c733742019-02-28 12:03:40 -08005525 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005526 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5527 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005528 enforceModifyPermission();
5529 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5530 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005531 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5532 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5533 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005534 }
5535
5536 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005537 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5538 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005539 }
5540
5541 // open APDU basic channel assuming the caller has sufficient permissions
5542 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5543 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005544 final long identity = Binder.clearCallingIdentity();
5545 try {
5546 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5547 && TextUtils.equals(ISDR_AID, data)) {
5548 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005549 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5550 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005551 if (bestComponent == null
5552 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5553 loge("The calling package is not allowed to select ISD-R.");
5554 throw new SecurityException(
5555 "The calling package is not allowed to select ISD-R.");
5556 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005557 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005558
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005559 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005560 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5561 null /* workSource */);
5562 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005563
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005564 // Append the returned status code to the end of the response payload.
5565 String s = Integer.toHexString(
5566 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5567 if (response.payload != null) {
5568 s = IccUtils.bytesToHexString(response.payload) + s;
5569 }
5570 return s;
5571 } finally {
5572 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005573 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005574 }
5575
5576 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005577 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005578 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005579 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5580 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005581
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005582 final long identity = Binder.clearCallingIdentity();
5583 try {
5584 if (DBG) {
5585 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5586 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5587 }
5588
5589 IccIoResult response =
5590 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5591 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5592 subId);
5593
5594 if (DBG) {
5595 log("Exchange SIM_IO [R]" + response);
5596 }
5597
5598 byte[] result = null;
5599 int length = 2;
5600 if (response.payload != null) {
5601 length = 2 + response.payload.length;
5602 result = new byte[length];
5603 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5604 } else {
5605 result = new byte[length];
5606 }
5607
5608 result[length - 1] = (byte) response.sw2;
5609 result[length - 2] = (byte) response.sw1;
5610 return result;
5611 } finally {
5612 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005613 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005614 }
5615
Nathan Haroldb3014052017-01-25 15:57:32 -08005616 /**
5617 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5618 * on a particular subscription
5619 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005620 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5621 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005622 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005623 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005624 return null;
5625 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005626
5627 final long identity = Binder.clearCallingIdentity();
5628 try {
5629 if (appType != TelephonyManager.APPTYPE_USIM
5630 && appType != TelephonyManager.APPTYPE_SIM) {
5631 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5632 return null;
5633 }
5634 Object response = sendRequest(
5635 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5636 if (response instanceof String[]) {
5637 return (String[]) response;
5638 }
yincheng zhao2737e882019-09-06 17:06:54 -07005639 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005640 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005641 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005642 } finally {
5643 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005644 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005645 }
5646
yincheng zhao2737e882019-09-06 17:06:54 -07005647 /**
5648 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5649 * subscription.
5650 *
5651 * @param subId the id of the subscription.
5652 * @param appType the uicc app type, must be USIM or SIM.
5653 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5654 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005655 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005656 * @return number of fplmns that is successfully written to the SIM.
5657 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005658 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5659 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005660 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5661 mApp, subId, "setForbiddenPlmns");
5662
yincheng zhao2737e882019-09-06 17:06:54 -07005663 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5664 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5665 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5666 }
5667 if (fplmns == null) {
5668 throw new IllegalArgumentException("Fplmn List provided is null");
5669 }
5670 for (String fplmn : fplmns) {
5671 if (!CellIdentity.isValidPlmn(fplmn)) {
5672 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5673 }
5674 }
5675 final long identity = Binder.clearCallingIdentity();
5676 try {
5677 Object response = sendRequest(
5678 CMD_SET_FORBIDDEN_PLMNS,
5679 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5680 subId);
5681 return (int) response;
5682 } finally {
5683 Binder.restoreCallingIdentity(identity);
5684 }
5685 }
5686
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005687 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005688 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005689 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5690 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005691
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005692 final long identity = Binder.clearCallingIdentity();
5693 try {
5694 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5695 if (response.payload == null) {
5696 return "";
5697 }
Evan Charltonc66da362014-05-16 14:06:40 -07005698
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005699 // Append the returned status code to the end of the response payload.
5700 String s = Integer.toHexString(
5701 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5702 s = IccUtils.bytesToHexString(response.payload) + s;
5703 return s;
5704 } finally {
5705 Binder.restoreCallingIdentity(identity);
5706 }
Evan Charltonc66da362014-05-16 14:06:40 -07005707 }
5708
Jake Hambye994d462014-02-03 13:10:13 -08005709 /**
5710 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5711 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5712 *
5713 * @param itemID the ID of the item to read
5714 * @return the NV item as a String, or null on error.
5715 */
5716 @Override
5717 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005718 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005719 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5720 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005721
5722 final long identity = Binder.clearCallingIdentity();
5723 try {
5724 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005725 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005726 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5727 return value;
5728 } finally {
5729 Binder.restoreCallingIdentity(identity);
5730 }
Jake Hambye994d462014-02-03 13:10:13 -08005731 }
5732
5733 /**
5734 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5735 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5736 *
5737 * @param itemID the ID of the item to read
5738 * @param itemValue the value to write, as a String
5739 * @return true on success; false on any failure
5740 */
5741 @Override
5742 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005743 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005744 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5745 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005746
5747 final long identity = Binder.clearCallingIdentity();
5748 try {
5749 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5750 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005751 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005752 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5753 return success;
5754 } finally {
5755 Binder.restoreCallingIdentity(identity);
5756 }
Jake Hambye994d462014-02-03 13:10:13 -08005757 }
5758
5759 /**
5760 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5761 * Used for device configuration by some CDMA operators.
5762 *
5763 * @param preferredRoamingList byte array containing the new PRL
5764 * @return true on success; false on any failure
5765 */
5766 @Override
5767 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005768 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5769 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005770
5771 final long identity = Binder.clearCallingIdentity();
5772 try {
5773 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5774 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5775 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5776 return success;
5777 } finally {
5778 Binder.restoreCallingIdentity(identity);
5779 }
Jake Hambye994d462014-02-03 13:10:13 -08005780 }
5781
5782 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005783 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005784 * Used for device configuration by some CDMA operators.
5785 *
chen xu6dac5ab2018-10-26 17:39:23 -07005786 * @param slotIndex - device slot.
5787 *
Jake Hambye994d462014-02-03 13:10:13 -08005788 * @return true on success; false on any failure
5789 */
5790 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005791 public boolean resetModemConfig(int slotIndex) {
5792 Phone phone = PhoneFactory.getPhone(slotIndex);
5793 if (phone != null) {
5794 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5795 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005796
chen xu6dac5ab2018-10-26 17:39:23 -07005797 final long identity = Binder.clearCallingIdentity();
5798 try {
5799 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5800 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5801 return success;
5802 } finally {
5803 Binder.restoreCallingIdentity(identity);
5804 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005805 }
chen xu6dac5ab2018-10-26 17:39:23 -07005806 return false;
5807 }
5808
5809 /**
5810 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5811 *
5812 * @param slotIndex - device slot.
5813 *
5814 * @return true on success; false on any failure
5815 */
5816 @Override
5817 public boolean rebootModem(int slotIndex) {
5818 Phone phone = PhoneFactory.getPhone(slotIndex);
5819 if (phone != null) {
5820 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5821 mApp, phone.getSubId(), "rebootModem");
5822
5823 final long identity = Binder.clearCallingIdentity();
5824 try {
5825 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5826 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5827 return success;
5828 } finally {
5829 Binder.restoreCallingIdentity(identity);
5830 }
5831 }
5832 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005833 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005834
Brad Ebinger51f743a2017-01-23 13:50:20 -08005835 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005836 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5837 * {@link #disableIms(int)}.
5838 * @param slotIndex device slot.
5839 */
5840 public void resetIms(int slotIndex) {
5841 enforceModifyPermission();
5842
5843 final long identity = Binder.clearCallingIdentity();
5844 try {
5845 if (mImsResolver == null) {
5846 // may happen if the does not support IMS.
5847 return;
5848 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00005849 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005850 } finally {
5851 Binder.restoreCallingIdentity(identity);
5852 }
5853 }
5854
5855 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005856 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5857 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005858 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005859 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005860 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005861
5862 final long identity = Binder.clearCallingIdentity();
5863 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005864 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005865 // may happen if the device does not support IMS.
5866 return;
5867 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005868 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005869 } finally {
5870 Binder.restoreCallingIdentity(identity);
5871 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005872 }
5873
5874 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005875 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5876 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005877 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005878 public void disableIms(int slotId) {
5879 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005880
5881 final long identity = Binder.clearCallingIdentity();
5882 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005883 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005884 // may happen if the device does not support IMS.
5885 return;
5886 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005887 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005888 } finally {
5889 Binder.restoreCallingIdentity(identity);
5890 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005891 }
5892
5893 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005894 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5895 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005896 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005897 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005898 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005899 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005900
5901 final long identity = Binder.clearCallingIdentity();
5902 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005903 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005904 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5905 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005906 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005907 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005908 } finally {
5909 Binder.restoreCallingIdentity(identity);
5910 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005911 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005912 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005913 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5914 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005915 @Override
5916 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005917 enforceModifyPermission();
5918
5919 final long identity = Binder.clearCallingIdentity();
5920 try {
5921 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005922 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005923 } finally {
5924 Binder.restoreCallingIdentity(identity);
5925 }
5926 }
5927
5928 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005929 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005930 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005931 */
5932 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5933 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005934
5935 final long identity = Binder.clearCallingIdentity();
5936 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005937 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005938 // may happen if the device does not support IMS.
5939 return null;
5940 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005941 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005942 } finally {
5943 Binder.restoreCallingIdentity(identity);
5944 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005945 }
5946
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005947 /**
5948 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005949 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005950 */
5951 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5952 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005953
5954 final long identity = Binder.clearCallingIdentity();
5955 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005956 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005957 // may happen if the device does not support IMS.
5958 return null;
5959 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005960 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005961 } finally {
5962 Binder.restoreCallingIdentity(identity);
5963 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005964 }
5965
Brad Ebinger884c07b2018-02-15 16:17:40 -08005966 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005967 * Sets the ImsService Package Name that Telephony will bind to.
5968 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005969 * @param slotIndex the slot ID that the ImsService should bind for.
5970 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005971 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005972 * @param featureTypes An integer array of feature types associated with a packageName.
5973 * @param packageName The name of the package that the current configuration will be replaced
5974 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005975 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005976 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005977 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5978 int[] featureTypes, String packageName) {
5979 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5980 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005981 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5982 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005983 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005984
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005985 final long identity = Binder.clearCallingIdentity();
5986 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005987 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005988 // may happen if the device does not support IMS.
5989 return false;
5990 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005991 Map<Integer, String> featureConfig = new HashMap<>();
5992 for (int featureType : featureTypes) {
5993 featureConfig.put(featureType, packageName);
5994 }
5995 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5996 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005997 } finally {
5998 Binder.restoreCallingIdentity(identity);
5999 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006000 }
6001
6002 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006003 * Clears any carrier ImsService overrides for the slot index specified that were previously
6004 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6005 *
6006 * This should only be used for testing.
6007 *
6008 * @param slotIndex the slot ID that the ImsService should bind for.
6009 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6010 */
6011 @Override
6012 public boolean clearCarrierImsServiceOverride(int slotIndex) {
6013 int[] subIds = SubscriptionManager.getSubId(slotIndex);
6014 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6015 "clearCarrierImsServiceOverride");
6016 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
6017 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
6018 "clearCarrierImsServiceOverride");
6019
6020 final long identity = Binder.clearCallingIdentity();
6021 try {
6022 if (mImsResolver == null) {
6023 // may happen if the device does not support IMS.
6024 return false;
6025 }
6026 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6027 } finally {
6028 Binder.restoreCallingIdentity(identity);
6029 }
6030 }
6031
6032 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006033 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006034 *
6035 * @param slotId The slot that the ImsService is associated with.
6036 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6037 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006038 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006039 * @return the package name of the ImsService configuration.
6040 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006041 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6042 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07006043 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08006044 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006045 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08006046 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
6047 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006048
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006049 final long identity = Binder.clearCallingIdentity();
6050 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006051 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006052 // may happen if the device does not support IMS.
6053 return "";
6054 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006055 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006056 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6057 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006058 } finally {
6059 Binder.restoreCallingIdentity(identity);
6060 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006061 }
6062
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006063 /**
6064 * Get the MmTelFeature state associated with the requested subscription id.
6065 * @param subId The subscription that the MmTelFeature is associated with.
6066 * @param callback A callback with an integer containing the
6067 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6068 */
6069 @Override
6070 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6071 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006072 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6073 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6074 "IMS not available on device.");
6075 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006076 final long token = Binder.clearCallingIdentity();
6077 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006078 int slotId = getSlotIndex(subId);
6079 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6080 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6081 + subId + "'");
6082 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6083 }
6084 verifyImsMmTelConfiguredOrThrow(slotId);
6085 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6086 try {
6087 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6088 } catch (RemoteException e) {
6089 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6090 + "Ignore");
6091 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006092 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006093 } catch (ImsException e) {
6094 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006095 } finally {
6096 Binder.restoreCallingIdentity(token);
6097 }
6098 }
6099
Daniel Brightbb5840b2021-01-12 15:48:18 -08006100 /**
6101 * Sets the ims registration state on all valid {@link Phone}s.
6102 */
6103 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006104 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006105
6106 final long identity = Binder.clearCallingIdentity();
6107 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006108 // NOTE: Before S, this method only set the default phone.
6109 for (final Phone phone : PhoneFactory.getPhones()) {
6110 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6111 phone.setImsRegistrationState(registered);
6112 }
6113 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006114 } finally {
6115 Binder.restoreCallingIdentity(identity);
6116 }
Wink Saville36469e72014-06-11 15:17:00 -07006117 }
6118
6119 /**
Stuart Scott54788802015-03-30 13:18:01 -07006120 * Set the network selection mode to automatic.
6121 *
6122 */
6123 @Override
6124 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006125 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6126 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006127
6128 final long identity = Binder.clearCallingIdentity();
6129 try {
shilufc958392020-01-20 11:36:01 -08006130 if (!isActiveSubscription(subId)) {
6131 return;
6132 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006133 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006134 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6135 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006136 } finally {
6137 Binder.restoreCallingIdentity(identity);
6138 }
Stuart Scott54788802015-03-30 13:18:01 -07006139 }
6140
Jack Yud10cdd42020-09-28 20:28:01 -07006141 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006142 * Ask the radio to connect to the input network and change selection mode to manual.
6143 *
6144 * @param subId the id of the subscription.
6145 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6146 * the operator to attach to.
6147 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6148 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6149 * normal network selection next time.
6150 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006151 */
6152 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006153 public boolean setNetworkSelectionModeManual(
6154 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006155 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6156 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006157
6158 if (!isActiveSubscription(subId)) {
6159 return false;
6160 }
6161
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006162 final long identity = Binder.clearCallingIdentity();
6163 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006164 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006165 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006166 if (DBG) {
6167 log("setNetworkSelectionModeManual: subId: " + subId
6168 + " operator: " + operatorInfo);
6169 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006170 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6171 } finally {
6172 Binder.restoreCallingIdentity(identity);
6173 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006174 }
shilu84f6e8b2019-12-19 13:58:01 -08006175 /**
6176 * Get the manual network selection
6177 *
6178 * @param subId the id of the subscription.
6179 *
6180 * @return the previously saved user selected PLMN
6181 */
6182 @Override
6183 public String getManualNetworkSelectionPlmn(int subId) {
6184 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006185 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006186 mApp, subId, "getManualNetworkSelectionPlmn");
6187
6188 final long identity = Binder.clearCallingIdentity();
6189 try {
6190 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006191 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006192 }
6193
6194 final Phone phone = getPhone(subId);
6195 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006196 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006197 }
6198 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6199 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6200 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6201 } finally {
6202 Binder.restoreCallingIdentity(identity);
6203 }
6204 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006205
6206 /**
6207 * Scans for available networks.
6208 */
6209 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006210 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6211 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006212 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6213 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006214 LocationAccessPolicy.LocationPermissionResult locationResult =
6215 LocationAccessPolicy.checkLocationPermission(mApp,
6216 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6217 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006218 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006219 .setCallingPid(Binder.getCallingPid())
6220 .setCallingUid(Binder.getCallingUid())
6221 .setMethod("getCellNetworkScanResults")
6222 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006223 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6224 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006225 .build());
6226 switch (locationResult) {
6227 case DENIED_HARD:
6228 throw new SecurityException("Not allowed to access scan results -- location");
6229 case DENIED_SOFT:
6230 return null;
6231 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006232
Pengquan Menga1bb6272018-09-06 09:59:22 -07006233 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006234 try {
6235 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006236 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006237 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006238 } finally {
6239 Binder.restoreCallingIdentity(identity);
6240 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006241 }
6242
6243 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006244 * Get the call forwarding info, given the call forwarding reason.
6245 */
6246 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006247 public void getCallForwarding(int subId, int callForwardingReason,
6248 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006249 enforceReadPrivilegedPermission("getCallForwarding");
6250 long identity = Binder.clearCallingIdentity();
6251 try {
6252 if (DBG) {
6253 log("getCallForwarding: subId " + subId
6254 + " callForwardingReason" + callForwardingReason);
6255 }
Hall Liu27d24262020-09-18 19:04:59 -07006256
6257 Phone phone = getPhone(subId);
6258 if (phone == null) {
6259 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006260 callback.onError(
6261 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006262 } catch (RemoteException e) {
6263 // ignore
6264 }
6265 return;
6266 }
6267
6268 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6269 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6270 @Override
6271 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6272 try {
6273 callback.onCallForwardingInfoAvailable(info);
6274 } catch (RemoteException e) {
6275 // ignore
6276 }
6277 }
6278
6279 @Override
6280 public void onError(int error) {
6281 try {
6282 callback.onError(error);
6283 } catch (RemoteException e) {
6284 // ignore
6285 }
6286 }
6287 });
6288 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006289 } finally {
6290 Binder.restoreCallingIdentity(identity);
6291 }
6292 }
6293
6294 /**
6295 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6296 * reason, the number to forward, and the timeout before the forwarding is attempted.
6297 */
6298 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006299 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6300 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006301 enforceModifyPermission();
6302 long identity = Binder.clearCallingIdentity();
6303 try {
6304 if (DBG) {
6305 log("setCallForwarding: subId " + subId
6306 + " callForwardingInfo" + callForwardingInfo);
6307 }
Hall Liu27d24262020-09-18 19:04:59 -07006308
6309 Phone phone = getPhone(subId);
6310 if (phone == null) {
6311 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006312 callback.accept(
6313 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006314 } catch (RemoteException e) {
6315 // ignore
6316 }
6317 return;
6318 }
6319
6320 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6321 FunctionalUtils.ignoreRemoteException(callback::accept));
6322
6323 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006324 } finally {
6325 Binder.restoreCallingIdentity(identity);
6326 }
6327 }
6328
6329 /**
Hall Liu27d24262020-09-18 19:04:59 -07006330 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006331 */
6332 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006333 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006334 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006335 long identity = Binder.clearCallingIdentity();
6336 try {
Hall Liu27d24262020-09-18 19:04:59 -07006337 Phone phone = getPhone(subId);
6338 if (phone == null) {
6339 try {
6340 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6341 } catch (RemoteException e) {
6342 // ignore
6343 }
6344 return;
6345 }
SongFerngWang0e767992021-03-31 22:08:45 +08006346 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6347 PersistableBundle c = configManager.getConfigForSubId(subId);
6348 boolean requireUssd = c.getBoolean(
6349 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006350
Shuo Qian4a594052020-01-23 11:59:30 -08006351 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006352 if (requireUssd) {
6353 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6354 getSubscriptionCarrierId(subId));
6355 String newUssdCommand = "";
6356 try {
6357 newUssdCommand = carrierXmlParser.getFeature(
6358 CarrierXmlParser.FEATURE_CALL_WAITING)
6359 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6360 } catch (NullPointerException e) {
6361 loge("Failed to generate USSD number" + e);
6362 }
6363 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6364 mMainThreadHandler, callback, carrierXmlParser,
6365 CarrierXmlParser.SsEntry.SSAction.QUERY);
6366 final String ussdCommand = newUssdCommand;
6367 Executors.newSingleThreadExecutor().execute(() -> {
6368 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6369 });
6370 } else {
6371 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6372 callback::accept);
6373 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6374 }
Shuo Qian4a594052020-01-23 11:59:30 -08006375 } finally {
6376 Binder.restoreCallingIdentity(identity);
6377 }
6378 }
6379
6380 /**
Hall Liu27d24262020-09-18 19:04:59 -07006381 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006382 */
6383 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006384 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006385 enforceModifyPermission();
6386 long identity = Binder.clearCallingIdentity();
6387 try {
Hall Liu27d24262020-09-18 19:04:59 -07006388 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6389
6390 Phone phone = getPhone(subId);
6391 if (phone == null) {
6392 try {
6393 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6394 } catch (RemoteException e) {
6395 // ignore
6396 }
6397 return;
6398 }
6399
SongFerngWang0e767992021-03-31 22:08:45 +08006400 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6401 PersistableBundle c = configManager.getConfigForSubId(subId);
6402 boolean requireUssd = c.getBoolean(
6403 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006404
SongFerngWang0e767992021-03-31 22:08:45 +08006405 if (DBG) log("getCallWaitingStatus: subId " + subId);
6406 if (requireUssd) {
6407 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6408 getSubscriptionCarrierId(subId));
6409 CarrierXmlParser.SsEntry.SSAction ssAction =
6410 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6411 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6412 String newUssdCommand = "";
6413 try {
6414 newUssdCommand = carrierXmlParser.getFeature(
6415 CarrierXmlParser.FEATURE_CALL_WAITING)
6416 .makeCommand(ssAction, null);
6417 } catch (NullPointerException e) {
6418 loge("Failed to generate USSD number" + e);
6419 }
6420 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6421 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6422 final String ussdCommand = newUssdCommand;
6423 Executors.newSingleThreadExecutor().execute(() -> {
6424 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6425 });
6426 } else {
6427 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6428 FunctionalUtils.ignoreRemoteException(callback::accept));
6429
6430 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6431 }
Shuo Qian4a594052020-01-23 11:59:30 -08006432 } finally {
6433 Binder.restoreCallingIdentity(identity);
6434 }
6435 }
6436
6437 /**
yinxub1bed742017-04-17 11:45:04 -07006438 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006439 *
yinxub1bed742017-04-17 11:45:04 -07006440 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006441 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6442 * location related information which will be sent if the caller already possess
6443 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006444 * @param request contains the radio access networks with bands/channels to scan
6445 * @param messenger callback messenger for scan results or errors
6446 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006447 * @return the id of the requested scan which can be used to stop the scan.
6448 */
6449 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006450 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6451 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006452 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006453 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6454 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006455 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006456 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6457 if (!renounceFineLocationAccess) {
6458 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6459 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6460 .setCallingPackage(callingPackage)
6461 .setCallingFeatureId(callingFeatureId)
6462 .setCallingPid(Binder.getCallingPid())
6463 .setCallingUid(Binder.getCallingUid())
6464 .setMethod("requestNetworkScan")
6465 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6466 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6467 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6468 .build());
6469 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006470 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006471 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6472 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006473 if (e != null) {
6474 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6475 throw e;
6476 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006477 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006478 return TelephonyScanManager.INVALID_SCAN_ID;
6479 }
6480 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006481 }
Hall Liu912dfd32019-04-25 14:02:26 -07006482 int callingUid = Binder.getCallingUid();
6483 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006484 final long identity = Binder.clearCallingIdentity();
6485 try {
6486 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006487 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006488 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006489 } finally {
6490 Binder.restoreCallingIdentity(identity);
6491 }
yinxu504e1392017-04-12 16:03:22 -07006492 }
6493
Hall Liub2ac8ef2019-02-28 15:56:23 -08006494 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006495 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00006496 boolean hasCarrierPriv;
6497 final long identity = Binder.clearCallingIdentity();
6498 try {
6499 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6500 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6501 } finally {
6502 Binder.restoreCallingIdentity(identity);
6503 }
Hall Liu558027f2019-05-15 19:14:05 -07006504 boolean hasNetworkScanPermission =
6505 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6506 == PERMISSION_GRANTED;
6507
6508 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6509 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6510 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006511 }
6512
6513 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6514 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006515 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6516 return new SecurityException("Specific channels must not be"
6517 + " scanned without location access.");
6518 }
6519 }
6520 }
6521
Hall Liub2ac8ef2019-02-28 15:56:23 -08006522 return null;
6523 }
6524
yinxu504e1392017-04-12 16:03:22 -07006525 /**
6526 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006527 *
6528 * @param subId id of the subscription
6529 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006530 */
6531 @Override
6532 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006533 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6534 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006535
Hall Liu912dfd32019-04-25 14:02:26 -07006536 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006537 final long identity = Binder.clearCallingIdentity();
6538 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006539 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006540 } finally {
6541 Binder.restoreCallingIdentity(identity);
6542 }
yinxu504e1392017-04-12 16:03:22 -07006543 }
6544
6545 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006546 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006547 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006548 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006549 */
6550 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006551 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006552 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006553 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006554 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006555
6556 final long identity = Binder.clearCallingIdentity();
6557 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006558 if (DBG) log("getAllowedNetworkTypesBitmask");
6559 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6560 int networkTypesBitmask = (result != null ? result[0] : -1);
6561 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6562 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006563 } finally {
6564 Binder.restoreCallingIdentity(identity);
6565 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006566 }
6567
6568 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006569 * Get the allowed network types for certain reason.
6570 *
6571 * @param subId the id of the subscription.
6572 * @param reason the reason the allowed network type change is taking place
6573 * @return the allowed network types.
6574 */
6575 @Override
6576 public long getAllowedNetworkTypesForReason(int subId,
6577 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006578 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006579 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006580 final long identity = Binder.clearCallingIdentity();
6581 try {
6582 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6583 } finally {
6584 Binder.restoreCallingIdentity(identity);
6585 }
6586 }
6587
6588 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006589 * Enable/Disable E-UTRA-NR Dual Connectivity
6590 * @param subId subscription id of the sim card
6591 * @param nrDualConnectivityState expected NR dual connectivity state
6592 * This can be passed following states
6593 * <ol>
6594 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6595 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6596 * <li>Disable NR dual connectivity and force secondary cell to be released
6597 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6598 * </ol>
6599 * @return operation result.
6600 */
6601 @Override
6602 public int setNrDualConnectivityState(int subId,
6603 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6604 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6605 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006606 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006607 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6608 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6609 }
6610
Sooraj Sasindran37444802020-08-11 10:40:43 -07006611 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6612 final long identity = Binder.clearCallingIdentity();
6613 try {
6614 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6615 nrDualConnectivityState, subId,
6616 workSource);
6617 if (DBG) log("enableNRDualConnectivity result: " + result);
6618 return result;
6619 } finally {
6620 Binder.restoreCallingIdentity(identity);
6621 }
6622 }
6623
6624 /**
6625 * Is E-UTRA-NR Dual Connectivity enabled
6626 * @return true if dual connectivity is enabled else false
6627 */
6628 @Override
6629 public boolean isNrDualConnectivityEnabled(int subId) {
6630 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006631 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006632 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006633 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006634 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6635 return false;
6636 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006637 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6638 final long identity = Binder.clearCallingIdentity();
6639 try {
6640 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6641 null, subId, workSource);
6642 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6643 return isEnabled;
6644 } finally {
6645 Binder.restoreCallingIdentity(identity);
6646 }
6647 }
6648
6649 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006650 * Set the allowed network types of the device and
6651 * provide the reason triggering the allowed network change.
6652 *
6653 * @param subId the id of the subscription.
6654 * @param reason the reason the allowed network type change is taking place
6655 * @param allowedNetworkTypes the allowed network types.
6656 * @return true on success; false on any failure.
6657 */
6658 @Override
6659 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006660 @TelephonyManager.AllowedNetworkTypesReason int reason,
6661 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006662 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6663 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006664 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006665 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6666 return false;
6667 }
6668 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6669 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006670 return false;
6671 }
6672
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006673 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6674 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6675
6676
6677 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6678 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6679 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006680 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006681
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006682 final long identity = Binder.clearCallingIdentity();
6683 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006684 Boolean success = (Boolean) sendRequest(
6685 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6686 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6687
6688 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6689 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006690 } finally {
6691 Binder.restoreCallingIdentity(identity);
6692 }
6693 }
6694
6695 /**
Miaoa84611c2019-03-15 09:21:10 +08006696 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006697 *
Miaoa84611c2019-03-15 09:21:10 +08006698 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006699 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006700 * @hide
6701 */
6702 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006703 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006704 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006705 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006706 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006707 try {
Miaoa84611c2019-03-15 09:21:10 +08006708 if (phone != null) {
6709 return phone.hasMatchedTetherApnSetting();
6710 } else {
6711 return false;
6712 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006713 } finally {
6714 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006715 }
Junda Liu475951f2014-11-07 16:45:03 -08006716 }
6717
6718 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006719 * Get the user enabled state of Mobile Data.
6720 *
6721 * TODO: remove and use isUserDataEnabled.
6722 * This can't be removed now because some vendor codes
6723 * calls through ITelephony directly while they should
6724 * use TelephonyManager.
6725 *
6726 * @return true on enabled
6727 */
6728 @Override
6729 public boolean getDataEnabled(int subId) {
6730 return isUserDataEnabled(subId);
6731 }
6732
6733 /**
6734 * Get whether mobile data is enabled per user setting.
6735 *
6736 * There are other factors deciding whether mobile data is actually enabled, but they are
6737 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006738 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006739 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6740 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006741 *
6742 * @return {@code true} if data is enabled else {@code false}
6743 */
6744 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006745 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006746 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006747 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006748 try {
6749 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6750 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006751 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006752 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6753 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006754 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006755 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006756 mApp, subId, functionName);
6757
Robert Greenwalt646120a2014-05-23 11:54:03 -07006758 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006759
6760 final long identity = Binder.clearCallingIdentity();
6761 try {
6762 int phoneId = mSubscriptionController.getPhoneId(subId);
6763 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6764 Phone phone = PhoneFactory.getPhone(phoneId);
6765 if (phone != null) {
6766 boolean retVal = phone.isUserDataEnabled();
6767 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6768 return retVal;
6769 } else {
6770 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6771 return false;
6772 }
6773 } finally {
6774 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006775 }
6776 }
6777
6778 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006779 * Checks if the device is capable of mobile data by considering whether whether the
6780 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6781 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006782 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006783 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006784 */
6785 @Override
6786 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006787 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006788 try {
6789 try {
6790 mApp.enforceCallingOrSelfPermission(
6791 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006792 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006793 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006794 try {
6795 mApp.enforceCallingOrSelfPermission(
6796 android.Manifest.permission.READ_PHONE_STATE,
6797 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006798 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006799 mApp.enforceCallingOrSelfPermission(
6800 permission.READ_BASIC_PHONE_STATE, functionName);
6801 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006802 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006803 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006804 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006805 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006806
6807 final long identity = Binder.clearCallingIdentity();
6808 try {
6809 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006810 Phone phone = PhoneFactory.getPhone(phoneId);
6811 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07006812 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006813 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006814 return retVal;
6815 } else {
6816 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6817 return false;
6818 }
6819 } finally {
6820 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006821 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006822 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006823
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006824 /**
6825 * Check if data is enabled for a specific reason
6826 * @param subId Subscription index
6827 * @param reason the reason the data enable change is taking place
6828 * @return {@code true} if the overall data is enabled; {@code false} if not.
6829 */
6830 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006831 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006832 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006833 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006834 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006835 try {
6836 mApp.enforceCallingOrSelfPermission(
6837 android.Manifest.permission.ACCESS_NETWORK_STATE,
6838 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006839 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006840 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6841 functionName);
6842 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006843 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006844 try {
6845 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006846 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006847 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006848 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006849 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006850 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006851 }
6852
6853
6854 final long identity = Binder.clearCallingIdentity();
6855 try {
6856 int phoneId = mSubscriptionController.getPhoneId(subId);
6857 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006858 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006859 + " reason=" + reason);
6860 }
6861 Phone phone = PhoneFactory.getPhone(phoneId);
6862 if (phone != null) {
6863 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07006864 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006865 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006866 return retVal;
6867 } else {
6868 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006869 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006870 + subId + " retVal=false");
6871 }
6872 return false;
6873 }
6874 } finally {
6875 Binder.restoreCallingIdentity(identity);
6876 }
6877 }
6878
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006879 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006880 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006881 // No permission needed; this only lets the caller inspect their own status.
6882 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006883 }
Junda Liu29340342014-07-10 15:23:27 -07006884
6885 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006886 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006887 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006888 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6889 }
6890
6891 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6892 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006893 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006894 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006895 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6896 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006897 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6898 if (cpt == null) {
6899 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006900 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6901 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006902 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006903 }
6904
6905 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006906 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006907 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006908 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006909 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006910 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006911 Phone phone = getPhone(subId);
6912 if (phone == null) {
6913 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6914 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6915 }
6916 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6917 if (cpt == null) {
6918 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006919 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6920 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006921 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006922 }
6923
6924 @Override
6925 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006926 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08006927 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
6928 }
6929
6930 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006931 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006932 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006933 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006934 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006935 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6936 Phone phone = PhoneFactory.getPhone(phoneId);
6937 if (phone == null) {
6938 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006939 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006940 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6941 if (cpt == null) {
6942 continue;
6943 }
6944 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006945 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6946 break;
6947 }
6948 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006949 return result;
Junda Liu29340342014-07-10 15:23:27 -07006950 }
Derek Tan89e89d42014-07-08 17:00:10 -07006951
6952 @Override
Junda Liue64de782015-04-16 17:19:16 -07006953 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006954 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00006955 Phone phone = PhoneFactory.getPhone(phoneId);
6956 if (phone == null) {
6957 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006958 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006959 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6960 if (cpt == null) {
6961 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006962 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006963 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006964 }
6965
Amith Yamasani6e118872016-02-19 12:53:51 -08006966 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006967 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006968 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006969 Phone phone = PhoneFactory.getPhone(phoneId);
6970 if (phone == null) {
6971 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006972 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006973 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6974 if (cpt == null) {
6975 return Collections.emptyList();
6976 }
6977 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006978 }
6979
chen xuf7e9fe82019-05-09 19:31:02 -07006980 @Override
6981 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006982 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006983 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006984 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00006985 try {
6986 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6987 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6988 }
6989 } finally {
6990 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006991 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006992 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07006993 }
6994
Rambo Wang6812ffb2022-03-15 16:54:17 -07006995 @Override
6996 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
6997 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
6998
6999 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7000 if (phone == null) {
7001 return null;
7002 }
7003 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7004 if (cpt == null) {
7005 return null;
7006 }
7007 return cpt.getCarrierServicePackageName();
7008 }
7009
Wink Savilleb564aae2014-10-23 10:18:09 -07007010 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007011 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007012 UiccPort port = phone == null ? null : phone.getUiccPort();
7013 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007014 return null;
7015 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007016 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007017 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007018 return null;
7019 }
7020 return iccId;
7021 }
7022
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007023 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007024 public void setCallComposerStatus(int subId, int status) {
7025 enforceModifyPermission();
7026
7027 final long identity = Binder.clearCallingIdentity();
7028 try {
7029 Phone phone = getPhone(subId);
7030 if (phone != null) {
7031 Phone defaultPhone = phone.getImsPhone();
7032 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7033 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7034 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007035 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7036 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007037 }
7038 }
Shuo Qian284ae752020-12-22 19:10:14 -08007039 } catch (ImsException e) {
7040 throw new ServiceSpecificException(e.getCode());
7041 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007042 Binder.restoreCallingIdentity(identity);
7043 }
7044 }
7045
7046 @Override
7047 public int getCallComposerStatus(int subId) {
7048 enforceReadPrivilegedPermission("getCallComposerStatus");
7049
7050 final long identity = Binder.clearCallingIdentity();
7051 try {
7052 Phone phone = getPhone(subId);
7053 if (phone != null) {
7054 Phone defaultPhone = phone.getImsPhone();
7055 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7056 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7057 return imsPhone.getCallComposerStatus();
7058 }
7059 }
7060 } finally {
7061 Binder.restoreCallingIdentity(identity);
7062 }
7063 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7064 }
7065
7066 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007067 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7068 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007069 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007070 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007071
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007072 final long identity = Binder.clearCallingIdentity();
7073 try {
7074 final String iccId = getIccId(subId);
7075 final Phone phone = getPhone(subId);
7076 if (phone == null) {
7077 return false;
7078 }
7079 final String subscriberId = phone.getSubscriberId();
7080
7081 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007082 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007083 + subscriberId + " to " + number);
7084 }
7085
7086 if (TextUtils.isEmpty(iccId)) {
7087 return false;
7088 }
7089
7090 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7091
7092 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7093 if (alphaTag == null) {
7094 editor.remove(alphaTagPrefKey);
7095 } else {
7096 editor.putString(alphaTagPrefKey, alphaTag);
7097 }
7098
7099 // Record both the line number and IMSI for this ICCID, since we need to
7100 // track all merged IMSIs based on line number
7101 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7102 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7103 if (number == null) {
7104 editor.remove(numberPrefKey);
7105 editor.remove(subscriberPrefKey);
7106 } else {
7107 editor.putString(numberPrefKey, number);
7108 editor.putString(subscriberPrefKey, subscriberId);
7109 }
7110
7111 editor.commit();
7112 return true;
7113 } finally {
7114 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007115 }
Derek Tan7226c842014-07-02 17:42:23 -07007116 }
7117
7118 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007119 public String getLine1NumberForDisplay(int subId, String callingPackage,
7120 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007121 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007122 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007123 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007124 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007125 return null;
7126 }
Derek Tan97ebb422014-09-05 16:55:38 -07007127
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007128 final long identity = Binder.clearCallingIdentity();
7129 try {
7130 String iccId = getIccId(subId);
7131 if (iccId != null) {
7132 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7133 if (DBG_MERGE) {
7134 log("getLine1NumberForDisplay returning "
7135 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7136 }
7137 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007138 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007139 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7140 return null;
7141 } finally {
7142 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007143 }
Derek Tan7226c842014-07-02 17:42:23 -07007144 }
7145
7146 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007147 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7148 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007149 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007150 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007151 return null;
7152 }
Derek Tan97ebb422014-09-05 16:55:38 -07007153
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007154 final long identity = Binder.clearCallingIdentity();
7155 try {
7156 String iccId = getIccId(subId);
7157 if (iccId != null) {
7158 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7159 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7160 }
7161 return null;
7162 } finally {
7163 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007164 }
Derek Tan7226c842014-07-02 17:42:23 -07007165 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007166
7167 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007168 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7169 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007170 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7171 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007172 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007173 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007174 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007175 return null;
7176 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007177
Jordan Liub49b04b2019-05-06 14:45:15 -07007178 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7179 // the process, where TelephonyManager was instantiated.
7180 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007181 final long identity = Binder.clearCallingIdentity();
7182 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007183 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007184 final TelephonyManager tele = TelephonyManager.from(context);
7185 final SubscriptionManager sub = SubscriptionManager.from(context);
7186
7187 // Figure out what subscribers are currently active
7188 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007189
Jordan Liub49b04b2019-05-06 14:45:15 -07007190 // Only consider subs which match the current subId
7191 // This logic can be simplified. See b/131189269 for progress.
7192 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007193 activeSubscriberIds.add(tele.getSubscriberId(subId));
7194 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007195
7196 // First pass, find a number override for an active subscriber
7197 String mergeNumber = null;
7198 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7199 for (String key : prefs.keySet()) {
7200 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7201 final String subscriberId = (String) prefs.get(key);
7202 if (activeSubscriberIds.contains(subscriberId)) {
7203 final String iccId = key.substring(
7204 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7205 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7206 mergeNumber = (String) prefs.get(numberKey);
7207 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007208 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007209 + " for active subscriber " + subscriberId);
7210 }
7211 if (!TextUtils.isEmpty(mergeNumber)) {
7212 break;
7213 }
7214 }
7215 }
7216 }
7217
7218 // Shortcut when no active merged subscribers
7219 if (TextUtils.isEmpty(mergeNumber)) {
7220 return null;
7221 }
7222
7223 // Second pass, find all subscribers under that line override
7224 final ArraySet<String> result = new ArraySet<>();
7225 for (String key : prefs.keySet()) {
7226 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7227 final String number = (String) prefs.get(key);
7228 if (mergeNumber.equals(number)) {
7229 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7230 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7231 final String subscriberId = (String) prefs.get(subscriberKey);
7232 if (!TextUtils.isEmpty(subscriberId)) {
7233 result.add(subscriberId);
7234 }
7235 }
7236 }
7237 }
7238
7239 final String[] resultArray = result.toArray(new String[result.size()]);
7240 Arrays.sort(resultArray);
7241 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007242 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007243 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7244 }
7245 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007246 } finally {
7247 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007248 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007249 }
7250
7251 @Override
zoey chen38003472019-12-13 17:16:31 +08007252 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7253 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007254
7255 final long identity = Binder.clearCallingIdentity();
7256 try {
7257 final TelephonyManager telephonyManager = mApp.getSystemService(
7258 TelephonyManager.class);
7259 String subscriberId = telephonyManager.getSubscriberId(subId);
7260 if (subscriberId == null) {
7261 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007262 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007263 + subId);
7264 }
7265 return null;
7266 }
7267
7268 final SubscriptionInfo info = SubscriptionController.getInstance()
7269 .getSubscriptionInfo(subId);
7270 final ParcelUuid groupUuid = info.getGroupUuid();
7271 // If it doesn't belong to any group, return just subscriberId of itself.
7272 if (groupUuid == null) {
7273 return new String[]{subscriberId};
7274 }
7275
7276 // Get all subscriberIds from the group.
7277 final List<String> mergedSubscriberIds = new ArrayList<>();
7278 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007279 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007280 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007281 for (SubscriptionInfo subInfo : groupInfos) {
7282 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7283 if (subscriberId != null) {
7284 mergedSubscriberIds.add(subscriberId);
7285 }
7286 }
7287
7288 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7289 } finally {
7290 Binder.restoreCallingIdentity(identity);
7291
7292 }
7293 }
7294
7295 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007296 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007297 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007298 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007299
7300 final long identity = Binder.clearCallingIdentity();
7301 try {
7302 final Phone phone = getPhone(subId);
7303 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7304 } finally {
7305 Binder.restoreCallingIdentity(identity);
7306 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007307 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007308
7309 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007310 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007311 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7312 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007313 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7314 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007315
7316 final long identity = Binder.clearCallingIdentity();
7317 try {
7318 final Phone phone = getPhone(subId);
7319 if (phone == null) {
7320 return false;
7321 }
7322 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7323 cdmaNonRoamingList);
7324 } finally {
7325 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007326 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007327 }
7328
7329 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007330 @Deprecated
7331 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7332 enforceModifyPermission();
7333
7334 int returnValue = 0;
7335 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007336 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007337 if(result.exception == null) {
7338 if (result.result != null) {
7339 byte[] responseData = (byte[])(result.result);
7340 if(responseData.length > oemResp.length) {
7341 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7342 responseData.length + "bytes. Buffer Size is " +
7343 oemResp.length + "bytes.");
7344 }
7345 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7346 returnValue = responseData.length;
7347 }
7348 } else {
7349 CommandException ex = (CommandException) result.exception;
7350 returnValue = ex.getCommandError().ordinal();
7351 if(returnValue > 0) returnValue *= -1;
7352 }
7353 } catch (RuntimeException e) {
7354 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7355 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7356 if(returnValue > 0) returnValue *= -1;
7357 }
7358
7359 return returnValue;
7360 }
7361
7362 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007363 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007364 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007365 try {
7366 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007367 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007368 mApp, phone.getSubId(), "getRadioAccessFamily");
7369 } catch (SecurityException e) {
7370 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7371 throw e;
7372 }
chen xub97461a2018-10-26 14:17:57 -07007373 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007374 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007375 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007376 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007377 final long identity = Binder.clearCallingIdentity();
7378 try {
chen xub97461a2018-10-26 14:17:57 -07007379 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007380 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007381 mApp, phone.getSubId(), "getRadioAccessFamily");
7382 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007383 } finally {
7384 Binder.restoreCallingIdentity(identity);
7385 }
chen xub97461a2018-10-26 14:17:57 -07007386 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007387 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007388
7389 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007390 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007391 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007392 try {
7393 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7394 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007395 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007396 }
7397 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007398 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007399 }
7400 RoleManager rm = mApp.getSystemService(RoleManager.class);
7401 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7402 if (!dialerRoleHolders.contains(callingPackage)) {
7403 throw new SecurityException("App must be the dialer role holder to"
7404 + " upload a call composer pic");
7405 }
7406
7407 Executors.newSingleThreadExecutor().execute(() -> {
7408 ByteArrayOutputStream output = new ByteArrayOutputStream(
7409 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7410 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7411 boolean readUntilEnd = false;
7412 int totalBytesRead = 0;
7413 byte[] buffer = new byte[16 * 1024];
7414 while (true) {
7415 int numRead;
7416 try {
7417 numRead = input.read(buffer);
7418 } catch (IOException e) {
7419 try {
7420 fd.checkError();
7421 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7422 null);
7423 } catch (IOException e1) {
7424 // This means that the other side closed explicitly with an error. If this
7425 // happens, log and ignore.
7426 loge("Remote end of call composer picture pipe closed: " + e1);
7427 }
7428 break;
7429 }
7430 if (numRead == -1) {
7431 readUntilEnd = true;
7432 break;
7433 }
7434 totalBytesRead += numRead;
7435 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7436 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7437 try {
7438 input.close();
7439 } catch (IOException e) {
7440 // ignore
7441 }
7442 break;
7443 }
7444 output.write(buffer, 0, numRead);
7445 }
7446 // Generally, the remote end will close the file descriptors. The only case where we
7447 // close is above, where the picture size is too big.
7448
7449 try {
7450 fd.checkError();
7451 } catch (IOException e) {
7452 loge("Remote end for call composer closed with an error: " + e);
7453 return;
7454 }
7455
Hall Liuaa4211e2021-01-20 15:43:39 -08007456 if (!readUntilEnd) {
7457 loge("Did not finish reading entire image; aborting");
7458 return;
7459 }
Hall Liu82694d52020-12-11 18:22:04 -08007460
Hall Liuaa4211e2021-01-20 15:43:39 -08007461 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7462 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7463 new CallComposerPictureTransfer.Factory() {},
7464 imageData,
7465 (result) -> {
7466 if (result.first != null) {
7467 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7468 Bundle outputResult = new Bundle();
7469 outputResult.putParcelable(
7470 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7471 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7472 outputResult);
7473 } else {
7474 callback.send(result.second, null);
7475 }
7476 }
7477 );
Hall Liu82694d52020-12-11 18:22:04 -08007478 });
7479 }
7480
7481 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007482 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007483 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007484 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007485
7486 final long identity = Binder.clearCallingIdentity();
7487 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007488 ImsManager.getInstance(defaultPhone.getContext(),
7489 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007490 } finally {
7491 Binder.restoreCallingIdentity(identity);
7492 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007493 }
7494
7495 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007496 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007497 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007498 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7499 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007500 return false;
7501 }
Svet Ganovb320e182015-04-16 12:30:10 -07007502
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007503 final long identity = Binder.clearCallingIdentity();
7504 try {
7505 // Check the user preference and the system-level IMS setting. Even if the user has
7506 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7507 // In the long run, we may instead need to check if there exists a connection service
7508 // which can support video calling.
7509 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007510 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007511 return imsManager.isVtEnabledByPlatform()
7512 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7513 && imsManager.isVtEnabledByUser();
7514 } finally {
7515 Binder.restoreCallingIdentity(identity);
7516 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007517 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007518
Andrew Leea1239f22015-03-02 17:44:07 -08007519 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007520 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7521 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007522 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007523 mApp, subId, callingPackage, callingFeatureId,
7524 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007525 return false;
7526 }
7527
7528 final long identity = Binder.clearCallingIdentity();
7529 try {
7530 CarrierConfigManager configManager =
7531 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007532 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007533 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7534 } finally {
7535 Binder.restoreCallingIdentity(identity);
7536 }
Andrew Leea1239f22015-03-02 17:44:07 -08007537 }
7538
7539 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007540 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007541 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007542 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007543 return false;
7544 }
7545
7546 final long identity = Binder.clearCallingIdentity();
7547 try {
7548 CarrierConfigManager configManager =
7549 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007550 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007551 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7552 } finally {
7553 Binder.restoreCallingIdentity(identity);
7554 }
Andrew Leea1239f22015-03-02 17:44:07 -08007555 }
7556
Andrew Lee9431b832015-03-09 18:46:45 -07007557 @Override
7558 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007559 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007560 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007561 }
7562
7563 @Override
7564 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007565 final long identity = Binder.clearCallingIdentity();
7566 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007567 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007568 } finally {
7569 Binder.restoreCallingIdentity(identity);
7570 }
Andrew Lee9431b832015-03-09 18:46:45 -07007571 }
7572
Hall Liuf6668912018-10-31 17:05:23 -07007573 /**
7574 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7575 * support for the feature and device firmware support.
7576 *
7577 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7578 */
7579 @Override
7580 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007581 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007582 final Phone phone = getPhone(subscriptionId);
7583 if (phone == null) {
7584 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7585 return false;
7586 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007587 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007588 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007589 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7590 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007591 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007592 return isCarrierSupported && isDeviceSupported;
7593 } finally {
7594 Binder.restoreCallingIdentity(identity);
7595 }
Hall Liu98187582018-01-22 19:15:32 -08007596 }
7597
Hall Liuf6668912018-10-31 17:05:23 -07007598 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007599 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7600 * RTT setting, will return true if the device and carrier both support RTT.
7601 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007602 */
7603 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007604 final long identity = Binder.clearCallingIdentity();
7605 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007606 boolean isRttSupported = isRttSupported(subscriptionId);
7607 boolean isUserRttSettingOn = Settings.Secure.getInt(
7608 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7609 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7610 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7611 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007612 } finally {
7613 Binder.restoreCallingIdentity(identity);
7614 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007615 }
7616
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007617 @Deprecated
7618 @Override
7619 public String getDeviceId(String callingPackage) {
7620 return getDeviceIdWithFeature(callingPackage, null);
7621 }
7622
Sanket Padawe7310cc72015-01-14 09:53:20 -08007623 /**
7624 * Returns the unique device ID of phone, for example, the IMEI for
7625 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7626 *
7627 * <p>Requires Permission:
7628 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7629 */
7630 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007631 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007632 try {
7633 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7634 } catch (SecurityException se) {
7635 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7636 throw new SecurityException("Package " + callingPackage + " does not belong to "
7637 + Binder.getCallingUid());
7638 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007639 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007640 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007641 return null;
7642 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007643 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007644 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007645 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007646 return null;
7647 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007648
7649 final long identity = Binder.clearCallingIdentity();
7650 try {
7651 return phone.getDeviceId();
7652 } finally {
7653 Binder.restoreCallingIdentity(identity);
7654 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007655 }
7656
Ping Sunc67b7c22016-03-02 19:16:45 +08007657 /**
7658 * {@hide}
7659 * Returns the IMS Registration Status on a particular subid
7660 *
7661 * @param subId
7662 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007663 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007664 Phone phone = getPhone(subId);
7665 if (phone != null) {
7666 return phone.isImsRegistered();
7667 } else {
7668 return false;
7669 }
7670 }
7671
Santos Cordon7a1885b2015-02-03 11:15:19 -08007672 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007673 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007674 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007675 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007676 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007677 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7678 }
7679 final long identity = Binder.clearCallingIdentity();
7680 try {
7681 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7682 } finally {
7683 Binder.restoreCallingIdentity(identity);
7684 }
7685 }
7686
7687 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007688 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007689 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007690 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007691 mApp,
7692 subscriptionId,
7693 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007694 final long identity = Binder.clearCallingIdentity();
7695 try {
7696 Phone phone = getPhone(subscriptionId);
7697 if (phone == null) {
7698 return null;
7699 }
7700 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7701 } finally {
7702 Binder.restoreCallingIdentity(identity);
7703 }
7704 }
7705
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007706 /**
7707 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007708 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007709 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007710 final long identity = Binder.clearCallingIdentity();
7711 try {
7712 Phone phone = getPhone(subId);
7713 if (phone != null) {
7714 return phone.isWifiCallingEnabled();
7715 } else {
7716 return false;
7717 }
7718 } finally {
7719 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007720 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007721 }
7722
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007723 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007724 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007725 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007726 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007727 final long identity = Binder.clearCallingIdentity();
7728 try {
7729 Phone phone = getPhone(subId);
7730 if (phone != null) {
7731 return phone.isVideoEnabled();
7732 } else {
7733 return false;
7734 }
7735 } finally {
7736 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007737 }
7738 }
7739
7740 /**
7741 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7742 * defined in {@link ImsRegistrationImplBase}.
7743 */
7744 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007745 final long identity = Binder.clearCallingIdentity();
7746 try {
7747 Phone phone = getPhone(subId);
7748 if (phone != null) {
7749 return phone.getImsRegistrationTech();
7750 } else {
7751 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7752 }
7753 } finally {
7754 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007755 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007756 }
7757
Stuart Scott8eef64f2015-04-08 15:13:54 -07007758 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007759 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007760 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007761 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7762 return;
7763 }
Kai Shif70f46f2021-03-03 13:59:46 -08007764 Phone defaultPhone = getDefaultPhone();
7765 if (defaultPhone != null) {
7766 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7767 mApp, getDefaultPhone().getSubId(), "factoryReset");
7768 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007769 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007770
Svet Ganovcc087f82015-05-12 20:35:54 -07007771 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007772 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7773 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007774 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007775 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007776 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007777 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007778 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007779 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007780 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007781 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007782 // There has been issues when Sms raw table somehow stores orphan
7783 // fragments. They lead to garbled message when new fragments come
7784 // in and combined with those stale ones. In case this happens again,
7785 // user can reset all network settings which will clean up this table.
7786 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007787 // Clean up IMS settings as well here.
7788 int slotId = getSlotIndex(subId);
7789 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7790 ImsManager.getInstance(mApp, slotId).factoryReset();
7791 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007792
Kai Shif70f46f2021-03-03 13:59:46 -08007793 if (defaultPhone == null) {
7794 return;
7795 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007796 // Erase modem config if erase modem on network setting is enabled.
7797 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7798 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7799 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007800 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007801 }
Kai Shif70f46f2021-03-03 13:59:46 -08007802
7803 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007804 } finally {
7805 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007806 }
7807 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007808
SongFerngWangfd89b102021-05-27 22:44:54 +08007809 @VisibleForTesting
7810 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7811 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7812 return;
7813 }
7814 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7815 RILConstants.PREFERRED_NETWORK_MODE);
7816 SubscriptionManager.setSubscriptionProperty(subId,
7817 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7818 "user=" + defaultNetworkType);
7819 phone.loadAllowedNetworksFromSubscriptionDatabase();
7820 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7821 defaultNetworkType, null);
7822 }
7823
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007824 private void cleanUpSmsRawTable(Context context) {
7825 ContentResolver resolver = context.getContentResolver();
7826 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7827 resolver.delete(uri, null, null);
7828 }
7829
Narayan Kamath1c496c22015-04-16 14:40:19 +01007830 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007831 public String getSimLocaleForSubscriber(int subId) {
7832 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7833 final Phone phone = getPhone(subId);
7834 if (phone == null) {
7835 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007836 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007837 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007838 final long identity = Binder.clearCallingIdentity();
7839 try {
chen xu5d3637b2019-01-21 23:31:38 -08007840 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007841 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007842 if (info == null) {
7843 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7844 return null;
7845 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007846 // Try and fetch the locale from the carrier properties or from the SIM language
7847 // preferences (EF-PL and EF-LI)...
7848 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007849 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007850 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7851 if (localeFromDefaultSim != null) {
7852 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7853 if (DBG) log("Using locale from subId: " + subId + " locale: "
7854 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08007855 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08007856 } else {
7857 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007858 }
7859 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007860
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007861 // The SIM language preferences only store a language (e.g. fr = French), not an
7862 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7863 // the SIM and carrier preferences does not include a country we add the country
7864 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007865 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007866 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007867 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08007868 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007869 }
7870
7871 if (DBG) log("No locale found - returning null");
7872 return null;
7873 } finally {
7874 Binder.restoreCallingIdentity(identity);
7875 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007876 }
7877
tom hsu0b59d292022-09-29 23:49:21 +08007878 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08007879 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08007880 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08007881 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08007882 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08007883 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
7884 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08007885 Locale.forLanguageTag(localeTag).getCountry())) {
7886 return localeTag;
7887 }
7888 }
7889 return inputLocale.toLanguageTag();
7890 }
7891
Narayan Kamath1c496c22015-04-16 14:40:19 +01007892 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007893 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007894 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007895 }
7896
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007897 /**
7898 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7899 */
7900 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007901 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007902 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007903 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007904
Gary Jian3aa9a762022-01-24 16:41:19 +08007905 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
7906 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08007907
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007908 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007909 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7910 * representing the state of the modem.
7911 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007912 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7913 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007914 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007915 */
7916 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007917 public void requestModemActivityInfo(ResultReceiver result) {
7918 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007919 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007920
7921 final long identity = Binder.clearCallingIdentity();
7922 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007923 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007924 } finally {
7925 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007926 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007927 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007928
Siddharth Rayb8114062018-06-17 15:02:38 -07007929 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7930 // less than total activity duration.
7931 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7932 if (info == null) {
7933 return false;
7934 }
7935 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007936 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7937 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7938
Siddharth Rayb8114062018-06-17 15:02:38 -07007939 return (info.isValid()
7940 && (info.getSleepTimeMillis() <= activityDurationMs)
7941 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007942 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007943 && (totalTxTimeMs <= activityDurationMs));
7944 }
7945
Gary Jian3aa9a762022-01-24 16:41:19 +08007946 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
7947 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7948 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
7949 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
7950
7951 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7952 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7953 }
7954
7955 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
7956 mLastModemActivityInfo.setReceiveTimeMillis(
7957 rat,
7958 freq,
7959 info.getReceiveTimeMillis(rat, freq)
7960 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
7961 }
7962
7963 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
7964 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7965 int[] txTimeMs = info.getTransmitTimeMillis(rat);
7966 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
7967
7968 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7969 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7970 }
7971 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
7972 mLastModemActivityInfo.setReceiveTimeMillis(
7973 rat,
7974 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
7975 }
7976
7977 /**
7978 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
7979 * @param info recent ModemActivityInfo
7980 */
7981 private void mergeModemActivityInfo(ModemActivityInfo info) {
7982 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
7983 ActivityStatsTechSpecificInfo mDeltaSpecificInfo;
7984 boolean matched;
7985 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
7986 matched = false;
7987 int rat = info.getSpecificInfoRat(i);
7988 int freq = info.getSpecificInfoFrequencyRange(i);
7989 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
7990 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
7991 //if it already exists
7992 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
7993 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
7994 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
7995 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
7996 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
7997 updateLastModemActivityInfo(info, rat, freq);
7998 matched = true;
7999 }
8000 } else {
8001 updateLastModemActivityInfo(info, rat);
8002 matched = true;
8003 }
8004 }
8005 }
8006
8007 if (!matched) {
8008 mDeltaSpecificInfo =
8009 new ActivityStatsTechSpecificInfo(
8010 rat,
8011 freq,
8012 info.getTransmitTimeMillis(rat, freq),
8013 (int) info.getReceiveTimeMillis(rat, freq));
8014 merged.addAll(Arrays.asList(mDeltaSpecificInfo));
8015 }
8016 }
8017 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8018 mLastModemActivitySpecificInfo =
8019 new ActivityStatsTechSpecificInfo[merged.size()];
8020 merged.toArray(mLastModemActivitySpecificInfo);
8021
8022 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8023 mLastModemActivityInfo.setSleepTimeMillis(
8024 info.getSleepTimeMillis()
8025 + mLastModemActivityInfo.getSleepTimeMillis());
8026 mLastModemActivityInfo.setIdleTimeMillis(
8027 info.getIdleTimeMillis()
8028 + mLastModemActivityInfo.getIdleTimeMillis());
8029 }
8030
Jack Yu85bd38a2015-11-09 11:34:32 -08008031 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008032 * Returns the service state information on specified subscription.
8033 */
8034 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008035 public ServiceState getServiceStateForSubscriber(int subId,
8036 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8037 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008038 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008039 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008040 return null;
8041 }
8042
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008043 boolean hasFinePermission = false;
8044 boolean hasCoarsePermission = false;
8045 if (!renounceFineLocationAccess) {
8046 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8047 LocationAccessPolicy.checkLocationPermission(mApp,
8048 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8049 .setCallingPackage(callingPackage)
8050 .setCallingFeatureId(callingFeatureId)
8051 .setCallingPid(Binder.getCallingPid())
8052 .setCallingUid(Binder.getCallingUid())
8053 .setMethod("getServiceStateForSubscriber")
8054 .setLogAsInfo(true)
8055 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8056 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8057 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8058 .build());
8059 hasFinePermission =
8060 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8061 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008062
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008063 if (!renounceCoarseLocationAccess) {
8064 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8065 LocationAccessPolicy.checkLocationPermission(mApp,
8066 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8067 .setCallingPackage(callingPackage)
8068 .setCallingFeatureId(callingFeatureId)
8069 .setCallingPid(Binder.getCallingPid())
8070 .setCallingUid(Binder.getCallingUid())
8071 .setMethod("getServiceStateForSubscriber")
8072 .setLogAsInfo(true)
8073 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8074 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8075 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8076 .build());
8077 hasCoarsePermission =
8078 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8079 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008080
Jack Yu479f40e2020-10-27 21:29:25 -07008081 final Phone phone = getPhone(subId);
8082 if (phone == null) {
8083 return null;
8084 }
8085
Jordan Liu0f2bc442020-11-18 16:47:37 -08008086 final long identity = Binder.clearCallingIdentity();
8087
Jack Yu479f40e2020-10-27 21:29:25 -07008088 boolean isCallingPackageDataService = phone.getDataServicePackages()
8089 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008090 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008091 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
8092 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
8093 Rlog.d(LOG_TAG,
8094 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
8095 return null;
8096 }
8097
Hall Liuf19c44f2018-11-27 14:38:17 -08008098 ServiceState ss = phone.getServiceState();
8099
8100 // Scrub out the location info in ServiceState depending on what level of access
8101 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008102 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008103 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8104 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008105 } finally {
8106 Binder.restoreCallingIdentity(identity);
8107 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008108 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008109
8110 /**
8111 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8112 *
8113 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8114 * voicemail ringtone.
8115 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8116 * PhoneAccount.
8117 */
8118 @Override
8119 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008120 final long identity = Binder.clearCallingIdentity();
8121 try {
8122 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8123 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008124 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008125 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008126
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008127 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8128 } finally {
8129 Binder.restoreCallingIdentity(identity);
8130 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008131 }
8132
8133 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008134 * Sets the per-account voicemail ringtone.
8135 *
8136 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8137 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8138 *
8139 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8140 * voicemail ringtone.
8141 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8142 * PhoneAccount.
8143 */
8144 @Override
8145 public void setVoicemailRingtoneUri(String callingPackage,
8146 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008147 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008148 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008149 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8150 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008151 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8152 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8153 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008154 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008155
8156 final long identity = Binder.clearCallingIdentity();
8157 try {
8158 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8159 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008160 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008161 }
8162 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8163 } finally {
8164 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008165 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008166 }
8167
8168 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008169 * Returns whether vibration is set for voicemail notification in Phone settings.
8170 *
8171 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8172 * voicemail vibration setting.
8173 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8174 */
8175 @Override
8176 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008177 final long identity = Binder.clearCallingIdentity();
8178 try {
8179 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8180 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008181 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008182 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008183
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008184 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8185 } finally {
8186 Binder.restoreCallingIdentity(identity);
8187 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008188 }
8189
Youhan Wange64578a2016-05-02 15:32:42 -07008190 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008191 * Sets the per-account voicemail vibration.
8192 *
8193 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8194 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8195 *
8196 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8197 * voicemail vibration setting.
8198 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8199 * specific PhoneAccount.
8200 */
8201 @Override
8202 public void setVoicemailVibrationEnabled(String callingPackage,
8203 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008204 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008205 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008206 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8207 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008208 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8209 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8210 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008211 }
8212
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008213 final long identity = Binder.clearCallingIdentity();
8214 try {
8215 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8216 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008217 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008218 }
8219 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8220 } finally {
8221 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008222 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008223 }
8224
8225 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008226 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8227 *
8228 * @throws SecurityException if the caller does not have the required permission
8229 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008230 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008231 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008232 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008233 }
8234
8235 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008236 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8237 * permission.
8238 *
8239 * @throws SecurityException if the caller does not have the required permission
8240 */
8241 private void enforceSendSmsPermission() {
8242 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8243 }
8244
8245 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008246 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008247 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008248 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008249 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008250 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008251 final long identity = Binder.clearCallingIdentity();
8252 try {
8253 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008254 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008255 if (componentName == null) {
8256 throw new SecurityException(
8257 "Caller not current active visual voicemail package[null]");
8258 }
8259 String vvmPackage = componentName.getPackageName();
8260 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008261 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008262 }
8263 } finally {
8264 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008265 }
8266 }
8267
8268 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008269 * Return the application ID for the app type.
8270 *
8271 * @param subId the subscription ID that this request applies to.
8272 * @param appType the uicc app type.
8273 * @return Application ID for specificied app type, or null if no uicc.
8274 */
8275 @Override
8276 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008277 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008278 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008279
8280 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008281 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008282 if (phone == null) {
8283 return null;
8284 }
8285 String aid = null;
8286 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008287 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008288 .getApplicationByType(appType).getAid();
8289 } catch (Exception e) {
8290 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8291 }
8292 return aid;
8293 } finally {
8294 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008295 }
Youhan Wange64578a2016-05-02 15:32:42 -07008296 }
8297
Youhan Wang4001d252016-05-11 10:29:41 -07008298 /**
8299 * Return the Electronic Serial Number.
8300 *
8301 * @param subId the subscription ID that this request applies to.
8302 * @return ESN or null if error.
8303 */
8304 @Override
8305 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008306 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008307 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008308
8309 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008310 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008311 if (phone == null) {
8312 return null;
8313 }
8314 String esn = null;
8315 try {
8316 esn = phone.getEsn();
8317 } catch (Exception e) {
8318 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8319 }
8320 return esn;
8321 } finally {
8322 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008323 }
Youhan Wang4001d252016-05-11 10:29:41 -07008324 }
8325
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008326 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008327 * Return the Preferred Roaming List Version.
8328 *
8329 * @param subId the subscription ID that this request applies to.
8330 * @return PRLVersion or null if error.
8331 */
8332 @Override
8333 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008334 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008335 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008336
8337 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008338 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008339 if (phone == null) {
8340 return null;
8341 }
8342 String cdmaPrlVersion = null;
8343 try {
8344 cdmaPrlVersion = phone.getCdmaPrlVersion();
8345 } catch (Exception e) {
8346 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8347 }
8348 return cdmaPrlVersion;
8349 } finally {
8350 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008351 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008352 }
8353
8354 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008355 * Get snapshot of Telephony histograms
8356 * @return List of Telephony histograms
8357 * @hide
8358 */
8359 @Override
8360 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008361 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8362 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008363
8364 final long identity = Binder.clearCallingIdentity();
8365 try {
8366 return RIL.getTelephonyRILTimingHistograms();
8367 } finally {
8368 Binder.restoreCallingIdentity(identity);
8369 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008370 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008371
8372 /**
8373 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008374 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8375 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008376 * Require system privileges. In the future we may add this to carrier APIs.
8377 *
Michele Berionne482f8202018-11-27 18:57:59 -08008378 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008379 */
8380 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008381 @TelephonyManager.SetCarrierRestrictionResult
8382 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008383 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008384 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008385
Michele Berionne482f8202018-11-27 18:57:59 -08008386 if (carrierRestrictionRules == null) {
8387 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008388 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008389
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008390 final long identity = Binder.clearCallingIdentity();
8391 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008392 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008393 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008394 } finally {
8395 Binder.restoreCallingIdentity(identity);
8396 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008397 }
8398
8399 /**
8400 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008401 * Get the allowed carrier list and the excluded carrier list, including the priority between
8402 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008403 * Require system privileges. In the future we may add this to carrier APIs.
8404 *
Michele Berionne482f8202018-11-27 18:57:59 -08008405 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008406 */
8407 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008408 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008409 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008410 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008411
8412 final long identity = Binder.clearCallingIdentity();
8413 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008414 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8415 if (response instanceof CarrierRestrictionRules) {
8416 return (CarrierRestrictionRules) response;
8417 }
8418 // Response is an Exception of some kind,
8419 // which is signalled to the user as a NULL retval
8420 return null;
8421 } catch (Exception e) {
8422 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8423 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008424 } finally {
8425 Binder.restoreCallingIdentity(identity);
8426 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008427 }
8428
fionaxu59545b42016-05-25 15:53:37 -07008429 /**
fionaxu59545b42016-05-25 15:53:37 -07008430 * Action set from carrier signalling broadcast receivers to enable/disable radio
8431 * @param subId the subscription ID that this action applies to.
8432 * @param enabled control enable or disable radio.
8433 * {@hide}
8434 */
8435 @Override
8436 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8437 enforceModifyPermission();
8438 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008439
8440 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008441 if (phone == null) {
8442 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8443 return;
8444 }
8445 try {
8446 phone.carrierActionSetRadioEnabled(enabled);
8447 } catch (Exception e) {
8448 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008449 } finally {
8450 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008451 }
8452 }
8453
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008454 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008455 * Enable or disable Voice over NR (VoNR)
8456 * @param subId the subscription ID that this action applies to.
8457 * @param enabled enable or disable VoNR.
8458 * @return operation result.
8459 */
8460 @Override
8461 public int setVoNrEnabled(int subId, boolean enabled) {
8462 enforceModifyPermission();
8463 final Phone phone = getPhone(subId);
8464
8465 final long identity = Binder.clearCallingIdentity();
8466 if (phone == null) {
8467 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8468 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8469 }
8470
8471 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8472 try {
8473 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8474 workSource);
8475 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008476
8477 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8478 if (DBG) {
8479 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8480 }
8481 SubscriptionManager.setSubscriptionProperty(
8482 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8483 (enabled ? "1" : "0"));
8484 }
8485
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008486 return result;
8487 } finally {
8488 Binder.restoreCallingIdentity(identity);
8489 }
8490 }
8491
8492 /**
8493 * Is voice over NR enabled
8494 * @return true if VoNR is enabled else false
8495 */
8496 @Override
8497 public boolean isVoNrEnabled(int subId) {
8498 enforceReadPrivilegedPermission("isVoNrEnabled");
8499 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8500 final long identity = Binder.clearCallingIdentity();
8501 try {
8502 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8503 null, subId, workSource);
8504 if (DBG) log("isVoNrEnabled: " + isEnabled);
8505 return isEnabled;
8506 } finally {
8507 Binder.restoreCallingIdentity(identity);
8508 }
8509 }
8510
8511 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008512 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8513 * network status based on which carrier apps could apply actions accordingly,
8514 * enable/disable default url handler for example.
8515 *
8516 * @param subId the subscription ID that this action applies to.
8517 * @param report control start/stop reporting the default network status.
8518 * {@hide}
8519 */
8520 @Override
8521 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8522 enforceModifyPermission();
8523 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008524
8525 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008526 if (phone == null) {
8527 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8528 return;
8529 }
8530 try {
8531 phone.carrierActionReportDefaultNetworkStatus(report);
8532 } catch (Exception e) {
8533 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008534 } finally {
8535 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008536 }
8537 }
8538
8539 /**
fionaxud9622282017-07-17 17:51:30 -07008540 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8541 * @param subId the subscription ID that this action applies to.
8542 * {@hide}
8543 */
8544 @Override
8545 public void carrierActionResetAll(int subId) {
8546 enforceModifyPermission();
8547 final Phone phone = getPhone(subId);
8548 if (phone == null) {
8549 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8550 return;
8551 }
8552 try {
8553 phone.carrierActionResetAll();
8554 } catch (Exception e) {
8555 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8556 }
8557 }
8558
8559 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008560 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8561 * bug report is being generated.
8562 */
8563 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008564 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008565 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8566 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008567 writer.println("Permission Denial: can't dump Phone from pid="
8568 + Binder.getCallingPid()
8569 + ", uid=" + Binder.getCallingUid()
8570 + "without permission "
8571 + android.Manifest.permission.DUMP);
8572 return;
8573 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008574 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008575 }
Jack Yueb89b242016-06-22 13:27:47 -07008576
Brad Ebingerdac2f002018-04-03 15:17:52 -07008577 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008578 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8579 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8580 @NonNull String[] args) {
8581 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8582 this, in.getFileDescriptor(), out.getFileDescriptor(),
8583 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008584 }
8585
Jack Yueb89b242016-06-22 13:27:47 -07008586 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008587 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008588 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008589 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008590 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008591 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008592 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008593 */
8594 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008595 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008596 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008597 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8598 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8599 try {
8600 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008601 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008602 } catch (SecurityException se) {
8603 enforceModifyPermission();
8604 }
8605 } else {
8606 enforceModifyPermission();
8607 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008608
8609 final long identity = Binder.clearCallingIdentity();
8610 try {
8611 Phone phone = getPhone(subId);
8612 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008613 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8614 phone.carrierActionSetMeteredApnsEnabled(enabled);
8615 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008616 phone.getDataSettingsManager().setDataEnabled(
8617 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008618 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008619 }
8620 } finally {
8621 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008622 }
8623 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008624
8625 /**
8626 * Get Client request stats
8627 * @return List of Client Request Stats
8628 * @hide
8629 */
8630 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008631 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8632 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008633 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008634 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008635 return null;
8636 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008637 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008638
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008639 final long identity = Binder.clearCallingIdentity();
8640 try {
8641 if (phone != null) {
8642 return phone.getClientRequestStats();
8643 }
8644
8645 return null;
8646 } finally {
8647 Binder.restoreCallingIdentity(identity);
8648 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008649 }
8650
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008651 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008652 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008653 if (uid == Process.ROOT_UID && packageName == null) {
8654 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8655 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8656 // exception. ROOT_UID seems not to have a valid package name returned by
8657 // PackageManager, so just fake it here to avoid issues when running telephony shell
8658 // commands that plumb through the RIL as root, like so:
8659 // $ adb root
8660 // $ adb shell cmd phone ...
8661 packageName = "root";
8662 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008663 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008664 }
Jack Yueb4124c2017-02-16 15:32:43 -08008665
8666 /**
Grace Chen70990072017-03-24 17:21:30 -07008667 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008668 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008669 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008670 * @param state State of SIM (power down, power up, pass through)
8671 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8672 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8673 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008674 *
8675 **/
8676 @Override
Grace Chen70990072017-03-24 17:21:30 -07008677 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008678 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008679 Phone phone = PhoneFactory.getPhone(slotIndex);
8680
vagdeviaf9a5b92018-08-15 16:01:53 -07008681 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8682
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008683 final long identity = Binder.clearCallingIdentity();
8684 try {
8685 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008686 phone.setSimPowerState(state, null, workSource);
8687 }
8688 } finally {
8689 Binder.restoreCallingIdentity(identity);
8690 }
8691 }
8692
8693 /**
8694 * Set SIM card power state.
8695 *
8696 * @param slotIndex SIM slot id.
8697 * @param state State of SIM (power down, power up, pass through)
8698 * @param callback callback to trigger after success or failure
8699 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8700 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8701 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8702 *
8703 **/
8704 @Override
8705 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8706 IIntegerConsumer callback) {
8707 enforceModifyPermission();
8708 Phone phone = PhoneFactory.getPhone(slotIndex);
8709
8710 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8711
8712 final long identity = Binder.clearCallingIdentity();
8713 try {
8714 if (phone != null) {
8715 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8716 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008717 }
8718 } finally {
8719 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008720 }
8721 }
Shuo Qiandd210312017-04-12 22:11:33 +00008722
Tyler Gunn65d45c22017-06-05 11:22:26 -07008723 private boolean isUssdApiAllowed(int subId) {
8724 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008725 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008726 if (configManager == null) {
8727 return false;
8728 }
8729 PersistableBundle pb = configManager.getConfigForSubId(subId);
8730 if (pb == null) {
8731 return false;
8732 }
8733 return pb.getBoolean(
8734 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8735 }
8736
Shuo Qiandd210312017-04-12 22:11:33 +00008737 /**
8738 * Check if phone is in emergency callback mode
8739 * @return true if phone is in emergency callback mode
8740 * @param subId sub id
8741 */
goneil9c5f4872017-12-05 14:07:56 -08008742 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008743 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008744 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008745 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008746
8747 final long identity = Binder.clearCallingIdentity();
8748 try {
8749 if (phone != null) {
8750 return phone.isInEcm();
8751 } else {
8752 return false;
8753 }
8754 } finally {
8755 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008756 }
8757 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008758
8759 /**
8760 * Get the current signal strength information for the given subscription.
8761 * Because this information is not updated when the device is in a low power state
8762 * it should not be relied-upon to be current.
8763 * @param subId Subscription index
8764 * @return the most recent cached signal strength info from the modem
8765 */
8766 @Override
8767 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008768 final long identity = Binder.clearCallingIdentity();
8769 try {
8770 Phone p = getPhone(subId);
8771 if (p == null) {
8772 return null;
8773 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008774
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008775 return p.getSignalStrength();
8776 } finally {
8777 Binder.restoreCallingIdentity(identity);
8778 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008779 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008780
Pengquan Meng77b7f132018-08-22 14:49:57 -07008781 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008782 * Get the current modem radio state for the given slot.
8783 * @param slotIndex slot index.
8784 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008785 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008786 * @return the current radio power state from the modem
8787 */
8788 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008789 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008790 Phone phone = PhoneFactory.getPhone(slotIndex);
8791 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008792 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8793 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008794 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8795 }
8796
8797 final long identity = Binder.clearCallingIdentity();
8798 try {
8799 return phone.getRadioPowerState();
8800 } finally {
8801 Binder.restoreCallingIdentity(identity);
8802 }
8803 }
8804 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8805 }
8806
8807 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008808 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8809 *
8810 * <p>Requires one of the following permissions:
8811 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008812 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008813 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8814 * privileges.
8815 *
8816 * @param subId subscription id
8817 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8818 * {@code false}.
8819 */
8820 @Override
8821 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008822 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008823 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008824 try {
8825 mApp.enforceCallingOrSelfPermission(
8826 android.Manifest.permission.ACCESS_NETWORK_STATE,
8827 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008828 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008829 mApp.enforceCallingOrSelfPermission(
8830 permission.READ_BASIC_PHONE_STATE, functionName);
8831 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008832 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008833 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008834 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008835 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008836
Pengquan Menga1bb6272018-09-06 09:59:22 -07008837 boolean isEnabled = false;
8838 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008839 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008840 Phone phone = getPhone(subId);
8841 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008842 } finally {
8843 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008844 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008845 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008846 }
8847
8848
8849 /**
8850 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8851 *
8852 * <p> Requires permission:
8853 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8854 * privileges.
8855 *
8856 * @param subId subscription id
8857 * @param isEnabled {@code true} means enable, {@code false} means disable.
8858 */
8859 @Override
8860 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008861 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8862 mApp, subId, "setDataRoamingEnabled");
8863
Pengquan Menga1bb6272018-09-06 09:59:22 -07008864 final long identity = Binder.clearCallingIdentity();
8865 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008866 Phone phone = getPhone(subId);
8867 if (phone != null) {
8868 phone.setDataRoamingEnabled(isEnabled);
8869 }
8870 } finally {
8871 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008872 }
8873 }
8874
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008875 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008876 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008877 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008878 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008879 mApp, subId, "isManualNetworkSelectionAllowed");
8880
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008881 boolean isAllowed = true;
8882 final long identity = Binder.clearCallingIdentity();
8883 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008884 Phone phone = getPhone(subId);
8885 if (phone != null) {
8886 isAllowed = phone.isCspPlmnEnabled();
8887 }
8888 } finally {
8889 Binder.restoreCallingIdentity(identity);
8890 }
8891 return isAllowed;
8892 }
8893
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008894 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8895 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008896 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008897 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008898 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008899 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8900 if (phone == null) {
8901 return false;
8902 }
8903 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8904 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8905 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008906 }
8907
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008908 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008909 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008910 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008911 mApp.getSystemService(AppOpsManager.class)
8912 .checkPackage(Binder.getCallingUid(), callingPackage);
8913
Jordan Liu1e142fc2019-04-22 15:10:43 -07008914 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008915 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008916 try {
8917 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008918 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008919 } catch (SecurityException e) {
8920 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8921 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08008922 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08008923 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008924 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008925 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008926 }
sandeepjsb6c87872021-09-27 15:34:44 +00008927 // checking compatibility, if calling app's target SDK is T and beyond.
8928 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8929 Binder.getCallingUid())) {
8930 isIccIdAccessRestricted = true;
8931 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008932 final long identity = Binder.clearCallingIdentity();
8933 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008934 UiccController uiccController = UiccController.getInstance();
8935 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008936 if (hasReadPermission) {
8937 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008938 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008939
8940 // Remove private info if the caller doesn't have access
8941 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8942 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008943 //setting the value after compatibility check
8944 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008945 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8946 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008947 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008948 if (card == null) {
8949 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008950 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008951 continue;
8952 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008953 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8954 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008955 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008956 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008957 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008958 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8959 for (UiccPortInfo portInfo : portInfos) {
8960 UiccPort port = uiccController.getUiccPortForSlot(
8961 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8962 if (port == null) {
8963 // assume no access if port is null
8964 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8965 continue;
8966 }
8967 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8968 uiccPortInfos.add(portInfo);
8969 } else {
8970 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8971 }
8972 }
8973 filteredInfos.add(new UiccCardInfo(
8974 cardInfo.isEuicc(),
8975 cardInfo.getCardId(),
8976 null,
8977 cardInfo.getPhysicalSlotIndex(),
8978 cardInfo.isRemovable(),
8979 cardInfo.isMultipleEnabledProfilesSupported(),
8980 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008981 }
8982 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008983 } finally {
8984 Binder.restoreCallingIdentity(identity);
8985 }
8986 }
8987
sandeepjsb6c87872021-09-27 15:34:44 +00008988 /**
8989 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8990 * generally private and require carrier privileges to view.
8991 *
8992 * @hide
8993 */
8994 @NonNull
8995 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8996 List<UiccPortInfo> portinfo = new ArrayList<>();
8997 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8998 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8999 }
9000 return new UiccCardInfo(
9001 cardInfo.isEuicc(),
9002 cardInfo.getCardId(),
9003 null,
9004 cardInfo.getPhysicalSlotIndex(),
9005 cardInfo.isRemovable(),
9006 cardInfo.isMultipleEnabledProfilesSupported(),
9007 portinfo
9008 );
9009 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009010
sandeepjsb6c87872021-09-27 15:34:44 +00009011 /**
9012 * @hide
9013 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9014 * These values are generally private and require carrier privileges to view.
9015 */
9016 @NonNull
9017 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9018 return new UiccPortInfo(
9019 UiccPortInfo.ICCID_REDACTED,
9020 portInfo.getPortIndex(),
9021 portInfo.getLogicalSlotIndex(),
9022 portInfo.isActive()
9023 );
9024 }
9025 @Override
9026 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009027 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009028 mApp.getSystemService(AppOpsManager.class)
9029 .checkPackage(Binder.getCallingUid(), callingPackage);
9030
sandeepjsb6c87872021-09-27 15:34:44 +00009031 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009032
Aman Guptaf3c90b32022-03-17 04:54:16 +00009033 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9034 // we are reading iccId which is PII data.
9035 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009036
9037 // checking compatibility, if calling app's target SDK is T and beyond.
9038 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9039 Binder.getCallingUid())) {
9040 isLogicalSlotAccessRestricted = true;
9041 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009042 final long identity = Binder.clearCallingIdentity();
9043 try {
9044 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009045 if (slots == null || slots.length == 0) {
9046 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009047 return null;
9048 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009049 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9050 for (int i = 0; i < slots.length; i++) {
9051 UiccSlot slot = slots[i];
9052 if (slot == null) {
9053 continue;
9054 }
9055
Jordan Liu7be7e652019-05-06 18:55:02 +00009056 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009057 UiccCard card = slot.getUiccCard();
9058 if (card != null) {
9059 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009060 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009061 cardId = slot.getEid();
9062 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009063 // If cardId is null, use iccId of default port as cardId.
9064 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009065 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009066 }
9067
Jordan Liu857451f2019-05-09 16:35:35 -07009068 if (cardId != null) {
9069 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9070 // if cardId is an EID, it's all digits so this is fine
9071 cardId = IccUtils.stripTrailingFs(cardId);
9072 }
9073
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009074 int cardState = 0;
9075 switch (slot.getCardState()) {
9076 case CARDSTATE_ABSENT:
9077 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9078 break;
9079 case CARDSTATE_PRESENT:
9080 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9081 break;
9082 case CARDSTATE_ERROR:
9083 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9084 break;
9085 case CARDSTATE_RESTRICTED:
9086 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9087 break;
9088 default:
9089 break;
9090
9091 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009092 List<UiccPortInfo> portInfos = new ArrayList<>();
9093 int[] portIndexes = slot.getPortList();
9094 for (int portIdx : portIndexes) {
9095 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009096 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009097 portInfos.add(new UiccPortInfo(iccId, portIdx,
9098 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009099 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009100 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009101 slot.isEuicc(),
9102 cardId,
9103 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009104 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009105 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009106 //setting the value after compatibility check
9107 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009108 }
9109 return infos;
9110 } finally {
9111 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009112 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009113 }
9114
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009115 /* Returns null if doesn't have read permission or carrier privilege access. */
9116 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9117 boolean hasReadPermission) {
9118 String iccId = slot.getIccId(portIndex);
9119 if (hasReadPermission) { // if has read permission
9120 return iccId;
9121 } else {
9122 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9123 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9124 // if no read permission, checking carrier privilege access
9125 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9126 return iccId;
9127 }
9128 }
9129 }
9130 // No read permission or carrier privilege access.
9131 return UiccPortInfo.ICCID_REDACTED;
9132 }
9133
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009134 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009135 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009136 public boolean switchSlots(int[] physicalSlots) {
9137 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009138
9139 final long identity = Binder.clearCallingIdentity();
9140 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009141 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9142 for (int i = 0; i < physicalSlots.length; i++) {
9143 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9144 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9145 physicalSlots[i], i));
9146 }
9147 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009148 } finally {
9149 Binder.restoreCallingIdentity(identity);
9150 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009151 }
Jack Yu4c988042018-02-27 15:30:01 -08009152
9153 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009154 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9155 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9156 enforceModifyPermission();
9157
9158 final long identity = Binder.clearCallingIdentity();
9159 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009160 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009161 } finally {
9162 Binder.restoreCallingIdentity(identity);
9163 }
9164 }
9165
9166 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009167 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009168 final long identity = Binder.clearCallingIdentity();
9169 try {
9170 return UiccController.getInstance().getCardIdForDefaultEuicc();
9171 } finally {
9172 Binder.restoreCallingIdentity(identity);
9173 }
9174 }
9175
Pengquan Meng85728fb2018-03-12 16:31:21 -07009176 /**
goneil47ffb6e2018-04-06 15:40:58 -07009177 * A test API to reload the UICC profile.
9178 *
9179 * <p>Requires that the calling app has permission
9180 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9181 * @hide
9182 */
9183 @Override
9184 public void refreshUiccProfile(int subId) {
9185 enforceModifyPermission();
9186
9187 final long identity = Binder.clearCallingIdentity();
9188 try {
9189 Phone phone = getPhone(subId);
9190 if (phone == null) {
9191 return;
9192 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009193 UiccPort uiccPort = phone.getUiccPort();
9194 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009195 return;
9196 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009197 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009198 if (uiccProfile == null) {
9199 return;
9200 }
9201 uiccProfile.refresh();
9202 } finally {
9203 Binder.restoreCallingIdentity(identity);
9204 }
9205 }
9206
9207 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009208 * Returns false if the mobile data is disabled by default, otherwise return true.
9209 */
9210 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009211 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009212 }
9213
9214 /**
9215 * Returns true if the data roaming is enabled by default, i.e the system property
9216 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9217 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9218 */
9219 private boolean getDefaultDataRoamingEnabled(int subId) {
9220 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009221 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009222 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009223 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9224 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9225 return isDataRoamingEnabled;
9226 }
9227
9228 /**
9229 * Returns the default network type for the given {@code subId}, if the default network type is
9230 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9231 */
9232 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009233 List<Integer> list = TelephonyProperties.default_network();
9234 int phoneId = mSubscriptionController.getPhoneId(subId);
9235 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9236 return list.get(phoneId);
9237 }
9238 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009239 }
fionaxua13278b2018-03-21 00:08:13 -07009240
9241 @Override
9242 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009243 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009244 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009245
9246 final long identity = Binder.clearCallingIdentity();
9247 try {
9248 final Phone phone = getPhone(subId);
9249 if (phone == null) {
9250 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9251 return;
9252 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009253 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9254 if (cpt != null) {
9255 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9256 }
9257 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009258 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9259 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009260 if (carrierPrivilegeRules == null) {
9261 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9262 } else {
9263 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9264 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009265 } finally {
9266 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009267 }
fionaxua13278b2018-03-21 00:08:13 -07009268 }
9269
9270 @Override
9271 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009272 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009273
9274 final long identity = Binder.clearCallingIdentity();
9275 try {
9276 final Phone phone = getPhone(subId);
9277 if (phone == null) {
9278 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9279 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9280 }
9281 return phone.getCarrierIdListVersion();
9282 } finally {
9283 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009284 }
fionaxua13278b2018-03-21 00:08:13 -07009285 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009286
9287 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009288 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9289 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009290 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009291 mApp, subId, callingPackage, callingFeatureId,
9292 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009293 return -1;
9294 }
9295
9296 final long identity = Binder.clearCallingIdentity();
9297 try {
9298 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9299 } finally {
9300 Binder.restoreCallingIdentity(identity);
9301 }
9302 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009303
9304 @Override
9305 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009306 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009307 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009308 mApp, subId, "getCdmaRoamingMode");
9309
9310 final long identity = Binder.clearCallingIdentity();
9311 try {
9312 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9313 } finally {
9314 Binder.restoreCallingIdentity(identity);
9315 }
9316 }
9317
9318 @Override
9319 public boolean setCdmaRoamingMode(int subId, int mode) {
9320 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9321 mApp, subId, "setCdmaRoamingMode");
9322
9323 final long identity = Binder.clearCallingIdentity();
9324 try {
9325 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9326 } finally {
9327 Binder.restoreCallingIdentity(identity);
9328 }
9329 }
9330
9331 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009332 public int getCdmaSubscriptionMode(int subId) {
9333 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009334 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009335 mApp, subId, "getCdmaSubscriptionMode");
9336
9337 final long identity = Binder.clearCallingIdentity();
9338 try {
9339 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9340 } finally {
9341 Binder.restoreCallingIdentity(identity);
9342 }
9343 }
9344
9345 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009346 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9347 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9348 mApp, subId, "setCdmaSubscriptionMode");
9349
9350 final long identity = Binder.clearCallingIdentity();
9351 try {
9352 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9353 } finally {
9354 Binder.restoreCallingIdentity(identity);
9355 }
9356 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009357
sqianc5eccab2018-10-19 18:46:41 -07009358 @Override
sqian8c685422019-02-22 15:55:18 -08009359 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009360 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009361 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009362 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9363 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009364 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9365 }
9366 final long identity = Binder.clearCallingIdentity();
9367 try {
sqian854d44b2018-12-12 16:48:18 -08009368 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9369 for (Phone phone: PhoneFactory.getPhones()) {
9370 if (phone.getEmergencyNumberTracker() != null
9371 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9372 emergencyNumberListInternal.put(
9373 phone.getSubId(),
9374 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9375 }
sqian11b7a0e2018-12-05 18:48:28 -08009376 }
sqian854d44b2018-12-12 16:48:18 -08009377 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009378 } finally {
9379 Binder.restoreCallingIdentity(identity);
9380 }
sqianc5eccab2018-10-19 18:46:41 -07009381 }
9382
9383 @Override
sqian8c685422019-02-22 15:55:18 -08009384 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009385 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009386 if (!exactMatch) {
9387 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009388 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009389 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009390 }
9391 final long identity = Binder.clearCallingIdentity();
9392 try {
sqian854d44b2018-12-12 16:48:18 -08009393 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009394 //Note: we ignore passed in param exactMatch. We can remove it once
9395 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009396 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009397 && phone.getEmergencyNumberTracker()
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009398 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009399 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009400 }
sqian11b7a0e2018-12-05 18:48:28 -08009401 }
9402 return false;
9403 } finally {
9404 Binder.restoreCallingIdentity(identity);
9405 }
9406 }
9407
sqianf4ca7ed2019-01-15 18:32:07 -08009408 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009409 * Start emergency callback mode for GsmCdmaPhone for testing.
9410 */
9411 @Override
9412 public void startEmergencyCallbackMode() {
9413 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9414 "startEmergencyCallbackMode");
9415 enforceModifyPermission();
9416 final long identity = Binder.clearCallingIdentity();
9417 try {
9418 for (Phone phone : PhoneFactory.getPhones()) {
9419 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9420 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9421 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9422 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9423 gsmCdmaPhone.obtainMessage(
9424 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9425 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9426 }
9427 }
9428 } finally {
9429 Binder.restoreCallingIdentity(identity);
9430 }
9431 }
9432
9433 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009434 * Update emergency number list for test mode.
9435 */
9436 @Override
9437 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9438 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9439 "updateEmergencyNumberListTestMode");
9440
9441 final long identity = Binder.clearCallingIdentity();
9442 try {
9443 for (Phone phone: PhoneFactory.getPhones()) {
9444 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9445 if (tracker != null) {
9446 tracker.executeEmergencyNumberTestModeCommand(action, num);
9447 }
9448 }
9449 } finally {
9450 Binder.restoreCallingIdentity(identity);
9451 }
9452 }
9453
9454 /**
9455 * Get the full emergency number list for test mode.
9456 */
9457 @Override
9458 public List<String> getEmergencyNumberListTestMode() {
9459 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9460 "getEmergencyNumberListTestMode");
9461
9462 final long identity = Binder.clearCallingIdentity();
9463 try {
9464 Set<String> emergencyNumbers = new HashSet<>();
9465 for (Phone phone: PhoneFactory.getPhones()) {
9466 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9467 if (tracker != null) {
9468 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9469 emergencyNumbers.add(num.getNumber());
9470 }
9471 }
9472 }
9473 return new ArrayList<>(emergencyNumbers);
9474 } finally {
9475 Binder.restoreCallingIdentity(identity);
9476 }
9477 }
9478
chen xud6b45bd2018-10-30 22:27:10 -07009479 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009480 public int getEmergencyNumberDbVersion(int subId) {
9481 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9482
9483 final long identity = Binder.clearCallingIdentity();
9484 try {
9485 final Phone phone = getPhone(subId);
9486 if (phone == null) {
9487 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9488 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9489 }
9490 return phone.getEmergencyNumberDbVersion();
9491 } finally {
9492 Binder.restoreCallingIdentity(identity);
9493 }
9494 }
9495
9496 @Override
9497 public void notifyOtaEmergencyNumberDbInstalled() {
9498 enforceModifyPermission();
9499
9500 final long identity = Binder.clearCallingIdentity();
9501 try {
9502 for (Phone phone: PhoneFactory.getPhones()) {
9503 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9504 if (tracker != null) {
9505 tracker.updateOtaEmergencyNumberDatabase();
9506 }
9507 }
9508 } finally {
9509 Binder.restoreCallingIdentity(identity);
9510 }
9511 }
9512
9513 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009514 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009515 enforceActiveEmergencySessionPermission();
9516
9517 final long identity = Binder.clearCallingIdentity();
9518 try {
9519 for (Phone phone: PhoneFactory.getPhones()) {
9520 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9521 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009522 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9523 }
9524 }
9525 } finally {
9526 Binder.restoreCallingIdentity(identity);
9527 }
9528 }
9529
9530 @Override
9531 public void resetOtaEmergencyNumberDbFilePath() {
9532 enforceActiveEmergencySessionPermission();
9533
9534 final long identity = Binder.clearCallingIdentity();
9535 try {
9536 for (Phone phone: PhoneFactory.getPhones()) {
9537 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9538 if (tracker != null) {
9539 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009540 }
9541 }
9542 } finally {
9543 Binder.restoreCallingIdentity(identity);
9544 }
9545 }
9546
9547 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009548 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9549 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9550 Phone phone = getPhone(subId);
9551 if (phone == null) {
9552 return null;
9553 }
9554 final long identity = Binder.clearCallingIdentity();
9555 try {
9556 UiccProfile profile = UiccController.getInstance()
9557 .getUiccProfileForPhone(phone.getPhoneId());
9558 if (profile != null) {
9559 return profile.getCertsFromCarrierPrivilegeAccessRules();
9560 }
9561 } finally {
9562 Binder.restoreCallingIdentity(identity);
9563 }
9564 return null;
9565 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009566
9567 /**
9568 * Enable or disable a modem stack.
9569 */
9570 @Override
9571 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9572 enforceModifyPermission();
9573
9574 final long identity = Binder.clearCallingIdentity();
9575 try {
9576 Phone phone = PhoneFactory.getPhone(slotIndex);
9577 if (phone == null) {
9578 return false;
9579 } else {
9580 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9581 }
9582 } finally {
9583 Binder.restoreCallingIdentity(identity);
9584 }
9585 }
Michelecea4cf22018-12-21 15:00:11 -08009586
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009587 /**
9588 * Whether a modem stack is enabled or not.
9589 */
9590 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009591 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9592 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009593 Phone phone = PhoneFactory.getPhone(slotIndex);
9594 if (phone == null) return false;
9595
9596 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009597 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9598 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009599 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9600 }
9601
9602 final long identity = Binder.clearCallingIdentity();
9603 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009604 try {
9605 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9606 } catch (NoSuchElementException ex) {
9607 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9608 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009609 } finally {
9610 Binder.restoreCallingIdentity(identity);
9611 }
9612 }
9613
Michelecea4cf22018-12-21 15:00:11 -08009614 @Override
Michele0ea7d782019-03-19 14:58:42 -07009615 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009616 enforceModifyPermission();
9617
9618 final long identity = Binder.clearCallingIdentity();
9619 try {
9620 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009621 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009622 .commit();
9623 } finally {
9624 Binder.restoreCallingIdentity(identity);
9625 }
9626 }
9627
9628 @Override
Michele0ea7d782019-03-19 14:58:42 -07009629 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009630 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009631 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009632 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9633 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009634 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009635 }
Michelecea4cf22018-12-21 15:00:11 -08009636
9637 final long identity = Binder.clearCallingIdentity();
9638 try {
Michele0ea7d782019-03-19 14:58:42 -07009639 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009640 } finally {
9641 Binder.restoreCallingIdentity(identity);
9642 }
9643 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009644
Michele0ea7d782019-03-19 14:58:42 -07009645 @TelephonyManager.IsMultiSimSupportedResult
9646 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009647 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9648 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9649 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009650 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9651 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009652 }
9653 // Check if the hardware supports multisim functionality. If usage of multisim is not
9654 // supported by the modem, indicate that it is restricted.
9655 PhoneCapability staticCapability =
9656 mPhoneConfigurationManager.getStaticPhoneCapability();
9657 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009658 loge("isMultiSimSupportedInternal: no static configuration available");
9659 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009660 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009661 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009662 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9663 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009664 }
9665 // Check if support of multiple SIMs is restricted by carrier
9666 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009667 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009668 }
9669
Michele0ea7d782019-03-19 14:58:42 -07009670 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009671 }
9672
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009673 /**
9674 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009675 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9676 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9677 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009678 * @param numOfSims number of active sims we want to switch to
9679 */
9680 @Override
9681 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009682 if (numOfSims == 1) {
9683 enforceModifyPermission();
9684 } else {
9685 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9686 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9687 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009688 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009689
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009690 try {
Michele30b57b22019-03-01 12:01:14 -08009691 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009692 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009693 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9694 return;
9695 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009696 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9697 } finally {
9698 Binder.restoreCallingIdentity(identity);
9699 }
9700 }
9701
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009702 @Override
9703 public boolean isApplicationOnUicc(int subId, int appType) {
9704 enforceReadPrivilegedPermission("isApplicationOnUicc");
9705 Phone phone = getPhone(subId);
9706 if (phone == null) {
9707 return false;
9708 }
9709 final long identity = Binder.clearCallingIdentity();
9710 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009711 UiccPort uiccPort = phone.getUiccPort();
9712 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009713 return false;
9714 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009715 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009716 if (uiccProfile == null) {
9717 return false;
9718 }
9719 if (TelephonyManager.APPTYPE_SIM <= appType
9720 && appType <= TelephonyManager.APPTYPE_ISIM) {
9721 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9722 }
9723 return false;
9724 } finally {
9725 Binder.restoreCallingIdentity(identity);
9726 }
9727 }
9728
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009729 /**
chen xub4baa772019-04-03 10:23:41 -07009730 * Get whether making changes to modem configurations will trigger reboot.
9731 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009732 */
9733 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009734 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9735 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009736 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009737 mApp, subId, callingPackage, callingFeatureId,
9738 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009739 return false;
9740 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009741 final long identity = Binder.clearCallingIdentity();
9742 try {
9743 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9744 } finally {
9745 Binder.restoreCallingIdentity(identity);
9746 }
9747 }
9748
Nathan Harold29f5f052019-02-15 13:41:57 -08009749 private void updateModemStateMetrics() {
9750 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9751 // TODO: check the state for each modem if the api is ready.
9752 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9753 }
9754
Pengquan Meng3889a572019-01-23 11:16:29 -08009755 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009756 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009757 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009758 // Verify that the callingPackage belongs to the calling UID
9759 mApp.getSystemService(AppOpsManager.class)
9760 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009761 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009762 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009763 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009764 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9765 if (slotInfos != null) {
9766 for (int i = 0; i < slotInfos.length; i++) {
9767 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9768 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9769 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9770 portInfo.getLogicalSlotIndex()));
9771 }
9772 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009773 }
9774 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009775 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009776 } finally {
9777 Binder.restoreCallingIdentity(identity);
9778 }
9779 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009780
9781 /**
9782 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +08009783 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -08009784 */
jimsunf9ec1622022-09-13 21:18:43 +08009785 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -08009786 @Override
9787 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +08009788 return getHalVersion(HAL_SERVICE_RADIO);
9789 }
9790
9791 /**
9792 * Get the HAL Version of a specific service
9793 */
9794 @Override
9795 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -08009796 Phone phone = getDefaultPhone();
9797 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +08009798 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -08009799 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9800 return hv.major * 100 + hv.minor;
9801 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009802
9803 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009804 * Get the current calling package name.
9805 * @return the current calling package name
9806 */
9807 @Override
9808 public String getCurrentPackageName() {
9809 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9810 }
9811
9812 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009813 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9814 * corresponding network requests on a subId.
9815 *
9816 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009817 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009818 * 2) APN is un-metered for this subscription, or
9819 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009820 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009821 *
9822 * @return whether data is allowed for a apn type.
9823 *
9824 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009825 */
9826 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009827 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009828 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9829 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009830
9831 // Now that all security checks passes, perform the operation as ourselves.
9832 final long identity = Binder.clearCallingIdentity();
9833 try {
9834 Phone phone = getPhone(subId);
9835 if (phone == null) return false;
9836
Jack Yu27422a52022-03-21 10:38:05 -07009837 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -08009838 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -07009839 isMetered = phone.getDataNetworkController().getDataConfigManager()
9840 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
9841 phone.getServiceState().getDataRoaming());
9842 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -08009843 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009844 } finally {
9845 Binder.restoreCallingIdentity(identity);
9846 }
9847 }
9848
9849 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009850 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009851 enforceReadPrivilegedPermission("isApnMetered");
9852
9853 // Now that all security checks passes, perform the operation as ourselves.
9854 final long identity = Binder.clearCallingIdentity();
9855 try {
9856 Phone phone = getPhone(subId);
9857 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -07009858 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
9859 DataUtils.apnTypeToNetworkCapability(apnType),
9860 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009861 } finally {
9862 Binder.restoreCallingIdentity(identity);
9863 }
9864 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009865
9866 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009867 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9868 int subscriptionId, IBooleanConsumer resultCallback) {
9869 enforceModifyPermission();
9870 long token = Binder.clearCallingIdentity();
9871 try {
9872 Phone phone = getPhone(subscriptionId);
9873 if (phone == null) {
9874 try {
9875 if (resultCallback != null) {
9876 resultCallback.accept(false);
9877 }
9878 } catch (RemoteException e) {
9879 // ignore
9880 }
9881 return;
9882 }
9883 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9884 Pair.create(specifiers, (x) -> {
9885 try {
9886 if (resultCallback != null) {
9887 resultCallback.accept(x);
9888 }
9889 } catch (RemoteException e) {
9890 // ignore
9891 }
9892 });
9893 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9894 } finally {
9895 Binder.restoreCallingIdentity(token);
9896 }
9897 }
9898
9899 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009900 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9901 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009902 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009903 mApp, subId, "getSystemSelectionChannels");
9904 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9905 final long identity = Binder.clearCallingIdentity();
9906 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009907 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9908 if (result instanceof IllegalStateException) {
9909 throw (IllegalStateException) result;
9910 }
9911 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009912 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9913 return specifiers;
9914 } finally {
9915 Binder.restoreCallingIdentity(identity);
9916 }
9917 }
9918
9919 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -07009920 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009921 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -07009922 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +08009923 }
9924
9925 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009926 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9927 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009928 if (callingPackage == null) {
9929 callingPackage = getCurrentPackageName();
9930 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009931 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9932 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009933 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9934 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009935 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9936 }
9937 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9938 Intent intent = new Intent();
9939 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9940 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9941 // Bring up choose default SMS subscription dialog right now
9942 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9943 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9944 mApp.startActivity(intent);
9945 }
chen xud5ca2d52019-05-28 15:20:57 -07009946
9947 @Override
9948 public String getMmsUAProfUrl(int subId) {
9949 //TODO investigate if this API should require proper permission check in R b/133791609
9950 final long identity = Binder.clearCallingIdentity();
9951 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009952 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9953 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9954 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9955 return carrierUAProfUrl;
9956 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009957 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9958 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009959 } finally {
9960 Binder.restoreCallingIdentity(identity);
9961 }
9962 }
9963
9964 @Override
9965 public String getMmsUserAgent(int subId) {
9966 //TODO investigate if this API should require proper permission check in R b/133791609
9967 final long identity = Binder.clearCallingIdentity();
9968 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009969 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9970 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9971 if (!TextUtils.isEmpty(carrierUserAgent)) {
9972 return carrierUserAgent;
9973 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009974 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9975 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009976 } finally {
9977 Binder.restoreCallingIdentity(identity);
9978 }
9979 }
Jack Yub07d4972019-05-28 16:12:25 -07009980
9981 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009982 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9983 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009984
Jack Yub07d4972019-05-28 16:12:25 -07009985 final long identity = Binder.clearCallingIdentity();
9986 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009987 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009988 if (phone == null) return false;
9989
Ling Maf188d502022-09-16 15:22:36 -07009990 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -07009991 } finally {
9992 Binder.restoreCallingIdentity(identity);
9993 }
9994 }
9995
9996 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009997 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009998 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009999 enforceModifyPermission();
10000
changbettyd5c246e2019-12-24 15:40:37 +080010001 final long identity = Binder.clearCallingIdentity();
10002 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010003 Phone phone = getPhone(subscriptionId);
10004 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010005
Ling Maf188d502022-09-16 15:22:36 -070010006 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010007 } finally {
10008 Binder.restoreCallingIdentity(identity);
10009 }
10010 }
10011
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010012 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010013 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010014 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10015 * otherwise.
10016 */
10017 @Override
10018 public void setCepEnabled(boolean isCepEnabled) {
10019 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10020
10021 final long identity = Binder.clearCallingIdentity();
10022 try {
10023 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10024 for (Phone phone : PhoneFactory.getPhones()) {
10025 Phone defaultPhone = phone.getImsPhone();
10026 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10027 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10028 ImsPhoneCallTracker imsPhoneCallTracker =
10029 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10030 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10031 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10032 + imsPhone.getMsisdn());
10033 }
10034 }
10035 } finally {
10036 Binder.restoreCallingIdentity(identity);
10037 }
10038 }
allenwtsu46dcc572020-01-08 18:24:03 +080010039
10040 /**
10041 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10042 *
10043 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10044 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10045 * before being read.
10046 */
10047 @Override
10048 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10049 isCompressed) {
10050 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10051 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010052 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10053 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10054 }
10055 if (!isImsAvailableOnDevice()) {
10056 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10057 "IMS not available on device.");
10058 }
10059
10060 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010061 try {
Hui Wang761a6682020-10-31 05:12:53 +000010062 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10063 } finally {
10064 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010065 }
10066 }
zoey chene02881a2019-12-30 16:11:23 +080010067
10068 @Override
10069 public boolean isIccLockEnabled(int subId) {
10070 enforceReadPrivilegedPermission("isIccLockEnabled");
10071
10072 // Now that all security checks passes, perform the operation as ourselves.
10073 final long identity = Binder.clearCallingIdentity();
10074 try {
10075 Phone phone = getPhone(subId);
10076 if (phone != null && phone.getIccCard() != null) {
10077 return phone.getIccCard().getIccLockEnabled();
10078 } else {
10079 return false;
10080 }
10081 } finally {
10082 Binder.restoreCallingIdentity(identity);
10083 }
10084 }
10085
10086 /**
10087 * Set the ICC pin lock enabled or disabled.
10088 *
10089 * @return an integer representing the status of IccLock enabled or disabled in the following
10090 * three cases:
10091 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10092 * successfully.
10093 * - Positive number and zero for remaining password attempts.
10094 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10095 *
10096 */
10097 @Override
10098 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10099 enforceModifyPermission();
10100
10101 Phone phone = getPhone(subId);
10102 if (phone == null) {
10103 return 0;
10104 }
10105 // Now that all security checks passes, perform the operation as ourselves.
10106 final long identity = Binder.clearCallingIdentity();
10107 try {
10108 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10109 new Pair<Boolean, String>(enabled, password), phone, null);
10110 return attemptsRemaining;
10111
10112 } catch (Exception e) {
10113 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10114 } finally {
10115 Binder.restoreCallingIdentity(identity);
10116 }
10117 return 0;
10118 }
10119
10120 /**
10121 * Change the ICC password used in ICC pin lock.
10122 *
10123 * @return an integer representing the status of IccLock changed in the following three cases:
10124 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10125 * - Positive number and zero for remaining password attempts.
10126 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10127 *
10128 */
10129 @Override
10130 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10131 enforceModifyPermission();
10132
10133 Phone phone = getPhone(subId);
10134 if (phone == null) {
10135 return 0;
10136 }
10137 // Now that all security checks passes, perform the operation as ourselves.
10138 final long identity = Binder.clearCallingIdentity();
10139 try {
10140 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10141 new Pair<String, String>(oldPassword, newPassword), phone, null);
10142 return attemptsRemaining;
10143
10144 } catch (Exception e) {
10145 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10146 } finally {
10147 Binder.restoreCallingIdentity(identity);
10148 }
10149 return 0;
10150 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010151
10152 /**
10153 * Request for receiving user activity notification
10154 */
10155 @Override
10156 public void requestUserActivityNotification() {
10157 if (!mNotifyUserActivity.get()
10158 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10159 mNotifyUserActivity.set(true);
10160 }
10161 }
10162
10163 /**
10164 * Called when userActivity is signalled in the power manager.
10165 * This is safe to call from any thread, with any window manager locks held or not.
10166 */
10167 @Override
10168 public void userActivity() {
10169 // ***************************************
10170 // * Inherited from PhoneWindowManager *
10171 // ***************************************
10172 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10173 // WITH ITS LOCKS HELD.
10174 //
10175 // This code must be VERY careful about the locks
10176 // it acquires.
10177 // In fact, the current code acquires way too many,
10178 // and probably has lurking deadlocks.
10179
10180 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10181 throw new SecurityException("Only the OS may call notifyUserActivity()");
10182 }
10183
10184 if (mNotifyUserActivity.getAndSet(false)) {
10185 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10186 USER_ACTIVITY_NOTIFICATION_DELAY);
10187 }
10188 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010189
10190 @Override
10191 public boolean canConnectTo5GInDsdsMode() {
10192 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10193 }
Jack Yud10cdd42020-09-28 20:28:01 -070010194
10195 @Override
10196 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10197 String callingFeatureId) {
10198 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10199 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10200 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10201 }
10202
10203 Phone phone = getPhone(subId);
10204 if (phone == null) {
10205 throw new RuntimeException("phone is not available");
10206 }
10207 // Now that all security checks passes, perform the operation as ourselves.
10208 final long identity = Binder.clearCallingIdentity();
10209 try {
10210 return phone.getEquivalentHomePlmns();
10211 } finally {
10212 Binder.restoreCallingIdentity(identity);
10213 }
10214 }
Daniel Bright59e67312020-11-13 11:49:37 -080010215
10216 @Override
10217 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010218 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10219 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010220 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010221 if (radioInterfaceCapabilities == null) {
10222 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010223 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010224 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010225 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010226
Hui Wang641e81c2020-10-12 12:14:23 -070010227 @Override
10228 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10229 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010230 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10231 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10232 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10233 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10234 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010235 if (DBG) {
10236 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10237 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10238 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10239 }
10240
10241 if (!SubscriptionManager.isValidSubscriptionId(subId)
10242 || appType < TelephonyManager.APPTYPE_UNKNOWN
10243 || appType > TelephonyManager.APPTYPE_ISIM
10244 || nafUrl == null || securityProtocol == null || callback == null) {
10245 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10246 if (callback != null) {
10247 try {
10248 callback.onAuthenticationFailure(
10249 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10250 } catch (RemoteException exception) {
10251 log("Fail to notify onAuthenticationFailure due to " + exception);
10252 }
10253 return;
10254 }
10255 }
10256
10257 final long token = Binder.clearCallingIdentity();
10258 try {
10259 getGbaManager(subId).bootstrapAuthenticationRequest(
10260 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10261 forceBootStrapping, callback));
10262 } finally {
10263 Binder.restoreCallingIdentity(token);
10264 }
10265 }
10266
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010267 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010268 * Attempts to set the radio power state for all phones for thermal reason.
10269 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010270 * requested radio power state will actually be set. See {@link
10271 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10272 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010273 * @param enable {@code true} if trying to turn radio on.
10274 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10275 * false}.
10276 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010277 private boolean setRadioPowerForThermal(boolean enable) {
10278 boolean isPhoneAvailable = false;
10279 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10280 Phone phone = PhoneFactory.getPhone(i);
10281 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010282 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010283 isPhoneAvailable = true;
10284 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010285 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010286
10287 // return true if successfully informed the phone object about the thermal radio power
10288 // request.
10289 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010290 }
10291
10292 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010293 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010294 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10295 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10296 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10297 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10298 throw new IllegalArgumentException("modem does not support data throttling");
10299 }
10300
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010301 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10302 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010303 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010304 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10305 }
10306
Sarah Chinecc78c42022-03-31 21:16:48 -070010307 setDataEnabledForReason(
10308 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010309
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010310 if (isDataThrottlingSupported) {
10311 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010312 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010313 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10314 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10315 } else if (thermalMitigationResult
10316 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010317 log("Modem likely does not support data throttling on secondary carrier. Data " +
10318 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10319 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010320 }
10321 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010322 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010323
10324 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010325 }
10326
Jack Nudelman644b91a2021-03-12 14:09:48 -080010327 private static List<String> getThermalMitigationAllowlist(Context context) {
10328 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10329 for (String pckg : context.getResources()
10330 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10331 sThermalMitigationAllowlistedPackages.add(pckg);
10332 }
10333 }
10334
10335 return sThermalMitigationAllowlistedPackages;
10336 }
10337
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010338 private boolean isAnyPhoneInEmergencyState() {
10339 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10340 if (tm.isInEmergencyCall()) {
10341 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10342 return true;
10343 }
10344 for (Phone phone : PhoneFactory.getPhones()) {
10345 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10346 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10347 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10348 + phone.isInEcm());
10349 return true;
10350 }
10351 }
10352
10353 return false;
10354 }
10355
Jack Nudelman644b91a2021-03-12 14:09:48 -080010356 /**
10357 * Used by shell commands to add an authorized package name for thermal mitigation.
10358 * @param packageName name of package to be allowlisted
10359 * @param context
10360 */
10361 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10362 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10363 sThermalMitigationAllowlistedPackages.add(packageName);
10364 }
10365
10366 /**
10367 * Used by shell commands to remove an authorized package name for thermal mitigation.
10368 * @param packageName name of package to remove from allowlist
10369 * @param context
10370 */
10371 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10372 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10373 sThermalMitigationAllowlistedPackages.remove(packageName);
10374 }
10375
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010376 /**
10377 * Thermal mitigation request to control functionalities at modem.
10378 *
10379 * @param subId the id of the subscription.
10380 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010381 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010382 *
10383 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10384 */
10385 @Override
10386 @ThermalMitigationResult
10387 public int sendThermalMitigationRequest(
10388 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010389 ThermalMitigationRequest thermalMitigationRequest,
10390 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010391 enforceModifyPermission();
10392
Jack Nudelman644b91a2021-03-12 14:09:48 -080010393 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10394 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10395 .contains(callingPackage)) {
10396 throw new SecurityException("Calling package must be configured in the device config. "
10397 + "calling package: " + callingPackage);
10398 }
10399
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010400 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10401 final long identity = Binder.clearCallingIdentity();
10402
10403 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10404 try {
10405 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10406 switch (thermalMitigationAction) {
10407 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10408 thermalMitigationResult =
10409 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010410 thermalMitigationRequest.getDataThrottlingRequest(),
10411 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010412 break;
10413 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10414 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10415 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10416 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10417 }
10418
10419 // Ensure that radio is on. If not able to power on due to phone being
10420 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010421 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010422 thermalMitigationResult =
10423 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10424 break;
10425 }
10426
10427 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010428 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010429 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10430 break;
10431 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10432 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10433 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10434 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10435 }
10436
10437 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10438 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010439 Phone phone = getPhone(subId);
10440 if (phone == null) {
10441 thermalMitigationResult =
10442 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10443 break;
10444 }
10445
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010446 TelephonyConnectionService service =
10447 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010448 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010449 Log.e(LOG_TAG, "An emergency call is pending");
10450 thermalMitigationResult =
10451 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10452 break;
10453 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010454 thermalMitigationResult =
10455 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10456 break;
10457 }
10458 } else {
10459 thermalMitigationResult =
10460 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10461 break;
10462 }
10463
10464 // Turn radio off. If not able to power off due to phone being unavailable,
10465 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010466 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010467 thermalMitigationResult =
10468 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10469 break;
10470 }
10471 thermalMitigationResult =
10472 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10473 break;
10474 default:
10475 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10476 + "not exist. Requested action: " + thermalMitigationAction);
10477 }
10478 } catch (IllegalArgumentException e) {
10479 throw e;
10480 } catch (Exception e) {
10481 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10482 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10483 } finally {
10484 Binder.restoreCallingIdentity(identity);
10485 }
10486
10487 if (DBG) {
10488 log("thermalMitigationRequest returning with thermalMitigationResult: "
10489 + thermalMitigationResult);
10490 }
10491
10492 return thermalMitigationResult;
10493 }
Hui Wang641e81c2020-10-12 12:14:23 -070010494
10495 /**
10496 * Set the GbaService Package Name that Telephony will bind to.
10497 *
10498 * @param subId The sim that the GbaService is associated with.
10499 * @param packageName The name of the package to be replaced with.
10500 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10501 */
10502 @Override
10503 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10504 enforceModifyPermission();
10505
10506 final long identity = Binder.clearCallingIdentity();
10507 try {
10508 return getGbaManager(subId).overrideServicePackage(packageName);
10509 } finally {
10510 Binder.restoreCallingIdentity(identity);
10511 }
10512 }
10513
10514 /**
10515 * Return the package name of the currently bound GbaService.
10516 *
10517 * @param subId The sim that the GbaService is associated with.
10518 * @return the package name of the GbaService configuration, null if GBA is not supported.
10519 */
10520 @Override
10521 public String getBoundGbaService(int subId) {
10522 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10523
10524 final long identity = Binder.clearCallingIdentity();
10525 try {
10526 return getGbaManager(subId).getServicePackage();
10527 } finally {
10528 Binder.restoreCallingIdentity(identity);
10529 }
10530 }
10531
10532 /**
10533 * Set the release time for telephony to unbind GbaService.
10534 *
10535 * @param subId The sim that the GbaService is associated with.
10536 * @param interval The release time to unbind GbaService by millisecond.
10537 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10538 */
10539 @Override
10540 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10541 enforceModifyPermission();
10542
10543 final long identity = Binder.clearCallingIdentity();
10544 try {
10545 return getGbaManager(subId).overrideReleaseTime(interval);
10546 } finally {
10547 Binder.restoreCallingIdentity(identity);
10548 }
10549 }
10550
10551 /**
10552 * Return the release time for telephony to unbind GbaService.
10553 *
10554 * @param subId The sim that the GbaService is associated with.
10555 * @return The release time to unbind GbaService by millisecond.
10556 */
10557 @Override
10558 public int getGbaReleaseTime(int subId) {
10559 enforceReadPrivilegedPermission("getGbaReleaseTime");
10560
10561 final long identity = Binder.clearCallingIdentity();
10562 try {
10563 return getGbaManager(subId).getReleaseTime();
10564 } finally {
10565 Binder.restoreCallingIdentity(identity);
10566 }
10567 }
10568
10569 private GbaManager getGbaManager(int subId) {
10570 GbaManager instance = GbaManager.getInstance(subId);
10571 if (instance == null) {
10572 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10573 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10574 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10575 }
10576 return instance;
10577 }
Hui Wang761a6682020-10-31 05:12:53 +000010578
10579 /**
10580 * indicate whether the device and the carrier can support
10581 * RCS VoLTE single registration.
10582 */
10583 @Override
10584 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010585 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10586 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10587 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10588 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010589
10590 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10591 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10592 }
10593
10594 final long identity = Binder.clearCallingIdentity();
10595 try {
10596 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10597 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010598 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10599 if (isCapable != null) {
10600 return isCapable;
10601 }
Hui Wang761a6682020-10-31 05:12:53 +000010602 }
Hui Wang67af90e2021-06-04 16:57:15 -070010603 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10604 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010605 } finally {
10606 Binder.restoreCallingIdentity(identity);
10607 }
10608 }
10609
10610 /**
10611 * Register RCS provisioning callback.
10612 */
10613 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010614 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010615 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010616 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010617 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010618 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10619 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010620
10621 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10622 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10623 }
10624 if (!isImsAvailableOnDevice()) {
10625 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10626 "IMS not available on device.");
10627 }
10628
10629 final long identity = Binder.clearCallingIdentity();
10630 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010631 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010632 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010633 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10634 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010635 }
Hui Wang761a6682020-10-31 05:12:53 +000010636 } finally {
10637 Binder.restoreCallingIdentity(identity);
10638 }
10639 }
10640
10641 /**
10642 * Unregister RCS provisioning callback.
10643 */
10644 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010645 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010646 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010647 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010648 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010649 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10650 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010651
10652 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10653 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10654 }
10655 if (!isImsAvailableOnDevice()) {
10656 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10657 "IMS not available on device.");
10658 }
10659
10660 final long identity = Binder.clearCallingIdentity();
10661 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010662 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010663 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010664 } finally {
10665 Binder.restoreCallingIdentity(identity);
10666 }
10667 }
10668
10669 /**
10670 * trigger RCS reconfiguration.
10671 */
10672 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010673 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10674 "triggerRcsReconfiguration",
10675 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010676
10677 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10678 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10679 }
10680 if (!isImsAvailableOnDevice()) {
10681 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10682 "IMS not available on device.");
10683 }
10684
10685 final long identity = Binder.clearCallingIdentity();
10686 try {
10687 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10688 } finally {
10689 Binder.restoreCallingIdentity(identity);
10690 }
10691 }
10692
10693 /**
10694 * Provide the client configuration parameters of the RCS application.
10695 */
10696 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010697 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10698 "setRcsClientConfiguration",
10699 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010700
10701 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10702 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10703 }
10704 if (!isImsAvailableOnDevice()) {
10705 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10706 "IMS not available on device.");
10707 }
10708
10709 final long identity = Binder.clearCallingIdentity();
10710
10711 try {
10712 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10713 if (configBinder == null) {
10714 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010715 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10716 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010717 } else {
10718 configBinder.setRcsClientConfiguration(rcc);
10719 }
joonhunshin3e154242021-09-17 06:33:39 +000010720
10721 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10722 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010723 } catch (RemoteException e) {
10724 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010725 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10726 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010727 } finally {
10728 Binder.restoreCallingIdentity(identity);
10729 }
10730 }
10731
10732 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010733 * Enables or disables the test mode for RCS VoLTE single registration.
10734 */
10735 @Override
10736 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10737 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10738 "setRcsSingleRegistrationTestModeEnabled");
10739
10740 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10741 }
10742
10743 /**
10744 * Gets the test mode for RCS VoLTE single registration.
10745 */
10746 @Override
10747 public boolean getRcsSingleRegistrationTestModeEnabled() {
10748 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10749 "getRcsSingleRegistrationTestModeEnabled");
10750
10751 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10752 }
10753
10754 /**
Hui Wang761a6682020-10-31 05:12:53 +000010755 * Overrides the config of RCS VoLTE single registration enabled for the device.
10756 */
10757 @Override
10758 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10759 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10760 "setDeviceSingleRegistrationEnabledOverride");
10761 enforceModifyPermission();
10762
10763 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10764 : Boolean.parseBoolean(enabledStr);
10765 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010766 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010767 }
10768
10769 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010770 * Sends a device to device communication message. Only usable via shell.
10771 * @param message message to send.
10772 * @param value message value.
10773 */
10774 @Override
10775 public void sendDeviceToDeviceMessage(int message, int value) {
10776 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010777 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010778 enforceModifyPermission();
10779
10780 final long identity = Binder.clearCallingIdentity();
10781 try {
10782 TelephonyConnectionService service =
10783 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10784 if (service == null) {
10785 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10786 return;
10787 }
10788 service.sendTestDeviceToDeviceMessage(message, value);
10789 } finally {
10790 Binder.restoreCallingIdentity(identity);
10791 }
10792 }
10793
Tyler Gunnbabbda02021-02-10 11:05:02 -080010794 /**
10795 * Sets the specified device to device transport active.
10796 * @param transport The transport to set active.
10797 */
10798 @Override
10799 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10800 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10801 "setActiveDeviceToDeviceTransport");
10802 enforceModifyPermission();
10803
10804 final long identity = Binder.clearCallingIdentity();
10805 try {
10806 TelephonyConnectionService service =
10807 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10808 if (service == null) {
10809 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10810 return;
10811 }
10812 service.setActiveDeviceToDeviceTransport(transport);
10813 } finally {
10814 Binder.restoreCallingIdentity(identity);
10815 }
10816 }
Tyler Gunn92479152021-01-20 16:30:10 -080010817
Tyler Gunnd4339262021-05-03 14:46:49 -070010818 @Override
10819 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10820 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10821 "setDeviceToDeviceForceEnabled");
10822
10823 final long identity = Binder.clearCallingIdentity();
10824 try {
10825 Arrays.stream(PhoneFactory.getPhones()).forEach(
10826 p -> {
10827 Phone thePhone = p.getImsPhone();
10828 if (thePhone != null && thePhone instanceof ImsPhone) {
10829 ImsPhone imsPhone = (ImsPhone) thePhone;
10830 CallTracker tracker = imsPhone.getCallTracker();
10831 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10832 ImsPhoneCallTracker imsPhoneCallTracker =
10833 (ImsPhoneCallTracker) tracker;
10834 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10835 }
10836 }
10837 }
10838 );
10839 } finally {
10840 Binder.restoreCallingIdentity(identity);
10841 }
10842 }
10843
Tyler Gunn92479152021-01-20 16:30:10 -080010844 /**
Hui Wang761a6682020-10-31 05:12:53 +000010845 * Gets the config of RCS VoLTE single registration enabled for the device.
10846 */
10847 @Override
10848 public boolean getDeviceSingleRegistrationEnabled() {
10849 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10850 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10851 }
10852
10853 /**
10854 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10855 */
10856 @Override
10857 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10858 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10859 "setCarrierSingleRegistrationEnabledOverride");
10860 enforceModifyPermission();
10861
10862 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10863 : Boolean.parseBoolean(enabledStr);
10864 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10865 subId, enabled);
10866 }
10867
10868 /**
10869 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10870 */
10871 @Override
10872 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10873 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10874 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10875 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010876
10877 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010878 * Overrides the ims feature validation result
10879 */
10880 @Override
10881 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10882 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10883 "setImsFeatureValidationOverride");
10884
10885 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10886 : Boolean.parseBoolean(enabledStr);
10887 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10888 subId, enabled);
10889 }
10890
10891 /**
10892 * Gets the ims feature validation override value
10893 */
10894 @Override
10895 public boolean getImsFeatureValidationOverride(int subId) {
10896 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10897 "getImsFeatureValidationOverride");
10898 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10899 }
10900
10901 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010902 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10903 * their mobile plan.
10904 */
10905 @Override
10906 public String getMobileProvisioningUrl() {
10907 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10908 final long identity = Binder.clearCallingIdentity();
10909 try {
10910 return getDefaultPhone().getMobileProvisioningUrl();
10911 } finally {
10912 Binder.restoreCallingIdentity(identity);
10913 }
10914 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010915
James.cf Linbcdf8b32021-01-14 16:44:13 +080010916 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010917 * Get the EAB contact from the EAB database.
10918 */
10919 @Override
10920 public String getContactFromEab(String contact) {
10921 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10922 enforceModifyPermission();
10923 final long identity = Binder.clearCallingIdentity();
10924 try {
10925 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10926 } finally {
10927 Binder.restoreCallingIdentity(identity);
10928 }
10929 }
10930
10931 /**
Calvin Pana1434322021-07-01 19:27:01 +080010932 * Get the EAB capability from the EAB database.
10933 */
10934 @Override
10935 public String getCapabilityFromEab(String contact) {
10936 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10937 enforceModifyPermission();
10938 final long identity = Binder.clearCallingIdentity();
10939 try {
10940 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10941 } finally {
10942 Binder.restoreCallingIdentity(identity);
10943 }
10944 }
10945
10946 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010947 * Remove the EAB contacts from the EAB database.
10948 */
10949 @Override
10950 public int removeContactFromEab(int subId, String contacts) {
10951 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10952 enforceModifyPermission();
10953 final long identity = Binder.clearCallingIdentity();
10954 try {
10955 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10956 } finally {
10957 Binder.restoreCallingIdentity(identity);
10958 }
10959 }
10960
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010961 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010962 public boolean getDeviceUceEnabled() {
10963 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10964 final long identity = Binder.clearCallingIdentity();
10965 try {
10966 return mApp.getDeviceUceEnabled();
10967 } finally {
10968 Binder.restoreCallingIdentity(identity);
10969 }
10970 }
10971
10972 @Override
10973 public void setDeviceUceEnabled(boolean isEnabled) {
10974 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10975 final long identity = Binder.clearCallingIdentity();
10976 try {
10977 mApp.setDeviceUceEnabled(isEnabled);
10978 } finally {
10979 Binder.restoreCallingIdentity(identity);
10980 }
10981 }
10982
Brad Ebinger14d467f2021-02-12 06:18:28 +000010983 /**
10984 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10985 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10986 */
10987 // Used for SHELL command only right now.
10988 @Override
10989 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10990 List<String> featureTags) {
10991 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10992 "addUceRegistrationOverrideShell");
10993 final long identity = Binder.clearCallingIdentity();
10994 try {
10995 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10996 new ArraySet<>(featureTags));
10997 } catch (ImsException e) {
10998 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10999 } finally {
11000 Binder.restoreCallingIdentity(identity);
11001 }
11002 }
11003
11004 /**
11005 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11006 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11007 */
11008 // Used for SHELL command only right now.
11009 @Override
11010 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11011 List<String> featureTags) {
11012 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11013 "removeUceRegistrationOverrideShell");
11014 final long identity = Binder.clearCallingIdentity();
11015 try {
11016 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11017 new ArraySet<>(featureTags));
11018 } catch (ImsException e) {
11019 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11020 } finally {
11021 Binder.restoreCallingIdentity(identity);
11022 }
11023 }
11024
11025 /**
11026 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11027 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11028 */
11029 // Used for SHELL command only right now.
11030 @Override
11031 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11032 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11033 "clearUceRegistrationOverrideShell");
11034 final long identity = Binder.clearCallingIdentity();
11035 try {
11036 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11037 } catch (ImsException e) {
11038 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11039 } finally {
11040 Binder.restoreCallingIdentity(identity);
11041 }
11042 }
11043
11044 /**
11045 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11046 */
11047 // Used for SHELL command only right now.
11048 @Override
11049 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11050 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11051 "getLatestRcsContactUceCapabilityShell");
11052 final long identity = Binder.clearCallingIdentity();
11053 try {
11054 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11055 } catch (ImsException e) {
11056 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11057 } finally {
11058 Binder.restoreCallingIdentity(identity);
11059 }
11060 }
11061
11062 /**
11063 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11064 * device does not have an active PUBLISH.
11065 */
11066 // Used for SHELL command only right now.
11067 @Override
11068 public String getLastUcePidfXmlShell(int subId) {
11069 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11070 final long identity = Binder.clearCallingIdentity();
11071 try {
11072 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11073 } catch (ImsException e) {
11074 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11075 } finally {
11076 Binder.restoreCallingIdentity(identity);
11077 }
11078 }
11079
James.cf Line8713a42021-04-29 16:04:26 +080011080 /**
11081 * Remove UCE requests cannot be sent to the network status.
11082 */
11083 // Used for SHELL command only right now.
11084 @Override
11085 public boolean removeUceRequestDisallowedStatus(int subId) {
11086 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11087 final long identity = Binder.clearCallingIdentity();
11088 try {
11089 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11090 } catch (ImsException e) {
11091 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11092 } finally {
11093 Binder.restoreCallingIdentity(identity);
11094 }
11095 }
11096
James.cf Lin18bb9002021-05-25 01:37:38 +080011097 /**
11098 * Remove UCE requests cannot be sent to the network status.
11099 */
11100 // Used for SHELL command only.
11101 @Override
11102 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11103 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11104 final long identity = Binder.clearCallingIdentity();
11105 try {
11106 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11107 } catch (ImsException e) {
11108 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11109 } finally {
11110 Binder.restoreCallingIdentity(identity);
11111 }
11112 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011113
James.cf Lin4b784aa2021-01-31 03:25:15 +080011114 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011115 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11116 String callingPackage) {
11117 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11118 mApp, subId, "setSignalStrengthUpdateRequest");
11119
11120 final int callingUid = Binder.getCallingUid();
11121 // Verify that tha callingPackage belongs to the calling UID
11122 mApp.getSystemService(AppOpsManager.class)
11123 .checkPackage(callingUid, callingPackage);
11124
Rambo Wang3607f502021-02-01 21:51:40 -080011125 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011126
11127 final long identity = Binder.clearCallingIdentity();
11128 try {
11129 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11130 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11131
11132 if (result instanceof IllegalStateException) {
11133 throw (IllegalStateException) result;
11134 }
11135 } finally {
11136 Binder.restoreCallingIdentity(identity);
11137 }
11138 }
11139
11140 @Override
11141 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11142 String callingPackage) {
11143 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11144 mApp, subId, "clearSignalStrengthUpdateRequest");
11145
11146 final int callingUid = Binder.getCallingUid();
11147 // Verify that tha callingPackage belongs to the calling UID
11148 mApp.getSystemService(AppOpsManager.class)
11149 .checkPackage(callingUid, callingPackage);
11150
11151 final long identity = Binder.clearCallingIdentity();
11152 try {
11153 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11154 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11155
11156 if (result instanceof IllegalStateException) {
11157 throw (IllegalStateException) result;
11158 }
11159 } finally {
11160 Binder.restoreCallingIdentity(identity);
11161 }
11162 }
11163
Rambo Wang3607f502021-02-01 21:51:40 -080011164 private static void validateSignalStrengthUpdateRequest(Context context,
11165 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011166 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11167 // phone/system process do not have further restriction on request
11168 return;
11169 }
11170
11171 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011172 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011173 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011174 context.enforceCallingOrSelfPermission(
11175 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11176 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011177 }
11178
11179 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11180 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11181 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11182 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11183 || info.isEnabled()) {
11184 throw new IllegalArgumentException(
11185 "Only system can set hide fields in SignalThresholdInfo");
11186 }
11187
11188 // Thresholds length for each RAN need in range. This has been validated in
11189 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11190 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11191 final int[] thresholds = info.getThresholds();
11192 Objects.requireNonNull(thresholds);
11193 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11194 || thresholds.length
11195 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11196 throw new IllegalArgumentException(
11197 "thresholds length is out of range: " + thresholds.length);
11198 }
11199 }
11200 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011201
11202 /**
11203 * Gets the current phone capability.
11204 *
11205 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11206 * @return the PhoneCapability which describes the data connection capability of modem.
11207 * It's used to evaluate possible phone config change, for example from single
11208 * SIM device to multi-SIM device.
11209 */
11210 @Override
11211 public PhoneCapability getPhoneCapability() {
11212 enforceReadPrivilegedPermission("getPhoneCapability");
11213 final long identity = Binder.clearCallingIdentity();
11214 try {
11215 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11216 } finally {
11217 Binder.restoreCallingIdentity(identity);
11218 }
11219 }
Michele Berionne5e411512020-11-13 02:36:59 +000011220
11221 /**
11222 * Prepare TelephonyManager for an unattended reboot. The reboot is
11223 * required to be done shortly after the API is invoked.
11224 */
11225 @Override
11226 @TelephonyManager.PrepareUnattendedRebootResult
11227 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011228 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011229 enforceRebootPermission();
11230
11231 final long identity = Binder.clearCallingIdentity();
11232 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011233 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011234 } finally {
11235 Binder.restoreCallingIdentity(identity);
11236 }
11237 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011238
11239 /**
11240 * Request to get the current slicing configuration including URSP rules and
11241 * NSSAIs (configured, allowed and rejected).
11242 *
11243 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11244 */
11245 @Override
11246 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011247 TelephonyPermissions
11248 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11249 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011250
11251 final long identity = Binder.clearCallingIdentity();
11252 try {
11253 Phone phone = getDefaultPhone();
11254 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11255 } finally {
11256 Binder.restoreCallingIdentity(identity);
11257 }
11258 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011259
11260 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011261 * Check whether the given premium capability is available for purchase from the carrier.
11262 *
11263 * @param capability The premium capability to check.
11264 * @param subId The subId to check the premium capability for.
11265 *
11266 * @return Whether the given premium capability is available to purchase.
11267 */
11268 @Override
11269 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11270 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11271 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11272 log("Premium capability "
11273 + TelephonyManager.convertPremiumCapabilityToString(capability)
11274 + " is not available for purchase due to missing permissions.");
11275 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11276 + "permission READ_BASIC_PHONE_STATE.");
11277 }
11278
11279 Phone phone = getPhone(subId);
11280 final long identity = Binder.clearCallingIdentity();
11281 try {
Sarah Chin46355ba2022-11-01 23:51:16 -070011282 return SlicePurchaseController.getInstance(phone)
Sarah Chin2ec39f62022-08-31 17:03:26 -070011283 .isPremiumCapabilityAvailableForPurchase(capability);
11284 } finally {
11285 Binder.restoreCallingIdentity(identity);
11286 }
11287 }
11288
11289 /**
11290 * Purchase the given premium capability from the carrier.
11291 *
11292 * @param capability The premium capability to purchase.
11293 * @param callback The result of the purchase request.
11294 * @param subId The subId to purchase the premium capability for.
11295 */
11296 @Override
11297 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11298 log("purchasePremiumCapability: capability="
11299 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11300 + getCurrentPackageName());
11301
11302 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11303 mApp, "purchasePremiumCapability")) {
11304 log("purchasePremiumCapability "
11305 + TelephonyManager.convertPremiumCapabilityToString(capability)
11306 + " failed due to missing permissions.");
11307 throw new SecurityException("purchasePremiumCapability requires permission "
11308 + "READ_BASIC_PHONE_STATE.");
11309 }
11310
11311 Phone phone = getPhone(subId);
Sarah Chin71b3a852022-09-28 15:54:19 -070011312 String appName;
11313 try {
11314 appName = mApp.getPackageManager().getApplicationLabel(mApp.getPackageManager()
11315 .getApplicationInfo(getCurrentPackageName(), 0)).toString();
11316 } catch (PackageManager.NameNotFoundException e) {
11317 appName = "An application";
11318 }
11319 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
11320 new PurchasePremiumCapabilityArgument(capability, appName, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011321 }
11322
11323 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011324 * Register an IMS connection state callback
11325 */
11326 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011327 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11328 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011329 if (feature == ImsFeature.FEATURE_MMTEL) {
11330 // ImsMmTelManager
11331 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11332 TelephonyPermissions
11333 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11334 mApp, subId, "registerImsStateCallback");
11335 } else if (feature == ImsFeature.FEATURE_RCS) {
11336 // ImsRcsManager or SipDelegateManager
11337 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11338 Binder.getCallingUid(), "registerImsStateCallback",
11339 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11340 Manifest.permission.READ_PRECISE_PHONE_STATE,
11341 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11342 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11343 }
11344
11345 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11346 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11347 "IMS not available on device.");
11348 }
11349
11350 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11351 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11352 }
11353
11354 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11355 if (controller == null) {
11356 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11357 "IMS not available on device.");
11358 }
11359
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011360 if (callingPackage == null) {
11361 callingPackage = getCurrentPackageName();
11362 }
11363
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011364 final long token = Binder.clearCallingIdentity();
11365 try {
11366 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011367 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011368 } catch (ImsException e) {
11369 throw new ServiceSpecificException(e.getCode());
11370 } finally {
11371 Binder.restoreCallingIdentity(token);
11372 }
11373 }
11374
11375 /**
11376 * Unregister an IMS connection state callback
11377 */
11378 @Override
11379 public void unregisterImsStateCallback(IImsStateCallback cb) {
11380 final long token = Binder.clearCallingIdentity();
11381 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11382 if (controller == null) {
11383 return;
11384 }
11385 try {
11386 controller.unregisterImsStateCallback(cb);
11387 } finally {
11388 Binder.restoreCallingIdentity(token);
11389 }
11390 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011391
11392 /**
11393 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11394 *
11395 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11396 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11397 * SecurityException.
11398 * If there is current registered network this value will be same as the registered cell
11399 * identity. If the device goes out of service the previous cell identity is cached and
11400 * will be returned. If the cache age of the Cell identity is more than 24 hours
11401 * it will be cleared and null will be returned.
11402 *
11403 */
11404 @Override
11405 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11406 String callingFeatureId) {
11407 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11408 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11409 LocationAccessPolicy.checkLocationPermission(mApp,
11410 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11411 .setCallingPackage(callingPackage)
11412 .setCallingFeatureId(callingFeatureId)
11413 .setCallingPid(Binder.getCallingPid())
11414 .setCallingUid(Binder.getCallingUid())
11415 .setMethod("getLastKnownCellIdentity")
11416 .setLogAsInfo(true)
11417 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11418 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11419 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11420 .build());
11421
11422 boolean hasFinePermission =
11423 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11424 if (!hasFinePermission
11425 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11426 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011427 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011428 }
11429
11430 final long identity = Binder.clearCallingIdentity();
11431 try {
11432 Phone phone = getPhone(subId);
11433 if (phone == null) return null;
11434 ServiceStateTracker sst = phone.getServiceStateTracker();
11435 if (sst == null) return null;
11436 return sst.getLastKnownCellIdentity();
11437 } finally {
11438 Binder.restoreCallingIdentity(identity);
11439 }
11440 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011441
jimsun3b9ccac2021-10-26 15:01:23 +080011442 /**
11443 * Sets the modem service class Name that Telephony will bind to.
11444 *
11445 * @param serviceName The class name of the modem service.
11446 * @return true if the operation is succeed, otherwise false.
11447 */
11448 public boolean setModemService(String serviceName) {
11449 Log.d(LOG_TAG, "setModemService - " + serviceName);
11450 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11451 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11452 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11453 "setModemService");
11454 return mPhoneConfigurationManager.setModemService(serviceName);
11455 }
11456
11457 /**
11458 * Return the class name of the currently bounded modem service.
11459 *
11460 * @return the class name of the modem service.
11461 */
11462 public String getModemService() {
11463 String result;
11464 Log.d(LOG_TAG, "getModemService");
11465 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11466 TelephonyPermissions
11467 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11468 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11469 "getModemService");
11470 result = mPhoneConfigurationManager.getModemService();
11471 Log.d(LOG_TAG, "result = " + result);
11472 return result;
11473 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011474
11475 @Override
11476 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11477 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11478 mApp.enforceCallingOrSelfPermission(
11479 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11480 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11481
11482 final long identity = Binder.clearCallingIdentity();
11483 try {
11484 Phone phone = getPhone(subId);
11485 if (phone == null) return;
11486 phone.setVoiceServiceStateOverride(hasService);
11487 } finally {
11488 Binder.restoreCallingIdentity(identity);
11489 }
11490 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011491
11492 /**
11493 * set removable eSIM as default eUICC.
11494 *
11495 * @hide
11496 */
11497 @Override
11498 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11499 enforceModifyPermission();
11500 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11501
11502 final long identity = Binder.clearCallingIdentity();
11503 try {
11504 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11505 } finally {
11506 Binder.restoreCallingIdentity(identity);
11507 }
11508 }
11509
11510 /**
11511 * Returns whether the removable eSIM is default eUICC or not.
11512 *
11513 * @hide
11514 */
11515 @Override
11516 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11517 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11518 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11519
11520 final long identity = Binder.clearCallingIdentity();
11521 try {
11522 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11523 } finally {
11524 Binder.restoreCallingIdentity(identity);
11525 }
11526 }
11527
11528
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011529}