blob: 07d2c6d682f7805473698994d5a00db73a3c5120 [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;
Chen Xu540470b2021-12-14 17:15:47 -080036import android.compat.Compatibility;
sandeepjsb6c87872021-09-27 15:34:44 +000037import android.compat.annotation.ChangeId;
38import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070039import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070040import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.content.Context;
42import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070043import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070044import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080045import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070046import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.net.Uri;
48import android.os.AsyncResult;
49import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080050import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070051import android.os.Bundle;
52import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070053import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054import android.os.Looper;
55import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070056import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080057import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070058import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070059import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080060import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080061import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070062import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070063import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080064import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070065import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070066import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070067import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070068import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070069import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080070import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070071import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090072import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080073import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080074import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070075import android.telecom.TelecomManager;
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;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700127import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800128import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700129import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800130import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700131import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000132import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700133import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800134import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800135import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800136import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800137import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800139import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700140import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700141import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800142import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800143
Andrew Lee312e8172014-10-23 17:01:36 -0700144import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800145import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800146import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800147import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800148import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700149import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700150import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700151import com.android.internal.telephony.CallTracker;
chen xu651eec72018-11-11 19:03:44 -0800152import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700153import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700154import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800155import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700156import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700157import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800158import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800159import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800160import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700161import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000162import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700163import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800164import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700165import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800166import com.android.internal.telephony.IccCard;
Rambo Wanga1782702021-11-10 20:15:19 -0800167import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700168import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700169import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700170import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700171import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700172import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800173import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700174import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700175import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700176import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700177import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800178import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800179import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700180import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700181import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700182import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800183import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800184import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800185import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700186import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800187import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700188import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800189import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700190import com.android.internal.telephony.imsphone.ImsPhone;
191import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000192import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800193import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700194import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700195import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800196import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700197import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800198import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700199import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800200import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700201import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000202import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800203import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000204import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800205import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700206import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700207import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800208import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800209import com.android.phone.callcomposer.CallComposerPictureManager;
210import com.android.phone.callcomposer.CallComposerPictureTransfer;
211import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700212import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700213import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800214import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700215import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700216import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800217import com.android.services.telephony.TelecomAccountRegistry;
218import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800219import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800220
Hall Liu82694d52020-12-11 18:22:04 -0800221import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700222import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800223import java.io.IOException;
224import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700225import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700226import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800227import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000228import java.util.Collection;
sqian11b7a0e2018-12-05 18:48:28 -0800229import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800230import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800231import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100232import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800233import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700234import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800235import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800236import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800237import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800238import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800239import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700240
241/**
242 * Implementation of the ITelephony interface.
243 */
Santos Cordon117fee72014-05-16 17:56:12 -0700244public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700245 private static final String LOG_TAG = "PhoneInterfaceManager";
246 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
247 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800248 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700249
250 // Message codes used with mMainThreadHandler
251 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700252 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
253 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700254 private static final int CMD_OPEN_CHANNEL = 9;
255 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
256 private static final int CMD_CLOSE_CHANNEL = 11;
257 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800258 private static final int CMD_NV_READ_ITEM = 13;
259 private static final int EVENT_NV_READ_ITEM_DONE = 14;
260 private static final int CMD_NV_WRITE_ITEM = 15;
261 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
262 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
263 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700264 private static final int CMD_RESET_MODEM_CONFIG = 19;
265 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800266 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
267 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800268 private static final int CMD_SEND_ENVELOPE = 25;
269 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000270 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
271 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700272 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
273 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
274 private static final int CMD_EXCHANGE_SIM_IO = 31;
275 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800276 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
277 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700278 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
279 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700280 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
281 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700282 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
283 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
284 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
285 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700286 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
287 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
288 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
289 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700290 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800291 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
292 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000293 private static final int CMD_SWITCH_SLOTS = 50;
294 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700295 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
296 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
297 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
298 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
299 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
300 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
301 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
302 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700303 private static final int CMD_GET_ALL_CELL_INFO = 60;
304 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
305 private static final int CMD_GET_CELL_LOCATION = 62;
306 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700307 private static final int CMD_MODEM_REBOOT = 64;
308 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700309 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
310 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800311 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
312 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700313 private static final int CMD_GET_MODEM_STATUS = 70;
314 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700315 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
316 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700317 private static final int CMD_ERASE_MODEM_CONFIG = 74;
318 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800319 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
320 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
321 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
322 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800323 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
324 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800325 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800326 private static final int CMD_GET_CALL_FORWARDING = 83;
327 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
328 private static final int CMD_SET_CALL_FORWARDING = 85;
329 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
330 private static final int CMD_GET_CALL_WAITING = 87;
331 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
332 private static final int CMD_SET_CALL_WAITING = 89;
333 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700334 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
335 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
336 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
337 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700338 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
339 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800340 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
341 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800342 private static final int CMD_SET_DATA_THROTTLING = 99;
343 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800344 private static final int CMD_SET_SIM_POWER = 101;
345 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800346 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
347 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
348 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
349 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800350 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
351 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000352 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800353 private static final int CMD_GET_SLICING_CONFIG = 110;
354 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800355 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700356 private static final int CMD_ENABLE_VONR = 113;
357 private static final int EVENT_ENABLE_VONR_DONE = 114;
358 private static final int CMD_IS_VONR_ENABLED = 115;
359 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700360
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800361 // Parameters of select command.
362 private static final int SELECT_COMMAND = 0xA4;
363 private static final int SELECT_P1 = 0x04;
364 private static final int SELECT_P2 = 0;
365 private static final int SELECT_P3 = 0x10;
366
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700367 /** The singleton instance. */
368 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800369 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700370
Wink Saville3ab207e2014-11-20 13:07:20 -0800371 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800372 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800373 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700374 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800375 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700376 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800377 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800378 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800379 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700380 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800381 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700382
Peter Wangdafb9ac2020-01-15 14:13:38 -0800383 /** User Activity */
384 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800385 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
386
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700387 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
388
Derek Tan97ebb422014-09-05 16:55:38 -0700389 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
390 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800391 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800392 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700393
Michelecea4cf22018-12-21 15:00:11 -0800394 // String to store multi SIM allowed
395 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
396
Derek Tan740e1672017-06-27 14:56:27 -0700397 // The AID of ISD-R.
398 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
399
yinxub1bed742017-04-17 11:45:04 -0700400 private NetworkScanRequestTracker mNetworkScanRequestTracker;
401
David Kelly5e06a7f2018-03-12 14:10:59 +0000402 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
403 private static final int MANUFACTURER_CODE_LENGTH = 8;
404
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800405 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800406 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800407
Derek Tan89e89d42014-07-08 17:00:10 -0700408 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700409 * Experiment flag to enable erase modem config on reset network, default value is false
410 */
411 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
412 "reset_network_erase_modem_config_enabled";
413
Rambo Wang0f050d82021-02-12 11:43:36 -0800414 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800415
sandeepjsb6c87872021-09-27 15:34:44 +0000416 /**
417 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
418 * one ICCID active at the same time.
419 * Apps should use below API signatures if targeting SDK is T and beyond.
420 *
421 * @hide
422 */
423 @ChangeId
424 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
425 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800426
Naina Nallurid63128d2019-09-17 14:10:30 -0700427 /**
Chen Xu540470b2021-12-14 17:15:47 -0800428 * Apps targeting on Android T and beyond will get exception whenever icc close channel
429 * operation fails.
430 */
431 @ChangeId
432 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
433 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
434
435 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700436 * A request object to use for transmitting data to an ICC.
437 */
438 private static final class IccAPDUArgument {
439 public int channel, cla, command, p1, p2, p3;
440 public String data;
441
442 public IccAPDUArgument(int channel, int cla, int command,
443 int p1, int p2, int p3, String data) {
444 this.channel = channel;
445 this.cla = cla;
446 this.command = command;
447 this.p1 = p1;
448 this.p2 = p2;
449 this.p3 = p3;
450 this.data = data;
451 }
452 }
453
454 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700455 * A request object to use for transmitting data to an ICC.
456 */
457 private static final class ManualNetworkSelectionArgument {
458 public OperatorInfo operatorInfo;
459 public boolean persistSelection;
460
461 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
462 this.operatorInfo = operatorInfo;
463 this.persistSelection = persistSelection;
464 }
465 }
466
467 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700468 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
469 * request after sending. The main thread will notify the request when it is complete.
470 */
471 private static final class MainThreadRequest {
472 /** The argument to use for the request */
473 public Object argument;
474 /** The result of the request that is run on the main thread */
475 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800476 // The subscriber id that this request applies to. Defaults to
477 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
478 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700479
Nathan Harold92bed182018-10-12 18:16:49 -0700480 // In cases where subId is unavailable, the caller needs to specify the phone.
481 public Phone phone;
482
vagdeviaf9a5b92018-08-15 16:01:53 -0700483 public WorkSource workSource;
484
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700485 public MainThreadRequest(Object argument) {
486 this.argument = argument;
487 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800488
Nathan Harold92bed182018-10-12 18:16:49 -0700489 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
490 this.argument = argument;
491 if (phone != null) {
492 this.phone = phone;
493 }
494 this.workSource = workSource;
495 }
496
vagdeviaf9a5b92018-08-15 16:01:53 -0700497 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800498 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800499 if (subId != null) {
500 this.subId = subId;
501 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700502 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800503 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700504 }
505
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800506 private static final class IncomingThirdPartyCallArgs {
507 public final ComponentName component;
508 public final String callId;
509 public final String callerDisplayName;
510
511 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
512 String callerDisplayName) {
513 this.component = component;
514 this.callId = callId;
515 this.callerDisplayName = callerDisplayName;
516 }
517 }
518
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700519 /**
520 * A handler that processes messages on the main thread in the phone process. Since many
521 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
522 * inbound binder threads to the main thread in the phone process. The Binder thread
523 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
524 * on, which will be notified when the operation completes and will contain the result of the
525 * request.
526 *
527 * <p>If a MainThreadRequest object is provided in the msg.obj field,
528 * note that request.result must be set to something non-null for the calling thread to
529 * unblock.
530 */
531 private final class MainThreadHandler extends Handler {
532 @Override
533 public void handleMessage(Message msg) {
534 MainThreadRequest request;
535 Message onCompleted;
536 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000537 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700538 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800539 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700540
541 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700542 case CMD_HANDLE_USSD_REQUEST: {
543 request = (MainThreadRequest) msg.obj;
544 final Phone phone = getPhoneFromRequest(request);
545 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
546 String ussdRequest = ussdObject.first;
547 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700548
Pengquan Menga1bb6272018-09-06 09:59:22 -0700549 if (!isUssdApiAllowed(request.subId)) {
550 // Carrier does not support use of this API, return failure.
551 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
552 UssdResponse response = new UssdResponse(ussdRequest, null);
553 Bundle returnData = new Bundle();
554 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
555 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700556
Pengquan Menga1bb6272018-09-06 09:59:22 -0700557 request.result = true;
558 notifyRequester(request);
559 return;
560 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700561
Pengquan Menga1bb6272018-09-06 09:59:22 -0700562 try {
563 request.result = phone != null
564 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
565 } catch (CallStateException cse) {
566 request.result = false;
567 }
568 // Wake up the requesting thread
569 notifyRequester(request);
570 break;
pkanwar32d516d2016-10-14 19:37:38 -0700571 }
572
Yorke Lee716f67e2015-06-17 15:39:16 -0700573 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700574 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700575 final Phone phone = getPhoneFromRequest(request);
576 request.result = phone != null ?
577 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
578 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700579 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700580 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700581 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700582 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700583
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700584 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700585 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700586 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000587 uiccPort = getUiccPortFromRequest(request);
588 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700589 loge("iccTransmitApduLogicalChannel: No UICC");
590 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700591 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700592 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700593 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
594 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000595 uiccPort.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700596 iccArgument.channel, iccArgument.cla, iccArgument.command,
597 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700598 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700599 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700600 break;
601
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700602 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700603 ar = (AsyncResult) msg.obj;
604 request = (MainThreadRequest) ar.userObj;
605 if (ar.exception == null && ar.result != null) {
606 request.result = ar.result;
607 } else {
608 request.result = new IccIoResult(0x6F, 0, (byte[])null);
609 if (ar.result == null) {
610 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800611 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700612 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800613 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700614 } else {
615 loge("iccTransmitApduLogicalChannel: Unknown exception");
616 }
617 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700618 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700619 break;
620
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700621 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
622 request = (MainThreadRequest) msg.obj;
623 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000624 uiccPort = getUiccPortFromRequest(request);
625 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700626 loge("iccTransmitApduBasicChannel: No UICC");
627 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700628 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700629 } else {
630 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
631 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000632 uiccPort.iccTransmitApduBasicChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700633 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
634 iccArgument.p3, iccArgument.data, onCompleted);
635 }
636 break;
637
638 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
639 ar = (AsyncResult) msg.obj;
640 request = (MainThreadRequest) ar.userObj;
641 if (ar.exception == null && ar.result != null) {
642 request.result = ar.result;
643 } else {
644 request.result = new IccIoResult(0x6F, 0, (byte[])null);
645 if (ar.result == null) {
646 loge("iccTransmitApduBasicChannel: Empty response");
647 } else if (ar.exception instanceof CommandException) {
648 loge("iccTransmitApduBasicChannel: CommandException: " +
649 ar.exception);
650 } else {
651 loge("iccTransmitApduBasicChannel: Unknown exception");
652 }
653 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700654 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700655 break;
656
657 case CMD_EXCHANGE_SIM_IO:
658 request = (MainThreadRequest) msg.obj;
659 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000660 uiccPort = getUiccPortFromRequest(request);
661 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700662 loge("iccExchangeSimIO: No UICC");
663 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700664 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700665 } else {
666 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
667 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000668 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700669 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
670 iccArgument.data, onCompleted);
671 }
672 break;
673
674 case EVENT_EXCHANGE_SIM_IO_DONE:
675 ar = (AsyncResult) msg.obj;
676 request = (MainThreadRequest) ar.userObj;
677 if (ar.exception == null && ar.result != null) {
678 request.result = ar.result;
679 } else {
680 request.result = new IccIoResult(0x6f, 0, (byte[])null);
681 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700682 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700683 break;
684
Derek Tan4d5e5c12014-02-04 11:54:58 -0800685 case CMD_SEND_ENVELOPE:
686 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000687 uiccPort = getUiccPortFromRequest(request);
688 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700689 loge("sendEnvelopeWithStatus: No UICC");
690 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700691 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700692 } else {
693 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000694 uiccPort.sendEnvelopeWithStatus((String)request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700695 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800696 break;
697
698 case EVENT_SEND_ENVELOPE_DONE:
699 ar = (AsyncResult) msg.obj;
700 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700701 if (ar.exception == null && ar.result != null) {
702 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800703 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700704 request.result = new IccIoResult(0x6F, 0, (byte[])null);
705 if (ar.result == null) {
706 loge("sendEnvelopeWithStatus: Empty response");
707 } else if (ar.exception instanceof CommandException) {
708 loge("sendEnvelopeWithStatus: CommandException: " +
709 ar.exception);
710 } else {
711 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
712 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800713 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700714 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800715 break;
716
Shishir Agrawal566b7612013-10-28 14:41:00 -0700717 case CMD_OPEN_CHANNEL:
718 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000719 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800720 IccLogicalChannelRequest openChannelRequest =
721 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000722 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700723 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800724 request.result = new IccOpenLogicalChannelResponse(-1,
725 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700726 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700727 } else {
728 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800729 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
730 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700731 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700732 break;
733
734 case EVENT_OPEN_CHANNEL_DONE:
735 ar = (AsyncResult) msg.obj;
736 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700737 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700738 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700739 int[] result = (int[]) ar.result;
740 int channelId = result[0];
741 byte[] selectResponse = null;
742 if (result.length > 1) {
743 selectResponse = new byte[result.length - 1];
744 for (int i = 1; i < result.length; ++i) {
745 selectResponse[i - 1] = (byte) result[i];
746 }
747 }
748 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700749 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700750 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700751 if (ar.result == null) {
752 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700753 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700754 if (ar.exception != null) {
755 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
756 }
757
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700758 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700759 if (ar.exception instanceof CommandException) {
760 CommandException.Error error =
761 ((CommandException) (ar.exception)).getCommandError();
762 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700763 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700764 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700765 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700766 }
767 }
768 openChannelResp = new IccOpenLogicalChannelResponse(
769 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700770 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700771 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700772 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700773 break;
774
775 case CMD_CLOSE_CHANNEL:
776 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000777 uiccPort = getUiccPortFromRequest(request);
778 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700779 loge("iccCloseLogicalChannel: No UICC");
Chen Xu540470b2021-12-14 17:15:47 -0800780 throw new IllegalArgumentException("iccCloseLogicalChannel: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700781 } else {
782 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000783 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700784 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700785 break;
786
787 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800788 ar = (AsyncResult) msg.obj;
789 request = (MainThreadRequest) ar.userObj;
790 if (ar.exception == null) {
791 request.result = true;
792 } else {
793 request.result = false;
794 if (ar.exception instanceof CommandException) {
795 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
796 CommandException.Error error =
797 ((CommandException) (ar.exception)).getCommandError();
798 // before this feature is enabled, this API should only return false if
799 // the operation fails instead of throwing runtime exception for
800 // backward-compatibility.
801 if (Compatibility.isChangeEnabled(
802 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE)
803 && error == CommandException.Error.INVALID_ARGUMENTS) {
804 throw new IllegalArgumentException(
805 "iccCloseLogicalChannel: invalid argument ");
806 }
807 } else {
808 loge("iccCloseLogicalChannel: Unknown exception");
809 }
810 if (Compatibility.isChangeEnabled(ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE)) {
811 throw new IllegalStateException(
812 "exception from modem to close iccLogical Channel");
813 }
814 }
815 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800816 break;
817
818 case CMD_NV_READ_ITEM:
819 request = (MainThreadRequest) msg.obj;
820 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800821 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
822 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800823 break;
824
825 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700826 ar = (AsyncResult) msg.obj;
827 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800828 if (ar.exception == null && ar.result != null) {
829 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700830 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800831 request.result = "";
832 if (ar.result == null) {
833 loge("nvReadItem: Empty response");
834 } else if (ar.exception instanceof CommandException) {
835 loge("nvReadItem: CommandException: " +
836 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700837 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800838 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700839 }
840 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700841 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700842 break;
843
Jake Hambye994d462014-02-03 13:10:13 -0800844 case CMD_NV_WRITE_ITEM:
845 request = (MainThreadRequest) msg.obj;
846 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
847 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800848 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700849 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800850 break;
851
852 case EVENT_NV_WRITE_ITEM_DONE:
853 handleNullReturnEvent(msg, "nvWriteItem");
854 break;
855
856 case CMD_NV_WRITE_CDMA_PRL:
857 request = (MainThreadRequest) msg.obj;
858 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800859 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800860 break;
861
862 case EVENT_NV_WRITE_CDMA_PRL_DONE:
863 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
864 break;
865
chen xu6dac5ab2018-10-26 17:39:23 -0700866 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800867 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700868 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800869 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800870 break;
871
chen xu6dac5ab2018-10-26 17:39:23 -0700872 case EVENT_RESET_MODEM_CONFIG_DONE:
873 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800874 break;
875
Sooraj Sasindran37444802020-08-11 10:40:43 -0700876 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
877 request = (MainThreadRequest) msg.obj;
878 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
879 request);
880 Phone phone = getPhoneFromRequest(request);
881 if (phone != null) {
882 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
883 } else {
884 loge("isNRDualConnectivityEnabled: No phone object");
885 request.result = false;
886 notifyRequester(request);
887 }
888 break;
889 }
890
891 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
892 ar = (AsyncResult) msg.obj;
893 request = (MainThreadRequest) ar.userObj;
894 if (ar.exception == null && ar.result != null) {
895 request.result = ar.result;
896 } else {
897 // request.result must be set to something non-null
898 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700899 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700900 request.result = ar.result;
901 } else {
902 request.result = false;
903 }
904 if (ar.result == null) {
905 loge("isNRDualConnectivityEnabled: Empty response");
906 } else if (ar.exception instanceof CommandException) {
907 loge("isNRDualConnectivityEnabled: CommandException: "
908 + ar.exception);
909 } else {
910 loge("isNRDualConnectivityEnabled: Unknown exception");
911 }
912 }
913 notifyRequester(request);
914 break;
915
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700916 case CMD_IS_VONR_ENABLED: {
917 request = (MainThreadRequest) msg.obj;
918 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
919 request);
920 Phone phone = getPhoneFromRequest(request);
921 if (phone != null) {
922 phone.isVoNrEnabled(onCompleted, request.workSource);
923 } else {
924 loge("isVoNrEnabled: No phone object");
925 request.result = false;
926 notifyRequester(request);
927 }
928 break;
929 }
930
931 case EVENT_IS_VONR_ENABLED_DONE:
932 ar = (AsyncResult) msg.obj;
933 request = (MainThreadRequest) ar.userObj;
934 if (ar.exception == null && ar.result != null) {
935 request.result = ar.result;
936 } else {
937 // request.result must be set to something non-null
938 // for the calling thread to unblock
939 if (ar.result != null) {
940 request.result = ar.result;
941 } else {
942 request.result = false;
943 }
944 if (ar.result == null) {
945 loge("isVoNrEnabled: Empty response");
946 } else if (ar.exception instanceof CommandException) {
947 loge("isVoNrEnabled: CommandException: "
948 + ar.exception);
949 } else {
950 loge("isVoNrEnabled: Unknown exception");
951 }
952 }
953 notifyRequester(request);
954 break;
955
Sooraj Sasindran37444802020-08-11 10:40:43 -0700956 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
957 request = (MainThreadRequest) msg.obj;
958 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
959 Phone phone = getPhoneFromRequest(request);
960 if (phone != null) {
961 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
962 request.workSource);
963 } else {
964 loge("enableNrDualConnectivity: No phone object");
965 request.result =
966 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
967 notifyRequester(request);
968 }
969 break;
970 }
971
972 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
973 ar = (AsyncResult) msg.obj;
974 request = (MainThreadRequest) ar.userObj;
975 if (ar.exception == null) {
976 request.result =
977 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
978 } else {
979 request.result =
980 TelephonyManager
981 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
982 if (ar.exception instanceof CommandException) {
983 CommandException.Error error =
984 ((CommandException) (ar.exception)).getCommandError();
985 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
986 request.result =
987 TelephonyManager
988 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000989 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
990 request.result =
991 TelephonyManager
992 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700993 }
994 loge("enableNrDualConnectivity" + ": CommandException: "
995 + ar.exception);
996 } else {
997 loge("enableNrDualConnectivity" + ": Unknown exception");
998 }
999 }
1000 notifyRequester(request);
1001 break;
1002 }
1003
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001004 case CMD_ENABLE_VONR: {
1005 request = (MainThreadRequest) msg.obj;
1006 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1007 Phone phone = getPhoneFromRequest(request);
1008 if (phone != null) {
1009 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1010 request.workSource);
1011 } else {
1012 loge("setVoNrEnabled: No phone object");
1013 request.result =
1014 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1015 notifyRequester(request);
1016 }
1017 break;
1018 }
1019
1020 case EVENT_ENABLE_VONR_DONE: {
1021 ar = (AsyncResult) msg.obj;
1022 request = (MainThreadRequest) ar.userObj;
1023 if (ar.exception == null) {
1024 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1025 } else {
1026 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1027 if (ar.exception instanceof CommandException) {
1028 CommandException.Error error =
1029 ((CommandException) (ar.exception)).getCommandError();
1030 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1031 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1032 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1033 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1034 } else {
1035 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1036 }
1037 loge("setVoNrEnabled" + ": CommandException: "
1038 + ar.exception);
1039 } else {
1040 loge("setVoNrEnabled" + ": Unknown exception");
1041 }
1042 }
1043 notifyRequester(request);
1044 break;
1045 }
1046
SongFerngWang3ef3e072020-12-21 16:41:52 +08001047 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001048 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001049 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1050 request);
1051 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001052 break;
1053
SongFerngWang3ef3e072020-12-21 16:41:52 +08001054 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001055 ar = (AsyncResult) msg.obj;
1056 request = (MainThreadRequest) ar.userObj;
1057 if (ar.exception == null && ar.result != null) {
1058 request.result = ar.result; // Integer
1059 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301060 // request.result must be set to something non-null
1061 // for the calling thread to unblock
1062 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001063 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001064 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001065 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001066 loge("getAllowedNetworkTypesBitmask: CommandException: "
1067 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001068 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001069 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001070 }
1071 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001072 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001073 break;
1074
SongFerngWang3ef3e072020-12-21 16:41:52 +08001075 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001076 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001077 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1078 request);
1079 Pair<Integer, Long> reasonWithNetworkTypes =
1080 (Pair<Integer, Long>) request.argument;
1081 getPhoneFromRequest(request).setAllowedNetworkTypes(
1082 reasonWithNetworkTypes.first,
1083 reasonWithNetworkTypes.second,
1084 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001085 break;
1086
SongFerngWang3ef3e072020-12-21 16:41:52 +08001087 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1088 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001089 break;
1090
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001091 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1092 request = (MainThreadRequest)msg.obj;
1093 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001094 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001095 break;
1096
1097 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1098 ar = (AsyncResult)msg.obj;
1099 request = (MainThreadRequest)ar.userObj;
1100 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001101 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001102 break;
1103
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001104 case CMD_SET_VOICEMAIL_NUMBER:
1105 request = (MainThreadRequest) msg.obj;
1106 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1107 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001108 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1109 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001110 break;
1111
1112 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1113 handleNullReturnEvent(msg, "setVoicemailNumber");
1114 break;
1115
Stuart Scott54788802015-03-30 13:18:01 -07001116 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1117 request = (MainThreadRequest) msg.obj;
1118 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1119 request);
1120 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1121 break;
1122
1123 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1124 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1125 break;
1126
Shishir Agrawal302c8692015-06-19 13:49:39 -07001127 case CMD_PERFORM_NETWORK_SCAN:
1128 request = (MainThreadRequest) msg.obj;
1129 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1130 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1131 break;
1132
Hall Liu27d24262020-09-18 19:04:59 -07001133 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001134 request = (MainThreadRequest) msg.obj;
1135 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001136 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1137 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1138 request.argument;
1139 int callForwardingReason = args.first;
1140 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001141 break;
Hall Liu27d24262020-09-18 19:04:59 -07001142 }
1143 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001144 ar = (AsyncResult) msg.obj;
1145 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001146 TelephonyManager.CallForwardingInfoCallback callback =
1147 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1148 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001149 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001150 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001151 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1152 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1153 // Service Class is a bit mask per 3gpp 27.007. Search for
1154 // any service for voice call.
1155 if ((callForwardInfo.serviceClass
1156 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001157 callForwardingInfo = new CallForwardingInfo(
1158 callForwardInfo.status
1159 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001160 callForwardInfo.reason,
1161 callForwardInfo.number,
1162 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001163 break;
1164 }
1165 }
1166 // Didn't find a call forward info for voice call.
1167 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001168 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1169 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001170 }
Hall Liu27d24262020-09-18 19:04:59 -07001171 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001172 } else {
1173 if (ar.result == null) {
1174 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1175 }
1176 if (ar.exception != null) {
1177 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1178 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001179 int errorCode = TelephonyManager
1180 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001181 if (ar.exception instanceof CommandException) {
1182 CommandException.Error error =
1183 ((CommandException) (ar.exception)).getCommandError();
1184 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001185 errorCode = TelephonyManager
1186 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001187 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001188 errorCode = TelephonyManager
1189 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001190 }
1191 }
Hall Liu27d24262020-09-18 19:04:59 -07001192 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001193 }
Shuo Qian4a594052020-01-23 11:59:30 -08001194 break;
Hall Liu27d24262020-09-18 19:04:59 -07001195 }
Shuo Qian4a594052020-01-23 11:59:30 -08001196
Hall Liu27d24262020-09-18 19:04:59 -07001197 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001198 request = (MainThreadRequest) msg.obj;
1199 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001200 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001201 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001202 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1203 request.argument).first;
1204 request.phone.setCallForwardingOption(
1205 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001206 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001207 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001208 callForwardingInfoToSet.getReason(),
1209 callForwardingInfoToSet.getNumber(),
1210 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1211 break;
Hall Liu27d24262020-09-18 19:04:59 -07001212 }
Shuo Qian4a594052020-01-23 11:59:30 -08001213
Hall Liu27d24262020-09-18 19:04:59 -07001214 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001215 ar = (AsyncResult) msg.obj;
1216 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001217 Consumer<Integer> callback =
1218 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1219 request.argument).second;
1220 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001221 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001222 int errorCode = TelephonyManager.CallForwardingInfoCallback
1223 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001224 if (ar.exception instanceof CommandException) {
1225 CommandException.Error error =
1226 ((CommandException) (ar.exception)).getCommandError();
1227 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001228 errorCode = TelephonyManager.CallForwardingInfoCallback
1229 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001230 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001231 errorCode = TelephonyManager.CallForwardingInfoCallback
1232 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001233 }
1234 }
1235 callback.accept(errorCode);
1236 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001237 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001238 }
Shuo Qian4a594052020-01-23 11:59:30 -08001239 break;
Hall Liu27d24262020-09-18 19:04:59 -07001240 }
Shuo Qian4a594052020-01-23 11:59:30 -08001241
Hall Liu27d24262020-09-18 19:04:59 -07001242 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001243 request = (MainThreadRequest) msg.obj;
1244 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1245 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1246 break;
Hall Liu27d24262020-09-18 19:04:59 -07001247 }
Shuo Qian4a594052020-01-23 11:59:30 -08001248
Hall Liu27d24262020-09-18 19:04:59 -07001249 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001250 ar = (AsyncResult) msg.obj;
1251 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001252 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001253 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1254 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001255 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001256 // Service Class is a bit mask per 3gpp 27.007.
1257 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001258 if (callForwardResults.length > 1
1259 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001260 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001261 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001262 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1263 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001264 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001265 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001266 }
1267 } else {
1268 if (ar.result == null) {
1269 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1270 }
1271 if (ar.exception != null) {
1272 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1273 }
1274 if (ar.exception instanceof CommandException) {
1275 CommandException.Error error =
1276 ((CommandException) (ar.exception)).getCommandError();
1277 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1278 callForwardingStatus =
1279 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1280 }
1281 }
1282 }
Hall Liu27d24262020-09-18 19:04:59 -07001283 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001284 break;
Hall Liu27d24262020-09-18 19:04:59 -07001285 }
Shuo Qian4a594052020-01-23 11:59:30 -08001286
Hall Liu27d24262020-09-18 19:04:59 -07001287 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001288 request = (MainThreadRequest) msg.obj;
1289 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001290 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1291 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001292 break;
Hall Liu27d24262020-09-18 19:04:59 -07001293 }
Shuo Qian4a594052020-01-23 11:59:30 -08001294
Hall Liu27d24262020-09-18 19:04:59 -07001295 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001296 ar = (AsyncResult) msg.obj;
1297 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001298 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1299 Consumer<Integer> callback =
1300 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1301 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001302 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001303 if (ar.exception instanceof CommandException) {
1304 CommandException.Error error =
1305 ((CommandException) (ar.exception)).getCommandError();
1306 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1307 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1308 } else {
1309 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1310 }
1311 } else {
1312 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1313 }
1314 } else {
1315 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1316 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001317 }
Shuo Qian4a594052020-01-23 11:59:30 -08001318 break;
Hall Liu27d24262020-09-18 19:04:59 -07001319 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001320 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1321 ar = (AsyncResult) msg.obj;
1322 request = (MainThreadRequest) ar.userObj;
1323 CellNetworkScanResult cellScanResult;
1324 if (ar.exception == null && ar.result != null) {
1325 cellScanResult = new CellNetworkScanResult(
1326 CellNetworkScanResult.STATUS_SUCCESS,
1327 (List<OperatorInfo>) ar.result);
1328 } else {
1329 if (ar.result == null) {
1330 loge("getCellNetworkScanResults: Empty response");
1331 }
1332 if (ar.exception != null) {
1333 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1334 }
1335 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1336 if (ar.exception instanceof CommandException) {
1337 CommandException.Error error =
1338 ((CommandException) (ar.exception)).getCommandError();
1339 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1340 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1341 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1342 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1343 }
1344 }
1345 cellScanResult = new CellNetworkScanResult(errorCode, null);
1346 }
1347 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001348 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001349 break;
1350
1351 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1352 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001353 ManualNetworkSelectionArgument selArg =
1354 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001355 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1356 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001357 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1358 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001359 break;
1360
1361 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001362 ar = (AsyncResult) msg.obj;
1363 request = (MainThreadRequest) ar.userObj;
1364 if (ar.exception == null) {
1365 request.result = true;
1366 } else {
1367 request.result = false;
1368 loge("setNetworkSelectionModeManual " + ar.exception);
1369 }
1370 notifyRequester(request);
1371 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001372 break;
1373
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001374 case CMD_GET_MODEM_ACTIVITY_INFO:
1375 request = (MainThreadRequest) msg.obj;
1376 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001377 if (defaultPhone != null) {
1378 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001379 } else {
1380 ResultReceiver result = (ResultReceiver) request.argument;
1381 Bundle bundle = new Bundle();
1382 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001383 new ModemActivityInfo(0, 0, 0,
1384 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001385 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001386 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001387 break;
1388
Hall Liud0f208c2020-10-14 16:54:44 -07001389 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001390 ar = (AsyncResult) msg.obj;
1391 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001392 ResultReceiver result = (ResultReceiver) request.argument;
1393
Hall Liud0f208c2020-10-14 16:54:44 -07001394 ModemActivityInfo ret = null;
1395 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001396 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001397 // Update the last modem activity info and the result of the request.
1398 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1399 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001400 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001401 int[] txTimeMs = info.getTransmitTimeMillis();
1402 int[] lastModemTxTimeMs = mLastModemActivityInfo
1403 .getTransmitTimeMillis();
1404 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1405 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1406 }
Hall Liu49656c02020-10-09 19:00:11 -07001407 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001408 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1409 + mLastModemActivityInfo.getSleepTimeMillis());
1410 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1411 + mLastModemActivityInfo.getIdleTimeMillis());
1412 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1413 mLastModemActivityInfo.setReceiveTimeMillis(
1414 info.getReceiveTimeMillis()
1415 + mLastModemActivityInfo.getReceiveTimeMillis());
1416 }
Hall Liu49656c02020-10-09 19:00:11 -07001417 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001418 mLastModemActivityInfo.getSleepTimeMillis(),
1419 mLastModemActivityInfo.getIdleTimeMillis(),
1420 mLastModemActivityInfo.getTransmitTimeMillis(),
1421 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001422 } else {
1423 if (ar.result == null) {
1424 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001425 error = TelephonyManager.ModemActivityInfoException
1426 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001427 } else if (ar.exception instanceof CommandException) {
1428 loge("queryModemActivityInfo: CommandException: " +
1429 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001430 error = TelephonyManager.ModemActivityInfoException
1431 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001432 } else {
1433 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001434 error = TelephonyManager.ModemActivityInfoException
1435 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001436 }
1437 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001438 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001439 if (ret != null) {
1440 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1441 } else {
1442 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1443 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001444 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001445 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001446 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001447 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001448
Meng Wang1a7c35a2016-05-05 20:56:15 -07001449 case CMD_SET_ALLOWED_CARRIERS:
1450 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001451 CarrierRestrictionRules argument =
1452 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001453 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001454 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001455 break;
1456
1457 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1458 ar = (AsyncResult) msg.obj;
1459 request = (MainThreadRequest) ar.userObj;
1460 if (ar.exception == null && ar.result != null) {
1461 request.result = ar.result;
1462 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001463 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1464 if (ar.exception instanceof CommandException) {
1465 loge("setAllowedCarriers: CommandException: " + ar.exception);
1466 CommandException.Error error =
1467 ((CommandException) (ar.exception)).getCommandError();
1468 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1469 request.result =
1470 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1471 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001472 } else {
1473 loge("setAllowedCarriers: Unknown exception");
1474 }
1475 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001476 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001477 break;
1478
1479 case CMD_GET_ALLOWED_CARRIERS:
1480 request = (MainThreadRequest) msg.obj;
1481 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001482 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001483 break;
1484
1485 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1486 ar = (AsyncResult) msg.obj;
1487 request = (MainThreadRequest) ar.userObj;
1488 if (ar.exception == null && ar.result != null) {
1489 request.result = ar.result;
1490 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001491 request.result = new IllegalStateException(
1492 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001493 if (ar.result == null) {
1494 loge("getAllowedCarriers: Empty response");
1495 } else if (ar.exception instanceof CommandException) {
1496 loge("getAllowedCarriers: CommandException: " +
1497 ar.exception);
1498 } else {
1499 loge("getAllowedCarriers: Unknown exception");
1500 }
1501 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001502 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001503 break;
1504
Nathan Haroldb3014052017-01-25 15:57:32 -08001505 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1506 ar = (AsyncResult) msg.obj;
1507 request = (MainThreadRequest) ar.userObj;
1508 if (ar.exception == null && ar.result != null) {
1509 request.result = ar.result;
1510 } else {
1511 request.result = new IllegalArgumentException(
1512 "Failed to retrieve Forbidden Plmns");
1513 if (ar.result == null) {
1514 loge("getForbiddenPlmns: Empty response");
1515 } else {
1516 loge("getForbiddenPlmns: Unknown exception");
1517 }
1518 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001519 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001520 break;
1521
1522 case CMD_GET_FORBIDDEN_PLMNS:
1523 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001524 uiccPort = getUiccPortFromRequest(request);
1525 if (uiccPort == null) {
1526 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001527 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001528 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001529 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001530 break;
1531 }
1532 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001533 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001534 if (uiccApp == null) {
1535 loge("getForbiddenPlmns() no app with specified type -- "
1536 + appType);
1537 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001538 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001539 break;
1540 } else {
1541 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1542 + " specified type -- " + appType);
1543 }
1544 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1545 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1546 onCompleted);
1547 break;
1548
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001549 case CMD_SWITCH_SLOTS:
1550 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001551 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001552 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001553 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001554 break;
1555
1556 case EVENT_SWITCH_SLOTS_DONE:
1557 ar = (AsyncResult) msg.obj;
1558 request = (MainThreadRequest) ar.userObj;
1559 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001560 notifyRequester(request);
1561 break;
1562 case CMD_GET_NETWORK_SELECTION_MODE:
1563 request = (MainThreadRequest) msg.obj;
1564 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1565 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1566 break;
1567
1568 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1569 ar = (AsyncResult) msg.obj;
1570 request = (MainThreadRequest) ar.userObj;
1571 if (ar.exception != null) {
1572 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1573 } else {
1574 int mode = ((int[]) ar.result)[0];
1575 if (mode == 0) {
1576 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1577 } else {
1578 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1579 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001580 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001581 notifyRequester(request);
1582 break;
1583 case CMD_GET_CDMA_ROAMING_MODE:
1584 request = (MainThreadRequest) msg.obj;
1585 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1586 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1587 break;
1588 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1589 ar = (AsyncResult) msg.obj;
1590 request = (MainThreadRequest) ar.userObj;
1591 if (ar.exception != null) {
1592 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1593 } else {
1594 request.result = ((int[]) ar.result)[0];
1595 }
1596 notifyRequester(request);
1597 break;
1598 case CMD_SET_CDMA_ROAMING_MODE:
1599 request = (MainThreadRequest) msg.obj;
1600 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1601 int mode = (int) request.argument;
1602 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1603 break;
1604 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1605 ar = (AsyncResult) msg.obj;
1606 request = (MainThreadRequest) ar.userObj;
1607 request.result = ar.exception == null;
1608 notifyRequester(request);
1609 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001610 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1611 request = (MainThreadRequest) msg.obj;
1612 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1613 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1614 break;
1615 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1616 ar = (AsyncResult) msg.obj;
1617 request = (MainThreadRequest) ar.userObj;
1618 if (ar.exception != null) {
1619 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1620 } else {
1621 request.result = ((int[]) ar.result)[0];
1622 }
1623 notifyRequester(request);
1624 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001625 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1626 request = (MainThreadRequest) msg.obj;
1627 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1628 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001629 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1630 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001631 break;
1632 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1633 ar = (AsyncResult) msg.obj;
1634 request = (MainThreadRequest) ar.userObj;
1635 request.result = ar.exception == null;
1636 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001637 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001638 case CMD_GET_ALL_CELL_INFO:
1639 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001640 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001641 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001642 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001643 case EVENT_GET_ALL_CELL_INFO_DONE:
1644 ar = (AsyncResult) msg.obj;
1645 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001646 // If a timeout occurs, the response will be null
1647 request.result = (ar.exception == null && ar.result != null)
1648 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001649 synchronized (request) {
1650 request.notifyAll();
1651 }
1652 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001653 case CMD_REQUEST_CELL_INFO_UPDATE:
1654 request = (MainThreadRequest) msg.obj;
1655 request.phone.requestCellInfoUpdate(request.workSource,
1656 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1657 break;
1658 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1659 ar = (AsyncResult) msg.obj;
1660 request = (MainThreadRequest) ar.userObj;
1661 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1662 try {
1663 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001664 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001665 cb.onError(
1666 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1667 ar.exception.getClass().getName(),
1668 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001669 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001670 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001671 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001672 } else {
1673 // use the result as returned
1674 cb.onCellInfo((List<CellInfo>) ar.result);
1675 }
1676 } catch (RemoteException re) {
1677 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1678 }
1679 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001680 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001681 request = (MainThreadRequest) msg.obj;
1682 WorkSource ws = (WorkSource) request.argument;
1683 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001684 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001685 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001686 }
1687 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001688 ar = (AsyncResult) msg.obj;
1689 request = (MainThreadRequest) ar.userObj;
1690 if (ar.exception == null) {
1691 request.result = ar.result;
1692 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001693 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001694 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001695 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001696 }
1697
1698 synchronized (request) {
1699 request.notifyAll();
1700 }
1701 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001702 }
chen xu6dac5ab2018-10-26 17:39:23 -07001703 case CMD_MODEM_REBOOT:
1704 request = (MainThreadRequest) msg.obj;
1705 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001706 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001707 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001708 case EVENT_CMD_MODEM_REBOOT_DONE:
1709 handleNullReturnEvent(msg, "rebootModem");
1710 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001711 case CMD_REQUEST_ENABLE_MODEM:
1712 request = (MainThreadRequest) msg.obj;
1713 boolean enable = (boolean) request.argument;
1714 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001715 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001716 PhoneConfigurationManager.getInstance()
1717 .enablePhone(request.phone, enable, onCompleted);
1718 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001719 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001720 ar = (AsyncResult) msg.obj;
1721 request = (MainThreadRequest) ar.userObj;
1722 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001723 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001724 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001725 if ((boolean) request.result) {
1726 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1727 updateModemStateMetrics();
1728 } else {
1729 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1730 + ar.exception);
1731 }
1732 notifyRequester(request);
1733 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001734 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001735 case CMD_GET_MODEM_STATUS:
1736 request = (MainThreadRequest) msg.obj;
1737 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1738 PhoneConfigurationManager.getInstance()
1739 .getPhoneStatusFromModem(request.phone, onCompleted);
1740 break;
1741 case EVENT_GET_MODEM_STATUS_DONE:
1742 ar = (AsyncResult) msg.obj;
1743 request = (MainThreadRequest) ar.userObj;
1744 int id = request.phone.getPhoneId();
1745 if (ar.exception == null && ar.result != null) {
1746 request.result = ar.result;
1747 //update the cache as modem status has changed
1748 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1749 (boolean) request.result);
1750 } else {
1751 // Return true if modem status cannot be retrieved. For most cases,
1752 // modem status is on. And for older version modems, GET_MODEM_STATUS
1753 // and disable modem are not supported. Modem is always on.
1754 // TODO: this should be fixed in R to support a third
1755 // status UNKNOWN b/131631629
1756 request.result = true;
1757 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1758 + ar.exception);
1759 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001760 notifyRequester(request);
1761 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001762 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1763 request = (MainThreadRequest) msg.obj;
1764 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1765 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1766 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1767 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1768 break;
1769 }
1770 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1771 ar = (AsyncResult) msg.obj;
1772 request = (MainThreadRequest) ar.userObj;
1773 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1774 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1775 args.second.accept(ar.exception == null);
1776 notifyRequester(request);
1777 break;
1778 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001779 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1780 request = (MainThreadRequest) msg.obj;
1781 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1782 Phone phone = getPhoneFromRequest(request);
1783 if (phone != null) {
1784 phone.getSystemSelectionChannels(onCompleted);
1785 } else {
1786 loge("getSystemSelectionChannels: No phone object");
1787 request.result = new ArrayList<RadioAccessSpecifier>();
1788 notifyRequester(request);
1789 }
1790 break;
1791 }
1792 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1793 ar = (AsyncResult) msg.obj;
1794 request = (MainThreadRequest) ar.userObj;
1795 if (ar.exception == null && ar.result != null) {
1796 request.result = ar.result;
1797 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001798 request.result = new IllegalStateException(
1799 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001800 if (ar.result == null) {
1801 loge("getSystemSelectionChannels: Empty response");
1802 } else {
1803 loge("getSystemSelectionChannels: Unknown exception");
1804 }
1805 }
1806 notifyRequester(request);
1807 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001808 case EVENT_SET_FORBIDDEN_PLMNS_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 {
1814 request.result = -1;
1815 loge("Failed to set Forbidden Plmns");
1816 if (ar.result == null) {
1817 loge("setForbidenPlmns: Empty response");
1818 } else if (ar.exception != null) {
1819 loge("setForbiddenPlmns: Exception: " + ar.exception);
1820 request.result = -1;
1821 } else {
1822 loge("setForbiddenPlmns: Unknown exception");
1823 }
1824 }
1825 notifyRequester(request);
1826 break;
1827 case CMD_SET_FORBIDDEN_PLMNS:
1828 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001829 uiccPort = getUiccPortFromRequest(request);
1830 if (uiccPort == null) {
1831 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001832 request.result = -1;
1833 notifyRequester(request);
1834 break;
1835 }
1836 Pair<Integer, List<String>> setFplmnsArgs =
1837 (Pair<Integer, List<String>>) request.argument;
1838 appType = setFplmnsArgs.first;
1839 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001840 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001841 if (uiccApp == null) {
1842 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1843 request.result = -1;
1844 loge("Failed to get UICC App");
1845 notifyRequester(request);
1846 } else {
1847 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1848 ((SIMRecords) uiccApp.getIccRecords())
1849 .setForbiddenPlmns(onCompleted, fplmns);
1850 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001851 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001852 case CMD_ERASE_MODEM_CONFIG:
1853 request = (MainThreadRequest) msg.obj;
1854 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1855 defaultPhone.eraseModemConfig(onCompleted);
1856 break;
1857 case EVENT_ERASE_MODEM_CONFIG_DONE:
1858 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001859 break;
zoey chene02881a2019-12-30 16:11:23 +08001860
Kai Shif70f46f2021-03-03 13:59:46 -08001861 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1862 request = (MainThreadRequest) msg.obj;
1863 request.result = defaultPhone.eraseDataInSharedPreferences();
1864 notifyRequester(request);
1865 break;
1866
zoey chene02881a2019-12-30 16:11:23 +08001867 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1868 request = (MainThreadRequest) msg.obj;
1869 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1870 Pair<String, String> changed = (Pair<String, String>) request.argument;
1871 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1872 changed.first, changed.second, onCompleted);
1873 break;
1874 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1875 ar = (AsyncResult) msg.obj;
1876 request = (MainThreadRequest) ar.userObj;
1877 if (ar.exception == null) {
1878 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001879 // If the operation is successful, update the PIN storage
1880 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1881 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001882 UiccController.getInstance().getPinStorage()
1883 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001884 } else {
1885 request.result = msg.arg1;
1886 }
1887 notifyRequester(request);
1888 break;
1889
Michele Berionne5e411512020-11-13 02:36:59 +00001890 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001891 request = (MainThreadRequest) msg.obj;
1892 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1893 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1894 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1895 enabled.first, enabled.second, onCompleted);
1896 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001897 }
zoey chene02881a2019-12-30 16:11:23 +08001898 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1899 ar = (AsyncResult) msg.obj;
1900 request = (MainThreadRequest) ar.userObj;
1901 if (ar.exception == null) {
1902 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001903 // If the operation is successful, update the PIN storage
1904 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1905 int phoneId = getPhoneFromRequest(request).getPhoneId();
1906 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001907 UiccController.getInstance().getPinStorage()
1908 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001909 } else {
1910 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1911 }
zoey chene02881a2019-12-30 16:11:23 +08001912 } else {
1913 request.result = msg.arg1;
1914 }
Michele Berionne5e411512020-11-13 02:36:59 +00001915
1916
zoey chene02881a2019-12-30 16:11:23 +08001917 notifyRequester(request);
1918 break;
1919
Peter Wangdafb9ac2020-01-15 14:13:38 -08001920 case MSG_NOTIFY_USER_ACTIVITY:
1921 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001922 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001923 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1924 getDefaultPhone().getContext().sendBroadcastAsUser(
1925 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1926 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001927
1928 case CMD_SET_DATA_THROTTLING: {
1929 request = (MainThreadRequest) msg.obj;
1930 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1931 DataThrottlingRequest dataThrottlingRequest =
1932 (DataThrottlingRequest) request.argument;
1933 Phone phone = getPhoneFromRequest(request);
1934 if (phone != null) {
1935 phone.setDataThrottling(onCompleted,
1936 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1937 dataThrottlingRequest.getCompletionDurationMillis());
1938 } else {
1939 loge("setDataThrottling: No phone object");
1940 request.result =
1941 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1942 notifyRequester(request);
1943 }
1944
1945 break;
1946 }
1947 case EVENT_SET_DATA_THROTTLING_DONE:
1948 ar = (AsyncResult) msg.obj;
1949 request = (MainThreadRequest) ar.userObj;
1950
1951 if (ar.exception == null) {
1952 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1953 } else if (ar.exception instanceof CommandException) {
1954 loge("setDataThrottling: CommandException: " + ar.exception);
1955 CommandException.Error error =
1956 ((CommandException) (ar.exception)).getCommandError();
1957
1958 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1959 request.result = TelephonyManager
1960 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1961 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1962 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001963 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1964 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001965 } else {
1966 request.result =
1967 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1968 }
1969 } else {
1970 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1971 }
1972 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1973 notifyRequester(request);
1974 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001975
1976 case CMD_SET_SIM_POWER: {
1977 request = (MainThreadRequest) msg.obj;
1978 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1979 request = (MainThreadRequest) msg.obj;
1980 int stateToSet =
1981 ((Pair<Integer, IIntegerConsumer>)
1982 request.argument).first;
1983 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1984 break;
1985 }
1986 case EVENT_SET_SIM_POWER_DONE: {
1987 ar = (AsyncResult) msg.obj;
1988 request = (MainThreadRequest) ar.userObj;
1989 IIntegerConsumer callback =
1990 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1991 if (ar.exception != null) {
1992 loge("setSimPower exception: " + ar.exception);
1993 int errorCode = TelephonyManager.CallForwardingInfoCallback
1994 .RESULT_ERROR_UNKNOWN;
1995 if (ar.exception instanceof CommandException) {
1996 CommandException.Error error =
1997 ((CommandException) (ar.exception)).getCommandError();
1998 if (error == CommandException.Error.SIM_ERR) {
1999 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2000 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2001 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2002 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2003 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2004 } else {
2005 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2006 }
2007 }
2008 try {
2009 callback.accept(errorCode);
2010 } catch (RemoteException e) {
2011 // Ignore if the remote process is no longer available to call back.
2012 Log.w(LOG_TAG, "setSimPower: callback not available.");
2013 }
2014 } else {
2015 try {
2016 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2017 } catch (RemoteException e) {
2018 // Ignore if the remote process is no longer available to call back.
2019 Log.w(LOG_TAG, "setSimPower: callback not available.");
2020 }
2021 }
2022 break;
2023 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002024 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2025 request = (MainThreadRequest) msg.obj;
2026
2027 final Phone phone = getPhoneFromRequest(request);
2028 if (phone == null || phone.getServiceStateTracker() == null) {
2029 request.result = new IllegalStateException("Phone or SST is null");
2030 notifyRequester(request);
2031 break;
2032 }
2033
2034 Pair<Integer, SignalStrengthUpdateRequest> pair =
2035 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2036 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2037 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002038 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002039 request.subId, pair.first /*callingUid*/,
2040 pair.second /*request*/, onCompleted);
2041 break;
2042 }
2043 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2044 ar = (AsyncResult) msg.obj;
2045 request = (MainThreadRequest) ar.userObj;
2046 // request.result will be the exception of ar if present, true otherwise.
2047 // Be cautious not to leave result null which will wait() forever
2048 request.result = ar.exception != null ? ar.exception : true;
2049 notifyRequester(request);
2050 break;
2051 }
2052 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2053 request = (MainThreadRequest) msg.obj;
2054
2055 Phone phone = getPhoneFromRequest(request);
2056 if (phone == null || phone.getServiceStateTracker() == null) {
2057 request.result = new IllegalStateException("Phone or SST is null");
2058 notifyRequester(request);
2059 break;
2060 }
2061
2062 Pair<Integer, SignalStrengthUpdateRequest> pair =
2063 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2064 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2065 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002066 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002067 request.subId, pair.first /*callingUid*/,
2068 pair.second /*request*/, onCompleted);
2069 break;
2070 }
2071 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2072 ar = (AsyncResult) msg.obj;
2073 request = (MainThreadRequest) ar.userObj;
2074 request.result = ar.exception != null ? ar.exception : true;
2075 notifyRequester(request);
2076 break;
2077 }
Jordan Liu109698e2020-11-24 14:50:34 -08002078
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002079 case CMD_GET_SLICING_CONFIG: {
2080 request = (MainThreadRequest) msg.obj;
2081 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2082 request.phone.getSlicingConfig(onCompleted);
2083 break;
2084 }
2085 case EVENT_GET_SLICING_CONFIG_DONE: {
2086 ar = (AsyncResult) msg.obj;
2087 request = (MainThreadRequest) ar.userObj;
2088 ResultReceiver result = (ResultReceiver) request.argument;
2089
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002090 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002091 Bundle bundle = new Bundle();
2092 int resultCode = 0;
2093 if (ar.exception != null) {
2094 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2095 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002096 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002097 } else if (ar.result == null) {
2098 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002099 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002100 } else {
2101 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002102 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2103 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002104 }
2105
2106 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002107 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002108 }
2109 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2110 result.send(resultCode, bundle);
2111 notifyRequester(request);
2112 break;
2113 }
2114
Michele Berionne5e411512020-11-13 02:36:59 +00002115 case CMD_PREPARE_UNATTENDED_REBOOT:
2116 request = (MainThreadRequest) msg.obj;
2117 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002118 UiccController.getInstance().getPinStorage()
2119 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002120 notifyRequester(request);
2121 break;
2122
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002123 default:
2124 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2125 break;
2126 }
2127 }
Jake Hambye994d462014-02-03 13:10:13 -08002128
Pengquan Menga1bb6272018-09-06 09:59:22 -07002129 private void notifyRequester(MainThreadRequest request) {
2130 synchronized (request) {
2131 request.notifyAll();
2132 }
2133 }
2134
Jake Hambye994d462014-02-03 13:10:13 -08002135 private void handleNullReturnEvent(Message msg, String command) {
2136 AsyncResult ar = (AsyncResult) msg.obj;
2137 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2138 if (ar.exception == null) {
2139 request.result = true;
2140 } else {
2141 request.result = false;
2142 if (ar.exception instanceof CommandException) {
2143 loge(command + ": CommandException: " + ar.exception);
2144 } else {
2145 loge(command + ": Unknown exception");
2146 }
2147 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002148 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002149 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002150 }
2151
2152 /**
2153 * Posts the specified command to be executed on the main thread,
2154 * waits for the request to complete, and returns the result.
2155 * @see #sendRequestAsync
2156 */
2157 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002158 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2159 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002160 }
2161
2162 /**
2163 * Posts the specified command to be executed on the main thread,
2164 * waits for the request to complete, and returns the result.
2165 * @see #sendRequestAsync
2166 */
2167 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2168 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002169 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002170 }
2171
2172 /**
2173 * Posts the specified command to be executed on the main thread,
2174 * waits for the request to complete, and returns the result.
2175 * @see #sendRequestAsync
2176 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002177 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002178 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2179 }
2180
2181 /**
2182 * Posts the specified command to be executed on the main thread,
2183 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2184 * if not timeout or null otherwise.
2185 * @see #sendRequestAsync
2186 */
2187 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2188 long timeoutInMs) {
2189 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002190 }
2191
2192 /**
2193 * Posts the specified command to be executed on the main thread,
2194 * waits for the request to complete, and returns the result.
2195 * @see #sendRequestAsync
2196 */
Nathan Harold92bed182018-10-12 18:16:49 -07002197 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002198 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002199 }
2200
2201 /**
2202 * Posts the specified command to be executed on the main thread,
2203 * waits for the request to complete, and returns the result.
2204 * @see #sendRequestAsync
2205 */
2206 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002207 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2208 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002209 }
2210
2211 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002212 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2213 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2214 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002215 * @see #sendRequestAsync
2216 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002217 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2218 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002219 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2220 throw new RuntimeException("This method will deadlock if called from the main thread.");
2221 }
2222
Nathan Harold92bed182018-10-12 18:16:49 -07002223 MainThreadRequest request = null;
2224 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2225 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2226 } else if (phone != null) {
2227 request = new MainThreadRequest(argument, phone, workSource);
2228 } else {
2229 request = new MainThreadRequest(argument, subId, workSource);
2230 }
2231
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002232 Message msg = mMainThreadHandler.obtainMessage(command, request);
2233 msg.sendToTarget();
2234
Rambo Wang0f050d82021-02-12 11:43:36 -08002235
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002236 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002237 if (timeoutInMs >= 0) {
2238 // Wait for at least timeoutInMs before returning null request result
2239 long now = SystemClock.elapsedRealtime();
2240 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002241 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002242 try {
2243 request.wait(deadline - now);
2244 } catch (InterruptedException e) {
2245 // Do nothing, go back and check if request is completed or timeout
2246 } finally {
2247 now = SystemClock.elapsedRealtime();
2248 }
2249 }
2250 } else {
2251 // Wait for the request to complete
2252 while (request.result == null) {
2253 try {
2254 request.wait();
2255 } catch (InterruptedException e) {
2256 // Do nothing, go back and wait until the request is complete
2257 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002258 }
2259 }
2260 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002261 if (request.result == null) {
2262 Log.wtf(LOG_TAG,
2263 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2264 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002265 return request.result;
2266 }
2267
2268 /**
2269 * Asynchronous ("fire and forget") version of sendRequest():
2270 * Posts the specified command to be executed on the main thread, and
2271 * returns immediately.
2272 * @see #sendRequest
2273 */
2274 private void sendRequestAsync(int command) {
2275 mMainThreadHandler.sendEmptyMessage(command);
2276 }
2277
2278 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002279 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002280 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002281 */
2282 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002283 sendRequestAsync(command, argument, null, null);
2284 }
2285
2286 /**
2287 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2288 * @see {@link #sendRequest(int,Object)}
2289 */
2290 private void sendRequestAsync(
2291 int command, Object argument, Phone phone, WorkSource workSource) {
2292 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002293 Message msg = mMainThreadHandler.obtainMessage(command, request);
2294 msg.sendToTarget();
2295 }
2296
2297 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002298 * Initialize the singleton PhoneInterfaceManager instance.
2299 * This is only done once, at startup, from PhoneApp.onCreate().
2300 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002301 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002302 synchronized (PhoneInterfaceManager.class) {
2303 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002304 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002305 } else {
2306 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2307 }
2308 return sInstance;
2309 }
2310 }
2311
2312 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002313 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002314 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002315 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002316 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002317 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002318 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002319 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002320 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002321 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002322 mTelephonySharedPreferences =
2323 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002324 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002325 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002326 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002327 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002328
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002329 publish();
2330 }
2331
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002332 private Phone getDefaultPhone() {
2333 Phone thePhone = getPhone(getDefaultSubscription());
2334 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2335 }
2336
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002337 private void publish() {
2338 if (DBG) log("publish: " + this);
2339
Peter Wangc035ce42020-01-08 21:00:22 -08002340 TelephonyFrameworkInitializer
2341 .getTelephonyServiceManager()
2342 .getTelephonyServiceRegisterer()
2343 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002344 }
2345
Stuart Scott584921c2015-01-15 17:10:34 -08002346 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002347 if (request.phone != null) {
2348 return request.phone;
2349 } else {
2350 return getPhoneFromSubId(request.subId);
2351 }
2352 }
2353
2354 private Phone getPhoneFromSubId(int subId) {
2355 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2356 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002357 }
2358
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002359 private UiccPort getUiccPortFromRequest(MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002360 Phone phone = getPhoneFromRequest(request);
2361 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002362 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002363 }
2364
Wink Saville36469e72014-06-11 15:17:00 -07002365 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002366 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002367 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002368 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002369
Kai Shif70f46f2021-03-03 13:59:46 -08002370 private void sendEraseModemConfig(@NonNull Phone phone) {
2371 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2372 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2373 }
2374
2375 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2376 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2377 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002378 }
2379
Peter Wang44b186e2020-01-13 23:33:09 -08002380 private boolean isImsAvailableOnDevice() {
2381 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2382 if (pm == null) {
2383 // For some reason package manger is not available.. This will fail internally anyway,
2384 // so do not throw error and allow.
2385 return true;
2386 }
2387 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2388 }
2389
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002390 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002391 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002392 }
2393
Wink Savilleb564aae2014-10-23 10:18:09 -07002394 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002395 if (DBG) log("dial: " + number);
2396 // No permission check needed here: This is just a wrapper around the
2397 // ACTION_DIAL intent, which is available to any app since it puts up
2398 // the UI before it does anything.
2399
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002400 final long identity = Binder.clearCallingIdentity();
2401 try {
2402 String url = createTelUrl(number);
2403 if (url == null) {
2404 return;
2405 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002406
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002407 // PENDING: should we just silently fail if phone is offhook or ringing?
2408 PhoneConstants.State state = mCM.getState(subId);
2409 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2410 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2411 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2412 mApp.startActivity(intent);
2413 }
2414 } finally {
2415 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002416 }
2417 }
2418
2419 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002420 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002421 }
2422
Wink Savilleb564aae2014-10-23 10:18:09 -07002423 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002424 if (DBG) log("call: " + number);
2425
2426 // This is just a wrapper around the ACTION_CALL intent, but we still
2427 // need to do a permission check since we're calling startActivity()
2428 // from the context of the phone app.
2429 enforceCallPermission();
2430
Jordan Liu1617b712019-07-10 15:06:26 -07002431 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002432 != AppOpsManager.MODE_ALLOWED) {
2433 return;
2434 }
2435
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002436 final long identity = Binder.clearCallingIdentity();
2437 try {
2438 String url = createTelUrl(number);
2439 if (url == null) {
2440 return;
2441 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002442
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002443 boolean isValid = false;
2444 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2445 if (slist != null) {
2446 for (SubscriptionInfo subInfoRecord : slist) {
2447 if (subInfoRecord.getSubscriptionId() == subId) {
2448 isValid = true;
2449 break;
2450 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002451 }
Wink Saville08874612014-08-31 19:19:58 -07002452 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002453 if (!isValid) {
2454 return;
2455 }
Wink Saville08874612014-08-31 19:19:58 -07002456
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002457 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2458 intent.putExtra(SUBSCRIPTION_KEY, subId);
2459 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2460 mApp.startActivity(intent);
2461 } finally {
2462 Binder.restoreCallingIdentity(identity);
2463 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002464 }
2465
Wink Savilleb564aae2014-10-23 10:18:09 -07002466 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002467 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002468 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2469 }
2470
Wink Savilleb564aae2014-10-23 10:18:09 -07002471 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002472 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002473 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2474 }
2475
Wink Savilleb564aae2014-10-23 10:18:09 -07002476 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002477 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002478
2479 final long identity = Binder.clearCallingIdentity();
2480 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002481 Phone phone = getPhone(subId);
2482 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002483 checkSimPin.start();
2484 return checkSimPin.unlockSim(null, pin);
2485 } finally {
2486 Binder.restoreCallingIdentity(identity);
2487 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002488 }
2489
Wink Savilleb564aae2014-10-23 10:18:09 -07002490 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002491 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002492
2493 final long identity = Binder.clearCallingIdentity();
2494 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002495 Phone phone = getPhone(subId);
2496 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002497 checkSimPuk.start();
2498 return checkSimPuk.unlockSim(puk, pin);
2499 } finally {
2500 Binder.restoreCallingIdentity(identity);
2501 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002502 }
2503
2504 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002505 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002506 * a synchronous one.
2507 */
2508 private static class UnlockSim extends Thread {
2509
2510 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002511 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002512
2513 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002514 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2515 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002516
2517 // For replies from SimCard interface
2518 private Handler mHandler;
2519
2520 // For async handler to identify request type
2521 private static final int SUPPLY_PIN_COMPLETE = 100;
2522
Michele Berionne5e411512020-11-13 02:36:59 +00002523 UnlockSim(int phoneId, IccCard simCard) {
2524 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002525 mSimCard = simCard;
2526 }
2527
2528 @Override
2529 public void run() {
2530 Looper.prepare();
2531 synchronized (UnlockSim.this) {
2532 mHandler = new Handler() {
2533 @Override
2534 public void handleMessage(Message msg) {
2535 AsyncResult ar = (AsyncResult) msg.obj;
2536 switch (msg.what) {
2537 case SUPPLY_PIN_COMPLETE:
2538 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2539 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002540 mRetryCount = msg.arg1;
2541 if (ar.exception != null) {
2542 if (ar.exception instanceof CommandException &&
2543 ((CommandException)(ar.exception)).getCommandError()
2544 == CommandException.Error.PASSWORD_INCORRECT) {
2545 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002546 } //When UiccCardApp dispose,handle message and return exception
2547 else if (ar.exception instanceof CommandException &&
2548 ((CommandException) (ar.exception)).getCommandError()
2549 == CommandException.Error.ABORTED) {
2550 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002551 } else {
2552 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2553 }
2554 } else {
2555 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2556 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002557 mDone = true;
2558 UnlockSim.this.notifyAll();
2559 }
2560 break;
2561 }
2562 }
2563 };
2564 UnlockSim.this.notifyAll();
2565 }
2566 Looper.loop();
2567 }
2568
2569 /*
2570 * Use PIN or PUK to unlock SIM card
2571 *
2572 * If PUK is null, unlock SIM card with PIN
2573 *
2574 * If PUK is not null, unlock SIM card with PUK and set PIN code
2575 */
Wink Saville9de0f752013-10-22 19:04:03 -07002576 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002577
2578 while (mHandler == null) {
2579 try {
2580 wait();
2581 } catch (InterruptedException e) {
2582 Thread.currentThread().interrupt();
2583 }
2584 }
2585 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2586
2587 if (puk == null) {
2588 mSimCard.supplyPin(pin, callback);
2589 } else {
2590 mSimCard.supplyPuk(puk, pin, callback);
2591 }
2592
2593 while (!mDone) {
2594 try {
2595 Log.d(LOG_TAG, "wait for done");
2596 wait();
2597 } catch (InterruptedException e) {
2598 // Restore the interrupted status
2599 Thread.currentThread().interrupt();
2600 }
2601 }
2602 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002603 int[] resultArray = new int[2];
2604 resultArray[0] = mResult;
2605 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002606
2607 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002608 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002609 }
2610
Wink Saville9de0f752013-10-22 19:04:03 -07002611 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002612 }
2613 }
2614
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002615 /**
2616 * This method has been removed due to privacy and stability concerns.
2617 */
2618 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002619 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002620 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2621 return;
Wink Saville36469e72014-06-11 15:17:00 -07002622 }
2623
Nathan Harold1f889d82020-06-04 17:05:26 -07002624 @Override
2625 public void updateServiceLocationWithPackageName(String callingPackage) {
2626 mApp.getSystemService(AppOpsManager.class)
2627 .checkPackage(Binder.getCallingUid(), callingPackage);
2628
Nathan Haroldf096d982020-11-18 17:18:06 -08002629 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002630 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2631 // Callers targeting S have no business invoking this method.
2632 return;
2633 }
2634
2635 LocationAccessPolicy.LocationPermissionResult locationResult =
2636 LocationAccessPolicy.checkLocationPermission(mApp,
2637 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2638 .setCallingPackage(callingPackage)
2639 .setCallingFeatureId(null)
2640 .setCallingPid(Binder.getCallingPid())
2641 .setCallingUid(Binder.getCallingUid())
2642 .setMethod("updateServiceLocation")
2643 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2644 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2645 .build());
2646 // Apps that lack location permission have no business calling this method;
2647 // however, because no permission was declared in the public API, denials must
2648 // all be "soft".
2649 switch (locationResult) {
2650 case DENIED_HARD: /* fall through */
2651 case DENIED_SOFT:
2652 return;
2653 }
2654
2655 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002656 final long identity = Binder.clearCallingIdentity();
2657 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002658 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002659 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002660 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002661 }
2662 } finally {
2663 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002664 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002665 }
2666
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002667 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002668 @Override
2669 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002670 return isRadioOnWithFeature(callingPackage, null);
2671 }
2672
2673
2674 @Override
2675 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2676 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2677 callingFeatureId);
2678 }
2679
2680 @Deprecated
2681 @Override
2682 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2683 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002684 }
2685
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002686 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002687 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2688 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002689 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002690 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002691 return false;
2692 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002693
2694 final long identity = Binder.clearCallingIdentity();
2695 try {
2696 return isRadioOnForSubscriber(subId);
2697 } finally {
2698 Binder.restoreCallingIdentity(identity);
2699 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002700 }
2701
2702 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002703 final long identity = Binder.clearCallingIdentity();
2704 try {
2705 final Phone phone = getPhone(subId);
2706 if (phone != null) {
2707 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2708 } else {
2709 return false;
2710 }
2711 } finally {
2712 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002713 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002714 }
2715
2716 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002717 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002718 }
Wink Saville36469e72014-06-11 15:17:00 -07002719
Wink Savilleb564aae2014-10-23 10:18:09 -07002720 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002721 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002722
2723 final long identity = Binder.clearCallingIdentity();
2724 try {
2725 final Phone phone = getPhone(subId);
2726 if (phone != null) {
2727 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2728 }
2729 } finally {
2730 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002731 }
Wink Saville36469e72014-06-11 15:17:00 -07002732 }
2733
2734 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002735 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002736 }
2737
Wink Savilleb564aae2014-10-23 10:18:09 -07002738 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002739 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002740
2741 final long identity = Binder.clearCallingIdentity();
2742 try {
2743 final Phone phone = getPhone(subId);
2744 if (phone == null) {
2745 return false;
2746 }
2747 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2748 toggleRadioOnOffForSubscriber(subId);
2749 }
2750 return true;
2751 } finally {
2752 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002753 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002754 }
Wink Saville36469e72014-06-11 15:17:00 -07002755
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002756 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002757 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002758 /*
2759 * If any of the Radios are available, it will need to be
2760 * shutdown. So return true if any Radio is available.
2761 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002762 final long identity = Binder.clearCallingIdentity();
2763 try {
2764 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2765 Phone phone = PhoneFactory.getPhone(i);
2766 if (phone != null && phone.isRadioAvailable()) return true;
2767 }
2768 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2769 return false;
2770 } finally {
2771 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002772 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002773 }
2774
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002775 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002776 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002777 enforceModifyPermission();
2778
2779 final long identity = Binder.clearCallingIdentity();
2780 try {
2781 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2782 logv("Shutting down Phone " + i);
2783 shutdownRadioUsingPhoneId(i);
2784 }
2785 } finally {
2786 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002787 }
2788 }
2789
2790 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002791 Phone phone = PhoneFactory.getPhone(phoneId);
2792 if (phone != null && phone.isRadioAvailable()) {
2793 phone.shutdownRadio();
2794 }
2795 }
2796
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002797 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002798 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002799
2800 final long identity = Binder.clearCallingIdentity();
2801 try {
2802 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2803 if (defaultPhone != null) {
2804 defaultPhone.setRadioPower(turnOn);
2805 return true;
2806 } else {
2807 loge("There's no default phone.");
2808 return false;
2809 }
2810 } finally {
2811 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002812 }
Wink Saville36469e72014-06-11 15:17:00 -07002813 }
2814
Wink Savilleb564aae2014-10-23 10:18:09 -07002815 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002816 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002817
2818 final long identity = Binder.clearCallingIdentity();
2819 try {
2820 final Phone phone = getPhone(subId);
2821 if (phone != null) {
2822 phone.setRadioPower(turnOn);
2823 return true;
2824 } else {
2825 return false;
2826 }
2827 } finally {
2828 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002829 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002830 }
2831
Wink Saville36469e72014-06-11 15:17:00 -07002832 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002833 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002834 public boolean enableDataConnectivity() {
2835 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002836
2837 final long identity = Binder.clearCallingIdentity();
2838 try {
2839 int subId = mSubscriptionController.getDefaultDataSubId();
2840 final Phone phone = getPhone(subId);
2841 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002842 phone.getDataEnabledSettings().setDataEnabled(
2843 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002844 return true;
2845 } else {
2846 return false;
2847 }
2848 } finally {
2849 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002850 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002851 }
2852
Wink Saville36469e72014-06-11 15:17:00 -07002853 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002854 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002855 public boolean disableDataConnectivity() {
2856 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002857
2858 final long identity = Binder.clearCallingIdentity();
2859 try {
2860 int subId = mSubscriptionController.getDefaultDataSubId();
2861 final Phone phone = getPhone(subId);
2862 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002863 phone.getDataEnabledSettings().setDataEnabled(
2864 TelephonyManager.DATA_ENABLED_REASON_USER, false);
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
Sanket Padawe356d7632015-06-22 14:03:32 -07002874 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002875 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002876 final long identity = Binder.clearCallingIdentity();
2877 try {
2878 final Phone phone = getPhone(subId);
2879 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002880 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002881 } else {
2882 return false;
2883 }
2884 } finally {
2885 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002886 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002887 }
2888
2889 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002890 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002891 }
2892
pkanwarae03a6b2016-11-06 20:37:09 -08002893 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002894 enforceCallPermission();
2895
2896 final long identity = Binder.clearCallingIdentity();
2897 try {
2898 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2899 return;
2900 }
2901 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2902 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2903 } finally {
2904 Binder.restoreCallingIdentity(identity);
2905 }
pkanwar32d516d2016-10-14 19:37:38 -07002906 };
2907
Wink Savilleb564aae2014-10-23 10:18:09 -07002908 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002909 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002910
2911 final long identity = Binder.clearCallingIdentity();
2912 try {
2913 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2914 return false;
2915 }
2916 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2917 } finally {
2918 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002919 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002920 }
2921
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002922 /**
2923 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2924 * tag on getCallState Binder call.
2925 */
2926 @Deprecated
2927 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002928 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002929 if (CompatChanges.isChangeEnabled(
2930 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2931 Binder.getCallingUid())) {
2932 // Do not allow this API to be called on API version 31+, it should only be
2933 // called on old apps using this Binder call directly.
2934 throw new SecurityException("This method can only be used for applications "
2935 + "targeting API version 30 or less.");
2936 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002937 final long identity = Binder.clearCallingIdentity();
2938 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002939 Phone phone = getPhone(getDefaultSubscription());
2940 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2941 PhoneConstantConversions.convertCallState(phone.getState());
2942 } finally {
2943 Binder.restoreCallingIdentity(identity);
2944 }
2945 }
2946
2947 @Override
2948 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2949 if (CompatChanges.isChangeEnabled(
2950 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2951 Binder.getCallingUid())) {
2952 // Check READ_PHONE_STATE for API version 31+
2953 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2954 featureId, "getCallStateForSubscription")) {
2955 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2956 + "targeting API level 31+.");
2957 }
2958 }
2959 final long identity = Binder.clearCallingIdentity();
2960 try {
2961 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002962 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2963 PhoneConstantConversions.convertCallState(phone.getState());
2964 } finally {
2965 Binder.restoreCallingIdentity(identity);
2966 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002967 }
2968
Sanket Padawe356d7632015-06-22 14:03:32 -07002969 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002970 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002971 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2972 }
2973
2974 @Override
2975 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002976 final long identity = Binder.clearCallingIdentity();
2977 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002978 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002979 if (phone != null) {
Jack Yu2c450952021-11-29 11:36:17 -08002980 if (phone.isUsingNewDataStack()) {
2981 return phone.getDataNetworkController().getInternetDataNetworkState();
2982 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002983 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2984 } else {
2985 return PhoneConstantConversions.convertDataState(
2986 PhoneConstants.DataState.DISCONNECTED);
2987 }
2988 } finally {
2989 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002990 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002991 }
2992
Sanket Padawe356d7632015-06-22 14:03:32 -07002993 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002994 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002995 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2996 }
2997
2998 @Override
2999 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003000 final long identity = Binder.clearCallingIdentity();
3001 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003002 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003003 if (phone != null) {
3004 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
3005 } else {
3006 return TelephonyManager.DATA_ACTIVITY_NONE;
3007 }
3008 } finally {
3009 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003010 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003011 }
3012
3013 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003014 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003015 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003016 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003017
3018 LocationAccessPolicy.LocationPermissionResult locationResult =
3019 LocationAccessPolicy.checkLocationPermission(mApp,
3020 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3021 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003022 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003023 .setCallingPid(Binder.getCallingPid())
3024 .setCallingUid(Binder.getCallingUid())
3025 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003026 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003027 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3028 .build());
3029 switch (locationResult) {
3030 case DENIED_HARD:
3031 throw new SecurityException("Not allowed to access cell location");
3032 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003033 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3034 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003035 }
3036
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003037 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003038 final long identity = Binder.clearCallingIdentity();
3039 try {
3040 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003041 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003042 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003043 } finally {
3044 Binder.restoreCallingIdentity(identity);
3045 }
Svetoslav64fad262015-04-14 14:35:21 -07003046 }
3047
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003048 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003049 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003050 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3051 // registered cell info, so return a NULL country instead.
3052 final long identity = Binder.clearCallingIdentity();
3053 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003054 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3055 // Get default phone in this case.
3056 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3057 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003058 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003059 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003060 if (phone == null) return "";
3061 ServiceStateTracker sst = phone.getServiceStateTracker();
3062 if (sst == null) return "";
3063 LocaleTracker lt = sst.getLocaleTracker();
3064 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003065 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003066 } finally {
3067 Binder.restoreCallingIdentity(identity);
3068 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003069 }
3070
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003071 /**
3072 * This method was removed due to potential issues caused by performing partial
3073 * updates of service state, and lack of a credible use case.
3074 *
3075 * This has the ability to break the telephony implementation by disabling notification of
3076 * changes in device connectivity. DO NOT USE THIS!
3077 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003078 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003079 public void enableLocationUpdates() {
3080 mApp.enforceCallingOrSelfPermission(
3081 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003082 }
3083
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003084 /**
3085 * This method was removed due to potential issues caused by performing partial
3086 * updates of service state, and lack of a credible use case.
3087 *
3088 * This has the ability to break the telephony implementation by disabling notification of
3089 * changes in device connectivity. DO NOT USE THIS!
3090 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003091 @Override
3092 public void disableLocationUpdates() {
3093 mApp.enforceCallingOrSelfPermission(
3094 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003095 }
3096
3097 @Override
3098 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003099 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3100 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003101 try {
3102 mApp.getSystemService(AppOpsManager.class)
3103 .checkPackage(Binder.getCallingUid(), callingPackage);
3104 } catch (SecurityException e) {
3105 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3106 throw e;
3107 }
3108
Nathan Haroldf096d982020-11-18 17:18:06 -08003109 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003110 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3111 throw new SecurityException(
3112 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3113 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003114
Jordan Liu1617b712019-07-10 15:06:26 -07003115 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003116 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3117 return null;
3118 }
Svetoslav64fad262015-04-14 14:35:21 -07003119
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003120 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003121
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003122 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003123 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003124
Nathan Haroldf180aac2018-06-01 18:43:55 -07003125 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3126 for (CellInfo ci : info) {
3127 if (ci instanceof CellInfoGsm) {
3128 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3129 } else if (ci instanceof CellInfoWcdma) {
3130 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3131 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003132 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003133 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003134 }
3135
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003136 private List<CellInfo> getCachedCellInfo() {
3137 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3138 for (Phone phone : PhoneFactory.getPhones()) {
3139 List<CellInfo> info = phone.getAllCellInfo();
3140 if (info != null) cellInfos.addAll(info);
3141 }
3142 return cellInfos;
3143 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003144
3145 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003146 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003147 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003148 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003149
3150 LocationAccessPolicy.LocationPermissionResult locationResult =
3151 LocationAccessPolicy.checkLocationPermission(mApp,
3152 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3153 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003154 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003155 .setCallingPid(Binder.getCallingPid())
3156 .setCallingUid(Binder.getCallingUid())
3157 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003158 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003159 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3160 .build());
3161 switch (locationResult) {
3162 case DENIED_HARD:
3163 throw new SecurityException("Not allowed to access cell info");
3164 case DENIED_SOFT:
3165 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003166 }
3167
Nathan Haroldf096d982020-11-18 17:18:06 -08003168 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003169 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3170 return getCachedCellInfo();
3171 }
3172
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003173 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003174 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003175 final long identity = Binder.clearCallingIdentity();
3176 try {
3177 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3178 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003179 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003180 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003181 if (info != null) cellInfos.addAll(info);
3182 }
3183 return cellInfos;
3184 } finally {
3185 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003186 }
3187 }
3188
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003189 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003190 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3191 String callingFeatureId) {
3192 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3193 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003194 }
3195
3196 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003197 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3198 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003199 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003200 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003201 }
3202
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003203 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3204 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003205 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003206 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003207
3208 LocationAccessPolicy.LocationPermissionResult locationResult =
3209 LocationAccessPolicy.checkLocationPermission(mApp,
3210 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3211 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003212 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003213 .setCallingPid(Binder.getCallingPid())
3214 .setCallingUid(Binder.getCallingUid())
3215 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003216 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3217 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003218 .build());
3219 switch (locationResult) {
3220 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003221 if (TelephonyPermissions
3222 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003223 // Safetynet logging for b/154934934
3224 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3225 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003226 throw new SecurityException("Not allowed to access cell info");
3227 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003228 if (TelephonyPermissions
3229 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003230 // Safetynet logging for b/154934934
3231 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3232 }
Nathan Harold5320c422019-05-09 10:26:08 -07003233 try {
3234 cb.onCellInfo(new ArrayList<CellInfo>());
3235 } catch (RemoteException re) {
3236 // Drop without consequences
3237 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003238 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003239 }
3240
Nathan Harolda939a962019-05-09 10:13:47 -07003241
3242 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003243 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3244
3245 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3246 }
3247
3248 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003249 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003250 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003251 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003252
3253 final long identity = Binder.clearCallingIdentity();
3254 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003255 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003256 } finally {
3257 Binder.restoreCallingIdentity(identity);
3258 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003259 }
3260
Shishir Agrawala9f32182016-04-12 12:00:16 -07003261 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003262 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003263 Phone phone = PhoneFactory.getPhone(slotIndex);
3264 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003265 return null;
3266 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003267 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003268 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003269 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003270 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003271 return null;
3272 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003273
3274 final long identity = Binder.clearCallingIdentity();
3275 try {
3276 return phone.getImei();
3277 } finally {
3278 Binder.restoreCallingIdentity(identity);
3279 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003280 }
3281
3282 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003283 public String getTypeAllocationCodeForSlot(int slotIndex) {
3284 Phone phone = PhoneFactory.getPhone(slotIndex);
3285 String tac = null;
3286 if (phone != null) {
3287 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003288 try {
3289 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3290 } catch (IndexOutOfBoundsException e) {
3291 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3292 return null;
3293 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003294 }
3295 return tac;
3296 }
3297
3298 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003299 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003300 try {
3301 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3302 } catch (SecurityException se) {
3303 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3304 throw new SecurityException("Package " + callingPackage + " does not belong to "
3305 + Binder.getCallingUid());
3306 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003307 Phone phone = PhoneFactory.getPhone(slotIndex);
3308 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003309 return null;
3310 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003311
Jeff Davidson913390f2018-02-23 17:11:49 -08003312 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003313 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003314 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003315 return null;
3316 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003317
3318 final long identity = Binder.clearCallingIdentity();
3319 try {
3320 return phone.getMeid();
3321 } finally {
3322 Binder.restoreCallingIdentity(identity);
3323 }
Jack Yu2af8d712017-03-15 17:14:14 -07003324 }
3325
3326 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003327 public String getManufacturerCodeForSlot(int slotIndex) {
3328 Phone phone = PhoneFactory.getPhone(slotIndex);
3329 String manufacturerCode = null;
3330 if (phone != null) {
3331 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003332 try {
3333 manufacturerCode =
3334 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3335 } catch (IndexOutOfBoundsException e) {
3336 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3337 return null;
3338 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003339 }
3340 return manufacturerCode;
3341 }
3342
3343 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003344 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3345 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003346 Phone phone = PhoneFactory.getPhone(slotIndex);
3347 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003348 return null;
3349 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003350 int subId = phone.getSubId();
3351 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003352 mApp, subId, callingPackage, callingFeatureId,
3353 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003354 return null;
3355 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003356
3357 final long identity = Binder.clearCallingIdentity();
3358 try {
3359 return phone.getDeviceSvn();
3360 } finally {
3361 Binder.restoreCallingIdentity(identity);
3362 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003363 }
3364
fionaxu43304da2017-11-27 22:51:16 -08003365 @Override
3366 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003367 final long identity = Binder.clearCallingIdentity();
3368 try {
3369 final Phone phone = getPhone(subId);
3370 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3371 } finally {
3372 Binder.restoreCallingIdentity(identity);
3373 }
fionaxu43304da2017-11-27 22:51:16 -08003374 }
3375
3376 @Override
3377 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003378 final long identity = Binder.clearCallingIdentity();
3379 try {
3380 final Phone phone = getPhone(subId);
3381 return phone == null ? null : phone.getCarrierName();
3382 } finally {
3383 Binder.restoreCallingIdentity(identity);
3384 }
fionaxu43304da2017-11-27 22:51:16 -08003385 }
3386
calvinpanffe225e2018-11-01 19:43:06 +08003387 @Override
chen xu0026ca62019-03-06 15:28:50 -08003388 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003389 final long identity = Binder.clearCallingIdentity();
3390 try {
3391 final Phone phone = getPhone(subId);
3392 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003393 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003394 } finally {
3395 Binder.restoreCallingIdentity(identity);
3396 }
3397 }
3398
3399 @Override
chen xu0026ca62019-03-06 15:28:50 -08003400 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003401 final long identity = Binder.clearCallingIdentity();
3402 try {
3403 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003404 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003405 } finally {
3406 Binder.restoreCallingIdentity(identity);
3407 }
3408 }
3409
chen xu651eec72018-11-11 19:03:44 -08003410 @Override
chen xu864e11c2018-12-06 22:10:03 -08003411 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3412 if (!isSubscriptionMccMnc) {
3413 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3414 }
chen xu651eec72018-11-11 19:03:44 -08003415 final Phone phone = PhoneFactory.getPhone(slotIndex);
3416 if (phone == null) {
3417 return TelephonyManager.UNKNOWN_CARRIER_ID;
3418 }
3419 final long identity = Binder.clearCallingIdentity();
3420 try {
3421 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3422 } finally {
3423 Binder.restoreCallingIdentity(identity);
3424 }
3425 }
3426
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003427 //
3428 // Internal helper methods.
3429 //
3430
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003431 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003432 * Make sure the caller is the calling package itself
3433 *
3434 * @throws SecurityException if the caller is not the calling package
3435 */
3436 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3437 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003438 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3439 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003440 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003441 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003442 } catch (PackageManager.NameNotFoundException e) {
3443 // packageUid is -1
3444 }
3445 if (packageUid != callingUid) {
3446 throw new SecurityException(message + ": Package " + callingPackage
3447 + " does not belong to " + callingUid);
3448 }
3449 }
3450
3451 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003452 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3453 *
3454 * @throws SecurityException if the caller does not have the required permission
3455 */
3456 private void enforceModifyPermission() {
3457 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3458 }
3459
Shuo Qian3b6ee772019-11-13 17:43:31 -08003460 private void enforceActiveEmergencySessionPermission() {
3461 mApp.enforceCallingOrSelfPermission(
3462 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3463 }
3464
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003465 /**
3466 * Make sure the caller has the CALL_PHONE permission.
3467 *
3468 * @throws SecurityException if the caller does not have the required permission
3469 */
3470 private void enforceCallPermission() {
3471 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3472 }
3473
paulhu5a773602019-08-23 19:17:33 +08003474 private void enforceSettingsPermission() {
3475 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003476 }
3477
Michele Berionne5e411512020-11-13 02:36:59 +00003478 private void enforceRebootPermission() {
3479 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3480 }
3481
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003482 private String createTelUrl(String number) {
3483 if (TextUtils.isEmpty(number)) {
3484 return null;
3485 }
3486
Jake Hambye994d462014-02-03 13:10:13 -08003487 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003488 }
3489
Ihab Awadf9e92732013-12-05 18:02:52 -08003490 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003491 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3492 }
3493
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003494 private static void logv(String msg) {
3495 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3496 }
3497
Ihab Awadf9e92732013-12-05 18:02:52 -08003498 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003499 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3500 }
3501
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003502 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003503 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003504 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003505 }
3506
Sanket Padawe356d7632015-06-22 14:03:32 -07003507 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003508 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003509 final long identity = Binder.clearCallingIdentity();
3510 try {
3511 final Phone phone = PhoneFactory.getPhone(slotIndex);
3512 if (phone == null) {
3513 return PhoneConstants.PHONE_TYPE_NONE;
3514 } else {
3515 return phone.getPhoneType();
3516 }
3517 } finally {
3518 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003519 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003520 }
3521
3522 /**
3523 * Returns the CDMA ERI icon index to display
3524 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003525 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003526 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3527 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3528 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003529 }
3530
Sanket Padawe356d7632015-06-22 14:03:32 -07003531 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003532 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3533 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003534 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003535 mApp, subId, callingPackage, callingFeatureId,
3536 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003537 return -1;
3538 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003539
3540 final long identity = Binder.clearCallingIdentity();
3541 try {
3542 final Phone phone = getPhone(subId);
3543 if (phone != null) {
3544 return phone.getCdmaEriIconIndex();
3545 } else {
3546 return -1;
3547 }
3548 } finally {
3549 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003550 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003551 }
3552
3553 /**
3554 * Returns the CDMA ERI icon mode,
3555 * 0 - ON
3556 * 1 - FLASHING
3557 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003558 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003559 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3560 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3561 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003562 }
3563
Sanket Padawe356d7632015-06-22 14:03:32 -07003564 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003565 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3566 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003567 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003568 mApp, subId, callingPackage, callingFeatureId,
3569 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003570 return -1;
3571 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003572
3573 final long identity = Binder.clearCallingIdentity();
3574 try {
3575 final Phone phone = getPhone(subId);
3576 if (phone != null) {
3577 return phone.getCdmaEriIconMode();
3578 } else {
3579 return -1;
3580 }
3581 } finally {
3582 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003583 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003584 }
3585
3586 /**
3587 * Returns the CDMA ERI text,
3588 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003589 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003590 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3591 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3592 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003593 }
3594
Sanket Padawe356d7632015-06-22 14:03:32 -07003595 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003596 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3597 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003598 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003599 mApp, subId, callingPackage, callingFeatureId,
3600 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003601 return null;
3602 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003603
3604 final long identity = Binder.clearCallingIdentity();
3605 try {
3606 final Phone phone = getPhone(subId);
3607 if (phone != null) {
3608 return phone.getCdmaEriText();
3609 } else {
3610 return null;
3611 }
3612 } finally {
3613 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003614 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003615 }
3616
3617 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003618 * Returns the CDMA MDN.
3619 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003620 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003621 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003622 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3623 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003624
3625 final long identity = Binder.clearCallingIdentity();
3626 try {
3627 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003628 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003629 return phone.getLine1Number();
3630 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003631 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003632 return null;
3633 }
3634 } finally {
3635 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003636 }
3637 }
3638
3639 /**
3640 * Returns the CDMA MIN.
3641 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003642 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003643 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003644 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3645 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003646
3647 final long identity = Binder.clearCallingIdentity();
3648 try {
3649 final Phone phone = getPhone(subId);
3650 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3651 return phone.getCdmaMin();
3652 } else {
3653 return null;
3654 }
3655 } finally {
3656 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003657 }
3658 }
3659
Hall Liud892bec2018-11-30 14:51:45 -08003660 @Override
3661 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3662 INumberVerificationCallback callback, String callingPackage) {
3663 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3664 != PERMISSION_GRANTED) {
3665 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3666 }
3667 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3668
3669 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3670 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003671 throw new SecurityException("Calling package must be configured in the device config: "
3672 + "calling package: " + callingPackage
3673 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003674 }
3675
3676 if (range == null) {
3677 throw new NullPointerException("Range must be non-null");
3678 }
3679
3680 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003681 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003682
3683 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3684 }
3685
Junda Liuca05d5d2014-08-14 22:36:34 -07003686 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003687 * Returns true if CDMA provisioning needs to run.
3688 */
3689 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003690 final long identity = Binder.clearCallingIdentity();
3691 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003692 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003693 } finally {
3694 Binder.restoreCallingIdentity(identity);
3695 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003696 }
3697
3698 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003699 * Sets the voice mail number of a given subId.
3700 */
3701 @Override
3702 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003703 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3704 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003705
3706 final long identity = Binder.clearCallingIdentity();
3707 try {
3708 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3709 new Pair<String, String>(alphaTag, number), new Integer(subId));
3710 return success;
3711 } finally {
3712 Binder.restoreCallingIdentity(identity);
3713 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003714 }
3715
Ta-wei Yen87c49842016-05-13 21:19:52 -07003716 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003717 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3718 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003719 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3720 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003721 if (!TextUtils.equals(callingPackage, systemDialer)) {
3722 throw new SecurityException("caller must be system dialer");
3723 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003724
3725 final long identity = Binder.clearCallingIdentity();
3726 try {
3727 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3728 if (phoneAccountHandle == null) {
3729 return null;
3730 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003731 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003732 } finally {
3733 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003734 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003735 }
3736
3737 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003738 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3739 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003740 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003741 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003742 mApp, subId, callingPackage, callingFeatureId,
3743 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003744 return null;
3745 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003746
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003747 final long identity = Binder.clearCallingIdentity();
3748 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003749 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003750 } finally {
3751 Binder.restoreCallingIdentity(identity);
3752 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003753 }
3754
3755 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003756 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3757 VisualVoicemailSmsFilterSettings settings) {
3758 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003759
3760 final long identity = Binder.clearCallingIdentity();
3761 try {
3762 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003763 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003764 } finally {
3765 Binder.restoreCallingIdentity(identity);
3766 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003767 }
3768
3769 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003770 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3771 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003772
3773 final long identity = Binder.clearCallingIdentity();
3774 try {
3775 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003776 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003777 } finally {
3778 Binder.restoreCallingIdentity(identity);
3779 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003780 }
3781
3782 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003783 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3784 String callingPackage, int subId) {
3785 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003786
3787 final long identity = Binder.clearCallingIdentity();
3788 try {
3789 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003790 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003791 } finally {
3792 Binder.restoreCallingIdentity(identity);
3793 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003794 }
3795
3796 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003797 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003798 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003799
3800 final long identity = Binder.clearCallingIdentity();
3801 try {
3802 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003803 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003804 } finally {
3805 Binder.restoreCallingIdentity(identity);
3806 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003807 }
3808
3809 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003810 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3811 String callingAttributionTag, int subId, String number, int port, String text,
3812 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003813 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003814 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003815 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003816 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003817 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3818 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003819 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003820
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003821 /**
fionaxu0152e512016-11-14 13:36:14 -08003822 * Sets the voice activation state of a given subId.
3823 */
3824 @Override
3825 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003826 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3827 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003828
3829 final long identity = Binder.clearCallingIdentity();
3830 try {
3831 final Phone phone = getPhone(subId);
3832 if (phone != null) {
3833 phone.setVoiceActivationState(activationState);
3834 } else {
3835 loge("setVoiceActivationState fails with invalid subId: " + subId);
3836 }
3837 } finally {
3838 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003839 }
3840 }
3841
3842 /**
3843 * Sets the data activation state of a given subId.
3844 */
3845 @Override
3846 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003847 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3848 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003849
3850 final long identity = Binder.clearCallingIdentity();
3851 try {
3852 final Phone phone = getPhone(subId);
3853 if (phone != null) {
3854 phone.setDataActivationState(activationState);
3855 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003856 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003857 }
3858 } finally {
3859 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003860 }
3861 }
3862
3863 /**
3864 * Returns the voice activation state of a given subId.
3865 */
3866 @Override
3867 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003868 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003869
fionaxu0152e512016-11-14 13:36:14 -08003870 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003871 final long identity = Binder.clearCallingIdentity();
3872 try {
3873 if (phone != null) {
3874 return phone.getVoiceActivationState();
3875 } else {
3876 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3877 }
3878 } finally {
3879 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003880 }
3881 }
3882
3883 /**
3884 * Returns the data activation state of a given subId.
3885 */
3886 @Override
3887 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003888 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003889
fionaxu0152e512016-11-14 13:36:14 -08003890 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003891 final long identity = Binder.clearCallingIdentity();
3892 try {
3893 if (phone != null) {
3894 return phone.getDataActivationState();
3895 } else {
3896 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3897 }
3898 } finally {
3899 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003900 }
3901 }
3902
3903 /**
Wink Saville36469e72014-06-11 15:17:00 -07003904 * Returns the unread count of voicemails for a subId
3905 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003906 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003907 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3908 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003909 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003910 mApp, subId, callingPackage, callingFeatureId,
3911 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003912 return 0;
3913 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003914 final long identity = Binder.clearCallingIdentity();
3915 try {
3916 final Phone phone = getPhone(subId);
3917 if (phone != null) {
3918 return phone.getVoiceMessageCount();
3919 } else {
3920 return 0;
3921 }
3922 } finally {
3923 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003924 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003925 }
3926
3927 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003928 * returns true, if the device is in a state where both voice and data
3929 * are supported simultaneously. This can change based on location or network condition.
3930 */
3931 @Override
3932 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003933 final long identity = Binder.clearCallingIdentity();
3934 try {
3935 final Phone phone = getPhone(subId);
3936 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3937 } finally {
3938 Binder.restoreCallingIdentity(identity);
3939 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003940 }
3941
3942 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003943 * Send the dialer code if called from the current default dialer or the caller has
3944 * carrier privilege.
3945 * @param inputCode The dialer code to send
3946 */
3947 @Override
3948 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003949 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003950 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003951 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3952 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003953 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003954 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003955 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003956 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003957
3958 final long identity = Binder.clearCallingIdentity();
3959 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003960 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003961 } finally {
3962 Binder.restoreCallingIdentity(identity);
3963 }
fionaxu235cc5e2017-03-06 22:25:57 -08003964 }
3965
Pengquan Menga1bb6272018-09-06 09:59:22 -07003966 @Override
3967 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003968 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003969 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003970 mApp, subId, "getNetworkSelectionMode");
3971 final long identity = Binder.clearCallingIdentity();
3972 try {
3973 if (!isActiveSubscription(subId)) {
3974 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3975 }
3976 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3977 } finally {
3978 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003979 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003980 }
3981
Brad Ebinger35c841c2018-10-01 10:40:55 -07003982 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003983 public boolean isInEmergencySmsMode() {
3984 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3985 final long identity = Binder.clearCallingIdentity();
3986 try {
3987 for (Phone phone : PhoneFactory.getPhones()) {
3988 if (phone.isInEmergencySmsMode()) {
3989 return true;
3990 }
3991 }
3992 } finally {
3993 Binder.restoreCallingIdentity(identity);
3994 }
3995 return false;
3996 }
3997
shilu366312e2019-12-17 09:28:10 -08003998 /**
3999 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4000 * @param subId The subscription to use to check the configuration.
4001 * @param c The callback that will be used to send the result.
4002 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004003 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004004 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4005 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004006 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004007 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08004008
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004009 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4010 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4011 "IMS not available on device.");
4012 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004013 final long token = Binder.clearCallingIdentity();
4014 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004015 int slotId = getSlotIndexOrException(subId);
4016 verifyImsMmTelConfiguredOrThrow(slotId);
4017 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004018 } catch (ImsException e) {
4019 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004020 } finally {
4021 Binder.restoreCallingIdentity(token);
4022 }
4023 }
4024
shilu366312e2019-12-17 09:28:10 -08004025 /**
4026 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4027 * @param subId The subscription to use to check the configuration.
4028 * @param c The callback that will be used to send the result.
4029 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004030 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004031 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004032 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004033 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004034 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4035 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4036 }
Meng Wangafbc5852019-09-19 17:37:13 -07004037 final long token = Binder.clearCallingIdentity();
4038 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004039 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4040 .removeRegistrationCallbackForSubscription(c, subId);
4041 } catch (ImsException e) {
4042 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4043 + "is inactive, ignoring unregister.");
4044 // If the subscription is no longer active, just return, since the callback
4045 // will already have been removed internally.
4046 } finally {
4047 Binder.restoreCallingIdentity(token);
4048 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004049 }
4050
Brad Ebingera34a6c22019-10-22 17:36:18 -07004051 /**
4052 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4053 */
4054 @Override
4055 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4056 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4057 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4058 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4059 "IMS not available on device.");
4060 }
4061 final long token = Binder.clearCallingIdentity();
4062 try {
4063 Phone phone = getPhone(subId);
4064 if (phone == null) {
4065 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4066 + subId + "'");
4067 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4068 }
4069 phone.getImsRegistrationState(regState -> {
4070 try {
4071 consumer.accept((regState == null)
4072 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4073 } catch (RemoteException e) {
4074 // Ignore if the remote process is no longer available to call back.
4075 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4076 }
4077 });
4078 } finally {
4079 Binder.restoreCallingIdentity(token);
4080 }
4081 }
4082
4083 /**
4084 * Get the transport type for the IMS service registration state.
4085 */
4086 @Override
4087 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004088 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004089 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004090 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4091 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4092 "IMS not available on device.");
4093 }
4094 final long token = Binder.clearCallingIdentity();
4095 try {
4096 Phone phone = getPhone(subId);
4097 if (phone == null) {
4098 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4099 + subId + "'");
4100 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4101 }
4102 phone.getImsRegistrationTech(regTech -> {
4103 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4104 int regTechConverted = (regTech == null)
4105 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4106 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4107 regTechConverted);
4108 try {
4109 consumer.accept(regTechConverted);
4110 } catch (RemoteException e) {
4111 // Ignore if the remote process is no longer available to call back.
4112 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4113 }
4114 });
4115 } finally {
4116 Binder.restoreCallingIdentity(token);
4117 }
4118 }
4119
shilu366312e2019-12-17 09:28:10 -08004120 /**
4121 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4122 * @param subId The subscription to use to check the configuration.
4123 * @param c The callback that will be used to send the result.
4124 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004125 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004126 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4127 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004128 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004129 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004130 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4131 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4132 "IMS not available on device.");
4133 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004134 final long token = Binder.clearCallingIdentity();
4135 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004136 int slotId = getSlotIndexOrException(subId);
4137 verifyImsMmTelConfiguredOrThrow(slotId);
4138 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004139 } catch (ImsException e) {
4140 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004141 } 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 unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004153 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004154 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004155 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4156 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4157 }
Meng Wangafbc5852019-09-19 17:37:13 -07004158
4159 final long token = Binder.clearCallingIdentity();
4160 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004161 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004162 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004163 } catch (ImsException e) {
4164 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4165 + "is inactive, ignoring unregister.");
4166 // If the subscription is no longer active, just return, since the callback
4167 // will already have been removed internally.
4168 } finally {
4169 Binder.restoreCallingIdentity(token);
4170 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004171 }
4172
4173 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004174 public boolean isCapable(int subId, int capability, int regTech) {
4175 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004176 final long token = Binder.clearCallingIdentity();
4177 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004178 int slotId = getSlotIndexOrException(subId);
4179 verifyImsMmTelConfiguredOrThrow(slotId);
4180 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004181 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004182 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4183 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004184 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004185 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4186 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004187 } finally {
4188 Binder.restoreCallingIdentity(token);
4189 }
4190 }
4191
4192 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004193 public boolean isAvailable(int subId, int capability, int regTech) {
4194 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004195 final long token = Binder.clearCallingIdentity();
4196 try {
4197 Phone phone = getPhone(subId);
4198 if (phone == null) return false;
4199 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004200 } catch (com.android.ims.ImsException e) {
4201 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4202 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004203 } finally {
4204 Binder.restoreCallingIdentity(token);
4205 }
4206 }
4207
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004208 /**
4209 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4210 * subscription.
4211 * @param subId The subscription to use to check the configuration.
4212 * @param callback The callback that will be used to send the result.
4213 * @param capability The MmTelFeature capability that will be used to send the result.
4214 * @param transportType The transport type of the MmTelFeature capability.
4215 */
4216 @Override
4217 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4218 int transportType) {
4219 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4220 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4221 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4222 "IMS not available on device.");
4223 }
4224 final long token = Binder.clearCallingIdentity();
4225 try {
4226 int slotId = getSlotIndex(subId);
4227 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4228 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4229 + subId + "'");
4230 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4231 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004232 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004233 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4234 transportType, aBoolean -> {
4235 try {
4236 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4237 } catch (RemoteException e) {
4238 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4239 + "running. Ignore");
4240 }
4241 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004242 } catch (ImsException e) {
4243 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004244 } finally {
4245 Binder.restoreCallingIdentity(token);
4246 }
4247 }
4248
shilu366312e2019-12-17 09:28:10 -08004249 /**
4250 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4251 * @param subId The subscription to use to check the configuration.
4252 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004253 @Override
4254 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004255 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004256 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004257
Brad Ebinger35c841c2018-10-01 10:40:55 -07004258 final long token = Binder.clearCallingIdentity();
4259 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004260 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004261 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004262 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004263 } catch (ImsException e) {
4264 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004265 } finally {
4266 Binder.restoreCallingIdentity(token);
4267 }
4268 }
4269
4270 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004271 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004272 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004273 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004274 final long identity = Binder.clearCallingIdentity();
4275 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004276 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004277 // This setting doesn't require an active ImsService connection, so do not verify. The
4278 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004279 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004280 } catch (ImsException e) {
4281 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004282 } finally {
4283 Binder.restoreCallingIdentity(identity);
4284 }
4285 }
4286
shilu366312e2019-12-17 09:28:10 -08004287 /**
4288 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4289 * @param subId The subscription to use to check the configuration.
4290 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004291 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004292 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004293 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004294 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004295 final long identity = Binder.clearCallingIdentity();
4296 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004297 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004298 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004299 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004300 } catch (ImsException e) {
4301 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004302 } finally {
4303 Binder.restoreCallingIdentity(identity);
4304 }
4305 }
4306
4307 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004308 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004309 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004310 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004311 final long identity = Binder.clearCallingIdentity();
4312 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004313 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004314 // This setting doesn't require an active ImsService connection, so do not verify. The
4315 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004316 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004317 } catch (ImsException e) {
4318 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004319 } finally {
4320 Binder.restoreCallingIdentity(identity);
4321 }
4322 }
4323
shilu366312e2019-12-17 09:28:10 -08004324 /**
4325 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4326 * @param subId The subscription to use to check the configuration.
4327 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004328 @Override
4329 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004330 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004331 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004332 final long identity = Binder.clearCallingIdentity();
4333 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004334 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004335 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004336 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004337 } catch (ImsException e) {
4338 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004339 } finally {
4340 Binder.restoreCallingIdentity(identity);
4341 }
4342 }
4343
4344 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004345 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004346 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004347 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004348 final long identity = Binder.clearCallingIdentity();
4349 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004350 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004351 // This setting doesn't require an active ImsService connection, so do not verify. The
4352 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004353 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004354 } catch (ImsException e) {
4355 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004356 } finally {
4357 Binder.restoreCallingIdentity(identity);
4358 }
4359 }
4360
shilu366312e2019-12-17 09:28:10 -08004361 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004362 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4363 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4364 * @param subId The subscription to use to check the configuration.
4365 */
4366 @Override
4367 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004368 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004369 mApp, subId, "isCrossSimCallingEnabledByUser");
4370 final long identity = Binder.clearCallingIdentity();
4371 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004372 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004373 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004374 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004375 } catch (ImsException e) {
4376 throw new ServiceSpecificException(e.getCode());
4377 } finally {
4378 Binder.restoreCallingIdentity(identity);
4379 }
4380 }
4381
4382 /**
4383 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4384 * Requires MODIFY_PHONE_STATE permission.
4385 * @param subId The subscription to use to check the configuration.
4386 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4387 * false otherwise
4388 */
4389 @Override
4390 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4391 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4392 "setCrossSimCallingEnabled");
4393 final long identity = Binder.clearCallingIdentity();
4394 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004395 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004396 // This setting doesn't require an active ImsService connection, so do not verify. The
4397 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004398 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004399 } catch (ImsException e) {
4400 throw new ServiceSpecificException(e.getCode());
4401 } finally {
4402 Binder.restoreCallingIdentity(identity);
4403 }
4404 }
4405
4406 /**
shilu366312e2019-12-17 09:28:10 -08004407 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4408 * @param subId The subscription to use to check the configuration.
4409 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004410 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004411
Brad Ebinger35c841c2018-10-01 10:40:55 -07004412 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004413 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004414 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004415 final long identity = Binder.clearCallingIdentity();
4416 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004417 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004418 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004419 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004420 } catch (ImsException e) {
4421 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004422 } finally {
4423 Binder.restoreCallingIdentity(identity);
4424 }
4425 }
4426
4427 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004428 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004429 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004430 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004431 final long identity = Binder.clearCallingIdentity();
4432 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004433 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004434 // This setting doesn't require an active ImsService connection, so do not verify. The
4435 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004436 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004437 } catch (ImsException e) {
4438 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004439 } finally {
4440 Binder.restoreCallingIdentity(identity);
4441 }
4442 }
4443
4444 @Override
4445 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4446 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4447 "setVoWiFiNonPersistent");
4448 final long identity = Binder.clearCallingIdentity();
4449 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004450 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004451 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004452 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004453 } catch (ImsException e) {
4454 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004455 } finally {
4456 Binder.restoreCallingIdentity(identity);
4457 }
4458 }
4459
shilu366312e2019-12-17 09:28:10 -08004460 /**
4461 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4462 * @param subId The subscription to use to check the configuration.
4463 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004464 @Override
4465 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004466 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004467 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004468 final long identity = Binder.clearCallingIdentity();
4469 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004470 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004471 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004472 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004473 } catch (ImsException e) {
4474 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004475 } finally {
4476 Binder.restoreCallingIdentity(identity);
4477 }
4478 }
4479
4480 @Override
4481 public void setVoWiFiModeSetting(int subId, int mode) {
4482 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4483 "setVoWiFiModeSetting");
4484 final long identity = Binder.clearCallingIdentity();
4485 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004486 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004487 // This setting doesn't require an active ImsService connection, so do not verify. The
4488 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004489 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004490 } catch (ImsException e) {
4491 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004492 } finally {
4493 Binder.restoreCallingIdentity(identity);
4494 }
4495 }
4496
4497 @Override
4498 public int getVoWiFiRoamingModeSetting(int subId) {
4499 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4500 final long identity = Binder.clearCallingIdentity();
4501 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004502 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004503 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004504 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004505 } catch (ImsException e) {
4506 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004507 } finally {
4508 Binder.restoreCallingIdentity(identity);
4509 }
4510 }
4511
4512 @Override
4513 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4514 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4515 "setVoWiFiRoamingModeSetting");
4516 final long identity = Binder.clearCallingIdentity();
4517 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004518 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004519 // This setting doesn't require an active ImsService connection, so do not verify. The
4520 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004521 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004522 } catch (ImsException e) {
4523 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004524 } finally {
4525 Binder.restoreCallingIdentity(identity);
4526 }
4527 }
4528
4529 @Override
4530 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4531 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4532 "setRttCapabilityEnabled");
4533 final long identity = Binder.clearCallingIdentity();
4534 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004535 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004536 // This setting doesn't require an active ImsService connection, so do not verify. The
4537 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004538 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004539 } catch (ImsException e) {
4540 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004541 } finally {
4542 Binder.restoreCallingIdentity(identity);
4543 }
4544 }
4545
shilu366312e2019-12-17 09:28:10 -08004546 /**
4547 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4548 * @param subId The subscription to use to check the configuration.
4549 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004550 @Override
4551 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004552 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004553 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004554 final long identity = Binder.clearCallingIdentity();
4555 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004556 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004557 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004558 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004559 } catch (ImsException e) {
4560 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004561 } finally {
4562 Binder.restoreCallingIdentity(identity);
4563 }
4564 }
4565
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004566 @Override
4567 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4568 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4569 final long identity = Binder.clearCallingIdentity();
4570 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004571 if (!isImsAvailableOnDevice()) {
4572 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4573 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004574 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004575 int slotId = getSlotIndexOrException(subId);
4576 verifyImsMmTelConfiguredOrThrow(slotId);
4577 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004578 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004579 } catch (ImsException e) {
4580 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004581 } finally {
4582 Binder.restoreCallingIdentity(identity);
4583 }
4584 }
4585
4586 @Override
4587 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4588 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4589 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004590 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4591 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4592 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004593 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004594 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004595 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004596 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004597 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4598 + "is inactive, ignoring unregister.");
4599 // If the subscription is no longer active, just return, since the callback will already
4600 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004601 } finally {
4602 Binder.restoreCallingIdentity(identity);
4603 }
4604 }
4605
allenwtsu99c623b2020-01-03 18:24:23 +08004606
4607 private void checkModifyPhoneStatePermission(int subId, String message) {
4608 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4609 message);
4610 }
4611
4612 private boolean isImsProvisioningRequired(int subId, int capability,
4613 boolean isMmtelCapability) {
4614 Phone phone = getPhone(subId);
4615 if (phone == null) {
4616 loge("phone instance null for subid " + subId);
4617 return false;
4618 }
4619 if (isMmtelCapability) {
4620 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4621 return false;
4622 }
4623 } else {
4624 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4625 return false;
4626 }
4627 }
4628 return true;
4629 }
4630
4631 @Override
4632 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4633 boolean isProvisioned) {
4634 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4635
4636 final long identity = Binder.clearCallingIdentity();
4637 try {
4638 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4639 if (!isImsProvisioningRequired(subId, capability, false)) {
4640 return;
4641 }
4642
4643 // this capability requires provisioning, route to the correct API.
4644 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4645 switch (capability) {
4646 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4647 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4648 ims.setEabProvisioned(isProvisioned);
4649 break;
4650 default: {
4651 throw new IllegalArgumentException("Tried to set provisioning for "
4652 + "rcs capability '" + capability + "', which does not require "
4653 + "provisioning.");
4654 }
4655 }
4656 } finally {
4657 Binder.restoreCallingIdentity(identity);
4658 }
4659
4660 }
4661
4662
4663 @Override
4664 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4665 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4666 final long identity = Binder.clearCallingIdentity();
4667 try {
4668 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4669 if (!isImsProvisioningRequired(subId, capability, false)) {
4670 return true;
4671 }
4672
4673 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4674 switch (capability) {
4675 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4676 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4677 return ims.isEabProvisionedOnDevice();
4678
4679 default: {
4680 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4681 + "capability '" + capability + "', which does not require "
4682 + "provisioning.");
4683 }
4684 }
4685
4686 } finally {
4687 Binder.restoreCallingIdentity(identity);
4688 }
4689 }
4690
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004691 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004692 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4693 boolean isProvisioned) {
4694 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004695 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4696 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4697 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004698 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4699 }
allenwtsu99c623b2020-01-03 18:24:23 +08004700 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004701 final long identity = Binder.clearCallingIdentity();
4702 try {
4703 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004704 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004705 return;
4706 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004707 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4708 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4709 loge("setImsProvisioningStatusForCapability: called for technology that does "
4710 + "not support provisioning - " + tech);
4711 return;
4712 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004713
4714 // this capability requires provisioning, route to the correct API.
4715 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4716 switch (capability) {
4717 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4718 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4719 ims.setVolteProvisioned(isProvisioned);
4720 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4721 ims.setWfcProvisioned(isProvisioned);
4722 }
4723 break;
4724 }
4725 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4726 // There is currently no difference in VT provisioning type.
4727 ims.setVtProvisioned(isProvisioned);
4728 break;
4729 }
4730 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4731 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4732 // change the capability of the feature instead if needed.
4733 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4734 == isProvisioned) {
4735 // No change in provisioning.
4736 return;
4737 }
4738 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4739 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004740 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004741 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004742 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4743 + ", Exception" + e.getMessage());
4744 }
4745 break;
4746 }
4747 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004748 throw new IllegalArgumentException("Tried to set provisioning for "
4749 + "MmTel capability '" + capability + "', which does not require "
4750 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004751 }
4752 }
4753
4754 } finally {
4755 Binder.restoreCallingIdentity(identity);
4756 }
4757 }
4758
4759 @Override
4760 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4761 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004762 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4763 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4764 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004765 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4766 }
4767 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4768 final long identity = Binder.clearCallingIdentity();
4769 try {
4770 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004771 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004772 return true;
4773 }
4774
Brad Ebinger0d79c572021-04-17 15:20:49 -07004775 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4776 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4777 loge("getImsProvisioningStatusForCapability: called for technology that does "
4778 + "not support provisioning - " + tech);
4779 return true;
4780 }
4781
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004782 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4783 switch (capability) {
4784 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4785 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4786 return ims.isVolteProvisionedOnDevice();
4787 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4788 return ims.isWfcProvisionedOnDevice();
4789 }
4790 // This should never happen, since we are checking tech above to make sure it
4791 // is either LTE or IWLAN.
4792 throw new IllegalArgumentException("Invalid radio technology for voice "
4793 + "capability.");
4794 }
4795 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4796 // There is currently no difference in VT provisioning type.
4797 return ims.isVtProvisionedOnDevice();
4798 }
4799 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4800 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4801 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4802 }
4803 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004804 throw new IllegalArgumentException(
4805 "Tried to get provisioning for MmTel capability '" + capability
4806 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004807 }
4808 }
4809
4810 } finally {
4811 Binder.restoreCallingIdentity(identity);
4812 }
4813 }
4814
4815 @Override
4816 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4817 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4818 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4819 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4820 }
4821 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4822 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4823 return (provisionedBits & capability) > 0;
4824 }
4825
4826 @Override
4827 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4828 boolean isProvisioned) {
4829 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4830 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4831 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4832 }
4833 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4834 "setProvisioningStatusForCapability");
4835 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4836 // If the current provisioning status for capability already matches isProvisioned,
4837 // do nothing.
4838 if (((provisionedBits & capability) > 0) == isProvisioned) {
4839 return;
4840 }
4841 if (isProvisioned) {
4842 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4843 } else {
4844 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4845 }
4846 }
4847
4848 /**
4849 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4850 * technology. The bitfield should mirror the bitfield defined by
4851 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4852 */
4853 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4854 String key = getMmTelProvisioningKey(subId, tech);
4855 // Default is no capabilities are provisioned.
4856 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4857 }
4858
4859 /**
4860 * Sets the MmTel capability provisioning bitfield (defined by
4861 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4862 * technology specified.
4863 *
4864 * Note: This is a synchronous command and should not be called on UI thread.
4865 */
4866 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4867 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4868 String key = getMmTelProvisioningKey(subId, tech);
4869 editor.putInt(key, newField);
4870 editor.commit();
4871 }
4872
4873 private static String getMmTelProvisioningKey(int subId, int tech) {
4874 // resulting key is provision_ims_mmtel_{subId}_{tech}
4875 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4876 }
4877
4878 /**
4879 * Query CarrierConfig to see if the specified capability requires provisioning for the
4880 * carrier associated with the subscription id.
4881 */
4882 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4883 int capability) {
4884 CarrierConfigManager configManager = new CarrierConfigManager(context);
4885 PersistableBundle c = configManager.getConfigForSubId(subId);
4886 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004887 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004888 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4889 false);
4890 boolean requireVoiceVtProvisioning = c.getBoolean(
4891 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4892
4893 // First check to make sure that the capability requires provisioning.
4894 switch (capability) {
4895 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4896 // intentional fallthrough
4897 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4898 if (requireVoiceVtProvisioning) {
4899 // Voice and Video requires provisioning
4900 return true;
4901 }
4902 break;
4903 }
4904 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4905 if (requireUtProvisioning) {
4906 // UT requires provisioning
4907 return true;
4908 }
4909 break;
4910 }
4911 }
4912 return false;
4913 }
4914
allenwtsu99c623b2020-01-03 18:24:23 +08004915 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4916 int capability) {
4917 CarrierConfigManager configManager = new CarrierConfigManager(context);
4918 PersistableBundle c = configManager.getConfigForSubId(subId);
4919
4920 boolean requireRcsProvisioning = c.getBoolean(
4921 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4922
4923 // First check to make sure that the capability requires provisioning.
4924 switch (capability) {
4925 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4926 // intentional fallthrough
4927 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4928 if (requireRcsProvisioning) {
4929 // OPTION or PRESENCE requires provisioning
4930 return true;
4931 }
4932 break;
4933 }
4934 }
4935 return false;
4936 }
4937
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004938 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004939 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004940 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4941 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4942 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004943 enforceReadPrivilegedPermission("getImsProvisioningInt");
4944 final long identity = Binder.clearCallingIdentity();
4945 try {
4946 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004947 int slotId = getSlotIndex(subId);
4948 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4949 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4950 + subId + "' for key:" + key);
4951 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4952 }
calvinpanb5a34062021-02-08 19:59:36 +08004953 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004954 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004955 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4956 + subId + "' for key:" + key);
4957 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004958 } finally {
4959 Binder.restoreCallingIdentity(identity);
4960 }
4961 }
4962
4963 @Override
4964 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004965 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4966 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4967 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004968 enforceReadPrivilegedPermission("getImsProvisioningString");
4969 final long identity = Binder.clearCallingIdentity();
4970 try {
4971 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004972 int slotId = getSlotIndex(subId);
4973 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4974 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4975 + subId + "' for key:" + key);
4976 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4977 }
calvinpanb5a34062021-02-08 19:59:36 +08004978 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004979 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004980 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4981 + subId + "' for key:" + key);
4982 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004983 } finally {
4984 Binder.restoreCallingIdentity(identity);
4985 }
4986 }
4987
4988 @Override
4989 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004990 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4991 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4992 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004993 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4994 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004995 final long identity = Binder.clearCallingIdentity();
4996 try {
4997 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004998 int slotId = getSlotIndex(subId);
4999 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5000 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5001 + subId + "' for key:" + key);
5002 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5003 }
calvinpanb5a34062021-02-08 19:59:36 +08005004 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5005 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005006 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005007 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005008 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005009 } finally {
5010 Binder.restoreCallingIdentity(identity);
5011 }
5012 }
5013
5014 @Override
5015 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005016 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5017 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5018 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005019 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5020 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005021 final long identity = Binder.clearCallingIdentity();
5022 try {
5023 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005024 int slotId = getSlotIndex(subId);
5025 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5026 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5027 + subId + "' for key:" + key);
5028 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5029 }
calvinpanb5a34062021-02-08 19:59:36 +08005030 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5031 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005032 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005033 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005034 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005035 } finally {
5036 Binder.restoreCallingIdentity(identity);
5037 }
5038 }
5039
Brad Ebinger919631e2021-06-02 17:46:35 -07005040 /**
5041 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5042 * for the given slot ID or no ImsResolver instance has been created.
5043 * @param slotId The slot ID that the IMS service is created for.
5044 * @throws ImsException If there is no ImsService configured for this slot.
5045 */
5046 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5047 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5048 ImsFeature.FEATURE_MMTEL)) {
5049 throw new ImsException("This subscription does not support MMTEL over IMS",
5050 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5051 }
5052 }
5053
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005054 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005055 int slotId = SubscriptionManager.getSlotIndex(subId);
5056 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005057 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5058 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005059 }
5060 return slotId;
5061 }
5062
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005063 private int getSlotIndex(int subId) {
5064 int slotId = SubscriptionManager.getSlotIndex(subId);
5065 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5066 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5067 }
5068 return slotId;
5069 }
5070
Wink Saville36469e72014-06-11 15:17:00 -07005071 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005072 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005073 */
5074 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005075 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5076 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005077 try {
5078 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5079 } catch (SecurityException se) {
5080 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5081 throw new SecurityException("Package " + callingPackage + " does not belong to "
5082 + Binder.getCallingUid());
5083 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005084 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005085 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005086 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005087 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005088 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005089 mApp, subId, callingPackage, callingFeatureId,
5090 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005091 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5092 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005093
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005094 final long identity = Binder.clearCallingIdentity();
5095 try {
5096 final Phone phone = getPhone(subId);
5097 if (phone != null) {
5098 return phone.getServiceState().getDataNetworkType();
5099 } else {
5100 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5101 }
5102 } finally {
5103 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005104 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005105 }
5106
5107 /**
5108 * Returns the data network type
5109 */
5110 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005111 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005112 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5113 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005114 }
5115
5116 /**
5117 * Returns the data network type for a subId
5118 */
5119 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005120 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5121 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005122 String functionName = "getDataNetworkTypeForSubscriber";
5123 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5124 mApp, functionName)) {
5125 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5126 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5127 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5128 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005129 }
5130
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005131 final long identity = Binder.clearCallingIdentity();
5132 try {
5133 final Phone phone = getPhone(subId);
5134 if (phone != null) {
5135 return phone.getServiceState().getDataNetworkType();
5136 } else {
5137 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5138 }
5139 } finally {
5140 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005141 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005142 }
5143
5144 /**
Wink Saville36469e72014-06-11 15:17:00 -07005145 * Returns the Voice network type for a subId
5146 */
5147 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005148 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5149 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005150 String functionName = "getVoiceNetworkTypeForSubscriber";
5151 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5152 mApp, functionName)) {
5153 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5154 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5155 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5156 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005157 }
5158
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005159 final long identity = Binder.clearCallingIdentity();
5160 try {
5161 final Phone phone = getPhone(subId);
5162 if (phone != null) {
5163 return phone.getServiceState().getVoiceNetworkType();
5164 } else {
5165 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5166 }
5167 } finally {
5168 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005169 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005170 }
5171
5172 /**
5173 * @return true if a ICC card is present
5174 */
5175 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005176 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005177 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5178 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005179 }
5180
5181 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005182 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005183 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005184 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005185 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005186 final long identity = Binder.clearCallingIdentity();
5187 try {
5188 final Phone phone = PhoneFactory.getPhone(slotIndex);
5189 if (phone != null) {
5190 return phone.getIccCard().hasIccCard();
5191 } else {
5192 return false;
5193 }
5194 } finally {
5195 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005196 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005197 }
5198
5199 /**
5200 * Return if the current radio is LTE on CDMA. This
5201 * is a tri-state return value as for a period of time
5202 * the mode may be unknown.
5203 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005204 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005205 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005206 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005207 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005208 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005209 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5210 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5211 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005212 }
5213
Sanket Padawe356d7632015-06-22 14:03:32 -07005214 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005215 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5216 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005217 try {
5218 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5219 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005220 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5221 }
5222
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005223 final long identity = Binder.clearCallingIdentity();
5224 try {
5225 final Phone phone = getPhone(subId);
5226 if (phone == null) {
5227 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5228 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005229 return TelephonyProperties.lte_on_cdma_device()
5230 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005231 }
5232 } finally {
5233 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005234 }
Wink Saville36469e72014-06-11 15:17:00 -07005235 }
5236
Wink Saville36469e72014-06-11 15:17:00 -07005237 /**
5238 * {@hide}
5239 * Returns Default subId, 0 in the case of single standby.
5240 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005241 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005242 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005243 }
5244
Shishir Agrawala9f32182016-04-12 12:00:16 -07005245 private int getSlotForDefaultSubscription() {
5246 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5247 }
5248
Wink Savilleb564aae2014-10-23 10:18:09 -07005249 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005250 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005251 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005252
Pengquan Menge92a50d2018-09-21 15:54:48 -07005253 private boolean isActiveSubscription(int subId) {
5254 return mSubscriptionController.isActiveSubId(subId);
5255 }
5256
Ihab Awadf2177b72013-11-25 13:33:23 -08005257 /**
5258 * @see android.telephony.TelephonyManager.WifiCallingChoices
5259 */
5260 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005261 final long identity = Binder.clearCallingIdentity();
5262 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005263 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005264 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5265 getWhenToMakeWifiCallsDefaultPreference());
5266 } finally {
5267 Binder.restoreCallingIdentity(identity);
5268 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005269 }
5270
5271 /**
5272 * @see android.telephony.TelephonyManager.WifiCallingChoices
5273 */
5274 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005275 final long identity = Binder.clearCallingIdentity();
5276 try {
5277 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005278 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005279 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5280 } finally {
5281 Binder.restoreCallingIdentity(identity);
5282 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005283 }
5284
Sailesh Nepald1e68152013-12-12 19:08:02 -08005285 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005286 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005287 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005288 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005289
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005290 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5291 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5292 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005293 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005294 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5295 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005296 }
5297 return PhoneFactory.getPhone(phoneId);
5298 }
5299
Shishir Agrawal566b7612013-10-28 14:41:00 -07005300 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005301 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005302 @NonNull IccLogicalChannelRequest request) {
5303 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5304 /*message=*/ "iccOpenLogicalChannel");
5305
5306 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5307 // Verify that the callingPackage in the request belongs to the calling UID
5308 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5309
5310 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005311 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005312
Rambo Wanga1782702021-11-10 20:15:19 -08005313 private Phone getPhoneFromValidIccLogicalChannelRequest(
5314 @NonNull IccLogicalChannelRequest request, String message) {
5315 Phone phone;
5316 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5317 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5318 mApp, request.subId, message);
5319 phone = getPhoneFromSubId(request.subId);
5320 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5321 enforceModifyPermission();
5322 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5323 } else {
5324 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005325 }
Rambo Wanga1782702021-11-10 20:15:19 -08005326 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005327 }
5328
5329 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005330 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005331 final long identity = Binder.clearCallingIdentity();
5332 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005333 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005334 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005335 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5336 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005337 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5338 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005339 loge("The calling package is not allowed to access ISD-R.");
5340 throw new SecurityException(
5341 "The calling package is not allowed to access ISD-R.");
5342 }
Derek Tan740e1672017-06-27 14:56:27 -07005343 }
Derek Tan740e1672017-06-27 14:56:27 -07005344
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005345 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005346 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5347 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005348 return response;
5349 } finally {
5350 Binder.restoreCallingIdentity(identity);
5351 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005352 }
5353
5354 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005355 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5356 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5357 /*message=*/"iccCloseLogicalChannel");
5358
5359 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5360
5361 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005362 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005363
Rambo Wanga1782702021-11-10 20:15:19 -08005364 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5365 IccLogicalChannelRequest request) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005366 final long identity = Binder.clearCallingIdentity();
5367 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005368 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005369 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005370 }
Rambo Wanga1782702021-11-10 20:15:19 -08005371 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005372 null /* workSource */);
Rambo Wanga1782702021-11-10 20:15:19 -08005373 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005374 return success;
5375 } finally {
5376 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005377 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005378 }
5379
5380 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005381 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005382 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005383 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5384 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005385 if (DBG) {
5386 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5387 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5388 + p3 + " data=" + data);
5389 }
5390 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5391 command, p1, p2, p3, data);
5392 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005393
Jordan Liu4c733742019-02-28 12:03:40 -08005394 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005395 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5396 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005397 enforceModifyPermission();
5398 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005399 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5400 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5401 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005402 }
5403 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005404 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5405 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005406 }
5407
5408 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5409 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005410 final long identity = Binder.clearCallingIdentity();
5411 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005412 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005413 return "";
5414 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005415
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005416 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005417 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5418 null /* workSource */);
5419 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005420
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005421 // Append the returned status code to the end of the response payload.
5422 String s = Integer.toHexString(
5423 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5424 if (response.payload != null) {
5425 s = IccUtils.bytesToHexString(response.payload) + s;
5426 }
5427 return s;
5428 } finally {
5429 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005430 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005431 }
Jake Hambye994d462014-02-03 13:10:13 -08005432
Evan Charltonc66da362014-05-16 14:06:40 -07005433 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005434 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5435 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005436 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5437 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005438 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005439 if (DBG) {
5440 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5441 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5442 }
5443 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5444 cla, command, p1, p2, p3, data);
5445 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005446
Jordan Liu4c733742019-02-28 12:03:40 -08005447 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005448 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5449 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005450 enforceModifyPermission();
5451 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5452 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005453 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5454 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5455 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005456 }
5457
5458 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005459 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5460 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005461 }
5462
5463 // open APDU basic channel assuming the caller has sufficient permissions
5464 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5465 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005466 final long identity = Binder.clearCallingIdentity();
5467 try {
5468 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5469 && TextUtils.equals(ISDR_AID, data)) {
5470 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005471 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5472 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005473 if (bestComponent == null
5474 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5475 loge("The calling package is not allowed to select ISD-R.");
5476 throw new SecurityException(
5477 "The calling package is not allowed to select ISD-R.");
5478 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005479 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005480
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005481 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005482 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5483 null /* workSource */);
5484 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005485
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005486 // Append the returned status code to the end of the response payload.
5487 String s = Integer.toHexString(
5488 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5489 if (response.payload != null) {
5490 s = IccUtils.bytesToHexString(response.payload) + s;
5491 }
5492 return s;
5493 } finally {
5494 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005495 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005496 }
5497
5498 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005499 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005500 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005501 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5502 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005503
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005504 final long identity = Binder.clearCallingIdentity();
5505 try {
5506 if (DBG) {
5507 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5508 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5509 }
5510
5511 IccIoResult response =
5512 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5513 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5514 subId);
5515
5516 if (DBG) {
5517 log("Exchange SIM_IO [R]" + response);
5518 }
5519
5520 byte[] result = null;
5521 int length = 2;
5522 if (response.payload != null) {
5523 length = 2 + response.payload.length;
5524 result = new byte[length];
5525 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5526 } else {
5527 result = new byte[length];
5528 }
5529
5530 result[length - 1] = (byte) response.sw2;
5531 result[length - 2] = (byte) response.sw1;
5532 return result;
5533 } finally {
5534 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005535 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005536 }
5537
Nathan Haroldb3014052017-01-25 15:57:32 -08005538 /**
5539 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5540 * on a particular subscription
5541 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005542 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5543 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005544 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005545 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005546 return null;
5547 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005548
5549 final long identity = Binder.clearCallingIdentity();
5550 try {
5551 if (appType != TelephonyManager.APPTYPE_USIM
5552 && appType != TelephonyManager.APPTYPE_SIM) {
5553 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5554 return null;
5555 }
5556 Object response = sendRequest(
5557 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5558 if (response instanceof String[]) {
5559 return (String[]) response;
5560 }
yincheng zhao2737e882019-09-06 17:06:54 -07005561 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005562 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005563 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005564 } finally {
5565 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005566 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005567 }
5568
yincheng zhao2737e882019-09-06 17:06:54 -07005569 /**
5570 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5571 * subscription.
5572 *
5573 * @param subId the id of the subscription.
5574 * @param appType the uicc app type, must be USIM or SIM.
5575 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5576 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005577 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005578 * @return number of fplmns that is successfully written to the SIM.
5579 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005580 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5581 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005582 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5583 mApp, subId, "setForbiddenPlmns");
5584
yincheng zhao2737e882019-09-06 17:06:54 -07005585 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5586 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5587 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5588 }
5589 if (fplmns == null) {
5590 throw new IllegalArgumentException("Fplmn List provided is null");
5591 }
5592 for (String fplmn : fplmns) {
5593 if (!CellIdentity.isValidPlmn(fplmn)) {
5594 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5595 }
5596 }
5597 final long identity = Binder.clearCallingIdentity();
5598 try {
5599 Object response = sendRequest(
5600 CMD_SET_FORBIDDEN_PLMNS,
5601 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5602 subId);
5603 return (int) response;
5604 } finally {
5605 Binder.restoreCallingIdentity(identity);
5606 }
5607 }
5608
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005609 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005610 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005611 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5612 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005613
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005614 final long identity = Binder.clearCallingIdentity();
5615 try {
5616 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5617 if (response.payload == null) {
5618 return "";
5619 }
Evan Charltonc66da362014-05-16 14:06:40 -07005620
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005621 // Append the returned status code to the end of the response payload.
5622 String s = Integer.toHexString(
5623 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5624 s = IccUtils.bytesToHexString(response.payload) + s;
5625 return s;
5626 } finally {
5627 Binder.restoreCallingIdentity(identity);
5628 }
Evan Charltonc66da362014-05-16 14:06:40 -07005629 }
5630
Jake Hambye994d462014-02-03 13:10:13 -08005631 /**
5632 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5633 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5634 *
5635 * @param itemID the ID of the item to read
5636 * @return the NV item as a String, or null on error.
5637 */
5638 @Override
5639 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005640 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005641 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5642 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005643
5644 final long identity = Binder.clearCallingIdentity();
5645 try {
5646 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005647 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005648 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5649 return value;
5650 } finally {
5651 Binder.restoreCallingIdentity(identity);
5652 }
Jake Hambye994d462014-02-03 13:10:13 -08005653 }
5654
5655 /**
5656 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5657 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5658 *
5659 * @param itemID the ID of the item to read
5660 * @param itemValue the value to write, as a String
5661 * @return true on success; false on any failure
5662 */
5663 @Override
5664 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005665 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005666 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5667 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005668
5669 final long identity = Binder.clearCallingIdentity();
5670 try {
5671 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5672 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005673 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005674 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5675 return success;
5676 } finally {
5677 Binder.restoreCallingIdentity(identity);
5678 }
Jake Hambye994d462014-02-03 13:10:13 -08005679 }
5680
5681 /**
5682 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5683 * Used for device configuration by some CDMA operators.
5684 *
5685 * @param preferredRoamingList byte array containing the new PRL
5686 * @return true on success; false on any failure
5687 */
5688 @Override
5689 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005690 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5691 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005692
5693 final long identity = Binder.clearCallingIdentity();
5694 try {
5695 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5696 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5697 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5698 return success;
5699 } finally {
5700 Binder.restoreCallingIdentity(identity);
5701 }
Jake Hambye994d462014-02-03 13:10:13 -08005702 }
5703
5704 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005705 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005706 * Used for device configuration by some CDMA operators.
5707 *
chen xu6dac5ab2018-10-26 17:39:23 -07005708 * @param slotIndex - device slot.
5709 *
Jake Hambye994d462014-02-03 13:10:13 -08005710 * @return true on success; false on any failure
5711 */
5712 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005713 public boolean resetModemConfig(int slotIndex) {
5714 Phone phone = PhoneFactory.getPhone(slotIndex);
5715 if (phone != null) {
5716 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5717 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005718
chen xu6dac5ab2018-10-26 17:39:23 -07005719 final long identity = Binder.clearCallingIdentity();
5720 try {
5721 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5722 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5723 return success;
5724 } finally {
5725 Binder.restoreCallingIdentity(identity);
5726 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005727 }
chen xu6dac5ab2018-10-26 17:39:23 -07005728 return false;
5729 }
5730
5731 /**
5732 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5733 *
5734 * @param slotIndex - device slot.
5735 *
5736 * @return true on success; false on any failure
5737 */
5738 @Override
5739 public boolean rebootModem(int slotIndex) {
5740 Phone phone = PhoneFactory.getPhone(slotIndex);
5741 if (phone != null) {
5742 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5743 mApp, phone.getSubId(), "rebootModem");
5744
5745 final long identity = Binder.clearCallingIdentity();
5746 try {
5747 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5748 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5749 return success;
5750 } finally {
5751 Binder.restoreCallingIdentity(identity);
5752 }
5753 }
5754 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005755 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005756
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005757 public String[] getPcscfAddress(String apnType, String callingPackage,
5758 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005759 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005760 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5761 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005762 return new String[0];
5763 }
5764
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005765 final long identity = Binder.clearCallingIdentity();
5766 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005767 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005768 } finally {
5769 Binder.restoreCallingIdentity(identity);
5770 }
Wink Saville36469e72014-06-11 15:17:00 -07005771 }
5772
Brad Ebinger51f743a2017-01-23 13:50:20 -08005773 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005774 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5775 * {@link #disableIms(int)}.
5776 * @param slotIndex device slot.
5777 */
5778 public void resetIms(int slotIndex) {
5779 enforceModifyPermission();
5780
5781 final long identity = Binder.clearCallingIdentity();
5782 try {
5783 if (mImsResolver == null) {
5784 // may happen if the does not support IMS.
5785 return;
5786 }
5787 mImsResolver.disableIms(slotIndex);
5788 mImsResolver.enableIms(slotIndex);
5789 } finally {
5790 Binder.restoreCallingIdentity(identity);
5791 }
5792 }
5793
5794 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005795 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5796 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005797 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005798 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005799 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005800
5801 final long identity = Binder.clearCallingIdentity();
5802 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005803 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005804 // may happen if the device does not support IMS.
5805 return;
5806 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005807 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005808 } finally {
5809 Binder.restoreCallingIdentity(identity);
5810 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005811 }
5812
5813 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005814 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5815 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005816 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005817 public void disableIms(int slotId) {
5818 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005819
5820 final long identity = Binder.clearCallingIdentity();
5821 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005822 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005823 // may happen if the device does not support IMS.
5824 return;
5825 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005826 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005827 } finally {
5828 Binder.restoreCallingIdentity(identity);
5829 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005830 }
5831
5832 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005833 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5834 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005835 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005836 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005837 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005838 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005839
5840 final long identity = Binder.clearCallingIdentity();
5841 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005842 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005843 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5844 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005845 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005846 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005847 } finally {
5848 Binder.restoreCallingIdentity(identity);
5849 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005850 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005851 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005852 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5853 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005854 @Override
5855 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005856 enforceModifyPermission();
5857
5858 final long identity = Binder.clearCallingIdentity();
5859 try {
5860 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005861 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005862 } finally {
5863 Binder.restoreCallingIdentity(identity);
5864 }
5865 }
5866
5867 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005868 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005869 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005870 */
5871 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5872 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005873
5874 final long identity = Binder.clearCallingIdentity();
5875 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005876 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005877 // may happen if the device does not support IMS.
5878 return null;
5879 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005880 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005881 } finally {
5882 Binder.restoreCallingIdentity(identity);
5883 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005884 }
5885
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005886 /**
5887 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005888 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005889 */
5890 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5891 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005892
5893 final long identity = Binder.clearCallingIdentity();
5894 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005895 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005896 // may happen if the device does not support IMS.
5897 return null;
5898 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005899 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005900 } finally {
5901 Binder.restoreCallingIdentity(identity);
5902 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005903 }
5904
Brad Ebinger884c07b2018-02-15 16:17:40 -08005905 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005906 * Sets the ImsService Package Name that Telephony will bind to.
5907 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005908 * @param slotIndex the slot ID that the ImsService should bind for.
5909 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005910 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005911 * @param featureTypes An integer array of feature types associated with a packageName.
5912 * @param packageName The name of the package that the current configuration will be replaced
5913 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005914 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005915 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005916 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5917 int[] featureTypes, String packageName) {
5918 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5919 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005920 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5921 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005922 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005923
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005924 final long identity = Binder.clearCallingIdentity();
5925 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005926 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005927 // may happen if the device does not support IMS.
5928 return false;
5929 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005930 Map<Integer, String> featureConfig = new HashMap<>();
5931 for (int featureType : featureTypes) {
5932 featureConfig.put(featureType, packageName);
5933 }
5934 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5935 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005936 } finally {
5937 Binder.restoreCallingIdentity(identity);
5938 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005939 }
5940
5941 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005942 * Clears any carrier ImsService overrides for the slot index specified that were previously
5943 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5944 *
5945 * This should only be used for testing.
5946 *
5947 * @param slotIndex the slot ID that the ImsService should bind for.
5948 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5949 */
5950 @Override
5951 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5952 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5953 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5954 "clearCarrierImsServiceOverride");
5955 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5956 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5957 "clearCarrierImsServiceOverride");
5958
5959 final long identity = Binder.clearCallingIdentity();
5960 try {
5961 if (mImsResolver == null) {
5962 // may happen if the device does not support IMS.
5963 return false;
5964 }
5965 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5966 } finally {
5967 Binder.restoreCallingIdentity(identity);
5968 }
5969 }
5970
5971 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005972 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005973 *
5974 * @param slotId The slot that the ImsService is associated with.
5975 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5976 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005977 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005978 * @return the package name of the ImsService configuration.
5979 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005980 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5981 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005982 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005983 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005984 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005985 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5986 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005987
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005988 final long identity = Binder.clearCallingIdentity();
5989 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005990 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005991 // may happen if the device does not support IMS.
5992 return "";
5993 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005994 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005995 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5996 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005997 } finally {
5998 Binder.restoreCallingIdentity(identity);
5999 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006000 }
6001
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006002 /**
6003 * Get the MmTelFeature state associated with the requested subscription id.
6004 * @param subId The subscription that the MmTelFeature is associated with.
6005 * @param callback A callback with an integer containing the
6006 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6007 */
6008 @Override
6009 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6010 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
6011 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6012 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6013 "IMS not available on device.");
6014 }
6015 final long token = Binder.clearCallingIdentity();
6016 try {
6017 int slotId = getSlotIndex(subId);
6018 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6019 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6020 + subId + "'");
6021 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6022 }
Brad Ebinger919631e2021-06-02 17:46:35 -07006023 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006024 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6025 try {
6026 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6027 } catch (RemoteException e) {
6028 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6029 + "Ignore");
6030 }
6031 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006032 } catch (ImsException e) {
6033 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006034 } finally {
6035 Binder.restoreCallingIdentity(token);
6036 }
6037 }
6038
Daniel Brightbb5840b2021-01-12 15:48:18 -08006039 /**
6040 * Sets the ims registration state on all valid {@link Phone}s.
6041 */
6042 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006043 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006044
6045 final long identity = Binder.clearCallingIdentity();
6046 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006047 // NOTE: Before S, this method only set the default phone.
6048 for (final Phone phone : PhoneFactory.getPhones()) {
6049 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6050 phone.setImsRegistrationState(registered);
6051 }
6052 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006053 } finally {
6054 Binder.restoreCallingIdentity(identity);
6055 }
Wink Saville36469e72014-06-11 15:17:00 -07006056 }
6057
6058 /**
Stuart Scott54788802015-03-30 13:18:01 -07006059 * Set the network selection mode to automatic.
6060 *
6061 */
6062 @Override
6063 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006064 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6065 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006066
6067 final long identity = Binder.clearCallingIdentity();
6068 try {
shilufc958392020-01-20 11:36:01 -08006069 if (!isActiveSubscription(subId)) {
6070 return;
6071 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006072 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006073 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6074 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006075 } finally {
6076 Binder.restoreCallingIdentity(identity);
6077 }
Stuart Scott54788802015-03-30 13:18:01 -07006078 }
6079
Jack Yud10cdd42020-09-28 20:28:01 -07006080 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006081 * Ask the radio to connect to the input network and change selection mode to manual.
6082 *
6083 * @param subId the id of the subscription.
6084 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6085 * the operator to attach to.
6086 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6087 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6088 * normal network selection next time.
6089 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006090 */
6091 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006092 public boolean setNetworkSelectionModeManual(
6093 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006094 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6095 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006096
6097 if (!isActiveSubscription(subId)) {
6098 return false;
6099 }
6100
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006101 final long identity = Binder.clearCallingIdentity();
6102 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006103 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006104 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006105 if (DBG) {
6106 log("setNetworkSelectionModeManual: subId: " + subId
6107 + " operator: " + operatorInfo);
6108 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006109 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6110 } finally {
6111 Binder.restoreCallingIdentity(identity);
6112 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006113 }
shilu84f6e8b2019-12-19 13:58:01 -08006114 /**
6115 * Get the manual network selection
6116 *
6117 * @param subId the id of the subscription.
6118 *
6119 * @return the previously saved user selected PLMN
6120 */
6121 @Override
6122 public String getManualNetworkSelectionPlmn(int subId) {
6123 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006124 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006125 mApp, subId, "getManualNetworkSelectionPlmn");
6126
6127 final long identity = Binder.clearCallingIdentity();
6128 try {
6129 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006130 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006131 }
6132
6133 final Phone phone = getPhone(subId);
6134 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006135 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006136 }
6137 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6138 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6139 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6140 } finally {
6141 Binder.restoreCallingIdentity(identity);
6142 }
6143 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006144
6145 /**
6146 * Scans for available networks.
6147 */
6148 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006149 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6150 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006151 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6152 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006153 LocationAccessPolicy.LocationPermissionResult locationResult =
6154 LocationAccessPolicy.checkLocationPermission(mApp,
6155 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6156 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006157 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006158 .setCallingPid(Binder.getCallingPid())
6159 .setCallingUid(Binder.getCallingUid())
6160 .setMethod("getCellNetworkScanResults")
6161 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006162 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6163 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006164 .build());
6165 switch (locationResult) {
6166 case DENIED_HARD:
6167 throw new SecurityException("Not allowed to access scan results -- location");
6168 case DENIED_SOFT:
6169 return null;
6170 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006171
Pengquan Menga1bb6272018-09-06 09:59:22 -07006172 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006173 try {
6174 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006175 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006176 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006177 } finally {
6178 Binder.restoreCallingIdentity(identity);
6179 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006180 }
6181
6182 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006183 * Get the call forwarding info, given the call forwarding reason.
6184 */
6185 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006186 public void getCallForwarding(int subId, int callForwardingReason,
6187 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006188 enforceReadPrivilegedPermission("getCallForwarding");
6189 long identity = Binder.clearCallingIdentity();
6190 try {
6191 if (DBG) {
6192 log("getCallForwarding: subId " + subId
6193 + " callForwardingReason" + callForwardingReason);
6194 }
Hall Liu27d24262020-09-18 19:04:59 -07006195
6196 Phone phone = getPhone(subId);
6197 if (phone == null) {
6198 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006199 callback.onError(
6200 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006201 } catch (RemoteException e) {
6202 // ignore
6203 }
6204 return;
6205 }
6206
6207 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6208 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6209 @Override
6210 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6211 try {
6212 callback.onCallForwardingInfoAvailable(info);
6213 } catch (RemoteException e) {
6214 // ignore
6215 }
6216 }
6217
6218 @Override
6219 public void onError(int error) {
6220 try {
6221 callback.onError(error);
6222 } catch (RemoteException e) {
6223 // ignore
6224 }
6225 }
6226 });
6227 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006228 } finally {
6229 Binder.restoreCallingIdentity(identity);
6230 }
6231 }
6232
6233 /**
6234 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6235 * reason, the number to forward, and the timeout before the forwarding is attempted.
6236 */
6237 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006238 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6239 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006240 enforceModifyPermission();
6241 long identity = Binder.clearCallingIdentity();
6242 try {
6243 if (DBG) {
6244 log("setCallForwarding: subId " + subId
6245 + " callForwardingInfo" + callForwardingInfo);
6246 }
Hall Liu27d24262020-09-18 19:04:59 -07006247
6248 Phone phone = getPhone(subId);
6249 if (phone == null) {
6250 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006251 callback.accept(
6252 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006253 } catch (RemoteException e) {
6254 // ignore
6255 }
6256 return;
6257 }
6258
6259 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6260 FunctionalUtils.ignoreRemoteException(callback::accept));
6261
6262 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006263 } finally {
6264 Binder.restoreCallingIdentity(identity);
6265 }
6266 }
6267
6268 /**
Hall Liu27d24262020-09-18 19:04:59 -07006269 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006270 */
6271 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006272 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006273 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006274 long identity = Binder.clearCallingIdentity();
6275 try {
Hall Liu27d24262020-09-18 19:04:59 -07006276 Phone phone = getPhone(subId);
6277 if (phone == null) {
6278 try {
6279 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6280 } catch (RemoteException e) {
6281 // ignore
6282 }
6283 return;
6284 }
SongFerngWang0e767992021-03-31 22:08:45 +08006285 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6286 PersistableBundle c = configManager.getConfigForSubId(subId);
6287 boolean requireUssd = c.getBoolean(
6288 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006289
Shuo Qian4a594052020-01-23 11:59:30 -08006290 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006291 if (requireUssd) {
6292 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6293 getSubscriptionCarrierId(subId));
6294 String newUssdCommand = "";
6295 try {
6296 newUssdCommand = carrierXmlParser.getFeature(
6297 CarrierXmlParser.FEATURE_CALL_WAITING)
6298 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6299 } catch (NullPointerException e) {
6300 loge("Failed to generate USSD number" + e);
6301 }
6302 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6303 mMainThreadHandler, callback, carrierXmlParser,
6304 CarrierXmlParser.SsEntry.SSAction.QUERY);
6305 final String ussdCommand = newUssdCommand;
6306 Executors.newSingleThreadExecutor().execute(() -> {
6307 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6308 });
6309 } else {
6310 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6311 callback::accept);
6312 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6313 }
Shuo Qian4a594052020-01-23 11:59:30 -08006314 } finally {
6315 Binder.restoreCallingIdentity(identity);
6316 }
6317 }
6318
6319 /**
Hall Liu27d24262020-09-18 19:04:59 -07006320 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006321 */
6322 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006323 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006324 enforceModifyPermission();
6325 long identity = Binder.clearCallingIdentity();
6326 try {
Hall Liu27d24262020-09-18 19:04:59 -07006327 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6328
6329 Phone phone = getPhone(subId);
6330 if (phone == null) {
6331 try {
6332 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6333 } catch (RemoteException e) {
6334 // ignore
6335 }
6336 return;
6337 }
6338
SongFerngWang0e767992021-03-31 22:08:45 +08006339 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6340 PersistableBundle c = configManager.getConfigForSubId(subId);
6341 boolean requireUssd = c.getBoolean(
6342 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006343
SongFerngWang0e767992021-03-31 22:08:45 +08006344 if (DBG) log("getCallWaitingStatus: subId " + subId);
6345 if (requireUssd) {
6346 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6347 getSubscriptionCarrierId(subId));
6348 CarrierXmlParser.SsEntry.SSAction ssAction =
6349 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6350 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6351 String newUssdCommand = "";
6352 try {
6353 newUssdCommand = carrierXmlParser.getFeature(
6354 CarrierXmlParser.FEATURE_CALL_WAITING)
6355 .makeCommand(ssAction, null);
6356 } catch (NullPointerException e) {
6357 loge("Failed to generate USSD number" + e);
6358 }
6359 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6360 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6361 final String ussdCommand = newUssdCommand;
6362 Executors.newSingleThreadExecutor().execute(() -> {
6363 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6364 });
6365 } else {
6366 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6367 FunctionalUtils.ignoreRemoteException(callback::accept));
6368
6369 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6370 }
Shuo Qian4a594052020-01-23 11:59:30 -08006371 } finally {
6372 Binder.restoreCallingIdentity(identity);
6373 }
6374 }
6375
6376 /**
yinxub1bed742017-04-17 11:45:04 -07006377 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006378 *
yinxub1bed742017-04-17 11:45:04 -07006379 * @param subId id of the subscription
6380 * @param request contains the radio access networks with bands/channels to scan
6381 * @param messenger callback messenger for scan results or errors
6382 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006383 * @return the id of the requested scan which can be used to stop the scan.
6384 */
6385 @Override
6386 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006387 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006388 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6389 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006390 LocationAccessPolicy.LocationPermissionResult locationResult =
6391 LocationAccessPolicy.checkLocationPermission(mApp,
6392 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6393 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006394 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006395 .setCallingPid(Binder.getCallingPid())
6396 .setCallingUid(Binder.getCallingUid())
6397 .setMethod("requestNetworkScan")
6398 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006399 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6400 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006401 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006402 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006403 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6404 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006405 if (e != null) {
6406 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6407 throw e;
6408 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006409 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006410 return TelephonyScanManager.INVALID_SCAN_ID;
6411 }
6412 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006413 }
Hall Liu912dfd32019-04-25 14:02:26 -07006414 int callingUid = Binder.getCallingUid();
6415 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006416 final long identity = Binder.clearCallingIdentity();
6417 try {
6418 return mNetworkScanRequestTracker.startNetworkScan(
6419 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006420 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006421 } finally {
6422 Binder.restoreCallingIdentity(identity);
6423 }
yinxu504e1392017-04-12 16:03:22 -07006424 }
6425
Hall Liub2ac8ef2019-02-28 15:56:23 -08006426 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006427 NetworkScanRequest request, int subId, String callingPackage) {
6428 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006429 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6430 boolean hasNetworkScanPermission =
6431 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6432 == PERMISSION_GRANTED;
6433
6434 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6435 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6436 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006437 }
6438
6439 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6440 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006441 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6442 return new SecurityException("Specific channels must not be"
6443 + " scanned without location access.");
6444 }
6445 }
6446 }
6447
Hall Liub2ac8ef2019-02-28 15:56:23 -08006448 return null;
6449 }
6450
yinxu504e1392017-04-12 16:03:22 -07006451 /**
6452 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006453 *
6454 * @param subId id of the subscription
6455 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006456 */
6457 @Override
6458 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006459 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6460 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006461
Hall Liu912dfd32019-04-25 14:02:26 -07006462 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006463 final long identity = Binder.clearCallingIdentity();
6464 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006465 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006466 } finally {
6467 Binder.restoreCallingIdentity(identity);
6468 }
yinxu504e1392017-04-12 16:03:22 -07006469 }
6470
6471 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006472 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006473 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006474 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006475 */
6476 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006477 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006478 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006479 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006480 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006481
6482 final long identity = Binder.clearCallingIdentity();
6483 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006484 if (DBG) log("getAllowedNetworkTypesBitmask");
6485 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6486 int networkTypesBitmask = (result != null ? result[0] : -1);
6487 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6488 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006489 } finally {
6490 Binder.restoreCallingIdentity(identity);
6491 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006492 }
6493
6494 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006495 * Get the allowed network types for certain reason.
6496 *
6497 * @param subId the id of the subscription.
6498 * @param reason the reason the allowed network type change is taking place
6499 * @return the allowed network types.
6500 */
6501 @Override
6502 public long getAllowedNetworkTypesForReason(int subId,
6503 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006504 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006505 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006506 final long identity = Binder.clearCallingIdentity();
6507 try {
6508 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6509 } finally {
6510 Binder.restoreCallingIdentity(identity);
6511 }
6512 }
6513
6514 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006515 * Enable/Disable E-UTRA-NR Dual Connectivity
6516 * @param subId subscription id of the sim card
6517 * @param nrDualConnectivityState expected NR dual connectivity state
6518 * This can be passed following states
6519 * <ol>
6520 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6521 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6522 * <li>Disable NR dual connectivity and force secondary cell to be released
6523 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6524 * </ol>
6525 * @return operation result.
6526 */
6527 @Override
6528 public int setNrDualConnectivityState(int subId,
6529 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6530 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6531 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006532 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006533 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6534 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6535 }
6536
Sooraj Sasindran37444802020-08-11 10:40:43 -07006537 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6538 final long identity = Binder.clearCallingIdentity();
6539 try {
6540 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6541 nrDualConnectivityState, subId,
6542 workSource);
6543 if (DBG) log("enableNRDualConnectivity result: " + result);
6544 return result;
6545 } finally {
6546 Binder.restoreCallingIdentity(identity);
6547 }
6548 }
6549
6550 /**
6551 * Is E-UTRA-NR Dual Connectivity enabled
6552 * @return true if dual connectivity is enabled else false
6553 */
6554 @Override
6555 public boolean isNrDualConnectivityEnabled(int subId) {
6556 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006557 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006558 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006559 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006560 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6561 return false;
6562 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006563 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6564 final long identity = Binder.clearCallingIdentity();
6565 try {
6566 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6567 null, subId, workSource);
6568 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6569 return isEnabled;
6570 } finally {
6571 Binder.restoreCallingIdentity(identity);
6572 }
6573 }
6574
6575 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006576 * Set the allowed network types of the device and
6577 * provide the reason triggering the allowed network change.
6578 *
6579 * @param subId the id of the subscription.
6580 * @param reason the reason the allowed network type change is taking place
6581 * @param allowedNetworkTypes the allowed network types.
6582 * @return true on success; false on any failure.
6583 */
6584 @Override
6585 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006586 @TelephonyManager.AllowedNetworkTypesReason int reason,
6587 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006588 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6589 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006590 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006591 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6592 return false;
6593 }
6594 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6595 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006596 return false;
6597 }
6598
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006599 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6600 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6601
6602
6603 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6604 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6605 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006606 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006607
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006608 final long identity = Binder.clearCallingIdentity();
6609 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006610 Boolean success = (Boolean) sendRequest(
6611 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6612 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6613
6614 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6615 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006616 } finally {
6617 Binder.restoreCallingIdentity(identity);
6618 }
6619 }
6620
6621 /**
Miaoa84611c2019-03-15 09:21:10 +08006622 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006623 *
Miaoa84611c2019-03-15 09:21:10 +08006624 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006625 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006626 * @hide
6627 */
6628 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006629 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006630 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006631 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006632 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006633 try {
Miaoa84611c2019-03-15 09:21:10 +08006634 if (phone != null) {
6635 return phone.hasMatchedTetherApnSetting();
6636 } else {
6637 return false;
6638 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006639 } finally {
6640 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006641 }
Junda Liu475951f2014-11-07 16:45:03 -08006642 }
6643
6644 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006645 * Get the user enabled state of Mobile Data.
6646 *
6647 * TODO: remove and use isUserDataEnabled.
6648 * This can't be removed now because some vendor codes
6649 * calls through ITelephony directly while they should
6650 * use TelephonyManager.
6651 *
6652 * @return true on enabled
6653 */
6654 @Override
6655 public boolean getDataEnabled(int subId) {
6656 return isUserDataEnabled(subId);
6657 }
6658
6659 /**
6660 * Get whether mobile data is enabled per user setting.
6661 *
6662 * There are other factors deciding whether mobile data is actually enabled, but they are
6663 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006664 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006665 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6666 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006667 *
6668 * @return {@code true} if data is enabled else {@code false}
6669 */
6670 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006671 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006672 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006673 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006674 try {
6675 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6676 functionName);
6677 } catch (Exception e) {
6678 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6679 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006680 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006681 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006682 mApp, subId, functionName);
6683
Robert Greenwalt646120a2014-05-23 11:54:03 -07006684 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006685
6686 final long identity = Binder.clearCallingIdentity();
6687 try {
6688 int phoneId = mSubscriptionController.getPhoneId(subId);
6689 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6690 Phone phone = PhoneFactory.getPhone(phoneId);
6691 if (phone != null) {
6692 boolean retVal = phone.isUserDataEnabled();
6693 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6694 return retVal;
6695 } else {
6696 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6697 return false;
6698 }
6699 } finally {
6700 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006701 }
6702 }
6703
6704 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006705 * Checks if the device is capable of mobile data by considering whether whether the
6706 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6707 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006708 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006709 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006710 */
6711 @Override
6712 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006713 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006714 try {
6715 try {
6716 mApp.enforceCallingOrSelfPermission(
6717 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006718 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006719 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006720 try {
6721 mApp.enforceCallingOrSelfPermission(
6722 android.Manifest.permission.READ_PHONE_STATE,
6723 functionName);
6724 } catch (Exception e2) {
6725 mApp.enforceCallingOrSelfPermission(
6726 permission.READ_BASIC_PHONE_STATE, functionName);
6727 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006728 }
6729 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006730 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006731 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006732
6733 final long identity = Binder.clearCallingIdentity();
6734 try {
6735 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006736 Phone phone = PhoneFactory.getPhone(phoneId);
6737 if (phone != null) {
Jack Yu4ad64e52021-12-03 14:23:53 -08006738 boolean retVal;
6739 if (phone.isUsingNewDataStack()) {
6740 retVal = phone.getDataNetworkController().getDataSettingsManager()
6741 .isDataEnabled();
6742 } else {
6743 retVal = phone.getDataEnabledSettings().isDataEnabled();
6744 }
6745 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006746 return retVal;
6747 } else {
6748 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6749 return false;
6750 }
6751 } finally {
6752 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006753 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006754 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006755
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006756 /**
6757 * Check if data is enabled for a specific reason
6758 * @param subId Subscription index
6759 * @param reason the reason the data enable change is taking place
6760 * @return {@code true} if the overall data is enabled; {@code false} if not.
6761 */
6762 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006763 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006764 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006765 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006766 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006767 try {
6768 mApp.enforceCallingOrSelfPermission(
6769 android.Manifest.permission.ACCESS_NETWORK_STATE,
6770 functionName);
6771 } catch (Exception e) {
6772 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6773 functionName);
6774 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006775 } catch (Exception e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006776 try {
6777 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006778 functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006779 } catch (Exception e2) {
6780 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006781 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006782 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006783 }
6784
6785
6786 final long identity = Binder.clearCallingIdentity();
6787 try {
6788 int phoneId = mSubscriptionController.getPhoneId(subId);
6789 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006790 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006791 + " reason=" + reason);
6792 }
6793 Phone phone = PhoneFactory.getPhone(phoneId);
6794 if (phone != null) {
6795 boolean retVal;
6796 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6797 retVal = phone.isUserDataEnabled();
6798 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006799 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006800 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006801 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006802 return retVal;
6803 } else {
6804 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006805 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006806 + subId + " retVal=false");
6807 }
6808 return false;
6809 }
6810 } finally {
6811 Binder.restoreCallingIdentity(identity);
6812 }
6813 }
6814
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006815 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006816 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006817 if (uid == Process.PHONE_UID) {
6818 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6819 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006820 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6821 }
6822
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006823 //load access rules from carrier configs, and check those as well: b/139133814
6824 SubscriptionController subController = SubscriptionController.getInstance();
6825 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6826 || subController == null) return privilegeFromSim;
6827
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006828 PackageManager pkgMgr = phone.getContext().getPackageManager();
6829 String[] packages = pkgMgr.getPackagesForUid(uid);
6830
6831 final long identity = Binder.clearCallingIdentity();
6832 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006833 int subId = phone.getSubId();
6834 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6835 // A test override is in place for the privileges for this subId, so don't try to
6836 // read the subscription privileges.
6837 return privilegeFromSim;
6838 }
6839 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006840 SubscriptionManager subManager = (SubscriptionManager)
6841 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6842 for (String pkg : packages) {
6843 if (subManager.canManageSubscription(subInfo, pkg)) {
6844 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6845 }
6846 }
6847 return privilegeFromSim;
6848 } finally {
6849 Binder.restoreCallingIdentity(identity);
6850 }
6851 }
6852
6853 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6854 String pkgName) {
6855 //load access rules from carrier configs, and check those as well: b/139133814
6856 SubscriptionController subController = SubscriptionController.getInstance();
6857 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6858 || subController == null) return privilegeFromSim;
6859
6860 final long identity = Binder.clearCallingIdentity();
6861 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006862 int subId = phone.getSubId();
6863 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6864 // A test override is in place for the privileges for this subId, so don't try to
6865 // read the subscription privileges.
6866 return privilegeFromSim;
6867 }
6868 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006869 SubscriptionManager subManager = (SubscriptionManager)
6870 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6871 return subManager.canManageSubscription(subInfo, pkgName)
6872 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6873 } finally {
6874 Binder.restoreCallingIdentity(identity);
6875 }
6876 }
6877
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006878 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006879 public int getCarrierPrivilegeStatus(int subId) {
6880 final Phone phone = getPhone(subId);
6881 if (phone == null) {
6882 loge("getCarrierPrivilegeStatus: Invalid subId");
6883 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6884 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006885 UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId());
6886 if (port == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006887 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006888 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6889 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006890
6891 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006892 port.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006893 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006894 }
Junda Liu29340342014-07-10 15:23:27 -07006895
6896 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006897 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006898 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006899 final Phone phone = getPhone(subId);
6900 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006901 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006902 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6903 }
6904 UiccProfile profile =
6905 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6906 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006907 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006908 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6909 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006910 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006911 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006912 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006913 }
6914
6915 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006916 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006917 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006918 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006919 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006920 }
6921
6922 int phoneId = SubscriptionManager.getPhoneId(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006923 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6924 if (port == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006925 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006926 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6927 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006928 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006929 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006930 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006931 }
6932
6933 @Override
6934 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006935 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006936 if (TextUtils.isEmpty(pkgName))
6937 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006938 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6939 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006940 UiccPort port = UiccController.getInstance().getUiccPort(i);
6941 if (port == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006942 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006943 continue;
6944 }
6945
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006946 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006947 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006948 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006949 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6950 break;
6951 }
6952 }
6953
6954 return result;
Junda Liu29340342014-07-10 15:23:27 -07006955 }
Derek Tan89e89d42014-07-08 17:00:10 -07006956
6957 @Override
Junda Liue64de782015-04-16 17:19:16 -07006958 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006959 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006960 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6961 loge("phoneId " + phoneId + " is not valid.");
6962 return null;
6963 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006964 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6965 if (port == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006966 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006967 return null ;
6968 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006969 return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006970 }
6971
Amith Yamasani6e118872016-02-19 12:53:51 -08006972 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006973 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006974 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006975 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006976 List<String> privilegedPackages = new ArrayList<>();
6977 List<PackageInfo> packages = null;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006978 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
chen xuf7e9fe82019-05-09 19:31:02 -07006979 // has UICC in that slot.
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006980 if (port != null) {
6981 if (port.hasCarrierPrivilegeRules()) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006982 if (packages == null) {
6983 // Only check packages in user 0 for now
6984 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006985 PackageManager.MATCH_DISABLED_COMPONENTS
6986 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006987 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006988 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006989 }
6990 for (int p = packages.size() - 1; p >= 0; p--) {
6991 PackageInfo pkgInfo = packages.get(p);
6992 if (pkgInfo != null && pkgInfo.packageName != null
Sooraj Sasindran97bce6f2021-09-28 21:37:29 +00006993 && getCarrierPrivilegeStatusFromCarrierConfigRules(
6994 port.getCarrierPrivilegeStatus(pkgInfo),
6995 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07006996 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006997 privilegedPackages.add(pkgInfo.packageName);
6998 }
6999 }
7000 }
7001 }
7002 return privilegedPackages;
7003 }
7004
chen xuf7e9fe82019-05-09 19:31:02 -07007005 @Override
7006 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007007 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
7008
7009 final long identity = Binder.clearCallingIdentity();
7010
chen xuf7e9fe82019-05-09 19:31:02 -07007011 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007012 try {
7013 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7014 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7015 }
7016 } finally {
7017 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007018 }
7019 return privilegedPackages;
7020 }
7021
Wink Savilleb564aae2014-10-23 10:18:09 -07007022 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007023 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007024 UiccPort port = phone == null ? null : phone.getUiccPort();
7025 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007026 return null;
7027 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007028 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007029 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007030 return null;
7031 }
7032 return iccId;
7033 }
7034
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007035 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007036 public void setCallComposerStatus(int subId, int status) {
7037 enforceModifyPermission();
7038
7039 final long identity = Binder.clearCallingIdentity();
7040 try {
7041 Phone phone = getPhone(subId);
7042 if (phone != null) {
7043 Phone defaultPhone = phone.getImsPhone();
7044 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7045 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7046 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007047 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7048 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007049 }
7050 }
Shuo Qian284ae752020-12-22 19:10:14 -08007051 } catch (ImsException e) {
7052 throw new ServiceSpecificException(e.getCode());
7053 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007054 Binder.restoreCallingIdentity(identity);
7055 }
7056 }
7057
7058 @Override
7059 public int getCallComposerStatus(int subId) {
7060 enforceReadPrivilegedPermission("getCallComposerStatus");
7061
7062 final long identity = Binder.clearCallingIdentity();
7063 try {
7064 Phone phone = getPhone(subId);
7065 if (phone != null) {
7066 Phone defaultPhone = phone.getImsPhone();
7067 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7068 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7069 return imsPhone.getCallComposerStatus();
7070 }
7071 }
7072 } finally {
7073 Binder.restoreCallingIdentity(identity);
7074 }
7075 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7076 }
7077
7078 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007079 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7080 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007081 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007082 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007083
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007084 final long identity = Binder.clearCallingIdentity();
7085 try {
7086 final String iccId = getIccId(subId);
7087 final Phone phone = getPhone(subId);
7088 if (phone == null) {
7089 return false;
7090 }
7091 final String subscriberId = phone.getSubscriberId();
7092
7093 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007094 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007095 + subscriberId + " to " + number);
7096 }
7097
7098 if (TextUtils.isEmpty(iccId)) {
7099 return false;
7100 }
7101
7102 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7103
7104 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7105 if (alphaTag == null) {
7106 editor.remove(alphaTagPrefKey);
7107 } else {
7108 editor.putString(alphaTagPrefKey, alphaTag);
7109 }
7110
7111 // Record both the line number and IMSI for this ICCID, since we need to
7112 // track all merged IMSIs based on line number
7113 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7114 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7115 if (number == null) {
7116 editor.remove(numberPrefKey);
7117 editor.remove(subscriberPrefKey);
7118 } else {
7119 editor.putString(numberPrefKey, number);
7120 editor.putString(subscriberPrefKey, subscriberId);
7121 }
7122
7123 editor.commit();
7124 return true;
7125 } finally {
7126 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007127 }
Derek Tan7226c842014-07-02 17:42:23 -07007128 }
7129
7130 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007131 public String getLine1NumberForDisplay(int subId, String callingPackage,
7132 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007133 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007134 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007135 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007136 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007137 return null;
7138 }
Derek Tan97ebb422014-09-05 16:55:38 -07007139
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007140 final long identity = Binder.clearCallingIdentity();
7141 try {
7142 String iccId = getIccId(subId);
7143 if (iccId != null) {
7144 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7145 if (DBG_MERGE) {
7146 log("getLine1NumberForDisplay returning "
7147 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7148 }
7149 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007150 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007151 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7152 return null;
7153 } finally {
7154 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007155 }
Derek Tan7226c842014-07-02 17:42:23 -07007156 }
7157
7158 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007159 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7160 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007161 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007162 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007163 return null;
7164 }
Derek Tan97ebb422014-09-05 16:55:38 -07007165
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007166 final long identity = Binder.clearCallingIdentity();
7167 try {
7168 String iccId = getIccId(subId);
7169 if (iccId != null) {
7170 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7171 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7172 }
7173 return null;
7174 } finally {
7175 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007176 }
Derek Tan7226c842014-07-02 17:42:23 -07007177 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007178
7179 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007180 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7181 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007182 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7183 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007184 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007185 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007186 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007187 return null;
7188 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007189
Jordan Liub49b04b2019-05-06 14:45:15 -07007190 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7191 // the process, where TelephonyManager was instantiated.
7192 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007193 final long identity = Binder.clearCallingIdentity();
7194 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007195 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007196 final TelephonyManager tele = TelephonyManager.from(context);
7197 final SubscriptionManager sub = SubscriptionManager.from(context);
7198
7199 // Figure out what subscribers are currently active
7200 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007201
Jordan Liub49b04b2019-05-06 14:45:15 -07007202 // Only consider subs which match the current subId
7203 // This logic can be simplified. See b/131189269 for progress.
7204 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007205 activeSubscriberIds.add(tele.getSubscriberId(subId));
7206 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007207
7208 // First pass, find a number override for an active subscriber
7209 String mergeNumber = null;
7210 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7211 for (String key : prefs.keySet()) {
7212 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7213 final String subscriberId = (String) prefs.get(key);
7214 if (activeSubscriberIds.contains(subscriberId)) {
7215 final String iccId = key.substring(
7216 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7217 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7218 mergeNumber = (String) prefs.get(numberKey);
7219 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007220 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007221 + " for active subscriber " + subscriberId);
7222 }
7223 if (!TextUtils.isEmpty(mergeNumber)) {
7224 break;
7225 }
7226 }
7227 }
7228 }
7229
7230 // Shortcut when no active merged subscribers
7231 if (TextUtils.isEmpty(mergeNumber)) {
7232 return null;
7233 }
7234
7235 // Second pass, find all subscribers under that line override
7236 final ArraySet<String> result = new ArraySet<>();
7237 for (String key : prefs.keySet()) {
7238 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7239 final String number = (String) prefs.get(key);
7240 if (mergeNumber.equals(number)) {
7241 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7242 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7243 final String subscriberId = (String) prefs.get(subscriberKey);
7244 if (!TextUtils.isEmpty(subscriberId)) {
7245 result.add(subscriberId);
7246 }
7247 }
7248 }
7249 }
7250
7251 final String[] resultArray = result.toArray(new String[result.size()]);
7252 Arrays.sort(resultArray);
7253 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007254 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007255 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7256 }
7257 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007258 } finally {
7259 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007260 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007261 }
7262
7263 @Override
zoey chen38003472019-12-13 17:16:31 +08007264 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7265 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007266
7267 final long identity = Binder.clearCallingIdentity();
7268 try {
7269 final TelephonyManager telephonyManager = mApp.getSystemService(
7270 TelephonyManager.class);
7271 String subscriberId = telephonyManager.getSubscriberId(subId);
7272 if (subscriberId == null) {
7273 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007274 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007275 + subId);
7276 }
7277 return null;
7278 }
7279
7280 final SubscriptionInfo info = SubscriptionController.getInstance()
7281 .getSubscriptionInfo(subId);
7282 final ParcelUuid groupUuid = info.getGroupUuid();
7283 // If it doesn't belong to any group, return just subscriberId of itself.
7284 if (groupUuid == null) {
7285 return new String[]{subscriberId};
7286 }
7287
7288 // Get all subscriberIds from the group.
7289 final List<String> mergedSubscriberIds = new ArrayList<>();
7290 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007291 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007292 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007293 for (SubscriptionInfo subInfo : groupInfos) {
7294 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7295 if (subscriberId != null) {
7296 mergedSubscriberIds.add(subscriberId);
7297 }
7298 }
7299
7300 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7301 } finally {
7302 Binder.restoreCallingIdentity(identity);
7303
7304 }
7305 }
7306
7307 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007308 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007309 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007310 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007311
7312 final long identity = Binder.clearCallingIdentity();
7313 try {
7314 final Phone phone = getPhone(subId);
7315 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7316 } finally {
7317 Binder.restoreCallingIdentity(identity);
7318 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007319 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007320
7321 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007322 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007323 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7324 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007325 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7326 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007327
7328 final long identity = Binder.clearCallingIdentity();
7329 try {
7330 final Phone phone = getPhone(subId);
7331 if (phone == null) {
7332 return false;
7333 }
7334 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7335 cdmaNonRoamingList);
7336 } finally {
7337 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007338 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007339 }
7340
7341 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007342 @Deprecated
7343 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7344 enforceModifyPermission();
7345
7346 int returnValue = 0;
7347 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007348 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007349 if(result.exception == null) {
7350 if (result.result != null) {
7351 byte[] responseData = (byte[])(result.result);
7352 if(responseData.length > oemResp.length) {
7353 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7354 responseData.length + "bytes. Buffer Size is " +
7355 oemResp.length + "bytes.");
7356 }
7357 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7358 returnValue = responseData.length;
7359 }
7360 } else {
7361 CommandException ex = (CommandException) result.exception;
7362 returnValue = ex.getCommandError().ordinal();
7363 if(returnValue > 0) returnValue *= -1;
7364 }
7365 } catch (RuntimeException e) {
7366 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7367 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7368 if(returnValue > 0) returnValue *= -1;
7369 }
7370
7371 return returnValue;
7372 }
7373
7374 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007375 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007376 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007377 try {
7378 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007379 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007380 mApp, phone.getSubId(), "getRadioAccessFamily");
7381 } catch (SecurityException e) {
7382 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7383 throw e;
7384 }
chen xub97461a2018-10-26 14:17:57 -07007385 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007386 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007387 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007388 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007389 final long identity = Binder.clearCallingIdentity();
7390 try {
chen xub97461a2018-10-26 14:17:57 -07007391 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007392 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007393 mApp, phone.getSubId(), "getRadioAccessFamily");
7394 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007395 } finally {
7396 Binder.restoreCallingIdentity(identity);
7397 }
chen xub97461a2018-10-26 14:17:57 -07007398 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007399 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007400
7401 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007402 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007403 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007404 try {
7405 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7406 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007407 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007408 }
7409 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007410 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007411 }
7412 RoleManager rm = mApp.getSystemService(RoleManager.class);
7413 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7414 if (!dialerRoleHolders.contains(callingPackage)) {
7415 throw new SecurityException("App must be the dialer role holder to"
7416 + " upload a call composer pic");
7417 }
7418
7419 Executors.newSingleThreadExecutor().execute(() -> {
7420 ByteArrayOutputStream output = new ByteArrayOutputStream(
7421 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7422 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7423 boolean readUntilEnd = false;
7424 int totalBytesRead = 0;
7425 byte[] buffer = new byte[16 * 1024];
7426 while (true) {
7427 int numRead;
7428 try {
7429 numRead = input.read(buffer);
7430 } catch (IOException e) {
7431 try {
7432 fd.checkError();
7433 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7434 null);
7435 } catch (IOException e1) {
7436 // This means that the other side closed explicitly with an error. If this
7437 // happens, log and ignore.
7438 loge("Remote end of call composer picture pipe closed: " + e1);
7439 }
7440 break;
7441 }
7442 if (numRead == -1) {
7443 readUntilEnd = true;
7444 break;
7445 }
7446 totalBytesRead += numRead;
7447 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7448 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7449 try {
7450 input.close();
7451 } catch (IOException e) {
7452 // ignore
7453 }
7454 break;
7455 }
7456 output.write(buffer, 0, numRead);
7457 }
7458 // Generally, the remote end will close the file descriptors. The only case where we
7459 // close is above, where the picture size is too big.
7460
7461 try {
7462 fd.checkError();
7463 } catch (IOException e) {
7464 loge("Remote end for call composer closed with an error: " + e);
7465 return;
7466 }
7467
Hall Liuaa4211e2021-01-20 15:43:39 -08007468 if (!readUntilEnd) {
7469 loge("Did not finish reading entire image; aborting");
7470 return;
7471 }
Hall Liu82694d52020-12-11 18:22:04 -08007472
Hall Liuaa4211e2021-01-20 15:43:39 -08007473 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7474 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7475 new CallComposerPictureTransfer.Factory() {},
7476 imageData,
7477 (result) -> {
7478 if (result.first != null) {
7479 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7480 Bundle outputResult = new Bundle();
7481 outputResult.putParcelable(
7482 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7483 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7484 outputResult);
7485 } else {
7486 callback.send(result.second, null);
7487 }
7488 }
7489 );
Hall Liu82694d52020-12-11 18:22:04 -08007490 });
7491 }
7492
7493 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007494 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007495 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007496 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007497
7498 final long identity = Binder.clearCallingIdentity();
7499 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007500 ImsManager.getInstance(defaultPhone.getContext(),
7501 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007502 } finally {
7503 Binder.restoreCallingIdentity(identity);
7504 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007505 }
7506
7507 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007508 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007509 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007510 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7511 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007512 return false;
7513 }
Svet Ganovb320e182015-04-16 12:30:10 -07007514
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007515 final long identity = Binder.clearCallingIdentity();
7516 try {
7517 // Check the user preference and the system-level IMS setting. Even if the user has
7518 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7519 // In the long run, we may instead need to check if there exists a connection service
7520 // which can support video calling.
7521 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007522 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007523 return imsManager.isVtEnabledByPlatform()
7524 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7525 && imsManager.isVtEnabledByUser();
7526 } finally {
7527 Binder.restoreCallingIdentity(identity);
7528 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007529 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007530
Andrew Leea1239f22015-03-02 17:44:07 -08007531 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007532 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7533 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007534 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007535 mApp, subId, callingPackage, callingFeatureId,
7536 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007537 return false;
7538 }
7539
7540 final long identity = Binder.clearCallingIdentity();
7541 try {
7542 CarrierConfigManager configManager =
7543 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007544 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007545 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7546 } finally {
7547 Binder.restoreCallingIdentity(identity);
7548 }
Andrew Leea1239f22015-03-02 17:44:07 -08007549 }
7550
7551 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007552 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007553 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007554 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007555 return false;
7556 }
7557
7558 final long identity = Binder.clearCallingIdentity();
7559 try {
7560 CarrierConfigManager configManager =
7561 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007562 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007563 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7564 } finally {
7565 Binder.restoreCallingIdentity(identity);
7566 }
Andrew Leea1239f22015-03-02 17:44:07 -08007567 }
7568
Andrew Lee9431b832015-03-09 18:46:45 -07007569 @Override
7570 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007571 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007572 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007573 }
7574
7575 @Override
7576 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007577 final long identity = Binder.clearCallingIdentity();
7578 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007579 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007580 } finally {
7581 Binder.restoreCallingIdentity(identity);
7582 }
Andrew Lee9431b832015-03-09 18:46:45 -07007583 }
7584
Hall Liuf6668912018-10-31 17:05:23 -07007585 /**
7586 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7587 * support for the feature and device firmware support.
7588 *
7589 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7590 */
7591 @Override
7592 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007593 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007594 final Phone phone = getPhone(subscriptionId);
7595 if (phone == null) {
7596 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7597 return false;
7598 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007599 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007600 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007601 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7602 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007603 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007604 return isCarrierSupported && isDeviceSupported;
7605 } finally {
7606 Binder.restoreCallingIdentity(identity);
7607 }
Hall Liu98187582018-01-22 19:15:32 -08007608 }
7609
Hall Liuf6668912018-10-31 17:05:23 -07007610 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007611 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7612 * RTT setting, will return true if the device and carrier both support RTT.
7613 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007614 */
7615 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007616 final long identity = Binder.clearCallingIdentity();
7617 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007618 boolean isRttSupported = isRttSupported(subscriptionId);
7619 boolean isUserRttSettingOn = Settings.Secure.getInt(
7620 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7621 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7622 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7623 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007624 } finally {
7625 Binder.restoreCallingIdentity(identity);
7626 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007627 }
7628
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007629 @Deprecated
7630 @Override
7631 public String getDeviceId(String callingPackage) {
7632 return getDeviceIdWithFeature(callingPackage, null);
7633 }
7634
Sanket Padawe7310cc72015-01-14 09:53:20 -08007635 /**
7636 * Returns the unique device ID of phone, for example, the IMEI for
7637 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7638 *
7639 * <p>Requires Permission:
7640 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7641 */
7642 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007643 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007644 try {
7645 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7646 } catch (SecurityException se) {
7647 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7648 throw new SecurityException("Package " + callingPackage + " does not belong to "
7649 + Binder.getCallingUid());
7650 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007651 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007652 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007653 return null;
7654 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007655 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007656 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007657 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007658 return null;
7659 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007660
7661 final long identity = Binder.clearCallingIdentity();
7662 try {
7663 return phone.getDeviceId();
7664 } finally {
7665 Binder.restoreCallingIdentity(identity);
7666 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007667 }
7668
Ping Sunc67b7c22016-03-02 19:16:45 +08007669 /**
7670 * {@hide}
7671 * Returns the IMS Registration Status on a particular subid
7672 *
7673 * @param subId
7674 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007675 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007676 Phone phone = getPhone(subId);
7677 if (phone != null) {
7678 return phone.isImsRegistered();
7679 } else {
7680 return false;
7681 }
7682 }
7683
Santos Cordon7a1885b2015-02-03 11:15:19 -08007684 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007685 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007686 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007687 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007688 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007689 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7690 }
7691 final long identity = Binder.clearCallingIdentity();
7692 try {
7693 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7694 } finally {
7695 Binder.restoreCallingIdentity(identity);
7696 }
7697 }
7698
7699 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007700 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007701 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007702 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007703 mApp,
7704 subscriptionId,
7705 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007706 final long identity = Binder.clearCallingIdentity();
7707 try {
7708 Phone phone = getPhone(subscriptionId);
7709 if (phone == null) {
7710 return null;
7711 }
7712 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7713 } finally {
7714 Binder.restoreCallingIdentity(identity);
7715 }
7716 }
7717
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007718 /**
7719 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007720 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007721 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007722 final long identity = Binder.clearCallingIdentity();
7723 try {
7724 Phone phone = getPhone(subId);
7725 if (phone != null) {
7726 return phone.isWifiCallingEnabled();
7727 } else {
7728 return false;
7729 }
7730 } finally {
7731 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007732 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007733 }
7734
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007735 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007736 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007737 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007738 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007739 final long identity = Binder.clearCallingIdentity();
7740 try {
7741 Phone phone = getPhone(subId);
7742 if (phone != null) {
7743 return phone.isVideoEnabled();
7744 } else {
7745 return false;
7746 }
7747 } finally {
7748 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007749 }
7750 }
7751
7752 /**
7753 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7754 * defined in {@link ImsRegistrationImplBase}.
7755 */
7756 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007757 final long identity = Binder.clearCallingIdentity();
7758 try {
7759 Phone phone = getPhone(subId);
7760 if (phone != null) {
7761 return phone.getImsRegistrationTech();
7762 } else {
7763 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7764 }
7765 } finally {
7766 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007767 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007768 }
7769
Stuart Scott8eef64f2015-04-08 15:13:54 -07007770 @Override
7771 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007772 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007773 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7774 return;
7775 }
Kai Shif70f46f2021-03-03 13:59:46 -08007776 Phone defaultPhone = getDefaultPhone();
7777 if (defaultPhone != null) {
7778 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7779 mApp, getDefaultPhone().getSubId(), "factoryReset");
7780 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007781 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007782
Svet Ganovcc087f82015-05-12 20:35:54 -07007783 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007784 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7785 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007786 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007787 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007788 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007789 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007790 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007791 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007792 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007793 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007794 // There has been issues when Sms raw table somehow stores orphan
7795 // fragments. They lead to garbled message when new fragments come
7796 // in and combined with those stale ones. In case this happens again,
7797 // user can reset all network settings which will clean up this table.
7798 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007799 // Clean up IMS settings as well here.
7800 int slotId = getSlotIndex(subId);
7801 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7802 ImsManager.getInstance(mApp, slotId).factoryReset();
7803 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007804
Kai Shif70f46f2021-03-03 13:59:46 -08007805 if (defaultPhone == null) {
7806 return;
7807 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007808 // Erase modem config if erase modem on network setting is enabled.
7809 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7810 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7811 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007812 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007813 }
Kai Shif70f46f2021-03-03 13:59:46 -08007814
7815 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007816 } finally {
7817 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007818 }
7819 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007820
SongFerngWangfd89b102021-05-27 22:44:54 +08007821 @VisibleForTesting
7822 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7823 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7824 return;
7825 }
7826 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7827 RILConstants.PREFERRED_NETWORK_MODE);
7828 SubscriptionManager.setSubscriptionProperty(subId,
7829 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7830 "user=" + defaultNetworkType);
7831 phone.loadAllowedNetworksFromSubscriptionDatabase();
7832 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7833 defaultNetworkType, null);
7834 }
7835
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007836 private void cleanUpSmsRawTable(Context context) {
7837 ContentResolver resolver = context.getContentResolver();
7838 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7839 resolver.delete(uri, null, null);
7840 }
7841
Narayan Kamath1c496c22015-04-16 14:40:19 +01007842 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007843 public String getSimLocaleForSubscriber(int subId) {
7844 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7845 final Phone phone = getPhone(subId);
7846 if (phone == null) {
7847 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007848 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007849 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007850 final long identity = Binder.clearCallingIdentity();
7851 try {
chen xu5d3637b2019-01-21 23:31:38 -08007852 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007853 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007854 if (info == null) {
7855 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7856 return null;
7857 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007858 // Try and fetch the locale from the carrier properties or from the SIM language
7859 // preferences (EF-PL and EF-LI)...
7860 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007861 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007862 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7863 if (localeFromDefaultSim != null) {
7864 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7865 if (DBG) log("Using locale from subId: " + subId + " locale: "
7866 + localeFromDefaultSim);
7867 return localeFromDefaultSim.toLanguageTag();
7868 } else {
7869 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007870 }
7871 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007872
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007873 // The SIM language preferences only store a language (e.g. fr = French), not an
7874 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7875 // the SIM and carrier preferences does not include a country we add the country
7876 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007877 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007878 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007879 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007880 return mccLocale.toLanguageTag();
7881 }
7882
7883 if (DBG) log("No locale found - returning null");
7884 return null;
7885 } finally {
7886 Binder.restoreCallingIdentity(identity);
7887 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007888 }
7889
7890 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007891 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007892 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007893 }
7894
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007895 /**
7896 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7897 */
7898 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007899 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007900 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007901 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007902
Chenjie Yu1ba97252018-01-11 18:16:20 -08007903 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007904 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007905
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007906 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007907 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7908 * representing the state of the modem.
7909 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007910 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7911 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007912 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007913 */
7914 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007915 public void requestModemActivityInfo(ResultReceiver result) {
7916 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007917 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007918
7919 final long identity = Binder.clearCallingIdentity();
7920 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007921 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007922 } finally {
7923 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007924 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007925 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007926
Siddharth Rayb8114062018-06-17 15:02:38 -07007927 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7928 // less than total activity duration.
7929 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7930 if (info == null) {
7931 return false;
7932 }
7933 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007934 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7935 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7936
Siddharth Rayb8114062018-06-17 15:02:38 -07007937 return (info.isValid()
7938 && (info.getSleepTimeMillis() <= activityDurationMs)
7939 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007940 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007941 && (totalTxTimeMs <= activityDurationMs));
7942 }
7943
Jack Yu85bd38a2015-11-09 11:34:32 -08007944 /**
7945 * {@hide}
7946 * Returns the service state information on specified subscription.
7947 */
7948 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007949 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7950 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007951 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007952 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007953 return null;
7954 }
7955
Hall Liuf19c44f2018-11-27 14:38:17 -08007956 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7957 LocationAccessPolicy.checkLocationPermission(mApp,
7958 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7959 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007960 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007961 .setCallingPid(Binder.getCallingPid())
7962 .setCallingUid(Binder.getCallingUid())
7963 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007964 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007965 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007966 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7967 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007968 .build());
7969
7970 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7971 LocationAccessPolicy.checkLocationPermission(mApp,
7972 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7973 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007974 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007975 .setCallingPid(Binder.getCallingPid())
7976 .setCallingUid(Binder.getCallingUid())
7977 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007978 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007979 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007980 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7981 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007982 .build());
7983 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7984 boolean hasFinePermission =
7985 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7986 boolean hasCoarsePermission =
7987 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7988
Jack Yu479f40e2020-10-27 21:29:25 -07007989 final Phone phone = getPhone(subId);
7990 if (phone == null) {
7991 return null;
7992 }
7993
Jordan Liu0f2bc442020-11-18 16:47:37 -08007994 final long identity = Binder.clearCallingIdentity();
7995
Jack Yu479f40e2020-10-27 21:29:25 -07007996 boolean isCallingPackageDataService = phone.getDataServicePackages()
7997 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007998 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007999 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
8000 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
8001 Rlog.d(LOG_TAG,
8002 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
8003 return null;
8004 }
8005
Hall Liuf19c44f2018-11-27 14:38:17 -08008006 ServiceState ss = phone.getServiceState();
8007
8008 // Scrub out the location info in ServiceState depending on what level of access
8009 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008010 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008011 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8012 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008013 } finally {
8014 Binder.restoreCallingIdentity(identity);
8015 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008016 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008017
8018 /**
8019 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8020 *
8021 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8022 * voicemail ringtone.
8023 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8024 * PhoneAccount.
8025 */
8026 @Override
8027 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008028 final long identity = Binder.clearCallingIdentity();
8029 try {
8030 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8031 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008032 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008033 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008034
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008035 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8036 } finally {
8037 Binder.restoreCallingIdentity(identity);
8038 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008039 }
8040
8041 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008042 * Sets the per-account voicemail ringtone.
8043 *
8044 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8045 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8046 *
8047 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8048 * voicemail ringtone.
8049 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8050 * PhoneAccount.
8051 */
8052 @Override
8053 public void setVoicemailRingtoneUri(String callingPackage,
8054 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008055 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008056 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008057 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8058 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008059 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8060 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8061 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008062 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008063
8064 final long identity = Binder.clearCallingIdentity();
8065 try {
8066 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8067 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008068 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008069 }
8070 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8071 } finally {
8072 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008073 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008074 }
8075
8076 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008077 * Returns whether vibration is set for voicemail notification in Phone settings.
8078 *
8079 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8080 * voicemail vibration setting.
8081 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8082 */
8083 @Override
8084 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008085 final long identity = Binder.clearCallingIdentity();
8086 try {
8087 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8088 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008089 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008090 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008091
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008092 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8093 } finally {
8094 Binder.restoreCallingIdentity(identity);
8095 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008096 }
8097
Youhan Wange64578a2016-05-02 15:32:42 -07008098 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008099 * Sets the per-account voicemail vibration.
8100 *
8101 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8102 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8103 *
8104 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8105 * voicemail vibration setting.
8106 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8107 * specific PhoneAccount.
8108 */
8109 @Override
8110 public void setVoicemailVibrationEnabled(String callingPackage,
8111 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008112 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008113 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008114 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8115 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008116 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8117 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8118 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008119 }
8120
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008121 final long identity = Binder.clearCallingIdentity();
8122 try {
8123 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8124 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008125 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008126 }
8127 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8128 } finally {
8129 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008130 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008131 }
8132
8133 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008134 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8135 *
8136 * @throws SecurityException if the caller does not have the required permission
8137 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008138 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008139 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008140 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008141 }
8142
8143 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008144 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8145 * permission.
8146 *
8147 * @throws SecurityException if the caller does not have the required permission
8148 */
8149 private void enforceSendSmsPermission() {
8150 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8151 }
8152
8153 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008154 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008155 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008156 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008157 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008158 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008159 final long identity = Binder.clearCallingIdentity();
8160 try {
8161 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008162 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008163 if (componentName == null) {
8164 throw new SecurityException(
8165 "Caller not current active visual voicemail package[null]");
8166 }
8167 String vvmPackage = componentName.getPackageName();
8168 if (!callingPackage.equals(vvmPackage)) {
8169 throw new SecurityException("Caller not current active visual voicemail package["
8170 + vvmPackage + "]");
8171 }
8172 } finally {
8173 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008174 }
8175 }
8176
8177 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008178 * Return the application ID for the app type.
8179 *
8180 * @param subId the subscription ID that this request applies to.
8181 * @param appType the uicc app type.
8182 * @return Application ID for specificied app type, or null if no uicc.
8183 */
8184 @Override
8185 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008186 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008187 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008188
8189 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008190 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008191 if (phone == null) {
8192 return null;
8193 }
8194 String aid = null;
8195 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008196 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008197 .getApplicationByType(appType).getAid();
8198 } catch (Exception e) {
8199 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8200 }
8201 return aid;
8202 } finally {
8203 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008204 }
Youhan Wange64578a2016-05-02 15:32:42 -07008205 }
8206
Youhan Wang4001d252016-05-11 10:29:41 -07008207 /**
8208 * Return the Electronic Serial Number.
8209 *
8210 * @param subId the subscription ID that this request applies to.
8211 * @return ESN or null if error.
8212 */
8213 @Override
8214 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008215 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008216 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008217
8218 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008219 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008220 if (phone == null) {
8221 return null;
8222 }
8223 String esn = null;
8224 try {
8225 esn = phone.getEsn();
8226 } catch (Exception e) {
8227 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8228 }
8229 return esn;
8230 } finally {
8231 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008232 }
Youhan Wang4001d252016-05-11 10:29:41 -07008233 }
8234
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008235 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008236 * Return the Preferred Roaming List Version.
8237 *
8238 * @param subId the subscription ID that this request applies to.
8239 * @return PRLVersion or null if error.
8240 */
8241 @Override
8242 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008243 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008244 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008245
8246 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008247 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008248 if (phone == null) {
8249 return null;
8250 }
8251 String cdmaPrlVersion = null;
8252 try {
8253 cdmaPrlVersion = phone.getCdmaPrlVersion();
8254 } catch (Exception e) {
8255 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8256 }
8257 return cdmaPrlVersion;
8258 } finally {
8259 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008260 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008261 }
8262
8263 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008264 * Get snapshot of Telephony histograms
8265 * @return List of Telephony histograms
8266 * @hide
8267 */
8268 @Override
8269 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008270 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8271 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008272
8273 final long identity = Binder.clearCallingIdentity();
8274 try {
8275 return RIL.getTelephonyRILTimingHistograms();
8276 } finally {
8277 Binder.restoreCallingIdentity(identity);
8278 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008279 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008280
8281 /**
8282 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008283 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8284 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008285 * Require system privileges. In the future we may add this to carrier APIs.
8286 *
Michele Berionne482f8202018-11-27 18:57:59 -08008287 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008288 */
8289 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008290 @TelephonyManager.SetCarrierRestrictionResult
8291 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008292 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008293 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008294
Michele Berionne482f8202018-11-27 18:57:59 -08008295 if (carrierRestrictionRules == null) {
8296 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008297 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008298
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008299 final long identity = Binder.clearCallingIdentity();
8300 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008301 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008302 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008303 } finally {
8304 Binder.restoreCallingIdentity(identity);
8305 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008306 }
8307
8308 /**
8309 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008310 * Get the allowed carrier list and the excluded carrier list, including the priority between
8311 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008312 * Require system privileges. In the future we may add this to carrier APIs.
8313 *
Michele Berionne482f8202018-11-27 18:57:59 -08008314 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008315 */
8316 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008317 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008318 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008319 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008320
8321 final long identity = Binder.clearCallingIdentity();
8322 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008323 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8324 if (response instanceof CarrierRestrictionRules) {
8325 return (CarrierRestrictionRules) response;
8326 }
8327 // Response is an Exception of some kind,
8328 // which is signalled to the user as a NULL retval
8329 return null;
8330 } catch (Exception e) {
8331 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8332 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008333 } finally {
8334 Binder.restoreCallingIdentity(identity);
8335 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008336 }
8337
fionaxu59545b42016-05-25 15:53:37 -07008338 /**
fionaxu59545b42016-05-25 15:53:37 -07008339 * Action set from carrier signalling broadcast receivers to enable/disable radio
8340 * @param subId the subscription ID that this action applies to.
8341 * @param enabled control enable or disable radio.
8342 * {@hide}
8343 */
8344 @Override
8345 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8346 enforceModifyPermission();
8347 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008348
8349 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008350 if (phone == null) {
8351 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8352 return;
8353 }
8354 try {
8355 phone.carrierActionSetRadioEnabled(enabled);
8356 } catch (Exception e) {
8357 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008358 } finally {
8359 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008360 }
8361 }
8362
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008363 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008364 * Enable or disable Voice over NR (VoNR)
8365 * @param subId the subscription ID that this action applies to.
8366 * @param enabled enable or disable VoNR.
8367 * @return operation result.
8368 */
8369 @Override
8370 public int setVoNrEnabled(int subId, boolean enabled) {
8371 enforceModifyPermission();
8372 final Phone phone = getPhone(subId);
8373
8374 final long identity = Binder.clearCallingIdentity();
8375 if (phone == null) {
8376 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8377 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8378 }
8379
8380 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8381 try {
8382 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8383 workSource);
8384 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008385
8386 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8387 if (DBG) {
8388 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8389 }
8390 SubscriptionManager.setSubscriptionProperty(
8391 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8392 (enabled ? "1" : "0"));
8393 }
8394
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008395 return result;
8396 } finally {
8397 Binder.restoreCallingIdentity(identity);
8398 }
8399 }
8400
8401 /**
8402 * Is voice over NR enabled
8403 * @return true if VoNR is enabled else false
8404 */
8405 @Override
8406 public boolean isVoNrEnabled(int subId) {
8407 enforceReadPrivilegedPermission("isVoNrEnabled");
8408 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8409 final long identity = Binder.clearCallingIdentity();
8410 try {
8411 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8412 null, subId, workSource);
8413 if (DBG) log("isVoNrEnabled: " + isEnabled);
8414 return isEnabled;
8415 } finally {
8416 Binder.restoreCallingIdentity(identity);
8417 }
8418 }
8419
8420 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008421 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8422 * network status based on which carrier apps could apply actions accordingly,
8423 * enable/disable default url handler for example.
8424 *
8425 * @param subId the subscription ID that this action applies to.
8426 * @param report control start/stop reporting the default network status.
8427 * {@hide}
8428 */
8429 @Override
8430 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8431 enforceModifyPermission();
8432 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008433
8434 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008435 if (phone == null) {
8436 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8437 return;
8438 }
8439 try {
8440 phone.carrierActionReportDefaultNetworkStatus(report);
8441 } catch (Exception e) {
8442 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008443 } finally {
8444 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008445 }
8446 }
8447
8448 /**
fionaxud9622282017-07-17 17:51:30 -07008449 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8450 * @param subId the subscription ID that this action applies to.
8451 * {@hide}
8452 */
8453 @Override
8454 public void carrierActionResetAll(int subId) {
8455 enforceModifyPermission();
8456 final Phone phone = getPhone(subId);
8457 if (phone == null) {
8458 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8459 return;
8460 }
8461 try {
8462 phone.carrierActionResetAll();
8463 } catch (Exception e) {
8464 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8465 }
8466 }
8467
8468 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008469 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8470 * bug report is being generated.
8471 */
8472 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008473 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008474 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8475 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008476 writer.println("Permission Denial: can't dump Phone from pid="
8477 + Binder.getCallingPid()
8478 + ", uid=" + Binder.getCallingUid()
8479 + "without permission "
8480 + android.Manifest.permission.DUMP);
8481 return;
8482 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008483 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008484 }
Jack Yueb89b242016-06-22 13:27:47 -07008485
Brad Ebingerdac2f002018-04-03 15:17:52 -07008486 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008487 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8488 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8489 @NonNull String[] args) {
8490 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8491 this, in.getFileDescriptor(), out.getFileDescriptor(),
8492 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008493 }
8494
Jack Yueb89b242016-06-22 13:27:47 -07008495 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008496 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008497 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008498 * @param reason the reason the data enable change is taking place
8499 * @param enabled True if enabling the data, otherwise disabling.
8500 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008501 */
8502 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008503 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008504 boolean enabled) {
8505 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8506 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8507 try {
8508 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008509 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008510 } catch (SecurityException se) {
8511 enforceModifyPermission();
8512 }
8513 } else {
8514 enforceModifyPermission();
8515 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008516
8517 final long identity = Binder.clearCallingIdentity();
8518 try {
8519 Phone phone = getPhone(subId);
8520 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008521 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8522 phone.carrierActionSetMeteredApnsEnabled(enabled);
8523 } else {
8524 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8525 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008526 }
8527 } finally {
8528 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008529 }
8530 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008531
8532 /**
8533 * Get Client request stats
8534 * @return List of Client Request Stats
8535 * @hide
8536 */
8537 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008538 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8539 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008540 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008541 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008542 return null;
8543 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008544 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008545
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008546 final long identity = Binder.clearCallingIdentity();
8547 try {
8548 if (phone != null) {
8549 return phone.getClientRequestStats();
8550 }
8551
8552 return null;
8553 } finally {
8554 Binder.restoreCallingIdentity(identity);
8555 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008556 }
8557
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008558 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008559 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008560 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008561 }
Jack Yueb4124c2017-02-16 15:32:43 -08008562
8563 /**
Grace Chen70990072017-03-24 17:21:30 -07008564 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008565 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008566 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008567 * @param state State of SIM (power down, power up, pass through)
8568 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8569 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8570 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008571 *
8572 **/
8573 @Override
Grace Chen70990072017-03-24 17:21:30 -07008574 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008575 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008576 Phone phone = PhoneFactory.getPhone(slotIndex);
8577
vagdeviaf9a5b92018-08-15 16:01:53 -07008578 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8579
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008580 final long identity = Binder.clearCallingIdentity();
8581 try {
8582 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008583 phone.setSimPowerState(state, null, workSource);
8584 }
8585 } finally {
8586 Binder.restoreCallingIdentity(identity);
8587 }
8588 }
8589
8590 /**
8591 * Set SIM card power state.
8592 *
8593 * @param slotIndex SIM slot id.
8594 * @param state State of SIM (power down, power up, pass through)
8595 * @param callback callback to trigger after success or failure
8596 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8597 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8598 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8599 *
8600 **/
8601 @Override
8602 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8603 IIntegerConsumer callback) {
8604 enforceModifyPermission();
8605 Phone phone = PhoneFactory.getPhone(slotIndex);
8606
8607 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8608
8609 final long identity = Binder.clearCallingIdentity();
8610 try {
8611 if (phone != null) {
8612 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8613 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008614 }
8615 } finally {
8616 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008617 }
8618 }
Shuo Qiandd210312017-04-12 22:11:33 +00008619
Tyler Gunn65d45c22017-06-05 11:22:26 -07008620 private boolean isUssdApiAllowed(int subId) {
8621 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008622 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008623 if (configManager == null) {
8624 return false;
8625 }
8626 PersistableBundle pb = configManager.getConfigForSubId(subId);
8627 if (pb == null) {
8628 return false;
8629 }
8630 return pb.getBoolean(
8631 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8632 }
8633
Shuo Qiandd210312017-04-12 22:11:33 +00008634 /**
8635 * Check if phone is in emergency callback mode
8636 * @return true if phone is in emergency callback mode
8637 * @param subId sub id
8638 */
goneil9c5f4872017-12-05 14:07:56 -08008639 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008640 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008641 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008642 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008643
8644 final long identity = Binder.clearCallingIdentity();
8645 try {
8646 if (phone != null) {
8647 return phone.isInEcm();
8648 } else {
8649 return false;
8650 }
8651 } finally {
8652 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008653 }
8654 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008655
8656 /**
8657 * Get the current signal strength information for the given subscription.
8658 * Because this information is not updated when the device is in a low power state
8659 * it should not be relied-upon to be current.
8660 * @param subId Subscription index
8661 * @return the most recent cached signal strength info from the modem
8662 */
8663 @Override
8664 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008665 final long identity = Binder.clearCallingIdentity();
8666 try {
8667 Phone p = getPhone(subId);
8668 if (p == null) {
8669 return null;
8670 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008671
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008672 return p.getSignalStrength();
8673 } finally {
8674 Binder.restoreCallingIdentity(identity);
8675 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008676 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008677
Pengquan Meng77b7f132018-08-22 14:49:57 -07008678 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008679 * Get the current modem radio state for the given slot.
8680 * @param slotIndex slot index.
8681 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008682 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008683 * @return the current radio power state from the modem
8684 */
8685 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008686 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008687 Phone phone = PhoneFactory.getPhone(slotIndex);
8688 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008689 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8690 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008691 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8692 }
8693
8694 final long identity = Binder.clearCallingIdentity();
8695 try {
8696 return phone.getRadioPowerState();
8697 } finally {
8698 Binder.restoreCallingIdentity(identity);
8699 }
8700 }
8701 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8702 }
8703
8704 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008705 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8706 *
8707 * <p>Requires one of the following permissions:
8708 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008709 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008710 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8711 * privileges.
8712 *
8713 * @param subId subscription id
8714 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8715 * {@code false}.
8716 */
8717 @Override
8718 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008719 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008720 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008721 try {
8722 mApp.enforceCallingOrSelfPermission(
8723 android.Manifest.permission.ACCESS_NETWORK_STATE,
8724 functionName);
8725 } catch (Exception e) {
8726 mApp.enforceCallingOrSelfPermission(
8727 permission.READ_BASIC_PHONE_STATE, functionName);
8728 }
Shuo Qian093013d2020-08-13 15:42:55 -07008729 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008730 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008731 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008732 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008733
Pengquan Menga1bb6272018-09-06 09:59:22 -07008734 boolean isEnabled = false;
8735 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008736 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008737 Phone phone = getPhone(subId);
8738 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008739 } finally {
8740 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008741 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008742 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008743 }
8744
8745
8746 /**
8747 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8748 *
8749 * <p> Requires permission:
8750 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8751 * privileges.
8752 *
8753 * @param subId subscription id
8754 * @param isEnabled {@code true} means enable, {@code false} means disable.
8755 */
8756 @Override
8757 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008758 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8759 mApp, subId, "setDataRoamingEnabled");
8760
Pengquan Menga1bb6272018-09-06 09:59:22 -07008761 final long identity = Binder.clearCallingIdentity();
8762 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008763 Phone phone = getPhone(subId);
8764 if (phone != null) {
8765 phone.setDataRoamingEnabled(isEnabled);
8766 }
8767 } finally {
8768 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008769 }
8770 }
8771
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008772 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008773 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008774 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008775 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008776 mApp, subId, "isManualNetworkSelectionAllowed");
8777
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008778 boolean isAllowed = true;
8779 final long identity = Binder.clearCallingIdentity();
8780 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008781 Phone phone = getPhone(subId);
8782 if (phone != null) {
8783 isAllowed = phone.isCspPlmnEnabled();
8784 }
8785 } finally {
8786 Binder.restoreCallingIdentity(identity);
8787 }
8788 return isAllowed;
8789 }
8790
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008791 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8792 UiccProfile profile = port.getUiccProfile();
8793 if (profile == null ||
8794 profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8795 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8796 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008797 }
8798 return true;
8799 }
8800
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008801 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008802 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008803 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008804 mApp.getSystemService(AppOpsManager.class)
8805 .checkPackage(Binder.getCallingUid(), callingPackage);
8806
Jordan Liu1e142fc2019-04-22 15:10:43 -07008807 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008808 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008809 try {
8810 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008811 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008812 } catch (SecurityException e) {
8813 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8814 // has carrier privileges on an active UICC
8815 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8816 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008817 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008818 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008819 }
sandeepjsb6c87872021-09-27 15:34:44 +00008820 // checking compatibility, if calling app's target SDK is T and beyond.
8821 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8822 Binder.getCallingUid())) {
8823 isIccIdAccessRestricted = true;
8824 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008825 final long identity = Binder.clearCallingIdentity();
8826 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008827 UiccController uiccController = UiccController.getInstance();
8828 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008829 if (hasReadPermission) {
8830 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008831 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008832
8833 // Remove private info if the caller doesn't have access
8834 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8835 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008836 //setting the value after compatibility check
8837 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008838 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8839 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008840 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008841 if (card == null) {
8842 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008843 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008844 continue;
8845 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008846 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8847 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008848 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008849 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008850 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008851 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8852 for (UiccPortInfo portInfo : portInfos) {
8853 UiccPort port = uiccController.getUiccPortForSlot(
8854 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8855 if (port == null) {
8856 // assume no access if port is null
8857 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8858 continue;
8859 }
8860 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8861 uiccPortInfos.add(portInfo);
8862 } else {
8863 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8864 }
8865 }
8866 filteredInfos.add(new UiccCardInfo(
8867 cardInfo.isEuicc(),
8868 cardInfo.getCardId(),
8869 null,
8870 cardInfo.getPhysicalSlotIndex(),
8871 cardInfo.isRemovable(),
8872 cardInfo.isMultipleEnabledProfilesSupported(),
8873 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008874 }
8875 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008876 } finally {
8877 Binder.restoreCallingIdentity(identity);
8878 }
8879 }
8880
sandeepjsb6c87872021-09-27 15:34:44 +00008881 /**
8882 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8883 * generally private and require carrier privileges to view.
8884 *
8885 * @hide
8886 */
8887 @NonNull
8888 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8889 List<UiccPortInfo> portinfo = new ArrayList<>();
8890 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8891 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8892 }
8893 return new UiccCardInfo(
8894 cardInfo.isEuicc(),
8895 cardInfo.getCardId(),
8896 null,
8897 cardInfo.getPhysicalSlotIndex(),
8898 cardInfo.isRemovable(),
8899 cardInfo.isMultipleEnabledProfilesSupported(),
8900 portinfo
8901 );
8902 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008903
sandeepjsb6c87872021-09-27 15:34:44 +00008904 /**
8905 * @hide
8906 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8907 * These values are generally private and require carrier privileges to view.
8908 */
8909 @NonNull
8910 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8911 return new UiccPortInfo(
8912 UiccPortInfo.ICCID_REDACTED,
8913 portInfo.getPortIndex(),
8914 portInfo.getLogicalSlotIndex(),
8915 portInfo.isActive()
8916 );
8917 }
8918 @Override
8919 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008920 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00008921 mApp.getSystemService(AppOpsManager.class)
8922 .checkPackage(Binder.getCallingUid(), callingPackage);
8923
8924 boolean hasReadPermission = false;
8925 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008926
8927 try {
8928 enforceReadPrivilegedPermission("getUiccSlotsInfo");
8929 hasReadPermission = true;
8930 } catch (SecurityException e) {
8931 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8932 // has carrier privileges on an active UICC
8933 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8934 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8935 hasReadPermission = true;
8936 }
8937 }
8938
8939 // checking compatibility, if calling app's target SDK is T and beyond.
8940 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8941 Binder.getCallingUid())) {
8942 isLogicalSlotAccessRestricted = true;
8943 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008944 final long identity = Binder.clearCallingIdentity();
8945 try {
8946 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8947 if (slots == null) {
8948 Rlog.i(LOG_TAG, "slots is null.");
8949 return null;
8950 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008951 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8952 for (int i = 0; i < slots.length; i++) {
8953 UiccSlot slot = slots[i];
8954 if (slot == null) {
8955 continue;
8956 }
8957
Jordan Liu7be7e652019-05-06 18:55:02 +00008958 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008959 UiccCard card = slot.getUiccCard();
8960 if (card != null) {
8961 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008962 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008963 cardId = slot.getEid();
8964 if (TextUtils.isEmpty(cardId)) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008965 // If cardId is null, use iccId of default port as cardId. Check if has
8966 // read permission otherwise set to null.(card is null which means no
8967 // carrier permission)
8968 cardId = hasReadPermission ? slot.getIccId(
8969 TelephonyManager.DEFAULT_PORT_INDEX) : null;
Jordan Liu01bd00d2019-09-12 16:19:43 -07008970 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008971 }
8972
Jordan Liu857451f2019-05-09 16:35:35 -07008973 if (cardId != null) {
8974 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8975 // if cardId is an EID, it's all digits so this is fine
8976 cardId = IccUtils.stripTrailingFs(cardId);
8977 }
8978
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008979 int cardState = 0;
8980 switch (slot.getCardState()) {
8981 case CARDSTATE_ABSENT:
8982 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8983 break;
8984 case CARDSTATE_PRESENT:
8985 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8986 break;
8987 case CARDSTATE_ERROR:
8988 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8989 break;
8990 case CARDSTATE_RESTRICTED:
8991 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8992 break;
8993 default:
8994 break;
8995
8996 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008997 List<UiccPortInfo> portInfos = new ArrayList<>();
8998 int[] portIndexes = slot.getPortList();
8999 for (int portIdx : portIndexes) {
9000 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
9001 callingPackage, hasReadPermission));
9002 if (slot.isPortActive(portIdx)) {
9003 UiccPort port = slot.getUiccCard().getUiccPort(portIdx);
9004 portInfos.add(new UiccPortInfo(iccId, port.getPortIdx(),
9005 port.getPhoneId(), true));
9006 } else {
9007 portInfos.add(new UiccPortInfo(iccId, portIdx, -1, false));
9008 }
9009 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009010 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009011 slot.isEuicc(),
9012 cardId,
9013 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009014 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009015 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009016 //setting the value after compatibility check
9017 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009018 }
9019 return infos;
9020 } finally {
9021 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009022 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009023 }
9024
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009025 /* Returns null if doesn't have read permission or carrier privilege access. */
9026 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9027 boolean hasReadPermission) {
9028 String iccId = slot.getIccId(portIndex);
9029 if (hasReadPermission) { // if has read permission
9030 return iccId;
9031 } else {
9032 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9033 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9034 // if no read permission, checking carrier privilege access
9035 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9036 return iccId;
9037 }
9038 }
9039 }
9040 // No read permission or carrier privilege access.
9041 return UiccPortInfo.ICCID_REDACTED;
9042 }
9043
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009044 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009045 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009046 public boolean switchSlots(int[] physicalSlots) {
9047 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009048
9049 final long identity = Binder.clearCallingIdentity();
9050 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009051 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9052 for (int i = 0; i < physicalSlots.length; i++) {
9053 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9054 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9055 physicalSlots[i], i));
9056 }
9057 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009058 } finally {
9059 Binder.restoreCallingIdentity(identity);
9060 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009061 }
Jack Yu4c988042018-02-27 15:30:01 -08009062
9063 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009064 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9065 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9066 enforceModifyPermission();
9067
9068 final long identity = Binder.clearCallingIdentity();
9069 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009070 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009071 } finally {
9072 Binder.restoreCallingIdentity(identity);
9073 }
9074 }
9075
9076 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009077 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009078 final long identity = Binder.clearCallingIdentity();
9079 try {
9080 return UiccController.getInstance().getCardIdForDefaultEuicc();
9081 } finally {
9082 Binder.restoreCallingIdentity(identity);
9083 }
9084 }
9085
Pengquan Meng85728fb2018-03-12 16:31:21 -07009086 /**
goneil47ffb6e2018-04-06 15:40:58 -07009087 * A test API to reload the UICC profile.
9088 *
9089 * <p>Requires that the calling app has permission
9090 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9091 * @hide
9092 */
9093 @Override
9094 public void refreshUiccProfile(int subId) {
9095 enforceModifyPermission();
9096
9097 final long identity = Binder.clearCallingIdentity();
9098 try {
9099 Phone phone = getPhone(subId);
9100 if (phone == null) {
9101 return;
9102 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009103 UiccPort uiccPort = phone.getUiccPort();
9104 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009105 return;
9106 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009107 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009108 if (uiccProfile == null) {
9109 return;
9110 }
9111 uiccProfile.refresh();
9112 } finally {
9113 Binder.restoreCallingIdentity(identity);
9114 }
9115 }
9116
9117 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009118 * Returns false if the mobile data is disabled by default, otherwise return true.
9119 */
9120 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009121 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009122 }
9123
9124 /**
9125 * Returns true if the data roaming is enabled by default, i.e the system property
9126 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9127 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9128 */
9129 private boolean getDefaultDataRoamingEnabled(int subId) {
9130 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009131 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009132 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009133 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9134 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9135 return isDataRoamingEnabled;
9136 }
9137
9138 /**
9139 * Returns the default network type for the given {@code subId}, if the default network type is
9140 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9141 */
9142 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009143 List<Integer> list = TelephonyProperties.default_network();
9144 int phoneId = mSubscriptionController.getPhoneId(subId);
9145 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9146 return list.get(phoneId);
9147 }
9148 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009149 }
fionaxua13278b2018-03-21 00:08:13 -07009150
9151 @Override
9152 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009153 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009154 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009155
9156 final long identity = Binder.clearCallingIdentity();
9157 try {
9158 final Phone phone = getPhone(subId);
9159 if (phone == null) {
9160 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9161 return;
9162 }
chen xueaba88a2019-03-15 13:15:10 -07009163 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9164 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009165 if (carrierPrivilegeRules == null) {
9166 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9167 } else {
9168 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9169 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009170 } finally {
9171 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009172 }
fionaxua13278b2018-03-21 00:08:13 -07009173 }
9174
9175 @Override
9176 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009177 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009178
9179 final long identity = Binder.clearCallingIdentity();
9180 try {
9181 final Phone phone = getPhone(subId);
9182 if (phone == null) {
9183 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9184 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9185 }
9186 return phone.getCarrierIdListVersion();
9187 } finally {
9188 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009189 }
fionaxua13278b2018-03-21 00:08:13 -07009190 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009191
9192 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009193 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9194 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009195 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009196 mApp, subId, callingPackage, callingFeatureId,
9197 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009198 return -1;
9199 }
9200
9201 final long identity = Binder.clearCallingIdentity();
9202 try {
9203 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9204 } finally {
9205 Binder.restoreCallingIdentity(identity);
9206 }
9207 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009208
9209 @Override
9210 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009211 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009212 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009213 mApp, subId, "getCdmaRoamingMode");
9214
9215 final long identity = Binder.clearCallingIdentity();
9216 try {
9217 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9218 } finally {
9219 Binder.restoreCallingIdentity(identity);
9220 }
9221 }
9222
9223 @Override
9224 public boolean setCdmaRoamingMode(int subId, int mode) {
9225 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9226 mApp, subId, "setCdmaRoamingMode");
9227
9228 final long identity = Binder.clearCallingIdentity();
9229 try {
9230 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9231 } finally {
9232 Binder.restoreCallingIdentity(identity);
9233 }
9234 }
9235
9236 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009237 public int getCdmaSubscriptionMode(int subId) {
9238 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009239 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009240 mApp, subId, "getCdmaSubscriptionMode");
9241
9242 final long identity = Binder.clearCallingIdentity();
9243 try {
9244 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9245 } finally {
9246 Binder.restoreCallingIdentity(identity);
9247 }
9248 }
9249
9250 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009251 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9252 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9253 mApp, subId, "setCdmaSubscriptionMode");
9254
9255 final long identity = Binder.clearCallingIdentity();
9256 try {
9257 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9258 } finally {
9259 Binder.restoreCallingIdentity(identity);
9260 }
9261 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009262
sqianc5eccab2018-10-19 18:46:41 -07009263 @Override
sqian8c685422019-02-22 15:55:18 -08009264 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009265 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009266 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009267 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9268 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009269 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9270 }
9271 final long identity = Binder.clearCallingIdentity();
9272 try {
sqian854d44b2018-12-12 16:48:18 -08009273 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9274 for (Phone phone: PhoneFactory.getPhones()) {
9275 if (phone.getEmergencyNumberTracker() != null
9276 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9277 emergencyNumberListInternal.put(
9278 phone.getSubId(),
9279 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9280 }
sqian11b7a0e2018-12-05 18:48:28 -08009281 }
sqian854d44b2018-12-12 16:48:18 -08009282 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009283 } finally {
9284 Binder.restoreCallingIdentity(identity);
9285 }
sqianc5eccab2018-10-19 18:46:41 -07009286 }
9287
9288 @Override
sqian8c685422019-02-22 15:55:18 -08009289 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009290 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009291 if (!exactMatch) {
9292 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009293 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009294 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009295 }
9296 final long identity = Binder.clearCallingIdentity();
9297 try {
sqian854d44b2018-12-12 16:48:18 -08009298 for (Phone phone: PhoneFactory.getPhones()) {
9299 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009300 && phone.getEmergencyNumberTracker()
9301 .isEmergencyNumber(number, exactMatch)) {
9302 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009303 }
sqian11b7a0e2018-12-05 18:48:28 -08009304 }
9305 return false;
9306 } finally {
9307 Binder.restoreCallingIdentity(identity);
9308 }
9309 }
9310
sqianf4ca7ed2019-01-15 18:32:07 -08009311 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009312 * Start emergency callback mode for GsmCdmaPhone for testing.
9313 */
9314 @Override
9315 public void startEmergencyCallbackMode() {
9316 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9317 "startEmergencyCallbackMode");
9318 enforceModifyPermission();
9319 final long identity = Binder.clearCallingIdentity();
9320 try {
9321 for (Phone phone : PhoneFactory.getPhones()) {
9322 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9323 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9324 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9325 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9326 gsmCdmaPhone.obtainMessage(
9327 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9328 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9329 }
9330 }
9331 } finally {
9332 Binder.restoreCallingIdentity(identity);
9333 }
9334 }
9335
9336 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009337 * Update emergency number list for test mode.
9338 */
9339 @Override
9340 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9341 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9342 "updateEmergencyNumberListTestMode");
9343
9344 final long identity = Binder.clearCallingIdentity();
9345 try {
9346 for (Phone phone: PhoneFactory.getPhones()) {
9347 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9348 if (tracker != null) {
9349 tracker.executeEmergencyNumberTestModeCommand(action, num);
9350 }
9351 }
9352 } finally {
9353 Binder.restoreCallingIdentity(identity);
9354 }
9355 }
9356
9357 /**
9358 * Get the full emergency number list for test mode.
9359 */
9360 @Override
9361 public List<String> getEmergencyNumberListTestMode() {
9362 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9363 "getEmergencyNumberListTestMode");
9364
9365 final long identity = Binder.clearCallingIdentity();
9366 try {
9367 Set<String> emergencyNumbers = new HashSet<>();
9368 for (Phone phone: PhoneFactory.getPhones()) {
9369 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9370 if (tracker != null) {
9371 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9372 emergencyNumbers.add(num.getNumber());
9373 }
9374 }
9375 }
9376 return new ArrayList<>(emergencyNumbers);
9377 } finally {
9378 Binder.restoreCallingIdentity(identity);
9379 }
9380 }
9381
chen xud6b45bd2018-10-30 22:27:10 -07009382 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009383 public int getEmergencyNumberDbVersion(int subId) {
9384 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9385
9386 final long identity = Binder.clearCallingIdentity();
9387 try {
9388 final Phone phone = getPhone(subId);
9389 if (phone == null) {
9390 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9391 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9392 }
9393 return phone.getEmergencyNumberDbVersion();
9394 } finally {
9395 Binder.restoreCallingIdentity(identity);
9396 }
9397 }
9398
9399 @Override
9400 public void notifyOtaEmergencyNumberDbInstalled() {
9401 enforceModifyPermission();
9402
9403 final long identity = Binder.clearCallingIdentity();
9404 try {
9405 for (Phone phone: PhoneFactory.getPhones()) {
9406 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9407 if (tracker != null) {
9408 tracker.updateOtaEmergencyNumberDatabase();
9409 }
9410 }
9411 } finally {
9412 Binder.restoreCallingIdentity(identity);
9413 }
9414 }
9415
9416 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009417 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009418 enforceActiveEmergencySessionPermission();
9419
9420 final long identity = Binder.clearCallingIdentity();
9421 try {
9422 for (Phone phone: PhoneFactory.getPhones()) {
9423 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9424 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009425 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9426 }
9427 }
9428 } finally {
9429 Binder.restoreCallingIdentity(identity);
9430 }
9431 }
9432
9433 @Override
9434 public void resetOtaEmergencyNumberDbFilePath() {
9435 enforceActiveEmergencySessionPermission();
9436
9437 final long identity = Binder.clearCallingIdentity();
9438 try {
9439 for (Phone phone: PhoneFactory.getPhones()) {
9440 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9441 if (tracker != null) {
9442 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009443 }
9444 }
9445 } finally {
9446 Binder.restoreCallingIdentity(identity);
9447 }
9448 }
9449
9450 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009451 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9452 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9453 Phone phone = getPhone(subId);
9454 if (phone == null) {
9455 return null;
9456 }
9457 final long identity = Binder.clearCallingIdentity();
9458 try {
9459 UiccProfile profile = UiccController.getInstance()
9460 .getUiccProfileForPhone(phone.getPhoneId());
9461 if (profile != null) {
9462 return profile.getCertsFromCarrierPrivilegeAccessRules();
9463 }
9464 } finally {
9465 Binder.restoreCallingIdentity(identity);
9466 }
9467 return null;
9468 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009469
9470 /**
9471 * Enable or disable a modem stack.
9472 */
9473 @Override
9474 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9475 enforceModifyPermission();
9476
9477 final long identity = Binder.clearCallingIdentity();
9478 try {
9479 Phone phone = PhoneFactory.getPhone(slotIndex);
9480 if (phone == null) {
9481 return false;
9482 } else {
9483 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9484 }
9485 } finally {
9486 Binder.restoreCallingIdentity(identity);
9487 }
9488 }
Michelecea4cf22018-12-21 15:00:11 -08009489
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009490 /**
9491 * Whether a modem stack is enabled or not.
9492 */
9493 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009494 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9495 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009496 Phone phone = PhoneFactory.getPhone(slotIndex);
9497 if (phone == null) return false;
9498
9499 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009500 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9501 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009502 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9503 }
9504
9505 final long identity = Binder.clearCallingIdentity();
9506 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009507 try {
9508 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9509 } catch (NoSuchElementException ex) {
9510 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9511 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009512 } finally {
9513 Binder.restoreCallingIdentity(identity);
9514 }
9515 }
9516
Michelecea4cf22018-12-21 15:00:11 -08009517 @Override
Michele0ea7d782019-03-19 14:58:42 -07009518 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009519 enforceModifyPermission();
9520
9521 final long identity = Binder.clearCallingIdentity();
9522 try {
9523 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009524 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009525 .commit();
9526 } finally {
9527 Binder.restoreCallingIdentity(identity);
9528 }
9529 }
9530
9531 @Override
Michele0ea7d782019-03-19 14:58:42 -07009532 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009533 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009534 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009535 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9536 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009537 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009538 }
Michelecea4cf22018-12-21 15:00:11 -08009539
9540 final long identity = Binder.clearCallingIdentity();
9541 try {
Michele0ea7d782019-03-19 14:58:42 -07009542 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009543 } finally {
9544 Binder.restoreCallingIdentity(identity);
9545 }
9546 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009547
Michele0ea7d782019-03-19 14:58:42 -07009548 @TelephonyManager.IsMultiSimSupportedResult
9549 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009550 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9551 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9552 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009553 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9554 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009555 }
9556 // Check if the hardware supports multisim functionality. If usage of multisim is not
9557 // supported by the modem, indicate that it is restricted.
9558 PhoneCapability staticCapability =
9559 mPhoneConfigurationManager.getStaticPhoneCapability();
9560 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009561 loge("isMultiSimSupportedInternal: no static configuration available");
9562 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009563 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009564 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009565 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9566 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009567 }
9568 // Check if support of multiple SIMs is restricted by carrier
9569 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009570 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009571 }
9572
Michele0ea7d782019-03-19 14:58:42 -07009573 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009574 }
9575
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009576 /**
9577 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009578 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9579 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9580 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009581 * @param numOfSims number of active sims we want to switch to
9582 */
9583 @Override
9584 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009585 if (numOfSims == 1) {
9586 enforceModifyPermission();
9587 } else {
9588 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9589 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9590 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009591 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009592
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009593 try {
Michele30b57b22019-03-01 12:01:14 -08009594 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009595 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009596 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9597 return;
9598 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009599 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9600 } finally {
9601 Binder.restoreCallingIdentity(identity);
9602 }
9603 }
9604
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009605 @Override
9606 public boolean isApplicationOnUicc(int subId, int appType) {
9607 enforceReadPrivilegedPermission("isApplicationOnUicc");
9608 Phone phone = getPhone(subId);
9609 if (phone == null) {
9610 return false;
9611 }
9612 final long identity = Binder.clearCallingIdentity();
9613 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009614 UiccPort uiccPort = phone.getUiccPort();
9615 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009616 return false;
9617 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009618 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009619 if (uiccProfile == null) {
9620 return false;
9621 }
9622 if (TelephonyManager.APPTYPE_SIM <= appType
9623 && appType <= TelephonyManager.APPTYPE_ISIM) {
9624 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9625 }
9626 return false;
9627 } finally {
9628 Binder.restoreCallingIdentity(identity);
9629 }
9630 }
9631
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009632 /**
chen xub4baa772019-04-03 10:23:41 -07009633 * Get whether making changes to modem configurations will trigger reboot.
9634 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009635 */
9636 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009637 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9638 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009639 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009640 mApp, subId, callingPackage, callingFeatureId,
9641 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009642 return false;
9643 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009644 final long identity = Binder.clearCallingIdentity();
9645 try {
9646 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9647 } finally {
9648 Binder.restoreCallingIdentity(identity);
9649 }
9650 }
9651
Nathan Harold29f5f052019-02-15 13:41:57 -08009652 private void updateModemStateMetrics() {
9653 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9654 // TODO: check the state for each modem if the api is ready.
9655 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9656 }
9657
Pengquan Meng3889a572019-01-23 11:16:29 -08009658 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009659 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009660 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009661 // Verify that the callingPackage belongs to the calling UID
9662 mApp.getSystemService(AppOpsManager.class)
9663 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009664 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009665 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009666 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009667 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9668 if (slotInfos != null) {
9669 for (int i = 0; i < slotInfos.length; i++) {
9670 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9671 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9672 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9673 portInfo.getLogicalSlotIndex()));
9674 }
9675 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009676 }
9677 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009678 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009679 } finally {
9680 Binder.restoreCallingIdentity(identity);
9681 }
9682 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009683
9684 /**
9685 * Get the IRadio HAL Version
9686 */
9687 @Override
9688 public int getRadioHalVersion() {
9689 Phone phone = getDefaultPhone();
9690 if (phone == null) return -1;
9691 HalVersion hv = phone.getHalVersion();
9692 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9693 return hv.major * 100 + hv.minor;
9694 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009695
9696 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009697 * Get the current calling package name.
9698 * @return the current calling package name
9699 */
9700 @Override
9701 public String getCurrentPackageName() {
9702 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9703 }
9704
9705 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009706 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9707 * corresponding network requests on a subId.
9708 *
9709 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009710 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009711 * 2) APN is un-metered for this subscription, or
9712 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009713 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009714 *
9715 * @return whether data is allowed for a apn type.
9716 *
9717 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009718 */
9719 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009720 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009721 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9722 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009723
9724 // Now that all security checks passes, perform the operation as ourselves.
9725 final long identity = Binder.clearCallingIdentity();
9726 try {
9727 Phone phone = getPhone(subId);
9728 if (phone == null) return false;
9729
Jack Yu41407ee2019-05-13 16:54:09 -07009730 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009731 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9732 } finally {
9733 Binder.restoreCallingIdentity(identity);
9734 }
9735 }
9736
9737 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009738 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009739 enforceReadPrivilegedPermission("isApnMetered");
9740
9741 // Now that all security checks passes, perform the operation as ourselves.
9742 final long identity = Binder.clearCallingIdentity();
9743 try {
9744 Phone phone = getPhone(subId);
9745 if (phone == null) return true; // By default return true.
9746
Jack Yu41407ee2019-05-13 16:54:09 -07009747 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009748 } finally {
9749 Binder.restoreCallingIdentity(identity);
9750 }
9751 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009752
9753 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009754 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9755 int subscriptionId, IBooleanConsumer resultCallback) {
9756 enforceModifyPermission();
9757 long token = Binder.clearCallingIdentity();
9758 try {
9759 Phone phone = getPhone(subscriptionId);
9760 if (phone == null) {
9761 try {
9762 if (resultCallback != null) {
9763 resultCallback.accept(false);
9764 }
9765 } catch (RemoteException e) {
9766 // ignore
9767 }
9768 return;
9769 }
9770 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9771 Pair.create(specifiers, (x) -> {
9772 try {
9773 if (resultCallback != null) {
9774 resultCallback.accept(x);
9775 }
9776 } catch (RemoteException e) {
9777 // ignore
9778 }
9779 });
9780 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9781 } finally {
9782 Binder.restoreCallingIdentity(token);
9783 }
9784 }
9785
9786 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009787 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9788 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009789 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009790 mApp, subId, "getSystemSelectionChannels");
9791 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9792 final long identity = Binder.clearCallingIdentity();
9793 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009794 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9795 if (result instanceof IllegalStateException) {
9796 throw (IllegalStateException) result;
9797 }
9798 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009799 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9800 return specifiers;
9801 } finally {
9802 Binder.restoreCallingIdentity(identity);
9803 }
9804 }
9805
9806 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009807 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009808 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009809 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9810 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9811 if (iccRecords == null) {
9812 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9813 return false;
9814 }
9815 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9816 }
9817
9818 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009819 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9820 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009821 if (callingPackage == null) {
9822 callingPackage = getCurrentPackageName();
9823 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009824 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9825 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009826 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9827 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009828 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9829 }
9830 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9831 Intent intent = new Intent();
9832 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9833 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9834 // Bring up choose default SMS subscription dialog right now
9835 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9836 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9837 mApp.startActivity(intent);
9838 }
chen xud5ca2d52019-05-28 15:20:57 -07009839
9840 @Override
9841 public String getMmsUAProfUrl(int subId) {
9842 //TODO investigate if this API should require proper permission check in R b/133791609
9843 final long identity = Binder.clearCallingIdentity();
9844 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009845 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9846 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9847 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9848 return carrierUAProfUrl;
9849 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009850 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9851 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009852 } finally {
9853 Binder.restoreCallingIdentity(identity);
9854 }
9855 }
9856
9857 @Override
9858 public String getMmsUserAgent(int subId) {
9859 //TODO investigate if this API should require proper permission check in R b/133791609
9860 final long identity = Binder.clearCallingIdentity();
9861 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009862 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9863 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9864 if (!TextUtils.isEmpty(carrierUserAgent)) {
9865 return carrierUserAgent;
9866 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009867 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9868 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009869 } finally {
9870 Binder.restoreCallingIdentity(identity);
9871 }
9872 }
Jack Yub07d4972019-05-28 16:12:25 -07009873
9874 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009875 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9876 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009877
Jack Yub07d4972019-05-28 16:12:25 -07009878 final long identity = Binder.clearCallingIdentity();
9879 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009880 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009881 if (phone == null) return false;
9882
Hall Liua62f5da2020-09-25 10:42:19 -07009883 switch (policy) {
9884 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9885 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9886 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9887 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9888 default:
9889 throw new IllegalArgumentException(policy + " is not a valid policy");
9890 }
Jack Yub07d4972019-05-28 16:12:25 -07009891 } finally {
9892 Binder.restoreCallingIdentity(identity);
9893 }
9894 }
9895
9896 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009897 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009898 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009899 enforceModifyPermission();
9900
changbettyd5c246e2019-12-24 15:40:37 +08009901 final long identity = Binder.clearCallingIdentity();
9902 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009903 Phone phone = getPhone(subscriptionId);
9904 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009905
Hall Liua62f5da2020-09-25 10:42:19 -07009906 switch (policy) {
9907 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9908 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9909 break;
9910 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9911 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9912 break;
9913 default:
9914 throw new IllegalArgumentException(policy + " is not a valid policy");
9915 }
changbettyd5c246e2019-12-24 15:40:37 +08009916 } finally {
9917 Binder.restoreCallingIdentity(identity);
9918 }
9919 }
9920
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009921 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009922 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009923 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9924 * otherwise.
9925 */
9926 @Override
9927 public void setCepEnabled(boolean isCepEnabled) {
9928 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9929
9930 final long identity = Binder.clearCallingIdentity();
9931 try {
9932 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9933 for (Phone phone : PhoneFactory.getPhones()) {
9934 Phone defaultPhone = phone.getImsPhone();
9935 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9936 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9937 ImsPhoneCallTracker imsPhoneCallTracker =
9938 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9939 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9940 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9941 + imsPhone.getMsisdn());
9942 }
9943 }
9944 } finally {
9945 Binder.restoreCallingIdentity(identity);
9946 }
9947 }
allenwtsu46dcc572020-01-08 18:24:03 +08009948
9949 /**
9950 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9951 *
9952 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9953 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9954 * before being read.
9955 */
9956 @Override
9957 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9958 isCompressed) {
9959 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9960 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009961 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9962 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9963 }
9964 if (!isImsAvailableOnDevice()) {
9965 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9966 "IMS not available on device.");
9967 }
9968
9969 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009970 try {
Hui Wang761a6682020-10-31 05:12:53 +00009971 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9972 } finally {
9973 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009974 }
9975 }
zoey chene02881a2019-12-30 16:11:23 +08009976
9977 @Override
9978 public boolean isIccLockEnabled(int subId) {
9979 enforceReadPrivilegedPermission("isIccLockEnabled");
9980
9981 // Now that all security checks passes, perform the operation as ourselves.
9982 final long identity = Binder.clearCallingIdentity();
9983 try {
9984 Phone phone = getPhone(subId);
9985 if (phone != null && phone.getIccCard() != null) {
9986 return phone.getIccCard().getIccLockEnabled();
9987 } else {
9988 return false;
9989 }
9990 } finally {
9991 Binder.restoreCallingIdentity(identity);
9992 }
9993 }
9994
9995 /**
9996 * Set the ICC pin lock enabled or disabled.
9997 *
9998 * @return an integer representing the status of IccLock enabled or disabled in the following
9999 * three cases:
10000 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10001 * successfully.
10002 * - Positive number and zero for remaining password attempts.
10003 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10004 *
10005 */
10006 @Override
10007 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10008 enforceModifyPermission();
10009
10010 Phone phone = getPhone(subId);
10011 if (phone == null) {
10012 return 0;
10013 }
10014 // Now that all security checks passes, perform the operation as ourselves.
10015 final long identity = Binder.clearCallingIdentity();
10016 try {
10017 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10018 new Pair<Boolean, String>(enabled, password), phone, null);
10019 return attemptsRemaining;
10020
10021 } catch (Exception e) {
10022 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10023 } finally {
10024 Binder.restoreCallingIdentity(identity);
10025 }
10026 return 0;
10027 }
10028
10029 /**
10030 * Change the ICC password used in ICC pin lock.
10031 *
10032 * @return an integer representing the status of IccLock changed in the following three cases:
10033 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10034 * - Positive number and zero for remaining password attempts.
10035 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10036 *
10037 */
10038 @Override
10039 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10040 enforceModifyPermission();
10041
10042 Phone phone = getPhone(subId);
10043 if (phone == null) {
10044 return 0;
10045 }
10046 // Now that all security checks passes, perform the operation as ourselves.
10047 final long identity = Binder.clearCallingIdentity();
10048 try {
10049 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10050 new Pair<String, String>(oldPassword, newPassword), phone, null);
10051 return attemptsRemaining;
10052
10053 } catch (Exception e) {
10054 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10055 } finally {
10056 Binder.restoreCallingIdentity(identity);
10057 }
10058 return 0;
10059 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010060
10061 /**
10062 * Request for receiving user activity notification
10063 */
10064 @Override
10065 public void requestUserActivityNotification() {
10066 if (!mNotifyUserActivity.get()
10067 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10068 mNotifyUserActivity.set(true);
10069 }
10070 }
10071
10072 /**
10073 * Called when userActivity is signalled in the power manager.
10074 * This is safe to call from any thread, with any window manager locks held or not.
10075 */
10076 @Override
10077 public void userActivity() {
10078 // ***************************************
10079 // * Inherited from PhoneWindowManager *
10080 // ***************************************
10081 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10082 // WITH ITS LOCKS HELD.
10083 //
10084 // This code must be VERY careful about the locks
10085 // it acquires.
10086 // In fact, the current code acquires way too many,
10087 // and probably has lurking deadlocks.
10088
10089 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10090 throw new SecurityException("Only the OS may call notifyUserActivity()");
10091 }
10092
10093 if (mNotifyUserActivity.getAndSet(false)) {
10094 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10095 USER_ACTIVITY_NOTIFICATION_DELAY);
10096 }
10097 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010098
10099 @Override
10100 public boolean canConnectTo5GInDsdsMode() {
10101 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10102 }
Jack Yud10cdd42020-09-28 20:28:01 -070010103
10104 @Override
10105 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10106 String callingFeatureId) {
10107 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10108 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10109 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10110 }
10111
10112 Phone phone = getPhone(subId);
10113 if (phone == null) {
10114 throw new RuntimeException("phone is not available");
10115 }
10116 // Now that all security checks passes, perform the operation as ourselves.
10117 final long identity = Binder.clearCallingIdentity();
10118 try {
10119 return phone.getEquivalentHomePlmns();
10120 } finally {
10121 Binder.restoreCallingIdentity(identity);
10122 }
10123 }
Daniel Bright59e67312020-11-13 11:49:37 -080010124
10125 @Override
10126 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010127 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10128 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010129 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010130 if (radioInterfaceCapabilities == null) {
10131 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010132 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010133 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010134 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010135
Hui Wang641e81c2020-10-12 12:14:23 -070010136 @Override
10137 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10138 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010139 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10140 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10141 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10142 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10143 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010144 if (DBG) {
10145 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10146 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10147 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10148 }
10149
10150 if (!SubscriptionManager.isValidSubscriptionId(subId)
10151 || appType < TelephonyManager.APPTYPE_UNKNOWN
10152 || appType > TelephonyManager.APPTYPE_ISIM
10153 || nafUrl == null || securityProtocol == null || callback == null) {
10154 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10155 if (callback != null) {
10156 try {
10157 callback.onAuthenticationFailure(
10158 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10159 } catch (RemoteException exception) {
10160 log("Fail to notify onAuthenticationFailure due to " + exception);
10161 }
10162 return;
10163 }
10164 }
10165
10166 final long token = Binder.clearCallingIdentity();
10167 try {
10168 getGbaManager(subId).bootstrapAuthenticationRequest(
10169 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10170 forceBootStrapping, callback));
10171 } finally {
10172 Binder.restoreCallingIdentity(token);
10173 }
10174 }
10175
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010176 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010177 * Attempts to set the radio power state for all phones for thermal reason.
10178 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010179 * requested radio power state will actually be set. See {@link
10180 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10181 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010182 * @param enable {@code true} if trying to turn radio on.
10183 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10184 * false}.
10185 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010186 private boolean setRadioPowerForThermal(boolean enable) {
10187 boolean isPhoneAvailable = false;
10188 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10189 Phone phone = PhoneFactory.getPhone(i);
10190 if (phone != null) {
10191 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10192 isPhoneAvailable = true;
10193 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010194 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010195
10196 // return true if successfully informed the phone object about the thermal radio power
10197 // request.
10198 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010199 }
10200
10201 private int handleDataThrottlingRequest(int subId,
10202 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010203 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10204 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10205 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10206 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10207 throw new IllegalArgumentException("modem does not support data throttling");
10208 }
10209
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010210 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10211 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010212 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010213 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10214 }
10215
10216 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10217
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010218 if (isDataThrottlingSupported) {
10219 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010220 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010221 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10222 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10223 } else if (thermalMitigationResult
10224 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010225 log("Modem likely does not support data throttling on secondary carrier. Data " +
10226 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10227 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010228 }
10229 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010230 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010231
10232 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010233 }
10234
Jack Nudelman644b91a2021-03-12 14:09:48 -080010235 private static List<String> getThermalMitigationAllowlist(Context context) {
10236 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10237 for (String pckg : context.getResources()
10238 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10239 sThermalMitigationAllowlistedPackages.add(pckg);
10240 }
10241 }
10242
10243 return sThermalMitigationAllowlistedPackages;
10244 }
10245
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010246 private boolean isAnyPhoneInEmergencyState() {
10247 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10248 if (tm.isInEmergencyCall()) {
10249 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10250 return true;
10251 }
10252 for (Phone phone : PhoneFactory.getPhones()) {
10253 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10254 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10255 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10256 + phone.isInEcm());
10257 return true;
10258 }
10259 }
10260
10261 return false;
10262 }
10263
Jack Nudelman644b91a2021-03-12 14:09:48 -080010264 /**
10265 * Used by shell commands to add an authorized package name for thermal mitigation.
10266 * @param packageName name of package to be allowlisted
10267 * @param context
10268 */
10269 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10270 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10271 sThermalMitigationAllowlistedPackages.add(packageName);
10272 }
10273
10274 /**
10275 * Used by shell commands to remove an authorized package name for thermal mitigation.
10276 * @param packageName name of package to remove from allowlist
10277 * @param context
10278 */
10279 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10280 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10281 sThermalMitigationAllowlistedPackages.remove(packageName);
10282 }
10283
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010284 /**
10285 * Thermal mitigation request to control functionalities at modem.
10286 *
10287 * @param subId the id of the subscription.
10288 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010289 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010290 *
10291 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10292 */
10293 @Override
10294 @ThermalMitigationResult
10295 public int sendThermalMitigationRequest(
10296 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010297 ThermalMitigationRequest thermalMitigationRequest,
10298 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010299 enforceModifyPermission();
10300
Jack Nudelman644b91a2021-03-12 14:09:48 -080010301 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10302 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10303 .contains(callingPackage)) {
10304 throw new SecurityException("Calling package must be configured in the device config. "
10305 + "calling package: " + callingPackage);
10306 }
10307
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010308 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10309 final long identity = Binder.clearCallingIdentity();
10310
10311 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10312 try {
10313 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10314 switch (thermalMitigationAction) {
10315 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10316 thermalMitigationResult =
10317 handleDataThrottlingRequest(subId,
10318 thermalMitigationRequest.getDataThrottlingRequest());
10319 break;
10320 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10321 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10322 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10323 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10324 }
10325
10326 // Ensure that radio is on. If not able to power on due to phone being
10327 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010328 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010329 thermalMitigationResult =
10330 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10331 break;
10332 }
10333
10334 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10335 false);
10336 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10337 break;
10338 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10339 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10340 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10341 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10342 }
10343
10344 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10345 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010346 Phone phone = getPhone(subId);
10347 if (phone == null) {
10348 thermalMitigationResult =
10349 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10350 break;
10351 }
10352
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010353 TelephonyConnectionService service =
10354 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010355 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010356 Log.e(LOG_TAG, "An emergency call is pending");
10357 thermalMitigationResult =
10358 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10359 break;
10360 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010361 thermalMitigationResult =
10362 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10363 break;
10364 }
10365 } else {
10366 thermalMitigationResult =
10367 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10368 break;
10369 }
10370
10371 // Turn radio off. If not able to power off due to phone being unavailable,
10372 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010373 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010374 thermalMitigationResult =
10375 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10376 break;
10377 }
10378 thermalMitigationResult =
10379 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10380 break;
10381 default:
10382 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10383 + "not exist. Requested action: " + thermalMitigationAction);
10384 }
10385 } catch (IllegalArgumentException e) {
10386 throw e;
10387 } catch (Exception e) {
10388 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10389 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10390 } finally {
10391 Binder.restoreCallingIdentity(identity);
10392 }
10393
10394 if (DBG) {
10395 log("thermalMitigationRequest returning with thermalMitigationResult: "
10396 + thermalMitigationResult);
10397 }
10398
10399 return thermalMitigationResult;
10400 }
Hui Wang641e81c2020-10-12 12:14:23 -070010401
10402 /**
10403 * Set the GbaService Package Name that Telephony will bind to.
10404 *
10405 * @param subId The sim that the GbaService is associated with.
10406 * @param packageName The name of the package to be replaced with.
10407 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10408 */
10409 @Override
10410 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10411 enforceModifyPermission();
10412
10413 final long identity = Binder.clearCallingIdentity();
10414 try {
10415 return getGbaManager(subId).overrideServicePackage(packageName);
10416 } finally {
10417 Binder.restoreCallingIdentity(identity);
10418 }
10419 }
10420
10421 /**
10422 * Return the package name of the currently bound GbaService.
10423 *
10424 * @param subId The sim that the GbaService is associated with.
10425 * @return the package name of the GbaService configuration, null if GBA is not supported.
10426 */
10427 @Override
10428 public String getBoundGbaService(int subId) {
10429 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10430
10431 final long identity = Binder.clearCallingIdentity();
10432 try {
10433 return getGbaManager(subId).getServicePackage();
10434 } finally {
10435 Binder.restoreCallingIdentity(identity);
10436 }
10437 }
10438
10439 /**
10440 * Set the release time for telephony to unbind GbaService.
10441 *
10442 * @param subId The sim that the GbaService is associated with.
10443 * @param interval The release time to unbind GbaService by millisecond.
10444 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10445 */
10446 @Override
10447 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10448 enforceModifyPermission();
10449
10450 final long identity = Binder.clearCallingIdentity();
10451 try {
10452 return getGbaManager(subId).overrideReleaseTime(interval);
10453 } finally {
10454 Binder.restoreCallingIdentity(identity);
10455 }
10456 }
10457
10458 /**
10459 * Return the release time for telephony to unbind GbaService.
10460 *
10461 * @param subId The sim that the GbaService is associated with.
10462 * @return The release time to unbind GbaService by millisecond.
10463 */
10464 @Override
10465 public int getGbaReleaseTime(int subId) {
10466 enforceReadPrivilegedPermission("getGbaReleaseTime");
10467
10468 final long identity = Binder.clearCallingIdentity();
10469 try {
10470 return getGbaManager(subId).getReleaseTime();
10471 } finally {
10472 Binder.restoreCallingIdentity(identity);
10473 }
10474 }
10475
10476 private GbaManager getGbaManager(int subId) {
10477 GbaManager instance = GbaManager.getInstance(subId);
10478 if (instance == null) {
10479 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10480 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10481 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10482 }
10483 return instance;
10484 }
Hui Wang761a6682020-10-31 05:12:53 +000010485
10486 /**
10487 * indicate whether the device and the carrier can support
10488 * RCS VoLTE single registration.
10489 */
10490 @Override
10491 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010492 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10493 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10494 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10495 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010496
10497 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10498 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10499 }
10500
10501 final long identity = Binder.clearCallingIdentity();
10502 try {
10503 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10504 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010505 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10506 if (isCapable != null) {
10507 return isCapable;
10508 }
Hui Wang761a6682020-10-31 05:12:53 +000010509 }
Hui Wang67af90e2021-06-04 16:57:15 -070010510 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10511 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010512 } finally {
10513 Binder.restoreCallingIdentity(identity);
10514 }
10515 }
10516
10517 /**
10518 * Register RCS provisioning callback.
10519 */
10520 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010521 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010522 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010523 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010524 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010525 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10526 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010527
10528 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10529 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10530 }
10531 if (!isImsAvailableOnDevice()) {
10532 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10533 "IMS not available on device.");
10534 }
10535
10536 final long identity = Binder.clearCallingIdentity();
10537 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010538 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010539 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010540 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10541 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010542 }
Hui Wang761a6682020-10-31 05:12:53 +000010543 } finally {
10544 Binder.restoreCallingIdentity(identity);
10545 }
10546 }
10547
10548 /**
10549 * Unregister RCS provisioning callback.
10550 */
10551 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010552 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010553 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010554 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010555 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010556 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10557 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010558
10559 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10560 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10561 }
10562 if (!isImsAvailableOnDevice()) {
10563 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10564 "IMS not available on device.");
10565 }
10566
10567 final long identity = Binder.clearCallingIdentity();
10568 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010569 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010570 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010571 } finally {
10572 Binder.restoreCallingIdentity(identity);
10573 }
10574 }
10575
10576 /**
10577 * trigger RCS reconfiguration.
10578 */
10579 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010580 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10581 "triggerRcsReconfiguration",
10582 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010583
10584 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10585 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10586 }
10587 if (!isImsAvailableOnDevice()) {
10588 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10589 "IMS not available on device.");
10590 }
10591
10592 final long identity = Binder.clearCallingIdentity();
10593 try {
10594 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10595 } finally {
10596 Binder.restoreCallingIdentity(identity);
10597 }
10598 }
10599
10600 /**
10601 * Provide the client configuration parameters of the RCS application.
10602 */
10603 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010604 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10605 "setRcsClientConfiguration",
10606 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010607
10608 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10609 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10610 }
10611 if (!isImsAvailableOnDevice()) {
10612 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10613 "IMS not available on device.");
10614 }
10615
10616 final long identity = Binder.clearCallingIdentity();
10617
10618 try {
10619 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10620 if (configBinder == null) {
10621 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010622 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10623 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010624 } else {
10625 configBinder.setRcsClientConfiguration(rcc);
10626 }
joonhunshin3e154242021-09-17 06:33:39 +000010627
10628 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10629 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010630 } catch (RemoteException e) {
10631 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010632 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10633 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010634 } finally {
10635 Binder.restoreCallingIdentity(identity);
10636 }
10637 }
10638
10639 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010640 * Enables or disables the test mode for RCS VoLTE single registration.
10641 */
10642 @Override
10643 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10644 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10645 "setRcsSingleRegistrationTestModeEnabled");
10646
10647 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10648 }
10649
10650 /**
10651 * Gets the test mode for RCS VoLTE single registration.
10652 */
10653 @Override
10654 public boolean getRcsSingleRegistrationTestModeEnabled() {
10655 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10656 "getRcsSingleRegistrationTestModeEnabled");
10657
10658 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10659 }
10660
10661 /**
Hui Wang761a6682020-10-31 05:12:53 +000010662 * Overrides the config of RCS VoLTE single registration enabled for the device.
10663 */
10664 @Override
10665 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10666 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10667 "setDeviceSingleRegistrationEnabledOverride");
10668 enforceModifyPermission();
10669
10670 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10671 : Boolean.parseBoolean(enabledStr);
10672 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010673 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010674 }
10675
10676 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010677 * Sends a device to device communication message. Only usable via shell.
10678 * @param message message to send.
10679 * @param value message value.
10680 */
10681 @Override
10682 public void sendDeviceToDeviceMessage(int message, int value) {
10683 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010684 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010685 enforceModifyPermission();
10686
10687 final long identity = Binder.clearCallingIdentity();
10688 try {
10689 TelephonyConnectionService service =
10690 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10691 if (service == null) {
10692 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10693 return;
10694 }
10695 service.sendTestDeviceToDeviceMessage(message, value);
10696 } finally {
10697 Binder.restoreCallingIdentity(identity);
10698 }
10699 }
10700
Tyler Gunnbabbda02021-02-10 11:05:02 -080010701 /**
10702 * Sets the specified device to device transport active.
10703 * @param transport The transport to set active.
10704 */
10705 @Override
10706 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10707 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10708 "setActiveDeviceToDeviceTransport");
10709 enforceModifyPermission();
10710
10711 final long identity = Binder.clearCallingIdentity();
10712 try {
10713 TelephonyConnectionService service =
10714 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10715 if (service == null) {
10716 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10717 return;
10718 }
10719 service.setActiveDeviceToDeviceTransport(transport);
10720 } finally {
10721 Binder.restoreCallingIdentity(identity);
10722 }
10723 }
Tyler Gunn92479152021-01-20 16:30:10 -080010724
Tyler Gunnd4339262021-05-03 14:46:49 -070010725 @Override
10726 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10727 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10728 "setDeviceToDeviceForceEnabled");
10729
10730 final long identity = Binder.clearCallingIdentity();
10731 try {
10732 Arrays.stream(PhoneFactory.getPhones()).forEach(
10733 p -> {
10734 Phone thePhone = p.getImsPhone();
10735 if (thePhone != null && thePhone instanceof ImsPhone) {
10736 ImsPhone imsPhone = (ImsPhone) thePhone;
10737 CallTracker tracker = imsPhone.getCallTracker();
10738 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10739 ImsPhoneCallTracker imsPhoneCallTracker =
10740 (ImsPhoneCallTracker) tracker;
10741 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10742 }
10743 }
10744 }
10745 );
10746 } finally {
10747 Binder.restoreCallingIdentity(identity);
10748 }
10749 }
10750
Tyler Gunn92479152021-01-20 16:30:10 -080010751 /**
Hui Wang761a6682020-10-31 05:12:53 +000010752 * Gets the config of RCS VoLTE single registration enabled for the device.
10753 */
10754 @Override
10755 public boolean getDeviceSingleRegistrationEnabled() {
10756 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10757 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10758 }
10759
10760 /**
10761 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10762 */
10763 @Override
10764 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10765 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10766 "setCarrierSingleRegistrationEnabledOverride");
10767 enforceModifyPermission();
10768
10769 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10770 : Boolean.parseBoolean(enabledStr);
10771 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10772 subId, enabled);
10773 }
10774
10775 /**
10776 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10777 */
10778 @Override
10779 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10780 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10781 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10782 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010783
10784 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010785 * Overrides the ims feature validation result
10786 */
10787 @Override
10788 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10789 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10790 "setImsFeatureValidationOverride");
10791
10792 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10793 : Boolean.parseBoolean(enabledStr);
10794 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10795 subId, enabled);
10796 }
10797
10798 /**
10799 * Gets the ims feature validation override value
10800 */
10801 @Override
10802 public boolean getImsFeatureValidationOverride(int subId) {
10803 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10804 "getImsFeatureValidationOverride");
10805 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10806 }
10807
10808 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010809 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10810 * their mobile plan.
10811 */
10812 @Override
10813 public String getMobileProvisioningUrl() {
10814 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10815 final long identity = Binder.clearCallingIdentity();
10816 try {
10817 return getDefaultPhone().getMobileProvisioningUrl();
10818 } finally {
10819 Binder.restoreCallingIdentity(identity);
10820 }
10821 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010822
James.cf Linbcdf8b32021-01-14 16:44:13 +080010823 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010824 * Get the EAB contact from the EAB database.
10825 */
10826 @Override
10827 public String getContactFromEab(String contact) {
10828 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10829 enforceModifyPermission();
10830 final long identity = Binder.clearCallingIdentity();
10831 try {
10832 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10833 } finally {
10834 Binder.restoreCallingIdentity(identity);
10835 }
10836 }
10837
10838 /**
Calvin Pana1434322021-07-01 19:27:01 +080010839 * Get the EAB capability from the EAB database.
10840 */
10841 @Override
10842 public String getCapabilityFromEab(String contact) {
10843 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10844 enforceModifyPermission();
10845 final long identity = Binder.clearCallingIdentity();
10846 try {
10847 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10848 } finally {
10849 Binder.restoreCallingIdentity(identity);
10850 }
10851 }
10852
10853 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010854 * Remove the EAB contacts from the EAB database.
10855 */
10856 @Override
10857 public int removeContactFromEab(int subId, String contacts) {
10858 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10859 enforceModifyPermission();
10860 final long identity = Binder.clearCallingIdentity();
10861 try {
10862 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10863 } finally {
10864 Binder.restoreCallingIdentity(identity);
10865 }
10866 }
10867
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010868 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010869 public boolean getDeviceUceEnabled() {
10870 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10871 final long identity = Binder.clearCallingIdentity();
10872 try {
10873 return mApp.getDeviceUceEnabled();
10874 } finally {
10875 Binder.restoreCallingIdentity(identity);
10876 }
10877 }
10878
10879 @Override
10880 public void setDeviceUceEnabled(boolean isEnabled) {
10881 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10882 final long identity = Binder.clearCallingIdentity();
10883 try {
10884 mApp.setDeviceUceEnabled(isEnabled);
10885 } finally {
10886 Binder.restoreCallingIdentity(identity);
10887 }
10888 }
10889
Brad Ebinger14d467f2021-02-12 06:18:28 +000010890 /**
10891 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10892 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10893 */
10894 // Used for SHELL command only right now.
10895 @Override
10896 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10897 List<String> featureTags) {
10898 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10899 "addUceRegistrationOverrideShell");
10900 final long identity = Binder.clearCallingIdentity();
10901 try {
10902 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10903 new ArraySet<>(featureTags));
10904 } catch (ImsException e) {
10905 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10906 } finally {
10907 Binder.restoreCallingIdentity(identity);
10908 }
10909 }
10910
10911 /**
10912 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10913 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10914 */
10915 // Used for SHELL command only right now.
10916 @Override
10917 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10918 List<String> featureTags) {
10919 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10920 "removeUceRegistrationOverrideShell");
10921 final long identity = Binder.clearCallingIdentity();
10922 try {
10923 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10924 new ArraySet<>(featureTags));
10925 } catch (ImsException e) {
10926 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10927 } finally {
10928 Binder.restoreCallingIdentity(identity);
10929 }
10930 }
10931
10932 /**
10933 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10934 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10935 */
10936 // Used for SHELL command only right now.
10937 @Override
10938 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10939 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10940 "clearUceRegistrationOverrideShell");
10941 final long identity = Binder.clearCallingIdentity();
10942 try {
10943 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10944 } catch (ImsException e) {
10945 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10946 } finally {
10947 Binder.restoreCallingIdentity(identity);
10948 }
10949 }
10950
10951 /**
10952 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10953 */
10954 // Used for SHELL command only right now.
10955 @Override
10956 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10957 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10958 "getLatestRcsContactUceCapabilityShell");
10959 final long identity = Binder.clearCallingIdentity();
10960 try {
10961 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10962 } catch (ImsException e) {
10963 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10964 } finally {
10965 Binder.restoreCallingIdentity(identity);
10966 }
10967 }
10968
10969 /**
10970 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10971 * device does not have an active PUBLISH.
10972 */
10973 // Used for SHELL command only right now.
10974 @Override
10975 public String getLastUcePidfXmlShell(int subId) {
10976 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10977 final long identity = Binder.clearCallingIdentity();
10978 try {
10979 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10980 } catch (ImsException e) {
10981 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10982 } finally {
10983 Binder.restoreCallingIdentity(identity);
10984 }
10985 }
10986
James.cf Line8713a42021-04-29 16:04:26 +080010987 /**
10988 * Remove UCE requests cannot be sent to the network status.
10989 */
10990 // Used for SHELL command only right now.
10991 @Override
10992 public boolean removeUceRequestDisallowedStatus(int subId) {
10993 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10994 final long identity = Binder.clearCallingIdentity();
10995 try {
10996 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10997 } catch (ImsException e) {
10998 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10999 } finally {
11000 Binder.restoreCallingIdentity(identity);
11001 }
11002 }
11003
James.cf Lin18bb9002021-05-25 01:37:38 +080011004 /**
11005 * Remove UCE requests cannot be sent to the network status.
11006 */
11007 // Used for SHELL command only.
11008 @Override
11009 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11010 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11011 final long identity = Binder.clearCallingIdentity();
11012 try {
11013 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11014 } catch (ImsException e) {
11015 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11016 } finally {
11017 Binder.restoreCallingIdentity(identity);
11018 }
11019 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011020
James.cf Lin4b784aa2021-01-31 03:25:15 +080011021 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011022 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11023 String callingPackage) {
11024 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11025 mApp, subId, "setSignalStrengthUpdateRequest");
11026
11027 final int callingUid = Binder.getCallingUid();
11028 // Verify that tha callingPackage belongs to the calling UID
11029 mApp.getSystemService(AppOpsManager.class)
11030 .checkPackage(callingUid, callingPackage);
11031
Rambo Wang3607f502021-02-01 21:51:40 -080011032 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011033
11034 final long identity = Binder.clearCallingIdentity();
11035 try {
11036 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11037 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11038
11039 if (result instanceof IllegalStateException) {
11040 throw (IllegalStateException) result;
11041 }
11042 } finally {
11043 Binder.restoreCallingIdentity(identity);
11044 }
11045 }
11046
11047 @Override
11048 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11049 String callingPackage) {
11050 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11051 mApp, subId, "clearSignalStrengthUpdateRequest");
11052
11053 final int callingUid = Binder.getCallingUid();
11054 // Verify that tha callingPackage belongs to the calling UID
11055 mApp.getSystemService(AppOpsManager.class)
11056 .checkPackage(callingUid, callingPackage);
11057
11058 final long identity = Binder.clearCallingIdentity();
11059 try {
11060 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11061 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11062
11063 if (result instanceof IllegalStateException) {
11064 throw (IllegalStateException) result;
11065 }
11066 } finally {
11067 Binder.restoreCallingIdentity(identity);
11068 }
11069 }
11070
Rambo Wang3607f502021-02-01 21:51:40 -080011071 private static void validateSignalStrengthUpdateRequest(Context context,
11072 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011073 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11074 // phone/system process do not have further restriction on request
11075 return;
11076 }
11077
11078 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011079 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011080 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011081 context.enforceCallingOrSelfPermission(
11082 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11083 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011084 }
11085
11086 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11087 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11088 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11089 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11090 || info.isEnabled()) {
11091 throw new IllegalArgumentException(
11092 "Only system can set hide fields in SignalThresholdInfo");
11093 }
11094
11095 // Thresholds length for each RAN need in range. This has been validated in
11096 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11097 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11098 final int[] thresholds = info.getThresholds();
11099 Objects.requireNonNull(thresholds);
11100 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11101 || thresholds.length
11102 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11103 throw new IllegalArgumentException(
11104 "thresholds length is out of range: " + thresholds.length);
11105 }
11106 }
11107 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011108
11109 /**
11110 * Gets the current phone capability.
11111 *
11112 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11113 * @return the PhoneCapability which describes the data connection capability of modem.
11114 * It's used to evaluate possible phone config change, for example from single
11115 * SIM device to multi-SIM device.
11116 */
11117 @Override
11118 public PhoneCapability getPhoneCapability() {
11119 enforceReadPrivilegedPermission("getPhoneCapability");
11120 final long identity = Binder.clearCallingIdentity();
11121 try {
11122 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11123 } finally {
11124 Binder.restoreCallingIdentity(identity);
11125 }
11126 }
Michele Berionne5e411512020-11-13 02:36:59 +000011127
11128 /**
11129 * Prepare TelephonyManager for an unattended reboot. The reboot is
11130 * required to be done shortly after the API is invoked.
11131 */
11132 @Override
11133 @TelephonyManager.PrepareUnattendedRebootResult
11134 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011135 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011136 enforceRebootPermission();
11137
11138 final long identity = Binder.clearCallingIdentity();
11139 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011140 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011141 } finally {
11142 Binder.restoreCallingIdentity(identity);
11143 }
11144 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011145
11146 /**
11147 * Request to get the current slicing configuration including URSP rules and
11148 * NSSAIs (configured, allowed and rejected).
11149 *
11150 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11151 */
11152 @Override
11153 public void getSlicingConfig(ResultReceiver callback) {
11154 enforceReadPrivilegedPermission("getSlicingConfig");
11155
11156 final long identity = Binder.clearCallingIdentity();
11157 try {
11158 Phone phone = getDefaultPhone();
11159 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11160 } finally {
11161 Binder.restoreCallingIdentity(identity);
11162 }
11163 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011164
11165 /**
11166 * Register an IMS connection state callback
11167 */
11168 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011169 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11170 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011171 if (feature == ImsFeature.FEATURE_MMTEL) {
11172 // ImsMmTelManager
11173 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11174 TelephonyPermissions
11175 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11176 mApp, subId, "registerImsStateCallback");
11177 } else if (feature == ImsFeature.FEATURE_RCS) {
11178 // ImsRcsManager or SipDelegateManager
11179 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11180 Binder.getCallingUid(), "registerImsStateCallback",
11181 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11182 Manifest.permission.READ_PRECISE_PHONE_STATE,
11183 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11184 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11185 }
11186
11187 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11188 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11189 "IMS not available on device.");
11190 }
11191
11192 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11193 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11194 }
11195
11196 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11197 if (controller == null) {
11198 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11199 "IMS not available on device.");
11200 }
11201
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011202 if (callingPackage == null) {
11203 callingPackage = getCurrentPackageName();
11204 }
11205
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011206 final long token = Binder.clearCallingIdentity();
11207 try {
11208 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011209 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011210 } catch (ImsException e) {
11211 throw new ServiceSpecificException(e.getCode());
11212 } finally {
11213 Binder.restoreCallingIdentity(token);
11214 }
11215 }
11216
11217 /**
11218 * Unregister an IMS connection state callback
11219 */
11220 @Override
11221 public void unregisterImsStateCallback(IImsStateCallback cb) {
11222 final long token = Binder.clearCallingIdentity();
11223 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11224 if (controller == null) {
11225 return;
11226 }
11227 try {
11228 controller.unregisterImsStateCallback(cb);
11229 } finally {
11230 Binder.restoreCallingIdentity(token);
11231 }
11232 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011233}