blob: 0af609e6701e9600363db13880d05abcfb8093d7 [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;
20
Shuo Qianccbaf742021-02-22 18:32:21 -080021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
22import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070024import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000025import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070026
Brad Ebinger34c09a52021-02-17 23:23:21 +000027import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080029import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070030import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000031import android.annotation.RequiresPermission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080033import android.app.PendingIntent;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000034import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080035import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000036import android.compat.annotation.ChangeId;
37import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070038import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070039import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070040import android.content.Context;
41import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070042import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070043import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070044import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.net.Uri;
46import android.os.AsyncResult;
47import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080048import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049import android.os.Bundle;
50import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070051import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052import android.os.Looper;
53import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070054import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080055import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070056import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070057import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080058import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080059import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070060import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070061import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080062import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070063import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070064import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070065import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070066import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070067import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080068import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070069import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090070import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080071import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080072import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070073import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080074import android.telephony.AccessNetworkConstants;
75import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070076import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080077import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080078import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070079import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080080import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070081import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080082import android.telephony.CellIdentityCdma;
83import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070084import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070085import android.telephony.CellInfoGsm;
86import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070087import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080088import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070089import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070090import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070091import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080092import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070093import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080094import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070095import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080096import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080097import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070098import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080099import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700100import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800101import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800102import android.telephony.SignalStrengthUpdateRequest;
103import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800104import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800105import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800106import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700107import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700108import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800109import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800110import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800111import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000112import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000113import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000114import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700115import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700116import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800117import android.telephony.data.ApnSetting;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800118import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800119import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700120import android.telephony.gba.GbaAuthRequest;
121import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700122import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800123import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000124import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000125import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700126import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000127import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700128import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800129import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700130import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800131import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700132import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000133import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700134import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800135import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800136import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800137import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800138import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700139import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800140import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700141import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700142import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800143import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800144
Andrew Lee312e8172014-10-23 17:01:36 -0700145import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800146import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800147import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800148import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800149import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700150import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700151import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700152import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800153import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800154import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700155import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700156import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800157import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700158import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700159import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800160import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800161import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800162import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700163import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000164import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700165import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800166import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700167import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800168import com.android.internal.telephony.IccCard;
Rambo Wanga1782702021-11-10 20:15:19 -0800169import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700170import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700171import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700172import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700173import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700174import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800175import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700176import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700177import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700178import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700179import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800180import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800181import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700182import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700183import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700184import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800185import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800186import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800187import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700188import com.android.internal.telephony.data.DataUtils;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700189import com.android.internal.telephony.dataconnection.ApnSettingUtils;
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;
changbetty7157e9e2019-12-06 18:16:37 +0800199import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700200import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800201import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700202import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800203import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700204import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000205import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800206import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000207import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800208import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700209import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700210import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800211import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800212import com.android.phone.callcomposer.CallComposerPictureManager;
213import com.android.phone.callcomposer.CallComposerPictureTransfer;
214import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700215import com.android.phone.settings.PickSmsSubscriptionActivity;
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;
Hall Liu82694d52020-12-11 18:22:04 -0800241import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800242import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800243import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700244
245/**
246 * Implementation of the ITelephony interface.
247 */
Santos Cordon117fee72014-05-16 17:56:12 -0700248public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700249 private static final String LOG_TAG = "PhoneInterfaceManager";
250 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
251 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800252 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700253
254 // Message codes used with mMainThreadHandler
255 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700256 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
257 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700258 private static final int CMD_OPEN_CHANNEL = 9;
259 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
260 private static final int CMD_CLOSE_CHANNEL = 11;
261 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800262 private static final int CMD_NV_READ_ITEM = 13;
263 private static final int EVENT_NV_READ_ITEM_DONE = 14;
264 private static final int CMD_NV_WRITE_ITEM = 15;
265 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
266 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
267 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700268 private static final int CMD_RESET_MODEM_CONFIG = 19;
269 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800270 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
271 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800272 private static final int CMD_SEND_ENVELOPE = 25;
273 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000274 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
275 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700276 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
277 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
278 private static final int CMD_EXCHANGE_SIM_IO = 31;
279 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800280 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
281 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700282 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
283 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700284 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
285 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700286 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
287 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
288 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
289 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700290 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
291 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
292 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
293 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700294 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800295 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
296 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000297 private static final int CMD_SWITCH_SLOTS = 50;
298 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700299 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
300 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
301 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
302 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
303 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
304 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
305 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
306 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700307 private static final int CMD_GET_ALL_CELL_INFO = 60;
308 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
309 private static final int CMD_GET_CELL_LOCATION = 62;
310 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700311 private static final int CMD_MODEM_REBOOT = 64;
312 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700313 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
314 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800315 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
316 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700317 private static final int CMD_GET_MODEM_STATUS = 70;
318 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700319 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
320 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700321 private static final int CMD_ERASE_MODEM_CONFIG = 74;
322 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800323 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
324 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
325 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
326 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800327 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
328 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800329 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800330 private static final int CMD_GET_CALL_FORWARDING = 83;
331 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
332 private static final int CMD_SET_CALL_FORWARDING = 85;
333 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
334 private static final int CMD_GET_CALL_WAITING = 87;
335 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
336 private static final int CMD_SET_CALL_WAITING = 89;
337 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700338 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
339 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
340 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
341 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700342 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
343 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800344 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
345 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800346 private static final int CMD_SET_DATA_THROTTLING = 99;
347 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800348 private static final int CMD_SET_SIM_POWER = 101;
349 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800350 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
351 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
352 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
353 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800354 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
355 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000356 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800357 private static final int CMD_GET_SLICING_CONFIG = 110;
358 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800359 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700360 private static final int CMD_ENABLE_VONR = 113;
361 private static final int EVENT_ENABLE_VONR_DONE = 114;
362 private static final int CMD_IS_VONR_ENABLED = 115;
363 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700364
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800365 // Parameters of select command.
366 private static final int SELECT_COMMAND = 0xA4;
367 private static final int SELECT_P1 = 0x04;
368 private static final int SELECT_P2 = 0;
369 private static final int SELECT_P3 = 0x10;
370
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371 /** The singleton instance. */
372 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800373 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700374
Wink Saville3ab207e2014-11-20 13:07:20 -0800375 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800376 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800377 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700378 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800379 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700380 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800381 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800382 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800383 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700384 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800385 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700386
Peter Wangdafb9ac2020-01-15 14:13:38 -0800387 /** User Activity */
388 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800389 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
390
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700391 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
392
Derek Tan97ebb422014-09-05 16:55:38 -0700393 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
394 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800395 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800396 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700397
Michelecea4cf22018-12-21 15:00:11 -0800398 // String to store multi SIM allowed
399 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
400
Derek Tan740e1672017-06-27 14:56:27 -0700401 // The AID of ISD-R.
402 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
403
yinxub1bed742017-04-17 11:45:04 -0700404 private NetworkScanRequestTracker mNetworkScanRequestTracker;
405
David Kelly5e06a7f2018-03-12 14:10:59 +0000406 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
407 private static final int MANUFACTURER_CODE_LENGTH = 8;
408
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800409 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800410 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800411
Derek Tan89e89d42014-07-08 17:00:10 -0700412 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700413 * Experiment flag to enable erase modem config on reset network, default value is false
414 */
415 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
416 "reset_network_erase_modem_config_enabled";
417
Rambo Wang0f050d82021-02-12 11:43:36 -0800418 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800419
sandeepjsb6c87872021-09-27 15:34:44 +0000420 /**
421 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
422 * one ICCID active at the same time.
423 * Apps should use below API signatures if targeting SDK is T and beyond.
424 *
425 * @hide
426 */
427 @ChangeId
428 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
429 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800430
Naina Nallurid63128d2019-09-17 14:10:30 -0700431 /**
Chen Xu540470b2021-12-14 17:15:47 -0800432 * Apps targeting on Android T and beyond will get exception whenever icc close channel
433 * operation fails.
434 */
435 @ChangeId
436 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
437 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
438
439 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700440 * A request object to use for transmitting data to an ICC.
441 */
442 private static final class IccAPDUArgument {
443 public int channel, cla, command, p1, p2, p3;
444 public String data;
445
446 public IccAPDUArgument(int channel, int cla, int command,
447 int p1, int p2, int p3, String data) {
448 this.channel = channel;
449 this.cla = cla;
450 this.command = command;
451 this.p1 = p1;
452 this.p2 = p2;
453 this.p3 = p3;
454 this.data = data;
455 }
456 }
457
458 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700459 * A request object to use for transmitting data to an ICC.
460 */
461 private static final class ManualNetworkSelectionArgument {
462 public OperatorInfo operatorInfo;
463 public boolean persistSelection;
464
465 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
466 this.operatorInfo = operatorInfo;
467 this.persistSelection = persistSelection;
468 }
469 }
470
471 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700472 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
473 * request after sending. The main thread will notify the request when it is complete.
474 */
475 private static final class MainThreadRequest {
476 /** The argument to use for the request */
477 public Object argument;
478 /** The result of the request that is run on the main thread */
479 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800480 // The subscriber id that this request applies to. Defaults to
481 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
482 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700483
Nathan Harold92bed182018-10-12 18:16:49 -0700484 // In cases where subId is unavailable, the caller needs to specify the phone.
485 public Phone phone;
486
vagdeviaf9a5b92018-08-15 16:01:53 -0700487 public WorkSource workSource;
488
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700489 public MainThreadRequest(Object argument) {
490 this.argument = argument;
491 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800492
Nathan Harold92bed182018-10-12 18:16:49 -0700493 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
494 this.argument = argument;
495 if (phone != null) {
496 this.phone = phone;
497 }
498 this.workSource = workSource;
499 }
500
vagdeviaf9a5b92018-08-15 16:01:53 -0700501 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800502 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800503 if (subId != null) {
504 this.subId = subId;
505 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700506 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800507 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700508 }
509
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800510 private static final class IncomingThirdPartyCallArgs {
511 public final ComponentName component;
512 public final String callId;
513 public final String callerDisplayName;
514
515 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
516 String callerDisplayName) {
517 this.component = component;
518 this.callId = callId;
519 this.callerDisplayName = callerDisplayName;
520 }
521 }
522
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700523 /**
524 * A handler that processes messages on the main thread in the phone process. Since many
525 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
526 * inbound binder threads to the main thread in the phone process. The Binder thread
527 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
528 * on, which will be notified when the operation completes and will contain the result of the
529 * request.
530 *
531 * <p>If a MainThreadRequest object is provided in the msg.obj field,
532 * note that request.result must be set to something non-null for the calling thread to
533 * unblock.
534 */
535 private final class MainThreadHandler extends Handler {
536 @Override
537 public void handleMessage(Message msg) {
538 MainThreadRequest request;
539 Message onCompleted;
540 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000541 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700542 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800543 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700544
545 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700546 case CMD_HANDLE_USSD_REQUEST: {
547 request = (MainThreadRequest) msg.obj;
548 final Phone phone = getPhoneFromRequest(request);
549 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800550 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700551 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700552
Pengquan Menga1bb6272018-09-06 09:59:22 -0700553 if (!isUssdApiAllowed(request.subId)) {
554 // Carrier does not support use of this API, return failure.
555 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
556 UssdResponse response = new UssdResponse(ussdRequest, null);
557 Bundle returnData = new Bundle();
558 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
559 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700560
Pengquan Menga1bb6272018-09-06 09:59:22 -0700561 request.result = true;
562 notifyRequester(request);
563 return;
564 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700565
Pengquan Menga1bb6272018-09-06 09:59:22 -0700566 try {
567 request.result = phone != null
568 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
569 } catch (CallStateException cse) {
570 request.result = false;
571 }
572 // Wake up the requesting thread
573 notifyRequester(request);
574 break;
pkanwar32d516d2016-10-14 19:37:38 -0700575 }
576
Yorke Lee716f67e2015-06-17 15:39:16 -0700577 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700578 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700579 final Phone phone = getPhoneFromRequest(request);
580 request.result = phone != null ?
581 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
582 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700583 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700584 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700585 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700586 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700587
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700588 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700589 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700590 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000591 uiccPort = getUiccPortFromRequest(request);
592 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700593 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800594 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700595 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700596 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700597 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800598 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000599 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800600 iccArgument.channel, iccArgument.cla, iccArgument.command,
601 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
602 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700603 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700604 break;
605
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700606 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700607 ar = (AsyncResult) msg.obj;
608 request = (MainThreadRequest) ar.userObj;
609 if (ar.exception == null && ar.result != null) {
610 request.result = ar.result;
611 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800612 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700613 if (ar.result == null) {
614 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800615 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700616 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800617 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700618 } else {
619 loge("iccTransmitApduLogicalChannel: Unknown exception");
620 }
621 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700622 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700623 break;
624
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700625 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
626 request = (MainThreadRequest) msg.obj;
627 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000628 uiccPort = getUiccPortFromRequest(request);
629 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700630 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800631 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700632 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700633 } else {
634 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800635 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000636 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800637 iccArgument.cla, iccArgument.command, iccArgument.p1,
638 iccArgument.p2,
639 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700640 }
641 break;
642
643 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
644 ar = (AsyncResult) msg.obj;
645 request = (MainThreadRequest) ar.userObj;
646 if (ar.exception == null && ar.result != null) {
647 request.result = ar.result;
648 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800649 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700650 if (ar.result == null) {
651 loge("iccTransmitApduBasicChannel: Empty response");
652 } else if (ar.exception instanceof CommandException) {
653 loge("iccTransmitApduBasicChannel: CommandException: " +
654 ar.exception);
655 } else {
656 loge("iccTransmitApduBasicChannel: Unknown exception");
657 }
658 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700659 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700660 break;
661
662 case CMD_EXCHANGE_SIM_IO:
663 request = (MainThreadRequest) msg.obj;
664 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000665 uiccPort = getUiccPortFromRequest(request);
666 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700667 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800668 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700669 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700670 } else {
671 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
672 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000673 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700674 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
675 iccArgument.data, onCompleted);
676 }
677 break;
678
679 case EVENT_EXCHANGE_SIM_IO_DONE:
680 ar = (AsyncResult) msg.obj;
681 request = (MainThreadRequest) ar.userObj;
682 if (ar.exception == null && ar.result != null) {
683 request.result = ar.result;
684 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800685 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700686 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700687 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700688 break;
689
Derek Tan4d5e5c12014-02-04 11:54:58 -0800690 case CMD_SEND_ENVELOPE:
691 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000692 uiccPort = getUiccPortFromRequest(request);
693 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700694 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800695 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700696 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700697 } else {
698 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800699 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700700 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800701 break;
702
703 case EVENT_SEND_ENVELOPE_DONE:
704 ar = (AsyncResult) msg.obj;
705 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700706 if (ar.exception == null && ar.result != null) {
707 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800708 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800709 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700710 if (ar.result == null) {
711 loge("sendEnvelopeWithStatus: Empty response");
712 } else if (ar.exception instanceof CommandException) {
713 loge("sendEnvelopeWithStatus: CommandException: " +
714 ar.exception);
715 } else {
716 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
717 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800718 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700719 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800720 break;
721
Shishir Agrawal566b7612013-10-28 14:41:00 -0700722 case CMD_OPEN_CHANNEL:
723 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000724 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800725 IccLogicalChannelRequest openChannelRequest =
726 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000727 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700728 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800729 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800730 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700731 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700732 } else {
733 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800734 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
735 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700736 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700737 break;
738
739 case EVENT_OPEN_CHANNEL_DONE:
740 ar = (AsyncResult) msg.obj;
741 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700742 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700743 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700744 int[] result = (int[]) ar.result;
745 int channelId = result[0];
746 byte[] selectResponse = null;
747 if (result.length > 1) {
748 selectResponse = new byte[result.length - 1];
749 for (int i = 1; i < result.length; ++i) {
750 selectResponse[i - 1] = (byte) result[i];
751 }
752 }
753 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800754 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800755
756 uiccPort = getUiccPortFromRequest(request);
757 IccLogicalChannelRequest channelRequest =
758 (IccLogicalChannelRequest) request.argument;
759 channelRequest.channel = channelId;
760 uiccPort.onLogicalChannelOpened(channelRequest);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700761 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700762 if (ar.result == null) {
763 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700764 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700765 if (ar.exception != null) {
766 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
767 }
768
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700769 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700770 if (ar.exception instanceof CommandException) {
771 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800772 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700773 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700774 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700775 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700776 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700777 }
778 }
779 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800780 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700781 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700782 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700783 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700784 break;
785
786 case CMD_CLOSE_CHANNEL:
787 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000788 uiccPort = getUiccPortFromRequest(request);
789 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700790 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800791 request.result = new IllegalArgumentException(
Chen Xue9d737e2022-01-01 23:41:31 -0800792 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800793 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700794 } else {
795 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000796 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700797 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700798 break;
799
800 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800801 ar = (AsyncResult) msg.obj;
802 request = (MainThreadRequest) ar.userObj;
803 if (ar.exception == null) {
804 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800805 uiccPort = getUiccPortFromRequest(request);
806 final int channelId = (Integer) request.argument;
807 uiccPort.onLogicalChannelClosed(channelId);
Chen Xu540470b2021-12-14 17:15:47 -0800808 } else {
809 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800810 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800811 if (ar.exception instanceof CommandException) {
812 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
813 CommandException.Error error =
814 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800815 if (error == CommandException.Error.INVALID_ARGUMENTS) {
816 // should only throw exceptions from the binder threads.
817 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800818 "iccCloseLogicalChannel: invalid argument ");
819 }
820 } else {
821 loge("iccCloseLogicalChannel: Unknown exception");
822 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800823 request.result = (exception != null) ? exception :
824 new IllegalStateException(
825 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800826 }
827 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800828 break;
829
830 case CMD_NV_READ_ITEM:
831 request = (MainThreadRequest) msg.obj;
832 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800833 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
834 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800835 break;
836
837 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700838 ar = (AsyncResult) msg.obj;
839 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800840 if (ar.exception == null && ar.result != null) {
841 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700842 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800843 request.result = "";
844 if (ar.result == null) {
845 loge("nvReadItem: Empty response");
846 } else if (ar.exception instanceof CommandException) {
847 loge("nvReadItem: CommandException: " +
848 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700849 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800850 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700851 }
852 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700853 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700854 break;
855
Jake Hambye994d462014-02-03 13:10:13 -0800856 case CMD_NV_WRITE_ITEM:
857 request = (MainThreadRequest) msg.obj;
858 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
859 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800860 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700861 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800862 break;
863
864 case EVENT_NV_WRITE_ITEM_DONE:
865 handleNullReturnEvent(msg, "nvWriteItem");
866 break;
867
868 case CMD_NV_WRITE_CDMA_PRL:
869 request = (MainThreadRequest) msg.obj;
870 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800871 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800872 break;
873
874 case EVENT_NV_WRITE_CDMA_PRL_DONE:
875 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
876 break;
877
chen xu6dac5ab2018-10-26 17:39:23 -0700878 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800879 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700880 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800881 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800882 break;
883
chen xu6dac5ab2018-10-26 17:39:23 -0700884 case EVENT_RESET_MODEM_CONFIG_DONE:
885 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800886 break;
887
Sooraj Sasindran37444802020-08-11 10:40:43 -0700888 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
889 request = (MainThreadRequest) msg.obj;
890 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
891 request);
892 Phone phone = getPhoneFromRequest(request);
893 if (phone != null) {
894 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
895 } else {
896 loge("isNRDualConnectivityEnabled: No phone object");
897 request.result = false;
898 notifyRequester(request);
899 }
900 break;
901 }
902
903 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
904 ar = (AsyncResult) msg.obj;
905 request = (MainThreadRequest) ar.userObj;
906 if (ar.exception == null && ar.result != null) {
907 request.result = ar.result;
908 } else {
909 // request.result must be set to something non-null
910 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700911 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700912 request.result = ar.result;
913 } else {
914 request.result = false;
915 }
916 if (ar.result == null) {
917 loge("isNRDualConnectivityEnabled: Empty response");
918 } else if (ar.exception instanceof CommandException) {
919 loge("isNRDualConnectivityEnabled: CommandException: "
920 + ar.exception);
921 } else {
922 loge("isNRDualConnectivityEnabled: Unknown exception");
923 }
924 }
925 notifyRequester(request);
926 break;
927
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700928 case CMD_IS_VONR_ENABLED: {
929 request = (MainThreadRequest) msg.obj;
930 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
931 request);
932 Phone phone = getPhoneFromRequest(request);
933 if (phone != null) {
934 phone.isVoNrEnabled(onCompleted, request.workSource);
935 } else {
936 loge("isVoNrEnabled: No phone object");
937 request.result = false;
938 notifyRequester(request);
939 }
940 break;
941 }
942
943 case EVENT_IS_VONR_ENABLED_DONE:
944 ar = (AsyncResult) msg.obj;
945 request = (MainThreadRequest) ar.userObj;
946 if (ar.exception == null && ar.result != null) {
947 request.result = ar.result;
948 } else {
949 // request.result must be set to something non-null
950 // for the calling thread to unblock
951 if (ar.result != null) {
952 request.result = ar.result;
953 } else {
954 request.result = false;
955 }
956 if (ar.result == null) {
957 loge("isVoNrEnabled: Empty response");
958 } else if (ar.exception instanceof CommandException) {
959 loge("isVoNrEnabled: CommandException: "
960 + ar.exception);
961 } else {
962 loge("isVoNrEnabled: Unknown exception");
963 }
964 }
965 notifyRequester(request);
966 break;
967
Sooraj Sasindran37444802020-08-11 10:40:43 -0700968 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
969 request = (MainThreadRequest) msg.obj;
970 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
971 Phone phone = getPhoneFromRequest(request);
972 if (phone != null) {
973 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
974 request.workSource);
975 } else {
976 loge("enableNrDualConnectivity: No phone object");
977 request.result =
978 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
979 notifyRequester(request);
980 }
981 break;
982 }
983
984 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
985 ar = (AsyncResult) msg.obj;
986 request = (MainThreadRequest) ar.userObj;
987 if (ar.exception == null) {
988 request.result =
989 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
990 } else {
991 request.result =
992 TelephonyManager
993 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
994 if (ar.exception instanceof CommandException) {
995 CommandException.Error error =
996 ((CommandException) (ar.exception)).getCommandError();
997 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
998 request.result =
999 TelephonyManager
1000 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001001 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1002 request.result =
1003 TelephonyManager
1004 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001005 }
1006 loge("enableNrDualConnectivity" + ": CommandException: "
1007 + ar.exception);
1008 } else {
1009 loge("enableNrDualConnectivity" + ": Unknown exception");
1010 }
1011 }
1012 notifyRequester(request);
1013 break;
1014 }
1015
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001016 case CMD_ENABLE_VONR: {
1017 request = (MainThreadRequest) msg.obj;
1018 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1019 Phone phone = getPhoneFromRequest(request);
1020 if (phone != null) {
1021 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1022 request.workSource);
1023 } else {
1024 loge("setVoNrEnabled: No phone object");
1025 request.result =
1026 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1027 notifyRequester(request);
1028 }
1029 break;
1030 }
1031
1032 case EVENT_ENABLE_VONR_DONE: {
1033 ar = (AsyncResult) msg.obj;
1034 request = (MainThreadRequest) ar.userObj;
1035 if (ar.exception == null) {
1036 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1037 } else {
1038 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1039 if (ar.exception instanceof CommandException) {
1040 CommandException.Error error =
1041 ((CommandException) (ar.exception)).getCommandError();
1042 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1043 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1044 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1045 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1046 } else {
1047 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1048 }
1049 loge("setVoNrEnabled" + ": CommandException: "
1050 + ar.exception);
1051 } else {
1052 loge("setVoNrEnabled" + ": Unknown exception");
1053 }
1054 }
1055 notifyRequester(request);
1056 break;
1057 }
1058
SongFerngWang3ef3e072020-12-21 16:41:52 +08001059 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001060 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001061 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1062 request);
1063 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001064 break;
1065
SongFerngWang3ef3e072020-12-21 16:41:52 +08001066 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001067 ar = (AsyncResult) msg.obj;
1068 request = (MainThreadRequest) ar.userObj;
1069 if (ar.exception == null && ar.result != null) {
1070 request.result = ar.result; // Integer
1071 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301072 // request.result must be set to something non-null
1073 // for the calling thread to unblock
1074 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001075 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001076 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001077 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001078 loge("getAllowedNetworkTypesBitmask: CommandException: "
1079 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001080 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001081 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001082 }
1083 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001084 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001085 break;
1086
SongFerngWang3ef3e072020-12-21 16:41:52 +08001087 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001088 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001089 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1090 request);
1091 Pair<Integer, Long> reasonWithNetworkTypes =
1092 (Pair<Integer, Long>) request.argument;
1093 getPhoneFromRequest(request).setAllowedNetworkTypes(
1094 reasonWithNetworkTypes.first,
1095 reasonWithNetworkTypes.second,
1096 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001097 break;
1098
SongFerngWang3ef3e072020-12-21 16:41:52 +08001099 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1100 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001101 break;
1102
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001103 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1104 request = (MainThreadRequest)msg.obj;
1105 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001106 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001107 break;
1108
1109 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1110 ar = (AsyncResult)msg.obj;
1111 request = (MainThreadRequest)ar.userObj;
1112 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001113 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001114 break;
1115
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001116 case CMD_SET_VOICEMAIL_NUMBER:
1117 request = (MainThreadRequest) msg.obj;
1118 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1119 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001120 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1121 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001122 break;
1123
1124 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1125 handleNullReturnEvent(msg, "setVoicemailNumber");
1126 break;
1127
Stuart Scott54788802015-03-30 13:18:01 -07001128 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1129 request = (MainThreadRequest) msg.obj;
1130 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1131 request);
1132 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1133 break;
1134
1135 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1136 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1137 break;
1138
Shishir Agrawal302c8692015-06-19 13:49:39 -07001139 case CMD_PERFORM_NETWORK_SCAN:
1140 request = (MainThreadRequest) msg.obj;
1141 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1142 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1143 break;
1144
Hall Liu27d24262020-09-18 19:04:59 -07001145 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001146 request = (MainThreadRequest) msg.obj;
1147 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001148 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1149 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1150 request.argument;
1151 int callForwardingReason = args.first;
1152 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001153 break;
Hall Liu27d24262020-09-18 19:04:59 -07001154 }
1155 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001156 ar = (AsyncResult) msg.obj;
1157 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001158 TelephonyManager.CallForwardingInfoCallback callback =
1159 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1160 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001161 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001162 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001163 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1164 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1165 // Service Class is a bit mask per 3gpp 27.007. Search for
1166 // any service for voice call.
1167 if ((callForwardInfo.serviceClass
1168 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001169 callForwardingInfo = new CallForwardingInfo(
1170 callForwardInfo.status
1171 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001172 callForwardInfo.reason,
1173 callForwardInfo.number,
1174 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001175 break;
1176 }
1177 }
1178 // Didn't find a call forward info for voice call.
1179 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001180 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1181 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001182 }
Hall Liu27d24262020-09-18 19:04:59 -07001183 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001184 } else {
1185 if (ar.result == null) {
1186 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1187 }
1188 if (ar.exception != null) {
1189 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1190 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001191 int errorCode = TelephonyManager
1192 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001193 if (ar.exception instanceof CommandException) {
1194 CommandException.Error error =
1195 ((CommandException) (ar.exception)).getCommandError();
1196 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001197 errorCode = TelephonyManager
1198 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001199 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001200 errorCode = TelephonyManager
1201 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001202 }
1203 }
Hall Liu27d24262020-09-18 19:04:59 -07001204 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001205 }
Shuo Qian4a594052020-01-23 11:59:30 -08001206 break;
Hall Liu27d24262020-09-18 19:04:59 -07001207 }
Shuo Qian4a594052020-01-23 11:59:30 -08001208
Hall Liu27d24262020-09-18 19:04:59 -07001209 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001210 request = (MainThreadRequest) msg.obj;
1211 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001212 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001213 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001214 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1215 request.argument).first;
1216 request.phone.setCallForwardingOption(
1217 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001218 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001219 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001220 callForwardingInfoToSet.getReason(),
1221 callForwardingInfoToSet.getNumber(),
1222 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1223 break;
Hall Liu27d24262020-09-18 19:04:59 -07001224 }
Shuo Qian4a594052020-01-23 11:59:30 -08001225
Hall Liu27d24262020-09-18 19:04:59 -07001226 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001227 ar = (AsyncResult) msg.obj;
1228 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001229 Consumer<Integer> callback =
1230 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1231 request.argument).second;
1232 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001233 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001234 int errorCode = TelephonyManager.CallForwardingInfoCallback
1235 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001236 if (ar.exception instanceof CommandException) {
1237 CommandException.Error error =
1238 ((CommandException) (ar.exception)).getCommandError();
1239 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001240 errorCode = TelephonyManager.CallForwardingInfoCallback
1241 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001242 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001243 errorCode = TelephonyManager.CallForwardingInfoCallback
1244 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001245 }
1246 }
1247 callback.accept(errorCode);
1248 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001249 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001250 }
Shuo Qian4a594052020-01-23 11:59:30 -08001251 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 CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001255 request = (MainThreadRequest) msg.obj;
1256 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1257 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1258 break;
Hall Liu27d24262020-09-18 19:04:59 -07001259 }
Shuo Qian4a594052020-01-23 11:59:30 -08001260
Hall Liu27d24262020-09-18 19:04:59 -07001261 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001262 ar = (AsyncResult) msg.obj;
1263 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001264 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001265 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001266 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001267 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001268 // Service Class is a bit mask per 3gpp 27.007.
1269 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001270 if (callForwardResults.length > 1
1271 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001272 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001273 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001274 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1275 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001276 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001277 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001278 }
1279 } else {
1280 if (ar.result == null) {
1281 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1282 }
1283 if (ar.exception != null) {
1284 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1285 }
1286 if (ar.exception instanceof CommandException) {
1287 CommandException.Error error =
1288 ((CommandException) (ar.exception)).getCommandError();
1289 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001290 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001291 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001292 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1293 callWaitingStatus =
1294 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001295 }
1296 }
1297 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001298 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001299 break;
Hall Liu27d24262020-09-18 19:04:59 -07001300 }
Shuo Qian4a594052020-01-23 11:59:30 -08001301
Hall Liu27d24262020-09-18 19:04:59 -07001302 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001303 request = (MainThreadRequest) msg.obj;
1304 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001305 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1306 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001307 break;
Hall Liu27d24262020-09-18 19:04:59 -07001308 }
Shuo Qian4a594052020-01-23 11:59:30 -08001309
Hall Liu27d24262020-09-18 19:04:59 -07001310 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001311 ar = (AsyncResult) msg.obj;
1312 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001313 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1314 Consumer<Integer> callback =
1315 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1316 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001317 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001318 if (ar.exception instanceof CommandException) {
1319 CommandException.Error error =
1320 ((CommandException) (ar.exception)).getCommandError();
1321 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1322 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001323 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1324 callback.accept(
1325 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001326 } else {
1327 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1328 }
1329 } else {
1330 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1331 }
1332 } else {
1333 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1334 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001335 }
Shuo Qian4a594052020-01-23 11:59:30 -08001336 break;
Hall Liu27d24262020-09-18 19:04:59 -07001337 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001338 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1339 ar = (AsyncResult) msg.obj;
1340 request = (MainThreadRequest) ar.userObj;
1341 CellNetworkScanResult cellScanResult;
1342 if (ar.exception == null && ar.result != null) {
1343 cellScanResult = new CellNetworkScanResult(
1344 CellNetworkScanResult.STATUS_SUCCESS,
1345 (List<OperatorInfo>) ar.result);
1346 } else {
1347 if (ar.result == null) {
1348 loge("getCellNetworkScanResults: Empty response");
1349 }
1350 if (ar.exception != null) {
1351 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1352 }
1353 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1354 if (ar.exception instanceof CommandException) {
1355 CommandException.Error error =
1356 ((CommandException) (ar.exception)).getCommandError();
1357 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1358 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1359 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1360 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1361 }
1362 }
1363 cellScanResult = new CellNetworkScanResult(errorCode, null);
1364 }
1365 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001366 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001367 break;
1368
1369 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1370 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001371 ManualNetworkSelectionArgument selArg =
1372 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001373 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1374 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001375 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1376 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001377 break;
1378
1379 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001380 ar = (AsyncResult) msg.obj;
1381 request = (MainThreadRequest) ar.userObj;
1382 if (ar.exception == null) {
1383 request.result = true;
1384 } else {
1385 request.result = false;
1386 loge("setNetworkSelectionModeManual " + ar.exception);
1387 }
1388 notifyRequester(request);
1389 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001390 break;
1391
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001392 case CMD_GET_MODEM_ACTIVITY_INFO:
1393 request = (MainThreadRequest) msg.obj;
1394 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001395 if (defaultPhone != null) {
1396 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001397 } else {
1398 ResultReceiver result = (ResultReceiver) request.argument;
1399 Bundle bundle = new Bundle();
1400 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001401 new ModemActivityInfo(0, 0, 0,
1402 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001403 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001404 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001405 break;
1406
Hall Liud0f208c2020-10-14 16:54:44 -07001407 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001408 ar = (AsyncResult) msg.obj;
1409 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001410 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001411 int error = 0;
Gary Jian3aa9a762022-01-24 16:41:19 +08001412 if (mLastModemActivityInfo == null) {
1413 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1414 mLastModemActivitySpecificInfo[0] =
1415 new ActivityStatsTechSpecificInfo(
1416 0,
1417 0,
1418 new int[ModemActivityInfo.getNumTxPowerLevels()],
1419 0);
1420 mLastModemActivityInfo =
1421 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1422 }
1423
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001424 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001425 // Update the last modem activity info and the result of the request.
1426 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1427 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001428 mergeModemActivityInfo(info);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001429 }
Gary Jian3aa9a762022-01-24 16:41:19 +08001430 mLastModemActivityInfo =
1431 new ModemActivityInfo(
1432 mLastModemActivityInfo.getTimestampMillis(),
1433 mLastModemActivityInfo.getSleepTimeMillis(),
1434 mLastModemActivityInfo.getIdleTimeMillis(),
1435 mLastModemActivitySpecificInfo);
1436
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001437 } else {
1438 if (ar.result == null) {
1439 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001440 error = TelephonyManager.ModemActivityInfoException
1441 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001442 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001443 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001444 error = TelephonyManager.ModemActivityInfoException
1445 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001446 } else {
1447 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001448 error = TelephonyManager.ModemActivityInfoException
1449 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001450 }
1451 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001452 Bundle bundle = new Bundle();
Gary Jian3aa9a762022-01-24 16:41:19 +08001453 if (mLastModemActivityInfo != null) {
1454 bundle.putParcelable(
1455 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1456 mLastModemActivityInfo);
Hall Liud0f208c2020-10-14 16:54:44 -07001457 } else {
1458 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1459 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001460 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001461 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001462 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001463 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001464
Meng Wang1a7c35a2016-05-05 20:56:15 -07001465 case CMD_SET_ALLOWED_CARRIERS:
1466 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001467 CarrierRestrictionRules argument =
1468 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001469 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001470 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001471 break;
1472
1473 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1474 ar = (AsyncResult) msg.obj;
1475 request = (MainThreadRequest) ar.userObj;
1476 if (ar.exception == null && ar.result != null) {
1477 request.result = ar.result;
1478 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001479 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1480 if (ar.exception instanceof CommandException) {
1481 loge("setAllowedCarriers: CommandException: " + ar.exception);
1482 CommandException.Error error =
1483 ((CommandException) (ar.exception)).getCommandError();
1484 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1485 request.result =
1486 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1487 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001488 } else {
1489 loge("setAllowedCarriers: Unknown exception");
1490 }
1491 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001492 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001493 break;
1494
1495 case CMD_GET_ALLOWED_CARRIERS:
1496 request = (MainThreadRequest) msg.obj;
1497 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001498 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001499 break;
1500
1501 case EVENT_GET_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 = new IllegalStateException(
1508 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001509 if (ar.result == null) {
1510 loge("getAllowedCarriers: Empty response");
1511 } else if (ar.exception instanceof CommandException) {
1512 loge("getAllowedCarriers: CommandException: " +
1513 ar.exception);
1514 } else {
1515 loge("getAllowedCarriers: Unknown exception");
1516 }
1517 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001518 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001519 break;
1520
Nathan Haroldb3014052017-01-25 15:57:32 -08001521 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1522 ar = (AsyncResult) msg.obj;
1523 request = (MainThreadRequest) ar.userObj;
1524 if (ar.exception == null && ar.result != null) {
1525 request.result = ar.result;
1526 } else {
1527 request.result = new IllegalArgumentException(
1528 "Failed to retrieve Forbidden Plmns");
1529 if (ar.result == null) {
1530 loge("getForbiddenPlmns: Empty response");
1531 } else {
1532 loge("getForbiddenPlmns: Unknown exception");
1533 }
1534 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001535 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001536 break;
1537
1538 case CMD_GET_FORBIDDEN_PLMNS:
1539 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001540 uiccPort = getUiccPortFromRequest(request);
1541 if (uiccPort == null) {
1542 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001543 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001544 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001545 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001546 break;
1547 }
1548 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001549 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001550 if (uiccApp == null) {
1551 loge("getForbiddenPlmns() no app with specified type -- "
1552 + appType);
1553 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001554 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001555 break;
1556 } else {
1557 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1558 + " specified type -- " + appType);
1559 }
1560 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1561 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1562 onCompleted);
1563 break;
1564
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001565 case CMD_SWITCH_SLOTS:
1566 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001567 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001568 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001569 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001570 break;
1571
1572 case EVENT_SWITCH_SLOTS_DONE:
1573 ar = (AsyncResult) msg.obj;
1574 request = (MainThreadRequest) ar.userObj;
1575 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001576 notifyRequester(request);
1577 break;
1578 case CMD_GET_NETWORK_SELECTION_MODE:
1579 request = (MainThreadRequest) msg.obj;
1580 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1581 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1582 break;
1583
1584 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1585 ar = (AsyncResult) msg.obj;
1586 request = (MainThreadRequest) ar.userObj;
1587 if (ar.exception != null) {
1588 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1589 } else {
1590 int mode = ((int[]) ar.result)[0];
1591 if (mode == 0) {
1592 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1593 } else {
1594 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1595 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001596 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001597 notifyRequester(request);
1598 break;
1599 case CMD_GET_CDMA_ROAMING_MODE:
1600 request = (MainThreadRequest) msg.obj;
1601 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1602 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1603 break;
1604 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1605 ar = (AsyncResult) msg.obj;
1606 request = (MainThreadRequest) ar.userObj;
1607 if (ar.exception != null) {
1608 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1609 } else {
1610 request.result = ((int[]) ar.result)[0];
1611 }
1612 notifyRequester(request);
1613 break;
1614 case CMD_SET_CDMA_ROAMING_MODE:
1615 request = (MainThreadRequest) msg.obj;
1616 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1617 int mode = (int) request.argument;
1618 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1619 break;
1620 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1621 ar = (AsyncResult) msg.obj;
1622 request = (MainThreadRequest) ar.userObj;
1623 request.result = ar.exception == null;
1624 notifyRequester(request);
1625 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001626 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1627 request = (MainThreadRequest) msg.obj;
1628 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1629 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1630 break;
1631 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1632 ar = (AsyncResult) msg.obj;
1633 request = (MainThreadRequest) ar.userObj;
1634 if (ar.exception != null) {
1635 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1636 } else {
1637 request.result = ((int[]) ar.result)[0];
1638 }
1639 notifyRequester(request);
1640 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001641 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1642 request = (MainThreadRequest) msg.obj;
1643 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1644 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001645 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1646 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001647 break;
1648 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1649 ar = (AsyncResult) msg.obj;
1650 request = (MainThreadRequest) ar.userObj;
1651 request.result = ar.exception == null;
1652 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001653 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001654 case CMD_GET_ALL_CELL_INFO:
1655 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001656 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001657 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001658 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001659 case EVENT_GET_ALL_CELL_INFO_DONE:
1660 ar = (AsyncResult) msg.obj;
1661 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001662 // If a timeout occurs, the response will be null
1663 request.result = (ar.exception == null && ar.result != null)
1664 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001665 synchronized (request) {
1666 request.notifyAll();
1667 }
1668 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001669 case CMD_REQUEST_CELL_INFO_UPDATE:
1670 request = (MainThreadRequest) msg.obj;
1671 request.phone.requestCellInfoUpdate(request.workSource,
1672 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1673 break;
1674 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1675 ar = (AsyncResult) msg.obj;
1676 request = (MainThreadRequest) ar.userObj;
1677 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1678 try {
1679 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001680 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001681 cb.onError(
1682 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1683 ar.exception.getClass().getName(),
1684 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001685 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001686 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001687 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001688 } else {
1689 // use the result as returned
1690 cb.onCellInfo((List<CellInfo>) ar.result);
1691 }
1692 } catch (RemoteException re) {
1693 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1694 }
1695 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001696 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001697 request = (MainThreadRequest) msg.obj;
1698 WorkSource ws = (WorkSource) request.argument;
1699 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001700 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001701 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001702 }
1703 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001704 ar = (AsyncResult) msg.obj;
1705 request = (MainThreadRequest) ar.userObj;
1706 if (ar.exception == null) {
1707 request.result = ar.result;
1708 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001709 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001710 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001711 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001712 }
1713
1714 synchronized (request) {
1715 request.notifyAll();
1716 }
1717 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001718 }
chen xu6dac5ab2018-10-26 17:39:23 -07001719 case CMD_MODEM_REBOOT:
1720 request = (MainThreadRequest) msg.obj;
1721 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001722 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001723 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001724 case EVENT_CMD_MODEM_REBOOT_DONE:
1725 handleNullReturnEvent(msg, "rebootModem");
1726 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001727 case CMD_REQUEST_ENABLE_MODEM:
1728 request = (MainThreadRequest) msg.obj;
1729 boolean enable = (boolean) request.argument;
1730 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001731 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001732 PhoneConfigurationManager.getInstance()
1733 .enablePhone(request.phone, enable, onCompleted);
1734 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001735 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001736 ar = (AsyncResult) msg.obj;
1737 request = (MainThreadRequest) ar.userObj;
1738 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001739 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001740 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001741 if ((boolean) request.result) {
1742 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1743 updateModemStateMetrics();
1744 } else {
1745 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1746 + ar.exception);
1747 }
1748 notifyRequester(request);
1749 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001750 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001751 case CMD_GET_MODEM_STATUS:
1752 request = (MainThreadRequest) msg.obj;
1753 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1754 PhoneConfigurationManager.getInstance()
1755 .getPhoneStatusFromModem(request.phone, onCompleted);
1756 break;
1757 case EVENT_GET_MODEM_STATUS_DONE:
1758 ar = (AsyncResult) msg.obj;
1759 request = (MainThreadRequest) ar.userObj;
1760 int id = request.phone.getPhoneId();
1761 if (ar.exception == null && ar.result != null) {
1762 request.result = ar.result;
1763 //update the cache as modem status has changed
1764 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1765 (boolean) request.result);
1766 } else {
1767 // Return true if modem status cannot be retrieved. For most cases,
1768 // modem status is on. And for older version modems, GET_MODEM_STATUS
1769 // and disable modem are not supported. Modem is always on.
1770 // TODO: this should be fixed in R to support a third
1771 // status UNKNOWN b/131631629
1772 request.result = true;
1773 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1774 + ar.exception);
1775 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001776 notifyRequester(request);
1777 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001778 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1779 request = (MainThreadRequest) msg.obj;
1780 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1781 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1782 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1783 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1784 break;
1785 }
1786 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1787 ar = (AsyncResult) msg.obj;
1788 request = (MainThreadRequest) ar.userObj;
1789 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1790 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1791 args.second.accept(ar.exception == null);
1792 notifyRequester(request);
1793 break;
1794 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001795 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1796 request = (MainThreadRequest) msg.obj;
1797 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1798 Phone phone = getPhoneFromRequest(request);
1799 if (phone != null) {
1800 phone.getSystemSelectionChannels(onCompleted);
1801 } else {
1802 loge("getSystemSelectionChannels: No phone object");
1803 request.result = new ArrayList<RadioAccessSpecifier>();
1804 notifyRequester(request);
1805 }
1806 break;
1807 }
1808 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1809 ar = (AsyncResult) msg.obj;
1810 request = (MainThreadRequest) ar.userObj;
1811 if (ar.exception == null && ar.result != null) {
1812 request.result = ar.result;
1813 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001814 request.result = new IllegalStateException(
1815 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001816 if (ar.result == null) {
1817 loge("getSystemSelectionChannels: Empty response");
1818 } else {
1819 loge("getSystemSelectionChannels: Unknown exception");
1820 }
1821 }
1822 notifyRequester(request);
1823 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001824 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1825 ar = (AsyncResult) msg.obj;
1826 request = (MainThreadRequest) ar.userObj;
1827 if (ar.exception == null && ar.result != null) {
1828 request.result = ar.result;
1829 } else {
1830 request.result = -1;
1831 loge("Failed to set Forbidden Plmns");
1832 if (ar.result == null) {
1833 loge("setForbidenPlmns: Empty response");
1834 } else if (ar.exception != null) {
1835 loge("setForbiddenPlmns: Exception: " + ar.exception);
1836 request.result = -1;
1837 } else {
1838 loge("setForbiddenPlmns: Unknown exception");
1839 }
1840 }
1841 notifyRequester(request);
1842 break;
1843 case CMD_SET_FORBIDDEN_PLMNS:
1844 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001845 uiccPort = getUiccPortFromRequest(request);
1846 if (uiccPort == null) {
1847 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001848 request.result = -1;
1849 notifyRequester(request);
1850 break;
1851 }
1852 Pair<Integer, List<String>> setFplmnsArgs =
1853 (Pair<Integer, List<String>>) request.argument;
1854 appType = setFplmnsArgs.first;
1855 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001856 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001857 if (uiccApp == null) {
1858 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1859 request.result = -1;
1860 loge("Failed to get UICC App");
1861 notifyRequester(request);
1862 } else {
1863 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1864 ((SIMRecords) uiccApp.getIccRecords())
1865 .setForbiddenPlmns(onCompleted, fplmns);
1866 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001867 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001868 case CMD_ERASE_MODEM_CONFIG:
1869 request = (MainThreadRequest) msg.obj;
1870 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1871 defaultPhone.eraseModemConfig(onCompleted);
1872 break;
1873 case EVENT_ERASE_MODEM_CONFIG_DONE:
1874 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001875 break;
zoey chene02881a2019-12-30 16:11:23 +08001876
Kai Shif70f46f2021-03-03 13:59:46 -08001877 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1878 request = (MainThreadRequest) msg.obj;
1879 request.result = defaultPhone.eraseDataInSharedPreferences();
1880 notifyRequester(request);
1881 break;
1882
zoey chene02881a2019-12-30 16:11:23 +08001883 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1884 request = (MainThreadRequest) msg.obj;
1885 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1886 Pair<String, String> changed = (Pair<String, String>) request.argument;
1887 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1888 changed.first, changed.second, onCompleted);
1889 break;
1890 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1891 ar = (AsyncResult) msg.obj;
1892 request = (MainThreadRequest) ar.userObj;
1893 if (ar.exception == null) {
1894 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001895 // If the operation is successful, update the PIN storage
1896 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1897 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001898 UiccController.getInstance().getPinStorage()
1899 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001900 } else {
1901 request.result = msg.arg1;
1902 }
1903 notifyRequester(request);
1904 break;
1905
Michele Berionne5e411512020-11-13 02:36:59 +00001906 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001907 request = (MainThreadRequest) msg.obj;
1908 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1909 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1910 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1911 enabled.first, enabled.second, onCompleted);
1912 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001913 }
zoey chene02881a2019-12-30 16:11:23 +08001914 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1915 ar = (AsyncResult) msg.obj;
1916 request = (MainThreadRequest) ar.userObj;
1917 if (ar.exception == null) {
1918 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001919 // If the operation is successful, update the PIN storage
1920 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1921 int phoneId = getPhoneFromRequest(request).getPhoneId();
1922 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001923 UiccController.getInstance().getPinStorage()
1924 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001925 } else {
1926 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1927 }
zoey chene02881a2019-12-30 16:11:23 +08001928 } else {
1929 request.result = msg.arg1;
1930 }
Michele Berionne5e411512020-11-13 02:36:59 +00001931
1932
zoey chene02881a2019-12-30 16:11:23 +08001933 notifyRequester(request);
1934 break;
1935
Peter Wangdafb9ac2020-01-15 14:13:38 -08001936 case MSG_NOTIFY_USER_ACTIVITY:
1937 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001938 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001939 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1940 getDefaultPhone().getContext().sendBroadcastAsUser(
1941 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1942 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001943
1944 case CMD_SET_DATA_THROTTLING: {
1945 request = (MainThreadRequest) msg.obj;
1946 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1947 DataThrottlingRequest dataThrottlingRequest =
1948 (DataThrottlingRequest) request.argument;
1949 Phone phone = getPhoneFromRequest(request);
1950 if (phone != null) {
1951 phone.setDataThrottling(onCompleted,
1952 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1953 dataThrottlingRequest.getCompletionDurationMillis());
1954 } else {
1955 loge("setDataThrottling: No phone object");
1956 request.result =
1957 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1958 notifyRequester(request);
1959 }
1960
1961 break;
1962 }
1963 case EVENT_SET_DATA_THROTTLING_DONE:
1964 ar = (AsyncResult) msg.obj;
1965 request = (MainThreadRequest) ar.userObj;
1966
1967 if (ar.exception == null) {
1968 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1969 } else if (ar.exception instanceof CommandException) {
1970 loge("setDataThrottling: CommandException: " + ar.exception);
1971 CommandException.Error error =
1972 ((CommandException) (ar.exception)).getCommandError();
1973
1974 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1975 request.result = TelephonyManager
1976 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1977 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1978 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001979 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1980 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001981 } else {
1982 request.result =
1983 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1984 }
1985 } else {
1986 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1987 }
1988 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1989 notifyRequester(request);
1990 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001991
1992 case CMD_SET_SIM_POWER: {
1993 request = (MainThreadRequest) msg.obj;
1994 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1995 request = (MainThreadRequest) msg.obj;
1996 int stateToSet =
1997 ((Pair<Integer, IIntegerConsumer>)
1998 request.argument).first;
1999 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2000 break;
2001 }
2002 case EVENT_SET_SIM_POWER_DONE: {
2003 ar = (AsyncResult) msg.obj;
2004 request = (MainThreadRequest) ar.userObj;
2005 IIntegerConsumer callback =
2006 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2007 if (ar.exception != null) {
2008 loge("setSimPower exception: " + ar.exception);
2009 int errorCode = TelephonyManager.CallForwardingInfoCallback
2010 .RESULT_ERROR_UNKNOWN;
2011 if (ar.exception instanceof CommandException) {
2012 CommandException.Error error =
2013 ((CommandException) (ar.exception)).getCommandError();
2014 if (error == CommandException.Error.SIM_ERR) {
2015 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2016 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2017 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2018 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2019 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2020 } else {
2021 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2022 }
2023 }
2024 try {
2025 callback.accept(errorCode);
2026 } catch (RemoteException e) {
2027 // Ignore if the remote process is no longer available to call back.
2028 Log.w(LOG_TAG, "setSimPower: callback not available.");
2029 }
2030 } else {
2031 try {
2032 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2033 } catch (RemoteException e) {
2034 // Ignore if the remote process is no longer available to call back.
2035 Log.w(LOG_TAG, "setSimPower: callback not available.");
2036 }
2037 }
2038 break;
2039 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002040 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2041 request = (MainThreadRequest) msg.obj;
2042
2043 final Phone phone = getPhoneFromRequest(request);
2044 if (phone == null || phone.getServiceStateTracker() == null) {
2045 request.result = new IllegalStateException("Phone or SST is null");
2046 notifyRequester(request);
2047 break;
2048 }
2049
2050 Pair<Integer, SignalStrengthUpdateRequest> pair =
2051 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2052 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2053 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002054 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002055 request.subId, pair.first /*callingUid*/,
2056 pair.second /*request*/, onCompleted);
2057 break;
2058 }
2059 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2060 ar = (AsyncResult) msg.obj;
2061 request = (MainThreadRequest) ar.userObj;
2062 // request.result will be the exception of ar if present, true otherwise.
2063 // Be cautious not to leave result null which will wait() forever
2064 request.result = ar.exception != null ? ar.exception : true;
2065 notifyRequester(request);
2066 break;
2067 }
2068 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2069 request = (MainThreadRequest) msg.obj;
2070
2071 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_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2081 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002082 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002083 request.subId, pair.first /*callingUid*/,
2084 pair.second /*request*/, onCompleted);
2085 break;
2086 }
2087 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2088 ar = (AsyncResult) msg.obj;
2089 request = (MainThreadRequest) ar.userObj;
2090 request.result = ar.exception != null ? ar.exception : true;
2091 notifyRequester(request);
2092 break;
2093 }
Jordan Liu109698e2020-11-24 14:50:34 -08002094
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002095 case CMD_GET_SLICING_CONFIG: {
2096 request = (MainThreadRequest) msg.obj;
2097 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2098 request.phone.getSlicingConfig(onCompleted);
2099 break;
2100 }
2101 case EVENT_GET_SLICING_CONFIG_DONE: {
2102 ar = (AsyncResult) msg.obj;
2103 request = (MainThreadRequest) ar.userObj;
2104 ResultReceiver result = (ResultReceiver) request.argument;
2105
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002106 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002107 Bundle bundle = new Bundle();
2108 int resultCode = 0;
2109 if (ar.exception != null) {
2110 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2111 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002112 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002113 } else if (ar.result == null) {
2114 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002115 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002116 } else {
2117 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002118 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2119 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002120 }
2121
2122 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002123 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002124 }
2125 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2126 result.send(resultCode, bundle);
2127 notifyRequester(request);
2128 break;
2129 }
2130
Michele Berionne5e411512020-11-13 02:36:59 +00002131 case CMD_PREPARE_UNATTENDED_REBOOT:
2132 request = (MainThreadRequest) msg.obj;
2133 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002134 UiccController.getInstance().getPinStorage()
2135 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002136 notifyRequester(request);
2137 break;
2138
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002139 default:
2140 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2141 break;
2142 }
2143 }
Jake Hambye994d462014-02-03 13:10:13 -08002144
Pengquan Menga1bb6272018-09-06 09:59:22 -07002145 private void notifyRequester(MainThreadRequest request) {
2146 synchronized (request) {
2147 request.notifyAll();
2148 }
2149 }
2150
Jake Hambye994d462014-02-03 13:10:13 -08002151 private void handleNullReturnEvent(Message msg, String command) {
2152 AsyncResult ar = (AsyncResult) msg.obj;
2153 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2154 if (ar.exception == null) {
2155 request.result = true;
2156 } else {
2157 request.result = false;
2158 if (ar.exception instanceof CommandException) {
2159 loge(command + ": CommandException: " + ar.exception);
2160 } else {
2161 loge(command + ": Unknown exception");
2162 }
2163 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002164 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002165 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002166 }
2167
2168 /**
2169 * Posts the specified command to be executed on the main thread,
2170 * waits for the request to complete, and returns the result.
2171 * @see #sendRequestAsync
2172 */
2173 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002174 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2175 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002176 }
2177
2178 /**
2179 * Posts the specified command to be executed on the main thread,
2180 * waits for the request to complete, and returns the result.
2181 * @see #sendRequestAsync
2182 */
2183 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2184 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002185 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002186 }
2187
2188 /**
2189 * Posts the specified command to be executed on the main thread,
2190 * waits for the request to complete, and returns the result.
2191 * @see #sendRequestAsync
2192 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002193 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002194 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2195 }
2196
2197 /**
2198 * Posts the specified command to be executed on the main thread,
2199 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2200 * if not timeout or null otherwise.
2201 * @see #sendRequestAsync
2202 */
2203 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2204 long timeoutInMs) {
2205 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002206 }
2207
2208 /**
2209 * Posts the specified command to be executed on the main thread,
2210 * waits for the request to complete, and returns the result.
2211 * @see #sendRequestAsync
2212 */
Nathan Harold92bed182018-10-12 18:16:49 -07002213 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002214 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002215 }
2216
2217 /**
2218 * Posts the specified command to be executed on the main thread,
2219 * waits for the request to complete, and returns the result.
2220 * @see #sendRequestAsync
2221 */
2222 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002223 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2224 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002225 }
2226
2227 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002228 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2229 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2230 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002231 * @see #sendRequestAsync
2232 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002233 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2234 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002235 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2236 throw new RuntimeException("This method will deadlock if called from the main thread.");
2237 }
2238
Nathan Harold92bed182018-10-12 18:16:49 -07002239 MainThreadRequest request = null;
2240 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2241 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2242 } else if (phone != null) {
2243 request = new MainThreadRequest(argument, phone, workSource);
2244 } else {
2245 request = new MainThreadRequest(argument, subId, workSource);
2246 }
2247
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002248 Message msg = mMainThreadHandler.obtainMessage(command, request);
2249 msg.sendToTarget();
2250
Rambo Wang0f050d82021-02-12 11:43:36 -08002251
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002252 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002253 if (timeoutInMs >= 0) {
2254 // Wait for at least timeoutInMs before returning null request result
2255 long now = SystemClock.elapsedRealtime();
2256 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002257 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002258 try {
2259 request.wait(deadline - now);
2260 } catch (InterruptedException e) {
2261 // Do nothing, go back and check if request is completed or timeout
2262 } finally {
2263 now = SystemClock.elapsedRealtime();
2264 }
2265 }
2266 } else {
2267 // Wait for the request to complete
2268 while (request.result == null) {
2269 try {
2270 request.wait();
2271 } catch (InterruptedException e) {
2272 // Do nothing, go back and wait until the request is complete
2273 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002274 }
2275 }
2276 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002277 if (request.result == null) {
2278 Log.wtf(LOG_TAG,
2279 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2280 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002281 return request.result;
2282 }
2283
2284 /**
2285 * Asynchronous ("fire and forget") version of sendRequest():
2286 * Posts the specified command to be executed on the main thread, and
2287 * returns immediately.
2288 * @see #sendRequest
2289 */
2290 private void sendRequestAsync(int command) {
2291 mMainThreadHandler.sendEmptyMessage(command);
2292 }
2293
2294 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002295 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002296 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002297 */
2298 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002299 sendRequestAsync(command, argument, null, null);
2300 }
2301
2302 /**
2303 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2304 * @see {@link #sendRequest(int,Object)}
2305 */
2306 private void sendRequestAsync(
2307 int command, Object argument, Phone phone, WorkSource workSource) {
2308 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002309 Message msg = mMainThreadHandler.obtainMessage(command, request);
2310 msg.sendToTarget();
2311 }
2312
2313 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002314 * Initialize the singleton PhoneInterfaceManager instance.
2315 * This is only done once, at startup, from PhoneApp.onCreate().
2316 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002317 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002318 synchronized (PhoneInterfaceManager.class) {
2319 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002320 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002321 } else {
2322 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2323 }
2324 return sInstance;
2325 }
2326 }
2327
2328 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002329 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002330 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002331 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002332 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002333 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002334 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002335 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002336 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002337 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002338 mTelephonySharedPreferences =
2339 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002340 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002341 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002342 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002343 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002344
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002345 publish();
2346 }
2347
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002348 private Phone getDefaultPhone() {
2349 Phone thePhone = getPhone(getDefaultSubscription());
2350 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2351 }
2352
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002353 private void publish() {
2354 if (DBG) log("publish: " + this);
2355
Peter Wangc035ce42020-01-08 21:00:22 -08002356 TelephonyFrameworkInitializer
2357 .getTelephonyServiceManager()
2358 .getTelephonyServiceRegisterer()
2359 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002360 }
2361
Stuart Scott584921c2015-01-15 17:10:34 -08002362 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002363 if (request.phone != null) {
2364 return request.phone;
2365 } else {
2366 return getPhoneFromSubId(request.subId);
2367 }
2368 }
2369
2370 private Phone getPhoneFromSubId(int subId) {
2371 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2372 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002373 }
2374
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002375 private UiccPort getUiccPortFromRequest(MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002376 Phone phone = getPhoneFromRequest(request);
2377 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002378 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002379 }
2380
Wink Saville36469e72014-06-11 15:17:00 -07002381 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002382 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002383 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002384 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002385
Kai Shif70f46f2021-03-03 13:59:46 -08002386 private void sendEraseModemConfig(@NonNull Phone phone) {
2387 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2388 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2389 }
2390
2391 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2392 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2393 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002394 }
2395
Peter Wang44b186e2020-01-13 23:33:09 -08002396 private boolean isImsAvailableOnDevice() {
2397 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2398 if (pm == null) {
2399 // For some reason package manger is not available.. This will fail internally anyway,
2400 // so do not throw error and allow.
2401 return true;
2402 }
2403 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2404 }
2405
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002406 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002407 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002408 }
2409
Wink Savilleb564aae2014-10-23 10:18:09 -07002410 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002411 if (DBG) log("dial: " + number);
2412 // No permission check needed here: This is just a wrapper around the
2413 // ACTION_DIAL intent, which is available to any app since it puts up
2414 // the UI before it does anything.
2415
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002416 final long identity = Binder.clearCallingIdentity();
2417 try {
2418 String url = createTelUrl(number);
2419 if (url == null) {
2420 return;
2421 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002422
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002423 // PENDING: should we just silently fail if phone is offhook or ringing?
2424 PhoneConstants.State state = mCM.getState(subId);
2425 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2426 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2427 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2428 mApp.startActivity(intent);
2429 }
2430 } finally {
2431 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002432 }
2433 }
2434
2435 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002436 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002437 }
2438
Wink Savilleb564aae2014-10-23 10:18:09 -07002439 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002440 if (DBG) log("call: " + number);
2441
2442 // This is just a wrapper around the ACTION_CALL intent, but we still
2443 // need to do a permission check since we're calling startActivity()
2444 // from the context of the phone app.
2445 enforceCallPermission();
2446
Jordan Liu1617b712019-07-10 15:06:26 -07002447 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002448 != AppOpsManager.MODE_ALLOWED) {
2449 return;
2450 }
2451
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002452 final long identity = Binder.clearCallingIdentity();
2453 try {
2454 String url = createTelUrl(number);
2455 if (url == null) {
2456 return;
2457 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002458
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002459 boolean isValid = false;
2460 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2461 if (slist != null) {
2462 for (SubscriptionInfo subInfoRecord : slist) {
2463 if (subInfoRecord.getSubscriptionId() == subId) {
2464 isValid = true;
2465 break;
2466 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002467 }
Wink Saville08874612014-08-31 19:19:58 -07002468 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002469 if (!isValid) {
2470 return;
2471 }
Wink Saville08874612014-08-31 19:19:58 -07002472
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002473 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2474 intent.putExtra(SUBSCRIPTION_KEY, subId);
2475 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2476 mApp.startActivity(intent);
2477 } finally {
2478 Binder.restoreCallingIdentity(identity);
2479 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002480 }
2481
Wink Savilleb564aae2014-10-23 10:18:09 -07002482 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002483 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002484 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2485 }
2486
Wink Savilleb564aae2014-10-23 10:18:09 -07002487 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002488 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002489 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2490 }
2491
Wink Savilleb564aae2014-10-23 10:18:09 -07002492 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002493 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002494
2495 final long identity = Binder.clearCallingIdentity();
2496 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002497 Phone phone = getPhone(subId);
2498 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002499 checkSimPin.start();
2500 return checkSimPin.unlockSim(null, pin);
2501 } finally {
2502 Binder.restoreCallingIdentity(identity);
2503 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002504 }
2505
Wink Savilleb564aae2014-10-23 10:18:09 -07002506 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002507 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002508
2509 final long identity = Binder.clearCallingIdentity();
2510 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002511 Phone phone = getPhone(subId);
2512 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002513 checkSimPuk.start();
2514 return checkSimPuk.unlockSim(puk, pin);
2515 } finally {
2516 Binder.restoreCallingIdentity(identity);
2517 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002518 }
2519
2520 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002521 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002522 * a synchronous one.
2523 */
2524 private static class UnlockSim extends Thread {
2525
2526 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002527 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002528
2529 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002530 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2531 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002532
2533 // For replies from SimCard interface
2534 private Handler mHandler;
2535
2536 // For async handler to identify request type
2537 private static final int SUPPLY_PIN_COMPLETE = 100;
2538
Michele Berionne5e411512020-11-13 02:36:59 +00002539 UnlockSim(int phoneId, IccCard simCard) {
2540 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002541 mSimCard = simCard;
2542 }
2543
2544 @Override
2545 public void run() {
2546 Looper.prepare();
2547 synchronized (UnlockSim.this) {
2548 mHandler = new Handler() {
2549 @Override
2550 public void handleMessage(Message msg) {
2551 AsyncResult ar = (AsyncResult) msg.obj;
2552 switch (msg.what) {
2553 case SUPPLY_PIN_COMPLETE:
2554 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2555 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002556 mRetryCount = msg.arg1;
2557 if (ar.exception != null) {
2558 if (ar.exception instanceof CommandException &&
2559 ((CommandException)(ar.exception)).getCommandError()
2560 == CommandException.Error.PASSWORD_INCORRECT) {
2561 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002562 } //When UiccCardApp dispose,handle message and return exception
2563 else if (ar.exception instanceof CommandException &&
2564 ((CommandException) (ar.exception)).getCommandError()
2565 == CommandException.Error.ABORTED) {
2566 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002567 } else {
2568 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2569 }
2570 } else {
2571 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2572 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002573 mDone = true;
2574 UnlockSim.this.notifyAll();
2575 }
2576 break;
2577 }
2578 }
2579 };
2580 UnlockSim.this.notifyAll();
2581 }
2582 Looper.loop();
2583 }
2584
2585 /*
2586 * Use PIN or PUK to unlock SIM card
2587 *
2588 * If PUK is null, unlock SIM card with PIN
2589 *
2590 * If PUK is not null, unlock SIM card with PUK and set PIN code
2591 */
Wink Saville9de0f752013-10-22 19:04:03 -07002592 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002593
2594 while (mHandler == null) {
2595 try {
2596 wait();
2597 } catch (InterruptedException e) {
2598 Thread.currentThread().interrupt();
2599 }
2600 }
2601 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2602
2603 if (puk == null) {
2604 mSimCard.supplyPin(pin, callback);
2605 } else {
2606 mSimCard.supplyPuk(puk, pin, callback);
2607 }
2608
2609 while (!mDone) {
2610 try {
2611 Log.d(LOG_TAG, "wait for done");
2612 wait();
2613 } catch (InterruptedException e) {
2614 // Restore the interrupted status
2615 Thread.currentThread().interrupt();
2616 }
2617 }
2618 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002619 int[] resultArray = new int[2];
2620 resultArray[0] = mResult;
2621 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002622
2623 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002624 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002625 }
2626
Wink Saville9de0f752013-10-22 19:04:03 -07002627 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002628 }
2629 }
2630
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002631 /**
2632 * This method has been removed due to privacy and stability concerns.
2633 */
2634 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002635 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002636 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2637 return;
Wink Saville36469e72014-06-11 15:17:00 -07002638 }
2639
Nathan Harold1f889d82020-06-04 17:05:26 -07002640 @Override
2641 public void updateServiceLocationWithPackageName(String callingPackage) {
2642 mApp.getSystemService(AppOpsManager.class)
2643 .checkPackage(Binder.getCallingUid(), callingPackage);
2644
Nathan Haroldf096d982020-11-18 17:18:06 -08002645 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002646 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2647 // Callers targeting S have no business invoking this method.
2648 return;
2649 }
2650
2651 LocationAccessPolicy.LocationPermissionResult locationResult =
2652 LocationAccessPolicy.checkLocationPermission(mApp,
2653 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2654 .setCallingPackage(callingPackage)
2655 .setCallingFeatureId(null)
2656 .setCallingPid(Binder.getCallingPid())
2657 .setCallingUid(Binder.getCallingUid())
2658 .setMethod("updateServiceLocation")
2659 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2660 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2661 .build());
2662 // Apps that lack location permission have no business calling this method;
2663 // however, because no permission was declared in the public API, denials must
2664 // all be "soft".
2665 switch (locationResult) {
2666 case DENIED_HARD: /* fall through */
2667 case DENIED_SOFT:
2668 return;
2669 }
2670
2671 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002672 final long identity = Binder.clearCallingIdentity();
2673 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002674 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002675 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002676 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002677 }
2678 } finally {
2679 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002680 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002681 }
2682
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002683 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002684 @Override
2685 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002686 return isRadioOnWithFeature(callingPackage, null);
2687 }
2688
2689
2690 @Override
2691 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2692 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2693 callingFeatureId);
2694 }
2695
2696 @Deprecated
2697 @Override
2698 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2699 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002700 }
2701
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002702 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002703 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2704 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002705 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002706 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002707 return false;
2708 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002709
2710 final long identity = Binder.clearCallingIdentity();
2711 try {
2712 return isRadioOnForSubscriber(subId);
2713 } finally {
2714 Binder.restoreCallingIdentity(identity);
2715 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002716 }
2717
2718 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002719 final long identity = Binder.clearCallingIdentity();
2720 try {
2721 final Phone phone = getPhone(subId);
2722 if (phone != null) {
2723 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2724 } else {
2725 return false;
2726 }
2727 } finally {
2728 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002729 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002730 }
2731
2732 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002733 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002734 }
Wink Saville36469e72014-06-11 15:17:00 -07002735
Wink Savilleb564aae2014-10-23 10:18:09 -07002736 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002737 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002738
2739 final long identity = Binder.clearCallingIdentity();
2740 try {
2741 final Phone phone = getPhone(subId);
2742 if (phone != null) {
2743 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2744 }
2745 } finally {
2746 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002747 }
Wink Saville36469e72014-06-11 15:17:00 -07002748 }
2749
2750 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002751 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002752 }
2753
Wink Savilleb564aae2014-10-23 10:18:09 -07002754 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002755 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002756
2757 final long identity = Binder.clearCallingIdentity();
2758 try {
2759 final Phone phone = getPhone(subId);
2760 if (phone == null) {
2761 return false;
2762 }
2763 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2764 toggleRadioOnOffForSubscriber(subId);
2765 }
2766 return true;
2767 } finally {
2768 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002769 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002770 }
Wink Saville36469e72014-06-11 15:17:00 -07002771
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002772 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002773 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002774 /*
2775 * If any of the Radios are available, it will need to be
2776 * shutdown. So return true if any Radio is available.
2777 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002778 final long identity = Binder.clearCallingIdentity();
2779 try {
2780 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2781 Phone phone = PhoneFactory.getPhone(i);
2782 if (phone != null && phone.isRadioAvailable()) return true;
2783 }
2784 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2785 return false;
2786 } finally {
2787 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002788 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002789 }
2790
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002791 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002792 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002793 enforceModifyPermission();
2794
2795 final long identity = Binder.clearCallingIdentity();
2796 try {
2797 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2798 logv("Shutting down Phone " + i);
2799 shutdownRadioUsingPhoneId(i);
2800 }
2801 } finally {
2802 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002803 }
2804 }
2805
2806 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002807 Phone phone = PhoneFactory.getPhone(phoneId);
2808 if (phone != null && phone.isRadioAvailable()) {
2809 phone.shutdownRadio();
2810 }
2811 }
2812
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002813 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002814 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002815
2816 final long identity = Binder.clearCallingIdentity();
2817 try {
2818 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2819 if (defaultPhone != null) {
2820 defaultPhone.setRadioPower(turnOn);
2821 return true;
2822 } else {
2823 loge("There's no default phone.");
2824 return false;
2825 }
2826 } finally {
2827 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002828 }
Wink Saville36469e72014-06-11 15:17:00 -07002829 }
2830
Wink Savilleb564aae2014-10-23 10:18:09 -07002831 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002832 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002833
2834 final long identity = Binder.clearCallingIdentity();
2835 try {
2836 final Phone phone = getPhone(subId);
2837 if (phone != null) {
2838 phone.setRadioPower(turnOn);
2839 return true;
2840 } else {
2841 return false;
2842 }
2843 } finally {
2844 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002845 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002846 }
2847
Wink Saville36469e72014-06-11 15:17:00 -07002848 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002849 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002850 public boolean enableDataConnectivity() {
2851 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002852
2853 final long identity = Binder.clearCallingIdentity();
2854 try {
2855 int subId = mSubscriptionController.getDefaultDataSubId();
2856 final Phone phone = getPhone(subId);
2857 if (phone != null) {
Jack Yu99e87332021-12-17 23:14:15 -08002858 if (phone.isUsingNewDataStack()) {
2859 phone.getDataSettingsManager().setDataEnabled(
2860 TelephonyManager.DATA_ENABLED_REASON_USER, true);
2861 } else {
2862 phone.getDataEnabledSettings().setDataEnabled(
2863 TelephonyManager.DATA_ENABLED_REASON_USER, true);
2864 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002865 return true;
2866 } else {
2867 return false;
2868 }
2869 } finally {
2870 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002871 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002872 }
2873
Wink Saville36469e72014-06-11 15:17:00 -07002874 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002875 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002876 public boolean disableDataConnectivity() {
2877 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002878
2879 final long identity = Binder.clearCallingIdentity();
2880 try {
2881 int subId = mSubscriptionController.getDefaultDataSubId();
2882 final Phone phone = getPhone(subId);
2883 if (phone != null) {
Jack Yu99e87332021-12-17 23:14:15 -08002884 if (phone.isUsingNewDataStack()) {
2885 phone.getDataSettingsManager().setDataEnabled(
2886 TelephonyManager.DATA_ENABLED_REASON_USER, false);
2887 } else {
2888 phone.getDataEnabledSettings().setDataEnabled(
2889 TelephonyManager.DATA_ENABLED_REASON_USER, false);
2890 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002891 return true;
2892 } else {
2893 return false;
2894 }
2895 } finally {
2896 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002897 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002898 }
2899
Sanket Padawe356d7632015-06-22 14:03:32 -07002900 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002901 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002902 final long identity = Binder.clearCallingIdentity();
2903 try {
2904 final Phone phone = getPhone(subId);
2905 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002906 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002907 } else {
2908 return false;
2909 }
2910 } finally {
2911 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002912 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002913 }
2914
2915 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002916 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002917 }
2918
pkanwarae03a6b2016-11-06 20:37:09 -08002919 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002920 enforceCallPermission();
2921
2922 final long identity = Binder.clearCallingIdentity();
2923 try {
2924 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2925 return;
2926 }
2927 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2928 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2929 } finally {
2930 Binder.restoreCallingIdentity(identity);
2931 }
pkanwar32d516d2016-10-14 19:37:38 -07002932 };
2933
Wink Savilleb564aae2014-10-23 10:18:09 -07002934 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002935 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002936
2937 final long identity = Binder.clearCallingIdentity();
2938 try {
2939 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2940 return false;
2941 }
2942 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2943 } finally {
2944 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002945 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002946 }
2947
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002948 /**
2949 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2950 * tag on getCallState Binder call.
2951 */
2952 @Deprecated
2953 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002954 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002955 if (CompatChanges.isChangeEnabled(
2956 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2957 Binder.getCallingUid())) {
2958 // Do not allow this API to be called on API version 31+, it should only be
2959 // called on old apps using this Binder call directly.
2960 throw new SecurityException("This method can only be used for applications "
2961 + "targeting API version 30 or less.");
2962 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002963 final long identity = Binder.clearCallingIdentity();
2964 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002965 Phone phone = getPhone(getDefaultSubscription());
2966 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2967 PhoneConstantConversions.convertCallState(phone.getState());
2968 } finally {
2969 Binder.restoreCallingIdentity(identity);
2970 }
2971 }
2972
2973 @Override
2974 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2975 if (CompatChanges.isChangeEnabled(
2976 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2977 Binder.getCallingUid())) {
2978 // Check READ_PHONE_STATE for API version 31+
2979 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2980 featureId, "getCallStateForSubscription")) {
2981 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2982 + "targeting API level 31+.");
2983 }
2984 }
2985 final long identity = Binder.clearCallingIdentity();
2986 try {
2987 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002988 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2989 PhoneConstantConversions.convertCallState(phone.getState());
2990 } finally {
2991 Binder.restoreCallingIdentity(identity);
2992 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002993 }
2994
Sanket Padawe356d7632015-06-22 14:03:32 -07002995 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002996 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002997 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2998 }
2999
3000 @Override
3001 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003002 final long identity = Binder.clearCallingIdentity();
3003 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003004 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003005 if (phone != null) {
Jack Yu2c450952021-11-29 11:36:17 -08003006 if (phone.isUsingNewDataStack()) {
3007 return phone.getDataNetworkController().getInternetDataNetworkState();
3008 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003009 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
3010 } else {
3011 return PhoneConstantConversions.convertDataState(
3012 PhoneConstants.DataState.DISCONNECTED);
3013 }
3014 } finally {
3015 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003016 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003017 }
3018
Sanket Padawe356d7632015-06-22 14:03:32 -07003019 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003020 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003021 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
3022 }
3023
3024 @Override
3025 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003026 final long identity = Binder.clearCallingIdentity();
3027 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003028 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003029 if (phone != null) {
3030 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
3031 } else {
3032 return TelephonyManager.DATA_ACTIVITY_NONE;
3033 }
3034 } finally {
3035 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003036 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003037 }
3038
3039 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003040 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003041 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003042 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003043
3044 LocationAccessPolicy.LocationPermissionResult locationResult =
3045 LocationAccessPolicy.checkLocationPermission(mApp,
3046 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3047 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003048 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003049 .setCallingPid(Binder.getCallingPid())
3050 .setCallingUid(Binder.getCallingUid())
3051 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003052 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003053 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3054 .build());
3055 switch (locationResult) {
3056 case DENIED_HARD:
3057 throw new SecurityException("Not allowed to access cell location");
3058 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003059 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3060 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003061 }
3062
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003063 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003064 final long identity = Binder.clearCallingIdentity();
3065 try {
3066 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003067 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003068 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003069 } finally {
3070 Binder.restoreCallingIdentity(identity);
3071 }
Svetoslav64fad262015-04-14 14:35:21 -07003072 }
3073
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003074 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003075 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003076 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3077 // registered cell info, so return a NULL country instead.
3078 final long identity = Binder.clearCallingIdentity();
3079 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003080 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3081 // Get default phone in this case.
3082 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3083 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003084 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003085 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003086 if (phone == null) return "";
3087 ServiceStateTracker sst = phone.getServiceStateTracker();
3088 if (sst == null) return "";
3089 LocaleTracker lt = sst.getLocaleTracker();
3090 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003091 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003092 } finally {
3093 Binder.restoreCallingIdentity(identity);
3094 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003095 }
3096
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003097 /**
3098 * This method was removed due to potential issues caused by performing partial
3099 * updates of service state, and lack of a credible use case.
3100 *
3101 * This has the ability to break the telephony implementation by disabling notification of
3102 * changes in device connectivity. DO NOT USE THIS!
3103 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003104 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003105 public void enableLocationUpdates() {
3106 mApp.enforceCallingOrSelfPermission(
3107 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003108 }
3109
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003110 /**
3111 * This method was removed due to potential issues caused by performing partial
3112 * updates of service state, and lack of a credible use case.
3113 *
3114 * This has the ability to break the telephony implementation by disabling notification of
3115 * changes in device connectivity. DO NOT USE THIS!
3116 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003117 @Override
3118 public void disableLocationUpdates() {
3119 mApp.enforceCallingOrSelfPermission(
3120 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003121 }
3122
3123 @Override
3124 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003125 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3126 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003127 try {
3128 mApp.getSystemService(AppOpsManager.class)
3129 .checkPackage(Binder.getCallingUid(), callingPackage);
3130 } catch (SecurityException e) {
3131 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3132 throw e;
3133 }
3134
Nathan Haroldf096d982020-11-18 17:18:06 -08003135 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003136 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3137 throw new SecurityException(
3138 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3139 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003140
Jordan Liu1617b712019-07-10 15:06:26 -07003141 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003142 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3143 return null;
3144 }
Svetoslav64fad262015-04-14 14:35:21 -07003145
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003146 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003147
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003148 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003149 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003150
Nathan Haroldf180aac2018-06-01 18:43:55 -07003151 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3152 for (CellInfo ci : info) {
3153 if (ci instanceof CellInfoGsm) {
3154 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3155 } else if (ci instanceof CellInfoWcdma) {
3156 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3157 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003158 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003159 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003160 }
3161
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003162 private List<CellInfo> getCachedCellInfo() {
3163 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3164 for (Phone phone : PhoneFactory.getPhones()) {
3165 List<CellInfo> info = phone.getAllCellInfo();
3166 if (info != null) cellInfos.addAll(info);
3167 }
3168 return cellInfos;
3169 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003170
3171 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003172 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003173 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003174 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003175
3176 LocationAccessPolicy.LocationPermissionResult locationResult =
3177 LocationAccessPolicy.checkLocationPermission(mApp,
3178 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3179 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003180 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003181 .setCallingPid(Binder.getCallingPid())
3182 .setCallingUid(Binder.getCallingUid())
3183 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003184 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003185 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3186 .build());
3187 switch (locationResult) {
3188 case DENIED_HARD:
3189 throw new SecurityException("Not allowed to access cell info");
3190 case DENIED_SOFT:
3191 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003192 }
3193
Nathan Haroldf096d982020-11-18 17:18:06 -08003194 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003195 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3196 return getCachedCellInfo();
3197 }
3198
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003199 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003200 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003201 final long identity = Binder.clearCallingIdentity();
3202 try {
3203 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3204 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003205 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003206 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003207 if (info != null) cellInfos.addAll(info);
3208 }
3209 return cellInfos;
3210 } finally {
3211 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003212 }
3213 }
3214
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003215 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003216 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3217 String callingFeatureId) {
3218 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3219 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003220 }
3221
3222 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003223 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3224 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003225 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003226 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003227 }
3228
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003229 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3230 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003231 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003232 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003233
3234 LocationAccessPolicy.LocationPermissionResult locationResult =
3235 LocationAccessPolicy.checkLocationPermission(mApp,
3236 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3237 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003238 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003239 .setCallingPid(Binder.getCallingPid())
3240 .setCallingUid(Binder.getCallingUid())
3241 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003242 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3243 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003244 .build());
3245 switch (locationResult) {
3246 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003247 if (TelephonyPermissions
3248 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003249 // Safetynet logging for b/154934934
3250 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3251 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003252 throw new SecurityException("Not allowed to access cell info");
3253 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003254 if (TelephonyPermissions
3255 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003256 // Safetynet logging for b/154934934
3257 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3258 }
Nathan Harold5320c422019-05-09 10:26:08 -07003259 try {
3260 cb.onCellInfo(new ArrayList<CellInfo>());
3261 } catch (RemoteException re) {
3262 // Drop without consequences
3263 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003264 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003265 }
3266
Nathan Harolda939a962019-05-09 10:13:47 -07003267
3268 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003269 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3270
3271 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3272 }
3273
3274 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003275 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003276 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003277 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003278
3279 final long identity = Binder.clearCallingIdentity();
3280 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003281 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003282 } finally {
3283 Binder.restoreCallingIdentity(identity);
3284 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003285 }
3286
Shishir Agrawala9f32182016-04-12 12:00:16 -07003287 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003288 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003289 Phone phone = PhoneFactory.getPhone(slotIndex);
3290 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003291 return null;
3292 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003293 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003294 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003295 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003296 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003297 return null;
3298 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003299
3300 final long identity = Binder.clearCallingIdentity();
3301 try {
3302 return phone.getImei();
3303 } finally {
3304 Binder.restoreCallingIdentity(identity);
3305 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003306 }
3307
3308 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003309 public String getTypeAllocationCodeForSlot(int slotIndex) {
3310 Phone phone = PhoneFactory.getPhone(slotIndex);
3311 String tac = null;
3312 if (phone != null) {
3313 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003314 try {
3315 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3316 } catch (IndexOutOfBoundsException e) {
3317 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3318 return null;
3319 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003320 }
3321 return tac;
3322 }
3323
3324 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003325 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003326 try {
3327 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3328 } catch (SecurityException se) {
3329 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3330 throw new SecurityException("Package " + callingPackage + " does not belong to "
3331 + Binder.getCallingUid());
3332 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003333 Phone phone = PhoneFactory.getPhone(slotIndex);
3334 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003335 return null;
3336 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003337
Jeff Davidson913390f2018-02-23 17:11:49 -08003338 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003339 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003340 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003341 return null;
3342 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003343
3344 final long identity = Binder.clearCallingIdentity();
3345 try {
3346 return phone.getMeid();
3347 } finally {
3348 Binder.restoreCallingIdentity(identity);
3349 }
Jack Yu2af8d712017-03-15 17:14:14 -07003350 }
3351
3352 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003353 public String getManufacturerCodeForSlot(int slotIndex) {
3354 Phone phone = PhoneFactory.getPhone(slotIndex);
3355 String manufacturerCode = null;
3356 if (phone != null) {
3357 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003358 try {
3359 manufacturerCode =
3360 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3361 } catch (IndexOutOfBoundsException e) {
3362 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3363 return null;
3364 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003365 }
3366 return manufacturerCode;
3367 }
3368
3369 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003370 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3371 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003372 Phone phone = PhoneFactory.getPhone(slotIndex);
3373 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003374 return null;
3375 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003376 int subId = phone.getSubId();
3377 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003378 mApp, subId, callingPackage, callingFeatureId,
3379 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003380 return null;
3381 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003382
3383 final long identity = Binder.clearCallingIdentity();
3384 try {
3385 return phone.getDeviceSvn();
3386 } finally {
3387 Binder.restoreCallingIdentity(identity);
3388 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003389 }
3390
fionaxu43304da2017-11-27 22:51:16 -08003391 @Override
3392 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003393 final long identity = Binder.clearCallingIdentity();
3394 try {
3395 final Phone phone = getPhone(subId);
3396 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3397 } finally {
3398 Binder.restoreCallingIdentity(identity);
3399 }
fionaxu43304da2017-11-27 22:51:16 -08003400 }
3401
3402 @Override
3403 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003404 final long identity = Binder.clearCallingIdentity();
3405 try {
3406 final Phone phone = getPhone(subId);
3407 return phone == null ? null : phone.getCarrierName();
3408 } finally {
3409 Binder.restoreCallingIdentity(identity);
3410 }
fionaxu43304da2017-11-27 22:51:16 -08003411 }
3412
calvinpanffe225e2018-11-01 19:43:06 +08003413 @Override
chen xu0026ca62019-03-06 15:28:50 -08003414 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003415 final long identity = Binder.clearCallingIdentity();
3416 try {
3417 final Phone phone = getPhone(subId);
3418 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003419 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003420 } finally {
3421 Binder.restoreCallingIdentity(identity);
3422 }
3423 }
3424
3425 @Override
chen xu0026ca62019-03-06 15:28:50 -08003426 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003427 final long identity = Binder.clearCallingIdentity();
3428 try {
3429 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003430 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003431 } finally {
3432 Binder.restoreCallingIdentity(identity);
3433 }
3434 }
3435
chen xu651eec72018-11-11 19:03:44 -08003436 @Override
chen xu864e11c2018-12-06 22:10:03 -08003437 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3438 if (!isSubscriptionMccMnc) {
3439 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3440 }
chen xu651eec72018-11-11 19:03:44 -08003441 final Phone phone = PhoneFactory.getPhone(slotIndex);
3442 if (phone == null) {
3443 return TelephonyManager.UNKNOWN_CARRIER_ID;
3444 }
3445 final long identity = Binder.clearCallingIdentity();
3446 try {
3447 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3448 } finally {
3449 Binder.restoreCallingIdentity(identity);
3450 }
3451 }
3452
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003453 //
3454 // Internal helper methods.
3455 //
3456
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003457 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003458 * Make sure the caller is the calling package itself
3459 *
3460 * @throws SecurityException if the caller is not the calling package
3461 */
3462 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3463 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003464 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3465 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003466 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003467 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003468 } catch (PackageManager.NameNotFoundException e) {
3469 // packageUid is -1
3470 }
3471 if (packageUid != callingUid) {
3472 throw new SecurityException(message + ": Package " + callingPackage
3473 + " does not belong to " + callingUid);
3474 }
3475 }
3476
3477 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003478 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3479 *
3480 * @throws SecurityException if the caller does not have the required permission
3481 */
3482 private void enforceModifyPermission() {
3483 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3484 }
3485
Shuo Qian3b6ee772019-11-13 17:43:31 -08003486 private void enforceActiveEmergencySessionPermission() {
3487 mApp.enforceCallingOrSelfPermission(
3488 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3489 }
3490
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003491 /**
3492 * Make sure the caller has the CALL_PHONE permission.
3493 *
3494 * @throws SecurityException if the caller does not have the required permission
3495 */
3496 private void enforceCallPermission() {
3497 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3498 }
3499
paulhu5a773602019-08-23 19:17:33 +08003500 private void enforceSettingsPermission() {
3501 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003502 }
3503
Michele Berionne5e411512020-11-13 02:36:59 +00003504 private void enforceRebootPermission() {
3505 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3506 }
3507
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003508 private String createTelUrl(String number) {
3509 if (TextUtils.isEmpty(number)) {
3510 return null;
3511 }
3512
Jake Hambye994d462014-02-03 13:10:13 -08003513 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003514 }
3515
Ihab Awadf9e92732013-12-05 18:02:52 -08003516 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003517 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3518 }
3519
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003520 private static void logv(String msg) {
3521 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3522 }
3523
Ihab Awadf9e92732013-12-05 18:02:52 -08003524 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003525 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3526 }
3527
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003528 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003529 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003530 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003531 }
3532
Sanket Padawe356d7632015-06-22 14:03:32 -07003533 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003534 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003535 final long identity = Binder.clearCallingIdentity();
3536 try {
3537 final Phone phone = PhoneFactory.getPhone(slotIndex);
3538 if (phone == null) {
3539 return PhoneConstants.PHONE_TYPE_NONE;
3540 } else {
3541 return phone.getPhoneType();
3542 }
3543 } finally {
3544 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003545 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003546 }
3547
3548 /**
3549 * Returns the CDMA ERI icon index to display
3550 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003551 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003552 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3553 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3554 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003555 }
3556
Sanket Padawe356d7632015-06-22 14:03:32 -07003557 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003558 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3559 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003560 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003561 mApp, subId, callingPackage, callingFeatureId,
3562 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003563 return -1;
3564 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003565
3566 final long identity = Binder.clearCallingIdentity();
3567 try {
3568 final Phone phone = getPhone(subId);
3569 if (phone != null) {
3570 return phone.getCdmaEriIconIndex();
3571 } else {
3572 return -1;
3573 }
3574 } finally {
3575 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003576 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003577 }
3578
3579 /**
3580 * Returns the CDMA ERI icon mode,
3581 * 0 - ON
3582 * 1 - FLASHING
3583 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003584 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003585 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3586 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3587 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003588 }
3589
Sanket Padawe356d7632015-06-22 14:03:32 -07003590 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003591 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3592 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003593 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003594 mApp, subId, callingPackage, callingFeatureId,
3595 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003596 return -1;
3597 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003598
3599 final long identity = Binder.clearCallingIdentity();
3600 try {
3601 final Phone phone = getPhone(subId);
3602 if (phone != null) {
3603 return phone.getCdmaEriIconMode();
3604 } else {
3605 return -1;
3606 }
3607 } finally {
3608 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003609 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003610 }
3611
3612 /**
3613 * Returns the CDMA ERI text,
3614 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003615 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003616 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3617 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3618 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003619 }
3620
Sanket Padawe356d7632015-06-22 14:03:32 -07003621 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003622 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3623 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003624 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003625 mApp, subId, callingPackage, callingFeatureId,
3626 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003627 return null;
3628 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003629
3630 final long identity = Binder.clearCallingIdentity();
3631 try {
3632 final Phone phone = getPhone(subId);
3633 if (phone != null) {
3634 return phone.getCdmaEriText();
3635 } else {
3636 return null;
3637 }
3638 } finally {
3639 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003640 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003641 }
3642
3643 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003644 * Returns the CDMA MDN.
3645 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003646 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003647 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003648 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3649 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003650
3651 final long identity = Binder.clearCallingIdentity();
3652 try {
3653 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003654 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003655 return phone.getLine1Number();
3656 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003657 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003658 return null;
3659 }
3660 } finally {
3661 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003662 }
3663 }
3664
3665 /**
3666 * Returns the CDMA MIN.
3667 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003668 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003669 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003670 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3671 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003672
3673 final long identity = Binder.clearCallingIdentity();
3674 try {
3675 final Phone phone = getPhone(subId);
3676 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3677 return phone.getCdmaMin();
3678 } else {
3679 return null;
3680 }
3681 } finally {
3682 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003683 }
3684 }
3685
Hall Liud892bec2018-11-30 14:51:45 -08003686 @Override
3687 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3688 INumberVerificationCallback callback, String callingPackage) {
3689 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3690 != PERMISSION_GRANTED) {
3691 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3692 }
3693 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3694
3695 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3696 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003697 throw new SecurityException("Calling package must be configured in the device config: "
3698 + "calling package: " + callingPackage
3699 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003700 }
3701
3702 if (range == null) {
3703 throw new NullPointerException("Range must be non-null");
3704 }
3705
3706 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003707 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003708
3709 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3710 }
3711
Junda Liuca05d5d2014-08-14 22:36:34 -07003712 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003713 * Returns true if CDMA provisioning needs to run.
3714 */
3715 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003716 final long identity = Binder.clearCallingIdentity();
3717 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003718 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003719 } finally {
3720 Binder.restoreCallingIdentity(identity);
3721 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003722 }
3723
3724 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003725 * Sets the voice mail number of a given subId.
3726 */
3727 @Override
3728 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003729 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3730 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003731
3732 final long identity = Binder.clearCallingIdentity();
3733 try {
3734 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3735 new Pair<String, String>(alphaTag, number), new Integer(subId));
3736 return success;
3737 } finally {
3738 Binder.restoreCallingIdentity(identity);
3739 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003740 }
3741
Ta-wei Yen87c49842016-05-13 21:19:52 -07003742 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003743 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3744 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003745 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3746 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003747 if (!TextUtils.equals(callingPackage, systemDialer)) {
3748 throw new SecurityException("caller must be system dialer");
3749 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003750
3751 final long identity = Binder.clearCallingIdentity();
3752 try {
3753 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3754 if (phoneAccountHandle == null) {
3755 return null;
3756 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003757 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003758 } finally {
3759 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003760 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003761 }
3762
3763 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003764 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3765 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003766 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003767 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003768 mApp, subId, callingPackage, callingFeatureId,
3769 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003770 return null;
3771 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003772
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003773 final long identity = Binder.clearCallingIdentity();
3774 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003775 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003776 } finally {
3777 Binder.restoreCallingIdentity(identity);
3778 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003779 }
3780
3781 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003782 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3783 VisualVoicemailSmsFilterSettings settings) {
3784 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003785
3786 final long identity = Binder.clearCallingIdentity();
3787 try {
3788 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003789 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003790 } finally {
3791 Binder.restoreCallingIdentity(identity);
3792 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003793 }
3794
3795 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003796 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3797 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003798
3799 final long identity = Binder.clearCallingIdentity();
3800 try {
3801 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003802 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003803 } finally {
3804 Binder.restoreCallingIdentity(identity);
3805 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003806 }
3807
3808 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003809 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3810 String callingPackage, int subId) {
3811 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003812
3813 final long identity = Binder.clearCallingIdentity();
3814 try {
3815 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003816 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003817 } finally {
3818 Binder.restoreCallingIdentity(identity);
3819 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003820 }
3821
3822 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003823 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003824 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003825
3826 final long identity = Binder.clearCallingIdentity();
3827 try {
3828 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003829 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003830 } finally {
3831 Binder.restoreCallingIdentity(identity);
3832 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003833 }
3834
3835 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003836 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3837 String callingAttributionTag, int subId, String number, int port, String text,
3838 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003839 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003840 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003841 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003842 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003843 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3844 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003845 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003846
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003847 /**
fionaxu0152e512016-11-14 13:36:14 -08003848 * Sets the voice activation state of a given subId.
3849 */
3850 @Override
3851 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003852 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3853 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003854
3855 final long identity = Binder.clearCallingIdentity();
3856 try {
3857 final Phone phone = getPhone(subId);
3858 if (phone != null) {
3859 phone.setVoiceActivationState(activationState);
3860 } else {
3861 loge("setVoiceActivationState fails with invalid subId: " + subId);
3862 }
3863 } finally {
3864 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003865 }
3866 }
3867
3868 /**
3869 * Sets the data activation state of a given subId.
3870 */
3871 @Override
3872 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003873 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3874 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003875
3876 final long identity = Binder.clearCallingIdentity();
3877 try {
3878 final Phone phone = getPhone(subId);
3879 if (phone != null) {
3880 phone.setDataActivationState(activationState);
3881 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003882 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003883 }
3884 } finally {
3885 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003886 }
3887 }
3888
3889 /**
3890 * Returns the voice activation state of a given subId.
3891 */
3892 @Override
3893 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003894 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003895
fionaxu0152e512016-11-14 13:36:14 -08003896 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003897 final long identity = Binder.clearCallingIdentity();
3898 try {
3899 if (phone != null) {
3900 return phone.getVoiceActivationState();
3901 } else {
3902 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3903 }
3904 } finally {
3905 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003906 }
3907 }
3908
3909 /**
3910 * Returns the data activation state of a given subId.
3911 */
3912 @Override
3913 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003914 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003915
fionaxu0152e512016-11-14 13:36:14 -08003916 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003917 final long identity = Binder.clearCallingIdentity();
3918 try {
3919 if (phone != null) {
3920 return phone.getDataActivationState();
3921 } else {
3922 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3923 }
3924 } finally {
3925 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003926 }
3927 }
3928
3929 /**
Wink Saville36469e72014-06-11 15:17:00 -07003930 * Returns the unread count of voicemails for a subId
3931 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003932 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003933 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3934 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003935 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003936 mApp, subId, callingPackage, callingFeatureId,
3937 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003938 return 0;
3939 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003940 final long identity = Binder.clearCallingIdentity();
3941 try {
3942 final Phone phone = getPhone(subId);
3943 if (phone != null) {
3944 return phone.getVoiceMessageCount();
3945 } else {
3946 return 0;
3947 }
3948 } finally {
3949 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003950 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003951 }
3952
3953 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003954 * returns true, if the device is in a state where both voice and data
3955 * are supported simultaneously. This can change based on location or network condition.
3956 */
3957 @Override
3958 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003959 final long identity = Binder.clearCallingIdentity();
3960 try {
3961 final Phone phone = getPhone(subId);
3962 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3963 } finally {
3964 Binder.restoreCallingIdentity(identity);
3965 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003966 }
3967
3968 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003969 * Send the dialer code if called from the current default dialer or the caller has
3970 * carrier privilege.
3971 * @param inputCode The dialer code to send
3972 */
3973 @Override
3974 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003975 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003976 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003977 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3978 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003979 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003980 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003981 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003982 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003983
3984 final long identity = Binder.clearCallingIdentity();
3985 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003986 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003987 } finally {
3988 Binder.restoreCallingIdentity(identity);
3989 }
fionaxu235cc5e2017-03-06 22:25:57 -08003990 }
3991
Pengquan Menga1bb6272018-09-06 09:59:22 -07003992 @Override
3993 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003994 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003995 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003996 mApp, subId, "getNetworkSelectionMode");
3997 final long identity = Binder.clearCallingIdentity();
3998 try {
3999 if (!isActiveSubscription(subId)) {
4000 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4001 }
4002 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4003 } finally {
4004 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004005 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004006 }
4007
Brad Ebinger35c841c2018-10-01 10:40:55 -07004008 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004009 public boolean isInEmergencySmsMode() {
4010 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4011 final long identity = Binder.clearCallingIdentity();
4012 try {
4013 for (Phone phone : PhoneFactory.getPhones()) {
4014 if (phone.isInEmergencySmsMode()) {
4015 return true;
4016 }
4017 }
4018 } finally {
4019 Binder.restoreCallingIdentity(identity);
4020 }
4021 return false;
4022 }
4023
shilu366312e2019-12-17 09:28:10 -08004024 /**
4025 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4026 * @param subId The subscription to use to check the configuration.
4027 * @param c The callback that will be used to send the result.
4028 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004029 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004030 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4031 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004032 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004033 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004034
4035 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4036 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4037 "IMS not available on device.");
4038 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004039 final long token = Binder.clearCallingIdentity();
4040 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004041 int slotId = getSlotIndexOrException(subId);
4042 verifyImsMmTelConfiguredOrThrow(slotId);
4043 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004044 } catch (ImsException e) {
4045 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004046 } finally {
4047 Binder.restoreCallingIdentity(token);
4048 }
4049 }
4050
shilu366312e2019-12-17 09:28:10 -08004051 /**
4052 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4053 * @param subId The subscription to use to check the configuration.
4054 * @param c The callback that will be used to send the result.
4055 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004056 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004057 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004058 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004059 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004060 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4061 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4062 }
Meng Wangafbc5852019-09-19 17:37:13 -07004063 final long token = Binder.clearCallingIdentity();
4064 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004065 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4066 .removeRegistrationCallbackForSubscription(c, subId);
4067 } catch (ImsException e) {
4068 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4069 + "is inactive, ignoring unregister.");
4070 // If the subscription is no longer active, just return, since the callback
4071 // will already have been removed internally.
4072 } finally {
4073 Binder.restoreCallingIdentity(token);
4074 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004075 }
4076
Brad Ebingera34a6c22019-10-22 17:36:18 -07004077 /**
4078 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4079 */
4080 @Override
4081 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4082 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4083 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4084 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4085 "IMS not available on device.");
4086 }
4087 final long token = Binder.clearCallingIdentity();
4088 try {
4089 Phone phone = getPhone(subId);
4090 if (phone == null) {
4091 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4092 + subId + "'");
4093 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4094 }
4095 phone.getImsRegistrationState(regState -> {
4096 try {
4097 consumer.accept((regState == null)
4098 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4099 } catch (RemoteException e) {
4100 // Ignore if the remote process is no longer available to call back.
4101 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4102 }
4103 });
4104 } finally {
4105 Binder.restoreCallingIdentity(token);
4106 }
4107 }
4108
4109 /**
4110 * Get the transport type for the IMS service registration state.
4111 */
4112 @Override
4113 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004114 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004115 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004116 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4117 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4118 "IMS not available on device.");
4119 }
4120 final long token = Binder.clearCallingIdentity();
4121 try {
4122 Phone phone = getPhone(subId);
4123 if (phone == null) {
4124 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4125 + subId + "'");
4126 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4127 }
4128 phone.getImsRegistrationTech(regTech -> {
4129 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4130 int regTechConverted = (regTech == null)
4131 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4132 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4133 regTechConverted);
4134 try {
4135 consumer.accept(regTechConverted);
4136 } catch (RemoteException e) {
4137 // Ignore if the remote process is no longer available to call back.
4138 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4139 }
4140 });
4141 } finally {
4142 Binder.restoreCallingIdentity(token);
4143 }
4144 }
4145
shilu366312e2019-12-17 09:28:10 -08004146 /**
4147 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4148 * @param subId The subscription to use to check the configuration.
4149 * @param c The callback that will be used to send the result.
4150 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004151 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004152 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4153 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004154 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004155 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004156 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4157 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4158 "IMS not available on device.");
4159 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004160 final long token = Binder.clearCallingIdentity();
4161 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004162 int slotId = getSlotIndexOrException(subId);
4163 verifyImsMmTelConfiguredOrThrow(slotId);
4164 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004165 } catch (ImsException e) {
4166 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004167 } finally {
4168 Binder.restoreCallingIdentity(token);
4169 }
4170 }
4171
shilu366312e2019-12-17 09:28:10 -08004172 /**
4173 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4174 * @param subId The subscription to use to check the configuration.
4175 * @param c The callback that will be used to send the result.
4176 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004177 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004178 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004179 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004180 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004181 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4182 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4183 }
Meng Wangafbc5852019-09-19 17:37:13 -07004184
4185 final long token = Binder.clearCallingIdentity();
4186 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004187 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004188 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004189 } catch (ImsException e) {
4190 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4191 + "is inactive, ignoring unregister.");
4192 // If the subscription is no longer active, just return, since the callback
4193 // will already have been removed internally.
4194 } finally {
4195 Binder.restoreCallingIdentity(token);
4196 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004197 }
4198
4199 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004200 public boolean isCapable(int subId, int capability, int regTech) {
4201 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004202 final long token = Binder.clearCallingIdentity();
4203 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004204 int slotId = getSlotIndexOrException(subId);
4205 verifyImsMmTelConfiguredOrThrow(slotId);
4206 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4207 } catch (com.android.ims.ImsException e) {
4208 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4209 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004210 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004211 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4212 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004213 } finally {
4214 Binder.restoreCallingIdentity(token);
4215 }
4216 }
4217
4218 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004219 public boolean isAvailable(int subId, int capability, int regTech) {
4220 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004221 final long token = Binder.clearCallingIdentity();
4222 try {
4223 Phone phone = getPhone(subId);
4224 if (phone == null) return false;
4225 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004226 } catch (com.android.ims.ImsException e) {
4227 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4228 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004229 } finally {
4230 Binder.restoreCallingIdentity(token);
4231 }
4232 }
4233
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004234 /**
4235 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4236 * subscription.
4237 * @param subId The subscription to use to check the configuration.
4238 * @param callback The callback that will be used to send the result.
4239 * @param capability The MmTelFeature capability that will be used to send the result.
4240 * @param transportType The transport type of the MmTelFeature capability.
4241 */
4242 @Override
4243 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4244 int transportType) {
4245 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004246 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4247 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4248 "IMS not available on device.");
4249 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004250 final long token = Binder.clearCallingIdentity();
4251 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004252 int slotId = getSlotIndex(subId);
4253 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4254 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4255 + subId + "'");
4256 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4257 }
4258 verifyImsMmTelConfiguredOrThrow(slotId);
4259 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4260 transportType, aBoolean -> {
4261 try {
4262 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4263 } catch (RemoteException e) {
4264 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4265 + "running. Ignore");
4266 }
4267 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004268 } catch (ImsException e) {
4269 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004270 } finally {
4271 Binder.restoreCallingIdentity(token);
4272 }
4273 }
4274
shilu366312e2019-12-17 09:28:10 -08004275 /**
4276 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4277 * @param subId The subscription to use to check the configuration.
4278 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004279 @Override
4280 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004281 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004282 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004283
Brad Ebinger35c841c2018-10-01 10:40:55 -07004284 final long token = Binder.clearCallingIdentity();
4285 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004286 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004287 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004288 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004289 } catch (ImsException e) {
4290 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004291 } finally {
4292 Binder.restoreCallingIdentity(token);
4293 }
4294 }
4295
4296 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004297 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004298 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004299 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004300 final long identity = Binder.clearCallingIdentity();
4301 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004302 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004303 // This setting doesn't require an active ImsService connection, so do not verify. The
4304 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004305 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004306 } catch (ImsException e) {
4307 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004308 } finally {
4309 Binder.restoreCallingIdentity(identity);
4310 }
4311 }
4312
shilu366312e2019-12-17 09:28:10 -08004313 /**
4314 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4315 * @param subId The subscription to use to check the configuration.
4316 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004317 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004318 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004319 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004320 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004321 final long identity = Binder.clearCallingIdentity();
4322 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004323 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004324 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004325 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004326 } catch (ImsException e) {
4327 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004328 } finally {
4329 Binder.restoreCallingIdentity(identity);
4330 }
4331 }
4332
4333 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004334 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004335 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004336 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004337 final long identity = Binder.clearCallingIdentity();
4338 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004339 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004340 // This setting doesn't require an active ImsService connection, so do not verify. The
4341 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004342 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004343 } catch (ImsException e) {
4344 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004345 } finally {
4346 Binder.restoreCallingIdentity(identity);
4347 }
4348 }
4349
shilu366312e2019-12-17 09:28:10 -08004350 /**
4351 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4352 * @param subId The subscription to use to check the configuration.
4353 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004354 @Override
4355 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004356 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004357 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004358 final long identity = Binder.clearCallingIdentity();
4359 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004360 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004361 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004362 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004363 } catch (ImsException e) {
4364 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004365 } finally {
4366 Binder.restoreCallingIdentity(identity);
4367 }
4368 }
4369
4370 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004371 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004372 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004373 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004374 final long identity = Binder.clearCallingIdentity();
4375 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004376 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004377 // This setting doesn't require an active ImsService connection, so do not verify. The
4378 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004379 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004380 } catch (ImsException e) {
4381 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004382 } finally {
4383 Binder.restoreCallingIdentity(identity);
4384 }
4385 }
4386
shilu366312e2019-12-17 09:28:10 -08004387 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004388 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4389 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4390 * @param subId The subscription to use to check the configuration.
4391 */
4392 @Override
4393 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004394 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004395 mApp, subId, "isCrossSimCallingEnabledByUser");
4396 final long identity = Binder.clearCallingIdentity();
4397 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004398 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004399 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004400 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004401 } catch (ImsException e) {
4402 throw new ServiceSpecificException(e.getCode());
4403 } finally {
4404 Binder.restoreCallingIdentity(identity);
4405 }
4406 }
4407
4408 /**
4409 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4410 * Requires MODIFY_PHONE_STATE permission.
4411 * @param subId The subscription to use to check the configuration.
4412 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4413 * false otherwise
4414 */
4415 @Override
4416 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4417 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4418 "setCrossSimCallingEnabled");
4419 final long identity = Binder.clearCallingIdentity();
4420 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004421 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004422 // This setting doesn't require an active ImsService connection, so do not verify. The
4423 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004424 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004425 } catch (ImsException e) {
4426 throw new ServiceSpecificException(e.getCode());
4427 } finally {
4428 Binder.restoreCallingIdentity(identity);
4429 }
4430 }
4431
4432 /**
shilu366312e2019-12-17 09:28:10 -08004433 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4434 * @param subId The subscription to use to check the configuration.
4435 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004436 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004437
Brad Ebinger35c841c2018-10-01 10:40:55 -07004438 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004439 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004440 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004441 final long identity = Binder.clearCallingIdentity();
4442 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004443 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004444 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004445 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004446 } catch (ImsException e) {
4447 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004448 } finally {
4449 Binder.restoreCallingIdentity(identity);
4450 }
4451 }
4452
4453 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004454 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004455 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004456 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004457 final long identity = Binder.clearCallingIdentity();
4458 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004459 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004460 // This setting doesn't require an active ImsService connection, so do not verify. The
4461 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004462 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004463 } catch (ImsException e) {
4464 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004465 } finally {
4466 Binder.restoreCallingIdentity(identity);
4467 }
4468 }
4469
4470 @Override
4471 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4472 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4473 "setVoWiFiNonPersistent");
4474 final long identity = Binder.clearCallingIdentity();
4475 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004476 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004477 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004478 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004479 } catch (ImsException e) {
4480 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004481 } finally {
4482 Binder.restoreCallingIdentity(identity);
4483 }
4484 }
4485
shilu366312e2019-12-17 09:28:10 -08004486 /**
4487 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4488 * @param subId The subscription to use to check the configuration.
4489 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004490 @Override
4491 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004492 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004493 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004494 final long identity = Binder.clearCallingIdentity();
4495 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004496 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004497 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004498 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004499 } catch (ImsException e) {
4500 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004501 } finally {
4502 Binder.restoreCallingIdentity(identity);
4503 }
4504 }
4505
4506 @Override
4507 public void setVoWiFiModeSetting(int subId, int mode) {
4508 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4509 "setVoWiFiModeSetting");
4510 final long identity = Binder.clearCallingIdentity();
4511 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004512 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004513 // This setting doesn't require an active ImsService connection, so do not verify. The
4514 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004515 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004516 } catch (ImsException e) {
4517 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004518 } finally {
4519 Binder.restoreCallingIdentity(identity);
4520 }
4521 }
4522
4523 @Override
4524 public int getVoWiFiRoamingModeSetting(int subId) {
4525 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4526 final long identity = Binder.clearCallingIdentity();
4527 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004528 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004529 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004530 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004531 } catch (ImsException e) {
4532 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004533 } finally {
4534 Binder.restoreCallingIdentity(identity);
4535 }
4536 }
4537
4538 @Override
4539 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4540 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4541 "setVoWiFiRoamingModeSetting");
4542 final long identity = Binder.clearCallingIdentity();
4543 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004544 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004545 // This setting doesn't require an active ImsService connection, so do not verify. The
4546 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004547 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004548 } catch (ImsException e) {
4549 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004550 } finally {
4551 Binder.restoreCallingIdentity(identity);
4552 }
4553 }
4554
4555 @Override
4556 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4557 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4558 "setRttCapabilityEnabled");
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. The
4563 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004564 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004565 } catch (ImsException e) {
4566 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004567 } finally {
4568 Binder.restoreCallingIdentity(identity);
4569 }
4570 }
4571
shilu366312e2019-12-17 09:28:10 -08004572 /**
4573 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4574 * @param subId The subscription to use to check the configuration.
4575 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004576 @Override
4577 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004578 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004579 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004580 final long identity = Binder.clearCallingIdentity();
4581 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004582 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004583 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004584 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004585 } catch (ImsException e) {
4586 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004587 } finally {
4588 Binder.restoreCallingIdentity(identity);
4589 }
4590 }
4591
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004592 @Override
4593 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4594 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004595
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004596 final long identity = Binder.clearCallingIdentity();
4597 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004598 if (!isImsAvailableOnDevice()) {
4599 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4600 "IMS not available on device.");
4601 }
4602 int slotId = getSlotIndexOrException(subId);
4603 verifyImsMmTelConfiguredOrThrow(slotId);
4604 ImsManager.getInstance(mApp, slotId)
4605 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004606 } catch (ImsException e) {
4607 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004608 } finally {
4609 Binder.restoreCallingIdentity(identity);
4610 }
4611 }
4612
4613 @Override
4614 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4615 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004616
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004617 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004618 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4619 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4620 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004621 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004622 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004623 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004624 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004625 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4626 + "is inactive, ignoring unregister.");
4627 // If the subscription is no longer active, just return, since the callback will already
4628 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004629 } finally {
4630 Binder.restoreCallingIdentity(identity);
4631 }
4632 }
4633
joonhunshincffb7fc2021-11-28 07:32:01 +00004634 @Override
4635 public void registerFeatureProvisioningChangedCallback(int subId,
4636 IFeatureProvisioningCallback callback) {
4637 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4638 mApp, subId, "registerFeatureProvisioningChangedCallback");
4639
4640 final long identity = Binder.clearCallingIdentity();
4641 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4642 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4643 }
4644
4645 ImsProvisioningController.getInstance()
4646 .addFeatureProvisioningChangedCallback(subId, callback);
4647
4648 Binder.restoreCallingIdentity(identity);
4649 }
4650
4651 @Override
4652 public void unregisterFeatureProvisioningChangedCallback(int subId,
4653 IFeatureProvisioningCallback callback) {
4654 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4655 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4656
4657 final long identity = Binder.clearCallingIdentity();
4658 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4659 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4660 }
4661
4662 ImsProvisioningController.getInstance()
4663 .removeFeatureProvisioningChangedCallback(subId, callback);
4664
4665 Binder.restoreCallingIdentity(identity);
4666 }
allenwtsu99c623b2020-01-03 18:24:23 +08004667
4668 private void checkModifyPhoneStatePermission(int subId, String message) {
4669 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4670 message);
4671 }
4672
4673 private boolean isImsProvisioningRequired(int subId, int capability,
4674 boolean isMmtelCapability) {
4675 Phone phone = getPhone(subId);
4676 if (phone == null) {
4677 loge("phone instance null for subid " + subId);
4678 return false;
4679 }
4680 if (isMmtelCapability) {
4681 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4682 return false;
4683 }
4684 } else {
4685 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4686 return false;
4687 }
4688 }
4689 return true;
4690 }
4691
4692 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004693 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004694 boolean isProvisioned) {
4695 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4696
4697 final long identity = Binder.clearCallingIdentity();
4698 try {
joonhunshincffb7fc2021-11-28 07:32:01 +00004699 ImsProvisioningController.getInstance()
4700 .setRcsProvisioningStatusForCapability(subId, capability, tech, isProvisioned);
4701 return;
allenwtsu99c623b2020-01-03 18:24:23 +08004702 } finally {
4703 Binder.restoreCallingIdentity(identity);
4704 }
allenwtsu99c623b2020-01-03 18:24:23 +08004705 }
4706
4707
4708 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004709 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4710 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4711 mApp, subId, "getRcsProvisioningStatusForCapability");
4712
allenwtsu99c623b2020-01-03 18:24:23 +08004713 final long identity = Binder.clearCallingIdentity();
4714 try {
joonhunshincffb7fc2021-11-28 07:32:01 +00004715 return ImsProvisioningController.getInstance()
4716 .getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004717 } finally {
4718 Binder.restoreCallingIdentity(identity);
4719 }
4720 }
4721
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004722 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004723 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4724 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004725 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004726
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004727 final long identity = Binder.clearCallingIdentity();
4728 try {
joonhunshincffb7fc2021-11-28 07:32:01 +00004729 ImsProvisioningController.getInstance()
4730 .setImsProvisioningStatusForCapability(subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004731 } finally {
4732 Binder.restoreCallingIdentity(identity);
4733 }
4734 }
4735
4736 @Override
4737 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00004738 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4739 mApp, subId, "getProvisioningStatusForCapability");
4740
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004741 final long identity = Binder.clearCallingIdentity();
4742 try {
joonhunshincffb7fc2021-11-28 07:32:01 +00004743 return ImsProvisioningController.getInstance()
4744 .getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004745
4746 } finally {
4747 Binder.restoreCallingIdentity(identity);
4748 }
4749 }
4750
4751 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004752 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4753 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4754 mApp, subId, "isProvisioningRequiredForCapability");
4755
4756 final long identity = Binder.clearCallingIdentity();
4757 try {
4758 return ImsProvisioningController.getInstance()
4759 .isImsProvisioningRequiredForCapability(subId, capability, tech);
4760 } finally {
4761 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004762 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004763 }
4764
4765 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004766 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4767 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4768 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004769
joonhunshincffb7fc2021-11-28 07:32:01 +00004770 final long identity = Binder.clearCallingIdentity();
4771 try {
4772 return ImsProvisioningController.getInstance()
4773 .isRcsProvisioningRequiredForCapability(subId, capability, tech);
4774 } finally {
4775 Binder.restoreCallingIdentity(identity);
4776 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004777 }
4778
4779 private static String getMmTelProvisioningKey(int subId, int tech) {
4780 // resulting key is provision_ims_mmtel_{subId}_{tech}
4781 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4782 }
4783
4784 /**
4785 * Query CarrierConfig to see if the specified capability requires provisioning for the
4786 * carrier associated with the subscription id.
4787 */
4788 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4789 int capability) {
4790 CarrierConfigManager configManager = new CarrierConfigManager(context);
4791 PersistableBundle c = configManager.getConfigForSubId(subId);
4792 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004793 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004794 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4795 false);
4796 boolean requireVoiceVtProvisioning = c.getBoolean(
4797 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4798
4799 // First check to make sure that the capability requires provisioning.
4800 switch (capability) {
4801 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4802 // intentional fallthrough
4803 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4804 if (requireVoiceVtProvisioning) {
4805 // Voice and Video requires provisioning
4806 return true;
4807 }
4808 break;
4809 }
4810 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4811 if (requireUtProvisioning) {
4812 // UT requires provisioning
4813 return true;
4814 }
4815 break;
4816 }
4817 }
4818 return false;
4819 }
4820
allenwtsu99c623b2020-01-03 18:24:23 +08004821 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4822 int capability) {
4823 CarrierConfigManager configManager = new CarrierConfigManager(context);
4824 PersistableBundle c = configManager.getConfigForSubId(subId);
4825
4826 boolean requireRcsProvisioning = c.getBoolean(
4827 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4828
4829 // First check to make sure that the capability requires provisioning.
4830 switch (capability) {
4831 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4832 // intentional fallthrough
4833 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4834 if (requireRcsProvisioning) {
4835 // OPTION or PRESENCE requires provisioning
4836 return true;
4837 }
4838 break;
4839 }
4840 }
4841 return false;
4842 }
4843
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004844 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004845 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004846 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4847 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4848 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004849 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4850 mApp, subId, "getImsProvisioningInt");
4851
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004852 final long identity = Binder.clearCallingIdentity();
4853 try {
4854 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004855 int slotId = getSlotIndex(subId);
4856 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4857 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4858 + subId + "' for key:" + key);
4859 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4860 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004861
4862 int retVal = ImsProvisioningController.getInstance().getProvisioningValue(subId, key);
4863 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4864 return retVal;
4865 }
4866
calvinpanb5a34062021-02-08 19:59:36 +08004867 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004868 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004869 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4870 + subId + "' for key:" + key);
4871 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004872 } finally {
4873 Binder.restoreCallingIdentity(identity);
4874 }
4875 }
4876
4877 @Override
4878 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004879 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4880 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4881 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004882 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4883 mApp, subId, "getImsProvisioningString");
4884
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004885 final long identity = Binder.clearCallingIdentity();
4886 try {
4887 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004888 int slotId = getSlotIndex(subId);
4889 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4890 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4891 + subId + "' for key:" + key);
4892 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4893 }
calvinpanb5a34062021-02-08 19:59:36 +08004894 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004895 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004896 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4897 + subId + "' for key:" + key);
4898 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004899 } finally {
4900 Binder.restoreCallingIdentity(identity);
4901 }
4902 }
4903
4904 @Override
4905 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004906 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4907 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4908 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004909 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4910 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00004911
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004912 final long identity = Binder.clearCallingIdentity();
4913 try {
4914 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004915 int slotId = getSlotIndex(subId);
4916 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4917 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4918 + subId + "' for key:" + key);
4919 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4920 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004921
4922 int retVal = ImsProvisioningController.getInstance()
4923 .setProvisioningValue(subId, key, value);
4924 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4925 return retVal;
4926 }
4927
calvinpanb5a34062021-02-08 19:59:36 +08004928 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4929 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004930 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004931 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004932 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004933 } finally {
4934 Binder.restoreCallingIdentity(identity);
4935 }
4936 }
4937
4938 @Override
4939 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004940 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4941 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4942 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004943 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4944 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004945 final long identity = Binder.clearCallingIdentity();
4946 try {
4947 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004948 int slotId = getSlotIndex(subId);
4949 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4950 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4951 + subId + "' for key:" + key);
4952 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4953 }
calvinpanb5a34062021-02-08 19:59:36 +08004954 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4955 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004956 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004957 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004958 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004959 } finally {
4960 Binder.restoreCallingIdentity(identity);
4961 }
4962 }
4963
Brad Ebinger919631e2021-06-02 17:46:35 -07004964 /**
4965 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4966 * for the given slot ID or no ImsResolver instance has been created.
4967 * @param slotId The slot ID that the IMS service is created for.
4968 * @throws ImsException If there is no ImsService configured for this slot.
4969 */
4970 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4971 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4972 ImsFeature.FEATURE_MMTEL)) {
4973 throw new ImsException("This subscription does not support MMTEL over IMS",
4974 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4975 }
4976 }
4977
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004978 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004979 int slotId = SubscriptionManager.getSlotIndex(subId);
4980 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004981 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4982 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004983 }
4984 return slotId;
4985 }
4986
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004987 private int getSlotIndex(int subId) {
4988 int slotId = SubscriptionManager.getSlotIndex(subId);
4989 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4990 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4991 }
4992 return slotId;
4993 }
4994
Wink Saville36469e72014-06-11 15:17:00 -07004995 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004996 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004997 */
4998 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004999 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5000 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005001 try {
5002 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5003 } catch (SecurityException se) {
5004 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5005 throw new SecurityException("Package " + callingPackage + " does not belong to "
5006 + Binder.getCallingUid());
5007 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005008 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005009 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005010 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005011 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005012 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005013 mApp, subId, callingPackage, callingFeatureId,
5014 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005015 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5016 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005017
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005018 final long identity = Binder.clearCallingIdentity();
5019 try {
5020 final Phone phone = getPhone(subId);
5021 if (phone != null) {
5022 return phone.getServiceState().getDataNetworkType();
5023 } else {
5024 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5025 }
5026 } finally {
5027 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005028 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005029 }
5030
5031 /**
5032 * Returns the data network type
5033 */
5034 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005035 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005036 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5037 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005038 }
5039
5040 /**
5041 * Returns the data network type for a subId
5042 */
5043 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005044 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5045 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005046 String functionName = "getDataNetworkTypeForSubscriber";
5047 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5048 mApp, functionName)) {
5049 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5050 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5051 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5052 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005053 }
5054
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005055 final long identity = Binder.clearCallingIdentity();
5056 try {
5057 final Phone phone = getPhone(subId);
5058 if (phone != null) {
5059 return phone.getServiceState().getDataNetworkType();
5060 } else {
5061 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5062 }
5063 } finally {
5064 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005065 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005066 }
5067
5068 /**
Wink Saville36469e72014-06-11 15:17:00 -07005069 * Returns the Voice network type for a subId
5070 */
5071 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005072 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5073 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005074 String functionName = "getVoiceNetworkTypeForSubscriber";
5075 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5076 mApp, functionName)) {
5077 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5078 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5079 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5080 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005081 }
5082
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005083 final long identity = Binder.clearCallingIdentity();
5084 try {
5085 final Phone phone = getPhone(subId);
5086 if (phone != null) {
5087 return phone.getServiceState().getVoiceNetworkType();
5088 } else {
5089 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5090 }
5091 } finally {
5092 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005093 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005094 }
5095
5096 /**
5097 * @return true if a ICC card is present
5098 */
5099 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005100 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005101 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5102 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005103 }
5104
5105 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005106 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005107 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005108 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005109 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005110 final long identity = Binder.clearCallingIdentity();
5111 try {
5112 final Phone phone = PhoneFactory.getPhone(slotIndex);
5113 if (phone != null) {
5114 return phone.getIccCard().hasIccCard();
5115 } else {
5116 return false;
5117 }
5118 } finally {
5119 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005120 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005121 }
5122
5123 /**
5124 * Return if the current radio is LTE on CDMA. This
5125 * is a tri-state return value as for a period of time
5126 * the mode may be unknown.
5127 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005128 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005129 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005130 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005131 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005132 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005133 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5134 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5135 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005136 }
5137
Sanket Padawe356d7632015-06-22 14:03:32 -07005138 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005139 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5140 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005141 try {
5142 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5143 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005144 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5145 }
5146
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005147 final long identity = Binder.clearCallingIdentity();
5148 try {
5149 final Phone phone = getPhone(subId);
5150 if (phone == null) {
5151 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5152 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005153 return TelephonyProperties.lte_on_cdma_device()
5154 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005155 }
5156 } finally {
5157 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005158 }
Wink Saville36469e72014-06-11 15:17:00 -07005159 }
5160
Wink Saville36469e72014-06-11 15:17:00 -07005161 /**
5162 * {@hide}
5163 * Returns Default subId, 0 in the case of single standby.
5164 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005165 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005166 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005167 }
5168
Shishir Agrawala9f32182016-04-12 12:00:16 -07005169 private int getSlotForDefaultSubscription() {
5170 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5171 }
5172
Wink Savilleb564aae2014-10-23 10:18:09 -07005173 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005174 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005175 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005176
Pengquan Menge92a50d2018-09-21 15:54:48 -07005177 private boolean isActiveSubscription(int subId) {
5178 return mSubscriptionController.isActiveSubId(subId);
5179 }
5180
Ihab Awadf2177b72013-11-25 13:33:23 -08005181 /**
5182 * @see android.telephony.TelephonyManager.WifiCallingChoices
5183 */
5184 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005185 final long identity = Binder.clearCallingIdentity();
5186 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005187 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005188 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5189 getWhenToMakeWifiCallsDefaultPreference());
5190 } finally {
5191 Binder.restoreCallingIdentity(identity);
5192 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005193 }
5194
5195 /**
5196 * @see android.telephony.TelephonyManager.WifiCallingChoices
5197 */
5198 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005199 final long identity = Binder.clearCallingIdentity();
5200 try {
5201 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005202 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005203 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5204 } finally {
5205 Binder.restoreCallingIdentity(identity);
5206 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005207 }
5208
Sailesh Nepald1e68152013-12-12 19:08:02 -08005209 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005210 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005211 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005212 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005213
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005214 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5215 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5216 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005217 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005218 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5219 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005220 }
5221 return PhoneFactory.getPhone(phoneId);
5222 }
5223
Shishir Agrawal566b7612013-10-28 14:41:00 -07005224 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005225 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005226 @NonNull IccLogicalChannelRequest request) {
5227 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5228 /*message=*/ "iccOpenLogicalChannel");
5229
5230 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5231 // Verify that the callingPackage in the request belongs to the calling UID
5232 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5233
5234 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005235 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005236
Rambo Wanga1782702021-11-10 20:15:19 -08005237 private Phone getPhoneFromValidIccLogicalChannelRequest(
5238 @NonNull IccLogicalChannelRequest request, String message) {
5239 Phone phone;
5240 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5241 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5242 mApp, request.subId, message);
5243 phone = getPhoneFromSubId(request.subId);
5244 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5245 enforceModifyPermission();
5246 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5247 } else {
5248 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005249 }
Rambo Wanga1782702021-11-10 20:15:19 -08005250 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005251 }
5252
5253 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005254 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005255 final long identity = Binder.clearCallingIdentity();
5256 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005257 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005258 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005259 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5260 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005261 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5262 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005263 loge("The calling package is not allowed to access ISD-R.");
5264 throw new SecurityException(
5265 "The calling package is not allowed to access ISD-R.");
5266 }
Derek Tan740e1672017-06-27 14:56:27 -07005267 }
Derek Tan740e1672017-06-27 14:56:27 -07005268
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005269 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005270 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5271 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005272 return response;
5273 } finally {
5274 Binder.restoreCallingIdentity(identity);
5275 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005276 }
5277
5278 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005279 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5280 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5281 /*message=*/"iccCloseLogicalChannel");
5282
5283 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5284
5285 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005286 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005287
Rambo Wanga1782702021-11-10 20:15:19 -08005288 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5289 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005290 // before this feature is enabled, this API should only return false if
5291 // the operation fails instead of throwing runtime exception for
5292 // backward-compatibility.
5293 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5294 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005295 final long identity = Binder.clearCallingIdentity();
5296 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005297 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005298 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005299 }
Chen Xue9d737e2022-01-01 23:41:31 -08005300 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005301 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005302 Boolean success = false;
5303 if (result instanceof RuntimeException) {
5304 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005305 if (shouldThrowExceptionOnFailure) {
5306 throw (RuntimeException) result;
5307 } else {
5308 return false;
5309 }
Chen Xue9d737e2022-01-01 23:41:31 -08005310 } else if (result instanceof Boolean) {
5311 success = (Boolean) result;
5312 } else {
5313 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5314 }
Rambo Wanga1782702021-11-10 20:15:19 -08005315 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005316 return success;
5317 } finally {
5318 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005319 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005320 }
5321
5322 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005323 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005324 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005325 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5326 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005327 if (DBG) {
5328 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5329 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5330 + p3 + " data=" + data);
5331 }
5332 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5333 command, p1, p2, p3, data);
5334 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005335
Jordan Liu4c733742019-02-28 12:03:40 -08005336 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005337 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5338 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005339 enforceModifyPermission();
5340 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005341 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5342 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5343 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005344 }
5345 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005346 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5347 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005348 }
5349
5350 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5351 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005352 final long identity = Binder.clearCallingIdentity();
5353 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005354 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005355 return "";
5356 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005357
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005358 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005359 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5360 null /* workSource */);
5361 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005362
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005363 // Append the returned status code to the end of the response payload.
5364 String s = Integer.toHexString(
5365 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5366 if (response.payload != null) {
5367 s = IccUtils.bytesToHexString(response.payload) + s;
5368 }
5369 return s;
5370 } finally {
5371 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005372 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005373 }
Jake Hambye994d462014-02-03 13:10:13 -08005374
Evan Charltonc66da362014-05-16 14:06:40 -07005375 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005376 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5377 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005378 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5379 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005380 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005381 if (DBG) {
5382 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5383 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5384 }
5385 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5386 cla, command, p1, p2, p3, data);
5387 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005388
Jordan Liu4c733742019-02-28 12:03:40 -08005389 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005390 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5391 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005392 enforceModifyPermission();
5393 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5394 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005395 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5396 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5397 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005398 }
5399
5400 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005401 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5402 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005403 }
5404
5405 // open APDU basic channel assuming the caller has sufficient permissions
5406 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5407 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005408 final long identity = Binder.clearCallingIdentity();
5409 try {
5410 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5411 && TextUtils.equals(ISDR_AID, data)) {
5412 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005413 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5414 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005415 if (bestComponent == null
5416 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5417 loge("The calling package is not allowed to select ISD-R.");
5418 throw new SecurityException(
5419 "The calling package is not allowed to select ISD-R.");
5420 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005421 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005422
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005423 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005424 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5425 null /* workSource */);
5426 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005427
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005428 // Append the returned status code to the end of the response payload.
5429 String s = Integer.toHexString(
5430 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5431 if (response.payload != null) {
5432 s = IccUtils.bytesToHexString(response.payload) + s;
5433 }
5434 return s;
5435 } finally {
5436 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005437 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005438 }
5439
5440 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005441 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005442 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005443 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5444 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005445
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005446 final long identity = Binder.clearCallingIdentity();
5447 try {
5448 if (DBG) {
5449 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5450 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5451 }
5452
5453 IccIoResult response =
5454 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5455 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5456 subId);
5457
5458 if (DBG) {
5459 log("Exchange SIM_IO [R]" + response);
5460 }
5461
5462 byte[] result = null;
5463 int length = 2;
5464 if (response.payload != null) {
5465 length = 2 + response.payload.length;
5466 result = new byte[length];
5467 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5468 } else {
5469 result = new byte[length];
5470 }
5471
5472 result[length - 1] = (byte) response.sw2;
5473 result[length - 2] = (byte) response.sw1;
5474 return result;
5475 } finally {
5476 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005477 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005478 }
5479
Nathan Haroldb3014052017-01-25 15:57:32 -08005480 /**
5481 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5482 * on a particular subscription
5483 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005484 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5485 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005486 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005487 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005488 return null;
5489 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005490
5491 final long identity = Binder.clearCallingIdentity();
5492 try {
5493 if (appType != TelephonyManager.APPTYPE_USIM
5494 && appType != TelephonyManager.APPTYPE_SIM) {
5495 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5496 return null;
5497 }
5498 Object response = sendRequest(
5499 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5500 if (response instanceof String[]) {
5501 return (String[]) response;
5502 }
yincheng zhao2737e882019-09-06 17:06:54 -07005503 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005504 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005505 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005506 } finally {
5507 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005508 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005509 }
5510
yincheng zhao2737e882019-09-06 17:06:54 -07005511 /**
5512 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5513 * subscription.
5514 *
5515 * @param subId the id of the subscription.
5516 * @param appType the uicc app type, must be USIM or SIM.
5517 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5518 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005519 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005520 * @return number of fplmns that is successfully written to the SIM.
5521 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005522 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5523 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005524 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5525 mApp, subId, "setForbiddenPlmns");
5526
yincheng zhao2737e882019-09-06 17:06:54 -07005527 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5528 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5529 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5530 }
5531 if (fplmns == null) {
5532 throw new IllegalArgumentException("Fplmn List provided is null");
5533 }
5534 for (String fplmn : fplmns) {
5535 if (!CellIdentity.isValidPlmn(fplmn)) {
5536 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5537 }
5538 }
5539 final long identity = Binder.clearCallingIdentity();
5540 try {
5541 Object response = sendRequest(
5542 CMD_SET_FORBIDDEN_PLMNS,
5543 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5544 subId);
5545 return (int) response;
5546 } finally {
5547 Binder.restoreCallingIdentity(identity);
5548 }
5549 }
5550
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005551 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005552 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005553 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5554 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005555
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005556 final long identity = Binder.clearCallingIdentity();
5557 try {
5558 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5559 if (response.payload == null) {
5560 return "";
5561 }
Evan Charltonc66da362014-05-16 14:06:40 -07005562
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005563 // Append the returned status code to the end of the response payload.
5564 String s = Integer.toHexString(
5565 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5566 s = IccUtils.bytesToHexString(response.payload) + s;
5567 return s;
5568 } finally {
5569 Binder.restoreCallingIdentity(identity);
5570 }
Evan Charltonc66da362014-05-16 14:06:40 -07005571 }
5572
Jake Hambye994d462014-02-03 13:10:13 -08005573 /**
5574 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5575 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5576 *
5577 * @param itemID the ID of the item to read
5578 * @return the NV item as a String, or null on error.
5579 */
5580 @Override
5581 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005582 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005583 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5584 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005585
5586 final long identity = Binder.clearCallingIdentity();
5587 try {
5588 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005589 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005590 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5591 return value;
5592 } finally {
5593 Binder.restoreCallingIdentity(identity);
5594 }
Jake Hambye994d462014-02-03 13:10:13 -08005595 }
5596
5597 /**
5598 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5599 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5600 *
5601 * @param itemID the ID of the item to read
5602 * @param itemValue the value to write, as a String
5603 * @return true on success; false on any failure
5604 */
5605 @Override
5606 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005607 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005608 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5609 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005610
5611 final long identity = Binder.clearCallingIdentity();
5612 try {
5613 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5614 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005615 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005616 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5617 return success;
5618 } finally {
5619 Binder.restoreCallingIdentity(identity);
5620 }
Jake Hambye994d462014-02-03 13:10:13 -08005621 }
5622
5623 /**
5624 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5625 * Used for device configuration by some CDMA operators.
5626 *
5627 * @param preferredRoamingList byte array containing the new PRL
5628 * @return true on success; false on any failure
5629 */
5630 @Override
5631 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005632 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5633 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005634
5635 final long identity = Binder.clearCallingIdentity();
5636 try {
5637 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5638 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5639 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5640 return success;
5641 } finally {
5642 Binder.restoreCallingIdentity(identity);
5643 }
Jake Hambye994d462014-02-03 13:10:13 -08005644 }
5645
5646 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005647 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005648 * Used for device configuration by some CDMA operators.
5649 *
chen xu6dac5ab2018-10-26 17:39:23 -07005650 * @param slotIndex - device slot.
5651 *
Jake Hambye994d462014-02-03 13:10:13 -08005652 * @return true on success; false on any failure
5653 */
5654 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005655 public boolean resetModemConfig(int slotIndex) {
5656 Phone phone = PhoneFactory.getPhone(slotIndex);
5657 if (phone != null) {
5658 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5659 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005660
chen xu6dac5ab2018-10-26 17:39:23 -07005661 final long identity = Binder.clearCallingIdentity();
5662 try {
5663 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5664 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5665 return success;
5666 } finally {
5667 Binder.restoreCallingIdentity(identity);
5668 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005669 }
chen xu6dac5ab2018-10-26 17:39:23 -07005670 return false;
5671 }
5672
5673 /**
5674 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5675 *
5676 * @param slotIndex - device slot.
5677 *
5678 * @return true on success; false on any failure
5679 */
5680 @Override
5681 public boolean rebootModem(int slotIndex) {
5682 Phone phone = PhoneFactory.getPhone(slotIndex);
5683 if (phone != null) {
5684 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5685 mApp, phone.getSubId(), "rebootModem");
5686
5687 final long identity = Binder.clearCallingIdentity();
5688 try {
5689 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5690 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5691 return success;
5692 } finally {
5693 Binder.restoreCallingIdentity(identity);
5694 }
5695 }
5696 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005697 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005698
Brad Ebinger51f743a2017-01-23 13:50:20 -08005699 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005700 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5701 * {@link #disableIms(int)}.
5702 * @param slotIndex device slot.
5703 */
5704 public void resetIms(int slotIndex) {
5705 enforceModifyPermission();
5706
5707 final long identity = Binder.clearCallingIdentity();
5708 try {
5709 if (mImsResolver == null) {
5710 // may happen if the does not support IMS.
5711 return;
5712 }
5713 mImsResolver.disableIms(slotIndex);
5714 mImsResolver.enableIms(slotIndex);
5715 } finally {
5716 Binder.restoreCallingIdentity(identity);
5717 }
5718 }
5719
5720 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005721 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5722 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005723 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005724 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005725 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005726
5727 final long identity = Binder.clearCallingIdentity();
5728 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005729 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005730 // may happen if the device does not support IMS.
5731 return;
5732 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005733 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005734 } finally {
5735 Binder.restoreCallingIdentity(identity);
5736 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005737 }
5738
5739 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005740 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5741 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005742 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005743 public void disableIms(int slotId) {
5744 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005745
5746 final long identity = Binder.clearCallingIdentity();
5747 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005748 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005749 // may happen if the device does not support IMS.
5750 return;
5751 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005752 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005753 } finally {
5754 Binder.restoreCallingIdentity(identity);
5755 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005756 }
5757
5758 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005759 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5760 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005761 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005762 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005763 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005764 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005765
5766 final long identity = Binder.clearCallingIdentity();
5767 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005768 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005769 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5770 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005771 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005772 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005773 } finally {
5774 Binder.restoreCallingIdentity(identity);
5775 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005776 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005777 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005778 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5779 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005780 @Override
5781 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005782 enforceModifyPermission();
5783
5784 final long identity = Binder.clearCallingIdentity();
5785 try {
5786 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005787 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005788 } finally {
5789 Binder.restoreCallingIdentity(identity);
5790 }
5791 }
5792
5793 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005794 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005795 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005796 */
5797 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5798 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005799
5800 final long identity = Binder.clearCallingIdentity();
5801 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005802 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005803 // may happen if the device does not support IMS.
5804 return null;
5805 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005806 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005807 } finally {
5808 Binder.restoreCallingIdentity(identity);
5809 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005810 }
5811
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005812 /**
5813 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005814 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005815 */
5816 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5817 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005818
5819 final long identity = Binder.clearCallingIdentity();
5820 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005821 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005822 // may happen if the device does not support IMS.
5823 return null;
5824 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005825 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005826 } finally {
5827 Binder.restoreCallingIdentity(identity);
5828 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005829 }
5830
Brad Ebinger884c07b2018-02-15 16:17:40 -08005831 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005832 * Sets the ImsService Package Name that Telephony will bind to.
5833 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005834 * @param slotIndex the slot ID that the ImsService should bind for.
5835 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005836 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005837 * @param featureTypes An integer array of feature types associated with a packageName.
5838 * @param packageName The name of the package that the current configuration will be replaced
5839 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005840 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005841 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005842 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5843 int[] featureTypes, String packageName) {
5844 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5845 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005846 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5847 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005848 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005849
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005850 final long identity = Binder.clearCallingIdentity();
5851 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005852 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005853 // may happen if the device does not support IMS.
5854 return false;
5855 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005856 Map<Integer, String> featureConfig = new HashMap<>();
5857 for (int featureType : featureTypes) {
5858 featureConfig.put(featureType, packageName);
5859 }
5860 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5861 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005862 } finally {
5863 Binder.restoreCallingIdentity(identity);
5864 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005865 }
5866
5867 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005868 * Clears any carrier ImsService overrides for the slot index specified that were previously
5869 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5870 *
5871 * This should only be used for testing.
5872 *
5873 * @param slotIndex the slot ID that the ImsService should bind for.
5874 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5875 */
5876 @Override
5877 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5878 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5879 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5880 "clearCarrierImsServiceOverride");
5881 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5882 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5883 "clearCarrierImsServiceOverride");
5884
5885 final long identity = Binder.clearCallingIdentity();
5886 try {
5887 if (mImsResolver == null) {
5888 // may happen if the device does not support IMS.
5889 return false;
5890 }
5891 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5892 } finally {
5893 Binder.restoreCallingIdentity(identity);
5894 }
5895 }
5896
5897 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005898 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005899 *
5900 * @param slotId The slot that the ImsService is associated with.
5901 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5902 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005903 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005904 * @return the package name of the ImsService configuration.
5905 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005906 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5907 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005908 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005909 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005910 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005911 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5912 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005913
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005914 final long identity = Binder.clearCallingIdentity();
5915 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005916 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005917 // may happen if the device does not support IMS.
5918 return "";
5919 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005920 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005921 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5922 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005923 } finally {
5924 Binder.restoreCallingIdentity(identity);
5925 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005926 }
5927
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005928 /**
5929 * Get the MmTelFeature state associated with the requested subscription id.
5930 * @param subId The subscription that the MmTelFeature is associated with.
5931 * @param callback A callback with an integer containing the
5932 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5933 */
5934 @Override
5935 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5936 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00005937 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5938 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5939 "IMS not available on device.");
5940 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005941 final long token = Binder.clearCallingIdentity();
5942 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005943 int slotId = getSlotIndex(subId);
5944 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5945 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5946 + subId + "'");
5947 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5948 }
5949 verifyImsMmTelConfiguredOrThrow(slotId);
5950 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5951 try {
5952 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5953 } catch (RemoteException e) {
5954 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5955 + "Ignore");
5956 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005957 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005958 } catch (ImsException e) {
5959 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005960 } finally {
5961 Binder.restoreCallingIdentity(token);
5962 }
5963 }
5964
Daniel Brightbb5840b2021-01-12 15:48:18 -08005965 /**
5966 * Sets the ims registration state on all valid {@link Phone}s.
5967 */
5968 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005969 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005970
5971 final long identity = Binder.clearCallingIdentity();
5972 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005973 // NOTE: Before S, this method only set the default phone.
5974 for (final Phone phone : PhoneFactory.getPhones()) {
5975 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5976 phone.setImsRegistrationState(registered);
5977 }
5978 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005979 } finally {
5980 Binder.restoreCallingIdentity(identity);
5981 }
Wink Saville36469e72014-06-11 15:17:00 -07005982 }
5983
5984 /**
Stuart Scott54788802015-03-30 13:18:01 -07005985 * Set the network selection mode to automatic.
5986 *
5987 */
5988 @Override
5989 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005990 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5991 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005992
5993 final long identity = Binder.clearCallingIdentity();
5994 try {
shilufc958392020-01-20 11:36:01 -08005995 if (!isActiveSubscription(subId)) {
5996 return;
5997 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005998 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005999 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6000 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006001 } finally {
6002 Binder.restoreCallingIdentity(identity);
6003 }
Stuart Scott54788802015-03-30 13:18:01 -07006004 }
6005
Jack Yud10cdd42020-09-28 20:28:01 -07006006 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006007 * Ask the radio to connect to the input network and change selection mode to manual.
6008 *
6009 * @param subId the id of the subscription.
6010 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6011 * the operator to attach to.
6012 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6013 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6014 * normal network selection next time.
6015 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006016 */
6017 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006018 public boolean setNetworkSelectionModeManual(
6019 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006020 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6021 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006022
6023 if (!isActiveSubscription(subId)) {
6024 return false;
6025 }
6026
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006027 final long identity = Binder.clearCallingIdentity();
6028 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006029 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006030 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006031 if (DBG) {
6032 log("setNetworkSelectionModeManual: subId: " + subId
6033 + " operator: " + operatorInfo);
6034 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006035 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6036 } finally {
6037 Binder.restoreCallingIdentity(identity);
6038 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006039 }
shilu84f6e8b2019-12-19 13:58:01 -08006040 /**
6041 * Get the manual network selection
6042 *
6043 * @param subId the id of the subscription.
6044 *
6045 * @return the previously saved user selected PLMN
6046 */
6047 @Override
6048 public String getManualNetworkSelectionPlmn(int subId) {
6049 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006050 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006051 mApp, subId, "getManualNetworkSelectionPlmn");
6052
6053 final long identity = Binder.clearCallingIdentity();
6054 try {
6055 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006056 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006057 }
6058
6059 final Phone phone = getPhone(subId);
6060 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006061 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006062 }
6063 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6064 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6065 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6066 } finally {
6067 Binder.restoreCallingIdentity(identity);
6068 }
6069 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006070
6071 /**
6072 * Scans for available networks.
6073 */
6074 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006075 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6076 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006077 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6078 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006079 LocationAccessPolicy.LocationPermissionResult locationResult =
6080 LocationAccessPolicy.checkLocationPermission(mApp,
6081 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6082 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006083 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006084 .setCallingPid(Binder.getCallingPid())
6085 .setCallingUid(Binder.getCallingUid())
6086 .setMethod("getCellNetworkScanResults")
6087 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006088 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6089 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006090 .build());
6091 switch (locationResult) {
6092 case DENIED_HARD:
6093 throw new SecurityException("Not allowed to access scan results -- location");
6094 case DENIED_SOFT:
6095 return null;
6096 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006097
Pengquan Menga1bb6272018-09-06 09:59:22 -07006098 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006099 try {
6100 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006101 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006102 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006103 } finally {
6104 Binder.restoreCallingIdentity(identity);
6105 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006106 }
6107
6108 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006109 * Get the call forwarding info, given the call forwarding reason.
6110 */
6111 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006112 public void getCallForwarding(int subId, int callForwardingReason,
6113 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006114 enforceReadPrivilegedPermission("getCallForwarding");
6115 long identity = Binder.clearCallingIdentity();
6116 try {
6117 if (DBG) {
6118 log("getCallForwarding: subId " + subId
6119 + " callForwardingReason" + callForwardingReason);
6120 }
Hall Liu27d24262020-09-18 19:04:59 -07006121
6122 Phone phone = getPhone(subId);
6123 if (phone == null) {
6124 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006125 callback.onError(
6126 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006127 } catch (RemoteException e) {
6128 // ignore
6129 }
6130 return;
6131 }
6132
6133 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6134 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6135 @Override
6136 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6137 try {
6138 callback.onCallForwardingInfoAvailable(info);
6139 } catch (RemoteException e) {
6140 // ignore
6141 }
6142 }
6143
6144 @Override
6145 public void onError(int error) {
6146 try {
6147 callback.onError(error);
6148 } catch (RemoteException e) {
6149 // ignore
6150 }
6151 }
6152 });
6153 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006154 } finally {
6155 Binder.restoreCallingIdentity(identity);
6156 }
6157 }
6158
6159 /**
6160 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6161 * reason, the number to forward, and the timeout before the forwarding is attempted.
6162 */
6163 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006164 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6165 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006166 enforceModifyPermission();
6167 long identity = Binder.clearCallingIdentity();
6168 try {
6169 if (DBG) {
6170 log("setCallForwarding: subId " + subId
6171 + " callForwardingInfo" + callForwardingInfo);
6172 }
Hall Liu27d24262020-09-18 19:04:59 -07006173
6174 Phone phone = getPhone(subId);
6175 if (phone == null) {
6176 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006177 callback.accept(
6178 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006179 } catch (RemoteException e) {
6180 // ignore
6181 }
6182 return;
6183 }
6184
6185 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6186 FunctionalUtils.ignoreRemoteException(callback::accept));
6187
6188 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006189 } finally {
6190 Binder.restoreCallingIdentity(identity);
6191 }
6192 }
6193
6194 /**
Hall Liu27d24262020-09-18 19:04:59 -07006195 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006196 */
6197 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006198 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006199 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006200 long identity = Binder.clearCallingIdentity();
6201 try {
Hall Liu27d24262020-09-18 19:04:59 -07006202 Phone phone = getPhone(subId);
6203 if (phone == null) {
6204 try {
6205 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6206 } catch (RemoteException e) {
6207 // ignore
6208 }
6209 return;
6210 }
SongFerngWang0e767992021-03-31 22:08:45 +08006211 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6212 PersistableBundle c = configManager.getConfigForSubId(subId);
6213 boolean requireUssd = c.getBoolean(
6214 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006215
Shuo Qian4a594052020-01-23 11:59:30 -08006216 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006217 if (requireUssd) {
6218 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6219 getSubscriptionCarrierId(subId));
6220 String newUssdCommand = "";
6221 try {
6222 newUssdCommand = carrierXmlParser.getFeature(
6223 CarrierXmlParser.FEATURE_CALL_WAITING)
6224 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6225 } catch (NullPointerException e) {
6226 loge("Failed to generate USSD number" + e);
6227 }
6228 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6229 mMainThreadHandler, callback, carrierXmlParser,
6230 CarrierXmlParser.SsEntry.SSAction.QUERY);
6231 final String ussdCommand = newUssdCommand;
6232 Executors.newSingleThreadExecutor().execute(() -> {
6233 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6234 });
6235 } else {
6236 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6237 callback::accept);
6238 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6239 }
Shuo Qian4a594052020-01-23 11:59:30 -08006240 } finally {
6241 Binder.restoreCallingIdentity(identity);
6242 }
6243 }
6244
6245 /**
Hall Liu27d24262020-09-18 19:04:59 -07006246 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006247 */
6248 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006249 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006250 enforceModifyPermission();
6251 long identity = Binder.clearCallingIdentity();
6252 try {
Hall Liu27d24262020-09-18 19:04:59 -07006253 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6254
6255 Phone phone = getPhone(subId);
6256 if (phone == null) {
6257 try {
6258 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6259 } catch (RemoteException e) {
6260 // ignore
6261 }
6262 return;
6263 }
6264
SongFerngWang0e767992021-03-31 22:08:45 +08006265 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6266 PersistableBundle c = configManager.getConfigForSubId(subId);
6267 boolean requireUssd = c.getBoolean(
6268 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006269
SongFerngWang0e767992021-03-31 22:08:45 +08006270 if (DBG) log("getCallWaitingStatus: subId " + subId);
6271 if (requireUssd) {
6272 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6273 getSubscriptionCarrierId(subId));
6274 CarrierXmlParser.SsEntry.SSAction ssAction =
6275 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6276 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6277 String newUssdCommand = "";
6278 try {
6279 newUssdCommand = carrierXmlParser.getFeature(
6280 CarrierXmlParser.FEATURE_CALL_WAITING)
6281 .makeCommand(ssAction, null);
6282 } catch (NullPointerException e) {
6283 loge("Failed to generate USSD number" + e);
6284 }
6285 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6286 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6287 final String ussdCommand = newUssdCommand;
6288 Executors.newSingleThreadExecutor().execute(() -> {
6289 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6290 });
6291 } else {
6292 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6293 FunctionalUtils.ignoreRemoteException(callback::accept));
6294
6295 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6296 }
Shuo Qian4a594052020-01-23 11:59:30 -08006297 } finally {
6298 Binder.restoreCallingIdentity(identity);
6299 }
6300 }
6301
6302 /**
yinxub1bed742017-04-17 11:45:04 -07006303 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006304 *
yinxub1bed742017-04-17 11:45:04 -07006305 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006306 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6307 * location related information which will be sent if the caller already possess
6308 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006309 * @param request contains the radio access networks with bands/channels to scan
6310 * @param messenger callback messenger for scan results or errors
6311 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006312 * @return the id of the requested scan which can be used to stop the scan.
6313 */
6314 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006315 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6316 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006317 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006318 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6319 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006320 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006321 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6322 if (!renounceFineLocationAccess) {
6323 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6324 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6325 .setCallingPackage(callingPackage)
6326 .setCallingFeatureId(callingFeatureId)
6327 .setCallingPid(Binder.getCallingPid())
6328 .setCallingUid(Binder.getCallingUid())
6329 .setMethod("requestNetworkScan")
6330 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6331 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6332 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6333 .build());
6334 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006335 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006336 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6337 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006338 if (e != null) {
6339 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6340 throw e;
6341 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006342 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006343 return TelephonyScanManager.INVALID_SCAN_ID;
6344 }
6345 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006346 }
Hall Liu912dfd32019-04-25 14:02:26 -07006347 int callingUid = Binder.getCallingUid();
6348 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006349 final long identity = Binder.clearCallingIdentity();
6350 try {
6351 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006352 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006353 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006354 } finally {
6355 Binder.restoreCallingIdentity(identity);
6356 }
yinxu504e1392017-04-12 16:03:22 -07006357 }
6358
Hall Liub2ac8ef2019-02-28 15:56:23 -08006359 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006360 NetworkScanRequest request, int subId, String callingPackage) {
6361 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006362 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6363 boolean hasNetworkScanPermission =
6364 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6365 == PERMISSION_GRANTED;
6366
6367 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6368 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6369 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006370 }
6371
6372 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6373 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006374 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6375 return new SecurityException("Specific channels must not be"
6376 + " scanned without location access.");
6377 }
6378 }
6379 }
6380
Hall Liub2ac8ef2019-02-28 15:56:23 -08006381 return null;
6382 }
6383
yinxu504e1392017-04-12 16:03:22 -07006384 /**
6385 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006386 *
6387 * @param subId id of the subscription
6388 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006389 */
6390 @Override
6391 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006392 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6393 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006394
Hall Liu912dfd32019-04-25 14:02:26 -07006395 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006396 final long identity = Binder.clearCallingIdentity();
6397 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006398 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006399 } finally {
6400 Binder.restoreCallingIdentity(identity);
6401 }
yinxu504e1392017-04-12 16:03:22 -07006402 }
6403
6404 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006405 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006406 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006407 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006408 */
6409 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006410 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006411 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006412 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006413 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006414
6415 final long identity = Binder.clearCallingIdentity();
6416 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006417 if (DBG) log("getAllowedNetworkTypesBitmask");
6418 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6419 int networkTypesBitmask = (result != null ? result[0] : -1);
6420 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6421 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006422 } finally {
6423 Binder.restoreCallingIdentity(identity);
6424 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006425 }
6426
6427 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006428 * Get the allowed network types for certain reason.
6429 *
6430 * @param subId the id of the subscription.
6431 * @param reason the reason the allowed network type change is taking place
6432 * @return the allowed network types.
6433 */
6434 @Override
6435 public long getAllowedNetworkTypesForReason(int subId,
6436 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006437 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006438 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006439 final long identity = Binder.clearCallingIdentity();
6440 try {
6441 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6442 } finally {
6443 Binder.restoreCallingIdentity(identity);
6444 }
6445 }
6446
6447 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006448 * Enable/Disable E-UTRA-NR Dual Connectivity
6449 * @param subId subscription id of the sim card
6450 * @param nrDualConnectivityState expected NR dual connectivity state
6451 * This can be passed following states
6452 * <ol>
6453 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6454 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6455 * <li>Disable NR dual connectivity and force secondary cell to be released
6456 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6457 * </ol>
6458 * @return operation result.
6459 */
6460 @Override
6461 public int setNrDualConnectivityState(int subId,
6462 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6463 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6464 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006465 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006466 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6467 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6468 }
6469
Sooraj Sasindran37444802020-08-11 10:40:43 -07006470 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6471 final long identity = Binder.clearCallingIdentity();
6472 try {
6473 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6474 nrDualConnectivityState, subId,
6475 workSource);
6476 if (DBG) log("enableNRDualConnectivity result: " + result);
6477 return result;
6478 } finally {
6479 Binder.restoreCallingIdentity(identity);
6480 }
6481 }
6482
6483 /**
6484 * Is E-UTRA-NR Dual Connectivity enabled
6485 * @return true if dual connectivity is enabled else false
6486 */
6487 @Override
6488 public boolean isNrDualConnectivityEnabled(int subId) {
6489 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006490 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006491 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006492 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006493 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6494 return false;
6495 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006496 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6497 final long identity = Binder.clearCallingIdentity();
6498 try {
6499 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6500 null, subId, workSource);
6501 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6502 return isEnabled;
6503 } finally {
6504 Binder.restoreCallingIdentity(identity);
6505 }
6506 }
6507
6508 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006509 * Set the allowed network types of the device and
6510 * provide the reason triggering the allowed network change.
6511 *
6512 * @param subId the id of the subscription.
6513 * @param reason the reason the allowed network type change is taking place
6514 * @param allowedNetworkTypes the allowed network types.
6515 * @return true on success; false on any failure.
6516 */
6517 @Override
6518 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006519 @TelephonyManager.AllowedNetworkTypesReason int reason,
6520 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006521 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6522 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006523 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006524 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6525 return false;
6526 }
6527 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6528 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006529 return false;
6530 }
6531
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006532 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6533 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6534
6535
6536 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6537 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6538 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006539 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006540
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006541 final long identity = Binder.clearCallingIdentity();
6542 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006543 Boolean success = (Boolean) sendRequest(
6544 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6545 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6546
6547 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6548 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006549 } finally {
6550 Binder.restoreCallingIdentity(identity);
6551 }
6552 }
6553
6554 /**
Miaoa84611c2019-03-15 09:21:10 +08006555 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006556 *
Miaoa84611c2019-03-15 09:21:10 +08006557 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006558 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006559 * @hide
6560 */
6561 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006562 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006563 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006564 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006565 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006566 try {
Miaoa84611c2019-03-15 09:21:10 +08006567 if (phone != null) {
6568 return phone.hasMatchedTetherApnSetting();
6569 } else {
6570 return false;
6571 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006572 } finally {
6573 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006574 }
Junda Liu475951f2014-11-07 16:45:03 -08006575 }
6576
6577 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006578 * Get the user enabled state of Mobile Data.
6579 *
6580 * TODO: remove and use isUserDataEnabled.
6581 * This can't be removed now because some vendor codes
6582 * calls through ITelephony directly while they should
6583 * use TelephonyManager.
6584 *
6585 * @return true on enabled
6586 */
6587 @Override
6588 public boolean getDataEnabled(int subId) {
6589 return isUserDataEnabled(subId);
6590 }
6591
6592 /**
6593 * Get whether mobile data is enabled per user setting.
6594 *
6595 * There are other factors deciding whether mobile data is actually enabled, but they are
6596 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006597 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006598 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6599 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006600 *
6601 * @return {@code true} if data is enabled else {@code false}
6602 */
6603 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006604 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006605 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006606 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006607 try {
6608 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6609 functionName);
6610 } catch (Exception e) {
6611 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6612 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006613 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006614 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006615 mApp, subId, functionName);
6616
Robert Greenwalt646120a2014-05-23 11:54:03 -07006617 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006618
6619 final long identity = Binder.clearCallingIdentity();
6620 try {
6621 int phoneId = mSubscriptionController.getPhoneId(subId);
6622 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6623 Phone phone = PhoneFactory.getPhone(phoneId);
6624 if (phone != null) {
6625 boolean retVal = phone.isUserDataEnabled();
6626 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6627 return retVal;
6628 } else {
6629 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6630 return false;
6631 }
6632 } finally {
6633 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006634 }
6635 }
6636
6637 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006638 * Checks if the device is capable of mobile data by considering whether whether the
6639 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6640 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006641 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006642 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006643 */
6644 @Override
6645 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006646 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006647 try {
6648 try {
6649 mApp.enforceCallingOrSelfPermission(
6650 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006651 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006652 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006653 try {
6654 mApp.enforceCallingOrSelfPermission(
6655 android.Manifest.permission.READ_PHONE_STATE,
6656 functionName);
6657 } catch (Exception e2) {
6658 mApp.enforceCallingOrSelfPermission(
6659 permission.READ_BASIC_PHONE_STATE, functionName);
6660 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006661 }
6662 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006663 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006664 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006665
6666 final long identity = Binder.clearCallingIdentity();
6667 try {
6668 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006669 Phone phone = PhoneFactory.getPhone(phoneId);
6670 if (phone != null) {
Jack Yu4ad64e52021-12-03 14:23:53 -08006671 boolean retVal;
6672 if (phone.isUsingNewDataStack()) {
Sarah Chin2c094c52022-03-09 13:57:52 -08006673 retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006674 } else {
6675 retVal = phone.getDataEnabledSettings().isDataEnabled();
6676 }
6677 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006678 return retVal;
6679 } else {
6680 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6681 return false;
6682 }
6683 } finally {
6684 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006685 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006686 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006687
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006688 /**
6689 * Check if data is enabled for a specific reason
6690 * @param subId Subscription index
6691 * @param reason the reason the data enable change is taking place
6692 * @return {@code true} if the overall data is enabled; {@code false} if not.
6693 */
6694 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006695 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006696 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006697 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006698 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006699 try {
6700 mApp.enforceCallingOrSelfPermission(
6701 android.Manifest.permission.ACCESS_NETWORK_STATE,
6702 functionName);
6703 } catch (Exception e) {
6704 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6705 functionName);
6706 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006707 } catch (Exception e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006708 try {
6709 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006710 functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006711 } catch (Exception e2) {
6712 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006713 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006714 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006715 }
6716
6717
6718 final long identity = Binder.clearCallingIdentity();
6719 try {
6720 int phoneId = mSubscriptionController.getPhoneId(subId);
6721 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006722 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006723 + " reason=" + reason);
6724 }
6725 Phone phone = PhoneFactory.getPhone(phoneId);
6726 if (phone != null) {
6727 boolean retVal;
Jack Yu99e87332021-12-17 23:14:15 -08006728 if (phone.isUsingNewDataStack()) {
6729 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006730 } else {
Jack Yu99e87332021-12-17 23:14:15 -08006731 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6732 retVal = phone.isUserDataEnabled();
6733 } else {
6734 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
6735 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006736 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006737 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006738 return retVal;
6739 } else {
6740 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006741 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006742 + subId + " retVal=false");
6743 }
6744 return false;
6745 }
6746 } finally {
6747 Binder.restoreCallingIdentity(identity);
6748 }
6749 }
6750
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006751 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006752 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006753 if (uid == Process.PHONE_UID) {
6754 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6755 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006756 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6757 }
6758
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006759 //load access rules from carrier configs, and check those as well: b/139133814
6760 SubscriptionController subController = SubscriptionController.getInstance();
6761 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6762 || subController == null) return privilegeFromSim;
6763
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006764 PackageManager pkgMgr = phone.getContext().getPackageManager();
6765 String[] packages = pkgMgr.getPackagesForUid(uid);
6766
6767 final long identity = Binder.clearCallingIdentity();
6768 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006769 int subId = phone.getSubId();
6770 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6771 // A test override is in place for the privileges for this subId, so don't try to
6772 // read the subscription privileges.
6773 return privilegeFromSim;
6774 }
6775 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006776 SubscriptionManager subManager = (SubscriptionManager)
6777 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6778 for (String pkg : packages) {
6779 if (subManager.canManageSubscription(subInfo, pkg)) {
6780 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6781 }
6782 }
6783 return privilegeFromSim;
6784 } finally {
6785 Binder.restoreCallingIdentity(identity);
6786 }
6787 }
6788
6789 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6790 String pkgName) {
6791 //load access rules from carrier configs, and check those as well: b/139133814
6792 SubscriptionController subController = SubscriptionController.getInstance();
6793 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6794 || subController == null) return privilegeFromSim;
6795
6796 final long identity = Binder.clearCallingIdentity();
6797 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006798 int subId = phone.getSubId();
6799 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6800 // A test override is in place for the privileges for this subId, so don't try to
6801 // read the subscription privileges.
6802 return privilegeFromSim;
6803 }
6804 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006805 SubscriptionManager subManager = (SubscriptionManager)
6806 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6807 return subManager.canManageSubscription(subInfo, pkgName)
6808 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6809 } finally {
6810 Binder.restoreCallingIdentity(identity);
6811 }
6812 }
6813
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006814 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006815 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006816 // No permission needed; this only lets the caller inspect their own status.
6817 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006818 }
Junda Liu29340342014-07-10 15:23:27 -07006819
6820 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006821 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006822 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006823 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6824 }
6825
6826 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6827 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006828 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006829 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006830 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6831 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006832 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6833 if (cpt == null) {
6834 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006835 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6836 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006837 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006838 }
6839
6840 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006841 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006842 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006843 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006844 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006845 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006846 Phone phone = getPhone(subId);
6847 if (phone == null) {
6848 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6849 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6850 }
6851 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6852 if (cpt == null) {
6853 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006854 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6855 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006856 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006857 }
6858
6859 @Override
6860 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006861 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08006862 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
6863 }
6864
6865 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006866 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006867 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006868 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006869 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006870 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6871 Phone phone = PhoneFactory.getPhone(phoneId);
6872 if (phone == null) {
6873 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006874 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006875 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6876 if (cpt == null) {
6877 continue;
6878 }
6879 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006880 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6881 break;
6882 }
6883 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006884 return result;
Junda Liu29340342014-07-10 15:23:27 -07006885 }
Derek Tan89e89d42014-07-08 17:00:10 -07006886
6887 @Override
Junda Liue64de782015-04-16 17:19:16 -07006888 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006889 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00006890 Phone phone = PhoneFactory.getPhone(phoneId);
6891 if (phone == null) {
6892 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006893 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006894 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6895 if (cpt == null) {
6896 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006897 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006898 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006899 }
6900
Amith Yamasani6e118872016-02-19 12:53:51 -08006901 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006902 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006903 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006904 Phone phone = PhoneFactory.getPhone(phoneId);
6905 if (phone == null) {
6906 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006907 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006908 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6909 if (cpt == null) {
6910 return Collections.emptyList();
6911 }
6912 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006913 }
6914
chen xuf7e9fe82019-05-09 19:31:02 -07006915 @Override
6916 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006917 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006918 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006919 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00006920 try {
6921 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6922 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6923 }
6924 } finally {
6925 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006926 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006927 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07006928 }
6929
Wink Savilleb564aae2014-10-23 10:18:09 -07006930 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006931 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006932 UiccPort port = phone == null ? null : phone.getUiccPort();
6933 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006934 return null;
6935 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006936 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006937 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006938 return null;
6939 }
6940 return iccId;
6941 }
6942
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006943 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006944 public void setCallComposerStatus(int subId, int status) {
6945 enforceModifyPermission();
6946
6947 final long identity = Binder.clearCallingIdentity();
6948 try {
6949 Phone phone = getPhone(subId);
6950 if (phone != null) {
6951 Phone defaultPhone = phone.getImsPhone();
6952 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6953 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6954 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006955 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6956 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006957 }
6958 }
Shuo Qian284ae752020-12-22 19:10:14 -08006959 } catch (ImsException e) {
6960 throw new ServiceSpecificException(e.getCode());
6961 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006962 Binder.restoreCallingIdentity(identity);
6963 }
6964 }
6965
6966 @Override
6967 public int getCallComposerStatus(int subId) {
6968 enforceReadPrivilegedPermission("getCallComposerStatus");
6969
6970 final long identity = Binder.clearCallingIdentity();
6971 try {
6972 Phone phone = getPhone(subId);
6973 if (phone != null) {
6974 Phone defaultPhone = phone.getImsPhone();
6975 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6976 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6977 return imsPhone.getCallComposerStatus();
6978 }
6979 }
6980 } finally {
6981 Binder.restoreCallingIdentity(identity);
6982 }
6983 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6984 }
6985
6986 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006987 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6988 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006989 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006990 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006991
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006992 final long identity = Binder.clearCallingIdentity();
6993 try {
6994 final String iccId = getIccId(subId);
6995 final Phone phone = getPhone(subId);
6996 if (phone == null) {
6997 return false;
6998 }
6999 final String subscriberId = phone.getSubscriberId();
7000
7001 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007002 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007003 + subscriberId + " to " + number);
7004 }
7005
7006 if (TextUtils.isEmpty(iccId)) {
7007 return false;
7008 }
7009
7010 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7011
7012 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7013 if (alphaTag == null) {
7014 editor.remove(alphaTagPrefKey);
7015 } else {
7016 editor.putString(alphaTagPrefKey, alphaTag);
7017 }
7018
7019 // Record both the line number and IMSI for this ICCID, since we need to
7020 // track all merged IMSIs based on line number
7021 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7022 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7023 if (number == null) {
7024 editor.remove(numberPrefKey);
7025 editor.remove(subscriberPrefKey);
7026 } else {
7027 editor.putString(numberPrefKey, number);
7028 editor.putString(subscriberPrefKey, subscriberId);
7029 }
7030
7031 editor.commit();
7032 return true;
7033 } finally {
7034 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007035 }
Derek Tan7226c842014-07-02 17:42:23 -07007036 }
7037
7038 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007039 public String getLine1NumberForDisplay(int subId, String callingPackage,
7040 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007041 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007042 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007043 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007044 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007045 return null;
7046 }
Derek Tan97ebb422014-09-05 16:55:38 -07007047
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007048 final long identity = Binder.clearCallingIdentity();
7049 try {
7050 String iccId = getIccId(subId);
7051 if (iccId != null) {
7052 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7053 if (DBG_MERGE) {
7054 log("getLine1NumberForDisplay returning "
7055 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7056 }
7057 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007058 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007059 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7060 return null;
7061 } finally {
7062 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007063 }
Derek Tan7226c842014-07-02 17:42:23 -07007064 }
7065
7066 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007067 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7068 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007069 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007070 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007071 return null;
7072 }
Derek Tan97ebb422014-09-05 16:55:38 -07007073
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007074 final long identity = Binder.clearCallingIdentity();
7075 try {
7076 String iccId = getIccId(subId);
7077 if (iccId != null) {
7078 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7079 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7080 }
7081 return null;
7082 } finally {
7083 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007084 }
Derek Tan7226c842014-07-02 17:42:23 -07007085 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007086
7087 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007088 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7089 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007090 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7091 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007092 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007093 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007094 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007095 return null;
7096 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007097
Jordan Liub49b04b2019-05-06 14:45:15 -07007098 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7099 // the process, where TelephonyManager was instantiated.
7100 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007101 final long identity = Binder.clearCallingIdentity();
7102 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007103 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007104 final TelephonyManager tele = TelephonyManager.from(context);
7105 final SubscriptionManager sub = SubscriptionManager.from(context);
7106
7107 // Figure out what subscribers are currently active
7108 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007109
Jordan Liub49b04b2019-05-06 14:45:15 -07007110 // Only consider subs which match the current subId
7111 // This logic can be simplified. See b/131189269 for progress.
7112 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007113 activeSubscriberIds.add(tele.getSubscriberId(subId));
7114 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007115
7116 // First pass, find a number override for an active subscriber
7117 String mergeNumber = null;
7118 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7119 for (String key : prefs.keySet()) {
7120 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7121 final String subscriberId = (String) prefs.get(key);
7122 if (activeSubscriberIds.contains(subscriberId)) {
7123 final String iccId = key.substring(
7124 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7125 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7126 mergeNumber = (String) prefs.get(numberKey);
7127 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007128 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007129 + " for active subscriber " + subscriberId);
7130 }
7131 if (!TextUtils.isEmpty(mergeNumber)) {
7132 break;
7133 }
7134 }
7135 }
7136 }
7137
7138 // Shortcut when no active merged subscribers
7139 if (TextUtils.isEmpty(mergeNumber)) {
7140 return null;
7141 }
7142
7143 // Second pass, find all subscribers under that line override
7144 final ArraySet<String> result = new ArraySet<>();
7145 for (String key : prefs.keySet()) {
7146 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7147 final String number = (String) prefs.get(key);
7148 if (mergeNumber.equals(number)) {
7149 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7150 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7151 final String subscriberId = (String) prefs.get(subscriberKey);
7152 if (!TextUtils.isEmpty(subscriberId)) {
7153 result.add(subscriberId);
7154 }
7155 }
7156 }
7157 }
7158
7159 final String[] resultArray = result.toArray(new String[result.size()]);
7160 Arrays.sort(resultArray);
7161 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007162 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007163 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7164 }
7165 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007166 } finally {
7167 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007168 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007169 }
7170
7171 @Override
zoey chen38003472019-12-13 17:16:31 +08007172 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7173 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007174
7175 final long identity = Binder.clearCallingIdentity();
7176 try {
7177 final TelephonyManager telephonyManager = mApp.getSystemService(
7178 TelephonyManager.class);
7179 String subscriberId = telephonyManager.getSubscriberId(subId);
7180 if (subscriberId == null) {
7181 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007182 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007183 + subId);
7184 }
7185 return null;
7186 }
7187
7188 final SubscriptionInfo info = SubscriptionController.getInstance()
7189 .getSubscriptionInfo(subId);
7190 final ParcelUuid groupUuid = info.getGroupUuid();
7191 // If it doesn't belong to any group, return just subscriberId of itself.
7192 if (groupUuid == null) {
7193 return new String[]{subscriberId};
7194 }
7195
7196 // Get all subscriberIds from the group.
7197 final List<String> mergedSubscriberIds = new ArrayList<>();
7198 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007199 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007200 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007201 for (SubscriptionInfo subInfo : groupInfos) {
7202 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7203 if (subscriberId != null) {
7204 mergedSubscriberIds.add(subscriberId);
7205 }
7206 }
7207
7208 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7209 } finally {
7210 Binder.restoreCallingIdentity(identity);
7211
7212 }
7213 }
7214
7215 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007216 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007217 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007218 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007219
7220 final long identity = Binder.clearCallingIdentity();
7221 try {
7222 final Phone phone = getPhone(subId);
7223 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7224 } finally {
7225 Binder.restoreCallingIdentity(identity);
7226 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007227 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007228
7229 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007230 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007231 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7232 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007233 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7234 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007235
7236 final long identity = Binder.clearCallingIdentity();
7237 try {
7238 final Phone phone = getPhone(subId);
7239 if (phone == null) {
7240 return false;
7241 }
7242 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7243 cdmaNonRoamingList);
7244 } finally {
7245 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007246 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007247 }
7248
7249 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007250 @Deprecated
7251 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7252 enforceModifyPermission();
7253
7254 int returnValue = 0;
7255 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007256 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007257 if(result.exception == null) {
7258 if (result.result != null) {
7259 byte[] responseData = (byte[])(result.result);
7260 if(responseData.length > oemResp.length) {
7261 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7262 responseData.length + "bytes. Buffer Size is " +
7263 oemResp.length + "bytes.");
7264 }
7265 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7266 returnValue = responseData.length;
7267 }
7268 } else {
7269 CommandException ex = (CommandException) result.exception;
7270 returnValue = ex.getCommandError().ordinal();
7271 if(returnValue > 0) returnValue *= -1;
7272 }
7273 } catch (RuntimeException e) {
7274 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7275 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7276 if(returnValue > 0) returnValue *= -1;
7277 }
7278
7279 return returnValue;
7280 }
7281
7282 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007283 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007284 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007285 try {
7286 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007287 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007288 mApp, phone.getSubId(), "getRadioAccessFamily");
7289 } catch (SecurityException e) {
7290 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7291 throw e;
7292 }
chen xub97461a2018-10-26 14:17:57 -07007293 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007294 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007295 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007296 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007297 final long identity = Binder.clearCallingIdentity();
7298 try {
chen xub97461a2018-10-26 14:17:57 -07007299 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007300 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007301 mApp, phone.getSubId(), "getRadioAccessFamily");
7302 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007303 } finally {
7304 Binder.restoreCallingIdentity(identity);
7305 }
chen xub97461a2018-10-26 14:17:57 -07007306 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007307 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007308
7309 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007310 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007311 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007312 try {
7313 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7314 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007315 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007316 }
7317 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007318 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007319 }
7320 RoleManager rm = mApp.getSystemService(RoleManager.class);
7321 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7322 if (!dialerRoleHolders.contains(callingPackage)) {
7323 throw new SecurityException("App must be the dialer role holder to"
7324 + " upload a call composer pic");
7325 }
7326
7327 Executors.newSingleThreadExecutor().execute(() -> {
7328 ByteArrayOutputStream output = new ByteArrayOutputStream(
7329 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7330 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7331 boolean readUntilEnd = false;
7332 int totalBytesRead = 0;
7333 byte[] buffer = new byte[16 * 1024];
7334 while (true) {
7335 int numRead;
7336 try {
7337 numRead = input.read(buffer);
7338 } catch (IOException e) {
7339 try {
7340 fd.checkError();
7341 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7342 null);
7343 } catch (IOException e1) {
7344 // This means that the other side closed explicitly with an error. If this
7345 // happens, log and ignore.
7346 loge("Remote end of call composer picture pipe closed: " + e1);
7347 }
7348 break;
7349 }
7350 if (numRead == -1) {
7351 readUntilEnd = true;
7352 break;
7353 }
7354 totalBytesRead += numRead;
7355 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7356 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7357 try {
7358 input.close();
7359 } catch (IOException e) {
7360 // ignore
7361 }
7362 break;
7363 }
7364 output.write(buffer, 0, numRead);
7365 }
7366 // Generally, the remote end will close the file descriptors. The only case where we
7367 // close is above, where the picture size is too big.
7368
7369 try {
7370 fd.checkError();
7371 } catch (IOException e) {
7372 loge("Remote end for call composer closed with an error: " + e);
7373 return;
7374 }
7375
Hall Liuaa4211e2021-01-20 15:43:39 -08007376 if (!readUntilEnd) {
7377 loge("Did not finish reading entire image; aborting");
7378 return;
7379 }
Hall Liu82694d52020-12-11 18:22:04 -08007380
Hall Liuaa4211e2021-01-20 15:43:39 -08007381 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7382 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7383 new CallComposerPictureTransfer.Factory() {},
7384 imageData,
7385 (result) -> {
7386 if (result.first != null) {
7387 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7388 Bundle outputResult = new Bundle();
7389 outputResult.putParcelable(
7390 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7391 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7392 outputResult);
7393 } else {
7394 callback.send(result.second, null);
7395 }
7396 }
7397 );
Hall Liu82694d52020-12-11 18:22:04 -08007398 });
7399 }
7400
7401 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007402 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007403 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007404 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007405
7406 final long identity = Binder.clearCallingIdentity();
7407 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007408 ImsManager.getInstance(defaultPhone.getContext(),
7409 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007410 } finally {
7411 Binder.restoreCallingIdentity(identity);
7412 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007413 }
7414
7415 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007416 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007417 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007418 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7419 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007420 return false;
7421 }
Svet Ganovb320e182015-04-16 12:30:10 -07007422
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007423 final long identity = Binder.clearCallingIdentity();
7424 try {
7425 // Check the user preference and the system-level IMS setting. Even if the user has
7426 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7427 // In the long run, we may instead need to check if there exists a connection service
7428 // which can support video calling.
7429 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007430 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007431 return imsManager.isVtEnabledByPlatform()
7432 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7433 && imsManager.isVtEnabledByUser();
7434 } finally {
7435 Binder.restoreCallingIdentity(identity);
7436 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007437 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007438
Andrew Leea1239f22015-03-02 17:44:07 -08007439 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007440 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7441 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007442 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007443 mApp, subId, callingPackage, callingFeatureId,
7444 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007445 return false;
7446 }
7447
7448 final long identity = Binder.clearCallingIdentity();
7449 try {
7450 CarrierConfigManager configManager =
7451 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007452 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007453 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7454 } finally {
7455 Binder.restoreCallingIdentity(identity);
7456 }
Andrew Leea1239f22015-03-02 17:44:07 -08007457 }
7458
7459 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007460 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007461 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007462 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007463 return false;
7464 }
7465
7466 final long identity = Binder.clearCallingIdentity();
7467 try {
7468 CarrierConfigManager configManager =
7469 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007470 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007471 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7472 } finally {
7473 Binder.restoreCallingIdentity(identity);
7474 }
Andrew Leea1239f22015-03-02 17:44:07 -08007475 }
7476
Andrew Lee9431b832015-03-09 18:46:45 -07007477 @Override
7478 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007479 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007480 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007481 }
7482
7483 @Override
7484 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007485 final long identity = Binder.clearCallingIdentity();
7486 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007487 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007488 } finally {
7489 Binder.restoreCallingIdentity(identity);
7490 }
Andrew Lee9431b832015-03-09 18:46:45 -07007491 }
7492
Hall Liuf6668912018-10-31 17:05:23 -07007493 /**
7494 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7495 * support for the feature and device firmware support.
7496 *
7497 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7498 */
7499 @Override
7500 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007501 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007502 final Phone phone = getPhone(subscriptionId);
7503 if (phone == null) {
7504 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7505 return false;
7506 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007507 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007508 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007509 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7510 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007511 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007512 return isCarrierSupported && isDeviceSupported;
7513 } finally {
7514 Binder.restoreCallingIdentity(identity);
7515 }
Hall Liu98187582018-01-22 19:15:32 -08007516 }
7517
Hall Liuf6668912018-10-31 17:05:23 -07007518 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007519 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7520 * RTT setting, will return true if the device and carrier both support RTT.
7521 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007522 */
7523 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007524 final long identity = Binder.clearCallingIdentity();
7525 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007526 boolean isRttSupported = isRttSupported(subscriptionId);
7527 boolean isUserRttSettingOn = Settings.Secure.getInt(
7528 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7529 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7530 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7531 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007532 } finally {
7533 Binder.restoreCallingIdentity(identity);
7534 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007535 }
7536
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007537 @Deprecated
7538 @Override
7539 public String getDeviceId(String callingPackage) {
7540 return getDeviceIdWithFeature(callingPackage, null);
7541 }
7542
Sanket Padawe7310cc72015-01-14 09:53:20 -08007543 /**
7544 * Returns the unique device ID of phone, for example, the IMEI for
7545 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7546 *
7547 * <p>Requires Permission:
7548 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7549 */
7550 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007551 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007552 try {
7553 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7554 } catch (SecurityException se) {
7555 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7556 throw new SecurityException("Package " + callingPackage + " does not belong to "
7557 + Binder.getCallingUid());
7558 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007559 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007560 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007561 return null;
7562 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007563 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007564 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007565 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007566 return null;
7567 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007568
7569 final long identity = Binder.clearCallingIdentity();
7570 try {
7571 return phone.getDeviceId();
7572 } finally {
7573 Binder.restoreCallingIdentity(identity);
7574 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007575 }
7576
Ping Sunc67b7c22016-03-02 19:16:45 +08007577 /**
7578 * {@hide}
7579 * Returns the IMS Registration Status on a particular subid
7580 *
7581 * @param subId
7582 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007583 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007584 Phone phone = getPhone(subId);
7585 if (phone != null) {
7586 return phone.isImsRegistered();
7587 } else {
7588 return false;
7589 }
7590 }
7591
Santos Cordon7a1885b2015-02-03 11:15:19 -08007592 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007593 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007594 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007595 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007596 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007597 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7598 }
7599 final long identity = Binder.clearCallingIdentity();
7600 try {
7601 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7602 } finally {
7603 Binder.restoreCallingIdentity(identity);
7604 }
7605 }
7606
7607 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007608 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007609 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007610 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007611 mApp,
7612 subscriptionId,
7613 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007614 final long identity = Binder.clearCallingIdentity();
7615 try {
7616 Phone phone = getPhone(subscriptionId);
7617 if (phone == null) {
7618 return null;
7619 }
7620 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7621 } finally {
7622 Binder.restoreCallingIdentity(identity);
7623 }
7624 }
7625
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007626 /**
7627 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007628 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007629 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007630 final long identity = Binder.clearCallingIdentity();
7631 try {
7632 Phone phone = getPhone(subId);
7633 if (phone != null) {
7634 return phone.isWifiCallingEnabled();
7635 } else {
7636 return false;
7637 }
7638 } finally {
7639 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007640 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007641 }
7642
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007643 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007644 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007645 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007646 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007647 final long identity = Binder.clearCallingIdentity();
7648 try {
7649 Phone phone = getPhone(subId);
7650 if (phone != null) {
7651 return phone.isVideoEnabled();
7652 } else {
7653 return false;
7654 }
7655 } finally {
7656 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007657 }
7658 }
7659
7660 /**
7661 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7662 * defined in {@link ImsRegistrationImplBase}.
7663 */
7664 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007665 final long identity = Binder.clearCallingIdentity();
7666 try {
7667 Phone phone = getPhone(subId);
7668 if (phone != null) {
7669 return phone.getImsRegistrationTech();
7670 } else {
7671 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7672 }
7673 } finally {
7674 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007675 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007676 }
7677
Stuart Scott8eef64f2015-04-08 15:13:54 -07007678 @Override
7679 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007680 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007681 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7682 return;
7683 }
Kai Shif70f46f2021-03-03 13:59:46 -08007684 Phone defaultPhone = getDefaultPhone();
7685 if (defaultPhone != null) {
7686 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7687 mApp, getDefaultPhone().getSubId(), "factoryReset");
7688 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007689 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007690
Svet Ganovcc087f82015-05-12 20:35:54 -07007691 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007692 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7693 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007694 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007695 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007696 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007697 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007698 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007699 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007700 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007701 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007702 // There has been issues when Sms raw table somehow stores orphan
7703 // fragments. They lead to garbled message when new fragments come
7704 // in and combined with those stale ones. In case this happens again,
7705 // user can reset all network settings which will clean up this table.
7706 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007707 // Clean up IMS settings as well here.
7708 int slotId = getSlotIndex(subId);
7709 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7710 ImsManager.getInstance(mApp, slotId).factoryReset();
7711 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007712
Kai Shif70f46f2021-03-03 13:59:46 -08007713 if (defaultPhone == null) {
7714 return;
7715 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007716 // Erase modem config if erase modem on network setting is enabled.
7717 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7718 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7719 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007720 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007721 }
Kai Shif70f46f2021-03-03 13:59:46 -08007722
7723 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007724 } finally {
7725 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007726 }
7727 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007728
SongFerngWangfd89b102021-05-27 22:44:54 +08007729 @VisibleForTesting
7730 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7731 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7732 return;
7733 }
7734 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7735 RILConstants.PREFERRED_NETWORK_MODE);
7736 SubscriptionManager.setSubscriptionProperty(subId,
7737 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7738 "user=" + defaultNetworkType);
7739 phone.loadAllowedNetworksFromSubscriptionDatabase();
7740 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7741 defaultNetworkType, null);
7742 }
7743
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007744 private void cleanUpSmsRawTable(Context context) {
7745 ContentResolver resolver = context.getContentResolver();
7746 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7747 resolver.delete(uri, null, null);
7748 }
7749
Narayan Kamath1c496c22015-04-16 14:40:19 +01007750 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007751 public String getSimLocaleForSubscriber(int subId) {
7752 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7753 final Phone phone = getPhone(subId);
7754 if (phone == null) {
7755 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007756 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007757 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007758 final long identity = Binder.clearCallingIdentity();
7759 try {
chen xu5d3637b2019-01-21 23:31:38 -08007760 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007761 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007762 if (info == null) {
7763 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7764 return null;
7765 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007766 // Try and fetch the locale from the carrier properties or from the SIM language
7767 // preferences (EF-PL and EF-LI)...
7768 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007769 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007770 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7771 if (localeFromDefaultSim != null) {
7772 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7773 if (DBG) log("Using locale from subId: " + subId + " locale: "
7774 + localeFromDefaultSim);
7775 return localeFromDefaultSim.toLanguageTag();
7776 } else {
7777 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007778 }
7779 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007780
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007781 // The SIM language preferences only store a language (e.g. fr = French), not an
7782 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7783 // the SIM and carrier preferences does not include a country we add the country
7784 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007785 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007786 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007787 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007788 return mccLocale.toLanguageTag();
7789 }
7790
7791 if (DBG) log("No locale found - returning null");
7792 return null;
7793 } finally {
7794 Binder.restoreCallingIdentity(identity);
7795 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007796 }
7797
7798 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007799 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007800 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007801 }
7802
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007803 /**
7804 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7805 */
7806 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007807 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007808 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007809 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007810
Gary Jian3aa9a762022-01-24 16:41:19 +08007811 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
7812 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08007813
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007814 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007815 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7816 * representing the state of the modem.
7817 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007818 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7819 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007820 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007821 */
7822 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007823 public void requestModemActivityInfo(ResultReceiver result) {
7824 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007825 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007826
7827 final long identity = Binder.clearCallingIdentity();
7828 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007829 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007830 } finally {
7831 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007832 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007833 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007834
Siddharth Rayb8114062018-06-17 15:02:38 -07007835 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7836 // less than total activity duration.
7837 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7838 if (info == null) {
7839 return false;
7840 }
7841 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007842 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7843 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7844
Siddharth Rayb8114062018-06-17 15:02:38 -07007845 return (info.isValid()
7846 && (info.getSleepTimeMillis() <= activityDurationMs)
7847 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007848 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007849 && (totalTxTimeMs <= activityDurationMs));
7850 }
7851
Gary Jian3aa9a762022-01-24 16:41:19 +08007852 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
7853 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7854 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
7855 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
7856
7857 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7858 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7859 }
7860
7861 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
7862 mLastModemActivityInfo.setReceiveTimeMillis(
7863 rat,
7864 freq,
7865 info.getReceiveTimeMillis(rat, freq)
7866 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
7867 }
7868
7869 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
7870 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7871 int[] txTimeMs = info.getTransmitTimeMillis(rat);
7872 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
7873
7874 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7875 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7876 }
7877 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
7878 mLastModemActivityInfo.setReceiveTimeMillis(
7879 rat,
7880 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
7881 }
7882
7883 /**
7884 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
7885 * @param info recent ModemActivityInfo
7886 */
7887 private void mergeModemActivityInfo(ModemActivityInfo info) {
7888 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
7889 ActivityStatsTechSpecificInfo mDeltaSpecificInfo;
7890 boolean matched;
7891 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
7892 matched = false;
7893 int rat = info.getSpecificInfoRat(i);
7894 int freq = info.getSpecificInfoFrequencyRange(i);
7895 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
7896 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
7897 //if it already exists
7898 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
7899 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
7900 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
7901 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
7902 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
7903 updateLastModemActivityInfo(info, rat, freq);
7904 matched = true;
7905 }
7906 } else {
7907 updateLastModemActivityInfo(info, rat);
7908 matched = true;
7909 }
7910 }
7911 }
7912
7913 if (!matched) {
7914 mDeltaSpecificInfo =
7915 new ActivityStatsTechSpecificInfo(
7916 rat,
7917 freq,
7918 info.getTransmitTimeMillis(rat, freq),
7919 (int) info.getReceiveTimeMillis(rat, freq));
7920 merged.addAll(Arrays.asList(mDeltaSpecificInfo));
7921 }
7922 }
7923 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
7924 mLastModemActivitySpecificInfo =
7925 new ActivityStatsTechSpecificInfo[merged.size()];
7926 merged.toArray(mLastModemActivitySpecificInfo);
7927
7928 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
7929 mLastModemActivityInfo.setSleepTimeMillis(
7930 info.getSleepTimeMillis()
7931 + mLastModemActivityInfo.getSleepTimeMillis());
7932 mLastModemActivityInfo.setIdleTimeMillis(
7933 info.getIdleTimeMillis()
7934 + mLastModemActivityInfo.getIdleTimeMillis());
7935 }
7936
Jack Yu85bd38a2015-11-09 11:34:32 -08007937 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007938 * Returns the service state information on specified subscription.
7939 */
7940 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007941 public ServiceState getServiceStateForSubscriber(int subId,
7942 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7943 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007944 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007945 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007946 return null;
7947 }
7948
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007949 boolean hasFinePermission = false;
7950 boolean hasCoarsePermission = false;
7951 if (!renounceFineLocationAccess) {
7952 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7953 LocationAccessPolicy.checkLocationPermission(mApp,
7954 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7955 .setCallingPackage(callingPackage)
7956 .setCallingFeatureId(callingFeatureId)
7957 .setCallingPid(Binder.getCallingPid())
7958 .setCallingUid(Binder.getCallingUid())
7959 .setMethod("getServiceStateForSubscriber")
7960 .setLogAsInfo(true)
7961 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7962 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7963 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7964 .build());
7965 hasFinePermission =
7966 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7967 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007968
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007969 if (!renounceCoarseLocationAccess) {
7970 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7971 LocationAccessPolicy.checkLocationPermission(mApp,
7972 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7973 .setCallingPackage(callingPackage)
7974 .setCallingFeatureId(callingFeatureId)
7975 .setCallingPid(Binder.getCallingPid())
7976 .setCallingUid(Binder.getCallingUid())
7977 .setMethod("getServiceStateForSubscriber")
7978 .setLogAsInfo(true)
7979 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7980 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7981 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7982 .build());
7983 hasCoarsePermission =
7984 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7985 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007986
Jack Yu479f40e2020-10-27 21:29:25 -07007987 final Phone phone = getPhone(subId);
7988 if (phone == null) {
7989 return null;
7990 }
7991
Jordan Liu0f2bc442020-11-18 16:47:37 -08007992 final long identity = Binder.clearCallingIdentity();
7993
Jack Yu479f40e2020-10-27 21:29:25 -07007994 boolean isCallingPackageDataService = phone.getDataServicePackages()
7995 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007996 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007997 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7998 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7999 Rlog.d(LOG_TAG,
8000 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
8001 return null;
8002 }
8003
Hall Liuf19c44f2018-11-27 14:38:17 -08008004 ServiceState ss = phone.getServiceState();
8005
8006 // Scrub out the location info in ServiceState depending on what level of access
8007 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008008 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008009 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8010 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008011 } finally {
8012 Binder.restoreCallingIdentity(identity);
8013 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008014 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008015
8016 /**
8017 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8018 *
8019 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8020 * voicemail ringtone.
8021 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8022 * PhoneAccount.
8023 */
8024 @Override
8025 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008026 final long identity = Binder.clearCallingIdentity();
8027 try {
8028 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8029 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008030 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008031 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008032
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008033 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8034 } finally {
8035 Binder.restoreCallingIdentity(identity);
8036 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008037 }
8038
8039 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008040 * Sets the per-account voicemail ringtone.
8041 *
8042 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8043 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8044 *
8045 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8046 * voicemail ringtone.
8047 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8048 * PhoneAccount.
8049 */
8050 @Override
8051 public void setVoicemailRingtoneUri(String callingPackage,
8052 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008053 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008054 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008055 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8056 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008057 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8058 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8059 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008060 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008061
8062 final long identity = Binder.clearCallingIdentity();
8063 try {
8064 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8065 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008066 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008067 }
8068 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8069 } finally {
8070 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008071 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008072 }
8073
8074 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008075 * Returns whether vibration is set for voicemail notification in Phone settings.
8076 *
8077 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8078 * voicemail vibration setting.
8079 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8080 */
8081 @Override
8082 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008083 final long identity = Binder.clearCallingIdentity();
8084 try {
8085 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8086 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008087 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008088 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008089
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008090 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8091 } finally {
8092 Binder.restoreCallingIdentity(identity);
8093 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008094 }
8095
Youhan Wange64578a2016-05-02 15:32:42 -07008096 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008097 * Sets the per-account voicemail vibration.
8098 *
8099 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8100 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8101 *
8102 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8103 * voicemail vibration setting.
8104 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8105 * specific PhoneAccount.
8106 */
8107 @Override
8108 public void setVoicemailVibrationEnabled(String callingPackage,
8109 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008110 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008111 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008112 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8113 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008114 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8115 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8116 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008117 }
8118
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008119 final long identity = Binder.clearCallingIdentity();
8120 try {
8121 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8122 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008123 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008124 }
8125 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8126 } finally {
8127 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008128 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008129 }
8130
8131 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008132 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8133 *
8134 * @throws SecurityException if the caller does not have the required permission
8135 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008136 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008137 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008138 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008139 }
8140
8141 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008142 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8143 * permission.
8144 *
8145 * @throws SecurityException if the caller does not have the required permission
8146 */
8147 private void enforceSendSmsPermission() {
8148 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8149 }
8150
8151 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008152 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008153 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008154 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008155 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008156 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008157 final long identity = Binder.clearCallingIdentity();
8158 try {
8159 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008160 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008161 if (componentName == null) {
8162 throw new SecurityException(
8163 "Caller not current active visual voicemail package[null]");
8164 }
8165 String vvmPackage = componentName.getPackageName();
8166 if (!callingPackage.equals(vvmPackage)) {
8167 throw new SecurityException("Caller not current active visual voicemail package["
8168 + vvmPackage + "]");
8169 }
8170 } finally {
8171 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008172 }
8173 }
8174
8175 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008176 * Return the application ID for the app type.
8177 *
8178 * @param subId the subscription ID that this request applies to.
8179 * @param appType the uicc app type.
8180 * @return Application ID for specificied app type, or null if no uicc.
8181 */
8182 @Override
8183 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008184 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008185 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008186
8187 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008188 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008189 if (phone == null) {
8190 return null;
8191 }
8192 String aid = null;
8193 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008194 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008195 .getApplicationByType(appType).getAid();
8196 } catch (Exception e) {
8197 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8198 }
8199 return aid;
8200 } finally {
8201 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008202 }
Youhan Wange64578a2016-05-02 15:32:42 -07008203 }
8204
Youhan Wang4001d252016-05-11 10:29:41 -07008205 /**
8206 * Return the Electronic Serial Number.
8207 *
8208 * @param subId the subscription ID that this request applies to.
8209 * @return ESN or null if error.
8210 */
8211 @Override
8212 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008213 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008214 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008215
8216 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008217 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008218 if (phone == null) {
8219 return null;
8220 }
8221 String esn = null;
8222 try {
8223 esn = phone.getEsn();
8224 } catch (Exception e) {
8225 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8226 }
8227 return esn;
8228 } finally {
8229 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008230 }
Youhan Wang4001d252016-05-11 10:29:41 -07008231 }
8232
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008233 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008234 * Return the Preferred Roaming List Version.
8235 *
8236 * @param subId the subscription ID that this request applies to.
8237 * @return PRLVersion or null if error.
8238 */
8239 @Override
8240 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008241 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008242 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008243
8244 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008245 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008246 if (phone == null) {
8247 return null;
8248 }
8249 String cdmaPrlVersion = null;
8250 try {
8251 cdmaPrlVersion = phone.getCdmaPrlVersion();
8252 } catch (Exception e) {
8253 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8254 }
8255 return cdmaPrlVersion;
8256 } finally {
8257 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008258 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008259 }
8260
8261 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008262 * Get snapshot of Telephony histograms
8263 * @return List of Telephony histograms
8264 * @hide
8265 */
8266 @Override
8267 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008268 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8269 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008270
8271 final long identity = Binder.clearCallingIdentity();
8272 try {
8273 return RIL.getTelephonyRILTimingHistograms();
8274 } finally {
8275 Binder.restoreCallingIdentity(identity);
8276 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008277 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008278
8279 /**
8280 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008281 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8282 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008283 * Require system privileges. In the future we may add this to carrier APIs.
8284 *
Michele Berionne482f8202018-11-27 18:57:59 -08008285 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008286 */
8287 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008288 @TelephonyManager.SetCarrierRestrictionResult
8289 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008290 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008291 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008292
Michele Berionne482f8202018-11-27 18:57:59 -08008293 if (carrierRestrictionRules == null) {
8294 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008295 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008296
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008297 final long identity = Binder.clearCallingIdentity();
8298 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008299 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008300 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008301 } finally {
8302 Binder.restoreCallingIdentity(identity);
8303 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008304 }
8305
8306 /**
8307 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008308 * Get the allowed carrier list and the excluded carrier list, including the priority between
8309 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008310 * Require system privileges. In the future we may add this to carrier APIs.
8311 *
Michele Berionne482f8202018-11-27 18:57:59 -08008312 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008313 */
8314 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008315 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008316 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008317 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008318
8319 final long identity = Binder.clearCallingIdentity();
8320 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008321 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8322 if (response instanceof CarrierRestrictionRules) {
8323 return (CarrierRestrictionRules) response;
8324 }
8325 // Response is an Exception of some kind,
8326 // which is signalled to the user as a NULL retval
8327 return null;
8328 } catch (Exception e) {
8329 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8330 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008331 } finally {
8332 Binder.restoreCallingIdentity(identity);
8333 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008334 }
8335
fionaxu59545b42016-05-25 15:53:37 -07008336 /**
fionaxu59545b42016-05-25 15:53:37 -07008337 * Action set from carrier signalling broadcast receivers to enable/disable radio
8338 * @param subId the subscription ID that this action applies to.
8339 * @param enabled control enable or disable radio.
8340 * {@hide}
8341 */
8342 @Override
8343 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8344 enforceModifyPermission();
8345 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008346
8347 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008348 if (phone == null) {
8349 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8350 return;
8351 }
8352 try {
8353 phone.carrierActionSetRadioEnabled(enabled);
8354 } catch (Exception e) {
8355 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008356 } finally {
8357 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008358 }
8359 }
8360
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008361 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008362 * Enable or disable Voice over NR (VoNR)
8363 * @param subId the subscription ID that this action applies to.
8364 * @param enabled enable or disable VoNR.
8365 * @return operation result.
8366 */
8367 @Override
8368 public int setVoNrEnabled(int subId, boolean enabled) {
8369 enforceModifyPermission();
8370 final Phone phone = getPhone(subId);
8371
8372 final long identity = Binder.clearCallingIdentity();
8373 if (phone == null) {
8374 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8375 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8376 }
8377
8378 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8379 try {
8380 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8381 workSource);
8382 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008383
8384 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8385 if (DBG) {
8386 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8387 }
8388 SubscriptionManager.setSubscriptionProperty(
8389 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8390 (enabled ? "1" : "0"));
8391 }
8392
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008393 return result;
8394 } finally {
8395 Binder.restoreCallingIdentity(identity);
8396 }
8397 }
8398
8399 /**
8400 * Is voice over NR enabled
8401 * @return true if VoNR is enabled else false
8402 */
8403 @Override
8404 public boolean isVoNrEnabled(int subId) {
8405 enforceReadPrivilegedPermission("isVoNrEnabled");
8406 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8407 final long identity = Binder.clearCallingIdentity();
8408 try {
8409 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8410 null, subId, workSource);
8411 if (DBG) log("isVoNrEnabled: " + isEnabled);
8412 return isEnabled;
8413 } finally {
8414 Binder.restoreCallingIdentity(identity);
8415 }
8416 }
8417
8418 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008419 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8420 * network status based on which carrier apps could apply actions accordingly,
8421 * enable/disable default url handler for example.
8422 *
8423 * @param subId the subscription ID that this action applies to.
8424 * @param report control start/stop reporting the default network status.
8425 * {@hide}
8426 */
8427 @Override
8428 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8429 enforceModifyPermission();
8430 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008431
8432 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008433 if (phone == null) {
8434 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8435 return;
8436 }
8437 try {
8438 phone.carrierActionReportDefaultNetworkStatus(report);
8439 } catch (Exception e) {
8440 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008441 } finally {
8442 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008443 }
8444 }
8445
8446 /**
fionaxud9622282017-07-17 17:51:30 -07008447 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8448 * @param subId the subscription ID that this action applies to.
8449 * {@hide}
8450 */
8451 @Override
8452 public void carrierActionResetAll(int subId) {
8453 enforceModifyPermission();
8454 final Phone phone = getPhone(subId);
8455 if (phone == null) {
8456 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8457 return;
8458 }
8459 try {
8460 phone.carrierActionResetAll();
8461 } catch (Exception e) {
8462 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8463 }
8464 }
8465
8466 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008467 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8468 * bug report is being generated.
8469 */
8470 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008471 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008472 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8473 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008474 writer.println("Permission Denial: can't dump Phone from pid="
8475 + Binder.getCallingPid()
8476 + ", uid=" + Binder.getCallingUid()
8477 + "without permission "
8478 + android.Manifest.permission.DUMP);
8479 return;
8480 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008481 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008482 }
Jack Yueb89b242016-06-22 13:27:47 -07008483
Brad Ebingerdac2f002018-04-03 15:17:52 -07008484 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008485 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8486 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8487 @NonNull String[] args) {
8488 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8489 this, in.getFileDescriptor(), out.getFileDescriptor(),
8490 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008491 }
8492
Jack Yueb89b242016-06-22 13:27:47 -07008493 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008494 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008495 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008496 * @param reason the reason the data enable change is taking place
8497 * @param enabled True if enabling the data, otherwise disabling.
8498 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008499 */
8500 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008501 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008502 boolean enabled) {
8503 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8504 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8505 try {
8506 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008507 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008508 } catch (SecurityException se) {
8509 enforceModifyPermission();
8510 }
8511 } else {
8512 enforceModifyPermission();
8513 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008514
8515 final long identity = Binder.clearCallingIdentity();
8516 try {
8517 Phone phone = getPhone(subId);
8518 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008519 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8520 phone.carrierActionSetMeteredApnsEnabled(enabled);
8521 } else {
Jack Yu99e87332021-12-17 23:14:15 -08008522 if (phone.isUsingNewDataStack()) {
8523 phone.getDataSettingsManager().setDataEnabled(reason, enabled);
8524 } else {
8525 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8526 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008527 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008528 }
8529 } finally {
8530 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008531 }
8532 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008533
8534 /**
8535 * Get Client request stats
8536 * @return List of Client Request Stats
8537 * @hide
8538 */
8539 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008540 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8541 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008542 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008543 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008544 return null;
8545 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008546 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008547
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008548 final long identity = Binder.clearCallingIdentity();
8549 try {
8550 if (phone != null) {
8551 return phone.getClientRequestStats();
8552 }
8553
8554 return null;
8555 } finally {
8556 Binder.restoreCallingIdentity(identity);
8557 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008558 }
8559
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008560 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008561 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008562 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008563 }
Jack Yueb4124c2017-02-16 15:32:43 -08008564
8565 /**
Grace Chen70990072017-03-24 17:21:30 -07008566 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008567 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008568 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008569 * @param state State of SIM (power down, power up, pass through)
8570 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8571 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8572 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008573 *
8574 **/
8575 @Override
Grace Chen70990072017-03-24 17:21:30 -07008576 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008577 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008578 Phone phone = PhoneFactory.getPhone(slotIndex);
8579
vagdeviaf9a5b92018-08-15 16:01:53 -07008580 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8581
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008582 final long identity = Binder.clearCallingIdentity();
8583 try {
8584 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008585 phone.setSimPowerState(state, null, workSource);
8586 }
8587 } finally {
8588 Binder.restoreCallingIdentity(identity);
8589 }
8590 }
8591
8592 /**
8593 * Set SIM card power state.
8594 *
8595 * @param slotIndex SIM slot id.
8596 * @param state State of SIM (power down, power up, pass through)
8597 * @param callback callback to trigger after success or failure
8598 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8599 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8600 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8601 *
8602 **/
8603 @Override
8604 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8605 IIntegerConsumer callback) {
8606 enforceModifyPermission();
8607 Phone phone = PhoneFactory.getPhone(slotIndex);
8608
8609 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8610
8611 final long identity = Binder.clearCallingIdentity();
8612 try {
8613 if (phone != null) {
8614 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8615 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008616 }
8617 } finally {
8618 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008619 }
8620 }
Shuo Qiandd210312017-04-12 22:11:33 +00008621
Tyler Gunn65d45c22017-06-05 11:22:26 -07008622 private boolean isUssdApiAllowed(int subId) {
8623 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008624 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008625 if (configManager == null) {
8626 return false;
8627 }
8628 PersistableBundle pb = configManager.getConfigForSubId(subId);
8629 if (pb == null) {
8630 return false;
8631 }
8632 return pb.getBoolean(
8633 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8634 }
8635
Shuo Qiandd210312017-04-12 22:11:33 +00008636 /**
8637 * Check if phone is in emergency callback mode
8638 * @return true if phone is in emergency callback mode
8639 * @param subId sub id
8640 */
goneil9c5f4872017-12-05 14:07:56 -08008641 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008642 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008643 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008644 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008645
8646 final long identity = Binder.clearCallingIdentity();
8647 try {
8648 if (phone != null) {
8649 return phone.isInEcm();
8650 } else {
8651 return false;
8652 }
8653 } finally {
8654 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008655 }
8656 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008657
8658 /**
8659 * Get the current signal strength information for the given subscription.
8660 * Because this information is not updated when the device is in a low power state
8661 * it should not be relied-upon to be current.
8662 * @param subId Subscription index
8663 * @return the most recent cached signal strength info from the modem
8664 */
8665 @Override
8666 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008667 final long identity = Binder.clearCallingIdentity();
8668 try {
8669 Phone p = getPhone(subId);
8670 if (p == null) {
8671 return null;
8672 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008673
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008674 return p.getSignalStrength();
8675 } finally {
8676 Binder.restoreCallingIdentity(identity);
8677 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008678 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008679
Pengquan Meng77b7f132018-08-22 14:49:57 -07008680 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008681 * Get the current modem radio state for the given slot.
8682 * @param slotIndex slot index.
8683 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008684 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008685 * @return the current radio power state from the modem
8686 */
8687 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008688 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008689 Phone phone = PhoneFactory.getPhone(slotIndex);
8690 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008691 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8692 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008693 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8694 }
8695
8696 final long identity = Binder.clearCallingIdentity();
8697 try {
8698 return phone.getRadioPowerState();
8699 } finally {
8700 Binder.restoreCallingIdentity(identity);
8701 }
8702 }
8703 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8704 }
8705
8706 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008707 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8708 *
8709 * <p>Requires one of the following permissions:
8710 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008711 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008712 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8713 * privileges.
8714 *
8715 * @param subId subscription id
8716 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8717 * {@code false}.
8718 */
8719 @Override
8720 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008721 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008722 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008723 try {
8724 mApp.enforceCallingOrSelfPermission(
8725 android.Manifest.permission.ACCESS_NETWORK_STATE,
8726 functionName);
8727 } catch (Exception e) {
8728 mApp.enforceCallingOrSelfPermission(
8729 permission.READ_BASIC_PHONE_STATE, functionName);
8730 }
Shuo Qian093013d2020-08-13 15:42:55 -07008731 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008732 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008733 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008734 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008735
Pengquan Menga1bb6272018-09-06 09:59:22 -07008736 boolean isEnabled = false;
8737 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008738 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008739 Phone phone = getPhone(subId);
8740 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008741 } finally {
8742 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008743 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008744 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008745 }
8746
8747
8748 /**
8749 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8750 *
8751 * <p> Requires permission:
8752 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8753 * privileges.
8754 *
8755 * @param subId subscription id
8756 * @param isEnabled {@code true} means enable, {@code false} means disable.
8757 */
8758 @Override
8759 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008760 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8761 mApp, subId, "setDataRoamingEnabled");
8762
Pengquan Menga1bb6272018-09-06 09:59:22 -07008763 final long identity = Binder.clearCallingIdentity();
8764 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008765 Phone phone = getPhone(subId);
8766 if (phone != null) {
8767 phone.setDataRoamingEnabled(isEnabled);
8768 }
8769 } finally {
8770 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008771 }
8772 }
8773
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008774 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008775 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008776 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008777 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008778 mApp, subId, "isManualNetworkSelectionAllowed");
8779
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008780 boolean isAllowed = true;
8781 final long identity = Binder.clearCallingIdentity();
8782 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008783 Phone phone = getPhone(subId);
8784 if (phone != null) {
8785 isAllowed = phone.isCspPlmnEnabled();
8786 }
8787 } finally {
8788 Binder.restoreCallingIdentity(identity);
8789 }
8790 return isAllowed;
8791 }
8792
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008793 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8794 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008795 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008796 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008797 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008798 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8799 if (phone == null) {
8800 return false;
8801 }
8802 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8803 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8804 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008805 }
8806
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008807 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008808 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008809 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008810 mApp.getSystemService(AppOpsManager.class)
8811 .checkPackage(Binder.getCallingUid(), callingPackage);
8812
Jordan Liu1e142fc2019-04-22 15:10:43 -07008813 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008814 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008815 try {
8816 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008817 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008818 } catch (SecurityException e) {
8819 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8820 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08008821 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08008822 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008823 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008824 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008825 }
sandeepjsb6c87872021-09-27 15:34:44 +00008826 // checking compatibility, if calling app's target SDK is T and beyond.
8827 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8828 Binder.getCallingUid())) {
8829 isIccIdAccessRestricted = true;
8830 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008831 final long identity = Binder.clearCallingIdentity();
8832 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008833 UiccController uiccController = UiccController.getInstance();
8834 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008835 if (hasReadPermission) {
8836 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008837 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008838
8839 // Remove private info if the caller doesn't have access
8840 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8841 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008842 //setting the value after compatibility check
8843 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008844 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8845 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008846 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008847 if (card == null) {
8848 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008849 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008850 continue;
8851 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008852 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8853 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008854 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008855 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008856 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008857 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8858 for (UiccPortInfo portInfo : portInfos) {
8859 UiccPort port = uiccController.getUiccPortForSlot(
8860 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8861 if (port == null) {
8862 // assume no access if port is null
8863 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8864 continue;
8865 }
8866 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8867 uiccPortInfos.add(portInfo);
8868 } else {
8869 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8870 }
8871 }
8872 filteredInfos.add(new UiccCardInfo(
8873 cardInfo.isEuicc(),
8874 cardInfo.getCardId(),
8875 null,
8876 cardInfo.getPhysicalSlotIndex(),
8877 cardInfo.isRemovable(),
8878 cardInfo.isMultipleEnabledProfilesSupported(),
8879 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008880 }
8881 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008882 } finally {
8883 Binder.restoreCallingIdentity(identity);
8884 }
8885 }
8886
sandeepjsb6c87872021-09-27 15:34:44 +00008887 /**
8888 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8889 * generally private and require carrier privileges to view.
8890 *
8891 * @hide
8892 */
8893 @NonNull
8894 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8895 List<UiccPortInfo> portinfo = new ArrayList<>();
8896 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8897 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8898 }
8899 return new UiccCardInfo(
8900 cardInfo.isEuicc(),
8901 cardInfo.getCardId(),
8902 null,
8903 cardInfo.getPhysicalSlotIndex(),
8904 cardInfo.isRemovable(),
8905 cardInfo.isMultipleEnabledProfilesSupported(),
8906 portinfo
8907 );
8908 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008909
sandeepjsb6c87872021-09-27 15:34:44 +00008910 /**
8911 * @hide
8912 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8913 * These values are generally private and require carrier privileges to view.
8914 */
8915 @NonNull
8916 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8917 return new UiccPortInfo(
8918 UiccPortInfo.ICCID_REDACTED,
8919 portInfo.getPortIndex(),
8920 portInfo.getLogicalSlotIndex(),
8921 portInfo.isActive()
8922 );
8923 }
8924 @Override
8925 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008926 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00008927 mApp.getSystemService(AppOpsManager.class)
8928 .checkPackage(Binder.getCallingUid(), callingPackage);
8929
8930 boolean hasReadPermission = false;
8931 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008932
8933 try {
8934 enforceReadPrivilegedPermission("getUiccSlotsInfo");
8935 hasReadPermission = true;
8936 } catch (SecurityException e) {
8937 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8938 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08008939 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
sandeepjsb6c87872021-09-27 15:34:44 +00008940 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8941 hasReadPermission = true;
8942 }
8943 }
8944
8945 // checking compatibility, if calling app's target SDK is T and beyond.
8946 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8947 Binder.getCallingUid())) {
8948 isLogicalSlotAccessRestricted = true;
8949 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008950 final long identity = Binder.clearCallingIdentity();
8951 try {
8952 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00008953 if (slots == null || slots.length == 0) {
8954 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008955 return null;
8956 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008957 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8958 for (int i = 0; i < slots.length; i++) {
8959 UiccSlot slot = slots[i];
8960 if (slot == null) {
8961 continue;
8962 }
8963
Jordan Liu7be7e652019-05-06 18:55:02 +00008964 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008965 UiccCard card = slot.getUiccCard();
8966 if (card != null) {
8967 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008968 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008969 cardId = slot.getEid();
8970 if (TextUtils.isEmpty(cardId)) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008971 // If cardId is null, use iccId of default port as cardId. Check if has
8972 // read permission otherwise set to null.(card is null which means no
8973 // carrier permission)
8974 cardId = hasReadPermission ? slot.getIccId(
8975 TelephonyManager.DEFAULT_PORT_INDEX) : null;
Jordan Liu01bd00d2019-09-12 16:19:43 -07008976 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008977 }
8978
Jordan Liu857451f2019-05-09 16:35:35 -07008979 if (cardId != null) {
8980 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8981 // if cardId is an EID, it's all digits so this is fine
8982 cardId = IccUtils.stripTrailingFs(cardId);
8983 }
8984
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008985 int cardState = 0;
8986 switch (slot.getCardState()) {
8987 case CARDSTATE_ABSENT:
8988 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8989 break;
8990 case CARDSTATE_PRESENT:
8991 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8992 break;
8993 case CARDSTATE_ERROR:
8994 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8995 break;
8996 case CARDSTATE_RESTRICTED:
8997 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8998 break;
8999 default:
9000 break;
9001
9002 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009003 List<UiccPortInfo> portInfos = new ArrayList<>();
9004 int[] portIndexes = slot.getPortList();
9005 for (int portIdx : portIndexes) {
9006 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
9007 callingPackage, hasReadPermission));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009008 portInfos.add(new UiccPortInfo(iccId, portIdx,
9009 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009010 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009011 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009012 slot.isEuicc(),
9013 cardId,
9014 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009015 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009016 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009017 //setting the value after compatibility check
9018 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009019 }
9020 return infos;
9021 } finally {
9022 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009023 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009024 }
9025
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009026 /* Returns null if doesn't have read permission or carrier privilege access. */
9027 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9028 boolean hasReadPermission) {
9029 String iccId = slot.getIccId(portIndex);
9030 if (hasReadPermission) { // if has read permission
9031 return iccId;
9032 } else {
9033 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9034 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9035 // if no read permission, checking carrier privilege access
9036 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9037 return iccId;
9038 }
9039 }
9040 }
9041 // No read permission or carrier privilege access.
9042 return UiccPortInfo.ICCID_REDACTED;
9043 }
9044
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009045 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009046 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009047 public boolean switchSlots(int[] physicalSlots) {
9048 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009049
9050 final long identity = Binder.clearCallingIdentity();
9051 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009052 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9053 for (int i = 0; i < physicalSlots.length; i++) {
9054 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9055 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9056 physicalSlots[i], i));
9057 }
9058 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009059 } finally {
9060 Binder.restoreCallingIdentity(identity);
9061 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009062 }
Jack Yu4c988042018-02-27 15:30:01 -08009063
9064 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009065 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9066 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9067 enforceModifyPermission();
9068
9069 final long identity = Binder.clearCallingIdentity();
9070 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009071 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009072 } finally {
9073 Binder.restoreCallingIdentity(identity);
9074 }
9075 }
9076
9077 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009078 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009079 final long identity = Binder.clearCallingIdentity();
9080 try {
9081 return UiccController.getInstance().getCardIdForDefaultEuicc();
9082 } finally {
9083 Binder.restoreCallingIdentity(identity);
9084 }
9085 }
9086
Pengquan Meng85728fb2018-03-12 16:31:21 -07009087 /**
goneil47ffb6e2018-04-06 15:40:58 -07009088 * A test API to reload the UICC profile.
9089 *
9090 * <p>Requires that the calling app has permission
9091 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9092 * @hide
9093 */
9094 @Override
9095 public void refreshUiccProfile(int subId) {
9096 enforceModifyPermission();
9097
9098 final long identity = Binder.clearCallingIdentity();
9099 try {
9100 Phone phone = getPhone(subId);
9101 if (phone == null) {
9102 return;
9103 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009104 UiccPort uiccPort = phone.getUiccPort();
9105 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009106 return;
9107 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009108 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009109 if (uiccProfile == null) {
9110 return;
9111 }
9112 uiccProfile.refresh();
9113 } finally {
9114 Binder.restoreCallingIdentity(identity);
9115 }
9116 }
9117
9118 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009119 * Returns false if the mobile data is disabled by default, otherwise return true.
9120 */
9121 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009122 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009123 }
9124
9125 /**
9126 * Returns true if the data roaming is enabled by default, i.e the system property
9127 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9128 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9129 */
9130 private boolean getDefaultDataRoamingEnabled(int subId) {
9131 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009132 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009133 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009134 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9135 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9136 return isDataRoamingEnabled;
9137 }
9138
9139 /**
9140 * Returns the default network type for the given {@code subId}, if the default network type is
9141 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9142 */
9143 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009144 List<Integer> list = TelephonyProperties.default_network();
9145 int phoneId = mSubscriptionController.getPhoneId(subId);
9146 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9147 return list.get(phoneId);
9148 }
9149 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009150 }
fionaxua13278b2018-03-21 00:08:13 -07009151
9152 @Override
9153 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009154 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009155 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009156
9157 final long identity = Binder.clearCallingIdentity();
9158 try {
9159 final Phone phone = getPhone(subId);
9160 if (phone == null) {
9161 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9162 return;
9163 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009164 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9165 if (cpt != null) {
9166 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9167 }
9168 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009169 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9170 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009171 if (carrierPrivilegeRules == null) {
9172 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9173 } else {
9174 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9175 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009176 } finally {
9177 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009178 }
fionaxua13278b2018-03-21 00:08:13 -07009179 }
9180
9181 @Override
9182 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009183 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009184
9185 final long identity = Binder.clearCallingIdentity();
9186 try {
9187 final Phone phone = getPhone(subId);
9188 if (phone == null) {
9189 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9190 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9191 }
9192 return phone.getCarrierIdListVersion();
9193 } finally {
9194 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009195 }
fionaxua13278b2018-03-21 00:08:13 -07009196 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009197
9198 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009199 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9200 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009201 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009202 mApp, subId, callingPackage, callingFeatureId,
9203 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009204 return -1;
9205 }
9206
9207 final long identity = Binder.clearCallingIdentity();
9208 try {
9209 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9210 } finally {
9211 Binder.restoreCallingIdentity(identity);
9212 }
9213 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009214
9215 @Override
9216 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009217 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009218 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009219 mApp, subId, "getCdmaRoamingMode");
9220
9221 final long identity = Binder.clearCallingIdentity();
9222 try {
9223 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9224 } finally {
9225 Binder.restoreCallingIdentity(identity);
9226 }
9227 }
9228
9229 @Override
9230 public boolean setCdmaRoamingMode(int subId, int mode) {
9231 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9232 mApp, subId, "setCdmaRoamingMode");
9233
9234 final long identity = Binder.clearCallingIdentity();
9235 try {
9236 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9237 } finally {
9238 Binder.restoreCallingIdentity(identity);
9239 }
9240 }
9241
9242 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009243 public int getCdmaSubscriptionMode(int subId) {
9244 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009245 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009246 mApp, subId, "getCdmaSubscriptionMode");
9247
9248 final long identity = Binder.clearCallingIdentity();
9249 try {
9250 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9251 } finally {
9252 Binder.restoreCallingIdentity(identity);
9253 }
9254 }
9255
9256 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009257 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9258 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9259 mApp, subId, "setCdmaSubscriptionMode");
9260
9261 final long identity = Binder.clearCallingIdentity();
9262 try {
9263 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9264 } finally {
9265 Binder.restoreCallingIdentity(identity);
9266 }
9267 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009268
sqianc5eccab2018-10-19 18:46:41 -07009269 @Override
sqian8c685422019-02-22 15:55:18 -08009270 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009271 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009272 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009273 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9274 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009275 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9276 }
9277 final long identity = Binder.clearCallingIdentity();
9278 try {
sqian854d44b2018-12-12 16:48:18 -08009279 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9280 for (Phone phone: PhoneFactory.getPhones()) {
9281 if (phone.getEmergencyNumberTracker() != null
9282 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9283 emergencyNumberListInternal.put(
9284 phone.getSubId(),
9285 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9286 }
sqian11b7a0e2018-12-05 18:48:28 -08009287 }
sqian854d44b2018-12-12 16:48:18 -08009288 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009289 } finally {
9290 Binder.restoreCallingIdentity(identity);
9291 }
sqianc5eccab2018-10-19 18:46:41 -07009292 }
9293
9294 @Override
sqian8c685422019-02-22 15:55:18 -08009295 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009296 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009297 if (!exactMatch) {
9298 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009299 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009300 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009301 }
9302 final long identity = Binder.clearCallingIdentity();
9303 try {
sqian854d44b2018-12-12 16:48:18 -08009304 for (Phone phone: PhoneFactory.getPhones()) {
9305 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009306 && phone.getEmergencyNumberTracker()
9307 .isEmergencyNumber(number, exactMatch)) {
9308 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009309 }
sqian11b7a0e2018-12-05 18:48:28 -08009310 }
9311 return false;
9312 } finally {
9313 Binder.restoreCallingIdentity(identity);
9314 }
9315 }
9316
sqianf4ca7ed2019-01-15 18:32:07 -08009317 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009318 * Start emergency callback mode for GsmCdmaPhone for testing.
9319 */
9320 @Override
9321 public void startEmergencyCallbackMode() {
9322 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9323 "startEmergencyCallbackMode");
9324 enforceModifyPermission();
9325 final long identity = Binder.clearCallingIdentity();
9326 try {
9327 for (Phone phone : PhoneFactory.getPhones()) {
9328 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9329 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9330 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9331 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9332 gsmCdmaPhone.obtainMessage(
9333 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9334 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9335 }
9336 }
9337 } finally {
9338 Binder.restoreCallingIdentity(identity);
9339 }
9340 }
9341
9342 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009343 * Update emergency number list for test mode.
9344 */
9345 @Override
9346 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9347 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9348 "updateEmergencyNumberListTestMode");
9349
9350 final long identity = Binder.clearCallingIdentity();
9351 try {
9352 for (Phone phone: PhoneFactory.getPhones()) {
9353 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9354 if (tracker != null) {
9355 tracker.executeEmergencyNumberTestModeCommand(action, num);
9356 }
9357 }
9358 } finally {
9359 Binder.restoreCallingIdentity(identity);
9360 }
9361 }
9362
9363 /**
9364 * Get the full emergency number list for test mode.
9365 */
9366 @Override
9367 public List<String> getEmergencyNumberListTestMode() {
9368 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9369 "getEmergencyNumberListTestMode");
9370
9371 final long identity = Binder.clearCallingIdentity();
9372 try {
9373 Set<String> emergencyNumbers = new HashSet<>();
9374 for (Phone phone: PhoneFactory.getPhones()) {
9375 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9376 if (tracker != null) {
9377 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9378 emergencyNumbers.add(num.getNumber());
9379 }
9380 }
9381 }
9382 return new ArrayList<>(emergencyNumbers);
9383 } finally {
9384 Binder.restoreCallingIdentity(identity);
9385 }
9386 }
9387
chen xud6b45bd2018-10-30 22:27:10 -07009388 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009389 public int getEmergencyNumberDbVersion(int subId) {
9390 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9391
9392 final long identity = Binder.clearCallingIdentity();
9393 try {
9394 final Phone phone = getPhone(subId);
9395 if (phone == null) {
9396 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9397 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9398 }
9399 return phone.getEmergencyNumberDbVersion();
9400 } finally {
9401 Binder.restoreCallingIdentity(identity);
9402 }
9403 }
9404
9405 @Override
9406 public void notifyOtaEmergencyNumberDbInstalled() {
9407 enforceModifyPermission();
9408
9409 final long identity = Binder.clearCallingIdentity();
9410 try {
9411 for (Phone phone: PhoneFactory.getPhones()) {
9412 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9413 if (tracker != null) {
9414 tracker.updateOtaEmergencyNumberDatabase();
9415 }
9416 }
9417 } finally {
9418 Binder.restoreCallingIdentity(identity);
9419 }
9420 }
9421
9422 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009423 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009424 enforceActiveEmergencySessionPermission();
9425
9426 final long identity = Binder.clearCallingIdentity();
9427 try {
9428 for (Phone phone: PhoneFactory.getPhones()) {
9429 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9430 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009431 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9432 }
9433 }
9434 } finally {
9435 Binder.restoreCallingIdentity(identity);
9436 }
9437 }
9438
9439 @Override
9440 public void resetOtaEmergencyNumberDbFilePath() {
9441 enforceActiveEmergencySessionPermission();
9442
9443 final long identity = Binder.clearCallingIdentity();
9444 try {
9445 for (Phone phone: PhoneFactory.getPhones()) {
9446 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9447 if (tracker != null) {
9448 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009449 }
9450 }
9451 } finally {
9452 Binder.restoreCallingIdentity(identity);
9453 }
9454 }
9455
9456 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009457 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9458 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9459 Phone phone = getPhone(subId);
9460 if (phone == null) {
9461 return null;
9462 }
9463 final long identity = Binder.clearCallingIdentity();
9464 try {
9465 UiccProfile profile = UiccController.getInstance()
9466 .getUiccProfileForPhone(phone.getPhoneId());
9467 if (profile != null) {
9468 return profile.getCertsFromCarrierPrivilegeAccessRules();
9469 }
9470 } finally {
9471 Binder.restoreCallingIdentity(identity);
9472 }
9473 return null;
9474 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009475
9476 /**
9477 * Enable or disable a modem stack.
9478 */
9479 @Override
9480 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9481 enforceModifyPermission();
9482
9483 final long identity = Binder.clearCallingIdentity();
9484 try {
9485 Phone phone = PhoneFactory.getPhone(slotIndex);
9486 if (phone == null) {
9487 return false;
9488 } else {
9489 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9490 }
9491 } finally {
9492 Binder.restoreCallingIdentity(identity);
9493 }
9494 }
Michelecea4cf22018-12-21 15:00:11 -08009495
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009496 /**
9497 * Whether a modem stack is enabled or not.
9498 */
9499 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009500 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9501 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009502 Phone phone = PhoneFactory.getPhone(slotIndex);
9503 if (phone == null) return false;
9504
9505 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009506 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9507 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009508 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9509 }
9510
9511 final long identity = Binder.clearCallingIdentity();
9512 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009513 try {
9514 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9515 } catch (NoSuchElementException ex) {
9516 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9517 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009518 } finally {
9519 Binder.restoreCallingIdentity(identity);
9520 }
9521 }
9522
Michelecea4cf22018-12-21 15:00:11 -08009523 @Override
Michele0ea7d782019-03-19 14:58:42 -07009524 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009525 enforceModifyPermission();
9526
9527 final long identity = Binder.clearCallingIdentity();
9528 try {
9529 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009530 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009531 .commit();
9532 } finally {
9533 Binder.restoreCallingIdentity(identity);
9534 }
9535 }
9536
9537 @Override
Michele0ea7d782019-03-19 14:58:42 -07009538 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009539 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009540 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009541 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9542 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009543 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009544 }
Michelecea4cf22018-12-21 15:00:11 -08009545
9546 final long identity = Binder.clearCallingIdentity();
9547 try {
Michele0ea7d782019-03-19 14:58:42 -07009548 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009549 } finally {
9550 Binder.restoreCallingIdentity(identity);
9551 }
9552 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009553
Michele0ea7d782019-03-19 14:58:42 -07009554 @TelephonyManager.IsMultiSimSupportedResult
9555 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009556 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9557 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9558 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009559 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9560 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009561 }
9562 // Check if the hardware supports multisim functionality. If usage of multisim is not
9563 // supported by the modem, indicate that it is restricted.
9564 PhoneCapability staticCapability =
9565 mPhoneConfigurationManager.getStaticPhoneCapability();
9566 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009567 loge("isMultiSimSupportedInternal: no static configuration available");
9568 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009569 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009570 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009571 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9572 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009573 }
9574 // Check if support of multiple SIMs is restricted by carrier
9575 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009576 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009577 }
9578
Michele0ea7d782019-03-19 14:58:42 -07009579 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009580 }
9581
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009582 /**
9583 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009584 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9585 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9586 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009587 * @param numOfSims number of active sims we want to switch to
9588 */
9589 @Override
9590 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009591 if (numOfSims == 1) {
9592 enforceModifyPermission();
9593 } else {
9594 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9595 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9596 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009597 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009598
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009599 try {
Michele30b57b22019-03-01 12:01:14 -08009600 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009601 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009602 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9603 return;
9604 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009605 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9606 } finally {
9607 Binder.restoreCallingIdentity(identity);
9608 }
9609 }
9610
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009611 @Override
9612 public boolean isApplicationOnUicc(int subId, int appType) {
9613 enforceReadPrivilegedPermission("isApplicationOnUicc");
9614 Phone phone = getPhone(subId);
9615 if (phone == null) {
9616 return false;
9617 }
9618 final long identity = Binder.clearCallingIdentity();
9619 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009620 UiccPort uiccPort = phone.getUiccPort();
9621 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009622 return false;
9623 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009624 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009625 if (uiccProfile == null) {
9626 return false;
9627 }
9628 if (TelephonyManager.APPTYPE_SIM <= appType
9629 && appType <= TelephonyManager.APPTYPE_ISIM) {
9630 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9631 }
9632 return false;
9633 } finally {
9634 Binder.restoreCallingIdentity(identity);
9635 }
9636 }
9637
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009638 /**
chen xub4baa772019-04-03 10:23:41 -07009639 * Get whether making changes to modem configurations will trigger reboot.
9640 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009641 */
9642 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009643 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9644 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009645 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009646 mApp, subId, callingPackage, callingFeatureId,
9647 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009648 return false;
9649 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009650 final long identity = Binder.clearCallingIdentity();
9651 try {
9652 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9653 } finally {
9654 Binder.restoreCallingIdentity(identity);
9655 }
9656 }
9657
Nathan Harold29f5f052019-02-15 13:41:57 -08009658 private void updateModemStateMetrics() {
9659 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9660 // TODO: check the state for each modem if the api is ready.
9661 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9662 }
9663
Pengquan Meng3889a572019-01-23 11:16:29 -08009664 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009665 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009666 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009667 // Verify that the callingPackage belongs to the calling UID
9668 mApp.getSystemService(AppOpsManager.class)
9669 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009670 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009671 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009672 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009673 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9674 if (slotInfos != null) {
9675 for (int i = 0; i < slotInfos.length; i++) {
9676 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9677 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9678 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9679 portInfo.getLogicalSlotIndex()));
9680 }
9681 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009682 }
9683 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009684 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009685 } finally {
9686 Binder.restoreCallingIdentity(identity);
9687 }
9688 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009689
9690 /**
9691 * Get the IRadio HAL Version
9692 */
9693 @Override
9694 public int getRadioHalVersion() {
9695 Phone phone = getDefaultPhone();
9696 if (phone == null) return -1;
9697 HalVersion hv = phone.getHalVersion();
9698 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9699 return hv.major * 100 + hv.minor;
9700 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009701
9702 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009703 * Get the current calling package name.
9704 * @return the current calling package name
9705 */
9706 @Override
9707 public String getCurrentPackageName() {
9708 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9709 }
9710
9711 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009712 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9713 * corresponding network requests on a subId.
9714 *
9715 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009716 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009717 * 2) APN is un-metered for this subscription, or
9718 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009719 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009720 *
9721 * @return whether data is allowed for a apn type.
9722 *
9723 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009724 */
9725 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009726 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009727 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9728 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009729
9730 // Now that all security checks passes, perform the operation as ourselves.
9731 final long identity = Binder.clearCallingIdentity();
9732 try {
9733 Phone phone = getPhone(subId);
9734 if (phone == null) return false;
9735
Jack Yu27422a52022-03-21 10:38:05 -07009736 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -08009737 boolean isDataEnabled;
9738 if (phone.isUsingNewDataStack()) {
Jack Yu27422a52022-03-21 10:38:05 -07009739 isMetered = phone.getDataNetworkController().getDataConfigManager()
9740 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
9741 phone.getServiceState().getDataRoaming());
Jack Yu99e87332021-12-17 23:14:15 -08009742 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
9743 } else {
Jack Yu27422a52022-03-21 10:38:05 -07009744 isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Jack Yu99e87332021-12-17 23:14:15 -08009745 isDataEnabled = phone.getDataEnabledSettings().isDataEnabled(apnType);
9746 }
9747 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009748 } finally {
9749 Binder.restoreCallingIdentity(identity);
9750 }
9751 }
9752
9753 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009754 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009755 enforceReadPrivilegedPermission("isApnMetered");
9756
9757 // Now that all security checks passes, perform the operation as ourselves.
9758 final long identity = Binder.clearCallingIdentity();
9759 try {
9760 Phone phone = getPhone(subId);
9761 if (phone == null) return true; // By default return true.
Jack Yu27422a52022-03-21 10:38:05 -07009762 if (phone.isUsingNewDataStack()) {
9763 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
9764 DataUtils.apnTypeToNetworkCapability(apnType),
9765 phone.getServiceState().getDataRoaming());
9766 }
Malcolm Chene5ad5792019-04-18 13:51:02 -07009767
Jack Yu41407ee2019-05-13 16:54:09 -07009768 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009769 } finally {
9770 Binder.restoreCallingIdentity(identity);
9771 }
9772 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009773
9774 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009775 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9776 int subscriptionId, IBooleanConsumer resultCallback) {
9777 enforceModifyPermission();
9778 long token = Binder.clearCallingIdentity();
9779 try {
9780 Phone phone = getPhone(subscriptionId);
9781 if (phone == null) {
9782 try {
9783 if (resultCallback != null) {
9784 resultCallback.accept(false);
9785 }
9786 } catch (RemoteException e) {
9787 // ignore
9788 }
9789 return;
9790 }
9791 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9792 Pair.create(specifiers, (x) -> {
9793 try {
9794 if (resultCallback != null) {
9795 resultCallback.accept(x);
9796 }
9797 } catch (RemoteException e) {
9798 // ignore
9799 }
9800 });
9801 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9802 } finally {
9803 Binder.restoreCallingIdentity(token);
9804 }
9805 }
9806
9807 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009808 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9809 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009810 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009811 mApp, subId, "getSystemSelectionChannels");
9812 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9813 final long identity = Binder.clearCallingIdentity();
9814 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009815 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9816 if (result instanceof IllegalStateException) {
9817 throw (IllegalStateException) result;
9818 }
9819 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009820 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9821 return specifiers;
9822 } finally {
9823 Binder.restoreCallingIdentity(identity);
9824 }
9825 }
9826
9827 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009828 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009829 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009830 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9831 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9832 if (iccRecords == null) {
9833 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9834 return false;
9835 }
9836 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9837 }
9838
9839 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009840 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9841 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009842 if (callingPackage == null) {
9843 callingPackage = getCurrentPackageName();
9844 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009845 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9846 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009847 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9848 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009849 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9850 }
9851 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9852 Intent intent = new Intent();
9853 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9854 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9855 // Bring up choose default SMS subscription dialog right now
9856 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9857 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9858 mApp.startActivity(intent);
9859 }
chen xud5ca2d52019-05-28 15:20:57 -07009860
9861 @Override
9862 public String getMmsUAProfUrl(int subId) {
9863 //TODO investigate if this API should require proper permission check in R b/133791609
9864 final long identity = Binder.clearCallingIdentity();
9865 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009866 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9867 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9868 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9869 return carrierUAProfUrl;
9870 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009871 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9872 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009873 } finally {
9874 Binder.restoreCallingIdentity(identity);
9875 }
9876 }
9877
9878 @Override
9879 public String getMmsUserAgent(int subId) {
9880 //TODO investigate if this API should require proper permission check in R b/133791609
9881 final long identity = Binder.clearCallingIdentity();
9882 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009883 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9884 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9885 if (!TextUtils.isEmpty(carrierUserAgent)) {
9886 return carrierUserAgent;
9887 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009888 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9889 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009890 } finally {
9891 Binder.restoreCallingIdentity(identity);
9892 }
9893 }
Jack Yub07d4972019-05-28 16:12:25 -07009894
9895 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009896 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9897 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009898
Jack Yub07d4972019-05-28 16:12:25 -07009899 final long identity = Binder.clearCallingIdentity();
9900 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009901 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009902 if (phone == null) return false;
9903
Hall Liua62f5da2020-09-25 10:42:19 -07009904 switch (policy) {
9905 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu99e87332021-12-17 23:14:15 -08009906 if (phone.isUsingNewDataStack()) {
9907 return phone.getDataSettingsManager().isDataAllowedInVoiceCall();
9908 } else {
9909 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9910 }
Hall Liua62f5da2020-09-25 10:42:19 -07009911 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu99e87332021-12-17 23:14:15 -08009912 if (phone.isUsingNewDataStack()) {
9913 return phone.getDataSettingsManager().isMmsAlwaysAllowed();
9914 } else {
9915 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9916 }
Hall Liua62f5da2020-09-25 10:42:19 -07009917 default:
9918 throw new IllegalArgumentException(policy + " is not a valid policy");
9919 }
Jack Yub07d4972019-05-28 16:12:25 -07009920 } finally {
9921 Binder.restoreCallingIdentity(identity);
9922 }
9923 }
9924
9925 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009926 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009927 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009928 enforceModifyPermission();
9929
changbettyd5c246e2019-12-24 15:40:37 +08009930 final long identity = Binder.clearCallingIdentity();
9931 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009932 Phone phone = getPhone(subscriptionId);
9933 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009934
Hall Liua62f5da2020-09-25 10:42:19 -07009935 switch (policy) {
9936 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu99e87332021-12-17 23:14:15 -08009937 if (phone.isUsingNewDataStack()) {
9938 phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled);
9939 } else {
9940 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9941 }
Hall Liua62f5da2020-09-25 10:42:19 -07009942 break;
9943 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu99e87332021-12-17 23:14:15 -08009944 if (phone.isUsingNewDataStack()) {
9945 phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled);
9946 } else {
9947 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9948 }
Hall Liua62f5da2020-09-25 10:42:19 -07009949 break;
9950 default:
9951 throw new IllegalArgumentException(policy + " is not a valid policy");
9952 }
changbettyd5c246e2019-12-24 15:40:37 +08009953 } finally {
9954 Binder.restoreCallingIdentity(identity);
9955 }
9956 }
9957
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009958 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009959 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009960 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9961 * otherwise.
9962 */
9963 @Override
9964 public void setCepEnabled(boolean isCepEnabled) {
9965 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9966
9967 final long identity = Binder.clearCallingIdentity();
9968 try {
9969 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9970 for (Phone phone : PhoneFactory.getPhones()) {
9971 Phone defaultPhone = phone.getImsPhone();
9972 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9973 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9974 ImsPhoneCallTracker imsPhoneCallTracker =
9975 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9976 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9977 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9978 + imsPhone.getMsisdn());
9979 }
9980 }
9981 } finally {
9982 Binder.restoreCallingIdentity(identity);
9983 }
9984 }
allenwtsu46dcc572020-01-08 18:24:03 +08009985
9986 /**
9987 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9988 *
9989 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9990 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9991 * before being read.
9992 */
9993 @Override
9994 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9995 isCompressed) {
9996 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9997 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009998 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9999 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10000 }
10001 if (!isImsAvailableOnDevice()) {
10002 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10003 "IMS not available on device.");
10004 }
10005
10006 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010007 try {
Hui Wang761a6682020-10-31 05:12:53 +000010008 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10009 } finally {
10010 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010011 }
10012 }
zoey chene02881a2019-12-30 16:11:23 +080010013
10014 @Override
10015 public boolean isIccLockEnabled(int subId) {
10016 enforceReadPrivilegedPermission("isIccLockEnabled");
10017
10018 // Now that all security checks passes, perform the operation as ourselves.
10019 final long identity = Binder.clearCallingIdentity();
10020 try {
10021 Phone phone = getPhone(subId);
10022 if (phone != null && phone.getIccCard() != null) {
10023 return phone.getIccCard().getIccLockEnabled();
10024 } else {
10025 return false;
10026 }
10027 } finally {
10028 Binder.restoreCallingIdentity(identity);
10029 }
10030 }
10031
10032 /**
10033 * Set the ICC pin lock enabled or disabled.
10034 *
10035 * @return an integer representing the status of IccLock enabled or disabled in the following
10036 * three cases:
10037 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10038 * successfully.
10039 * - Positive number and zero for remaining password attempts.
10040 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10041 *
10042 */
10043 @Override
10044 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10045 enforceModifyPermission();
10046
10047 Phone phone = getPhone(subId);
10048 if (phone == null) {
10049 return 0;
10050 }
10051 // Now that all security checks passes, perform the operation as ourselves.
10052 final long identity = Binder.clearCallingIdentity();
10053 try {
10054 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10055 new Pair<Boolean, String>(enabled, password), phone, null);
10056 return attemptsRemaining;
10057
10058 } catch (Exception e) {
10059 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10060 } finally {
10061 Binder.restoreCallingIdentity(identity);
10062 }
10063 return 0;
10064 }
10065
10066 /**
10067 * Change the ICC password used in ICC pin lock.
10068 *
10069 * @return an integer representing the status of IccLock changed in the following three cases:
10070 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10071 * - Positive number and zero for remaining password attempts.
10072 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10073 *
10074 */
10075 @Override
10076 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10077 enforceModifyPermission();
10078
10079 Phone phone = getPhone(subId);
10080 if (phone == null) {
10081 return 0;
10082 }
10083 // Now that all security checks passes, perform the operation as ourselves.
10084 final long identity = Binder.clearCallingIdentity();
10085 try {
10086 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10087 new Pair<String, String>(oldPassword, newPassword), phone, null);
10088 return attemptsRemaining;
10089
10090 } catch (Exception e) {
10091 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10092 } finally {
10093 Binder.restoreCallingIdentity(identity);
10094 }
10095 return 0;
10096 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010097
10098 /**
10099 * Request for receiving user activity notification
10100 */
10101 @Override
10102 public void requestUserActivityNotification() {
10103 if (!mNotifyUserActivity.get()
10104 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10105 mNotifyUserActivity.set(true);
10106 }
10107 }
10108
10109 /**
10110 * Called when userActivity is signalled in the power manager.
10111 * This is safe to call from any thread, with any window manager locks held or not.
10112 */
10113 @Override
10114 public void userActivity() {
10115 // ***************************************
10116 // * Inherited from PhoneWindowManager *
10117 // ***************************************
10118 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10119 // WITH ITS LOCKS HELD.
10120 //
10121 // This code must be VERY careful about the locks
10122 // it acquires.
10123 // In fact, the current code acquires way too many,
10124 // and probably has lurking deadlocks.
10125
10126 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10127 throw new SecurityException("Only the OS may call notifyUserActivity()");
10128 }
10129
10130 if (mNotifyUserActivity.getAndSet(false)) {
10131 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10132 USER_ACTIVITY_NOTIFICATION_DELAY);
10133 }
10134 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010135
10136 @Override
10137 public boolean canConnectTo5GInDsdsMode() {
10138 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10139 }
Jack Yud10cdd42020-09-28 20:28:01 -070010140
10141 @Override
10142 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10143 String callingFeatureId) {
10144 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10145 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10146 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10147 }
10148
10149 Phone phone = getPhone(subId);
10150 if (phone == null) {
10151 throw new RuntimeException("phone is not available");
10152 }
10153 // Now that all security checks passes, perform the operation as ourselves.
10154 final long identity = Binder.clearCallingIdentity();
10155 try {
10156 return phone.getEquivalentHomePlmns();
10157 } finally {
10158 Binder.restoreCallingIdentity(identity);
10159 }
10160 }
Daniel Bright59e67312020-11-13 11:49:37 -080010161
10162 @Override
10163 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010164 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10165 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010166 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010167 if (radioInterfaceCapabilities == null) {
10168 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010169 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010170 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010171 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010172
Hui Wang641e81c2020-10-12 12:14:23 -070010173 @Override
10174 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10175 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010176 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10177 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10178 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10179 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10180 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010181 if (DBG) {
10182 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10183 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10184 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10185 }
10186
10187 if (!SubscriptionManager.isValidSubscriptionId(subId)
10188 || appType < TelephonyManager.APPTYPE_UNKNOWN
10189 || appType > TelephonyManager.APPTYPE_ISIM
10190 || nafUrl == null || securityProtocol == null || callback == null) {
10191 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10192 if (callback != null) {
10193 try {
10194 callback.onAuthenticationFailure(
10195 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10196 } catch (RemoteException exception) {
10197 log("Fail to notify onAuthenticationFailure due to " + exception);
10198 }
10199 return;
10200 }
10201 }
10202
10203 final long token = Binder.clearCallingIdentity();
10204 try {
10205 getGbaManager(subId).bootstrapAuthenticationRequest(
10206 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10207 forceBootStrapping, callback));
10208 } finally {
10209 Binder.restoreCallingIdentity(token);
10210 }
10211 }
10212
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010213 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010214 * Attempts to set the radio power state for all phones for thermal reason.
10215 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010216 * requested radio power state will actually be set. See {@link
10217 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10218 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010219 * @param enable {@code true} if trying to turn radio on.
10220 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10221 * false}.
10222 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010223 private boolean setRadioPowerForThermal(boolean enable) {
10224 boolean isPhoneAvailable = false;
10225 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10226 Phone phone = PhoneFactory.getPhone(i);
10227 if (phone != null) {
10228 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10229 isPhoneAvailable = true;
10230 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010231 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010232
10233 // return true if successfully informed the phone object about the thermal radio power
10234 // request.
10235 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010236 }
10237
10238 private int handleDataThrottlingRequest(int subId,
10239 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010240 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10241 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10242 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10243 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10244 throw new IllegalArgumentException("modem does not support data throttling");
10245 }
10246
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010247 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10248 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010249 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010250 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10251 }
10252
10253 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10254
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010255 if (isDataThrottlingSupported) {
10256 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010257 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010258 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10259 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10260 } else if (thermalMitigationResult
10261 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010262 log("Modem likely does not support data throttling on secondary carrier. Data " +
10263 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10264 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010265 }
10266 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010267 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010268
10269 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010270 }
10271
Jack Nudelman644b91a2021-03-12 14:09:48 -080010272 private static List<String> getThermalMitigationAllowlist(Context context) {
10273 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10274 for (String pckg : context.getResources()
10275 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10276 sThermalMitigationAllowlistedPackages.add(pckg);
10277 }
10278 }
10279
10280 return sThermalMitigationAllowlistedPackages;
10281 }
10282
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010283 private boolean isAnyPhoneInEmergencyState() {
10284 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10285 if (tm.isInEmergencyCall()) {
10286 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10287 return true;
10288 }
10289 for (Phone phone : PhoneFactory.getPhones()) {
10290 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10291 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10292 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10293 + phone.isInEcm());
10294 return true;
10295 }
10296 }
10297
10298 return false;
10299 }
10300
Jack Nudelman644b91a2021-03-12 14:09:48 -080010301 /**
10302 * Used by shell commands to add an authorized package name for thermal mitigation.
10303 * @param packageName name of package to be allowlisted
10304 * @param context
10305 */
10306 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10307 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10308 sThermalMitigationAllowlistedPackages.add(packageName);
10309 }
10310
10311 /**
10312 * Used by shell commands to remove an authorized package name for thermal mitigation.
10313 * @param packageName name of package to remove from allowlist
10314 * @param context
10315 */
10316 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10317 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10318 sThermalMitigationAllowlistedPackages.remove(packageName);
10319 }
10320
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010321 /**
10322 * Thermal mitigation request to control functionalities at modem.
10323 *
10324 * @param subId the id of the subscription.
10325 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010326 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010327 *
10328 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10329 */
10330 @Override
10331 @ThermalMitigationResult
10332 public int sendThermalMitigationRequest(
10333 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010334 ThermalMitigationRequest thermalMitigationRequest,
10335 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010336 enforceModifyPermission();
10337
Jack Nudelman644b91a2021-03-12 14:09:48 -080010338 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10339 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10340 .contains(callingPackage)) {
10341 throw new SecurityException("Calling package must be configured in the device config. "
10342 + "calling package: " + callingPackage);
10343 }
10344
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010345 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10346 final long identity = Binder.clearCallingIdentity();
10347
10348 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10349 try {
10350 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10351 switch (thermalMitigationAction) {
10352 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10353 thermalMitigationResult =
10354 handleDataThrottlingRequest(subId,
10355 thermalMitigationRequest.getDataThrottlingRequest());
10356 break;
10357 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10358 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10359 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10360 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10361 }
10362
10363 // Ensure that radio is on. If not able to power on due to phone being
10364 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010365 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010366 thermalMitigationResult =
10367 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10368 break;
10369 }
10370
10371 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10372 false);
10373 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10374 break;
10375 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10376 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10377 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10378 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10379 }
10380
10381 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10382 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010383 Phone phone = getPhone(subId);
10384 if (phone == null) {
10385 thermalMitigationResult =
10386 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10387 break;
10388 }
10389
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010390 TelephonyConnectionService service =
10391 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010392 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010393 Log.e(LOG_TAG, "An emergency call is pending");
10394 thermalMitigationResult =
10395 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10396 break;
10397 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010398 thermalMitigationResult =
10399 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10400 break;
10401 }
10402 } else {
10403 thermalMitigationResult =
10404 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10405 break;
10406 }
10407
10408 // Turn radio off. If not able to power off due to phone being unavailable,
10409 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010410 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010411 thermalMitigationResult =
10412 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10413 break;
10414 }
10415 thermalMitigationResult =
10416 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10417 break;
10418 default:
10419 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10420 + "not exist. Requested action: " + thermalMitigationAction);
10421 }
10422 } catch (IllegalArgumentException e) {
10423 throw e;
10424 } catch (Exception e) {
10425 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10426 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10427 } finally {
10428 Binder.restoreCallingIdentity(identity);
10429 }
10430
10431 if (DBG) {
10432 log("thermalMitigationRequest returning with thermalMitigationResult: "
10433 + thermalMitigationResult);
10434 }
10435
10436 return thermalMitigationResult;
10437 }
Hui Wang641e81c2020-10-12 12:14:23 -070010438
10439 /**
10440 * Set the GbaService Package Name that Telephony will bind to.
10441 *
10442 * @param subId The sim that the GbaService is associated with.
10443 * @param packageName The name of the package to be replaced with.
10444 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10445 */
10446 @Override
10447 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10448 enforceModifyPermission();
10449
10450 final long identity = Binder.clearCallingIdentity();
10451 try {
10452 return getGbaManager(subId).overrideServicePackage(packageName);
10453 } finally {
10454 Binder.restoreCallingIdentity(identity);
10455 }
10456 }
10457
10458 /**
10459 * Return the package name of the currently bound GbaService.
10460 *
10461 * @param subId The sim that the GbaService is associated with.
10462 * @return the package name of the GbaService configuration, null if GBA is not supported.
10463 */
10464 @Override
10465 public String getBoundGbaService(int subId) {
10466 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10467
10468 final long identity = Binder.clearCallingIdentity();
10469 try {
10470 return getGbaManager(subId).getServicePackage();
10471 } finally {
10472 Binder.restoreCallingIdentity(identity);
10473 }
10474 }
10475
10476 /**
10477 * Set the release time for telephony to unbind GbaService.
10478 *
10479 * @param subId The sim that the GbaService is associated with.
10480 * @param interval The release time to unbind GbaService by millisecond.
10481 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10482 */
10483 @Override
10484 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10485 enforceModifyPermission();
10486
10487 final long identity = Binder.clearCallingIdentity();
10488 try {
10489 return getGbaManager(subId).overrideReleaseTime(interval);
10490 } finally {
10491 Binder.restoreCallingIdentity(identity);
10492 }
10493 }
10494
10495 /**
10496 * Return the release time for telephony to unbind GbaService.
10497 *
10498 * @param subId The sim that the GbaService is associated with.
10499 * @return The release time to unbind GbaService by millisecond.
10500 */
10501 @Override
10502 public int getGbaReleaseTime(int subId) {
10503 enforceReadPrivilegedPermission("getGbaReleaseTime");
10504
10505 final long identity = Binder.clearCallingIdentity();
10506 try {
10507 return getGbaManager(subId).getReleaseTime();
10508 } finally {
10509 Binder.restoreCallingIdentity(identity);
10510 }
10511 }
10512
10513 private GbaManager getGbaManager(int subId) {
10514 GbaManager instance = GbaManager.getInstance(subId);
10515 if (instance == null) {
10516 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10517 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10518 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10519 }
10520 return instance;
10521 }
Hui Wang761a6682020-10-31 05:12:53 +000010522
10523 /**
10524 * indicate whether the device and the carrier can support
10525 * RCS VoLTE single registration.
10526 */
10527 @Override
10528 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010529 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10530 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10531 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10532 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010533
10534 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10535 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10536 }
10537
10538 final long identity = Binder.clearCallingIdentity();
10539 try {
10540 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10541 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010542 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10543 if (isCapable != null) {
10544 return isCapable;
10545 }
Hui Wang761a6682020-10-31 05:12:53 +000010546 }
Hui Wang67af90e2021-06-04 16:57:15 -070010547 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10548 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010549 } finally {
10550 Binder.restoreCallingIdentity(identity);
10551 }
10552 }
10553
10554 /**
10555 * Register RCS provisioning callback.
10556 */
10557 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010558 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010559 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010560 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010561 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010562 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10563 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010564
10565 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10566 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10567 }
10568 if (!isImsAvailableOnDevice()) {
10569 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10570 "IMS not available on device.");
10571 }
10572
10573 final long identity = Binder.clearCallingIdentity();
10574 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010575 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010576 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010577 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10578 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010579 }
Hui Wang761a6682020-10-31 05:12:53 +000010580 } finally {
10581 Binder.restoreCallingIdentity(identity);
10582 }
10583 }
10584
10585 /**
10586 * Unregister RCS provisioning callback.
10587 */
10588 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010589 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010590 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010591 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010592 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010593 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10594 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010595
10596 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10597 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10598 }
10599 if (!isImsAvailableOnDevice()) {
10600 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10601 "IMS not available on device.");
10602 }
10603
10604 final long identity = Binder.clearCallingIdentity();
10605 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010606 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010607 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010608 } finally {
10609 Binder.restoreCallingIdentity(identity);
10610 }
10611 }
10612
10613 /**
10614 * trigger RCS reconfiguration.
10615 */
10616 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010617 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10618 "triggerRcsReconfiguration",
10619 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
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 {
10631 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10632 } finally {
10633 Binder.restoreCallingIdentity(identity);
10634 }
10635 }
10636
10637 /**
10638 * Provide the client configuration parameters of the RCS application.
10639 */
10640 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010641 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10642 "setRcsClientConfiguration",
10643 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010644
10645 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10646 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10647 }
10648 if (!isImsAvailableOnDevice()) {
10649 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10650 "IMS not available on device.");
10651 }
10652
10653 final long identity = Binder.clearCallingIdentity();
10654
10655 try {
10656 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10657 if (configBinder == null) {
10658 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010659 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10660 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010661 } else {
10662 configBinder.setRcsClientConfiguration(rcc);
10663 }
joonhunshin3e154242021-09-17 06:33:39 +000010664
10665 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10666 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010667 } catch (RemoteException e) {
10668 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010669 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10670 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010671 } finally {
10672 Binder.restoreCallingIdentity(identity);
10673 }
10674 }
10675
10676 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010677 * Enables or disables the test mode for RCS VoLTE single registration.
10678 */
10679 @Override
10680 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10681 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10682 "setRcsSingleRegistrationTestModeEnabled");
10683
10684 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10685 }
10686
10687 /**
10688 * Gets the test mode for RCS VoLTE single registration.
10689 */
10690 @Override
10691 public boolean getRcsSingleRegistrationTestModeEnabled() {
10692 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10693 "getRcsSingleRegistrationTestModeEnabled");
10694
10695 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10696 }
10697
10698 /**
Hui Wang761a6682020-10-31 05:12:53 +000010699 * Overrides the config of RCS VoLTE single registration enabled for the device.
10700 */
10701 @Override
10702 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10703 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10704 "setDeviceSingleRegistrationEnabledOverride");
10705 enforceModifyPermission();
10706
10707 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10708 : Boolean.parseBoolean(enabledStr);
10709 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010710 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010711 }
10712
10713 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010714 * Sends a device to device communication message. Only usable via shell.
10715 * @param message message to send.
10716 * @param value message value.
10717 */
10718 @Override
10719 public void sendDeviceToDeviceMessage(int message, int value) {
10720 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010721 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010722 enforceModifyPermission();
10723
10724 final long identity = Binder.clearCallingIdentity();
10725 try {
10726 TelephonyConnectionService service =
10727 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10728 if (service == null) {
10729 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10730 return;
10731 }
10732 service.sendTestDeviceToDeviceMessage(message, value);
10733 } finally {
10734 Binder.restoreCallingIdentity(identity);
10735 }
10736 }
10737
Tyler Gunnbabbda02021-02-10 11:05:02 -080010738 /**
10739 * Sets the specified device to device transport active.
10740 * @param transport The transport to set active.
10741 */
10742 @Override
10743 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10744 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10745 "setActiveDeviceToDeviceTransport");
10746 enforceModifyPermission();
10747
10748 final long identity = Binder.clearCallingIdentity();
10749 try {
10750 TelephonyConnectionService service =
10751 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10752 if (service == null) {
10753 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10754 return;
10755 }
10756 service.setActiveDeviceToDeviceTransport(transport);
10757 } finally {
10758 Binder.restoreCallingIdentity(identity);
10759 }
10760 }
Tyler Gunn92479152021-01-20 16:30:10 -080010761
Tyler Gunnd4339262021-05-03 14:46:49 -070010762 @Override
10763 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10764 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10765 "setDeviceToDeviceForceEnabled");
10766
10767 final long identity = Binder.clearCallingIdentity();
10768 try {
10769 Arrays.stream(PhoneFactory.getPhones()).forEach(
10770 p -> {
10771 Phone thePhone = p.getImsPhone();
10772 if (thePhone != null && thePhone instanceof ImsPhone) {
10773 ImsPhone imsPhone = (ImsPhone) thePhone;
10774 CallTracker tracker = imsPhone.getCallTracker();
10775 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10776 ImsPhoneCallTracker imsPhoneCallTracker =
10777 (ImsPhoneCallTracker) tracker;
10778 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10779 }
10780 }
10781 }
10782 );
10783 } finally {
10784 Binder.restoreCallingIdentity(identity);
10785 }
10786 }
10787
Tyler Gunn92479152021-01-20 16:30:10 -080010788 /**
Hui Wang761a6682020-10-31 05:12:53 +000010789 * Gets the config of RCS VoLTE single registration enabled for the device.
10790 */
10791 @Override
10792 public boolean getDeviceSingleRegistrationEnabled() {
10793 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10794 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10795 }
10796
10797 /**
10798 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10799 */
10800 @Override
10801 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10802 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10803 "setCarrierSingleRegistrationEnabledOverride");
10804 enforceModifyPermission();
10805
10806 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10807 : Boolean.parseBoolean(enabledStr);
10808 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10809 subId, enabled);
10810 }
10811
10812 /**
10813 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10814 */
10815 @Override
10816 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10817 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10818 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10819 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010820
10821 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010822 * Overrides the ims feature validation result
10823 */
10824 @Override
10825 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10826 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10827 "setImsFeatureValidationOverride");
10828
10829 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10830 : Boolean.parseBoolean(enabledStr);
10831 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10832 subId, enabled);
10833 }
10834
10835 /**
10836 * Gets the ims feature validation override value
10837 */
10838 @Override
10839 public boolean getImsFeatureValidationOverride(int subId) {
10840 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10841 "getImsFeatureValidationOverride");
10842 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10843 }
10844
10845 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010846 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10847 * their mobile plan.
10848 */
10849 @Override
10850 public String getMobileProvisioningUrl() {
10851 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10852 final long identity = Binder.clearCallingIdentity();
10853 try {
10854 return getDefaultPhone().getMobileProvisioningUrl();
10855 } finally {
10856 Binder.restoreCallingIdentity(identity);
10857 }
10858 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010859
James.cf Linbcdf8b32021-01-14 16:44:13 +080010860 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010861 * Get the EAB contact from the EAB database.
10862 */
10863 @Override
10864 public String getContactFromEab(String contact) {
10865 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10866 enforceModifyPermission();
10867 final long identity = Binder.clearCallingIdentity();
10868 try {
10869 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10870 } finally {
10871 Binder.restoreCallingIdentity(identity);
10872 }
10873 }
10874
10875 /**
Calvin Pana1434322021-07-01 19:27:01 +080010876 * Get the EAB capability from the EAB database.
10877 */
10878 @Override
10879 public String getCapabilityFromEab(String contact) {
10880 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10881 enforceModifyPermission();
10882 final long identity = Binder.clearCallingIdentity();
10883 try {
10884 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10885 } finally {
10886 Binder.restoreCallingIdentity(identity);
10887 }
10888 }
10889
10890 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010891 * Remove the EAB contacts from the EAB database.
10892 */
10893 @Override
10894 public int removeContactFromEab(int subId, String contacts) {
10895 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10896 enforceModifyPermission();
10897 final long identity = Binder.clearCallingIdentity();
10898 try {
10899 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10900 } finally {
10901 Binder.restoreCallingIdentity(identity);
10902 }
10903 }
10904
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010905 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010906 public boolean getDeviceUceEnabled() {
10907 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10908 final long identity = Binder.clearCallingIdentity();
10909 try {
10910 return mApp.getDeviceUceEnabled();
10911 } finally {
10912 Binder.restoreCallingIdentity(identity);
10913 }
10914 }
10915
10916 @Override
10917 public void setDeviceUceEnabled(boolean isEnabled) {
10918 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10919 final long identity = Binder.clearCallingIdentity();
10920 try {
10921 mApp.setDeviceUceEnabled(isEnabled);
10922 } finally {
10923 Binder.restoreCallingIdentity(identity);
10924 }
10925 }
10926
Brad Ebinger14d467f2021-02-12 06:18:28 +000010927 /**
10928 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10929 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10930 */
10931 // Used for SHELL command only right now.
10932 @Override
10933 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10934 List<String> featureTags) {
10935 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10936 "addUceRegistrationOverrideShell");
10937 final long identity = Binder.clearCallingIdentity();
10938 try {
10939 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10940 new ArraySet<>(featureTags));
10941 } catch (ImsException e) {
10942 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10943 } finally {
10944 Binder.restoreCallingIdentity(identity);
10945 }
10946 }
10947
10948 /**
10949 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10950 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10951 */
10952 // Used for SHELL command only right now.
10953 @Override
10954 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10955 List<String> featureTags) {
10956 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10957 "removeUceRegistrationOverrideShell");
10958 final long identity = Binder.clearCallingIdentity();
10959 try {
10960 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10961 new ArraySet<>(featureTags));
10962 } catch (ImsException e) {
10963 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10964 } finally {
10965 Binder.restoreCallingIdentity(identity);
10966 }
10967 }
10968
10969 /**
10970 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10971 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10972 */
10973 // Used for SHELL command only right now.
10974 @Override
10975 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10976 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10977 "clearUceRegistrationOverrideShell");
10978 final long identity = Binder.clearCallingIdentity();
10979 try {
10980 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10981 } catch (ImsException e) {
10982 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10983 } finally {
10984 Binder.restoreCallingIdentity(identity);
10985 }
10986 }
10987
10988 /**
10989 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10990 */
10991 // Used for SHELL command only right now.
10992 @Override
10993 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10994 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10995 "getLatestRcsContactUceCapabilityShell");
10996 final long identity = Binder.clearCallingIdentity();
10997 try {
10998 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10999 } catch (ImsException e) {
11000 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11001 } finally {
11002 Binder.restoreCallingIdentity(identity);
11003 }
11004 }
11005
11006 /**
11007 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11008 * device does not have an active PUBLISH.
11009 */
11010 // Used for SHELL command only right now.
11011 @Override
11012 public String getLastUcePidfXmlShell(int subId) {
11013 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11014 final long identity = Binder.clearCallingIdentity();
11015 try {
11016 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11017 } catch (ImsException e) {
11018 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11019 } finally {
11020 Binder.restoreCallingIdentity(identity);
11021 }
11022 }
11023
James.cf Line8713a42021-04-29 16:04:26 +080011024 /**
11025 * Remove UCE requests cannot be sent to the network status.
11026 */
11027 // Used for SHELL command only right now.
11028 @Override
11029 public boolean removeUceRequestDisallowedStatus(int subId) {
11030 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11031 final long identity = Binder.clearCallingIdentity();
11032 try {
11033 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11034 } catch (ImsException e) {
11035 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11036 } finally {
11037 Binder.restoreCallingIdentity(identity);
11038 }
11039 }
11040
James.cf Lin18bb9002021-05-25 01:37:38 +080011041 /**
11042 * Remove UCE requests cannot be sent to the network status.
11043 */
11044 // Used for SHELL command only.
11045 @Override
11046 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11047 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11048 final long identity = Binder.clearCallingIdentity();
11049 try {
11050 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11051 } catch (ImsException e) {
11052 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11053 } finally {
11054 Binder.restoreCallingIdentity(identity);
11055 }
11056 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011057
James.cf Lin4b784aa2021-01-31 03:25:15 +080011058 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011059 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11060 String callingPackage) {
11061 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11062 mApp, subId, "setSignalStrengthUpdateRequest");
11063
11064 final int callingUid = Binder.getCallingUid();
11065 // Verify that tha callingPackage belongs to the calling UID
11066 mApp.getSystemService(AppOpsManager.class)
11067 .checkPackage(callingUid, callingPackage);
11068
Rambo Wang3607f502021-02-01 21:51:40 -080011069 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011070
11071 final long identity = Binder.clearCallingIdentity();
11072 try {
11073 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11074 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11075
11076 if (result instanceof IllegalStateException) {
11077 throw (IllegalStateException) result;
11078 }
11079 } finally {
11080 Binder.restoreCallingIdentity(identity);
11081 }
11082 }
11083
11084 @Override
11085 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11086 String callingPackage) {
11087 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11088 mApp, subId, "clearSignalStrengthUpdateRequest");
11089
11090 final int callingUid = Binder.getCallingUid();
11091 // Verify that tha callingPackage belongs to the calling UID
11092 mApp.getSystemService(AppOpsManager.class)
11093 .checkPackage(callingUid, callingPackage);
11094
11095 final long identity = Binder.clearCallingIdentity();
11096 try {
11097 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11098 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11099
11100 if (result instanceof IllegalStateException) {
11101 throw (IllegalStateException) result;
11102 }
11103 } finally {
11104 Binder.restoreCallingIdentity(identity);
11105 }
11106 }
11107
Rambo Wang3607f502021-02-01 21:51:40 -080011108 private static void validateSignalStrengthUpdateRequest(Context context,
11109 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011110 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11111 // phone/system process do not have further restriction on request
11112 return;
11113 }
11114
11115 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011116 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011117 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011118 context.enforceCallingOrSelfPermission(
11119 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11120 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011121 }
11122
11123 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11124 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11125 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11126 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11127 || info.isEnabled()) {
11128 throw new IllegalArgumentException(
11129 "Only system can set hide fields in SignalThresholdInfo");
11130 }
11131
11132 // Thresholds length for each RAN need in range. This has been validated in
11133 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11134 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11135 final int[] thresholds = info.getThresholds();
11136 Objects.requireNonNull(thresholds);
11137 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11138 || thresholds.length
11139 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11140 throw new IllegalArgumentException(
11141 "thresholds length is out of range: " + thresholds.length);
11142 }
11143 }
11144 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011145
11146 /**
11147 * Gets the current phone capability.
11148 *
11149 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11150 * @return the PhoneCapability which describes the data connection capability of modem.
11151 * It's used to evaluate possible phone config change, for example from single
11152 * SIM device to multi-SIM device.
11153 */
11154 @Override
11155 public PhoneCapability getPhoneCapability() {
11156 enforceReadPrivilegedPermission("getPhoneCapability");
11157 final long identity = Binder.clearCallingIdentity();
11158 try {
11159 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11160 } finally {
11161 Binder.restoreCallingIdentity(identity);
11162 }
11163 }
Michele Berionne5e411512020-11-13 02:36:59 +000011164
11165 /**
11166 * Prepare TelephonyManager for an unattended reboot. The reboot is
11167 * required to be done shortly after the API is invoked.
11168 */
11169 @Override
11170 @TelephonyManager.PrepareUnattendedRebootResult
11171 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011172 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011173 enforceRebootPermission();
11174
11175 final long identity = Binder.clearCallingIdentity();
11176 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011177 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011178 } finally {
11179 Binder.restoreCallingIdentity(identity);
11180 }
11181 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011182
11183 /**
11184 * Request to get the current slicing configuration including URSP rules and
11185 * NSSAIs (configured, allowed and rejected).
11186 *
11187 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11188 */
11189 @Override
11190 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011191 TelephonyPermissions
11192 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11193 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011194
11195 final long identity = Binder.clearCallingIdentity();
11196 try {
11197 Phone phone = getDefaultPhone();
11198 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11199 } finally {
11200 Binder.restoreCallingIdentity(identity);
11201 }
11202 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011203
11204 /**
11205 * Register an IMS connection state callback
11206 */
11207 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011208 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11209 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011210 if (feature == ImsFeature.FEATURE_MMTEL) {
11211 // ImsMmTelManager
11212 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11213 TelephonyPermissions
11214 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11215 mApp, subId, "registerImsStateCallback");
11216 } else if (feature == ImsFeature.FEATURE_RCS) {
11217 // ImsRcsManager or SipDelegateManager
11218 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11219 Binder.getCallingUid(), "registerImsStateCallback",
11220 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11221 Manifest.permission.READ_PRECISE_PHONE_STATE,
11222 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11223 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11224 }
11225
11226 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11227 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11228 "IMS not available on device.");
11229 }
11230
11231 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11232 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11233 }
11234
11235 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11236 if (controller == null) {
11237 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11238 "IMS not available on device.");
11239 }
11240
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011241 if (callingPackage == null) {
11242 callingPackage = getCurrentPackageName();
11243 }
11244
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011245 final long token = Binder.clearCallingIdentity();
11246 try {
11247 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011248 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011249 } catch (ImsException e) {
11250 throw new ServiceSpecificException(e.getCode());
11251 } finally {
11252 Binder.restoreCallingIdentity(token);
11253 }
11254 }
11255
11256 /**
11257 * Unregister an IMS connection state callback
11258 */
11259 @Override
11260 public void unregisterImsStateCallback(IImsStateCallback cb) {
11261 final long token = Binder.clearCallingIdentity();
11262 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11263 if (controller == null) {
11264 return;
11265 }
11266 try {
11267 controller.unregisterImsStateCallback(cb);
11268 } finally {
11269 Binder.restoreCallingIdentity(token);
11270 }
11271 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011272
11273 /**
11274 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11275 *
11276 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11277 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11278 * SecurityException.
11279 * If there is current registered network this value will be same as the registered cell
11280 * identity. If the device goes out of service the previous cell identity is cached and
11281 * will be returned. If the cache age of the Cell identity is more than 24 hours
11282 * it will be cleared and null will be returned.
11283 *
11284 */
11285 @Override
11286 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11287 String callingFeatureId) {
11288 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11289 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11290 LocationAccessPolicy.checkLocationPermission(mApp,
11291 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11292 .setCallingPackage(callingPackage)
11293 .setCallingFeatureId(callingFeatureId)
11294 .setCallingPid(Binder.getCallingPid())
11295 .setCallingUid(Binder.getCallingUid())
11296 .setMethod("getLastKnownCellIdentity")
11297 .setLogAsInfo(true)
11298 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11299 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11300 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11301 .build());
11302
11303 boolean hasFinePermission =
11304 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11305 if (!hasFinePermission
11306 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11307 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
11308 + "and BIND_CONNECTION_SERVICE permission.");
11309 }
11310
11311 final long identity = Binder.clearCallingIdentity();
11312 try {
11313 Phone phone = getPhone(subId);
11314 if (phone == null) return null;
11315 ServiceStateTracker sst = phone.getServiceStateTracker();
11316 if (sst == null) return null;
11317 return sst.getLastKnownCellIdentity();
11318 } finally {
11319 Binder.restoreCallingIdentity(identity);
11320 }
11321 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011322
11323 @Override
11324 public boolean isUsingNewDataStack() {
11325 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "isUsingNewDataStack");
11326 return getDefaultPhone().isUsingNewDataStack();
11327 }
jimsun3b9ccac2021-10-26 15:01:23 +080011328
11329 /**
11330 * Sets the modem service class Name that Telephony will bind to.
11331 *
11332 * @param serviceName The class name of the modem service.
11333 * @return true if the operation is succeed, otherwise false.
11334 */
11335 public boolean setModemService(String serviceName) {
11336 Log.d(LOG_TAG, "setModemService - " + serviceName);
11337 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11338 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11339 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11340 "setModemService");
11341 return mPhoneConfigurationManager.setModemService(serviceName);
11342 }
11343
11344 /**
11345 * Return the class name of the currently bounded modem service.
11346 *
11347 * @return the class name of the modem service.
11348 */
11349 public String getModemService() {
11350 String result;
11351 Log.d(LOG_TAG, "getModemService");
11352 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11353 TelephonyPermissions
11354 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11355 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11356 "getModemService");
11357 result = mPhoneConfigurationManager.getModemService();
11358 Log.d(LOG_TAG, "result = " + result);
11359 return result;
11360 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011361
11362 @Override
11363 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11364 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11365 mApp.enforceCallingOrSelfPermission(
11366 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11367 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11368
11369 final long identity = Binder.clearCallingIdentity();
11370 try {
11371 Phone phone = getPhone(subId);
11372 if (phone == null) return;
11373 phone.setVoiceServiceStateOverride(hasService);
11374 } finally {
11375 Binder.restoreCallingIdentity(identity);
11376 }
11377 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011378}