blob: 77bcd0c8292df3b0d0da0eccc94c7130b10a5712 [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);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800750
751 uiccPort = getUiccPortFromRequest(request);
752 IccLogicalChannelRequest channelRequest =
753 (IccLogicalChannelRequest) request.argument;
754 channelRequest.channel = channelId;
755 uiccPort.onLogicalChannelOpened(channelRequest);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700756 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700757 if (ar.result == null) {
758 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700759 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700760 if (ar.exception != null) {
761 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
762 }
763
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700764 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700765 if (ar.exception instanceof CommandException) {
766 CommandException.Error error =
767 ((CommandException) (ar.exception)).getCommandError();
768 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700769 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700770 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700771 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700772 }
773 }
774 openChannelResp = new IccOpenLogicalChannelResponse(
775 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700776 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700777 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700778 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700779 break;
780
781 case CMD_CLOSE_CHANNEL:
782 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000783 uiccPort = getUiccPortFromRequest(request);
784 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700785 loge("iccCloseLogicalChannel: No UICC");
Chen Xu540470b2021-12-14 17:15:47 -0800786 throw new IllegalArgumentException("iccCloseLogicalChannel: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700787 } else {
788 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000789 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700790 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700791 break;
792
793 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800794 ar = (AsyncResult) msg.obj;
795 request = (MainThreadRequest) ar.userObj;
796 if (ar.exception == null) {
797 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800798 uiccPort = getUiccPortFromRequest(request);
799 final int channelId = (Integer) request.argument;
800 uiccPort.onLogicalChannelClosed(channelId);
Chen Xu540470b2021-12-14 17:15:47 -0800801 } else {
802 request.result = false;
803 if (ar.exception instanceof CommandException) {
804 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
805 CommandException.Error error =
806 ((CommandException) (ar.exception)).getCommandError();
807 // before this feature is enabled, this API should only return false if
808 // the operation fails instead of throwing runtime exception for
809 // backward-compatibility.
810 if (Compatibility.isChangeEnabled(
811 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE)
812 && error == CommandException.Error.INVALID_ARGUMENTS) {
813 throw new IllegalArgumentException(
814 "iccCloseLogicalChannel: invalid argument ");
815 }
816 } else {
817 loge("iccCloseLogicalChannel: Unknown exception");
818 }
819 if (Compatibility.isChangeEnabled(ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE)) {
820 throw new IllegalStateException(
821 "exception from modem to close iccLogical Channel");
822 }
823 }
824 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800825 break;
826
827 case CMD_NV_READ_ITEM:
828 request = (MainThreadRequest) msg.obj;
829 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800830 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
831 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800832 break;
833
834 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700835 ar = (AsyncResult) msg.obj;
836 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800837 if (ar.exception == null && ar.result != null) {
838 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700839 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800840 request.result = "";
841 if (ar.result == null) {
842 loge("nvReadItem: Empty response");
843 } else if (ar.exception instanceof CommandException) {
844 loge("nvReadItem: CommandException: " +
845 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700846 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800847 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700848 }
849 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700850 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700851 break;
852
Jake Hambye994d462014-02-03 13:10:13 -0800853 case CMD_NV_WRITE_ITEM:
854 request = (MainThreadRequest) msg.obj;
855 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
856 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800857 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700858 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800859 break;
860
861 case EVENT_NV_WRITE_ITEM_DONE:
862 handleNullReturnEvent(msg, "nvWriteItem");
863 break;
864
865 case CMD_NV_WRITE_CDMA_PRL:
866 request = (MainThreadRequest) msg.obj;
867 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800868 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800869 break;
870
871 case EVENT_NV_WRITE_CDMA_PRL_DONE:
872 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
873 break;
874
chen xu6dac5ab2018-10-26 17:39:23 -0700875 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800876 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700877 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800878 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800879 break;
880
chen xu6dac5ab2018-10-26 17:39:23 -0700881 case EVENT_RESET_MODEM_CONFIG_DONE:
882 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800883 break;
884
Sooraj Sasindran37444802020-08-11 10:40:43 -0700885 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
886 request = (MainThreadRequest) msg.obj;
887 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
888 request);
889 Phone phone = getPhoneFromRequest(request);
890 if (phone != null) {
891 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
892 } else {
893 loge("isNRDualConnectivityEnabled: No phone object");
894 request.result = false;
895 notifyRequester(request);
896 }
897 break;
898 }
899
900 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
901 ar = (AsyncResult) msg.obj;
902 request = (MainThreadRequest) ar.userObj;
903 if (ar.exception == null && ar.result != null) {
904 request.result = ar.result;
905 } else {
906 // request.result must be set to something non-null
907 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700908 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700909 request.result = ar.result;
910 } else {
911 request.result = false;
912 }
913 if (ar.result == null) {
914 loge("isNRDualConnectivityEnabled: Empty response");
915 } else if (ar.exception instanceof CommandException) {
916 loge("isNRDualConnectivityEnabled: CommandException: "
917 + ar.exception);
918 } else {
919 loge("isNRDualConnectivityEnabled: Unknown exception");
920 }
921 }
922 notifyRequester(request);
923 break;
924
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700925 case CMD_IS_VONR_ENABLED: {
926 request = (MainThreadRequest) msg.obj;
927 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
928 request);
929 Phone phone = getPhoneFromRequest(request);
930 if (phone != null) {
931 phone.isVoNrEnabled(onCompleted, request.workSource);
932 } else {
933 loge("isVoNrEnabled: No phone object");
934 request.result = false;
935 notifyRequester(request);
936 }
937 break;
938 }
939
940 case EVENT_IS_VONR_ENABLED_DONE:
941 ar = (AsyncResult) msg.obj;
942 request = (MainThreadRequest) ar.userObj;
943 if (ar.exception == null && ar.result != null) {
944 request.result = ar.result;
945 } else {
946 // request.result must be set to something non-null
947 // for the calling thread to unblock
948 if (ar.result != null) {
949 request.result = ar.result;
950 } else {
951 request.result = false;
952 }
953 if (ar.result == null) {
954 loge("isVoNrEnabled: Empty response");
955 } else if (ar.exception instanceof CommandException) {
956 loge("isVoNrEnabled: CommandException: "
957 + ar.exception);
958 } else {
959 loge("isVoNrEnabled: Unknown exception");
960 }
961 }
962 notifyRequester(request);
963 break;
964
Sooraj Sasindran37444802020-08-11 10:40:43 -0700965 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
966 request = (MainThreadRequest) msg.obj;
967 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
968 Phone phone = getPhoneFromRequest(request);
969 if (phone != null) {
970 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
971 request.workSource);
972 } else {
973 loge("enableNrDualConnectivity: No phone object");
974 request.result =
975 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
976 notifyRequester(request);
977 }
978 break;
979 }
980
981 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
982 ar = (AsyncResult) msg.obj;
983 request = (MainThreadRequest) ar.userObj;
984 if (ar.exception == null) {
985 request.result =
986 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
987 } else {
988 request.result =
989 TelephonyManager
990 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
991 if (ar.exception instanceof CommandException) {
992 CommandException.Error error =
993 ((CommandException) (ar.exception)).getCommandError();
994 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
995 request.result =
996 TelephonyManager
997 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000998 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
999 request.result =
1000 TelephonyManager
1001 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001002 }
1003 loge("enableNrDualConnectivity" + ": CommandException: "
1004 + ar.exception);
1005 } else {
1006 loge("enableNrDualConnectivity" + ": Unknown exception");
1007 }
1008 }
1009 notifyRequester(request);
1010 break;
1011 }
1012
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001013 case CMD_ENABLE_VONR: {
1014 request = (MainThreadRequest) msg.obj;
1015 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1016 Phone phone = getPhoneFromRequest(request);
1017 if (phone != null) {
1018 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1019 request.workSource);
1020 } else {
1021 loge("setVoNrEnabled: No phone object");
1022 request.result =
1023 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1024 notifyRequester(request);
1025 }
1026 break;
1027 }
1028
1029 case EVENT_ENABLE_VONR_DONE: {
1030 ar = (AsyncResult) msg.obj;
1031 request = (MainThreadRequest) ar.userObj;
1032 if (ar.exception == null) {
1033 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1034 } else {
1035 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1036 if (ar.exception instanceof CommandException) {
1037 CommandException.Error error =
1038 ((CommandException) (ar.exception)).getCommandError();
1039 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1040 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1041 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1042 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1043 } else {
1044 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1045 }
1046 loge("setVoNrEnabled" + ": CommandException: "
1047 + ar.exception);
1048 } else {
1049 loge("setVoNrEnabled" + ": Unknown exception");
1050 }
1051 }
1052 notifyRequester(request);
1053 break;
1054 }
1055
SongFerngWang3ef3e072020-12-21 16:41:52 +08001056 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001057 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001058 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1059 request);
1060 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001061 break;
1062
SongFerngWang3ef3e072020-12-21 16:41:52 +08001063 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001064 ar = (AsyncResult) msg.obj;
1065 request = (MainThreadRequest) ar.userObj;
1066 if (ar.exception == null && ar.result != null) {
1067 request.result = ar.result; // Integer
1068 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301069 // request.result must be set to something non-null
1070 // for the calling thread to unblock
1071 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001072 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001073 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001074 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001075 loge("getAllowedNetworkTypesBitmask: CommandException: "
1076 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001077 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001078 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001079 }
1080 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001081 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001082 break;
1083
SongFerngWang3ef3e072020-12-21 16:41:52 +08001084 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001085 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001086 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1087 request);
1088 Pair<Integer, Long> reasonWithNetworkTypes =
1089 (Pair<Integer, Long>) request.argument;
1090 getPhoneFromRequest(request).setAllowedNetworkTypes(
1091 reasonWithNetworkTypes.first,
1092 reasonWithNetworkTypes.second,
1093 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001094 break;
1095
SongFerngWang3ef3e072020-12-21 16:41:52 +08001096 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1097 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001098 break;
1099
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001100 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1101 request = (MainThreadRequest)msg.obj;
1102 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001103 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001104 break;
1105
1106 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1107 ar = (AsyncResult)msg.obj;
1108 request = (MainThreadRequest)ar.userObj;
1109 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001110 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001111 break;
1112
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001113 case CMD_SET_VOICEMAIL_NUMBER:
1114 request = (MainThreadRequest) msg.obj;
1115 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1116 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001117 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1118 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001119 break;
1120
1121 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1122 handleNullReturnEvent(msg, "setVoicemailNumber");
1123 break;
1124
Stuart Scott54788802015-03-30 13:18:01 -07001125 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1126 request = (MainThreadRequest) msg.obj;
1127 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1128 request);
1129 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1130 break;
1131
1132 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1133 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1134 break;
1135
Shishir Agrawal302c8692015-06-19 13:49:39 -07001136 case CMD_PERFORM_NETWORK_SCAN:
1137 request = (MainThreadRequest) msg.obj;
1138 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1139 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1140 break;
1141
Hall Liu27d24262020-09-18 19:04:59 -07001142 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001143 request = (MainThreadRequest) msg.obj;
1144 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001145 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1146 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1147 request.argument;
1148 int callForwardingReason = args.first;
1149 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001150 break;
Hall Liu27d24262020-09-18 19:04:59 -07001151 }
1152 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001153 ar = (AsyncResult) msg.obj;
1154 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001155 TelephonyManager.CallForwardingInfoCallback callback =
1156 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1157 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001158 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001159 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001160 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1161 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1162 // Service Class is a bit mask per 3gpp 27.007. Search for
1163 // any service for voice call.
1164 if ((callForwardInfo.serviceClass
1165 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001166 callForwardingInfo = new CallForwardingInfo(
1167 callForwardInfo.status
1168 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001169 callForwardInfo.reason,
1170 callForwardInfo.number,
1171 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001172 break;
1173 }
1174 }
1175 // Didn't find a call forward info for voice call.
1176 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001177 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1178 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001179 }
Hall Liu27d24262020-09-18 19:04:59 -07001180 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001181 } else {
1182 if (ar.result == null) {
1183 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1184 }
1185 if (ar.exception != null) {
1186 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1187 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001188 int errorCode = TelephonyManager
1189 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001190 if (ar.exception instanceof CommandException) {
1191 CommandException.Error error =
1192 ((CommandException) (ar.exception)).getCommandError();
1193 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001194 errorCode = TelephonyManager
1195 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001196 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001197 errorCode = TelephonyManager
1198 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001199 }
1200 }
Hall Liu27d24262020-09-18 19:04:59 -07001201 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001202 }
Shuo Qian4a594052020-01-23 11:59:30 -08001203 break;
Hall Liu27d24262020-09-18 19:04:59 -07001204 }
Shuo Qian4a594052020-01-23 11:59:30 -08001205
Hall Liu27d24262020-09-18 19:04:59 -07001206 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001207 request = (MainThreadRequest) msg.obj;
1208 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001209 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001210 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001211 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1212 request.argument).first;
1213 request.phone.setCallForwardingOption(
1214 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001215 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001216 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001217 callForwardingInfoToSet.getReason(),
1218 callForwardingInfoToSet.getNumber(),
1219 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1220 break;
Hall Liu27d24262020-09-18 19:04:59 -07001221 }
Shuo Qian4a594052020-01-23 11:59:30 -08001222
Hall Liu27d24262020-09-18 19:04:59 -07001223 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001224 ar = (AsyncResult) msg.obj;
1225 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001226 Consumer<Integer> callback =
1227 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1228 request.argument).second;
1229 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001230 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001231 int errorCode = TelephonyManager.CallForwardingInfoCallback
1232 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001233 if (ar.exception instanceof CommandException) {
1234 CommandException.Error error =
1235 ((CommandException) (ar.exception)).getCommandError();
1236 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001237 errorCode = TelephonyManager.CallForwardingInfoCallback
1238 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001239 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001240 errorCode = TelephonyManager.CallForwardingInfoCallback
1241 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001242 }
1243 }
1244 callback.accept(errorCode);
1245 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001246 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001247 }
Shuo Qian4a594052020-01-23 11:59:30 -08001248 break;
Hall Liu27d24262020-09-18 19:04:59 -07001249 }
Shuo Qian4a594052020-01-23 11:59:30 -08001250
Hall Liu27d24262020-09-18 19:04:59 -07001251 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001252 request = (MainThreadRequest) msg.obj;
1253 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1254 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1255 break;
Hall Liu27d24262020-09-18 19:04:59 -07001256 }
Shuo Qian4a594052020-01-23 11:59:30 -08001257
Hall Liu27d24262020-09-18 19:04:59 -07001258 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001259 ar = (AsyncResult) msg.obj;
1260 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001261 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001262 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1263 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001264 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001265 // Service Class is a bit mask per 3gpp 27.007.
1266 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001267 if (callForwardResults.length > 1
1268 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001269 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001270 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001271 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1272 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001273 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001274 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001275 }
1276 } else {
1277 if (ar.result == null) {
1278 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1279 }
1280 if (ar.exception != null) {
1281 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1282 }
1283 if (ar.exception instanceof CommandException) {
1284 CommandException.Error error =
1285 ((CommandException) (ar.exception)).getCommandError();
1286 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1287 callForwardingStatus =
1288 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1289 }
1290 }
1291 }
Hall Liu27d24262020-09-18 19:04:59 -07001292 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001293 break;
Hall Liu27d24262020-09-18 19:04:59 -07001294 }
Shuo Qian4a594052020-01-23 11:59:30 -08001295
Hall Liu27d24262020-09-18 19:04:59 -07001296 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001297 request = (MainThreadRequest) msg.obj;
1298 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001299 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1300 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001301 break;
Hall Liu27d24262020-09-18 19:04:59 -07001302 }
Shuo Qian4a594052020-01-23 11:59:30 -08001303
Hall Liu27d24262020-09-18 19:04:59 -07001304 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001305 ar = (AsyncResult) msg.obj;
1306 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001307 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1308 Consumer<Integer> callback =
1309 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1310 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001311 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001312 if (ar.exception instanceof CommandException) {
1313 CommandException.Error error =
1314 ((CommandException) (ar.exception)).getCommandError();
1315 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1316 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1317 } else {
1318 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1319 }
1320 } else {
1321 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1322 }
1323 } else {
1324 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1325 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001326 }
Shuo Qian4a594052020-01-23 11:59:30 -08001327 break;
Hall Liu27d24262020-09-18 19:04:59 -07001328 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001329 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1330 ar = (AsyncResult) msg.obj;
1331 request = (MainThreadRequest) ar.userObj;
1332 CellNetworkScanResult cellScanResult;
1333 if (ar.exception == null && ar.result != null) {
1334 cellScanResult = new CellNetworkScanResult(
1335 CellNetworkScanResult.STATUS_SUCCESS,
1336 (List<OperatorInfo>) ar.result);
1337 } else {
1338 if (ar.result == null) {
1339 loge("getCellNetworkScanResults: Empty response");
1340 }
1341 if (ar.exception != null) {
1342 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1343 }
1344 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1345 if (ar.exception instanceof CommandException) {
1346 CommandException.Error error =
1347 ((CommandException) (ar.exception)).getCommandError();
1348 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1349 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1350 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1351 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1352 }
1353 }
1354 cellScanResult = new CellNetworkScanResult(errorCode, null);
1355 }
1356 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001357 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001358 break;
1359
1360 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1361 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001362 ManualNetworkSelectionArgument selArg =
1363 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001364 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1365 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001366 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1367 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001368 break;
1369
1370 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001371 ar = (AsyncResult) msg.obj;
1372 request = (MainThreadRequest) ar.userObj;
1373 if (ar.exception == null) {
1374 request.result = true;
1375 } else {
1376 request.result = false;
1377 loge("setNetworkSelectionModeManual " + ar.exception);
1378 }
1379 notifyRequester(request);
1380 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001381 break;
1382
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001383 case CMD_GET_MODEM_ACTIVITY_INFO:
1384 request = (MainThreadRequest) msg.obj;
1385 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001386 if (defaultPhone != null) {
1387 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001388 } else {
1389 ResultReceiver result = (ResultReceiver) request.argument;
1390 Bundle bundle = new Bundle();
1391 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001392 new ModemActivityInfo(0, 0, 0,
1393 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001394 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001395 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001396 break;
1397
Hall Liud0f208c2020-10-14 16:54:44 -07001398 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001399 ar = (AsyncResult) msg.obj;
1400 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001401 ResultReceiver result = (ResultReceiver) request.argument;
1402
Hall Liud0f208c2020-10-14 16:54:44 -07001403 ModemActivityInfo ret = null;
1404 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001405 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001406 // Update the last modem activity info and the result of the request.
1407 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1408 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001409 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001410 int[] txTimeMs = info.getTransmitTimeMillis();
1411 int[] lastModemTxTimeMs = mLastModemActivityInfo
1412 .getTransmitTimeMillis();
1413 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1414 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1415 }
Hall Liu49656c02020-10-09 19:00:11 -07001416 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001417 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1418 + mLastModemActivityInfo.getSleepTimeMillis());
1419 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1420 + mLastModemActivityInfo.getIdleTimeMillis());
1421 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1422 mLastModemActivityInfo.setReceiveTimeMillis(
1423 info.getReceiveTimeMillis()
1424 + mLastModemActivityInfo.getReceiveTimeMillis());
1425 }
Hall Liu49656c02020-10-09 19:00:11 -07001426 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001427 mLastModemActivityInfo.getSleepTimeMillis(),
1428 mLastModemActivityInfo.getIdleTimeMillis(),
1429 mLastModemActivityInfo.getTransmitTimeMillis(),
1430 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001431 } else {
1432 if (ar.result == null) {
1433 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001434 error = TelephonyManager.ModemActivityInfoException
1435 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001436 } else if (ar.exception instanceof CommandException) {
1437 loge("queryModemActivityInfo: CommandException: " +
1438 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001439 error = TelephonyManager.ModemActivityInfoException
1440 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001441 } else {
1442 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001443 error = TelephonyManager.ModemActivityInfoException
1444 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001445 }
1446 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001447 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001448 if (ret != null) {
1449 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1450 } else {
1451 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1452 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001453 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001454 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001455 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001456 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001457
Meng Wang1a7c35a2016-05-05 20:56:15 -07001458 case CMD_SET_ALLOWED_CARRIERS:
1459 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001460 CarrierRestrictionRules argument =
1461 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001462 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001463 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001464 break;
1465
1466 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1467 ar = (AsyncResult) msg.obj;
1468 request = (MainThreadRequest) ar.userObj;
1469 if (ar.exception == null && ar.result != null) {
1470 request.result = ar.result;
1471 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001472 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1473 if (ar.exception instanceof CommandException) {
1474 loge("setAllowedCarriers: CommandException: " + ar.exception);
1475 CommandException.Error error =
1476 ((CommandException) (ar.exception)).getCommandError();
1477 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1478 request.result =
1479 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1480 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001481 } else {
1482 loge("setAllowedCarriers: Unknown exception");
1483 }
1484 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001485 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001486 break;
1487
1488 case CMD_GET_ALLOWED_CARRIERS:
1489 request = (MainThreadRequest) msg.obj;
1490 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001491 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001492 break;
1493
1494 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1495 ar = (AsyncResult) msg.obj;
1496 request = (MainThreadRequest) ar.userObj;
1497 if (ar.exception == null && ar.result != null) {
1498 request.result = ar.result;
1499 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001500 request.result = new IllegalStateException(
1501 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001502 if (ar.result == null) {
1503 loge("getAllowedCarriers: Empty response");
1504 } else if (ar.exception instanceof CommandException) {
1505 loge("getAllowedCarriers: CommandException: " +
1506 ar.exception);
1507 } else {
1508 loge("getAllowedCarriers: Unknown exception");
1509 }
1510 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001511 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001512 break;
1513
Nathan Haroldb3014052017-01-25 15:57:32 -08001514 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1515 ar = (AsyncResult) msg.obj;
1516 request = (MainThreadRequest) ar.userObj;
1517 if (ar.exception == null && ar.result != null) {
1518 request.result = ar.result;
1519 } else {
1520 request.result = new IllegalArgumentException(
1521 "Failed to retrieve Forbidden Plmns");
1522 if (ar.result == null) {
1523 loge("getForbiddenPlmns: Empty response");
1524 } else {
1525 loge("getForbiddenPlmns: Unknown exception");
1526 }
1527 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001528 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001529 break;
1530
1531 case CMD_GET_FORBIDDEN_PLMNS:
1532 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001533 uiccPort = getUiccPortFromRequest(request);
1534 if (uiccPort == null) {
1535 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001536 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001537 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001538 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001539 break;
1540 }
1541 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001542 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001543 if (uiccApp == null) {
1544 loge("getForbiddenPlmns() no app with specified type -- "
1545 + appType);
1546 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001547 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001548 break;
1549 } else {
1550 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1551 + " specified type -- " + appType);
1552 }
1553 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1554 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1555 onCompleted);
1556 break;
1557
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001558 case CMD_SWITCH_SLOTS:
1559 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001560 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001561 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001562 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001563 break;
1564
1565 case EVENT_SWITCH_SLOTS_DONE:
1566 ar = (AsyncResult) msg.obj;
1567 request = (MainThreadRequest) ar.userObj;
1568 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001569 notifyRequester(request);
1570 break;
1571 case CMD_GET_NETWORK_SELECTION_MODE:
1572 request = (MainThreadRequest) msg.obj;
1573 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1574 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1575 break;
1576
1577 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1578 ar = (AsyncResult) msg.obj;
1579 request = (MainThreadRequest) ar.userObj;
1580 if (ar.exception != null) {
1581 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1582 } else {
1583 int mode = ((int[]) ar.result)[0];
1584 if (mode == 0) {
1585 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1586 } else {
1587 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1588 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001589 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001590 notifyRequester(request);
1591 break;
1592 case CMD_GET_CDMA_ROAMING_MODE:
1593 request = (MainThreadRequest) msg.obj;
1594 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1595 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1596 break;
1597 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1598 ar = (AsyncResult) msg.obj;
1599 request = (MainThreadRequest) ar.userObj;
1600 if (ar.exception != null) {
1601 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1602 } else {
1603 request.result = ((int[]) ar.result)[0];
1604 }
1605 notifyRequester(request);
1606 break;
1607 case CMD_SET_CDMA_ROAMING_MODE:
1608 request = (MainThreadRequest) msg.obj;
1609 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1610 int mode = (int) request.argument;
1611 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1612 break;
1613 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1614 ar = (AsyncResult) msg.obj;
1615 request = (MainThreadRequest) ar.userObj;
1616 request.result = ar.exception == null;
1617 notifyRequester(request);
1618 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001619 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1620 request = (MainThreadRequest) msg.obj;
1621 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1622 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1623 break;
1624 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1625 ar = (AsyncResult) msg.obj;
1626 request = (MainThreadRequest) ar.userObj;
1627 if (ar.exception != null) {
1628 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1629 } else {
1630 request.result = ((int[]) ar.result)[0];
1631 }
1632 notifyRequester(request);
1633 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001634 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1635 request = (MainThreadRequest) msg.obj;
1636 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1637 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001638 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1639 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001640 break;
1641 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1642 ar = (AsyncResult) msg.obj;
1643 request = (MainThreadRequest) ar.userObj;
1644 request.result = ar.exception == null;
1645 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001646 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001647 case CMD_GET_ALL_CELL_INFO:
1648 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001649 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001650 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001651 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001652 case EVENT_GET_ALL_CELL_INFO_DONE:
1653 ar = (AsyncResult) msg.obj;
1654 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001655 // If a timeout occurs, the response will be null
1656 request.result = (ar.exception == null && ar.result != null)
1657 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001658 synchronized (request) {
1659 request.notifyAll();
1660 }
1661 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001662 case CMD_REQUEST_CELL_INFO_UPDATE:
1663 request = (MainThreadRequest) msg.obj;
1664 request.phone.requestCellInfoUpdate(request.workSource,
1665 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1666 break;
1667 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1668 ar = (AsyncResult) msg.obj;
1669 request = (MainThreadRequest) ar.userObj;
1670 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1671 try {
1672 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001673 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001674 cb.onError(
1675 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1676 ar.exception.getClass().getName(),
1677 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001678 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001679 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001680 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001681 } else {
1682 // use the result as returned
1683 cb.onCellInfo((List<CellInfo>) ar.result);
1684 }
1685 } catch (RemoteException re) {
1686 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1687 }
1688 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001689 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001690 request = (MainThreadRequest) msg.obj;
1691 WorkSource ws = (WorkSource) request.argument;
1692 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001693 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001694 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001695 }
1696 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001697 ar = (AsyncResult) msg.obj;
1698 request = (MainThreadRequest) ar.userObj;
1699 if (ar.exception == null) {
1700 request.result = ar.result;
1701 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001702 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001703 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001704 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001705 }
1706
1707 synchronized (request) {
1708 request.notifyAll();
1709 }
1710 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001711 }
chen xu6dac5ab2018-10-26 17:39:23 -07001712 case CMD_MODEM_REBOOT:
1713 request = (MainThreadRequest) msg.obj;
1714 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001715 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001716 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001717 case EVENT_CMD_MODEM_REBOOT_DONE:
1718 handleNullReturnEvent(msg, "rebootModem");
1719 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001720 case CMD_REQUEST_ENABLE_MODEM:
1721 request = (MainThreadRequest) msg.obj;
1722 boolean enable = (boolean) request.argument;
1723 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001724 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001725 PhoneConfigurationManager.getInstance()
1726 .enablePhone(request.phone, enable, onCompleted);
1727 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001728 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001729 ar = (AsyncResult) msg.obj;
1730 request = (MainThreadRequest) ar.userObj;
1731 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001732 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001733 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001734 if ((boolean) request.result) {
1735 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1736 updateModemStateMetrics();
1737 } else {
1738 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1739 + ar.exception);
1740 }
1741 notifyRequester(request);
1742 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001743 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001744 case CMD_GET_MODEM_STATUS:
1745 request = (MainThreadRequest) msg.obj;
1746 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1747 PhoneConfigurationManager.getInstance()
1748 .getPhoneStatusFromModem(request.phone, onCompleted);
1749 break;
1750 case EVENT_GET_MODEM_STATUS_DONE:
1751 ar = (AsyncResult) msg.obj;
1752 request = (MainThreadRequest) ar.userObj;
1753 int id = request.phone.getPhoneId();
1754 if (ar.exception == null && ar.result != null) {
1755 request.result = ar.result;
1756 //update the cache as modem status has changed
1757 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1758 (boolean) request.result);
1759 } else {
1760 // Return true if modem status cannot be retrieved. For most cases,
1761 // modem status is on. And for older version modems, GET_MODEM_STATUS
1762 // and disable modem are not supported. Modem is always on.
1763 // TODO: this should be fixed in R to support a third
1764 // status UNKNOWN b/131631629
1765 request.result = true;
1766 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1767 + ar.exception);
1768 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001769 notifyRequester(request);
1770 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001771 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1772 request = (MainThreadRequest) msg.obj;
1773 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1774 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1775 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1776 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1777 break;
1778 }
1779 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1780 ar = (AsyncResult) msg.obj;
1781 request = (MainThreadRequest) ar.userObj;
1782 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1783 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1784 args.second.accept(ar.exception == null);
1785 notifyRequester(request);
1786 break;
1787 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001788 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1789 request = (MainThreadRequest) msg.obj;
1790 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1791 Phone phone = getPhoneFromRequest(request);
1792 if (phone != null) {
1793 phone.getSystemSelectionChannels(onCompleted);
1794 } else {
1795 loge("getSystemSelectionChannels: No phone object");
1796 request.result = new ArrayList<RadioAccessSpecifier>();
1797 notifyRequester(request);
1798 }
1799 break;
1800 }
1801 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1802 ar = (AsyncResult) msg.obj;
1803 request = (MainThreadRequest) ar.userObj;
1804 if (ar.exception == null && ar.result != null) {
1805 request.result = ar.result;
1806 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001807 request.result = new IllegalStateException(
1808 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001809 if (ar.result == null) {
1810 loge("getSystemSelectionChannels: Empty response");
1811 } else {
1812 loge("getSystemSelectionChannels: Unknown exception");
1813 }
1814 }
1815 notifyRequester(request);
1816 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001817 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1818 ar = (AsyncResult) msg.obj;
1819 request = (MainThreadRequest) ar.userObj;
1820 if (ar.exception == null && ar.result != null) {
1821 request.result = ar.result;
1822 } else {
1823 request.result = -1;
1824 loge("Failed to set Forbidden Plmns");
1825 if (ar.result == null) {
1826 loge("setForbidenPlmns: Empty response");
1827 } else if (ar.exception != null) {
1828 loge("setForbiddenPlmns: Exception: " + ar.exception);
1829 request.result = -1;
1830 } else {
1831 loge("setForbiddenPlmns: Unknown exception");
1832 }
1833 }
1834 notifyRequester(request);
1835 break;
1836 case CMD_SET_FORBIDDEN_PLMNS:
1837 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001838 uiccPort = getUiccPortFromRequest(request);
1839 if (uiccPort == null) {
1840 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001841 request.result = -1;
1842 notifyRequester(request);
1843 break;
1844 }
1845 Pair<Integer, List<String>> setFplmnsArgs =
1846 (Pair<Integer, List<String>>) request.argument;
1847 appType = setFplmnsArgs.first;
1848 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001849 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001850 if (uiccApp == null) {
1851 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1852 request.result = -1;
1853 loge("Failed to get UICC App");
1854 notifyRequester(request);
1855 } else {
1856 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1857 ((SIMRecords) uiccApp.getIccRecords())
1858 .setForbiddenPlmns(onCompleted, fplmns);
1859 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001860 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001861 case CMD_ERASE_MODEM_CONFIG:
1862 request = (MainThreadRequest) msg.obj;
1863 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1864 defaultPhone.eraseModemConfig(onCompleted);
1865 break;
1866 case EVENT_ERASE_MODEM_CONFIG_DONE:
1867 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001868 break;
zoey chene02881a2019-12-30 16:11:23 +08001869
Kai Shif70f46f2021-03-03 13:59:46 -08001870 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1871 request = (MainThreadRequest) msg.obj;
1872 request.result = defaultPhone.eraseDataInSharedPreferences();
1873 notifyRequester(request);
1874 break;
1875
zoey chene02881a2019-12-30 16:11:23 +08001876 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1877 request = (MainThreadRequest) msg.obj;
1878 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1879 Pair<String, String> changed = (Pair<String, String>) request.argument;
1880 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1881 changed.first, changed.second, onCompleted);
1882 break;
1883 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1884 ar = (AsyncResult) msg.obj;
1885 request = (MainThreadRequest) ar.userObj;
1886 if (ar.exception == null) {
1887 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001888 // If the operation is successful, update the PIN storage
1889 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1890 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001891 UiccController.getInstance().getPinStorage()
1892 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001893 } else {
1894 request.result = msg.arg1;
1895 }
1896 notifyRequester(request);
1897 break;
1898
Michele Berionne5e411512020-11-13 02:36:59 +00001899 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001900 request = (MainThreadRequest) msg.obj;
1901 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1902 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1903 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1904 enabled.first, enabled.second, onCompleted);
1905 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001906 }
zoey chene02881a2019-12-30 16:11:23 +08001907 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1908 ar = (AsyncResult) msg.obj;
1909 request = (MainThreadRequest) ar.userObj;
1910 if (ar.exception == null) {
1911 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001912 // If the operation is successful, update the PIN storage
1913 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1914 int phoneId = getPhoneFromRequest(request).getPhoneId();
1915 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001916 UiccController.getInstance().getPinStorage()
1917 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001918 } else {
1919 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1920 }
zoey chene02881a2019-12-30 16:11:23 +08001921 } else {
1922 request.result = msg.arg1;
1923 }
Michele Berionne5e411512020-11-13 02:36:59 +00001924
1925
zoey chene02881a2019-12-30 16:11:23 +08001926 notifyRequester(request);
1927 break;
1928
Peter Wangdafb9ac2020-01-15 14:13:38 -08001929 case MSG_NOTIFY_USER_ACTIVITY:
1930 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001931 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001932 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1933 getDefaultPhone().getContext().sendBroadcastAsUser(
1934 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1935 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001936
1937 case CMD_SET_DATA_THROTTLING: {
1938 request = (MainThreadRequest) msg.obj;
1939 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1940 DataThrottlingRequest dataThrottlingRequest =
1941 (DataThrottlingRequest) request.argument;
1942 Phone phone = getPhoneFromRequest(request);
1943 if (phone != null) {
1944 phone.setDataThrottling(onCompleted,
1945 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1946 dataThrottlingRequest.getCompletionDurationMillis());
1947 } else {
1948 loge("setDataThrottling: No phone object");
1949 request.result =
1950 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1951 notifyRequester(request);
1952 }
1953
1954 break;
1955 }
1956 case EVENT_SET_DATA_THROTTLING_DONE:
1957 ar = (AsyncResult) msg.obj;
1958 request = (MainThreadRequest) ar.userObj;
1959
1960 if (ar.exception == null) {
1961 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1962 } else if (ar.exception instanceof CommandException) {
1963 loge("setDataThrottling: CommandException: " + ar.exception);
1964 CommandException.Error error =
1965 ((CommandException) (ar.exception)).getCommandError();
1966
1967 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1968 request.result = TelephonyManager
1969 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1970 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1971 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001972 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1973 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001974 } else {
1975 request.result =
1976 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1977 }
1978 } else {
1979 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1980 }
1981 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1982 notifyRequester(request);
1983 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001984
1985 case CMD_SET_SIM_POWER: {
1986 request = (MainThreadRequest) msg.obj;
1987 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1988 request = (MainThreadRequest) msg.obj;
1989 int stateToSet =
1990 ((Pair<Integer, IIntegerConsumer>)
1991 request.argument).first;
1992 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1993 break;
1994 }
1995 case EVENT_SET_SIM_POWER_DONE: {
1996 ar = (AsyncResult) msg.obj;
1997 request = (MainThreadRequest) ar.userObj;
1998 IIntegerConsumer callback =
1999 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2000 if (ar.exception != null) {
2001 loge("setSimPower exception: " + ar.exception);
2002 int errorCode = TelephonyManager.CallForwardingInfoCallback
2003 .RESULT_ERROR_UNKNOWN;
2004 if (ar.exception instanceof CommandException) {
2005 CommandException.Error error =
2006 ((CommandException) (ar.exception)).getCommandError();
2007 if (error == CommandException.Error.SIM_ERR) {
2008 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2009 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2010 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2011 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2012 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2013 } else {
2014 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2015 }
2016 }
2017 try {
2018 callback.accept(errorCode);
2019 } catch (RemoteException e) {
2020 // Ignore if the remote process is no longer available to call back.
2021 Log.w(LOG_TAG, "setSimPower: callback not available.");
2022 }
2023 } else {
2024 try {
2025 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2026 } catch (RemoteException e) {
2027 // Ignore if the remote process is no longer available to call back.
2028 Log.w(LOG_TAG, "setSimPower: callback not available.");
2029 }
2030 }
2031 break;
2032 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002033 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2034 request = (MainThreadRequest) msg.obj;
2035
2036 final Phone phone = getPhoneFromRequest(request);
2037 if (phone == null || phone.getServiceStateTracker() == null) {
2038 request.result = new IllegalStateException("Phone or SST is null");
2039 notifyRequester(request);
2040 break;
2041 }
2042
2043 Pair<Integer, SignalStrengthUpdateRequest> pair =
2044 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2045 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2046 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002047 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002048 request.subId, pair.first /*callingUid*/,
2049 pair.second /*request*/, onCompleted);
2050 break;
2051 }
2052 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2053 ar = (AsyncResult) msg.obj;
2054 request = (MainThreadRequest) ar.userObj;
2055 // request.result will be the exception of ar if present, true otherwise.
2056 // Be cautious not to leave result null which will wait() forever
2057 request.result = ar.exception != null ? ar.exception : true;
2058 notifyRequester(request);
2059 break;
2060 }
2061 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2062 request = (MainThreadRequest) msg.obj;
2063
2064 Phone phone = getPhoneFromRequest(request);
2065 if (phone == null || phone.getServiceStateTracker() == null) {
2066 request.result = new IllegalStateException("Phone or SST is null");
2067 notifyRequester(request);
2068 break;
2069 }
2070
2071 Pair<Integer, SignalStrengthUpdateRequest> pair =
2072 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2073 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2074 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002075 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002076 request.subId, pair.first /*callingUid*/,
2077 pair.second /*request*/, onCompleted);
2078 break;
2079 }
2080 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2081 ar = (AsyncResult) msg.obj;
2082 request = (MainThreadRequest) ar.userObj;
2083 request.result = ar.exception != null ? ar.exception : true;
2084 notifyRequester(request);
2085 break;
2086 }
Jordan Liu109698e2020-11-24 14:50:34 -08002087
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002088 case CMD_GET_SLICING_CONFIG: {
2089 request = (MainThreadRequest) msg.obj;
2090 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2091 request.phone.getSlicingConfig(onCompleted);
2092 break;
2093 }
2094 case EVENT_GET_SLICING_CONFIG_DONE: {
2095 ar = (AsyncResult) msg.obj;
2096 request = (MainThreadRequest) ar.userObj;
2097 ResultReceiver result = (ResultReceiver) request.argument;
2098
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002099 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002100 Bundle bundle = new Bundle();
2101 int resultCode = 0;
2102 if (ar.exception != null) {
2103 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2104 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002105 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002106 } else if (ar.result == null) {
2107 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002108 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002109 } else {
2110 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002111 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2112 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002113 }
2114
2115 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002116 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002117 }
2118 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2119 result.send(resultCode, bundle);
2120 notifyRequester(request);
2121 break;
2122 }
2123
Michele Berionne5e411512020-11-13 02:36:59 +00002124 case CMD_PREPARE_UNATTENDED_REBOOT:
2125 request = (MainThreadRequest) msg.obj;
2126 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002127 UiccController.getInstance().getPinStorage()
2128 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002129 notifyRequester(request);
2130 break;
2131
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002132 default:
2133 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2134 break;
2135 }
2136 }
Jake Hambye994d462014-02-03 13:10:13 -08002137
Pengquan Menga1bb6272018-09-06 09:59:22 -07002138 private void notifyRequester(MainThreadRequest request) {
2139 synchronized (request) {
2140 request.notifyAll();
2141 }
2142 }
2143
Jake Hambye994d462014-02-03 13:10:13 -08002144 private void handleNullReturnEvent(Message msg, String command) {
2145 AsyncResult ar = (AsyncResult) msg.obj;
2146 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2147 if (ar.exception == null) {
2148 request.result = true;
2149 } else {
2150 request.result = false;
2151 if (ar.exception instanceof CommandException) {
2152 loge(command + ": CommandException: " + ar.exception);
2153 } else {
2154 loge(command + ": Unknown exception");
2155 }
2156 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002157 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002158 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002159 }
2160
2161 /**
2162 * Posts the specified command to be executed on the main thread,
2163 * waits for the request to complete, and returns the result.
2164 * @see #sendRequestAsync
2165 */
2166 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002167 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2168 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002169 }
2170
2171 /**
2172 * Posts the specified command to be executed on the main thread,
2173 * waits for the request to complete, and returns the result.
2174 * @see #sendRequestAsync
2175 */
2176 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2177 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002178 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002179 }
2180
2181 /**
2182 * Posts the specified command to be executed on the main thread,
2183 * waits for the request to complete, and returns the result.
2184 * @see #sendRequestAsync
2185 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002186 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002187 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2188 }
2189
2190 /**
2191 * Posts the specified command to be executed on the main thread,
2192 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2193 * if not timeout or null otherwise.
2194 * @see #sendRequestAsync
2195 */
2196 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2197 long timeoutInMs) {
2198 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -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 */
Nathan Harold92bed182018-10-12 18:16:49 -07002206 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002207 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002208 }
2209
2210 /**
2211 * Posts the specified command to be executed on the main thread,
2212 * waits for the request to complete, and returns the result.
2213 * @see #sendRequestAsync
2214 */
2215 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002216 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2217 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002218 }
2219
2220 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002221 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2222 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2223 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002224 * @see #sendRequestAsync
2225 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002226 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2227 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002228 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2229 throw new RuntimeException("This method will deadlock if called from the main thread.");
2230 }
2231
Nathan Harold92bed182018-10-12 18:16:49 -07002232 MainThreadRequest request = null;
2233 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2234 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2235 } else if (phone != null) {
2236 request = new MainThreadRequest(argument, phone, workSource);
2237 } else {
2238 request = new MainThreadRequest(argument, subId, workSource);
2239 }
2240
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002241 Message msg = mMainThreadHandler.obtainMessage(command, request);
2242 msg.sendToTarget();
2243
Rambo Wang0f050d82021-02-12 11:43:36 -08002244
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002245 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002246 if (timeoutInMs >= 0) {
2247 // Wait for at least timeoutInMs before returning null request result
2248 long now = SystemClock.elapsedRealtime();
2249 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002250 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002251 try {
2252 request.wait(deadline - now);
2253 } catch (InterruptedException e) {
2254 // Do nothing, go back and check if request is completed or timeout
2255 } finally {
2256 now = SystemClock.elapsedRealtime();
2257 }
2258 }
2259 } else {
2260 // Wait for the request to complete
2261 while (request.result == null) {
2262 try {
2263 request.wait();
2264 } catch (InterruptedException e) {
2265 // Do nothing, go back and wait until the request is complete
2266 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002267 }
2268 }
2269 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002270 if (request.result == null) {
2271 Log.wtf(LOG_TAG,
2272 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2273 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002274 return request.result;
2275 }
2276
2277 /**
2278 * Asynchronous ("fire and forget") version of sendRequest():
2279 * Posts the specified command to be executed on the main thread, and
2280 * returns immediately.
2281 * @see #sendRequest
2282 */
2283 private void sendRequestAsync(int command) {
2284 mMainThreadHandler.sendEmptyMessage(command);
2285 }
2286
2287 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002288 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002289 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002290 */
2291 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002292 sendRequestAsync(command, argument, null, null);
2293 }
2294
2295 /**
2296 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2297 * @see {@link #sendRequest(int,Object)}
2298 */
2299 private void sendRequestAsync(
2300 int command, Object argument, Phone phone, WorkSource workSource) {
2301 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002302 Message msg = mMainThreadHandler.obtainMessage(command, request);
2303 msg.sendToTarget();
2304 }
2305
2306 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002307 * Initialize the singleton PhoneInterfaceManager instance.
2308 * This is only done once, at startup, from PhoneApp.onCreate().
2309 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002310 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002311 synchronized (PhoneInterfaceManager.class) {
2312 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002313 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002314 } else {
2315 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2316 }
2317 return sInstance;
2318 }
2319 }
2320
2321 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002322 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002323 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002324 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002325 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002326 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002327 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002328 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002329 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002330 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002331 mTelephonySharedPreferences =
2332 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002333 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002334 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002335 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002336 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002337
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002338 publish();
2339 }
2340
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002341 private Phone getDefaultPhone() {
2342 Phone thePhone = getPhone(getDefaultSubscription());
2343 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2344 }
2345
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002346 private void publish() {
2347 if (DBG) log("publish: " + this);
2348
Peter Wangc035ce42020-01-08 21:00:22 -08002349 TelephonyFrameworkInitializer
2350 .getTelephonyServiceManager()
2351 .getTelephonyServiceRegisterer()
2352 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002353 }
2354
Stuart Scott584921c2015-01-15 17:10:34 -08002355 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002356 if (request.phone != null) {
2357 return request.phone;
2358 } else {
2359 return getPhoneFromSubId(request.subId);
2360 }
2361 }
2362
2363 private Phone getPhoneFromSubId(int subId) {
2364 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2365 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002366 }
2367
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002368 private UiccPort getUiccPortFromRequest(MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002369 Phone phone = getPhoneFromRequest(request);
2370 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002371 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002372 }
2373
Wink Saville36469e72014-06-11 15:17:00 -07002374 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002375 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002376 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002377 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002378
Kai Shif70f46f2021-03-03 13:59:46 -08002379 private void sendEraseModemConfig(@NonNull Phone phone) {
2380 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2381 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2382 }
2383
2384 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2385 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2386 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002387 }
2388
Peter Wang44b186e2020-01-13 23:33:09 -08002389 private boolean isImsAvailableOnDevice() {
2390 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2391 if (pm == null) {
2392 // For some reason package manger is not available.. This will fail internally anyway,
2393 // so do not throw error and allow.
2394 return true;
2395 }
2396 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2397 }
2398
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002399 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002400 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002401 }
2402
Wink Savilleb564aae2014-10-23 10:18:09 -07002403 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002404 if (DBG) log("dial: " + number);
2405 // No permission check needed here: This is just a wrapper around the
2406 // ACTION_DIAL intent, which is available to any app since it puts up
2407 // the UI before it does anything.
2408
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002409 final long identity = Binder.clearCallingIdentity();
2410 try {
2411 String url = createTelUrl(number);
2412 if (url == null) {
2413 return;
2414 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002415
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002416 // PENDING: should we just silently fail if phone is offhook or ringing?
2417 PhoneConstants.State state = mCM.getState(subId);
2418 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2419 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2420 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2421 mApp.startActivity(intent);
2422 }
2423 } finally {
2424 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002425 }
2426 }
2427
2428 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002429 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002430 }
2431
Wink Savilleb564aae2014-10-23 10:18:09 -07002432 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002433 if (DBG) log("call: " + number);
2434
2435 // This is just a wrapper around the ACTION_CALL intent, but we still
2436 // need to do a permission check since we're calling startActivity()
2437 // from the context of the phone app.
2438 enforceCallPermission();
2439
Jordan Liu1617b712019-07-10 15:06:26 -07002440 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002441 != AppOpsManager.MODE_ALLOWED) {
2442 return;
2443 }
2444
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002445 final long identity = Binder.clearCallingIdentity();
2446 try {
2447 String url = createTelUrl(number);
2448 if (url == null) {
2449 return;
2450 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002451
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002452 boolean isValid = false;
2453 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2454 if (slist != null) {
2455 for (SubscriptionInfo subInfoRecord : slist) {
2456 if (subInfoRecord.getSubscriptionId() == subId) {
2457 isValid = true;
2458 break;
2459 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002460 }
Wink Saville08874612014-08-31 19:19:58 -07002461 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002462 if (!isValid) {
2463 return;
2464 }
Wink Saville08874612014-08-31 19:19:58 -07002465
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002466 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2467 intent.putExtra(SUBSCRIPTION_KEY, subId);
2468 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2469 mApp.startActivity(intent);
2470 } finally {
2471 Binder.restoreCallingIdentity(identity);
2472 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002473 }
2474
Wink Savilleb564aae2014-10-23 10:18:09 -07002475 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002476 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002477 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2478 }
2479
Wink Savilleb564aae2014-10-23 10:18:09 -07002480 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002481 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002482 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2483 }
2484
Wink Savilleb564aae2014-10-23 10:18:09 -07002485 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002486 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002487
2488 final long identity = Binder.clearCallingIdentity();
2489 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002490 Phone phone = getPhone(subId);
2491 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002492 checkSimPin.start();
2493 return checkSimPin.unlockSim(null, pin);
2494 } finally {
2495 Binder.restoreCallingIdentity(identity);
2496 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002497 }
2498
Wink Savilleb564aae2014-10-23 10:18:09 -07002499 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002500 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002501
2502 final long identity = Binder.clearCallingIdentity();
2503 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002504 Phone phone = getPhone(subId);
2505 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002506 checkSimPuk.start();
2507 return checkSimPuk.unlockSim(puk, pin);
2508 } finally {
2509 Binder.restoreCallingIdentity(identity);
2510 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002511 }
2512
2513 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002514 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002515 * a synchronous one.
2516 */
2517 private static class UnlockSim extends Thread {
2518
2519 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002520 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002521
2522 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002523 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2524 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002525
2526 // For replies from SimCard interface
2527 private Handler mHandler;
2528
2529 // For async handler to identify request type
2530 private static final int SUPPLY_PIN_COMPLETE = 100;
2531
Michele Berionne5e411512020-11-13 02:36:59 +00002532 UnlockSim(int phoneId, IccCard simCard) {
2533 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002534 mSimCard = simCard;
2535 }
2536
2537 @Override
2538 public void run() {
2539 Looper.prepare();
2540 synchronized (UnlockSim.this) {
2541 mHandler = new Handler() {
2542 @Override
2543 public void handleMessage(Message msg) {
2544 AsyncResult ar = (AsyncResult) msg.obj;
2545 switch (msg.what) {
2546 case SUPPLY_PIN_COMPLETE:
2547 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2548 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002549 mRetryCount = msg.arg1;
2550 if (ar.exception != null) {
2551 if (ar.exception instanceof CommandException &&
2552 ((CommandException)(ar.exception)).getCommandError()
2553 == CommandException.Error.PASSWORD_INCORRECT) {
2554 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002555 } //When UiccCardApp dispose,handle message and return exception
2556 else if (ar.exception instanceof CommandException &&
2557 ((CommandException) (ar.exception)).getCommandError()
2558 == CommandException.Error.ABORTED) {
2559 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002560 } else {
2561 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2562 }
2563 } else {
2564 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2565 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002566 mDone = true;
2567 UnlockSim.this.notifyAll();
2568 }
2569 break;
2570 }
2571 }
2572 };
2573 UnlockSim.this.notifyAll();
2574 }
2575 Looper.loop();
2576 }
2577
2578 /*
2579 * Use PIN or PUK to unlock SIM card
2580 *
2581 * If PUK is null, unlock SIM card with PIN
2582 *
2583 * If PUK is not null, unlock SIM card with PUK and set PIN code
2584 */
Wink Saville9de0f752013-10-22 19:04:03 -07002585 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002586
2587 while (mHandler == null) {
2588 try {
2589 wait();
2590 } catch (InterruptedException e) {
2591 Thread.currentThread().interrupt();
2592 }
2593 }
2594 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2595
2596 if (puk == null) {
2597 mSimCard.supplyPin(pin, callback);
2598 } else {
2599 mSimCard.supplyPuk(puk, pin, callback);
2600 }
2601
2602 while (!mDone) {
2603 try {
2604 Log.d(LOG_TAG, "wait for done");
2605 wait();
2606 } catch (InterruptedException e) {
2607 // Restore the interrupted status
2608 Thread.currentThread().interrupt();
2609 }
2610 }
2611 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002612 int[] resultArray = new int[2];
2613 resultArray[0] = mResult;
2614 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002615
2616 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002617 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002618 }
2619
Wink Saville9de0f752013-10-22 19:04:03 -07002620 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002621 }
2622 }
2623
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002624 /**
2625 * This method has been removed due to privacy and stability concerns.
2626 */
2627 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002628 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002629 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2630 return;
Wink Saville36469e72014-06-11 15:17:00 -07002631 }
2632
Nathan Harold1f889d82020-06-04 17:05:26 -07002633 @Override
2634 public void updateServiceLocationWithPackageName(String callingPackage) {
2635 mApp.getSystemService(AppOpsManager.class)
2636 .checkPackage(Binder.getCallingUid(), callingPackage);
2637
Nathan Haroldf096d982020-11-18 17:18:06 -08002638 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002639 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2640 // Callers targeting S have no business invoking this method.
2641 return;
2642 }
2643
2644 LocationAccessPolicy.LocationPermissionResult locationResult =
2645 LocationAccessPolicy.checkLocationPermission(mApp,
2646 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2647 .setCallingPackage(callingPackage)
2648 .setCallingFeatureId(null)
2649 .setCallingPid(Binder.getCallingPid())
2650 .setCallingUid(Binder.getCallingUid())
2651 .setMethod("updateServiceLocation")
2652 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2653 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2654 .build());
2655 // Apps that lack location permission have no business calling this method;
2656 // however, because no permission was declared in the public API, denials must
2657 // all be "soft".
2658 switch (locationResult) {
2659 case DENIED_HARD: /* fall through */
2660 case DENIED_SOFT:
2661 return;
2662 }
2663
2664 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002665 final long identity = Binder.clearCallingIdentity();
2666 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002667 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002668 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002669 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002670 }
2671 } finally {
2672 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002673 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002674 }
2675
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002676 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002677 @Override
2678 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002679 return isRadioOnWithFeature(callingPackage, null);
2680 }
2681
2682
2683 @Override
2684 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2685 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2686 callingFeatureId);
2687 }
2688
2689 @Deprecated
2690 @Override
2691 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2692 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002693 }
2694
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002695 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002696 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2697 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002698 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002699 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002700 return false;
2701 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002702
2703 final long identity = Binder.clearCallingIdentity();
2704 try {
2705 return isRadioOnForSubscriber(subId);
2706 } finally {
2707 Binder.restoreCallingIdentity(identity);
2708 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002709 }
2710
2711 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002712 final long identity = Binder.clearCallingIdentity();
2713 try {
2714 final Phone phone = getPhone(subId);
2715 if (phone != null) {
2716 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2717 } else {
2718 return false;
2719 }
2720 } finally {
2721 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002722 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002723 }
2724
2725 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002726 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002727 }
Wink Saville36469e72014-06-11 15:17:00 -07002728
Wink Savilleb564aae2014-10-23 10:18:09 -07002729 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002730 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002731
2732 final long identity = Binder.clearCallingIdentity();
2733 try {
2734 final Phone phone = getPhone(subId);
2735 if (phone != null) {
2736 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2737 }
2738 } finally {
2739 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002740 }
Wink Saville36469e72014-06-11 15:17:00 -07002741 }
2742
2743 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002744 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002745 }
2746
Wink Savilleb564aae2014-10-23 10:18:09 -07002747 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002748 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002749
2750 final long identity = Binder.clearCallingIdentity();
2751 try {
2752 final Phone phone = getPhone(subId);
2753 if (phone == null) {
2754 return false;
2755 }
2756 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2757 toggleRadioOnOffForSubscriber(subId);
2758 }
2759 return true;
2760 } finally {
2761 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002762 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002763 }
Wink Saville36469e72014-06-11 15:17:00 -07002764
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002765 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002766 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002767 /*
2768 * If any of the Radios are available, it will need to be
2769 * shutdown. So return true if any Radio is available.
2770 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002771 final long identity = Binder.clearCallingIdentity();
2772 try {
2773 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2774 Phone phone = PhoneFactory.getPhone(i);
2775 if (phone != null && phone.isRadioAvailable()) return true;
2776 }
2777 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2778 return false;
2779 } finally {
2780 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002781 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002782 }
2783
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002784 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002785 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002786 enforceModifyPermission();
2787
2788 final long identity = Binder.clearCallingIdentity();
2789 try {
2790 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2791 logv("Shutting down Phone " + i);
2792 shutdownRadioUsingPhoneId(i);
2793 }
2794 } finally {
2795 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002796 }
2797 }
2798
2799 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002800 Phone phone = PhoneFactory.getPhone(phoneId);
2801 if (phone != null && phone.isRadioAvailable()) {
2802 phone.shutdownRadio();
2803 }
2804 }
2805
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002806 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002807 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002808
2809 final long identity = Binder.clearCallingIdentity();
2810 try {
2811 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2812 if (defaultPhone != null) {
2813 defaultPhone.setRadioPower(turnOn);
2814 return true;
2815 } else {
2816 loge("There's no default phone.");
2817 return false;
2818 }
2819 } finally {
2820 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002821 }
Wink Saville36469e72014-06-11 15:17:00 -07002822 }
2823
Wink Savilleb564aae2014-10-23 10:18:09 -07002824 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002825 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002826
2827 final long identity = Binder.clearCallingIdentity();
2828 try {
2829 final Phone phone = getPhone(subId);
2830 if (phone != null) {
2831 phone.setRadioPower(turnOn);
2832 return true;
2833 } else {
2834 return false;
2835 }
2836 } finally {
2837 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002838 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002839 }
2840
Wink Saville36469e72014-06-11 15:17:00 -07002841 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002842 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002843 public boolean enableDataConnectivity() {
2844 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002845
2846 final long identity = Binder.clearCallingIdentity();
2847 try {
2848 int subId = mSubscriptionController.getDefaultDataSubId();
2849 final Phone phone = getPhone(subId);
2850 if (phone != null) {
Jack Yu99e87332021-12-17 23:14:15 -08002851 if (phone.isUsingNewDataStack()) {
2852 phone.getDataSettingsManager().setDataEnabled(
2853 TelephonyManager.DATA_ENABLED_REASON_USER, true);
2854 } else {
2855 phone.getDataEnabledSettings().setDataEnabled(
2856 TelephonyManager.DATA_ENABLED_REASON_USER, true);
2857 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002858 return true;
2859 } else {
2860 return false;
2861 }
2862 } finally {
2863 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002864 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002865 }
2866
Wink Saville36469e72014-06-11 15:17:00 -07002867 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002868 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002869 public boolean disableDataConnectivity() {
2870 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002871
2872 final long identity = Binder.clearCallingIdentity();
2873 try {
2874 int subId = mSubscriptionController.getDefaultDataSubId();
2875 final Phone phone = getPhone(subId);
2876 if (phone != null) {
Jack Yu99e87332021-12-17 23:14:15 -08002877 if (phone.isUsingNewDataStack()) {
2878 phone.getDataSettingsManager().setDataEnabled(
2879 TelephonyManager.DATA_ENABLED_REASON_USER, false);
2880 } else {
2881 phone.getDataEnabledSettings().setDataEnabled(
2882 TelephonyManager.DATA_ENABLED_REASON_USER, false);
2883 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002884 return true;
2885 } else {
2886 return false;
2887 }
2888 } finally {
2889 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002890 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002891 }
2892
Sanket Padawe356d7632015-06-22 14:03:32 -07002893 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002894 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002895 final long identity = Binder.clearCallingIdentity();
2896 try {
2897 final Phone phone = getPhone(subId);
2898 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002899 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002900 } else {
2901 return false;
2902 }
2903 } finally {
2904 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002905 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002906 }
2907
2908 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002909 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002910 }
2911
pkanwarae03a6b2016-11-06 20:37:09 -08002912 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002913 enforceCallPermission();
2914
2915 final long identity = Binder.clearCallingIdentity();
2916 try {
2917 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2918 return;
2919 }
2920 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2921 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2922 } finally {
2923 Binder.restoreCallingIdentity(identity);
2924 }
pkanwar32d516d2016-10-14 19:37:38 -07002925 };
2926
Wink Savilleb564aae2014-10-23 10:18:09 -07002927 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002928 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002929
2930 final long identity = Binder.clearCallingIdentity();
2931 try {
2932 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2933 return false;
2934 }
2935 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2936 } finally {
2937 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002938 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002939 }
2940
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002941 /**
2942 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2943 * tag on getCallState Binder call.
2944 */
2945 @Deprecated
2946 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002947 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002948 if (CompatChanges.isChangeEnabled(
2949 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2950 Binder.getCallingUid())) {
2951 // Do not allow this API to be called on API version 31+, it should only be
2952 // called on old apps using this Binder call directly.
2953 throw new SecurityException("This method can only be used for applications "
2954 + "targeting API version 30 or less.");
2955 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002956 final long identity = Binder.clearCallingIdentity();
2957 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002958 Phone phone = getPhone(getDefaultSubscription());
2959 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2960 PhoneConstantConversions.convertCallState(phone.getState());
2961 } finally {
2962 Binder.restoreCallingIdentity(identity);
2963 }
2964 }
2965
2966 @Override
2967 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2968 if (CompatChanges.isChangeEnabled(
2969 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2970 Binder.getCallingUid())) {
2971 // Check READ_PHONE_STATE for API version 31+
2972 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2973 featureId, "getCallStateForSubscription")) {
2974 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2975 + "targeting API level 31+.");
2976 }
2977 }
2978 final long identity = Binder.clearCallingIdentity();
2979 try {
2980 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002981 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2982 PhoneConstantConversions.convertCallState(phone.getState());
2983 } finally {
2984 Binder.restoreCallingIdentity(identity);
2985 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002986 }
2987
Sanket Padawe356d7632015-06-22 14:03:32 -07002988 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002989 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002990 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2991 }
2992
2993 @Override
2994 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002995 final long identity = Binder.clearCallingIdentity();
2996 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002997 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002998 if (phone != null) {
Jack Yu2c450952021-11-29 11:36:17 -08002999 if (phone.isUsingNewDataStack()) {
3000 return phone.getDataNetworkController().getInternetDataNetworkState();
3001 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003002 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
3003 } else {
3004 return PhoneConstantConversions.convertDataState(
3005 PhoneConstants.DataState.DISCONNECTED);
3006 }
3007 } finally {
3008 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003009 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003010 }
3011
Sanket Padawe356d7632015-06-22 14:03:32 -07003012 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003013 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003014 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
3015 }
3016
3017 @Override
3018 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003019 final long identity = Binder.clearCallingIdentity();
3020 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003021 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003022 if (phone != null) {
3023 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
3024 } else {
3025 return TelephonyManager.DATA_ACTIVITY_NONE;
3026 }
3027 } finally {
3028 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003029 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003030 }
3031
3032 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003033 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003034 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003035 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003036
3037 LocationAccessPolicy.LocationPermissionResult locationResult =
3038 LocationAccessPolicy.checkLocationPermission(mApp,
3039 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3040 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003041 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003042 .setCallingPid(Binder.getCallingPid())
3043 .setCallingUid(Binder.getCallingUid())
3044 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003045 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003046 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3047 .build());
3048 switch (locationResult) {
3049 case DENIED_HARD:
3050 throw new SecurityException("Not allowed to access cell location");
3051 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003052 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3053 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003054 }
3055
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003056 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003057 final long identity = Binder.clearCallingIdentity();
3058 try {
3059 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003060 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003061 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003062 } finally {
3063 Binder.restoreCallingIdentity(identity);
3064 }
Svetoslav64fad262015-04-14 14:35:21 -07003065 }
3066
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003067 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003068 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003069 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3070 // registered cell info, so return a NULL country instead.
3071 final long identity = Binder.clearCallingIdentity();
3072 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003073 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3074 // Get default phone in this case.
3075 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3076 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003077 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003078 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003079 if (phone == null) return "";
3080 ServiceStateTracker sst = phone.getServiceStateTracker();
3081 if (sst == null) return "";
3082 LocaleTracker lt = sst.getLocaleTracker();
3083 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003084 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003085 } finally {
3086 Binder.restoreCallingIdentity(identity);
3087 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003088 }
3089
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003090 /**
3091 * This method was removed due to potential issues caused by performing partial
3092 * updates of service state, and lack of a credible use case.
3093 *
3094 * This has the ability to break the telephony implementation by disabling notification of
3095 * changes in device connectivity. DO NOT USE THIS!
3096 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003097 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003098 public void enableLocationUpdates() {
3099 mApp.enforceCallingOrSelfPermission(
3100 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003101 }
3102
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003103 /**
3104 * This method was removed due to potential issues caused by performing partial
3105 * updates of service state, and lack of a credible use case.
3106 *
3107 * This has the ability to break the telephony implementation by disabling notification of
3108 * changes in device connectivity. DO NOT USE THIS!
3109 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003110 @Override
3111 public void disableLocationUpdates() {
3112 mApp.enforceCallingOrSelfPermission(
3113 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003114 }
3115
3116 @Override
3117 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003118 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3119 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003120 try {
3121 mApp.getSystemService(AppOpsManager.class)
3122 .checkPackage(Binder.getCallingUid(), callingPackage);
3123 } catch (SecurityException e) {
3124 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3125 throw e;
3126 }
3127
Nathan Haroldf096d982020-11-18 17:18:06 -08003128 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003129 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3130 throw new SecurityException(
3131 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3132 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003133
Jordan Liu1617b712019-07-10 15:06:26 -07003134 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003135 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3136 return null;
3137 }
Svetoslav64fad262015-04-14 14:35:21 -07003138
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003139 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003140
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003141 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003142 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003143
Nathan Haroldf180aac2018-06-01 18:43:55 -07003144 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3145 for (CellInfo ci : info) {
3146 if (ci instanceof CellInfoGsm) {
3147 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3148 } else if (ci instanceof CellInfoWcdma) {
3149 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3150 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003151 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003152 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003153 }
3154
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003155 private List<CellInfo> getCachedCellInfo() {
3156 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3157 for (Phone phone : PhoneFactory.getPhones()) {
3158 List<CellInfo> info = phone.getAllCellInfo();
3159 if (info != null) cellInfos.addAll(info);
3160 }
3161 return cellInfos;
3162 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003163
3164 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003165 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003166 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003167 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003168
3169 LocationAccessPolicy.LocationPermissionResult locationResult =
3170 LocationAccessPolicy.checkLocationPermission(mApp,
3171 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3172 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003173 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003174 .setCallingPid(Binder.getCallingPid())
3175 .setCallingUid(Binder.getCallingUid())
3176 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003177 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003178 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3179 .build());
3180 switch (locationResult) {
3181 case DENIED_HARD:
3182 throw new SecurityException("Not allowed to access cell info");
3183 case DENIED_SOFT:
3184 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003185 }
3186
Nathan Haroldf096d982020-11-18 17:18:06 -08003187 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003188 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3189 return getCachedCellInfo();
3190 }
3191
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003192 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003193 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003194 final long identity = Binder.clearCallingIdentity();
3195 try {
3196 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3197 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003198 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003199 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003200 if (info != null) cellInfos.addAll(info);
3201 }
3202 return cellInfos;
3203 } finally {
3204 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003205 }
3206 }
3207
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003208 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003209 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3210 String callingFeatureId) {
3211 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3212 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003213 }
3214
3215 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003216 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3217 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003218 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003219 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003220 }
3221
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003222 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3223 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003224 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003225 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003226
3227 LocationAccessPolicy.LocationPermissionResult locationResult =
3228 LocationAccessPolicy.checkLocationPermission(mApp,
3229 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3230 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003231 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003232 .setCallingPid(Binder.getCallingPid())
3233 .setCallingUid(Binder.getCallingUid())
3234 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003235 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3236 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003237 .build());
3238 switch (locationResult) {
3239 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003240 if (TelephonyPermissions
3241 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003242 // Safetynet logging for b/154934934
3243 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3244 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003245 throw new SecurityException("Not allowed to access cell info");
3246 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003247 if (TelephonyPermissions
3248 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003249 // Safetynet logging for b/154934934
3250 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3251 }
Nathan Harold5320c422019-05-09 10:26:08 -07003252 try {
3253 cb.onCellInfo(new ArrayList<CellInfo>());
3254 } catch (RemoteException re) {
3255 // Drop without consequences
3256 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003257 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003258 }
3259
Nathan Harolda939a962019-05-09 10:13:47 -07003260
3261 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003262 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3263
3264 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3265 }
3266
3267 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003268 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003269 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003270 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003271
3272 final long identity = Binder.clearCallingIdentity();
3273 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003274 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003275 } finally {
3276 Binder.restoreCallingIdentity(identity);
3277 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003278 }
3279
Shishir Agrawala9f32182016-04-12 12:00:16 -07003280 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003281 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003282 Phone phone = PhoneFactory.getPhone(slotIndex);
3283 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003284 return null;
3285 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003286 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003287 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003288 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003289 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003290 return null;
3291 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003292
3293 final long identity = Binder.clearCallingIdentity();
3294 try {
3295 return phone.getImei();
3296 } finally {
3297 Binder.restoreCallingIdentity(identity);
3298 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003299 }
3300
3301 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003302 public String getTypeAllocationCodeForSlot(int slotIndex) {
3303 Phone phone = PhoneFactory.getPhone(slotIndex);
3304 String tac = null;
3305 if (phone != null) {
3306 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003307 try {
3308 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3309 } catch (IndexOutOfBoundsException e) {
3310 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3311 return null;
3312 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003313 }
3314 return tac;
3315 }
3316
3317 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003318 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003319 try {
3320 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3321 } catch (SecurityException se) {
3322 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3323 throw new SecurityException("Package " + callingPackage + " does not belong to "
3324 + Binder.getCallingUid());
3325 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003326 Phone phone = PhoneFactory.getPhone(slotIndex);
3327 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003328 return null;
3329 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003330
Jeff Davidson913390f2018-02-23 17:11:49 -08003331 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003332 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003333 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003334 return null;
3335 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003336
3337 final long identity = Binder.clearCallingIdentity();
3338 try {
3339 return phone.getMeid();
3340 } finally {
3341 Binder.restoreCallingIdentity(identity);
3342 }
Jack Yu2af8d712017-03-15 17:14:14 -07003343 }
3344
3345 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003346 public String getManufacturerCodeForSlot(int slotIndex) {
3347 Phone phone = PhoneFactory.getPhone(slotIndex);
3348 String manufacturerCode = null;
3349 if (phone != null) {
3350 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003351 try {
3352 manufacturerCode =
3353 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3354 } catch (IndexOutOfBoundsException e) {
3355 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3356 return null;
3357 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003358 }
3359 return manufacturerCode;
3360 }
3361
3362 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003363 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3364 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003365 Phone phone = PhoneFactory.getPhone(slotIndex);
3366 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003367 return null;
3368 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003369 int subId = phone.getSubId();
3370 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003371 mApp, subId, callingPackage, callingFeatureId,
3372 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003373 return null;
3374 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003375
3376 final long identity = Binder.clearCallingIdentity();
3377 try {
3378 return phone.getDeviceSvn();
3379 } finally {
3380 Binder.restoreCallingIdentity(identity);
3381 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003382 }
3383
fionaxu43304da2017-11-27 22:51:16 -08003384 @Override
3385 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003386 final long identity = Binder.clearCallingIdentity();
3387 try {
3388 final Phone phone = getPhone(subId);
3389 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3390 } finally {
3391 Binder.restoreCallingIdentity(identity);
3392 }
fionaxu43304da2017-11-27 22:51:16 -08003393 }
3394
3395 @Override
3396 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003397 final long identity = Binder.clearCallingIdentity();
3398 try {
3399 final Phone phone = getPhone(subId);
3400 return phone == null ? null : phone.getCarrierName();
3401 } finally {
3402 Binder.restoreCallingIdentity(identity);
3403 }
fionaxu43304da2017-11-27 22:51:16 -08003404 }
3405
calvinpanffe225e2018-11-01 19:43:06 +08003406 @Override
chen xu0026ca62019-03-06 15:28:50 -08003407 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003408 final long identity = Binder.clearCallingIdentity();
3409 try {
3410 final Phone phone = getPhone(subId);
3411 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003412 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003413 } finally {
3414 Binder.restoreCallingIdentity(identity);
3415 }
3416 }
3417
3418 @Override
chen xu0026ca62019-03-06 15:28:50 -08003419 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003420 final long identity = Binder.clearCallingIdentity();
3421 try {
3422 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003423 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003424 } finally {
3425 Binder.restoreCallingIdentity(identity);
3426 }
3427 }
3428
chen xu651eec72018-11-11 19:03:44 -08003429 @Override
chen xu864e11c2018-12-06 22:10:03 -08003430 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3431 if (!isSubscriptionMccMnc) {
3432 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3433 }
chen xu651eec72018-11-11 19:03:44 -08003434 final Phone phone = PhoneFactory.getPhone(slotIndex);
3435 if (phone == null) {
3436 return TelephonyManager.UNKNOWN_CARRIER_ID;
3437 }
3438 final long identity = Binder.clearCallingIdentity();
3439 try {
3440 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3441 } finally {
3442 Binder.restoreCallingIdentity(identity);
3443 }
3444 }
3445
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003446 //
3447 // Internal helper methods.
3448 //
3449
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003450 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003451 * Make sure the caller is the calling package itself
3452 *
3453 * @throws SecurityException if the caller is not the calling package
3454 */
3455 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3456 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003457 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3458 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003459 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003460 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003461 } catch (PackageManager.NameNotFoundException e) {
3462 // packageUid is -1
3463 }
3464 if (packageUid != callingUid) {
3465 throw new SecurityException(message + ": Package " + callingPackage
3466 + " does not belong to " + callingUid);
3467 }
3468 }
3469
3470 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003471 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3472 *
3473 * @throws SecurityException if the caller does not have the required permission
3474 */
3475 private void enforceModifyPermission() {
3476 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3477 }
3478
Shuo Qian3b6ee772019-11-13 17:43:31 -08003479 private void enforceActiveEmergencySessionPermission() {
3480 mApp.enforceCallingOrSelfPermission(
3481 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3482 }
3483
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003484 /**
3485 * Make sure the caller has the CALL_PHONE permission.
3486 *
3487 * @throws SecurityException if the caller does not have the required permission
3488 */
3489 private void enforceCallPermission() {
3490 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3491 }
3492
paulhu5a773602019-08-23 19:17:33 +08003493 private void enforceSettingsPermission() {
3494 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003495 }
3496
Michele Berionne5e411512020-11-13 02:36:59 +00003497 private void enforceRebootPermission() {
3498 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3499 }
3500
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003501 private String createTelUrl(String number) {
3502 if (TextUtils.isEmpty(number)) {
3503 return null;
3504 }
3505
Jake Hambye994d462014-02-03 13:10:13 -08003506 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003507 }
3508
Ihab Awadf9e92732013-12-05 18:02:52 -08003509 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003510 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3511 }
3512
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003513 private static void logv(String msg) {
3514 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3515 }
3516
Ihab Awadf9e92732013-12-05 18:02:52 -08003517 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003518 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3519 }
3520
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003521 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003522 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003523 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003524 }
3525
Sanket Padawe356d7632015-06-22 14:03:32 -07003526 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003527 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003528 final long identity = Binder.clearCallingIdentity();
3529 try {
3530 final Phone phone = PhoneFactory.getPhone(slotIndex);
3531 if (phone == null) {
3532 return PhoneConstants.PHONE_TYPE_NONE;
3533 } else {
3534 return phone.getPhoneType();
3535 }
3536 } finally {
3537 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003538 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003539 }
3540
3541 /**
3542 * Returns the CDMA ERI icon index to display
3543 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003544 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003545 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3546 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3547 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003548 }
3549
Sanket Padawe356d7632015-06-22 14:03:32 -07003550 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003551 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3552 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003553 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003554 mApp, subId, callingPackage, callingFeatureId,
3555 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003556 return -1;
3557 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003558
3559 final long identity = Binder.clearCallingIdentity();
3560 try {
3561 final Phone phone = getPhone(subId);
3562 if (phone != null) {
3563 return phone.getCdmaEriIconIndex();
3564 } else {
3565 return -1;
3566 }
3567 } finally {
3568 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003569 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003570 }
3571
3572 /**
3573 * Returns the CDMA ERI icon mode,
3574 * 0 - ON
3575 * 1 - FLASHING
3576 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003577 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003578 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3579 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3580 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003581 }
3582
Sanket Padawe356d7632015-06-22 14:03:32 -07003583 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003584 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3585 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003586 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003587 mApp, subId, callingPackage, callingFeatureId,
3588 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003589 return -1;
3590 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003591
3592 final long identity = Binder.clearCallingIdentity();
3593 try {
3594 final Phone phone = getPhone(subId);
3595 if (phone != null) {
3596 return phone.getCdmaEriIconMode();
3597 } else {
3598 return -1;
3599 }
3600 } finally {
3601 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003602 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003603 }
3604
3605 /**
3606 * Returns the CDMA ERI text,
3607 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003608 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003609 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3610 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3611 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003612 }
3613
Sanket Padawe356d7632015-06-22 14:03:32 -07003614 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003615 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3616 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003617 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003618 mApp, subId, callingPackage, callingFeatureId,
3619 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003620 return null;
3621 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003622
3623 final long identity = Binder.clearCallingIdentity();
3624 try {
3625 final Phone phone = getPhone(subId);
3626 if (phone != null) {
3627 return phone.getCdmaEriText();
3628 } else {
3629 return null;
3630 }
3631 } finally {
3632 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003633 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003634 }
3635
3636 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003637 * Returns the CDMA MDN.
3638 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003639 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003640 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003641 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3642 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003643
3644 final long identity = Binder.clearCallingIdentity();
3645 try {
3646 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003647 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003648 return phone.getLine1Number();
3649 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003650 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003651 return null;
3652 }
3653 } finally {
3654 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003655 }
3656 }
3657
3658 /**
3659 * Returns the CDMA MIN.
3660 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003661 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003662 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003663 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3664 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003665
3666 final long identity = Binder.clearCallingIdentity();
3667 try {
3668 final Phone phone = getPhone(subId);
3669 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3670 return phone.getCdmaMin();
3671 } else {
3672 return null;
3673 }
3674 } finally {
3675 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003676 }
3677 }
3678
Hall Liud892bec2018-11-30 14:51:45 -08003679 @Override
3680 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3681 INumberVerificationCallback callback, String callingPackage) {
3682 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3683 != PERMISSION_GRANTED) {
3684 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3685 }
3686 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3687
3688 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3689 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003690 throw new SecurityException("Calling package must be configured in the device config: "
3691 + "calling package: " + callingPackage
3692 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003693 }
3694
3695 if (range == null) {
3696 throw new NullPointerException("Range must be non-null");
3697 }
3698
3699 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003700 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003701
3702 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3703 }
3704
Junda Liuca05d5d2014-08-14 22:36:34 -07003705 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003706 * Returns true if CDMA provisioning needs to run.
3707 */
3708 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003709 final long identity = Binder.clearCallingIdentity();
3710 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003711 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003712 } finally {
3713 Binder.restoreCallingIdentity(identity);
3714 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003715 }
3716
3717 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003718 * Sets the voice mail number of a given subId.
3719 */
3720 @Override
3721 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003722 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3723 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003724
3725 final long identity = Binder.clearCallingIdentity();
3726 try {
3727 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3728 new Pair<String, String>(alphaTag, number), new Integer(subId));
3729 return success;
3730 } finally {
3731 Binder.restoreCallingIdentity(identity);
3732 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003733 }
3734
Ta-wei Yen87c49842016-05-13 21:19:52 -07003735 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003736 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3737 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003738 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3739 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003740 if (!TextUtils.equals(callingPackage, systemDialer)) {
3741 throw new SecurityException("caller must be system dialer");
3742 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003743
3744 final long identity = Binder.clearCallingIdentity();
3745 try {
3746 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3747 if (phoneAccountHandle == null) {
3748 return null;
3749 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003750 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003751 } finally {
3752 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003753 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003754 }
3755
3756 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003757 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3758 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003759 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003760 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003761 mApp, subId, callingPackage, callingFeatureId,
3762 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003763 return null;
3764 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003765
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003766 final long identity = Binder.clearCallingIdentity();
3767 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003768 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003769 } finally {
3770 Binder.restoreCallingIdentity(identity);
3771 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003772 }
3773
3774 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003775 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3776 VisualVoicemailSmsFilterSettings settings) {
3777 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003778
3779 final long identity = Binder.clearCallingIdentity();
3780 try {
3781 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003782 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003783 } finally {
3784 Binder.restoreCallingIdentity(identity);
3785 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003786 }
3787
3788 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003789 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3790 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003791
3792 final long identity = Binder.clearCallingIdentity();
3793 try {
3794 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003795 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003796 } finally {
3797 Binder.restoreCallingIdentity(identity);
3798 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003799 }
3800
3801 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003802 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3803 String callingPackage, int subId) {
3804 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003805
3806 final long identity = Binder.clearCallingIdentity();
3807 try {
3808 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003809 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003810 } finally {
3811 Binder.restoreCallingIdentity(identity);
3812 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003813 }
3814
3815 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003816 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003817 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003818
3819 final long identity = Binder.clearCallingIdentity();
3820 try {
3821 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003822 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003823 } finally {
3824 Binder.restoreCallingIdentity(identity);
3825 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003826 }
3827
3828 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003829 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3830 String callingAttributionTag, int subId, String number, int port, String text,
3831 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003832 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003833 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003834 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003835 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003836 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3837 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003838 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003839
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003840 /**
fionaxu0152e512016-11-14 13:36:14 -08003841 * Sets the voice activation state of a given subId.
3842 */
3843 @Override
3844 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003845 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3846 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003847
3848 final long identity = Binder.clearCallingIdentity();
3849 try {
3850 final Phone phone = getPhone(subId);
3851 if (phone != null) {
3852 phone.setVoiceActivationState(activationState);
3853 } else {
3854 loge("setVoiceActivationState fails with invalid subId: " + subId);
3855 }
3856 } finally {
3857 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003858 }
3859 }
3860
3861 /**
3862 * Sets the data activation state of a given subId.
3863 */
3864 @Override
3865 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003866 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3867 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003868
3869 final long identity = Binder.clearCallingIdentity();
3870 try {
3871 final Phone phone = getPhone(subId);
3872 if (phone != null) {
3873 phone.setDataActivationState(activationState);
3874 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003875 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003876 }
3877 } finally {
3878 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003879 }
3880 }
3881
3882 /**
3883 * Returns the voice activation state of a given subId.
3884 */
3885 @Override
3886 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003887 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003888
fionaxu0152e512016-11-14 13:36:14 -08003889 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003890 final long identity = Binder.clearCallingIdentity();
3891 try {
3892 if (phone != null) {
3893 return phone.getVoiceActivationState();
3894 } else {
3895 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3896 }
3897 } finally {
3898 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003899 }
3900 }
3901
3902 /**
3903 * Returns the data activation state of a given subId.
3904 */
3905 @Override
3906 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003907 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003908
fionaxu0152e512016-11-14 13:36:14 -08003909 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003910 final long identity = Binder.clearCallingIdentity();
3911 try {
3912 if (phone != null) {
3913 return phone.getDataActivationState();
3914 } else {
3915 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3916 }
3917 } finally {
3918 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003919 }
3920 }
3921
3922 /**
Wink Saville36469e72014-06-11 15:17:00 -07003923 * Returns the unread count of voicemails for a subId
3924 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003925 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003926 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3927 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003928 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003929 mApp, subId, callingPackage, callingFeatureId,
3930 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003931 return 0;
3932 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003933 final long identity = Binder.clearCallingIdentity();
3934 try {
3935 final Phone phone = getPhone(subId);
3936 if (phone != null) {
3937 return phone.getVoiceMessageCount();
3938 } else {
3939 return 0;
3940 }
3941 } finally {
3942 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003943 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003944 }
3945
3946 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003947 * returns true, if the device is in a state where both voice and data
3948 * are supported simultaneously. This can change based on location or network condition.
3949 */
3950 @Override
3951 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003952 final long identity = Binder.clearCallingIdentity();
3953 try {
3954 final Phone phone = getPhone(subId);
3955 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3956 } finally {
3957 Binder.restoreCallingIdentity(identity);
3958 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003959 }
3960
3961 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003962 * Send the dialer code if called from the current default dialer or the caller has
3963 * carrier privilege.
3964 * @param inputCode The dialer code to send
3965 */
3966 @Override
3967 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003968 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003969 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003970 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3971 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003972 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003973 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003974 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003975 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003976
3977 final long identity = Binder.clearCallingIdentity();
3978 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003979 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003980 } finally {
3981 Binder.restoreCallingIdentity(identity);
3982 }
fionaxu235cc5e2017-03-06 22:25:57 -08003983 }
3984
Pengquan Menga1bb6272018-09-06 09:59:22 -07003985 @Override
3986 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003987 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003988 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003989 mApp, subId, "getNetworkSelectionMode");
3990 final long identity = Binder.clearCallingIdentity();
3991 try {
3992 if (!isActiveSubscription(subId)) {
3993 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3994 }
3995 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3996 } finally {
3997 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003998 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003999 }
4000
Brad Ebinger35c841c2018-10-01 10:40:55 -07004001 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004002 public boolean isInEmergencySmsMode() {
4003 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4004 final long identity = Binder.clearCallingIdentity();
4005 try {
4006 for (Phone phone : PhoneFactory.getPhones()) {
4007 if (phone.isInEmergencySmsMode()) {
4008 return true;
4009 }
4010 }
4011 } finally {
4012 Binder.restoreCallingIdentity(identity);
4013 }
4014 return false;
4015 }
4016
shilu366312e2019-12-17 09:28:10 -08004017 /**
4018 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4019 * @param subId The subscription to use to check the configuration.
4020 * @param c The callback that will be used to send the result.
4021 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004022 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004023 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4024 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004025 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004026 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08004027
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004028 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4029 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4030 "IMS not available on device.");
4031 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004032 final long token = Binder.clearCallingIdentity();
4033 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004034 int slotId = getSlotIndexOrException(subId);
4035 verifyImsMmTelConfiguredOrThrow(slotId);
4036 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004037 } catch (ImsException e) {
4038 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004039 } finally {
4040 Binder.restoreCallingIdentity(token);
4041 }
4042 }
4043
shilu366312e2019-12-17 09:28:10 -08004044 /**
4045 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4046 * @param subId The subscription to use to check the configuration.
4047 * @param c The callback that will be used to send the result.
4048 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004049 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004050 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004051 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004052 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004053 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4054 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4055 }
Meng Wangafbc5852019-09-19 17:37:13 -07004056 final long token = Binder.clearCallingIdentity();
4057 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004058 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4059 .removeRegistrationCallbackForSubscription(c, subId);
4060 } catch (ImsException e) {
4061 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4062 + "is inactive, ignoring unregister.");
4063 // If the subscription is no longer active, just return, since the callback
4064 // will already have been removed internally.
4065 } finally {
4066 Binder.restoreCallingIdentity(token);
4067 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004068 }
4069
Brad Ebingera34a6c22019-10-22 17:36:18 -07004070 /**
4071 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4072 */
4073 @Override
4074 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4075 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4076 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4077 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4078 "IMS not available on device.");
4079 }
4080 final long token = Binder.clearCallingIdentity();
4081 try {
4082 Phone phone = getPhone(subId);
4083 if (phone == null) {
4084 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4085 + subId + "'");
4086 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4087 }
4088 phone.getImsRegistrationState(regState -> {
4089 try {
4090 consumer.accept((regState == null)
4091 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4092 } catch (RemoteException e) {
4093 // Ignore if the remote process is no longer available to call back.
4094 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4095 }
4096 });
4097 } finally {
4098 Binder.restoreCallingIdentity(token);
4099 }
4100 }
4101
4102 /**
4103 * Get the transport type for the IMS service registration state.
4104 */
4105 @Override
4106 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004107 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004108 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004109 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4110 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4111 "IMS not available on device.");
4112 }
4113 final long token = Binder.clearCallingIdentity();
4114 try {
4115 Phone phone = getPhone(subId);
4116 if (phone == null) {
4117 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4118 + subId + "'");
4119 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4120 }
4121 phone.getImsRegistrationTech(regTech -> {
4122 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4123 int regTechConverted = (regTech == null)
4124 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4125 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4126 regTechConverted);
4127 try {
4128 consumer.accept(regTechConverted);
4129 } catch (RemoteException e) {
4130 // Ignore if the remote process is no longer available to call back.
4131 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4132 }
4133 });
4134 } finally {
4135 Binder.restoreCallingIdentity(token);
4136 }
4137 }
4138
shilu366312e2019-12-17 09:28:10 -08004139 /**
4140 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4141 * @param subId The subscription to use to check the configuration.
4142 * @param c The callback that will be used to send the result.
4143 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004144 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004145 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4146 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004147 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004148 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004149 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4150 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4151 "IMS not available on device.");
4152 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004153 final long token = Binder.clearCallingIdentity();
4154 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004155 int slotId = getSlotIndexOrException(subId);
4156 verifyImsMmTelConfiguredOrThrow(slotId);
4157 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004158 } catch (ImsException e) {
4159 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004160 } finally {
4161 Binder.restoreCallingIdentity(token);
4162 }
4163 }
4164
shilu366312e2019-12-17 09:28:10 -08004165 /**
4166 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4167 * @param subId The subscription to use to check the configuration.
4168 * @param c The callback that will be used to send the result.
4169 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004170 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004171 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004172 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004173 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004174 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4175 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4176 }
Meng Wangafbc5852019-09-19 17:37:13 -07004177
4178 final long token = Binder.clearCallingIdentity();
4179 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004180 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004181 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004182 } catch (ImsException e) {
4183 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4184 + "is inactive, ignoring unregister.");
4185 // If the subscription is no longer active, just return, since the callback
4186 // will already have been removed internally.
4187 } finally {
4188 Binder.restoreCallingIdentity(token);
4189 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004190 }
4191
4192 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004193 public boolean isCapable(int subId, int capability, int regTech) {
4194 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004195 final long token = Binder.clearCallingIdentity();
4196 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004197 int slotId = getSlotIndexOrException(subId);
4198 verifyImsMmTelConfiguredOrThrow(slotId);
4199 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004200 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004201 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4202 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004203 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004204 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4205 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004206 } finally {
4207 Binder.restoreCallingIdentity(token);
4208 }
4209 }
4210
4211 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004212 public boolean isAvailable(int subId, int capability, int regTech) {
4213 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004214 final long token = Binder.clearCallingIdentity();
4215 try {
4216 Phone phone = getPhone(subId);
4217 if (phone == null) return false;
4218 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004219 } catch (com.android.ims.ImsException e) {
4220 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4221 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004222 } finally {
4223 Binder.restoreCallingIdentity(token);
4224 }
4225 }
4226
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004227 /**
4228 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4229 * subscription.
4230 * @param subId The subscription to use to check the configuration.
4231 * @param callback The callback that will be used to send the result.
4232 * @param capability The MmTelFeature capability that will be used to send the result.
4233 * @param transportType The transport type of the MmTelFeature capability.
4234 */
4235 @Override
4236 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4237 int transportType) {
4238 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4239 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4240 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4241 "IMS not available on device.");
4242 }
4243 final long token = Binder.clearCallingIdentity();
4244 try {
4245 int slotId = getSlotIndex(subId);
4246 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4247 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4248 + subId + "'");
4249 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4250 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004251 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004252 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4253 transportType, aBoolean -> {
4254 try {
4255 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4256 } catch (RemoteException e) {
4257 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4258 + "running. Ignore");
4259 }
4260 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004261 } catch (ImsException e) {
4262 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004263 } finally {
4264 Binder.restoreCallingIdentity(token);
4265 }
4266 }
4267
shilu366312e2019-12-17 09:28:10 -08004268 /**
4269 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4270 * @param subId The subscription to use to check the configuration.
4271 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004272 @Override
4273 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004274 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004275 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004276
Brad Ebinger35c841c2018-10-01 10:40:55 -07004277 final long token = Binder.clearCallingIdentity();
4278 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004279 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004280 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004281 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004282 } catch (ImsException e) {
4283 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004284 } finally {
4285 Binder.restoreCallingIdentity(token);
4286 }
4287 }
4288
4289 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004290 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004291 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004292 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004293 final long identity = Binder.clearCallingIdentity();
4294 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004295 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004296 // This setting doesn't require an active ImsService connection, so do not verify. The
4297 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004298 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004299 } catch (ImsException e) {
4300 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004301 } finally {
4302 Binder.restoreCallingIdentity(identity);
4303 }
4304 }
4305
shilu366312e2019-12-17 09:28:10 -08004306 /**
4307 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4308 * @param subId The subscription to use to check the configuration.
4309 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004310 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004311 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004312 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004313 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004314 final long identity = Binder.clearCallingIdentity();
4315 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004316 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004317 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004318 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004319 } catch (ImsException e) {
4320 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004321 } finally {
4322 Binder.restoreCallingIdentity(identity);
4323 }
4324 }
4325
4326 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004327 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004328 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004329 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004330 final long identity = Binder.clearCallingIdentity();
4331 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004332 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004333 // This setting doesn't require an active ImsService connection, so do not verify. The
4334 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004335 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004336 } catch (ImsException e) {
4337 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004338 } finally {
4339 Binder.restoreCallingIdentity(identity);
4340 }
4341 }
4342
shilu366312e2019-12-17 09:28:10 -08004343 /**
4344 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4345 * @param subId The subscription to use to check the configuration.
4346 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004347 @Override
4348 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004349 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004350 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004351 final long identity = Binder.clearCallingIdentity();
4352 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004353 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004354 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004355 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004356 } catch (ImsException e) {
4357 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004358 } finally {
4359 Binder.restoreCallingIdentity(identity);
4360 }
4361 }
4362
4363 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004364 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004365 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004366 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004367 final long identity = Binder.clearCallingIdentity();
4368 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004369 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004370 // This setting doesn't require an active ImsService connection, so do not verify. The
4371 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004372 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004373 } catch (ImsException e) {
4374 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004375 } finally {
4376 Binder.restoreCallingIdentity(identity);
4377 }
4378 }
4379
shilu366312e2019-12-17 09:28:10 -08004380 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004381 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4382 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4383 * @param subId The subscription to use to check the configuration.
4384 */
4385 @Override
4386 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004387 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004388 mApp, subId, "isCrossSimCallingEnabledByUser");
4389 final long identity = Binder.clearCallingIdentity();
4390 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004391 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004392 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004393 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004394 } catch (ImsException e) {
4395 throw new ServiceSpecificException(e.getCode());
4396 } finally {
4397 Binder.restoreCallingIdentity(identity);
4398 }
4399 }
4400
4401 /**
4402 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4403 * Requires MODIFY_PHONE_STATE permission.
4404 * @param subId The subscription to use to check the configuration.
4405 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4406 * false otherwise
4407 */
4408 @Override
4409 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4410 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4411 "setCrossSimCallingEnabled");
4412 final long identity = Binder.clearCallingIdentity();
4413 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004414 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004415 // This setting doesn't require an active ImsService connection, so do not verify. The
4416 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004417 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004418 } catch (ImsException e) {
4419 throw new ServiceSpecificException(e.getCode());
4420 } finally {
4421 Binder.restoreCallingIdentity(identity);
4422 }
4423 }
4424
4425 /**
shilu366312e2019-12-17 09:28:10 -08004426 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4427 * @param subId The subscription to use to check the configuration.
4428 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004429 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004430
Brad Ebinger35c841c2018-10-01 10:40:55 -07004431 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004432 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004433 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004434 final long identity = Binder.clearCallingIdentity();
4435 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004436 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004437 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004438 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004439 } catch (ImsException e) {
4440 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004441 } finally {
4442 Binder.restoreCallingIdentity(identity);
4443 }
4444 }
4445
4446 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004447 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004448 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004449 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004450 final long identity = Binder.clearCallingIdentity();
4451 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004452 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004453 // This setting doesn't require an active ImsService connection, so do not verify. The
4454 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004455 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004456 } catch (ImsException e) {
4457 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004458 } finally {
4459 Binder.restoreCallingIdentity(identity);
4460 }
4461 }
4462
4463 @Override
4464 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4465 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4466 "setVoWiFiNonPersistent");
4467 final long identity = Binder.clearCallingIdentity();
4468 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004469 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004470 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004471 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004472 } catch (ImsException e) {
4473 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004474 } finally {
4475 Binder.restoreCallingIdentity(identity);
4476 }
4477 }
4478
shilu366312e2019-12-17 09:28:10 -08004479 /**
4480 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4481 * @param subId The subscription to use to check the configuration.
4482 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004483 @Override
4484 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004485 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004486 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004487 final long identity = Binder.clearCallingIdentity();
4488 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004489 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004490 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004491 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004492 } catch (ImsException e) {
4493 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004494 } finally {
4495 Binder.restoreCallingIdentity(identity);
4496 }
4497 }
4498
4499 @Override
4500 public void setVoWiFiModeSetting(int subId, int mode) {
4501 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4502 "setVoWiFiModeSetting");
4503 final long identity = Binder.clearCallingIdentity();
4504 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004505 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004506 // This setting doesn't require an active ImsService connection, so do not verify. The
4507 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004508 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004509 } catch (ImsException e) {
4510 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004511 } finally {
4512 Binder.restoreCallingIdentity(identity);
4513 }
4514 }
4515
4516 @Override
4517 public int getVoWiFiRoamingModeSetting(int subId) {
4518 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4519 final long identity = Binder.clearCallingIdentity();
4520 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004521 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004522 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004523 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004524 } catch (ImsException e) {
4525 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004526 } finally {
4527 Binder.restoreCallingIdentity(identity);
4528 }
4529 }
4530
4531 @Override
4532 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4533 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4534 "setVoWiFiRoamingModeSetting");
4535 final long identity = Binder.clearCallingIdentity();
4536 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004537 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004538 // This setting doesn't require an active ImsService connection, so do not verify. The
4539 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004540 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004541 } catch (ImsException e) {
4542 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004543 } finally {
4544 Binder.restoreCallingIdentity(identity);
4545 }
4546 }
4547
4548 @Override
4549 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4550 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4551 "setRttCapabilityEnabled");
4552 final long identity = Binder.clearCallingIdentity();
4553 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004554 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004555 // This setting doesn't require an active ImsService connection, so do not verify. The
4556 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004557 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004558 } catch (ImsException e) {
4559 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004560 } finally {
4561 Binder.restoreCallingIdentity(identity);
4562 }
4563 }
4564
shilu366312e2019-12-17 09:28:10 -08004565 /**
4566 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4567 * @param subId The subscription to use to check the configuration.
4568 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004569 @Override
4570 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004571 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004572 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004573 final long identity = Binder.clearCallingIdentity();
4574 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004575 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004576 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004577 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004578 } catch (ImsException e) {
4579 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004580 } finally {
4581 Binder.restoreCallingIdentity(identity);
4582 }
4583 }
4584
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004585 @Override
4586 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4587 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4588 final long identity = Binder.clearCallingIdentity();
4589 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004590 if (!isImsAvailableOnDevice()) {
4591 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4592 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004593 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004594 int slotId = getSlotIndexOrException(subId);
4595 verifyImsMmTelConfiguredOrThrow(slotId);
4596 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004597 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004598 } catch (ImsException e) {
4599 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004600 } finally {
4601 Binder.restoreCallingIdentity(identity);
4602 }
4603 }
4604
4605 @Override
4606 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4607 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4608 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004609 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4610 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4611 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004612 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004613 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004614 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004615 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004616 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4617 + "is inactive, ignoring unregister.");
4618 // If the subscription is no longer active, just return, since the callback will already
4619 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004620 } finally {
4621 Binder.restoreCallingIdentity(identity);
4622 }
4623 }
4624
allenwtsu99c623b2020-01-03 18:24:23 +08004625
4626 private void checkModifyPhoneStatePermission(int subId, String message) {
4627 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4628 message);
4629 }
4630
4631 private boolean isImsProvisioningRequired(int subId, int capability,
4632 boolean isMmtelCapability) {
4633 Phone phone = getPhone(subId);
4634 if (phone == null) {
4635 loge("phone instance null for subid " + subId);
4636 return false;
4637 }
4638 if (isMmtelCapability) {
4639 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4640 return false;
4641 }
4642 } else {
4643 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4644 return false;
4645 }
4646 }
4647 return true;
4648 }
4649
4650 @Override
4651 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4652 boolean isProvisioned) {
4653 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4654
4655 final long identity = Binder.clearCallingIdentity();
4656 try {
4657 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4658 if (!isImsProvisioningRequired(subId, capability, false)) {
4659 return;
4660 }
4661
4662 // this capability requires provisioning, route to the correct API.
4663 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4664 switch (capability) {
4665 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4666 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4667 ims.setEabProvisioned(isProvisioned);
4668 break;
4669 default: {
4670 throw new IllegalArgumentException("Tried to set provisioning for "
4671 + "rcs capability '" + capability + "', which does not require "
4672 + "provisioning.");
4673 }
4674 }
4675 } finally {
4676 Binder.restoreCallingIdentity(identity);
4677 }
4678
4679 }
4680
4681
4682 @Override
4683 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4684 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4685 final long identity = Binder.clearCallingIdentity();
4686 try {
4687 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4688 if (!isImsProvisioningRequired(subId, capability, false)) {
4689 return true;
4690 }
4691
4692 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4693 switch (capability) {
4694 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4695 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4696 return ims.isEabProvisionedOnDevice();
4697
4698 default: {
4699 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4700 + "capability '" + capability + "', which does not require "
4701 + "provisioning.");
4702 }
4703 }
4704
4705 } finally {
4706 Binder.restoreCallingIdentity(identity);
4707 }
4708 }
4709
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004710 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004711 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4712 boolean isProvisioned) {
4713 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004714 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4715 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4716 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004717 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4718 }
allenwtsu99c623b2020-01-03 18:24:23 +08004719 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004720 final long identity = Binder.clearCallingIdentity();
4721 try {
4722 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004723 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004724 return;
4725 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004726 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4727 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4728 loge("setImsProvisioningStatusForCapability: called for technology that does "
4729 + "not support provisioning - " + tech);
4730 return;
4731 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004732
4733 // this capability requires provisioning, route to the correct API.
4734 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4735 switch (capability) {
4736 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4737 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4738 ims.setVolteProvisioned(isProvisioned);
4739 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4740 ims.setWfcProvisioned(isProvisioned);
4741 }
4742 break;
4743 }
4744 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4745 // There is currently no difference in VT provisioning type.
4746 ims.setVtProvisioned(isProvisioned);
4747 break;
4748 }
4749 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4750 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4751 // change the capability of the feature instead if needed.
4752 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4753 == isProvisioned) {
4754 // No change in provisioning.
4755 return;
4756 }
4757 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4758 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004759 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004760 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004761 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4762 + ", Exception" + e.getMessage());
4763 }
4764 break;
4765 }
4766 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004767 throw new IllegalArgumentException("Tried to set provisioning for "
4768 + "MmTel capability '" + capability + "', which does not require "
4769 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004770 }
4771 }
4772
4773 } finally {
4774 Binder.restoreCallingIdentity(identity);
4775 }
4776 }
4777
4778 @Override
4779 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4780 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004781 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4782 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4783 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004784 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4785 }
4786 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4787 final long identity = Binder.clearCallingIdentity();
4788 try {
4789 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004790 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004791 return true;
4792 }
4793
Brad Ebinger0d79c572021-04-17 15:20:49 -07004794 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4795 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4796 loge("getImsProvisioningStatusForCapability: called for technology that does "
4797 + "not support provisioning - " + tech);
4798 return true;
4799 }
4800
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004801 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4802 switch (capability) {
4803 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4804 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4805 return ims.isVolteProvisionedOnDevice();
4806 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4807 return ims.isWfcProvisionedOnDevice();
4808 }
4809 // This should never happen, since we are checking tech above to make sure it
4810 // is either LTE or IWLAN.
4811 throw new IllegalArgumentException("Invalid radio technology for voice "
4812 + "capability.");
4813 }
4814 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4815 // There is currently no difference in VT provisioning type.
4816 return ims.isVtProvisionedOnDevice();
4817 }
4818 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4819 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4820 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4821 }
4822 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004823 throw new IllegalArgumentException(
4824 "Tried to get provisioning for MmTel capability '" + capability
4825 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004826 }
4827 }
4828
4829 } finally {
4830 Binder.restoreCallingIdentity(identity);
4831 }
4832 }
4833
4834 @Override
4835 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4836 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4837 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4838 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4839 }
4840 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4841 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4842 return (provisionedBits & capability) > 0;
4843 }
4844
4845 @Override
4846 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4847 boolean isProvisioned) {
4848 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4849 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4850 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4851 }
4852 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4853 "setProvisioningStatusForCapability");
4854 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4855 // If the current provisioning status for capability already matches isProvisioned,
4856 // do nothing.
4857 if (((provisionedBits & capability) > 0) == isProvisioned) {
4858 return;
4859 }
4860 if (isProvisioned) {
4861 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4862 } else {
4863 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4864 }
4865 }
4866
4867 /**
4868 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4869 * technology. The bitfield should mirror the bitfield defined by
4870 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4871 */
4872 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4873 String key = getMmTelProvisioningKey(subId, tech);
4874 // Default is no capabilities are provisioned.
4875 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4876 }
4877
4878 /**
4879 * Sets the MmTel capability provisioning bitfield (defined by
4880 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4881 * technology specified.
4882 *
4883 * Note: This is a synchronous command and should not be called on UI thread.
4884 */
4885 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4886 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4887 String key = getMmTelProvisioningKey(subId, tech);
4888 editor.putInt(key, newField);
4889 editor.commit();
4890 }
4891
4892 private static String getMmTelProvisioningKey(int subId, int tech) {
4893 // resulting key is provision_ims_mmtel_{subId}_{tech}
4894 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4895 }
4896
4897 /**
4898 * Query CarrierConfig to see if the specified capability requires provisioning for the
4899 * carrier associated with the subscription id.
4900 */
4901 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4902 int capability) {
4903 CarrierConfigManager configManager = new CarrierConfigManager(context);
4904 PersistableBundle c = configManager.getConfigForSubId(subId);
4905 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004906 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004907 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4908 false);
4909 boolean requireVoiceVtProvisioning = c.getBoolean(
4910 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4911
4912 // First check to make sure that the capability requires provisioning.
4913 switch (capability) {
4914 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4915 // intentional fallthrough
4916 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4917 if (requireVoiceVtProvisioning) {
4918 // Voice and Video requires provisioning
4919 return true;
4920 }
4921 break;
4922 }
4923 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4924 if (requireUtProvisioning) {
4925 // UT requires provisioning
4926 return true;
4927 }
4928 break;
4929 }
4930 }
4931 return false;
4932 }
4933
allenwtsu99c623b2020-01-03 18:24:23 +08004934 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4935 int capability) {
4936 CarrierConfigManager configManager = new CarrierConfigManager(context);
4937 PersistableBundle c = configManager.getConfigForSubId(subId);
4938
4939 boolean requireRcsProvisioning = c.getBoolean(
4940 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4941
4942 // First check to make sure that the capability requires provisioning.
4943 switch (capability) {
4944 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4945 // intentional fallthrough
4946 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4947 if (requireRcsProvisioning) {
4948 // OPTION or PRESENCE requires provisioning
4949 return true;
4950 }
4951 break;
4952 }
4953 }
4954 return false;
4955 }
4956
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004957 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004958 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004959 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4960 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4961 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004962 enforceReadPrivilegedPermission("getImsProvisioningInt");
4963 final long identity = Binder.clearCallingIdentity();
4964 try {
4965 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004966 int slotId = getSlotIndex(subId);
4967 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4968 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4969 + subId + "' for key:" + key);
4970 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4971 }
calvinpanb5a34062021-02-08 19:59:36 +08004972 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004973 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004974 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4975 + subId + "' for key:" + key);
4976 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004977 } finally {
4978 Binder.restoreCallingIdentity(identity);
4979 }
4980 }
4981
4982 @Override
4983 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004984 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4985 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4986 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004987 enforceReadPrivilegedPermission("getImsProvisioningString");
4988 final long identity = Binder.clearCallingIdentity();
4989 try {
4990 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004991 int slotId = getSlotIndex(subId);
4992 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4993 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4994 + subId + "' for key:" + key);
4995 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4996 }
calvinpanb5a34062021-02-08 19:59:36 +08004997 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004998 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004999 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5000 + subId + "' for key:" + key);
5001 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005002 } finally {
5003 Binder.restoreCallingIdentity(identity);
5004 }
5005 }
5006
5007 @Override
5008 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005009 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5010 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5011 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005012 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5013 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005014 final long identity = Binder.clearCallingIdentity();
5015 try {
5016 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005017 int slotId = getSlotIndex(subId);
5018 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5019 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5020 + subId + "' for key:" + key);
5021 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5022 }
calvinpanb5a34062021-02-08 19:59:36 +08005023 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5024 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005025 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005026 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005027 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005028 } finally {
5029 Binder.restoreCallingIdentity(identity);
5030 }
5031 }
5032
5033 @Override
5034 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005035 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5036 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5037 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005038 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5039 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005040 final long identity = Binder.clearCallingIdentity();
5041 try {
5042 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005043 int slotId = getSlotIndex(subId);
5044 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5045 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5046 + subId + "' for key:" + key);
5047 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5048 }
calvinpanb5a34062021-02-08 19:59:36 +08005049 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5050 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005051 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005052 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005053 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005054 } finally {
5055 Binder.restoreCallingIdentity(identity);
5056 }
5057 }
5058
Brad Ebinger919631e2021-06-02 17:46:35 -07005059 /**
5060 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5061 * for the given slot ID or no ImsResolver instance has been created.
5062 * @param slotId The slot ID that the IMS service is created for.
5063 * @throws ImsException If there is no ImsService configured for this slot.
5064 */
5065 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5066 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5067 ImsFeature.FEATURE_MMTEL)) {
5068 throw new ImsException("This subscription does not support MMTEL over IMS",
5069 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5070 }
5071 }
5072
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005073 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005074 int slotId = SubscriptionManager.getSlotIndex(subId);
5075 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005076 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5077 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005078 }
5079 return slotId;
5080 }
5081
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005082 private int getSlotIndex(int subId) {
5083 int slotId = SubscriptionManager.getSlotIndex(subId);
5084 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5085 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5086 }
5087 return slotId;
5088 }
5089
Wink Saville36469e72014-06-11 15:17:00 -07005090 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005091 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005092 */
5093 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005094 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5095 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005096 try {
5097 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5098 } catch (SecurityException se) {
5099 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5100 throw new SecurityException("Package " + callingPackage + " does not belong to "
5101 + Binder.getCallingUid());
5102 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005103 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005104 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005105 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005106 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005107 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005108 mApp, subId, callingPackage, callingFeatureId,
5109 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005110 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5111 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005112
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005113 final long identity = Binder.clearCallingIdentity();
5114 try {
5115 final Phone phone = getPhone(subId);
5116 if (phone != null) {
5117 return phone.getServiceState().getDataNetworkType();
5118 } else {
5119 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5120 }
5121 } finally {
5122 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005123 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005124 }
5125
5126 /**
5127 * Returns the data network type
5128 */
5129 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005130 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005131 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5132 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005133 }
5134
5135 /**
5136 * Returns the data network type for a subId
5137 */
5138 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005139 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5140 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005141 String functionName = "getDataNetworkTypeForSubscriber";
5142 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5143 mApp, functionName)) {
5144 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5145 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5146 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5147 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005148 }
5149
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005150 final long identity = Binder.clearCallingIdentity();
5151 try {
5152 final Phone phone = getPhone(subId);
5153 if (phone != null) {
5154 return phone.getServiceState().getDataNetworkType();
5155 } else {
5156 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5157 }
5158 } finally {
5159 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005160 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005161 }
5162
5163 /**
Wink Saville36469e72014-06-11 15:17:00 -07005164 * Returns the Voice network type for a subId
5165 */
5166 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005167 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5168 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005169 String functionName = "getVoiceNetworkTypeForSubscriber";
5170 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5171 mApp, functionName)) {
5172 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5173 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5174 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5175 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005176 }
5177
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005178 final long identity = Binder.clearCallingIdentity();
5179 try {
5180 final Phone phone = getPhone(subId);
5181 if (phone != null) {
5182 return phone.getServiceState().getVoiceNetworkType();
5183 } else {
5184 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5185 }
5186 } finally {
5187 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005188 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005189 }
5190
5191 /**
5192 * @return true if a ICC card is present
5193 */
5194 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005195 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005196 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5197 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005198 }
5199
5200 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005201 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005202 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005203 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005204 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005205 final long identity = Binder.clearCallingIdentity();
5206 try {
5207 final Phone phone = PhoneFactory.getPhone(slotIndex);
5208 if (phone != null) {
5209 return phone.getIccCard().hasIccCard();
5210 } else {
5211 return false;
5212 }
5213 } finally {
5214 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005215 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005216 }
5217
5218 /**
5219 * Return if the current radio is LTE on CDMA. This
5220 * is a tri-state return value as for a period of time
5221 * the mode may be unknown.
5222 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005223 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005224 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005225 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005226 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005227 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005228 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5229 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5230 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005231 }
5232
Sanket Padawe356d7632015-06-22 14:03:32 -07005233 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005234 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5235 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005236 try {
5237 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5238 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005239 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5240 }
5241
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005242 final long identity = Binder.clearCallingIdentity();
5243 try {
5244 final Phone phone = getPhone(subId);
5245 if (phone == null) {
5246 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5247 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005248 return TelephonyProperties.lte_on_cdma_device()
5249 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005250 }
5251 } finally {
5252 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005253 }
Wink Saville36469e72014-06-11 15:17:00 -07005254 }
5255
Wink Saville36469e72014-06-11 15:17:00 -07005256 /**
5257 * {@hide}
5258 * Returns Default subId, 0 in the case of single standby.
5259 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005260 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005261 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005262 }
5263
Shishir Agrawala9f32182016-04-12 12:00:16 -07005264 private int getSlotForDefaultSubscription() {
5265 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5266 }
5267
Wink Savilleb564aae2014-10-23 10:18:09 -07005268 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005269 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005270 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005271
Pengquan Menge92a50d2018-09-21 15:54:48 -07005272 private boolean isActiveSubscription(int subId) {
5273 return mSubscriptionController.isActiveSubId(subId);
5274 }
5275
Ihab Awadf2177b72013-11-25 13:33:23 -08005276 /**
5277 * @see android.telephony.TelephonyManager.WifiCallingChoices
5278 */
5279 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005280 final long identity = Binder.clearCallingIdentity();
5281 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005282 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005283 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5284 getWhenToMakeWifiCallsDefaultPreference());
5285 } finally {
5286 Binder.restoreCallingIdentity(identity);
5287 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005288 }
5289
5290 /**
5291 * @see android.telephony.TelephonyManager.WifiCallingChoices
5292 */
5293 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005294 final long identity = Binder.clearCallingIdentity();
5295 try {
5296 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005297 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005298 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5299 } finally {
5300 Binder.restoreCallingIdentity(identity);
5301 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005302 }
5303
Sailesh Nepald1e68152013-12-12 19:08:02 -08005304 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005305 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005306 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005307 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005308
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005309 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5310 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5311 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005312 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005313 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5314 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005315 }
5316 return PhoneFactory.getPhone(phoneId);
5317 }
5318
Shishir Agrawal566b7612013-10-28 14:41:00 -07005319 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005320 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005321 @NonNull IccLogicalChannelRequest request) {
5322 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5323 /*message=*/ "iccOpenLogicalChannel");
5324
5325 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5326 // Verify that the callingPackage in the request belongs to the calling UID
5327 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5328
5329 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005330 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005331
Rambo Wanga1782702021-11-10 20:15:19 -08005332 private Phone getPhoneFromValidIccLogicalChannelRequest(
5333 @NonNull IccLogicalChannelRequest request, String message) {
5334 Phone phone;
5335 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5336 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5337 mApp, request.subId, message);
5338 phone = getPhoneFromSubId(request.subId);
5339 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5340 enforceModifyPermission();
5341 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5342 } else {
5343 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005344 }
Rambo Wanga1782702021-11-10 20:15:19 -08005345 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005346 }
5347
5348 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005349 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005350 final long identity = Binder.clearCallingIdentity();
5351 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005352 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005353 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005354 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5355 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005356 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5357 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005358 loge("The calling package is not allowed to access ISD-R.");
5359 throw new SecurityException(
5360 "The calling package is not allowed to access ISD-R.");
5361 }
Derek Tan740e1672017-06-27 14:56:27 -07005362 }
Derek Tan740e1672017-06-27 14:56:27 -07005363
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005364 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005365 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5366 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005367 return response;
5368 } finally {
5369 Binder.restoreCallingIdentity(identity);
5370 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005371 }
5372
5373 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005374 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5375 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5376 /*message=*/"iccCloseLogicalChannel");
5377
5378 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5379
5380 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005381 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005382
Rambo Wanga1782702021-11-10 20:15:19 -08005383 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5384 IccLogicalChannelRequest request) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005385 final long identity = Binder.clearCallingIdentity();
5386 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005387 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005388 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005389 }
Rambo Wanga1782702021-11-10 20:15:19 -08005390 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005391 null /* workSource */);
Rambo Wanga1782702021-11-10 20:15:19 -08005392 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005393 return success;
5394 } finally {
5395 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005396 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005397 }
5398
5399 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005400 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005401 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005402 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5403 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005404 if (DBG) {
5405 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5406 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5407 + p3 + " data=" + data);
5408 }
5409 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5410 command, p1, p2, p3, data);
5411 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005412
Jordan Liu4c733742019-02-28 12:03:40 -08005413 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005414 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5415 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005416 enforceModifyPermission();
5417 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005418 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5419 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5420 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005421 }
5422 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005423 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5424 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005425 }
5426
5427 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5428 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005429 final long identity = Binder.clearCallingIdentity();
5430 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005431 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005432 return "";
5433 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005434
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005435 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005436 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5437 null /* workSource */);
5438 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005439
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005440 // Append the returned status code to the end of the response payload.
5441 String s = Integer.toHexString(
5442 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5443 if (response.payload != null) {
5444 s = IccUtils.bytesToHexString(response.payload) + s;
5445 }
5446 return s;
5447 } finally {
5448 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005449 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005450 }
Jake Hambye994d462014-02-03 13:10:13 -08005451
Evan Charltonc66da362014-05-16 14:06:40 -07005452 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005453 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5454 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005455 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5456 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005457 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005458 if (DBG) {
5459 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5460 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5461 }
5462 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5463 cla, command, p1, p2, p3, data);
5464 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005465
Jordan Liu4c733742019-02-28 12:03:40 -08005466 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005467 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5468 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005469 enforceModifyPermission();
5470 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5471 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005472 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5473 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5474 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005475 }
5476
5477 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005478 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5479 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005480 }
5481
5482 // open APDU basic channel assuming the caller has sufficient permissions
5483 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5484 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005485 final long identity = Binder.clearCallingIdentity();
5486 try {
5487 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5488 && TextUtils.equals(ISDR_AID, data)) {
5489 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005490 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5491 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005492 if (bestComponent == null
5493 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5494 loge("The calling package is not allowed to select ISD-R.");
5495 throw new SecurityException(
5496 "The calling package is not allowed to select ISD-R.");
5497 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005498 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005499
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005500 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005501 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5502 null /* workSource */);
5503 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005504
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005505 // Append the returned status code to the end of the response payload.
5506 String s = Integer.toHexString(
5507 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5508 if (response.payload != null) {
5509 s = IccUtils.bytesToHexString(response.payload) + s;
5510 }
5511 return s;
5512 } finally {
5513 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005514 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005515 }
5516
5517 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005518 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005519 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005520 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5521 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005522
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005523 final long identity = Binder.clearCallingIdentity();
5524 try {
5525 if (DBG) {
5526 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5527 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5528 }
5529
5530 IccIoResult response =
5531 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5532 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5533 subId);
5534
5535 if (DBG) {
5536 log("Exchange SIM_IO [R]" + response);
5537 }
5538
5539 byte[] result = null;
5540 int length = 2;
5541 if (response.payload != null) {
5542 length = 2 + response.payload.length;
5543 result = new byte[length];
5544 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5545 } else {
5546 result = new byte[length];
5547 }
5548
5549 result[length - 1] = (byte) response.sw2;
5550 result[length - 2] = (byte) response.sw1;
5551 return result;
5552 } finally {
5553 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005554 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005555 }
5556
Nathan Haroldb3014052017-01-25 15:57:32 -08005557 /**
5558 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5559 * on a particular subscription
5560 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005561 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5562 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005563 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005564 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005565 return null;
5566 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005567
5568 final long identity = Binder.clearCallingIdentity();
5569 try {
5570 if (appType != TelephonyManager.APPTYPE_USIM
5571 && appType != TelephonyManager.APPTYPE_SIM) {
5572 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5573 return null;
5574 }
5575 Object response = sendRequest(
5576 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5577 if (response instanceof String[]) {
5578 return (String[]) response;
5579 }
yincheng zhao2737e882019-09-06 17:06:54 -07005580 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005581 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005582 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005583 } finally {
5584 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005585 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005586 }
5587
yincheng zhao2737e882019-09-06 17:06:54 -07005588 /**
5589 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5590 * subscription.
5591 *
5592 * @param subId the id of the subscription.
5593 * @param appType the uicc app type, must be USIM or SIM.
5594 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5595 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005596 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005597 * @return number of fplmns that is successfully written to the SIM.
5598 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005599 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5600 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005601 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5602 mApp, subId, "setForbiddenPlmns");
5603
yincheng zhao2737e882019-09-06 17:06:54 -07005604 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5605 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5606 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5607 }
5608 if (fplmns == null) {
5609 throw new IllegalArgumentException("Fplmn List provided is null");
5610 }
5611 for (String fplmn : fplmns) {
5612 if (!CellIdentity.isValidPlmn(fplmn)) {
5613 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5614 }
5615 }
5616 final long identity = Binder.clearCallingIdentity();
5617 try {
5618 Object response = sendRequest(
5619 CMD_SET_FORBIDDEN_PLMNS,
5620 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5621 subId);
5622 return (int) response;
5623 } finally {
5624 Binder.restoreCallingIdentity(identity);
5625 }
5626 }
5627
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005628 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005629 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005630 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5631 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005632
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005633 final long identity = Binder.clearCallingIdentity();
5634 try {
5635 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5636 if (response.payload == null) {
5637 return "";
5638 }
Evan Charltonc66da362014-05-16 14:06:40 -07005639
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005640 // Append the returned status code to the end of the response payload.
5641 String s = Integer.toHexString(
5642 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5643 s = IccUtils.bytesToHexString(response.payload) + s;
5644 return s;
5645 } finally {
5646 Binder.restoreCallingIdentity(identity);
5647 }
Evan Charltonc66da362014-05-16 14:06:40 -07005648 }
5649
Jake Hambye994d462014-02-03 13:10:13 -08005650 /**
5651 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5652 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5653 *
5654 * @param itemID the ID of the item to read
5655 * @return the NV item as a String, or null on error.
5656 */
5657 @Override
5658 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005659 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005660 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5661 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005662
5663 final long identity = Binder.clearCallingIdentity();
5664 try {
5665 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005666 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005667 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5668 return value;
5669 } finally {
5670 Binder.restoreCallingIdentity(identity);
5671 }
Jake Hambye994d462014-02-03 13:10:13 -08005672 }
5673
5674 /**
5675 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5676 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5677 *
5678 * @param itemID the ID of the item to read
5679 * @param itemValue the value to write, as a String
5680 * @return true on success; false on any failure
5681 */
5682 @Override
5683 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005684 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005685 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5686 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005687
5688 final long identity = Binder.clearCallingIdentity();
5689 try {
5690 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5691 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005692 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005693 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5694 return success;
5695 } finally {
5696 Binder.restoreCallingIdentity(identity);
5697 }
Jake Hambye994d462014-02-03 13:10:13 -08005698 }
5699
5700 /**
5701 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5702 * Used for device configuration by some CDMA operators.
5703 *
5704 * @param preferredRoamingList byte array containing the new PRL
5705 * @return true on success; false on any failure
5706 */
5707 @Override
5708 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005709 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5710 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005711
5712 final long identity = Binder.clearCallingIdentity();
5713 try {
5714 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5715 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5716 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5717 return success;
5718 } finally {
5719 Binder.restoreCallingIdentity(identity);
5720 }
Jake Hambye994d462014-02-03 13:10:13 -08005721 }
5722
5723 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005724 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005725 * Used for device configuration by some CDMA operators.
5726 *
chen xu6dac5ab2018-10-26 17:39:23 -07005727 * @param slotIndex - device slot.
5728 *
Jake Hambye994d462014-02-03 13:10:13 -08005729 * @return true on success; false on any failure
5730 */
5731 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005732 public boolean resetModemConfig(int slotIndex) {
5733 Phone phone = PhoneFactory.getPhone(slotIndex);
5734 if (phone != null) {
5735 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5736 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005737
chen xu6dac5ab2018-10-26 17:39:23 -07005738 final long identity = Binder.clearCallingIdentity();
5739 try {
5740 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5741 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5742 return success;
5743 } finally {
5744 Binder.restoreCallingIdentity(identity);
5745 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005746 }
chen xu6dac5ab2018-10-26 17:39:23 -07005747 return false;
5748 }
5749
5750 /**
5751 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5752 *
5753 * @param slotIndex - device slot.
5754 *
5755 * @return true on success; false on any failure
5756 */
5757 @Override
5758 public boolean rebootModem(int slotIndex) {
5759 Phone phone = PhoneFactory.getPhone(slotIndex);
5760 if (phone != null) {
5761 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5762 mApp, phone.getSubId(), "rebootModem");
5763
5764 final long identity = Binder.clearCallingIdentity();
5765 try {
5766 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5767 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5768 return success;
5769 } finally {
5770 Binder.restoreCallingIdentity(identity);
5771 }
5772 }
5773 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005774 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005775
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005776 public String[] getPcscfAddress(String apnType, String callingPackage,
5777 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005778 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005779 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5780 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005781 return new String[0];
5782 }
5783
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005784 final long identity = Binder.clearCallingIdentity();
5785 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005786 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005787 } finally {
5788 Binder.restoreCallingIdentity(identity);
5789 }
Wink Saville36469e72014-06-11 15:17:00 -07005790 }
5791
Brad Ebinger51f743a2017-01-23 13:50:20 -08005792 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005793 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5794 * {@link #disableIms(int)}.
5795 * @param slotIndex device slot.
5796 */
5797 public void resetIms(int slotIndex) {
5798 enforceModifyPermission();
5799
5800 final long identity = Binder.clearCallingIdentity();
5801 try {
5802 if (mImsResolver == null) {
5803 // may happen if the does not support IMS.
5804 return;
5805 }
5806 mImsResolver.disableIms(slotIndex);
5807 mImsResolver.enableIms(slotIndex);
5808 } finally {
5809 Binder.restoreCallingIdentity(identity);
5810 }
5811 }
5812
5813 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005814 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5815 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005816 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005817 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005818 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.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005827 } finally {
5828 Binder.restoreCallingIdentity(identity);
5829 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005830 }
5831
5832 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005833 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5834 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005835 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005836 public void disableIms(int slotId) {
5837 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005838
5839 final long identity = Binder.clearCallingIdentity();
5840 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005841 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005842 // may happen if the device does not support IMS.
5843 return;
5844 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005845 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005846 } finally {
5847 Binder.restoreCallingIdentity(identity);
5848 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005849 }
5850
5851 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005852 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5853 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005854 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005855 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005856 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005857 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005858
5859 final long identity = Binder.clearCallingIdentity();
5860 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005861 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005862 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5863 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005864 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005865 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005866 } finally {
5867 Binder.restoreCallingIdentity(identity);
5868 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005869 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005870 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005871 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5872 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005873 @Override
5874 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005875 enforceModifyPermission();
5876
5877 final long identity = Binder.clearCallingIdentity();
5878 try {
5879 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005880 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005881 } finally {
5882 Binder.restoreCallingIdentity(identity);
5883 }
5884 }
5885
5886 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005887 * Returns the {@link IImsRegistration} 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 Ebinger5f64b052017-12-14 14:26:15 -08005889 */
5890 public IImsRegistration getImsRegistration(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.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005900 } finally {
5901 Binder.restoreCallingIdentity(identity);
5902 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005903 }
5904
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005905 /**
5906 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005907 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005908 */
5909 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5910 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005911
5912 final long identity = Binder.clearCallingIdentity();
5913 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005914 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005915 // may happen if the device does not support IMS.
5916 return null;
5917 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005918 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005919 } finally {
5920 Binder.restoreCallingIdentity(identity);
5921 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005922 }
5923
Brad Ebinger884c07b2018-02-15 16:17:40 -08005924 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005925 * Sets the ImsService Package Name that Telephony will bind to.
5926 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005927 * @param slotIndex the slot ID that the ImsService should bind for.
5928 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005929 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005930 * @param featureTypes An integer array of feature types associated with a packageName.
5931 * @param packageName The name of the package that the current configuration will be replaced
5932 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005933 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005934 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005935 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5936 int[] featureTypes, String packageName) {
5937 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5938 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005939 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5940 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005941 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005942
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005943 final long identity = Binder.clearCallingIdentity();
5944 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005945 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005946 // may happen if the device does not support IMS.
5947 return false;
5948 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005949 Map<Integer, String> featureConfig = new HashMap<>();
5950 for (int featureType : featureTypes) {
5951 featureConfig.put(featureType, packageName);
5952 }
5953 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5954 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005955 } finally {
5956 Binder.restoreCallingIdentity(identity);
5957 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005958 }
5959
5960 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005961 * Clears any carrier ImsService overrides for the slot index specified that were previously
5962 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5963 *
5964 * This should only be used for testing.
5965 *
5966 * @param slotIndex the slot ID that the ImsService should bind for.
5967 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5968 */
5969 @Override
5970 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5971 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5972 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5973 "clearCarrierImsServiceOverride");
5974 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5975 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5976 "clearCarrierImsServiceOverride");
5977
5978 final long identity = Binder.clearCallingIdentity();
5979 try {
5980 if (mImsResolver == null) {
5981 // may happen if the device does not support IMS.
5982 return false;
5983 }
5984 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5985 } finally {
5986 Binder.restoreCallingIdentity(identity);
5987 }
5988 }
5989
5990 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005991 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005992 *
5993 * @param slotId The slot that the ImsService is associated with.
5994 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5995 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005996 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005997 * @return the package name of the ImsService configuration.
5998 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005999 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6000 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07006001 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08006002 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006003 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08006004 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
6005 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006006
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006007 final long identity = Binder.clearCallingIdentity();
6008 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006009 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006010 // may happen if the device does not support IMS.
6011 return "";
6012 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006013 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006014 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6015 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006016 } finally {
6017 Binder.restoreCallingIdentity(identity);
6018 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006019 }
6020
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006021 /**
6022 * Get the MmTelFeature state associated with the requested subscription id.
6023 * @param subId The subscription that the MmTelFeature is associated with.
6024 * @param callback A callback with an integer containing the
6025 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6026 */
6027 @Override
6028 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6029 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
6030 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6031 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6032 "IMS not available on device.");
6033 }
6034 final long token = Binder.clearCallingIdentity();
6035 try {
6036 int slotId = getSlotIndex(subId);
6037 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6038 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6039 + subId + "'");
6040 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6041 }
Brad Ebinger919631e2021-06-02 17:46:35 -07006042 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006043 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6044 try {
6045 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6046 } catch (RemoteException e) {
6047 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6048 + "Ignore");
6049 }
6050 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006051 } catch (ImsException e) {
6052 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006053 } finally {
6054 Binder.restoreCallingIdentity(token);
6055 }
6056 }
6057
Daniel Brightbb5840b2021-01-12 15:48:18 -08006058 /**
6059 * Sets the ims registration state on all valid {@link Phone}s.
6060 */
6061 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006062 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006063
6064 final long identity = Binder.clearCallingIdentity();
6065 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006066 // NOTE: Before S, this method only set the default phone.
6067 for (final Phone phone : PhoneFactory.getPhones()) {
6068 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6069 phone.setImsRegistrationState(registered);
6070 }
6071 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006072 } finally {
6073 Binder.restoreCallingIdentity(identity);
6074 }
Wink Saville36469e72014-06-11 15:17:00 -07006075 }
6076
6077 /**
Stuart Scott54788802015-03-30 13:18:01 -07006078 * Set the network selection mode to automatic.
6079 *
6080 */
6081 @Override
6082 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006083 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6084 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006085
6086 final long identity = Binder.clearCallingIdentity();
6087 try {
shilufc958392020-01-20 11:36:01 -08006088 if (!isActiveSubscription(subId)) {
6089 return;
6090 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006091 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006092 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6093 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006094 } finally {
6095 Binder.restoreCallingIdentity(identity);
6096 }
Stuart Scott54788802015-03-30 13:18:01 -07006097 }
6098
Jack Yud10cdd42020-09-28 20:28:01 -07006099 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006100 * Ask the radio to connect to the input network and change selection mode to manual.
6101 *
6102 * @param subId the id of the subscription.
6103 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6104 * the operator to attach to.
6105 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6106 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6107 * normal network selection next time.
6108 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006109 */
6110 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006111 public boolean setNetworkSelectionModeManual(
6112 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006113 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6114 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006115
6116 if (!isActiveSubscription(subId)) {
6117 return false;
6118 }
6119
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006120 final long identity = Binder.clearCallingIdentity();
6121 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006122 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006123 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006124 if (DBG) {
6125 log("setNetworkSelectionModeManual: subId: " + subId
6126 + " operator: " + operatorInfo);
6127 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006128 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6129 } finally {
6130 Binder.restoreCallingIdentity(identity);
6131 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006132 }
shilu84f6e8b2019-12-19 13:58:01 -08006133 /**
6134 * Get the manual network selection
6135 *
6136 * @param subId the id of the subscription.
6137 *
6138 * @return the previously saved user selected PLMN
6139 */
6140 @Override
6141 public String getManualNetworkSelectionPlmn(int subId) {
6142 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006143 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006144 mApp, subId, "getManualNetworkSelectionPlmn");
6145
6146 final long identity = Binder.clearCallingIdentity();
6147 try {
6148 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006149 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006150 }
6151
6152 final Phone phone = getPhone(subId);
6153 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006154 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006155 }
6156 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6157 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6158 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6159 } finally {
6160 Binder.restoreCallingIdentity(identity);
6161 }
6162 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006163
6164 /**
6165 * Scans for available networks.
6166 */
6167 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006168 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6169 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006170 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6171 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006172 LocationAccessPolicy.LocationPermissionResult locationResult =
6173 LocationAccessPolicy.checkLocationPermission(mApp,
6174 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6175 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006176 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006177 .setCallingPid(Binder.getCallingPid())
6178 .setCallingUid(Binder.getCallingUid())
6179 .setMethod("getCellNetworkScanResults")
6180 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006181 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6182 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006183 .build());
6184 switch (locationResult) {
6185 case DENIED_HARD:
6186 throw new SecurityException("Not allowed to access scan results -- location");
6187 case DENIED_SOFT:
6188 return null;
6189 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006190
Pengquan Menga1bb6272018-09-06 09:59:22 -07006191 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006192 try {
6193 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006194 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006195 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006196 } finally {
6197 Binder.restoreCallingIdentity(identity);
6198 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006199 }
6200
6201 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006202 * Get the call forwarding info, given the call forwarding reason.
6203 */
6204 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006205 public void getCallForwarding(int subId, int callForwardingReason,
6206 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006207 enforceReadPrivilegedPermission("getCallForwarding");
6208 long identity = Binder.clearCallingIdentity();
6209 try {
6210 if (DBG) {
6211 log("getCallForwarding: subId " + subId
6212 + " callForwardingReason" + callForwardingReason);
6213 }
Hall Liu27d24262020-09-18 19:04:59 -07006214
6215 Phone phone = getPhone(subId);
6216 if (phone == null) {
6217 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006218 callback.onError(
6219 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006220 } catch (RemoteException e) {
6221 // ignore
6222 }
6223 return;
6224 }
6225
6226 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6227 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6228 @Override
6229 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6230 try {
6231 callback.onCallForwardingInfoAvailable(info);
6232 } catch (RemoteException e) {
6233 // ignore
6234 }
6235 }
6236
6237 @Override
6238 public void onError(int error) {
6239 try {
6240 callback.onError(error);
6241 } catch (RemoteException e) {
6242 // ignore
6243 }
6244 }
6245 });
6246 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006247 } finally {
6248 Binder.restoreCallingIdentity(identity);
6249 }
6250 }
6251
6252 /**
6253 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6254 * reason, the number to forward, and the timeout before the forwarding is attempted.
6255 */
6256 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006257 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6258 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006259 enforceModifyPermission();
6260 long identity = Binder.clearCallingIdentity();
6261 try {
6262 if (DBG) {
6263 log("setCallForwarding: subId " + subId
6264 + " callForwardingInfo" + callForwardingInfo);
6265 }
Hall Liu27d24262020-09-18 19:04:59 -07006266
6267 Phone phone = getPhone(subId);
6268 if (phone == null) {
6269 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006270 callback.accept(
6271 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006272 } catch (RemoteException e) {
6273 // ignore
6274 }
6275 return;
6276 }
6277
6278 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6279 FunctionalUtils.ignoreRemoteException(callback::accept));
6280
6281 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006282 } finally {
6283 Binder.restoreCallingIdentity(identity);
6284 }
6285 }
6286
6287 /**
Hall Liu27d24262020-09-18 19:04:59 -07006288 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006289 */
6290 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006291 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006292 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006293 long identity = Binder.clearCallingIdentity();
6294 try {
Hall Liu27d24262020-09-18 19:04:59 -07006295 Phone phone = getPhone(subId);
6296 if (phone == null) {
6297 try {
6298 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6299 } catch (RemoteException e) {
6300 // ignore
6301 }
6302 return;
6303 }
SongFerngWang0e767992021-03-31 22:08:45 +08006304 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6305 PersistableBundle c = configManager.getConfigForSubId(subId);
6306 boolean requireUssd = c.getBoolean(
6307 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006308
Shuo Qian4a594052020-01-23 11:59:30 -08006309 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006310 if (requireUssd) {
6311 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6312 getSubscriptionCarrierId(subId));
6313 String newUssdCommand = "";
6314 try {
6315 newUssdCommand = carrierXmlParser.getFeature(
6316 CarrierXmlParser.FEATURE_CALL_WAITING)
6317 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6318 } catch (NullPointerException e) {
6319 loge("Failed to generate USSD number" + e);
6320 }
6321 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6322 mMainThreadHandler, callback, carrierXmlParser,
6323 CarrierXmlParser.SsEntry.SSAction.QUERY);
6324 final String ussdCommand = newUssdCommand;
6325 Executors.newSingleThreadExecutor().execute(() -> {
6326 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6327 });
6328 } else {
6329 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6330 callback::accept);
6331 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6332 }
Shuo Qian4a594052020-01-23 11:59:30 -08006333 } finally {
6334 Binder.restoreCallingIdentity(identity);
6335 }
6336 }
6337
6338 /**
Hall Liu27d24262020-09-18 19:04:59 -07006339 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006340 */
6341 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006342 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006343 enforceModifyPermission();
6344 long identity = Binder.clearCallingIdentity();
6345 try {
Hall Liu27d24262020-09-18 19:04:59 -07006346 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6347
6348 Phone phone = getPhone(subId);
6349 if (phone == null) {
6350 try {
6351 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6352 } catch (RemoteException e) {
6353 // ignore
6354 }
6355 return;
6356 }
6357
SongFerngWang0e767992021-03-31 22:08:45 +08006358 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6359 PersistableBundle c = configManager.getConfigForSubId(subId);
6360 boolean requireUssd = c.getBoolean(
6361 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006362
SongFerngWang0e767992021-03-31 22:08:45 +08006363 if (DBG) log("getCallWaitingStatus: subId " + subId);
6364 if (requireUssd) {
6365 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6366 getSubscriptionCarrierId(subId));
6367 CarrierXmlParser.SsEntry.SSAction ssAction =
6368 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6369 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6370 String newUssdCommand = "";
6371 try {
6372 newUssdCommand = carrierXmlParser.getFeature(
6373 CarrierXmlParser.FEATURE_CALL_WAITING)
6374 .makeCommand(ssAction, null);
6375 } catch (NullPointerException e) {
6376 loge("Failed to generate USSD number" + e);
6377 }
6378 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6379 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6380 final String ussdCommand = newUssdCommand;
6381 Executors.newSingleThreadExecutor().execute(() -> {
6382 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6383 });
6384 } else {
6385 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6386 FunctionalUtils.ignoreRemoteException(callback::accept));
6387
6388 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6389 }
Shuo Qian4a594052020-01-23 11:59:30 -08006390 } finally {
6391 Binder.restoreCallingIdentity(identity);
6392 }
6393 }
6394
6395 /**
yinxub1bed742017-04-17 11:45:04 -07006396 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006397 *
yinxub1bed742017-04-17 11:45:04 -07006398 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006399 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6400 * location related information which will be sent if the caller already possess
6401 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006402 * @param request contains the radio access networks with bands/channels to scan
6403 * @param messenger callback messenger for scan results or errors
6404 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006405 * @return the id of the requested scan which can be used to stop the scan.
6406 */
6407 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006408 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6409 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006410 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006411 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6412 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006413 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006414 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6415 if (!renounceFineLocationAccess) {
6416 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6417 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6418 .setCallingPackage(callingPackage)
6419 .setCallingFeatureId(callingFeatureId)
6420 .setCallingPid(Binder.getCallingPid())
6421 .setCallingUid(Binder.getCallingUid())
6422 .setMethod("requestNetworkScan")
6423 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6424 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6425 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6426 .build());
6427 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006428 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006429 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6430 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006431 if (e != null) {
6432 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6433 throw e;
6434 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006435 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006436 return TelephonyScanManager.INVALID_SCAN_ID;
6437 }
6438 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006439 }
Hall Liu912dfd32019-04-25 14:02:26 -07006440 int callingUid = Binder.getCallingUid();
6441 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006442 final long identity = Binder.clearCallingIdentity();
6443 try {
6444 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006445 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006446 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006447 } finally {
6448 Binder.restoreCallingIdentity(identity);
6449 }
yinxu504e1392017-04-12 16:03:22 -07006450 }
6451
Hall Liub2ac8ef2019-02-28 15:56:23 -08006452 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006453 NetworkScanRequest request, int subId, String callingPackage) {
6454 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006455 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6456 boolean hasNetworkScanPermission =
6457 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6458 == PERMISSION_GRANTED;
6459
6460 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6461 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6462 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006463 }
6464
6465 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6466 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006467 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6468 return new SecurityException("Specific channels must not be"
6469 + " scanned without location access.");
6470 }
6471 }
6472 }
6473
Hall Liub2ac8ef2019-02-28 15:56:23 -08006474 return null;
6475 }
6476
yinxu504e1392017-04-12 16:03:22 -07006477 /**
6478 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006479 *
6480 * @param subId id of the subscription
6481 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006482 */
6483 @Override
6484 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006485 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6486 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006487
Hall Liu912dfd32019-04-25 14:02:26 -07006488 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006489 final long identity = Binder.clearCallingIdentity();
6490 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006491 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006492 } finally {
6493 Binder.restoreCallingIdentity(identity);
6494 }
yinxu504e1392017-04-12 16:03:22 -07006495 }
6496
6497 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006498 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006499 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006500 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006501 */
6502 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006503 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006504 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006505 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006506 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006507
6508 final long identity = Binder.clearCallingIdentity();
6509 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006510 if (DBG) log("getAllowedNetworkTypesBitmask");
6511 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6512 int networkTypesBitmask = (result != null ? result[0] : -1);
6513 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6514 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006515 } finally {
6516 Binder.restoreCallingIdentity(identity);
6517 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006518 }
6519
6520 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006521 * Get the allowed network types for certain reason.
6522 *
6523 * @param subId the id of the subscription.
6524 * @param reason the reason the allowed network type change is taking place
6525 * @return the allowed network types.
6526 */
6527 @Override
6528 public long getAllowedNetworkTypesForReason(int subId,
6529 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006530 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006531 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006532 final long identity = Binder.clearCallingIdentity();
6533 try {
6534 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6535 } finally {
6536 Binder.restoreCallingIdentity(identity);
6537 }
6538 }
6539
6540 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006541 * Enable/Disable E-UTRA-NR Dual Connectivity
6542 * @param subId subscription id of the sim card
6543 * @param nrDualConnectivityState expected NR dual connectivity state
6544 * This can be passed following states
6545 * <ol>
6546 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6547 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6548 * <li>Disable NR dual connectivity and force secondary cell to be released
6549 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6550 * </ol>
6551 * @return operation result.
6552 */
6553 @Override
6554 public int setNrDualConnectivityState(int subId,
6555 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6556 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6557 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006558 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006559 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6560 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6561 }
6562
Sooraj Sasindran37444802020-08-11 10:40:43 -07006563 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6564 final long identity = Binder.clearCallingIdentity();
6565 try {
6566 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6567 nrDualConnectivityState, subId,
6568 workSource);
6569 if (DBG) log("enableNRDualConnectivity result: " + result);
6570 return result;
6571 } finally {
6572 Binder.restoreCallingIdentity(identity);
6573 }
6574 }
6575
6576 /**
6577 * Is E-UTRA-NR Dual Connectivity enabled
6578 * @return true if dual connectivity is enabled else false
6579 */
6580 @Override
6581 public boolean isNrDualConnectivityEnabled(int subId) {
6582 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006583 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006584 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006585 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006586 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6587 return false;
6588 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006589 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6590 final long identity = Binder.clearCallingIdentity();
6591 try {
6592 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6593 null, subId, workSource);
6594 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6595 return isEnabled;
6596 } finally {
6597 Binder.restoreCallingIdentity(identity);
6598 }
6599 }
6600
6601 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006602 * Set the allowed network types of the device and
6603 * provide the reason triggering the allowed network change.
6604 *
6605 * @param subId the id of the subscription.
6606 * @param reason the reason the allowed network type change is taking place
6607 * @param allowedNetworkTypes the allowed network types.
6608 * @return true on success; false on any failure.
6609 */
6610 @Override
6611 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006612 @TelephonyManager.AllowedNetworkTypesReason int reason,
6613 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006614 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6615 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006616 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006617 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6618 return false;
6619 }
6620 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6621 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006622 return false;
6623 }
6624
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006625 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6626 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6627
6628
6629 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6630 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6631 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006632 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006633
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006634 final long identity = Binder.clearCallingIdentity();
6635 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006636 Boolean success = (Boolean) sendRequest(
6637 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6638 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6639
6640 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6641 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006642 } finally {
6643 Binder.restoreCallingIdentity(identity);
6644 }
6645 }
6646
6647 /**
Miaoa84611c2019-03-15 09:21:10 +08006648 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006649 *
Miaoa84611c2019-03-15 09:21:10 +08006650 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006651 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006652 * @hide
6653 */
6654 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006655 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006656 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006657 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006658 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006659 try {
Miaoa84611c2019-03-15 09:21:10 +08006660 if (phone != null) {
6661 return phone.hasMatchedTetherApnSetting();
6662 } else {
6663 return false;
6664 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006665 } finally {
6666 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006667 }
Junda Liu475951f2014-11-07 16:45:03 -08006668 }
6669
6670 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006671 * Get the user enabled state of Mobile Data.
6672 *
6673 * TODO: remove and use isUserDataEnabled.
6674 * This can't be removed now because some vendor codes
6675 * calls through ITelephony directly while they should
6676 * use TelephonyManager.
6677 *
6678 * @return true on enabled
6679 */
6680 @Override
6681 public boolean getDataEnabled(int subId) {
6682 return isUserDataEnabled(subId);
6683 }
6684
6685 /**
6686 * Get whether mobile data is enabled per user setting.
6687 *
6688 * There are other factors deciding whether mobile data is actually enabled, but they are
6689 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006690 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006691 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6692 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006693 *
6694 * @return {@code true} if data is enabled else {@code false}
6695 */
6696 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006697 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006698 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006699 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006700 try {
6701 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6702 functionName);
6703 } catch (Exception e) {
6704 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6705 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006706 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006707 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006708 mApp, subId, functionName);
6709
Robert Greenwalt646120a2014-05-23 11:54:03 -07006710 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006711
6712 final long identity = Binder.clearCallingIdentity();
6713 try {
6714 int phoneId = mSubscriptionController.getPhoneId(subId);
6715 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6716 Phone phone = PhoneFactory.getPhone(phoneId);
6717 if (phone != null) {
6718 boolean retVal = phone.isUserDataEnabled();
6719 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6720 return retVal;
6721 } else {
6722 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6723 return false;
6724 }
6725 } finally {
6726 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006727 }
6728 }
6729
6730 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006731 * Checks if the device is capable of mobile data by considering whether whether the
6732 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6733 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006734 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006735 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006736 */
6737 @Override
6738 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006739 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006740 try {
6741 try {
6742 mApp.enforceCallingOrSelfPermission(
6743 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006744 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006745 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006746 try {
6747 mApp.enforceCallingOrSelfPermission(
6748 android.Manifest.permission.READ_PHONE_STATE,
6749 functionName);
6750 } catch (Exception e2) {
6751 mApp.enforceCallingOrSelfPermission(
6752 permission.READ_BASIC_PHONE_STATE, functionName);
6753 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006754 }
6755 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006756 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006757 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006758
6759 final long identity = Binder.clearCallingIdentity();
6760 try {
6761 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006762 Phone phone = PhoneFactory.getPhone(phoneId);
6763 if (phone != null) {
Jack Yu4ad64e52021-12-03 14:23:53 -08006764 boolean retVal;
6765 if (phone.isUsingNewDataStack()) {
6766 retVal = phone.getDataNetworkController().getDataSettingsManager()
6767 .isDataEnabled();
6768 } else {
6769 retVal = phone.getDataEnabledSettings().isDataEnabled();
6770 }
6771 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006772 return retVal;
6773 } else {
6774 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6775 return false;
6776 }
6777 } finally {
6778 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006779 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006780 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006781
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006782 /**
6783 * Check if data is enabled for a specific reason
6784 * @param subId Subscription index
6785 * @param reason the reason the data enable change is taking place
6786 * @return {@code true} if the overall data is enabled; {@code false} if not.
6787 */
6788 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006789 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006790 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006791 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006792 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006793 try {
6794 mApp.enforceCallingOrSelfPermission(
6795 android.Manifest.permission.ACCESS_NETWORK_STATE,
6796 functionName);
6797 } catch (Exception e) {
6798 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6799 functionName);
6800 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006801 } catch (Exception e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006802 try {
6803 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006804 functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006805 } catch (Exception e2) {
6806 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006807 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006808 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006809 }
6810
6811
6812 final long identity = Binder.clearCallingIdentity();
6813 try {
6814 int phoneId = mSubscriptionController.getPhoneId(subId);
6815 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006816 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006817 + " reason=" + reason);
6818 }
6819 Phone phone = PhoneFactory.getPhone(phoneId);
6820 if (phone != null) {
6821 boolean retVal;
Jack Yu99e87332021-12-17 23:14:15 -08006822 if (phone.isUsingNewDataStack()) {
6823 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006824 } else {
Jack Yu99e87332021-12-17 23:14:15 -08006825 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6826 retVal = phone.isUserDataEnabled();
6827 } else {
6828 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
6829 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006830 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006831 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006832 return retVal;
6833 } else {
6834 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006835 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006836 + subId + " retVal=false");
6837 }
6838 return false;
6839 }
6840 } finally {
6841 Binder.restoreCallingIdentity(identity);
6842 }
6843 }
6844
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006845 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006846 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006847 if (uid == Process.PHONE_UID) {
6848 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6849 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006850 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6851 }
6852
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006853 //load access rules from carrier configs, and check those as well: b/139133814
6854 SubscriptionController subController = SubscriptionController.getInstance();
6855 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6856 || subController == null) return privilegeFromSim;
6857
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006858 PackageManager pkgMgr = phone.getContext().getPackageManager();
6859 String[] packages = pkgMgr.getPackagesForUid(uid);
6860
6861 final long identity = Binder.clearCallingIdentity();
6862 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006863 int subId = phone.getSubId();
6864 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6865 // A test override is in place for the privileges for this subId, so don't try to
6866 // read the subscription privileges.
6867 return privilegeFromSim;
6868 }
6869 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006870 SubscriptionManager subManager = (SubscriptionManager)
6871 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6872 for (String pkg : packages) {
6873 if (subManager.canManageSubscription(subInfo, pkg)) {
6874 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6875 }
6876 }
6877 return privilegeFromSim;
6878 } finally {
6879 Binder.restoreCallingIdentity(identity);
6880 }
6881 }
6882
6883 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6884 String pkgName) {
6885 //load access rules from carrier configs, and check those as well: b/139133814
6886 SubscriptionController subController = SubscriptionController.getInstance();
6887 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6888 || subController == null) return privilegeFromSim;
6889
6890 final long identity = Binder.clearCallingIdentity();
6891 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006892 int subId = phone.getSubId();
6893 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6894 // A test override is in place for the privileges for this subId, so don't try to
6895 // read the subscription privileges.
6896 return privilegeFromSim;
6897 }
6898 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006899 SubscriptionManager subManager = (SubscriptionManager)
6900 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6901 return subManager.canManageSubscription(subInfo, pkgName)
6902 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6903 } finally {
6904 Binder.restoreCallingIdentity(identity);
6905 }
6906 }
6907
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006908 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006909 public int getCarrierPrivilegeStatus(int subId) {
6910 final Phone phone = getPhone(subId);
6911 if (phone == null) {
6912 loge("getCarrierPrivilegeStatus: Invalid subId");
6913 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6914 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006915 UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId());
6916 if (port == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006917 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006918 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6919 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006920
6921 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006922 port.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006923 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006924 }
Junda Liu29340342014-07-10 15:23:27 -07006925
6926 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006927 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006928 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006929 final Phone phone = getPhone(subId);
6930 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006931 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006932 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6933 }
6934 UiccProfile profile =
6935 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6936 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006937 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006938 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6939 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006940 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006941 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006942 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006943 }
6944
6945 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006946 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006947 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006948 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006949 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006950 }
6951
6952 int phoneId = SubscriptionManager.getPhoneId(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006953 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6954 if (port == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006955 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006956 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6957 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006958 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006959 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006960 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006961 }
6962
6963 @Override
6964 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006965 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006966 if (TextUtils.isEmpty(pkgName))
6967 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006968 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6969 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006970 UiccPort port = UiccController.getInstance().getUiccPort(i);
6971 if (port == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006972 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006973 continue;
6974 }
6975
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006976 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006977 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006978 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006979 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6980 break;
6981 }
6982 }
6983
6984 return result;
Junda Liu29340342014-07-10 15:23:27 -07006985 }
Derek Tan89e89d42014-07-08 17:00:10 -07006986
6987 @Override
Junda Liue64de782015-04-16 17:19:16 -07006988 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006989 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006990 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6991 loge("phoneId " + phoneId + " is not valid.");
6992 return null;
6993 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006994 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6995 if (port == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006996 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006997 return null ;
6998 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006999 return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007000 }
7001
Amith Yamasani6e118872016-02-19 12:53:51 -08007002 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007003 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007004 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007005 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08007006 List<String> privilegedPackages = new ArrayList<>();
7007 List<PackageInfo> packages = null;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007008 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
chen xuf7e9fe82019-05-09 19:31:02 -07007009 // has UICC in that slot.
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007010 if (port != null) {
7011 if (port.hasCarrierPrivilegeRules()) {
Amith Yamasani6e118872016-02-19 12:53:51 -08007012 if (packages == null) {
7013 // Only check packages in user 0 for now
7014 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07007015 PackageManager.MATCH_DISABLED_COMPONENTS
7016 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09007017 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08007018 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08007019 }
7020 for (int p = packages.size() - 1; p >= 0; p--) {
7021 PackageInfo pkgInfo = packages.get(p);
7022 if (pkgInfo != null && pkgInfo.packageName != null
Sooraj Sasindran97bce6f2021-09-28 21:37:29 +00007023 && getCarrierPrivilegeStatusFromCarrierConfigRules(
7024 port.getCarrierPrivilegeStatus(pkgInfo),
7025 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07007026 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08007027 privilegedPackages.add(pkgInfo.packageName);
7028 }
7029 }
7030 }
7031 }
7032 return privilegedPackages;
7033 }
7034
chen xuf7e9fe82019-05-09 19:31:02 -07007035 @Override
7036 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007037 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
7038
7039 final long identity = Binder.clearCallingIdentity();
7040
chen xuf7e9fe82019-05-09 19:31:02 -07007041 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007042 try {
7043 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7044 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7045 }
7046 } finally {
7047 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007048 }
7049 return privilegedPackages;
7050 }
7051
Wink Savilleb564aae2014-10-23 10:18:09 -07007052 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007053 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007054 UiccPort port = phone == null ? null : phone.getUiccPort();
7055 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007056 return null;
7057 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007058 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007059 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007060 return null;
7061 }
7062 return iccId;
7063 }
7064
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007065 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007066 public void setCallComposerStatus(int subId, int status) {
7067 enforceModifyPermission();
7068
7069 final long identity = Binder.clearCallingIdentity();
7070 try {
7071 Phone phone = getPhone(subId);
7072 if (phone != null) {
7073 Phone defaultPhone = phone.getImsPhone();
7074 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7075 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7076 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007077 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7078 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007079 }
7080 }
Shuo Qian284ae752020-12-22 19:10:14 -08007081 } catch (ImsException e) {
7082 throw new ServiceSpecificException(e.getCode());
7083 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007084 Binder.restoreCallingIdentity(identity);
7085 }
7086 }
7087
7088 @Override
7089 public int getCallComposerStatus(int subId) {
7090 enforceReadPrivilegedPermission("getCallComposerStatus");
7091
7092 final long identity = Binder.clearCallingIdentity();
7093 try {
7094 Phone phone = getPhone(subId);
7095 if (phone != null) {
7096 Phone defaultPhone = phone.getImsPhone();
7097 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7098 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7099 return imsPhone.getCallComposerStatus();
7100 }
7101 }
7102 } finally {
7103 Binder.restoreCallingIdentity(identity);
7104 }
7105 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7106 }
7107
7108 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007109 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7110 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007111 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007112 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007113
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007114 final long identity = Binder.clearCallingIdentity();
7115 try {
7116 final String iccId = getIccId(subId);
7117 final Phone phone = getPhone(subId);
7118 if (phone == null) {
7119 return false;
7120 }
7121 final String subscriberId = phone.getSubscriberId();
7122
7123 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007124 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007125 + subscriberId + " to " + number);
7126 }
7127
7128 if (TextUtils.isEmpty(iccId)) {
7129 return false;
7130 }
7131
7132 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7133
7134 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7135 if (alphaTag == null) {
7136 editor.remove(alphaTagPrefKey);
7137 } else {
7138 editor.putString(alphaTagPrefKey, alphaTag);
7139 }
7140
7141 // Record both the line number and IMSI for this ICCID, since we need to
7142 // track all merged IMSIs based on line number
7143 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7144 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7145 if (number == null) {
7146 editor.remove(numberPrefKey);
7147 editor.remove(subscriberPrefKey);
7148 } else {
7149 editor.putString(numberPrefKey, number);
7150 editor.putString(subscriberPrefKey, subscriberId);
7151 }
7152
7153 editor.commit();
7154 return true;
7155 } finally {
7156 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007157 }
Derek Tan7226c842014-07-02 17:42:23 -07007158 }
7159
7160 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007161 public String getLine1NumberForDisplay(int subId, String callingPackage,
7162 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007163 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007164 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007165 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007166 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007167 return null;
7168 }
Derek Tan97ebb422014-09-05 16:55:38 -07007169
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007170 final long identity = Binder.clearCallingIdentity();
7171 try {
7172 String iccId = getIccId(subId);
7173 if (iccId != null) {
7174 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7175 if (DBG_MERGE) {
7176 log("getLine1NumberForDisplay returning "
7177 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7178 }
7179 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007180 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007181 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7182 return null;
7183 } finally {
7184 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007185 }
Derek Tan7226c842014-07-02 17:42:23 -07007186 }
7187
7188 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007189 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7190 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007191 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007192 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007193 return null;
7194 }
Derek Tan97ebb422014-09-05 16:55:38 -07007195
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007196 final long identity = Binder.clearCallingIdentity();
7197 try {
7198 String iccId = getIccId(subId);
7199 if (iccId != null) {
7200 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7201 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7202 }
7203 return null;
7204 } finally {
7205 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007206 }
Derek Tan7226c842014-07-02 17:42:23 -07007207 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007208
7209 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007210 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7211 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007212 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7213 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007214 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007215 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007216 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007217 return null;
7218 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007219
Jordan Liub49b04b2019-05-06 14:45:15 -07007220 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7221 // the process, where TelephonyManager was instantiated.
7222 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007223 final long identity = Binder.clearCallingIdentity();
7224 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007225 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007226 final TelephonyManager tele = TelephonyManager.from(context);
7227 final SubscriptionManager sub = SubscriptionManager.from(context);
7228
7229 // Figure out what subscribers are currently active
7230 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007231
Jordan Liub49b04b2019-05-06 14:45:15 -07007232 // Only consider subs which match the current subId
7233 // This logic can be simplified. See b/131189269 for progress.
7234 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007235 activeSubscriberIds.add(tele.getSubscriberId(subId));
7236 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007237
7238 // First pass, find a number override for an active subscriber
7239 String mergeNumber = null;
7240 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7241 for (String key : prefs.keySet()) {
7242 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7243 final String subscriberId = (String) prefs.get(key);
7244 if (activeSubscriberIds.contains(subscriberId)) {
7245 final String iccId = key.substring(
7246 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7247 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7248 mergeNumber = (String) prefs.get(numberKey);
7249 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007250 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007251 + " for active subscriber " + subscriberId);
7252 }
7253 if (!TextUtils.isEmpty(mergeNumber)) {
7254 break;
7255 }
7256 }
7257 }
7258 }
7259
7260 // Shortcut when no active merged subscribers
7261 if (TextUtils.isEmpty(mergeNumber)) {
7262 return null;
7263 }
7264
7265 // Second pass, find all subscribers under that line override
7266 final ArraySet<String> result = new ArraySet<>();
7267 for (String key : prefs.keySet()) {
7268 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7269 final String number = (String) prefs.get(key);
7270 if (mergeNumber.equals(number)) {
7271 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7272 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7273 final String subscriberId = (String) prefs.get(subscriberKey);
7274 if (!TextUtils.isEmpty(subscriberId)) {
7275 result.add(subscriberId);
7276 }
7277 }
7278 }
7279 }
7280
7281 final String[] resultArray = result.toArray(new String[result.size()]);
7282 Arrays.sort(resultArray);
7283 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007284 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007285 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7286 }
7287 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007288 } finally {
7289 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007290 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007291 }
7292
7293 @Override
zoey chen38003472019-12-13 17:16:31 +08007294 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7295 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007296
7297 final long identity = Binder.clearCallingIdentity();
7298 try {
7299 final TelephonyManager telephonyManager = mApp.getSystemService(
7300 TelephonyManager.class);
7301 String subscriberId = telephonyManager.getSubscriberId(subId);
7302 if (subscriberId == null) {
7303 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007304 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007305 + subId);
7306 }
7307 return null;
7308 }
7309
7310 final SubscriptionInfo info = SubscriptionController.getInstance()
7311 .getSubscriptionInfo(subId);
7312 final ParcelUuid groupUuid = info.getGroupUuid();
7313 // If it doesn't belong to any group, return just subscriberId of itself.
7314 if (groupUuid == null) {
7315 return new String[]{subscriberId};
7316 }
7317
7318 // Get all subscriberIds from the group.
7319 final List<String> mergedSubscriberIds = new ArrayList<>();
7320 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007321 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007322 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007323 for (SubscriptionInfo subInfo : groupInfos) {
7324 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7325 if (subscriberId != null) {
7326 mergedSubscriberIds.add(subscriberId);
7327 }
7328 }
7329
7330 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7331 } finally {
7332 Binder.restoreCallingIdentity(identity);
7333
7334 }
7335 }
7336
7337 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007338 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007339 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007340 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007341
7342 final long identity = Binder.clearCallingIdentity();
7343 try {
7344 final Phone phone = getPhone(subId);
7345 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7346 } finally {
7347 Binder.restoreCallingIdentity(identity);
7348 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007349 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007350
7351 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007352 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007353 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7354 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007355 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7356 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007357
7358 final long identity = Binder.clearCallingIdentity();
7359 try {
7360 final Phone phone = getPhone(subId);
7361 if (phone == null) {
7362 return false;
7363 }
7364 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7365 cdmaNonRoamingList);
7366 } finally {
7367 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007368 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007369 }
7370
7371 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007372 @Deprecated
7373 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7374 enforceModifyPermission();
7375
7376 int returnValue = 0;
7377 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007378 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007379 if(result.exception == null) {
7380 if (result.result != null) {
7381 byte[] responseData = (byte[])(result.result);
7382 if(responseData.length > oemResp.length) {
7383 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7384 responseData.length + "bytes. Buffer Size is " +
7385 oemResp.length + "bytes.");
7386 }
7387 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7388 returnValue = responseData.length;
7389 }
7390 } else {
7391 CommandException ex = (CommandException) result.exception;
7392 returnValue = ex.getCommandError().ordinal();
7393 if(returnValue > 0) returnValue *= -1;
7394 }
7395 } catch (RuntimeException e) {
7396 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7397 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7398 if(returnValue > 0) returnValue *= -1;
7399 }
7400
7401 return returnValue;
7402 }
7403
7404 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007405 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007406 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007407 try {
7408 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007409 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007410 mApp, phone.getSubId(), "getRadioAccessFamily");
7411 } catch (SecurityException e) {
7412 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7413 throw e;
7414 }
chen xub97461a2018-10-26 14:17:57 -07007415 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007416 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007417 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007418 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007419 final long identity = Binder.clearCallingIdentity();
7420 try {
chen xub97461a2018-10-26 14:17:57 -07007421 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007422 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007423 mApp, phone.getSubId(), "getRadioAccessFamily");
7424 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007425 } finally {
7426 Binder.restoreCallingIdentity(identity);
7427 }
chen xub97461a2018-10-26 14:17:57 -07007428 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007429 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007430
7431 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007432 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007433 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007434 try {
7435 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7436 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007437 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007438 }
7439 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007440 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007441 }
7442 RoleManager rm = mApp.getSystemService(RoleManager.class);
7443 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7444 if (!dialerRoleHolders.contains(callingPackage)) {
7445 throw new SecurityException("App must be the dialer role holder to"
7446 + " upload a call composer pic");
7447 }
7448
7449 Executors.newSingleThreadExecutor().execute(() -> {
7450 ByteArrayOutputStream output = new ByteArrayOutputStream(
7451 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7452 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7453 boolean readUntilEnd = false;
7454 int totalBytesRead = 0;
7455 byte[] buffer = new byte[16 * 1024];
7456 while (true) {
7457 int numRead;
7458 try {
7459 numRead = input.read(buffer);
7460 } catch (IOException e) {
7461 try {
7462 fd.checkError();
7463 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7464 null);
7465 } catch (IOException e1) {
7466 // This means that the other side closed explicitly with an error. If this
7467 // happens, log and ignore.
7468 loge("Remote end of call composer picture pipe closed: " + e1);
7469 }
7470 break;
7471 }
7472 if (numRead == -1) {
7473 readUntilEnd = true;
7474 break;
7475 }
7476 totalBytesRead += numRead;
7477 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7478 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7479 try {
7480 input.close();
7481 } catch (IOException e) {
7482 // ignore
7483 }
7484 break;
7485 }
7486 output.write(buffer, 0, numRead);
7487 }
7488 // Generally, the remote end will close the file descriptors. The only case where we
7489 // close is above, where the picture size is too big.
7490
7491 try {
7492 fd.checkError();
7493 } catch (IOException e) {
7494 loge("Remote end for call composer closed with an error: " + e);
7495 return;
7496 }
7497
Hall Liuaa4211e2021-01-20 15:43:39 -08007498 if (!readUntilEnd) {
7499 loge("Did not finish reading entire image; aborting");
7500 return;
7501 }
Hall Liu82694d52020-12-11 18:22:04 -08007502
Hall Liuaa4211e2021-01-20 15:43:39 -08007503 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7504 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7505 new CallComposerPictureTransfer.Factory() {},
7506 imageData,
7507 (result) -> {
7508 if (result.first != null) {
7509 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7510 Bundle outputResult = new Bundle();
7511 outputResult.putParcelable(
7512 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7513 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7514 outputResult);
7515 } else {
7516 callback.send(result.second, null);
7517 }
7518 }
7519 );
Hall Liu82694d52020-12-11 18:22:04 -08007520 });
7521 }
7522
7523 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007524 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007525 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007526 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007527
7528 final long identity = Binder.clearCallingIdentity();
7529 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007530 ImsManager.getInstance(defaultPhone.getContext(),
7531 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007532 } finally {
7533 Binder.restoreCallingIdentity(identity);
7534 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007535 }
7536
7537 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007538 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007539 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007540 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7541 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007542 return false;
7543 }
Svet Ganovb320e182015-04-16 12:30:10 -07007544
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007545 final long identity = Binder.clearCallingIdentity();
7546 try {
7547 // Check the user preference and the system-level IMS setting. Even if the user has
7548 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7549 // In the long run, we may instead need to check if there exists a connection service
7550 // which can support video calling.
7551 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007552 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007553 return imsManager.isVtEnabledByPlatform()
7554 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7555 && imsManager.isVtEnabledByUser();
7556 } finally {
7557 Binder.restoreCallingIdentity(identity);
7558 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007559 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007560
Andrew Leea1239f22015-03-02 17:44:07 -08007561 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007562 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7563 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007564 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007565 mApp, subId, callingPackage, callingFeatureId,
7566 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007567 return false;
7568 }
7569
7570 final long identity = Binder.clearCallingIdentity();
7571 try {
7572 CarrierConfigManager configManager =
7573 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007574 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007575 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7576 } finally {
7577 Binder.restoreCallingIdentity(identity);
7578 }
Andrew Leea1239f22015-03-02 17:44:07 -08007579 }
7580
7581 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007582 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007583 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007584 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007585 return false;
7586 }
7587
7588 final long identity = Binder.clearCallingIdentity();
7589 try {
7590 CarrierConfigManager configManager =
7591 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007592 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007593 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7594 } finally {
7595 Binder.restoreCallingIdentity(identity);
7596 }
Andrew Leea1239f22015-03-02 17:44:07 -08007597 }
7598
Andrew Lee9431b832015-03-09 18:46:45 -07007599 @Override
7600 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007601 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007602 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007603 }
7604
7605 @Override
7606 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007607 final long identity = Binder.clearCallingIdentity();
7608 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007609 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007610 } finally {
7611 Binder.restoreCallingIdentity(identity);
7612 }
Andrew Lee9431b832015-03-09 18:46:45 -07007613 }
7614
Hall Liuf6668912018-10-31 17:05:23 -07007615 /**
7616 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7617 * support for the feature and device firmware support.
7618 *
7619 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7620 */
7621 @Override
7622 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007623 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007624 final Phone phone = getPhone(subscriptionId);
7625 if (phone == null) {
7626 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7627 return false;
7628 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007629 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007630 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007631 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7632 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007633 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007634 return isCarrierSupported && isDeviceSupported;
7635 } finally {
7636 Binder.restoreCallingIdentity(identity);
7637 }
Hall Liu98187582018-01-22 19:15:32 -08007638 }
7639
Hall Liuf6668912018-10-31 17:05:23 -07007640 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007641 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7642 * RTT setting, will return true if the device and carrier both support RTT.
7643 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007644 */
7645 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007646 final long identity = Binder.clearCallingIdentity();
7647 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007648 boolean isRttSupported = isRttSupported(subscriptionId);
7649 boolean isUserRttSettingOn = Settings.Secure.getInt(
7650 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7651 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7652 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7653 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007654 } finally {
7655 Binder.restoreCallingIdentity(identity);
7656 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007657 }
7658
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007659 @Deprecated
7660 @Override
7661 public String getDeviceId(String callingPackage) {
7662 return getDeviceIdWithFeature(callingPackage, null);
7663 }
7664
Sanket Padawe7310cc72015-01-14 09:53:20 -08007665 /**
7666 * Returns the unique device ID of phone, for example, the IMEI for
7667 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7668 *
7669 * <p>Requires Permission:
7670 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7671 */
7672 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007673 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007674 try {
7675 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7676 } catch (SecurityException se) {
7677 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7678 throw new SecurityException("Package " + callingPackage + " does not belong to "
7679 + Binder.getCallingUid());
7680 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007681 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007682 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007683 return null;
7684 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007685 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007686 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007687 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007688 return null;
7689 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007690
7691 final long identity = Binder.clearCallingIdentity();
7692 try {
7693 return phone.getDeviceId();
7694 } finally {
7695 Binder.restoreCallingIdentity(identity);
7696 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007697 }
7698
Ping Sunc67b7c22016-03-02 19:16:45 +08007699 /**
7700 * {@hide}
7701 * Returns the IMS Registration Status on a particular subid
7702 *
7703 * @param subId
7704 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007705 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007706 Phone phone = getPhone(subId);
7707 if (phone != null) {
7708 return phone.isImsRegistered();
7709 } else {
7710 return false;
7711 }
7712 }
7713
Santos Cordon7a1885b2015-02-03 11:15:19 -08007714 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007715 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007716 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007717 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007718 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007719 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7720 }
7721 final long identity = Binder.clearCallingIdentity();
7722 try {
7723 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7724 } finally {
7725 Binder.restoreCallingIdentity(identity);
7726 }
7727 }
7728
7729 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007730 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007731 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007732 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007733 mApp,
7734 subscriptionId,
7735 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007736 final long identity = Binder.clearCallingIdentity();
7737 try {
7738 Phone phone = getPhone(subscriptionId);
7739 if (phone == null) {
7740 return null;
7741 }
7742 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7743 } finally {
7744 Binder.restoreCallingIdentity(identity);
7745 }
7746 }
7747
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007748 /**
7749 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007750 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007751 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007752 final long identity = Binder.clearCallingIdentity();
7753 try {
7754 Phone phone = getPhone(subId);
7755 if (phone != null) {
7756 return phone.isWifiCallingEnabled();
7757 } else {
7758 return false;
7759 }
7760 } finally {
7761 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007762 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007763 }
7764
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007765 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007766 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007767 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007768 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007769 final long identity = Binder.clearCallingIdentity();
7770 try {
7771 Phone phone = getPhone(subId);
7772 if (phone != null) {
7773 return phone.isVideoEnabled();
7774 } else {
7775 return false;
7776 }
7777 } finally {
7778 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007779 }
7780 }
7781
7782 /**
7783 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7784 * defined in {@link ImsRegistrationImplBase}.
7785 */
7786 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007787 final long identity = Binder.clearCallingIdentity();
7788 try {
7789 Phone phone = getPhone(subId);
7790 if (phone != null) {
7791 return phone.getImsRegistrationTech();
7792 } else {
7793 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7794 }
7795 } finally {
7796 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007797 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007798 }
7799
Stuart Scott8eef64f2015-04-08 15:13:54 -07007800 @Override
7801 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007802 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007803 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7804 return;
7805 }
Kai Shif70f46f2021-03-03 13:59:46 -08007806 Phone defaultPhone = getDefaultPhone();
7807 if (defaultPhone != null) {
7808 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7809 mApp, getDefaultPhone().getSubId(), "factoryReset");
7810 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007811 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007812
Svet Ganovcc087f82015-05-12 20:35:54 -07007813 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007814 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7815 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007816 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007817 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007818 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007819 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007820 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007821 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007822 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007823 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007824 // There has been issues when Sms raw table somehow stores orphan
7825 // fragments. They lead to garbled message when new fragments come
7826 // in and combined with those stale ones. In case this happens again,
7827 // user can reset all network settings which will clean up this table.
7828 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007829 // Clean up IMS settings as well here.
7830 int slotId = getSlotIndex(subId);
7831 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7832 ImsManager.getInstance(mApp, slotId).factoryReset();
7833 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007834
Kai Shif70f46f2021-03-03 13:59:46 -08007835 if (defaultPhone == null) {
7836 return;
7837 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007838 // Erase modem config if erase modem on network setting is enabled.
7839 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7840 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7841 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007842 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007843 }
Kai Shif70f46f2021-03-03 13:59:46 -08007844
7845 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007846 } finally {
7847 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007848 }
7849 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007850
SongFerngWangfd89b102021-05-27 22:44:54 +08007851 @VisibleForTesting
7852 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7853 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7854 return;
7855 }
7856 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7857 RILConstants.PREFERRED_NETWORK_MODE);
7858 SubscriptionManager.setSubscriptionProperty(subId,
7859 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7860 "user=" + defaultNetworkType);
7861 phone.loadAllowedNetworksFromSubscriptionDatabase();
7862 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7863 defaultNetworkType, null);
7864 }
7865
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007866 private void cleanUpSmsRawTable(Context context) {
7867 ContentResolver resolver = context.getContentResolver();
7868 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7869 resolver.delete(uri, null, null);
7870 }
7871
Narayan Kamath1c496c22015-04-16 14:40:19 +01007872 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007873 public String getSimLocaleForSubscriber(int subId) {
7874 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7875 final Phone phone = getPhone(subId);
7876 if (phone == null) {
7877 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007878 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007879 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007880 final long identity = Binder.clearCallingIdentity();
7881 try {
chen xu5d3637b2019-01-21 23:31:38 -08007882 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007883 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007884 if (info == null) {
7885 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7886 return null;
7887 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007888 // Try and fetch the locale from the carrier properties or from the SIM language
7889 // preferences (EF-PL and EF-LI)...
7890 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007891 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007892 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7893 if (localeFromDefaultSim != null) {
7894 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7895 if (DBG) log("Using locale from subId: " + subId + " locale: "
7896 + localeFromDefaultSim);
7897 return localeFromDefaultSim.toLanguageTag();
7898 } else {
7899 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007900 }
7901 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007902
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007903 // The SIM language preferences only store a language (e.g. fr = French), not an
7904 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7905 // the SIM and carrier preferences does not include a country we add the country
7906 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007907 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007908 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007909 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007910 return mccLocale.toLanguageTag();
7911 }
7912
7913 if (DBG) log("No locale found - returning null");
7914 return null;
7915 } finally {
7916 Binder.restoreCallingIdentity(identity);
7917 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007918 }
7919
7920 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007921 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007922 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007923 }
7924
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007925 /**
7926 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7927 */
7928 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007929 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007930 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007931 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007932
Chenjie Yu1ba97252018-01-11 18:16:20 -08007933 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007934 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007935
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007936 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007937 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7938 * representing the state of the modem.
7939 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007940 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7941 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007942 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007943 */
7944 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007945 public void requestModemActivityInfo(ResultReceiver result) {
7946 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007947 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007948
7949 final long identity = Binder.clearCallingIdentity();
7950 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007951 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007952 } finally {
7953 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007954 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007955 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007956
Siddharth Rayb8114062018-06-17 15:02:38 -07007957 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7958 // less than total activity duration.
7959 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7960 if (info == null) {
7961 return false;
7962 }
7963 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007964 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7965 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7966
Siddharth Rayb8114062018-06-17 15:02:38 -07007967 return (info.isValid()
7968 && (info.getSleepTimeMillis() <= activityDurationMs)
7969 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007970 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007971 && (totalTxTimeMs <= activityDurationMs));
7972 }
7973
Jack Yu85bd38a2015-11-09 11:34:32 -08007974 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007975 * Returns the service state information on specified subscription.
7976 */
7977 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007978 public ServiceState getServiceStateForSubscriber(int subId,
7979 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7980 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007981 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007982 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007983 return null;
7984 }
7985
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007986 boolean hasFinePermission = false;
7987 boolean hasCoarsePermission = false;
7988 if (!renounceFineLocationAccess) {
7989 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7990 LocationAccessPolicy.checkLocationPermission(mApp,
7991 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7992 .setCallingPackage(callingPackage)
7993 .setCallingFeatureId(callingFeatureId)
7994 .setCallingPid(Binder.getCallingPid())
7995 .setCallingUid(Binder.getCallingUid())
7996 .setMethod("getServiceStateForSubscriber")
7997 .setLogAsInfo(true)
7998 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7999 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8000 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8001 .build());
8002 hasFinePermission =
8003 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8004 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008005
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008006 if (!renounceCoarseLocationAccess) {
8007 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8008 LocationAccessPolicy.checkLocationPermission(mApp,
8009 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8010 .setCallingPackage(callingPackage)
8011 .setCallingFeatureId(callingFeatureId)
8012 .setCallingPid(Binder.getCallingPid())
8013 .setCallingUid(Binder.getCallingUid())
8014 .setMethod("getServiceStateForSubscriber")
8015 .setLogAsInfo(true)
8016 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8017 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8018 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8019 .build());
8020 hasCoarsePermission =
8021 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8022 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008023
Jack Yu479f40e2020-10-27 21:29:25 -07008024 final Phone phone = getPhone(subId);
8025 if (phone == null) {
8026 return null;
8027 }
8028
Jordan Liu0f2bc442020-11-18 16:47:37 -08008029 final long identity = Binder.clearCallingIdentity();
8030
Jack Yu479f40e2020-10-27 21:29:25 -07008031 boolean isCallingPackageDataService = phone.getDataServicePackages()
8032 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008033 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008034 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
8035 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
8036 Rlog.d(LOG_TAG,
8037 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
8038 return null;
8039 }
8040
Hall Liuf19c44f2018-11-27 14:38:17 -08008041 ServiceState ss = phone.getServiceState();
8042
8043 // Scrub out the location info in ServiceState depending on what level of access
8044 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008045 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008046 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8047 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008048 } finally {
8049 Binder.restoreCallingIdentity(identity);
8050 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008051 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008052
8053 /**
8054 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8055 *
8056 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8057 * voicemail ringtone.
8058 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8059 * PhoneAccount.
8060 */
8061 @Override
8062 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008063 final long identity = Binder.clearCallingIdentity();
8064 try {
8065 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8066 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008067 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008068 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008069
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008070 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8071 } finally {
8072 Binder.restoreCallingIdentity(identity);
8073 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008074 }
8075
8076 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008077 * Sets the per-account voicemail ringtone.
8078 *
8079 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8080 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8081 *
8082 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8083 * voicemail ringtone.
8084 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8085 * PhoneAccount.
8086 */
8087 @Override
8088 public void setVoicemailRingtoneUri(String callingPackage,
8089 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008090 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008091 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008092 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8093 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008094 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8095 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8096 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008097 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008098
8099 final long identity = Binder.clearCallingIdentity();
8100 try {
8101 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8102 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008103 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008104 }
8105 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8106 } finally {
8107 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008108 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008109 }
8110
8111 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008112 * Returns whether vibration is set for voicemail notification in Phone settings.
8113 *
8114 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8115 * voicemail vibration setting.
8116 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8117 */
8118 @Override
8119 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008120 final long identity = Binder.clearCallingIdentity();
8121 try {
8122 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8123 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008124 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008125 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008126
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008127 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8128 } finally {
8129 Binder.restoreCallingIdentity(identity);
8130 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008131 }
8132
Youhan Wange64578a2016-05-02 15:32:42 -07008133 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008134 * Sets the per-account voicemail vibration.
8135 *
8136 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8137 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8138 *
8139 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8140 * voicemail vibration setting.
8141 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8142 * specific PhoneAccount.
8143 */
8144 @Override
8145 public void setVoicemailVibrationEnabled(String callingPackage,
8146 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008147 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008148 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008149 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8150 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008151 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8152 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8153 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008154 }
8155
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008156 final long identity = Binder.clearCallingIdentity();
8157 try {
8158 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8159 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008160 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008161 }
8162 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8163 } finally {
8164 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008165 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008166 }
8167
8168 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008169 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8170 *
8171 * @throws SecurityException if the caller does not have the required permission
8172 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008173 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008174 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008175 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008176 }
8177
8178 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008179 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8180 * permission.
8181 *
8182 * @throws SecurityException if the caller does not have the required permission
8183 */
8184 private void enforceSendSmsPermission() {
8185 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8186 }
8187
8188 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008189 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008190 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008191 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008192 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008193 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008194 final long identity = Binder.clearCallingIdentity();
8195 try {
8196 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008197 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008198 if (componentName == null) {
8199 throw new SecurityException(
8200 "Caller not current active visual voicemail package[null]");
8201 }
8202 String vvmPackage = componentName.getPackageName();
8203 if (!callingPackage.equals(vvmPackage)) {
8204 throw new SecurityException("Caller not current active visual voicemail package["
8205 + vvmPackage + "]");
8206 }
8207 } finally {
8208 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008209 }
8210 }
8211
8212 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008213 * Return the application ID for the app type.
8214 *
8215 * @param subId the subscription ID that this request applies to.
8216 * @param appType the uicc app type.
8217 * @return Application ID for specificied app type, or null if no uicc.
8218 */
8219 @Override
8220 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008221 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008222 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008223
8224 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008225 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008226 if (phone == null) {
8227 return null;
8228 }
8229 String aid = null;
8230 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008231 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008232 .getApplicationByType(appType).getAid();
8233 } catch (Exception e) {
8234 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8235 }
8236 return aid;
8237 } finally {
8238 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008239 }
Youhan Wange64578a2016-05-02 15:32:42 -07008240 }
8241
Youhan Wang4001d252016-05-11 10:29:41 -07008242 /**
8243 * Return the Electronic Serial Number.
8244 *
8245 * @param subId the subscription ID that this request applies to.
8246 * @return ESN or null if error.
8247 */
8248 @Override
8249 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008250 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008251 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008252
8253 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008254 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008255 if (phone == null) {
8256 return null;
8257 }
8258 String esn = null;
8259 try {
8260 esn = phone.getEsn();
8261 } catch (Exception e) {
8262 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8263 }
8264 return esn;
8265 } finally {
8266 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008267 }
Youhan Wang4001d252016-05-11 10:29:41 -07008268 }
8269
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008270 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008271 * Return the Preferred Roaming List Version.
8272 *
8273 * @param subId the subscription ID that this request applies to.
8274 * @return PRLVersion or null if error.
8275 */
8276 @Override
8277 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008278 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008279 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008280
8281 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008282 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008283 if (phone == null) {
8284 return null;
8285 }
8286 String cdmaPrlVersion = null;
8287 try {
8288 cdmaPrlVersion = phone.getCdmaPrlVersion();
8289 } catch (Exception e) {
8290 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8291 }
8292 return cdmaPrlVersion;
8293 } finally {
8294 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008295 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008296 }
8297
8298 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008299 * Get snapshot of Telephony histograms
8300 * @return List of Telephony histograms
8301 * @hide
8302 */
8303 @Override
8304 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008305 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8306 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008307
8308 final long identity = Binder.clearCallingIdentity();
8309 try {
8310 return RIL.getTelephonyRILTimingHistograms();
8311 } finally {
8312 Binder.restoreCallingIdentity(identity);
8313 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008314 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008315
8316 /**
8317 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008318 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8319 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008320 * Require system privileges. In the future we may add this to carrier APIs.
8321 *
Michele Berionne482f8202018-11-27 18:57:59 -08008322 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008323 */
8324 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008325 @TelephonyManager.SetCarrierRestrictionResult
8326 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008327 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008328 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008329
Michele Berionne482f8202018-11-27 18:57:59 -08008330 if (carrierRestrictionRules == null) {
8331 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008332 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008333
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008334 final long identity = Binder.clearCallingIdentity();
8335 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008336 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008337 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008338 } finally {
8339 Binder.restoreCallingIdentity(identity);
8340 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008341 }
8342
8343 /**
8344 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008345 * Get the allowed carrier list and the excluded carrier list, including the priority between
8346 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008347 * Require system privileges. In the future we may add this to carrier APIs.
8348 *
Michele Berionne482f8202018-11-27 18:57:59 -08008349 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008350 */
8351 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008352 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008353 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008354 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008355
8356 final long identity = Binder.clearCallingIdentity();
8357 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008358 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8359 if (response instanceof CarrierRestrictionRules) {
8360 return (CarrierRestrictionRules) response;
8361 }
8362 // Response is an Exception of some kind,
8363 // which is signalled to the user as a NULL retval
8364 return null;
8365 } catch (Exception e) {
8366 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8367 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008368 } finally {
8369 Binder.restoreCallingIdentity(identity);
8370 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008371 }
8372
fionaxu59545b42016-05-25 15:53:37 -07008373 /**
fionaxu59545b42016-05-25 15:53:37 -07008374 * Action set from carrier signalling broadcast receivers to enable/disable radio
8375 * @param subId the subscription ID that this action applies to.
8376 * @param enabled control enable or disable radio.
8377 * {@hide}
8378 */
8379 @Override
8380 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8381 enforceModifyPermission();
8382 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008383
8384 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008385 if (phone == null) {
8386 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8387 return;
8388 }
8389 try {
8390 phone.carrierActionSetRadioEnabled(enabled);
8391 } catch (Exception e) {
8392 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008393 } finally {
8394 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008395 }
8396 }
8397
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008398 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008399 * Enable or disable Voice over NR (VoNR)
8400 * @param subId the subscription ID that this action applies to.
8401 * @param enabled enable or disable VoNR.
8402 * @return operation result.
8403 */
8404 @Override
8405 public int setVoNrEnabled(int subId, boolean enabled) {
8406 enforceModifyPermission();
8407 final Phone phone = getPhone(subId);
8408
8409 final long identity = Binder.clearCallingIdentity();
8410 if (phone == null) {
8411 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8412 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8413 }
8414
8415 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8416 try {
8417 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8418 workSource);
8419 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008420
8421 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8422 if (DBG) {
8423 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8424 }
8425 SubscriptionManager.setSubscriptionProperty(
8426 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8427 (enabled ? "1" : "0"));
8428 }
8429
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008430 return result;
8431 } finally {
8432 Binder.restoreCallingIdentity(identity);
8433 }
8434 }
8435
8436 /**
8437 * Is voice over NR enabled
8438 * @return true if VoNR is enabled else false
8439 */
8440 @Override
8441 public boolean isVoNrEnabled(int subId) {
8442 enforceReadPrivilegedPermission("isVoNrEnabled");
8443 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8444 final long identity = Binder.clearCallingIdentity();
8445 try {
8446 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8447 null, subId, workSource);
8448 if (DBG) log("isVoNrEnabled: " + isEnabled);
8449 return isEnabled;
8450 } finally {
8451 Binder.restoreCallingIdentity(identity);
8452 }
8453 }
8454
8455 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008456 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8457 * network status based on which carrier apps could apply actions accordingly,
8458 * enable/disable default url handler for example.
8459 *
8460 * @param subId the subscription ID that this action applies to.
8461 * @param report control start/stop reporting the default network status.
8462 * {@hide}
8463 */
8464 @Override
8465 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8466 enforceModifyPermission();
8467 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008468
8469 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008470 if (phone == null) {
8471 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8472 return;
8473 }
8474 try {
8475 phone.carrierActionReportDefaultNetworkStatus(report);
8476 } catch (Exception e) {
8477 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008478 } finally {
8479 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008480 }
8481 }
8482
8483 /**
fionaxud9622282017-07-17 17:51:30 -07008484 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8485 * @param subId the subscription ID that this action applies to.
8486 * {@hide}
8487 */
8488 @Override
8489 public void carrierActionResetAll(int subId) {
8490 enforceModifyPermission();
8491 final Phone phone = getPhone(subId);
8492 if (phone == null) {
8493 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8494 return;
8495 }
8496 try {
8497 phone.carrierActionResetAll();
8498 } catch (Exception e) {
8499 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8500 }
8501 }
8502
8503 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008504 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8505 * bug report is being generated.
8506 */
8507 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008508 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008509 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8510 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008511 writer.println("Permission Denial: can't dump Phone from pid="
8512 + Binder.getCallingPid()
8513 + ", uid=" + Binder.getCallingUid()
8514 + "without permission "
8515 + android.Manifest.permission.DUMP);
8516 return;
8517 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008518 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008519 }
Jack Yueb89b242016-06-22 13:27:47 -07008520
Brad Ebingerdac2f002018-04-03 15:17:52 -07008521 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008522 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8523 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8524 @NonNull String[] args) {
8525 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8526 this, in.getFileDescriptor(), out.getFileDescriptor(),
8527 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008528 }
8529
Jack Yueb89b242016-06-22 13:27:47 -07008530 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008531 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008532 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008533 * @param reason the reason the data enable change is taking place
8534 * @param enabled True if enabling the data, otherwise disabling.
8535 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008536 */
8537 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008538 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008539 boolean enabled) {
8540 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8541 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8542 try {
8543 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008544 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008545 } catch (SecurityException se) {
8546 enforceModifyPermission();
8547 }
8548 } else {
8549 enforceModifyPermission();
8550 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008551
8552 final long identity = Binder.clearCallingIdentity();
8553 try {
8554 Phone phone = getPhone(subId);
8555 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008556 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8557 phone.carrierActionSetMeteredApnsEnabled(enabled);
8558 } else {
Jack Yu99e87332021-12-17 23:14:15 -08008559 if (phone.isUsingNewDataStack()) {
8560 phone.getDataSettingsManager().setDataEnabled(reason, enabled);
8561 } else {
8562 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8563 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008564 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008565 }
8566 } finally {
8567 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008568 }
8569 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008570
8571 /**
8572 * Get Client request stats
8573 * @return List of Client Request Stats
8574 * @hide
8575 */
8576 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008577 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8578 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008579 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008580 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008581 return null;
8582 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008583 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008584
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008585 final long identity = Binder.clearCallingIdentity();
8586 try {
8587 if (phone != null) {
8588 return phone.getClientRequestStats();
8589 }
8590
8591 return null;
8592 } finally {
8593 Binder.restoreCallingIdentity(identity);
8594 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008595 }
8596
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008597 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008598 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008599 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008600 }
Jack Yueb4124c2017-02-16 15:32:43 -08008601
8602 /**
Grace Chen70990072017-03-24 17:21:30 -07008603 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008604 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008605 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008606 * @param state State of SIM (power down, power up, pass through)
8607 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8608 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8609 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008610 *
8611 **/
8612 @Override
Grace Chen70990072017-03-24 17:21:30 -07008613 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008614 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008615 Phone phone = PhoneFactory.getPhone(slotIndex);
8616
vagdeviaf9a5b92018-08-15 16:01:53 -07008617 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8618
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008619 final long identity = Binder.clearCallingIdentity();
8620 try {
8621 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008622 phone.setSimPowerState(state, null, workSource);
8623 }
8624 } finally {
8625 Binder.restoreCallingIdentity(identity);
8626 }
8627 }
8628
8629 /**
8630 * Set SIM card power state.
8631 *
8632 * @param slotIndex SIM slot id.
8633 * @param state State of SIM (power down, power up, pass through)
8634 * @param callback callback to trigger after success or failure
8635 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8636 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8637 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8638 *
8639 **/
8640 @Override
8641 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8642 IIntegerConsumer callback) {
8643 enforceModifyPermission();
8644 Phone phone = PhoneFactory.getPhone(slotIndex);
8645
8646 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8647
8648 final long identity = Binder.clearCallingIdentity();
8649 try {
8650 if (phone != null) {
8651 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8652 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008653 }
8654 } finally {
8655 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008656 }
8657 }
Shuo Qiandd210312017-04-12 22:11:33 +00008658
Tyler Gunn65d45c22017-06-05 11:22:26 -07008659 private boolean isUssdApiAllowed(int subId) {
8660 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008661 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008662 if (configManager == null) {
8663 return false;
8664 }
8665 PersistableBundle pb = configManager.getConfigForSubId(subId);
8666 if (pb == null) {
8667 return false;
8668 }
8669 return pb.getBoolean(
8670 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8671 }
8672
Shuo Qiandd210312017-04-12 22:11:33 +00008673 /**
8674 * Check if phone is in emergency callback mode
8675 * @return true if phone is in emergency callback mode
8676 * @param subId sub id
8677 */
goneil9c5f4872017-12-05 14:07:56 -08008678 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008679 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008680 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008681 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008682
8683 final long identity = Binder.clearCallingIdentity();
8684 try {
8685 if (phone != null) {
8686 return phone.isInEcm();
8687 } else {
8688 return false;
8689 }
8690 } finally {
8691 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008692 }
8693 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008694
8695 /**
8696 * Get the current signal strength information for the given subscription.
8697 * Because this information is not updated when the device is in a low power state
8698 * it should not be relied-upon to be current.
8699 * @param subId Subscription index
8700 * @return the most recent cached signal strength info from the modem
8701 */
8702 @Override
8703 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008704 final long identity = Binder.clearCallingIdentity();
8705 try {
8706 Phone p = getPhone(subId);
8707 if (p == null) {
8708 return null;
8709 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008710
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008711 return p.getSignalStrength();
8712 } finally {
8713 Binder.restoreCallingIdentity(identity);
8714 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008715 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008716
Pengquan Meng77b7f132018-08-22 14:49:57 -07008717 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008718 * Get the current modem radio state for the given slot.
8719 * @param slotIndex slot index.
8720 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008721 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008722 * @return the current radio power state from the modem
8723 */
8724 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008725 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008726 Phone phone = PhoneFactory.getPhone(slotIndex);
8727 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008728 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8729 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008730 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8731 }
8732
8733 final long identity = Binder.clearCallingIdentity();
8734 try {
8735 return phone.getRadioPowerState();
8736 } finally {
8737 Binder.restoreCallingIdentity(identity);
8738 }
8739 }
8740 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8741 }
8742
8743 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008744 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8745 *
8746 * <p>Requires one of the following permissions:
8747 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008748 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008749 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8750 * privileges.
8751 *
8752 * @param subId subscription id
8753 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8754 * {@code false}.
8755 */
8756 @Override
8757 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008758 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008759 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008760 try {
8761 mApp.enforceCallingOrSelfPermission(
8762 android.Manifest.permission.ACCESS_NETWORK_STATE,
8763 functionName);
8764 } catch (Exception e) {
8765 mApp.enforceCallingOrSelfPermission(
8766 permission.READ_BASIC_PHONE_STATE, functionName);
8767 }
Shuo Qian093013d2020-08-13 15:42:55 -07008768 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008769 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008770 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008771 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008772
Pengquan Menga1bb6272018-09-06 09:59:22 -07008773 boolean isEnabled = false;
8774 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008775 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008776 Phone phone = getPhone(subId);
8777 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008778 } finally {
8779 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008780 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008781 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008782 }
8783
8784
8785 /**
8786 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8787 *
8788 * <p> Requires permission:
8789 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8790 * privileges.
8791 *
8792 * @param subId subscription id
8793 * @param isEnabled {@code true} means enable, {@code false} means disable.
8794 */
8795 @Override
8796 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008797 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8798 mApp, subId, "setDataRoamingEnabled");
8799
Pengquan Menga1bb6272018-09-06 09:59:22 -07008800 final long identity = Binder.clearCallingIdentity();
8801 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008802 Phone phone = getPhone(subId);
8803 if (phone != null) {
8804 phone.setDataRoamingEnabled(isEnabled);
8805 }
8806 } finally {
8807 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008808 }
8809 }
8810
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008811 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008812 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008813 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008814 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008815 mApp, subId, "isManualNetworkSelectionAllowed");
8816
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008817 boolean isAllowed = true;
8818 final long identity = Binder.clearCallingIdentity();
8819 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008820 Phone phone = getPhone(subId);
8821 if (phone != null) {
8822 isAllowed = phone.isCspPlmnEnabled();
8823 }
8824 } finally {
8825 Binder.restoreCallingIdentity(identity);
8826 }
8827 return isAllowed;
8828 }
8829
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008830 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8831 UiccProfile profile = port.getUiccProfile();
8832 if (profile == null ||
8833 profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8834 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8835 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008836 }
8837 return true;
8838 }
8839
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008840 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008841 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008842 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008843 mApp.getSystemService(AppOpsManager.class)
8844 .checkPackage(Binder.getCallingUid(), callingPackage);
8845
Jordan Liu1e142fc2019-04-22 15:10:43 -07008846 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008847 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008848 try {
8849 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008850 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008851 } catch (SecurityException e) {
8852 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8853 // has carrier privileges on an active UICC
8854 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8855 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008856 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008857 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008858 }
sandeepjsb6c87872021-09-27 15:34:44 +00008859 // checking compatibility, if calling app's target SDK is T and beyond.
8860 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8861 Binder.getCallingUid())) {
8862 isIccIdAccessRestricted = true;
8863 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008864 final long identity = Binder.clearCallingIdentity();
8865 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008866 UiccController uiccController = UiccController.getInstance();
8867 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008868 if (hasReadPermission) {
8869 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008870 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008871
8872 // Remove private info if the caller doesn't have access
8873 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8874 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008875 //setting the value after compatibility check
8876 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008877 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8878 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008879 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008880 if (card == null) {
8881 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008882 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008883 continue;
8884 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008885 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8886 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008887 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008888 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008889 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008890 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8891 for (UiccPortInfo portInfo : portInfos) {
8892 UiccPort port = uiccController.getUiccPortForSlot(
8893 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8894 if (port == null) {
8895 // assume no access if port is null
8896 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8897 continue;
8898 }
8899 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8900 uiccPortInfos.add(portInfo);
8901 } else {
8902 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8903 }
8904 }
8905 filteredInfos.add(new UiccCardInfo(
8906 cardInfo.isEuicc(),
8907 cardInfo.getCardId(),
8908 null,
8909 cardInfo.getPhysicalSlotIndex(),
8910 cardInfo.isRemovable(),
8911 cardInfo.isMultipleEnabledProfilesSupported(),
8912 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008913 }
8914 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008915 } finally {
8916 Binder.restoreCallingIdentity(identity);
8917 }
8918 }
8919
sandeepjsb6c87872021-09-27 15:34:44 +00008920 /**
8921 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8922 * generally private and require carrier privileges to view.
8923 *
8924 * @hide
8925 */
8926 @NonNull
8927 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8928 List<UiccPortInfo> portinfo = new ArrayList<>();
8929 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8930 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8931 }
8932 return new UiccCardInfo(
8933 cardInfo.isEuicc(),
8934 cardInfo.getCardId(),
8935 null,
8936 cardInfo.getPhysicalSlotIndex(),
8937 cardInfo.isRemovable(),
8938 cardInfo.isMultipleEnabledProfilesSupported(),
8939 portinfo
8940 );
8941 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008942
sandeepjsb6c87872021-09-27 15:34:44 +00008943 /**
8944 * @hide
8945 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8946 * These values are generally private and require carrier privileges to view.
8947 */
8948 @NonNull
8949 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8950 return new UiccPortInfo(
8951 UiccPortInfo.ICCID_REDACTED,
8952 portInfo.getPortIndex(),
8953 portInfo.getLogicalSlotIndex(),
8954 portInfo.isActive()
8955 );
8956 }
8957 @Override
8958 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008959 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00008960 mApp.getSystemService(AppOpsManager.class)
8961 .checkPackage(Binder.getCallingUid(), callingPackage);
8962
8963 boolean hasReadPermission = false;
8964 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008965
8966 try {
8967 enforceReadPrivilegedPermission("getUiccSlotsInfo");
8968 hasReadPermission = true;
8969 } catch (SecurityException e) {
8970 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8971 // has carrier privileges on an active UICC
8972 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8973 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8974 hasReadPermission = true;
8975 }
8976 }
8977
8978 // checking compatibility, if calling app's target SDK is T and beyond.
8979 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8980 Binder.getCallingUid())) {
8981 isLogicalSlotAccessRestricted = true;
8982 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008983 final long identity = Binder.clearCallingIdentity();
8984 try {
8985 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8986 if (slots == null) {
8987 Rlog.i(LOG_TAG, "slots is null.");
8988 return null;
8989 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008990 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8991 for (int i = 0; i < slots.length; i++) {
8992 UiccSlot slot = slots[i];
8993 if (slot == null) {
8994 continue;
8995 }
8996
Jordan Liu7be7e652019-05-06 18:55:02 +00008997 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008998 UiccCard card = slot.getUiccCard();
8999 if (card != null) {
9000 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009001 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009002 cardId = slot.getEid();
9003 if (TextUtils.isEmpty(cardId)) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009004 // If cardId is null, use iccId of default port as cardId. Check if has
9005 // read permission otherwise set to null.(card is null which means no
9006 // carrier permission)
9007 cardId = hasReadPermission ? slot.getIccId(
9008 TelephonyManager.DEFAULT_PORT_INDEX) : null;
Jordan Liu01bd00d2019-09-12 16:19:43 -07009009 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009010 }
9011
Jordan Liu857451f2019-05-09 16:35:35 -07009012 if (cardId != null) {
9013 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9014 // if cardId is an EID, it's all digits so this is fine
9015 cardId = IccUtils.stripTrailingFs(cardId);
9016 }
9017
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009018 int cardState = 0;
9019 switch (slot.getCardState()) {
9020 case CARDSTATE_ABSENT:
9021 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9022 break;
9023 case CARDSTATE_PRESENT:
9024 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9025 break;
9026 case CARDSTATE_ERROR:
9027 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9028 break;
9029 case CARDSTATE_RESTRICTED:
9030 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9031 break;
9032 default:
9033 break;
9034
9035 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009036 List<UiccPortInfo> portInfos = new ArrayList<>();
9037 int[] portIndexes = slot.getPortList();
9038 for (int portIdx : portIndexes) {
9039 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
9040 callingPackage, hasReadPermission));
9041 if (slot.isPortActive(portIdx)) {
9042 UiccPort port = slot.getUiccCard().getUiccPort(portIdx);
9043 portInfos.add(new UiccPortInfo(iccId, port.getPortIdx(),
9044 port.getPhoneId(), true));
9045 } else {
9046 portInfos.add(new UiccPortInfo(iccId, portIdx, -1, false));
9047 }
9048 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009049 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009050 slot.isEuicc(),
9051 cardId,
9052 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009053 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009054 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009055 //setting the value after compatibility check
9056 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009057 }
9058 return infos;
9059 } finally {
9060 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009061 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009062 }
9063
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009064 /* Returns null if doesn't have read permission or carrier privilege access. */
9065 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9066 boolean hasReadPermission) {
9067 String iccId = slot.getIccId(portIndex);
9068 if (hasReadPermission) { // if has read permission
9069 return iccId;
9070 } else {
9071 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9072 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9073 // if no read permission, checking carrier privilege access
9074 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9075 return iccId;
9076 }
9077 }
9078 }
9079 // No read permission or carrier privilege access.
9080 return UiccPortInfo.ICCID_REDACTED;
9081 }
9082
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009083 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009084 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009085 public boolean switchSlots(int[] physicalSlots) {
9086 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009087
9088 final long identity = Binder.clearCallingIdentity();
9089 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009090 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9091 for (int i = 0; i < physicalSlots.length; i++) {
9092 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9093 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9094 physicalSlots[i], i));
9095 }
9096 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009097 } finally {
9098 Binder.restoreCallingIdentity(identity);
9099 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009100 }
Jack Yu4c988042018-02-27 15:30:01 -08009101
9102 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009103 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9104 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9105 enforceModifyPermission();
9106
9107 final long identity = Binder.clearCallingIdentity();
9108 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009109 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009110 } finally {
9111 Binder.restoreCallingIdentity(identity);
9112 }
9113 }
9114
9115 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009116 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009117 final long identity = Binder.clearCallingIdentity();
9118 try {
9119 return UiccController.getInstance().getCardIdForDefaultEuicc();
9120 } finally {
9121 Binder.restoreCallingIdentity(identity);
9122 }
9123 }
9124
Pengquan Meng85728fb2018-03-12 16:31:21 -07009125 /**
goneil47ffb6e2018-04-06 15:40:58 -07009126 * A test API to reload the UICC profile.
9127 *
9128 * <p>Requires that the calling app has permission
9129 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9130 * @hide
9131 */
9132 @Override
9133 public void refreshUiccProfile(int subId) {
9134 enforceModifyPermission();
9135
9136 final long identity = Binder.clearCallingIdentity();
9137 try {
9138 Phone phone = getPhone(subId);
9139 if (phone == null) {
9140 return;
9141 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009142 UiccPort uiccPort = phone.getUiccPort();
9143 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009144 return;
9145 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009146 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009147 if (uiccProfile == null) {
9148 return;
9149 }
9150 uiccProfile.refresh();
9151 } finally {
9152 Binder.restoreCallingIdentity(identity);
9153 }
9154 }
9155
9156 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009157 * Returns false if the mobile data is disabled by default, otherwise return true.
9158 */
9159 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009160 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009161 }
9162
9163 /**
9164 * Returns true if the data roaming is enabled by default, i.e the system property
9165 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9166 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9167 */
9168 private boolean getDefaultDataRoamingEnabled(int subId) {
9169 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009170 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009171 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009172 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9173 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9174 return isDataRoamingEnabled;
9175 }
9176
9177 /**
9178 * Returns the default network type for the given {@code subId}, if the default network type is
9179 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9180 */
9181 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009182 List<Integer> list = TelephonyProperties.default_network();
9183 int phoneId = mSubscriptionController.getPhoneId(subId);
9184 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9185 return list.get(phoneId);
9186 }
9187 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009188 }
fionaxua13278b2018-03-21 00:08:13 -07009189
9190 @Override
9191 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009192 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009193 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009194
9195 final long identity = Binder.clearCallingIdentity();
9196 try {
9197 final Phone phone = getPhone(subId);
9198 if (phone == null) {
9199 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9200 return;
9201 }
chen xueaba88a2019-03-15 13:15:10 -07009202 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9203 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009204 if (carrierPrivilegeRules == null) {
9205 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9206 } else {
9207 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9208 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009209 } finally {
9210 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009211 }
fionaxua13278b2018-03-21 00:08:13 -07009212 }
9213
9214 @Override
9215 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009216 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009217
9218 final long identity = Binder.clearCallingIdentity();
9219 try {
9220 final Phone phone = getPhone(subId);
9221 if (phone == null) {
9222 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9223 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9224 }
9225 return phone.getCarrierIdListVersion();
9226 } finally {
9227 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009228 }
fionaxua13278b2018-03-21 00:08:13 -07009229 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009230
9231 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009232 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9233 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009234 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009235 mApp, subId, callingPackage, callingFeatureId,
9236 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009237 return -1;
9238 }
9239
9240 final long identity = Binder.clearCallingIdentity();
9241 try {
9242 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9243 } finally {
9244 Binder.restoreCallingIdentity(identity);
9245 }
9246 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009247
9248 @Override
9249 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009250 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009251 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009252 mApp, subId, "getCdmaRoamingMode");
9253
9254 final long identity = Binder.clearCallingIdentity();
9255 try {
9256 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9257 } finally {
9258 Binder.restoreCallingIdentity(identity);
9259 }
9260 }
9261
9262 @Override
9263 public boolean setCdmaRoamingMode(int subId, int mode) {
9264 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9265 mApp, subId, "setCdmaRoamingMode");
9266
9267 final long identity = Binder.clearCallingIdentity();
9268 try {
9269 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9270 } finally {
9271 Binder.restoreCallingIdentity(identity);
9272 }
9273 }
9274
9275 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009276 public int getCdmaSubscriptionMode(int subId) {
9277 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009278 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009279 mApp, subId, "getCdmaSubscriptionMode");
9280
9281 final long identity = Binder.clearCallingIdentity();
9282 try {
9283 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9284 } finally {
9285 Binder.restoreCallingIdentity(identity);
9286 }
9287 }
9288
9289 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009290 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9291 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9292 mApp, subId, "setCdmaSubscriptionMode");
9293
9294 final long identity = Binder.clearCallingIdentity();
9295 try {
9296 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9297 } finally {
9298 Binder.restoreCallingIdentity(identity);
9299 }
9300 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009301
sqianc5eccab2018-10-19 18:46:41 -07009302 @Override
sqian8c685422019-02-22 15:55:18 -08009303 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009304 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009305 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009306 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9307 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009308 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9309 }
9310 final long identity = Binder.clearCallingIdentity();
9311 try {
sqian854d44b2018-12-12 16:48:18 -08009312 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9313 for (Phone phone: PhoneFactory.getPhones()) {
9314 if (phone.getEmergencyNumberTracker() != null
9315 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9316 emergencyNumberListInternal.put(
9317 phone.getSubId(),
9318 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9319 }
sqian11b7a0e2018-12-05 18:48:28 -08009320 }
sqian854d44b2018-12-12 16:48:18 -08009321 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009322 } finally {
9323 Binder.restoreCallingIdentity(identity);
9324 }
sqianc5eccab2018-10-19 18:46:41 -07009325 }
9326
9327 @Override
sqian8c685422019-02-22 15:55:18 -08009328 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009329 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009330 if (!exactMatch) {
9331 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009332 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009333 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009334 }
9335 final long identity = Binder.clearCallingIdentity();
9336 try {
sqian854d44b2018-12-12 16:48:18 -08009337 for (Phone phone: PhoneFactory.getPhones()) {
9338 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009339 && phone.getEmergencyNumberTracker()
9340 .isEmergencyNumber(number, exactMatch)) {
9341 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009342 }
sqian11b7a0e2018-12-05 18:48:28 -08009343 }
9344 return false;
9345 } finally {
9346 Binder.restoreCallingIdentity(identity);
9347 }
9348 }
9349
sqianf4ca7ed2019-01-15 18:32:07 -08009350 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009351 * Start emergency callback mode for GsmCdmaPhone for testing.
9352 */
9353 @Override
9354 public void startEmergencyCallbackMode() {
9355 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9356 "startEmergencyCallbackMode");
9357 enforceModifyPermission();
9358 final long identity = Binder.clearCallingIdentity();
9359 try {
9360 for (Phone phone : PhoneFactory.getPhones()) {
9361 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9362 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9363 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9364 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9365 gsmCdmaPhone.obtainMessage(
9366 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9367 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9368 }
9369 }
9370 } finally {
9371 Binder.restoreCallingIdentity(identity);
9372 }
9373 }
9374
9375 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009376 * Update emergency number list for test mode.
9377 */
9378 @Override
9379 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9380 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9381 "updateEmergencyNumberListTestMode");
9382
9383 final long identity = Binder.clearCallingIdentity();
9384 try {
9385 for (Phone phone: PhoneFactory.getPhones()) {
9386 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9387 if (tracker != null) {
9388 tracker.executeEmergencyNumberTestModeCommand(action, num);
9389 }
9390 }
9391 } finally {
9392 Binder.restoreCallingIdentity(identity);
9393 }
9394 }
9395
9396 /**
9397 * Get the full emergency number list for test mode.
9398 */
9399 @Override
9400 public List<String> getEmergencyNumberListTestMode() {
9401 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9402 "getEmergencyNumberListTestMode");
9403
9404 final long identity = Binder.clearCallingIdentity();
9405 try {
9406 Set<String> emergencyNumbers = new HashSet<>();
9407 for (Phone phone: PhoneFactory.getPhones()) {
9408 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9409 if (tracker != null) {
9410 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9411 emergencyNumbers.add(num.getNumber());
9412 }
9413 }
9414 }
9415 return new ArrayList<>(emergencyNumbers);
9416 } finally {
9417 Binder.restoreCallingIdentity(identity);
9418 }
9419 }
9420
chen xud6b45bd2018-10-30 22:27:10 -07009421 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009422 public int getEmergencyNumberDbVersion(int subId) {
9423 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9424
9425 final long identity = Binder.clearCallingIdentity();
9426 try {
9427 final Phone phone = getPhone(subId);
9428 if (phone == null) {
9429 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9430 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9431 }
9432 return phone.getEmergencyNumberDbVersion();
9433 } finally {
9434 Binder.restoreCallingIdentity(identity);
9435 }
9436 }
9437
9438 @Override
9439 public void notifyOtaEmergencyNumberDbInstalled() {
9440 enforceModifyPermission();
9441
9442 final long identity = Binder.clearCallingIdentity();
9443 try {
9444 for (Phone phone: PhoneFactory.getPhones()) {
9445 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9446 if (tracker != null) {
9447 tracker.updateOtaEmergencyNumberDatabase();
9448 }
9449 }
9450 } finally {
9451 Binder.restoreCallingIdentity(identity);
9452 }
9453 }
9454
9455 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009456 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009457 enforceActiveEmergencySessionPermission();
9458
9459 final long identity = Binder.clearCallingIdentity();
9460 try {
9461 for (Phone phone: PhoneFactory.getPhones()) {
9462 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9463 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009464 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9465 }
9466 }
9467 } finally {
9468 Binder.restoreCallingIdentity(identity);
9469 }
9470 }
9471
9472 @Override
9473 public void resetOtaEmergencyNumberDbFilePath() {
9474 enforceActiveEmergencySessionPermission();
9475
9476 final long identity = Binder.clearCallingIdentity();
9477 try {
9478 for (Phone phone: PhoneFactory.getPhones()) {
9479 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9480 if (tracker != null) {
9481 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009482 }
9483 }
9484 } finally {
9485 Binder.restoreCallingIdentity(identity);
9486 }
9487 }
9488
9489 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009490 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9491 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9492 Phone phone = getPhone(subId);
9493 if (phone == null) {
9494 return null;
9495 }
9496 final long identity = Binder.clearCallingIdentity();
9497 try {
9498 UiccProfile profile = UiccController.getInstance()
9499 .getUiccProfileForPhone(phone.getPhoneId());
9500 if (profile != null) {
9501 return profile.getCertsFromCarrierPrivilegeAccessRules();
9502 }
9503 } finally {
9504 Binder.restoreCallingIdentity(identity);
9505 }
9506 return null;
9507 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009508
9509 /**
9510 * Enable or disable a modem stack.
9511 */
9512 @Override
9513 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9514 enforceModifyPermission();
9515
9516 final long identity = Binder.clearCallingIdentity();
9517 try {
9518 Phone phone = PhoneFactory.getPhone(slotIndex);
9519 if (phone == null) {
9520 return false;
9521 } else {
9522 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9523 }
9524 } finally {
9525 Binder.restoreCallingIdentity(identity);
9526 }
9527 }
Michelecea4cf22018-12-21 15:00:11 -08009528
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009529 /**
9530 * Whether a modem stack is enabled or not.
9531 */
9532 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009533 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9534 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009535 Phone phone = PhoneFactory.getPhone(slotIndex);
9536 if (phone == null) return false;
9537
9538 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009539 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9540 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009541 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9542 }
9543
9544 final long identity = Binder.clearCallingIdentity();
9545 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009546 try {
9547 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9548 } catch (NoSuchElementException ex) {
9549 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9550 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009551 } finally {
9552 Binder.restoreCallingIdentity(identity);
9553 }
9554 }
9555
Michelecea4cf22018-12-21 15:00:11 -08009556 @Override
Michele0ea7d782019-03-19 14:58:42 -07009557 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009558 enforceModifyPermission();
9559
9560 final long identity = Binder.clearCallingIdentity();
9561 try {
9562 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009563 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009564 .commit();
9565 } finally {
9566 Binder.restoreCallingIdentity(identity);
9567 }
9568 }
9569
9570 @Override
Michele0ea7d782019-03-19 14:58:42 -07009571 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009572 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009573 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009574 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9575 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009576 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009577 }
Michelecea4cf22018-12-21 15:00:11 -08009578
9579 final long identity = Binder.clearCallingIdentity();
9580 try {
Michele0ea7d782019-03-19 14:58:42 -07009581 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009582 } finally {
9583 Binder.restoreCallingIdentity(identity);
9584 }
9585 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009586
Michele0ea7d782019-03-19 14:58:42 -07009587 @TelephonyManager.IsMultiSimSupportedResult
9588 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009589 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9590 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9591 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009592 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9593 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009594 }
9595 // Check if the hardware supports multisim functionality. If usage of multisim is not
9596 // supported by the modem, indicate that it is restricted.
9597 PhoneCapability staticCapability =
9598 mPhoneConfigurationManager.getStaticPhoneCapability();
9599 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009600 loge("isMultiSimSupportedInternal: no static configuration available");
9601 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009602 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009603 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009604 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9605 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009606 }
9607 // Check if support of multiple SIMs is restricted by carrier
9608 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009609 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009610 }
9611
Michele0ea7d782019-03-19 14:58:42 -07009612 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009613 }
9614
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009615 /**
9616 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009617 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9618 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9619 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009620 * @param numOfSims number of active sims we want to switch to
9621 */
9622 @Override
9623 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009624 if (numOfSims == 1) {
9625 enforceModifyPermission();
9626 } else {
9627 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9628 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9629 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009630 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009631
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009632 try {
Michele30b57b22019-03-01 12:01:14 -08009633 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009634 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009635 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9636 return;
9637 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009638 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9639 } finally {
9640 Binder.restoreCallingIdentity(identity);
9641 }
9642 }
9643
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009644 @Override
9645 public boolean isApplicationOnUicc(int subId, int appType) {
9646 enforceReadPrivilegedPermission("isApplicationOnUicc");
9647 Phone phone = getPhone(subId);
9648 if (phone == null) {
9649 return false;
9650 }
9651 final long identity = Binder.clearCallingIdentity();
9652 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009653 UiccPort uiccPort = phone.getUiccPort();
9654 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009655 return false;
9656 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009657 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009658 if (uiccProfile == null) {
9659 return false;
9660 }
9661 if (TelephonyManager.APPTYPE_SIM <= appType
9662 && appType <= TelephonyManager.APPTYPE_ISIM) {
9663 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9664 }
9665 return false;
9666 } finally {
9667 Binder.restoreCallingIdentity(identity);
9668 }
9669 }
9670
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009671 /**
chen xub4baa772019-04-03 10:23:41 -07009672 * Get whether making changes to modem configurations will trigger reboot.
9673 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009674 */
9675 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009676 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9677 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009678 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009679 mApp, subId, callingPackage, callingFeatureId,
9680 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009681 return false;
9682 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009683 final long identity = Binder.clearCallingIdentity();
9684 try {
9685 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9686 } finally {
9687 Binder.restoreCallingIdentity(identity);
9688 }
9689 }
9690
Nathan Harold29f5f052019-02-15 13:41:57 -08009691 private void updateModemStateMetrics() {
9692 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9693 // TODO: check the state for each modem if the api is ready.
9694 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9695 }
9696
Pengquan Meng3889a572019-01-23 11:16:29 -08009697 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009698 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009699 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009700 // Verify that the callingPackage belongs to the calling UID
9701 mApp.getSystemService(AppOpsManager.class)
9702 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009703 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009704 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009705 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009706 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9707 if (slotInfos != null) {
9708 for (int i = 0; i < slotInfos.length; i++) {
9709 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9710 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9711 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9712 portInfo.getLogicalSlotIndex()));
9713 }
9714 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009715 }
9716 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009717 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009718 } finally {
9719 Binder.restoreCallingIdentity(identity);
9720 }
9721 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009722
9723 /**
9724 * Get the IRadio HAL Version
9725 */
9726 @Override
9727 public int getRadioHalVersion() {
9728 Phone phone = getDefaultPhone();
9729 if (phone == null) return -1;
9730 HalVersion hv = phone.getHalVersion();
9731 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9732 return hv.major * 100 + hv.minor;
9733 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009734
9735 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009736 * Get the current calling package name.
9737 * @return the current calling package name
9738 */
9739 @Override
9740 public String getCurrentPackageName() {
9741 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9742 }
9743
9744 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009745 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9746 * corresponding network requests on a subId.
9747 *
9748 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009749 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009750 * 2) APN is un-metered for this subscription, or
9751 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009752 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009753 *
9754 * @return whether data is allowed for a apn type.
9755 *
9756 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009757 */
9758 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009759 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009760 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9761 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009762
9763 // Now that all security checks passes, perform the operation as ourselves.
9764 final long identity = Binder.clearCallingIdentity();
9765 try {
9766 Phone phone = getPhone(subId);
9767 if (phone == null) return false;
9768
Jack Yu41407ee2019-05-13 16:54:09 -07009769 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Jack Yu99e87332021-12-17 23:14:15 -08009770 boolean isDataEnabled;
9771 if (phone.isUsingNewDataStack()) {
9772 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
9773 } else {
9774 isDataEnabled = phone.getDataEnabledSettings().isDataEnabled(apnType);
9775 }
9776 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009777 } finally {
9778 Binder.restoreCallingIdentity(identity);
9779 }
9780 }
9781
9782 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009783 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009784 enforceReadPrivilegedPermission("isApnMetered");
9785
9786 // Now that all security checks passes, perform the operation as ourselves.
9787 final long identity = Binder.clearCallingIdentity();
9788 try {
9789 Phone phone = getPhone(subId);
9790 if (phone == null) return true; // By default return true.
9791
Jack Yu41407ee2019-05-13 16:54:09 -07009792 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009793 } finally {
9794 Binder.restoreCallingIdentity(identity);
9795 }
9796 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009797
9798 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009799 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9800 int subscriptionId, IBooleanConsumer resultCallback) {
9801 enforceModifyPermission();
9802 long token = Binder.clearCallingIdentity();
9803 try {
9804 Phone phone = getPhone(subscriptionId);
9805 if (phone == null) {
9806 try {
9807 if (resultCallback != null) {
9808 resultCallback.accept(false);
9809 }
9810 } catch (RemoteException e) {
9811 // ignore
9812 }
9813 return;
9814 }
9815 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9816 Pair.create(specifiers, (x) -> {
9817 try {
9818 if (resultCallback != null) {
9819 resultCallback.accept(x);
9820 }
9821 } catch (RemoteException e) {
9822 // ignore
9823 }
9824 });
9825 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9826 } finally {
9827 Binder.restoreCallingIdentity(token);
9828 }
9829 }
9830
9831 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009832 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9833 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009834 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009835 mApp, subId, "getSystemSelectionChannels");
9836 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9837 final long identity = Binder.clearCallingIdentity();
9838 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009839 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9840 if (result instanceof IllegalStateException) {
9841 throw (IllegalStateException) result;
9842 }
9843 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009844 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9845 return specifiers;
9846 } finally {
9847 Binder.restoreCallingIdentity(identity);
9848 }
9849 }
9850
9851 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009852 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009853 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009854 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9855 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9856 if (iccRecords == null) {
9857 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9858 return false;
9859 }
9860 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9861 }
9862
9863 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009864 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9865 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009866 if (callingPackage == null) {
9867 callingPackage = getCurrentPackageName();
9868 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009869 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9870 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009871 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9872 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009873 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9874 }
9875 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9876 Intent intent = new Intent();
9877 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9878 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9879 // Bring up choose default SMS subscription dialog right now
9880 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9881 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9882 mApp.startActivity(intent);
9883 }
chen xud5ca2d52019-05-28 15:20:57 -07009884
9885 @Override
9886 public String getMmsUAProfUrl(int subId) {
9887 //TODO investigate if this API should require proper permission check in R b/133791609
9888 final long identity = Binder.clearCallingIdentity();
9889 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009890 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9891 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9892 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9893 return carrierUAProfUrl;
9894 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009895 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9896 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009897 } finally {
9898 Binder.restoreCallingIdentity(identity);
9899 }
9900 }
9901
9902 @Override
9903 public String getMmsUserAgent(int subId) {
9904 //TODO investigate if this API should require proper permission check in R b/133791609
9905 final long identity = Binder.clearCallingIdentity();
9906 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009907 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9908 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9909 if (!TextUtils.isEmpty(carrierUserAgent)) {
9910 return carrierUserAgent;
9911 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009912 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9913 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009914 } finally {
9915 Binder.restoreCallingIdentity(identity);
9916 }
9917 }
Jack Yub07d4972019-05-28 16:12:25 -07009918
9919 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009920 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9921 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009922
Jack Yub07d4972019-05-28 16:12:25 -07009923 final long identity = Binder.clearCallingIdentity();
9924 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009925 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009926 if (phone == null) return false;
9927
Hall Liua62f5da2020-09-25 10:42:19 -07009928 switch (policy) {
9929 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu99e87332021-12-17 23:14:15 -08009930 if (phone.isUsingNewDataStack()) {
9931 return phone.getDataSettingsManager().isDataAllowedInVoiceCall();
9932 } else {
9933 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9934 }
Hall Liua62f5da2020-09-25 10:42:19 -07009935 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu99e87332021-12-17 23:14:15 -08009936 if (phone.isUsingNewDataStack()) {
9937 return phone.getDataSettingsManager().isMmsAlwaysAllowed();
9938 } else {
9939 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9940 }
Hall Liua62f5da2020-09-25 10:42:19 -07009941 default:
9942 throw new IllegalArgumentException(policy + " is not a valid policy");
9943 }
Jack Yub07d4972019-05-28 16:12:25 -07009944 } finally {
9945 Binder.restoreCallingIdentity(identity);
9946 }
9947 }
9948
9949 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009950 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009951 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009952 enforceModifyPermission();
9953
changbettyd5c246e2019-12-24 15:40:37 +08009954 final long identity = Binder.clearCallingIdentity();
9955 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009956 Phone phone = getPhone(subscriptionId);
9957 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009958
Hall Liua62f5da2020-09-25 10:42:19 -07009959 switch (policy) {
9960 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu99e87332021-12-17 23:14:15 -08009961 if (phone.isUsingNewDataStack()) {
9962 phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled);
9963 } else {
9964 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9965 }
Hall Liua62f5da2020-09-25 10:42:19 -07009966 break;
9967 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu99e87332021-12-17 23:14:15 -08009968 if (phone.isUsingNewDataStack()) {
9969 phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled);
9970 } else {
9971 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9972 }
Hall Liua62f5da2020-09-25 10:42:19 -07009973 break;
9974 default:
9975 throw new IllegalArgumentException(policy + " is not a valid policy");
9976 }
changbettyd5c246e2019-12-24 15:40:37 +08009977 } finally {
9978 Binder.restoreCallingIdentity(identity);
9979 }
9980 }
9981
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009982 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009983 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009984 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9985 * otherwise.
9986 */
9987 @Override
9988 public void setCepEnabled(boolean isCepEnabled) {
9989 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9990
9991 final long identity = Binder.clearCallingIdentity();
9992 try {
9993 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9994 for (Phone phone : PhoneFactory.getPhones()) {
9995 Phone defaultPhone = phone.getImsPhone();
9996 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9997 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9998 ImsPhoneCallTracker imsPhoneCallTracker =
9999 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10000 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10001 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10002 + imsPhone.getMsisdn());
10003 }
10004 }
10005 } finally {
10006 Binder.restoreCallingIdentity(identity);
10007 }
10008 }
allenwtsu46dcc572020-01-08 18:24:03 +080010009
10010 /**
10011 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10012 *
10013 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10014 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10015 * before being read.
10016 */
10017 @Override
10018 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10019 isCompressed) {
10020 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10021 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010022 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10023 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10024 }
10025 if (!isImsAvailableOnDevice()) {
10026 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10027 "IMS not available on device.");
10028 }
10029
10030 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010031 try {
Hui Wang761a6682020-10-31 05:12:53 +000010032 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10033 } finally {
10034 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010035 }
10036 }
zoey chene02881a2019-12-30 16:11:23 +080010037
10038 @Override
10039 public boolean isIccLockEnabled(int subId) {
10040 enforceReadPrivilegedPermission("isIccLockEnabled");
10041
10042 // Now that all security checks passes, perform the operation as ourselves.
10043 final long identity = Binder.clearCallingIdentity();
10044 try {
10045 Phone phone = getPhone(subId);
10046 if (phone != null && phone.getIccCard() != null) {
10047 return phone.getIccCard().getIccLockEnabled();
10048 } else {
10049 return false;
10050 }
10051 } finally {
10052 Binder.restoreCallingIdentity(identity);
10053 }
10054 }
10055
10056 /**
10057 * Set the ICC pin lock enabled or disabled.
10058 *
10059 * @return an integer representing the status of IccLock enabled or disabled in the following
10060 * three cases:
10061 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10062 * successfully.
10063 * - Positive number and zero for remaining password attempts.
10064 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10065 *
10066 */
10067 @Override
10068 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10069 enforceModifyPermission();
10070
10071 Phone phone = getPhone(subId);
10072 if (phone == null) {
10073 return 0;
10074 }
10075 // Now that all security checks passes, perform the operation as ourselves.
10076 final long identity = Binder.clearCallingIdentity();
10077 try {
10078 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10079 new Pair<Boolean, String>(enabled, password), phone, null);
10080 return attemptsRemaining;
10081
10082 } catch (Exception e) {
10083 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10084 } finally {
10085 Binder.restoreCallingIdentity(identity);
10086 }
10087 return 0;
10088 }
10089
10090 /**
10091 * Change the ICC password used in ICC pin lock.
10092 *
10093 * @return an integer representing the status of IccLock changed in the following three cases:
10094 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10095 * - Positive number and zero for remaining password attempts.
10096 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10097 *
10098 */
10099 @Override
10100 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10101 enforceModifyPermission();
10102
10103 Phone phone = getPhone(subId);
10104 if (phone == null) {
10105 return 0;
10106 }
10107 // Now that all security checks passes, perform the operation as ourselves.
10108 final long identity = Binder.clearCallingIdentity();
10109 try {
10110 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10111 new Pair<String, String>(oldPassword, newPassword), phone, null);
10112 return attemptsRemaining;
10113
10114 } catch (Exception e) {
10115 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10116 } finally {
10117 Binder.restoreCallingIdentity(identity);
10118 }
10119 return 0;
10120 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010121
10122 /**
10123 * Request for receiving user activity notification
10124 */
10125 @Override
10126 public void requestUserActivityNotification() {
10127 if (!mNotifyUserActivity.get()
10128 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10129 mNotifyUserActivity.set(true);
10130 }
10131 }
10132
10133 /**
10134 * Called when userActivity is signalled in the power manager.
10135 * This is safe to call from any thread, with any window manager locks held or not.
10136 */
10137 @Override
10138 public void userActivity() {
10139 // ***************************************
10140 // * Inherited from PhoneWindowManager *
10141 // ***************************************
10142 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10143 // WITH ITS LOCKS HELD.
10144 //
10145 // This code must be VERY careful about the locks
10146 // it acquires.
10147 // In fact, the current code acquires way too many,
10148 // and probably has lurking deadlocks.
10149
10150 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10151 throw new SecurityException("Only the OS may call notifyUserActivity()");
10152 }
10153
10154 if (mNotifyUserActivity.getAndSet(false)) {
10155 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10156 USER_ACTIVITY_NOTIFICATION_DELAY);
10157 }
10158 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010159
10160 @Override
10161 public boolean canConnectTo5GInDsdsMode() {
10162 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10163 }
Jack Yud10cdd42020-09-28 20:28:01 -070010164
10165 @Override
10166 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10167 String callingFeatureId) {
10168 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10169 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10170 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10171 }
10172
10173 Phone phone = getPhone(subId);
10174 if (phone == null) {
10175 throw new RuntimeException("phone is not available");
10176 }
10177 // Now that all security checks passes, perform the operation as ourselves.
10178 final long identity = Binder.clearCallingIdentity();
10179 try {
10180 return phone.getEquivalentHomePlmns();
10181 } finally {
10182 Binder.restoreCallingIdentity(identity);
10183 }
10184 }
Daniel Bright59e67312020-11-13 11:49:37 -080010185
10186 @Override
10187 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010188 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10189 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010190 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010191 if (radioInterfaceCapabilities == null) {
10192 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010193 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010194 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010195 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010196
Hui Wang641e81c2020-10-12 12:14:23 -070010197 @Override
10198 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10199 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010200 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10201 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10202 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10203 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10204 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010205 if (DBG) {
10206 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10207 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10208 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10209 }
10210
10211 if (!SubscriptionManager.isValidSubscriptionId(subId)
10212 || appType < TelephonyManager.APPTYPE_UNKNOWN
10213 || appType > TelephonyManager.APPTYPE_ISIM
10214 || nafUrl == null || securityProtocol == null || callback == null) {
10215 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10216 if (callback != null) {
10217 try {
10218 callback.onAuthenticationFailure(
10219 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10220 } catch (RemoteException exception) {
10221 log("Fail to notify onAuthenticationFailure due to " + exception);
10222 }
10223 return;
10224 }
10225 }
10226
10227 final long token = Binder.clearCallingIdentity();
10228 try {
10229 getGbaManager(subId).bootstrapAuthenticationRequest(
10230 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10231 forceBootStrapping, callback));
10232 } finally {
10233 Binder.restoreCallingIdentity(token);
10234 }
10235 }
10236
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010237 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010238 * Attempts to set the radio power state for all phones for thermal reason.
10239 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010240 * requested radio power state will actually be set. See {@link
10241 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10242 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010243 * @param enable {@code true} if trying to turn radio on.
10244 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10245 * false}.
10246 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010247 private boolean setRadioPowerForThermal(boolean enable) {
10248 boolean isPhoneAvailable = false;
10249 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10250 Phone phone = PhoneFactory.getPhone(i);
10251 if (phone != null) {
10252 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10253 isPhoneAvailable = true;
10254 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010255 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010256
10257 // return true if successfully informed the phone object about the thermal radio power
10258 // request.
10259 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010260 }
10261
10262 private int handleDataThrottlingRequest(int subId,
10263 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010264 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10265 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10266 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10267 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10268 throw new IllegalArgumentException("modem does not support data throttling");
10269 }
10270
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010271 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10272 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010273 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010274 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10275 }
10276
10277 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10278
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010279 if (isDataThrottlingSupported) {
10280 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010281 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010282 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10283 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10284 } else if (thermalMitigationResult
10285 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010286 log("Modem likely does not support data throttling on secondary carrier. Data " +
10287 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10288 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010289 }
10290 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010291 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010292
10293 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010294 }
10295
Jack Nudelman644b91a2021-03-12 14:09:48 -080010296 private static List<String> getThermalMitigationAllowlist(Context context) {
10297 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10298 for (String pckg : context.getResources()
10299 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10300 sThermalMitigationAllowlistedPackages.add(pckg);
10301 }
10302 }
10303
10304 return sThermalMitigationAllowlistedPackages;
10305 }
10306
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010307 private boolean isAnyPhoneInEmergencyState() {
10308 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10309 if (tm.isInEmergencyCall()) {
10310 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10311 return true;
10312 }
10313 for (Phone phone : PhoneFactory.getPhones()) {
10314 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10315 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10316 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10317 + phone.isInEcm());
10318 return true;
10319 }
10320 }
10321
10322 return false;
10323 }
10324
Jack Nudelman644b91a2021-03-12 14:09:48 -080010325 /**
10326 * Used by shell commands to add an authorized package name for thermal mitigation.
10327 * @param packageName name of package to be allowlisted
10328 * @param context
10329 */
10330 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10331 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10332 sThermalMitigationAllowlistedPackages.add(packageName);
10333 }
10334
10335 /**
10336 * Used by shell commands to remove an authorized package name for thermal mitigation.
10337 * @param packageName name of package to remove from allowlist
10338 * @param context
10339 */
10340 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10341 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10342 sThermalMitigationAllowlistedPackages.remove(packageName);
10343 }
10344
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010345 /**
10346 * Thermal mitigation request to control functionalities at modem.
10347 *
10348 * @param subId the id of the subscription.
10349 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010350 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010351 *
10352 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10353 */
10354 @Override
10355 @ThermalMitigationResult
10356 public int sendThermalMitigationRequest(
10357 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010358 ThermalMitigationRequest thermalMitigationRequest,
10359 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010360 enforceModifyPermission();
10361
Jack Nudelman644b91a2021-03-12 14:09:48 -080010362 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10363 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10364 .contains(callingPackage)) {
10365 throw new SecurityException("Calling package must be configured in the device config. "
10366 + "calling package: " + callingPackage);
10367 }
10368
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010369 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10370 final long identity = Binder.clearCallingIdentity();
10371
10372 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10373 try {
10374 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10375 switch (thermalMitigationAction) {
10376 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10377 thermalMitigationResult =
10378 handleDataThrottlingRequest(subId,
10379 thermalMitigationRequest.getDataThrottlingRequest());
10380 break;
10381 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10382 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10383 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10384 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10385 }
10386
10387 // Ensure that radio is on. If not able to power on due to phone being
10388 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010389 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010390 thermalMitigationResult =
10391 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10392 break;
10393 }
10394
10395 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10396 false);
10397 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10398 break;
10399 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10400 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10401 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10402 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10403 }
10404
10405 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10406 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010407 Phone phone = getPhone(subId);
10408 if (phone == null) {
10409 thermalMitigationResult =
10410 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10411 break;
10412 }
10413
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010414 TelephonyConnectionService service =
10415 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010416 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010417 Log.e(LOG_TAG, "An emergency call is pending");
10418 thermalMitigationResult =
10419 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10420 break;
10421 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010422 thermalMitigationResult =
10423 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10424 break;
10425 }
10426 } else {
10427 thermalMitigationResult =
10428 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10429 break;
10430 }
10431
10432 // Turn radio off. If not able to power off due to phone being unavailable,
10433 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010434 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010435 thermalMitigationResult =
10436 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10437 break;
10438 }
10439 thermalMitigationResult =
10440 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10441 break;
10442 default:
10443 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10444 + "not exist. Requested action: " + thermalMitigationAction);
10445 }
10446 } catch (IllegalArgumentException e) {
10447 throw e;
10448 } catch (Exception e) {
10449 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10450 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10451 } finally {
10452 Binder.restoreCallingIdentity(identity);
10453 }
10454
10455 if (DBG) {
10456 log("thermalMitigationRequest returning with thermalMitigationResult: "
10457 + thermalMitigationResult);
10458 }
10459
10460 return thermalMitigationResult;
10461 }
Hui Wang641e81c2020-10-12 12:14:23 -070010462
10463 /**
10464 * Set the GbaService Package Name that Telephony will bind to.
10465 *
10466 * @param subId The sim that the GbaService is associated with.
10467 * @param packageName The name of the package to be replaced with.
10468 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10469 */
10470 @Override
10471 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10472 enforceModifyPermission();
10473
10474 final long identity = Binder.clearCallingIdentity();
10475 try {
10476 return getGbaManager(subId).overrideServicePackage(packageName);
10477 } finally {
10478 Binder.restoreCallingIdentity(identity);
10479 }
10480 }
10481
10482 /**
10483 * Return the package name of the currently bound GbaService.
10484 *
10485 * @param subId The sim that the GbaService is associated with.
10486 * @return the package name of the GbaService configuration, null if GBA is not supported.
10487 */
10488 @Override
10489 public String getBoundGbaService(int subId) {
10490 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10491
10492 final long identity = Binder.clearCallingIdentity();
10493 try {
10494 return getGbaManager(subId).getServicePackage();
10495 } finally {
10496 Binder.restoreCallingIdentity(identity);
10497 }
10498 }
10499
10500 /**
10501 * Set the release time for telephony to unbind GbaService.
10502 *
10503 * @param subId The sim that the GbaService is associated with.
10504 * @param interval The release time to unbind GbaService by millisecond.
10505 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10506 */
10507 @Override
10508 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10509 enforceModifyPermission();
10510
10511 final long identity = Binder.clearCallingIdentity();
10512 try {
10513 return getGbaManager(subId).overrideReleaseTime(interval);
10514 } finally {
10515 Binder.restoreCallingIdentity(identity);
10516 }
10517 }
10518
10519 /**
10520 * Return the release time for telephony to unbind GbaService.
10521 *
10522 * @param subId The sim that the GbaService is associated with.
10523 * @return The release time to unbind GbaService by millisecond.
10524 */
10525 @Override
10526 public int getGbaReleaseTime(int subId) {
10527 enforceReadPrivilegedPermission("getGbaReleaseTime");
10528
10529 final long identity = Binder.clearCallingIdentity();
10530 try {
10531 return getGbaManager(subId).getReleaseTime();
10532 } finally {
10533 Binder.restoreCallingIdentity(identity);
10534 }
10535 }
10536
10537 private GbaManager getGbaManager(int subId) {
10538 GbaManager instance = GbaManager.getInstance(subId);
10539 if (instance == null) {
10540 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10541 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10542 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10543 }
10544 return instance;
10545 }
Hui Wang761a6682020-10-31 05:12:53 +000010546
10547 /**
10548 * indicate whether the device and the carrier can support
10549 * RCS VoLTE single registration.
10550 */
10551 @Override
10552 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010553 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10554 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10555 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10556 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010557
10558 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10559 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10560 }
10561
10562 final long identity = Binder.clearCallingIdentity();
10563 try {
10564 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10565 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010566 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10567 if (isCapable != null) {
10568 return isCapable;
10569 }
Hui Wang761a6682020-10-31 05:12:53 +000010570 }
Hui Wang67af90e2021-06-04 16:57:15 -070010571 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10572 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010573 } finally {
10574 Binder.restoreCallingIdentity(identity);
10575 }
10576 }
10577
10578 /**
10579 * Register RCS provisioning callback.
10580 */
10581 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010582 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010583 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010584 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010585 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010586 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10587 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010588
10589 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10590 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10591 }
10592 if (!isImsAvailableOnDevice()) {
10593 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10594 "IMS not available on device.");
10595 }
10596
10597 final long identity = Binder.clearCallingIdentity();
10598 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010599 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010600 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010601 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10602 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010603 }
Hui Wang761a6682020-10-31 05:12:53 +000010604 } finally {
10605 Binder.restoreCallingIdentity(identity);
10606 }
10607 }
10608
10609 /**
10610 * Unregister RCS provisioning callback.
10611 */
10612 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010613 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010614 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010615 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010616 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010617 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10618 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010619
10620 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10621 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10622 }
10623 if (!isImsAvailableOnDevice()) {
10624 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10625 "IMS not available on device.");
10626 }
10627
10628 final long identity = Binder.clearCallingIdentity();
10629 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010630 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010631 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010632 } finally {
10633 Binder.restoreCallingIdentity(identity);
10634 }
10635 }
10636
10637 /**
10638 * trigger RCS reconfiguration.
10639 */
10640 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010641 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10642 "triggerRcsReconfiguration",
10643 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010644
10645 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10646 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10647 }
10648 if (!isImsAvailableOnDevice()) {
10649 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10650 "IMS not available on device.");
10651 }
10652
10653 final long identity = Binder.clearCallingIdentity();
10654 try {
10655 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10656 } finally {
10657 Binder.restoreCallingIdentity(identity);
10658 }
10659 }
10660
10661 /**
10662 * Provide the client configuration parameters of the RCS application.
10663 */
10664 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010665 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10666 "setRcsClientConfiguration",
10667 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010668
10669 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10670 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10671 }
10672 if (!isImsAvailableOnDevice()) {
10673 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10674 "IMS not available on device.");
10675 }
10676
10677 final long identity = Binder.clearCallingIdentity();
10678
10679 try {
10680 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10681 if (configBinder == null) {
10682 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010683 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10684 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010685 } else {
10686 configBinder.setRcsClientConfiguration(rcc);
10687 }
joonhunshin3e154242021-09-17 06:33:39 +000010688
10689 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10690 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010691 } catch (RemoteException e) {
10692 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010693 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10694 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010695 } finally {
10696 Binder.restoreCallingIdentity(identity);
10697 }
10698 }
10699
10700 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010701 * Enables or disables the test mode for RCS VoLTE single registration.
10702 */
10703 @Override
10704 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10705 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10706 "setRcsSingleRegistrationTestModeEnabled");
10707
10708 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10709 }
10710
10711 /**
10712 * Gets the test mode for RCS VoLTE single registration.
10713 */
10714 @Override
10715 public boolean getRcsSingleRegistrationTestModeEnabled() {
10716 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10717 "getRcsSingleRegistrationTestModeEnabled");
10718
10719 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10720 }
10721
10722 /**
Hui Wang761a6682020-10-31 05:12:53 +000010723 * Overrides the config of RCS VoLTE single registration enabled for the device.
10724 */
10725 @Override
10726 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10727 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10728 "setDeviceSingleRegistrationEnabledOverride");
10729 enforceModifyPermission();
10730
10731 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10732 : Boolean.parseBoolean(enabledStr);
10733 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010734 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010735 }
10736
10737 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010738 * Sends a device to device communication message. Only usable via shell.
10739 * @param message message to send.
10740 * @param value message value.
10741 */
10742 @Override
10743 public void sendDeviceToDeviceMessage(int message, int value) {
10744 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010745 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010746 enforceModifyPermission();
10747
10748 final long identity = Binder.clearCallingIdentity();
10749 try {
10750 TelephonyConnectionService service =
10751 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10752 if (service == null) {
10753 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10754 return;
10755 }
10756 service.sendTestDeviceToDeviceMessage(message, value);
10757 } finally {
10758 Binder.restoreCallingIdentity(identity);
10759 }
10760 }
10761
Tyler Gunnbabbda02021-02-10 11:05:02 -080010762 /**
10763 * Sets the specified device to device transport active.
10764 * @param transport The transport to set active.
10765 */
10766 @Override
10767 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10768 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10769 "setActiveDeviceToDeviceTransport");
10770 enforceModifyPermission();
10771
10772 final long identity = Binder.clearCallingIdentity();
10773 try {
10774 TelephonyConnectionService service =
10775 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10776 if (service == null) {
10777 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10778 return;
10779 }
10780 service.setActiveDeviceToDeviceTransport(transport);
10781 } finally {
10782 Binder.restoreCallingIdentity(identity);
10783 }
10784 }
Tyler Gunn92479152021-01-20 16:30:10 -080010785
Tyler Gunnd4339262021-05-03 14:46:49 -070010786 @Override
10787 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10788 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10789 "setDeviceToDeviceForceEnabled");
10790
10791 final long identity = Binder.clearCallingIdentity();
10792 try {
10793 Arrays.stream(PhoneFactory.getPhones()).forEach(
10794 p -> {
10795 Phone thePhone = p.getImsPhone();
10796 if (thePhone != null && thePhone instanceof ImsPhone) {
10797 ImsPhone imsPhone = (ImsPhone) thePhone;
10798 CallTracker tracker = imsPhone.getCallTracker();
10799 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10800 ImsPhoneCallTracker imsPhoneCallTracker =
10801 (ImsPhoneCallTracker) tracker;
10802 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10803 }
10804 }
10805 }
10806 );
10807 } finally {
10808 Binder.restoreCallingIdentity(identity);
10809 }
10810 }
10811
Tyler Gunn92479152021-01-20 16:30:10 -080010812 /**
Hui Wang761a6682020-10-31 05:12:53 +000010813 * Gets the config of RCS VoLTE single registration enabled for the device.
10814 */
10815 @Override
10816 public boolean getDeviceSingleRegistrationEnabled() {
10817 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10818 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10819 }
10820
10821 /**
10822 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10823 */
10824 @Override
10825 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10826 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10827 "setCarrierSingleRegistrationEnabledOverride");
10828 enforceModifyPermission();
10829
10830 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10831 : Boolean.parseBoolean(enabledStr);
10832 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10833 subId, enabled);
10834 }
10835
10836 /**
10837 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10838 */
10839 @Override
10840 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10841 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10842 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10843 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010844
10845 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010846 * Overrides the ims feature validation result
10847 */
10848 @Override
10849 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10850 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10851 "setImsFeatureValidationOverride");
10852
10853 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10854 : Boolean.parseBoolean(enabledStr);
10855 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10856 subId, enabled);
10857 }
10858
10859 /**
10860 * Gets the ims feature validation override value
10861 */
10862 @Override
10863 public boolean getImsFeatureValidationOverride(int subId) {
10864 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10865 "getImsFeatureValidationOverride");
10866 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10867 }
10868
10869 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010870 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10871 * their mobile plan.
10872 */
10873 @Override
10874 public String getMobileProvisioningUrl() {
10875 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10876 final long identity = Binder.clearCallingIdentity();
10877 try {
10878 return getDefaultPhone().getMobileProvisioningUrl();
10879 } finally {
10880 Binder.restoreCallingIdentity(identity);
10881 }
10882 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010883
James.cf Linbcdf8b32021-01-14 16:44:13 +080010884 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010885 * Get the EAB contact from the EAB database.
10886 */
10887 @Override
10888 public String getContactFromEab(String contact) {
10889 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10890 enforceModifyPermission();
10891 final long identity = Binder.clearCallingIdentity();
10892 try {
10893 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10894 } finally {
10895 Binder.restoreCallingIdentity(identity);
10896 }
10897 }
10898
10899 /**
Calvin Pana1434322021-07-01 19:27:01 +080010900 * Get the EAB capability from the EAB database.
10901 */
10902 @Override
10903 public String getCapabilityFromEab(String contact) {
10904 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10905 enforceModifyPermission();
10906 final long identity = Binder.clearCallingIdentity();
10907 try {
10908 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10909 } finally {
10910 Binder.restoreCallingIdentity(identity);
10911 }
10912 }
10913
10914 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010915 * Remove the EAB contacts from the EAB database.
10916 */
10917 @Override
10918 public int removeContactFromEab(int subId, String contacts) {
10919 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10920 enforceModifyPermission();
10921 final long identity = Binder.clearCallingIdentity();
10922 try {
10923 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10924 } finally {
10925 Binder.restoreCallingIdentity(identity);
10926 }
10927 }
10928
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010929 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010930 public boolean getDeviceUceEnabled() {
10931 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10932 final long identity = Binder.clearCallingIdentity();
10933 try {
10934 return mApp.getDeviceUceEnabled();
10935 } finally {
10936 Binder.restoreCallingIdentity(identity);
10937 }
10938 }
10939
10940 @Override
10941 public void setDeviceUceEnabled(boolean isEnabled) {
10942 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10943 final long identity = Binder.clearCallingIdentity();
10944 try {
10945 mApp.setDeviceUceEnabled(isEnabled);
10946 } finally {
10947 Binder.restoreCallingIdentity(identity);
10948 }
10949 }
10950
Brad Ebinger14d467f2021-02-12 06:18:28 +000010951 /**
10952 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10953 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10954 */
10955 // Used for SHELL command only right now.
10956 @Override
10957 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10958 List<String> featureTags) {
10959 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10960 "addUceRegistrationOverrideShell");
10961 final long identity = Binder.clearCallingIdentity();
10962 try {
10963 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10964 new ArraySet<>(featureTags));
10965 } catch (ImsException e) {
10966 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10967 } finally {
10968 Binder.restoreCallingIdentity(identity);
10969 }
10970 }
10971
10972 /**
10973 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10974 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10975 */
10976 // Used for SHELL command only right now.
10977 @Override
10978 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10979 List<String> featureTags) {
10980 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10981 "removeUceRegistrationOverrideShell");
10982 final long identity = Binder.clearCallingIdentity();
10983 try {
10984 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10985 new ArraySet<>(featureTags));
10986 } catch (ImsException e) {
10987 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10988 } finally {
10989 Binder.restoreCallingIdentity(identity);
10990 }
10991 }
10992
10993 /**
10994 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10995 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10996 */
10997 // Used for SHELL command only right now.
10998 @Override
10999 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11000 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11001 "clearUceRegistrationOverrideShell");
11002 final long identity = Binder.clearCallingIdentity();
11003 try {
11004 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11005 } catch (ImsException e) {
11006 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11007 } finally {
11008 Binder.restoreCallingIdentity(identity);
11009 }
11010 }
11011
11012 /**
11013 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11014 */
11015 // Used for SHELL command only right now.
11016 @Override
11017 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11018 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11019 "getLatestRcsContactUceCapabilityShell");
11020 final long identity = Binder.clearCallingIdentity();
11021 try {
11022 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11023 } catch (ImsException e) {
11024 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11025 } finally {
11026 Binder.restoreCallingIdentity(identity);
11027 }
11028 }
11029
11030 /**
11031 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11032 * device does not have an active PUBLISH.
11033 */
11034 // Used for SHELL command only right now.
11035 @Override
11036 public String getLastUcePidfXmlShell(int subId) {
11037 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11038 final long identity = Binder.clearCallingIdentity();
11039 try {
11040 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11041 } catch (ImsException e) {
11042 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11043 } finally {
11044 Binder.restoreCallingIdentity(identity);
11045 }
11046 }
11047
James.cf Line8713a42021-04-29 16:04:26 +080011048 /**
11049 * Remove UCE requests cannot be sent to the network status.
11050 */
11051 // Used for SHELL command only right now.
11052 @Override
11053 public boolean removeUceRequestDisallowedStatus(int subId) {
11054 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11055 final long identity = Binder.clearCallingIdentity();
11056 try {
11057 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11058 } catch (ImsException e) {
11059 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11060 } finally {
11061 Binder.restoreCallingIdentity(identity);
11062 }
11063 }
11064
James.cf Lin18bb9002021-05-25 01:37:38 +080011065 /**
11066 * Remove UCE requests cannot be sent to the network status.
11067 */
11068 // Used for SHELL command only.
11069 @Override
11070 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11071 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11072 final long identity = Binder.clearCallingIdentity();
11073 try {
11074 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11075 } catch (ImsException e) {
11076 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11077 } finally {
11078 Binder.restoreCallingIdentity(identity);
11079 }
11080 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011081
James.cf Lin4b784aa2021-01-31 03:25:15 +080011082 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011083 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11084 String callingPackage) {
11085 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11086 mApp, subId, "setSignalStrengthUpdateRequest");
11087
11088 final int callingUid = Binder.getCallingUid();
11089 // Verify that tha callingPackage belongs to the calling UID
11090 mApp.getSystemService(AppOpsManager.class)
11091 .checkPackage(callingUid, callingPackage);
11092
Rambo Wang3607f502021-02-01 21:51:40 -080011093 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011094
11095 final long identity = Binder.clearCallingIdentity();
11096 try {
11097 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11098 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11099
11100 if (result instanceof IllegalStateException) {
11101 throw (IllegalStateException) result;
11102 }
11103 } finally {
11104 Binder.restoreCallingIdentity(identity);
11105 }
11106 }
11107
11108 @Override
11109 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11110 String callingPackage) {
11111 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11112 mApp, subId, "clearSignalStrengthUpdateRequest");
11113
11114 final int callingUid = Binder.getCallingUid();
11115 // Verify that tha callingPackage belongs to the calling UID
11116 mApp.getSystemService(AppOpsManager.class)
11117 .checkPackage(callingUid, callingPackage);
11118
11119 final long identity = Binder.clearCallingIdentity();
11120 try {
11121 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11122 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11123
11124 if (result instanceof IllegalStateException) {
11125 throw (IllegalStateException) result;
11126 }
11127 } finally {
11128 Binder.restoreCallingIdentity(identity);
11129 }
11130 }
11131
Rambo Wang3607f502021-02-01 21:51:40 -080011132 private static void validateSignalStrengthUpdateRequest(Context context,
11133 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011134 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11135 // phone/system process do not have further restriction on request
11136 return;
11137 }
11138
11139 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011140 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011141 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011142 context.enforceCallingOrSelfPermission(
11143 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11144 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011145 }
11146
11147 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11148 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11149 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11150 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11151 || info.isEnabled()) {
11152 throw new IllegalArgumentException(
11153 "Only system can set hide fields in SignalThresholdInfo");
11154 }
11155
11156 // Thresholds length for each RAN need in range. This has been validated in
11157 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11158 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11159 final int[] thresholds = info.getThresholds();
11160 Objects.requireNonNull(thresholds);
11161 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11162 || thresholds.length
11163 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11164 throw new IllegalArgumentException(
11165 "thresholds length is out of range: " + thresholds.length);
11166 }
11167 }
11168 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011169
11170 /**
11171 * Gets the current phone capability.
11172 *
11173 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11174 * @return the PhoneCapability which describes the data connection capability of modem.
11175 * It's used to evaluate possible phone config change, for example from single
11176 * SIM device to multi-SIM device.
11177 */
11178 @Override
11179 public PhoneCapability getPhoneCapability() {
11180 enforceReadPrivilegedPermission("getPhoneCapability");
11181 final long identity = Binder.clearCallingIdentity();
11182 try {
11183 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11184 } finally {
11185 Binder.restoreCallingIdentity(identity);
11186 }
11187 }
Michele Berionne5e411512020-11-13 02:36:59 +000011188
11189 /**
11190 * Prepare TelephonyManager for an unattended reboot. The reboot is
11191 * required to be done shortly after the API is invoked.
11192 */
11193 @Override
11194 @TelephonyManager.PrepareUnattendedRebootResult
11195 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011196 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011197 enforceRebootPermission();
11198
11199 final long identity = Binder.clearCallingIdentity();
11200 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011201 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011202 } finally {
11203 Binder.restoreCallingIdentity(identity);
11204 }
11205 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011206
11207 /**
11208 * Request to get the current slicing configuration including URSP rules and
11209 * NSSAIs (configured, allowed and rejected).
11210 *
11211 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11212 */
11213 @Override
11214 public void getSlicingConfig(ResultReceiver callback) {
11215 enforceReadPrivilegedPermission("getSlicingConfig");
11216
11217 final long identity = Binder.clearCallingIdentity();
11218 try {
11219 Phone phone = getDefaultPhone();
11220 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11221 } finally {
11222 Binder.restoreCallingIdentity(identity);
11223 }
11224 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011225
11226 /**
11227 * Register an IMS connection state callback
11228 */
11229 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011230 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11231 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011232 if (feature == ImsFeature.FEATURE_MMTEL) {
11233 // ImsMmTelManager
11234 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11235 TelephonyPermissions
11236 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11237 mApp, subId, "registerImsStateCallback");
11238 } else if (feature == ImsFeature.FEATURE_RCS) {
11239 // ImsRcsManager or SipDelegateManager
11240 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11241 Binder.getCallingUid(), "registerImsStateCallback",
11242 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11243 Manifest.permission.READ_PRECISE_PHONE_STATE,
11244 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11245 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11246 }
11247
11248 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11249 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11250 "IMS not available on device.");
11251 }
11252
11253 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11254 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11255 }
11256
11257 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11258 if (controller == null) {
11259 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11260 "IMS not available on device.");
11261 }
11262
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011263 if (callingPackage == null) {
11264 callingPackage = getCurrentPackageName();
11265 }
11266
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011267 final long token = Binder.clearCallingIdentity();
11268 try {
11269 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011270 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011271 } catch (ImsException e) {
11272 throw new ServiceSpecificException(e.getCode());
11273 } finally {
11274 Binder.restoreCallingIdentity(token);
11275 }
11276 }
11277
11278 /**
11279 * Unregister an IMS connection state callback
11280 */
11281 @Override
11282 public void unregisterImsStateCallback(IImsStateCallback cb) {
11283 final long token = Binder.clearCallingIdentity();
11284 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11285 if (controller == null) {
11286 return;
11287 }
11288 try {
11289 controller.unregisterImsStateCallback(cb);
11290 } finally {
11291 Binder.restoreCallingIdentity(token);
11292 }
11293 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011294
11295 /**
11296 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11297 *
11298 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11299 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11300 * SecurityException.
11301 * If there is current registered network this value will be same as the registered cell
11302 * identity. If the device goes out of service the previous cell identity is cached and
11303 * will be returned. If the cache age of the Cell identity is more than 24 hours
11304 * it will be cleared and null will be returned.
11305 *
11306 */
11307 @Override
11308 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11309 String callingFeatureId) {
11310 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11311 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11312 LocationAccessPolicy.checkLocationPermission(mApp,
11313 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11314 .setCallingPackage(callingPackage)
11315 .setCallingFeatureId(callingFeatureId)
11316 .setCallingPid(Binder.getCallingPid())
11317 .setCallingUid(Binder.getCallingUid())
11318 .setMethod("getLastKnownCellIdentity")
11319 .setLogAsInfo(true)
11320 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11321 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11322 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11323 .build());
11324
11325 boolean hasFinePermission =
11326 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11327 if (!hasFinePermission
11328 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11329 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
11330 + "and BIND_CONNECTION_SERVICE permission.");
11331 }
11332
11333 final long identity = Binder.clearCallingIdentity();
11334 try {
11335 Phone phone = getPhone(subId);
11336 if (phone == null) return null;
11337 ServiceStateTracker sst = phone.getServiceStateTracker();
11338 if (sst == null) return null;
11339 return sst.getLastKnownCellIdentity();
11340 } finally {
11341 Binder.restoreCallingIdentity(identity);
11342 }
11343 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011344
11345 @Override
11346 public boolean isUsingNewDataStack() {
11347 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "isUsingNewDataStack");
11348 return getDefaultPhone().isUsingNewDataStack();
11349 }
jimsun3b9ccac2021-10-26 15:01:23 +080011350
11351 /**
11352 * Sets the modem service class Name that Telephony will bind to.
11353 *
11354 * @param serviceName The class name of the modem service.
11355 * @return true if the operation is succeed, otherwise false.
11356 */
11357 public boolean setModemService(String serviceName) {
11358 Log.d(LOG_TAG, "setModemService - " + serviceName);
11359 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11360 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11361 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11362 "setModemService");
11363 return mPhoneConfigurationManager.setModemService(serviceName);
11364 }
11365
11366 /**
11367 * Return the class name of the currently bounded modem service.
11368 *
11369 * @return the class name of the modem service.
11370 */
11371 public String getModemService() {
11372 String result;
11373 Log.d(LOG_TAG, "getModemService");
11374 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11375 TelephonyPermissions
11376 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11377 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11378 "getModemService");
11379 result = mPhoneConfigurationManager.getModemService();
11380 Log.d(LOG_TAG, "result = " + result);
11381 return result;
11382 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011383}