blob: c988cbf849721274ee1217f58abf22f94d36f8ac [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;
SongFerngWangebda2c52022-01-11 15:28:38 +08001262 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001263 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)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001270 callWaitingStatus = 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 {
SongFerngWangebda2c52022-01-11 15:28:38 +08001274 callWaitingStatus = 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) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001287 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001288 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001289 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1290 callWaitingStatus =
1291 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001292 }
1293 }
1294 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001295 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001296 break;
Hall Liu27d24262020-09-18 19:04:59 -07001297 }
Shuo Qian4a594052020-01-23 11:59:30 -08001298
Hall Liu27d24262020-09-18 19:04:59 -07001299 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001300 request = (MainThreadRequest) msg.obj;
1301 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001302 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1303 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001304 break;
Hall Liu27d24262020-09-18 19:04:59 -07001305 }
Shuo Qian4a594052020-01-23 11:59:30 -08001306
Hall Liu27d24262020-09-18 19:04:59 -07001307 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001308 ar = (AsyncResult) msg.obj;
1309 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001310 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1311 Consumer<Integer> callback =
1312 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1313 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001314 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001315 if (ar.exception instanceof CommandException) {
1316 CommandException.Error error =
1317 ((CommandException) (ar.exception)).getCommandError();
1318 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1319 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001320 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1321 callback.accept(
1322 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001323 } else {
1324 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1325 }
1326 } else {
1327 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1328 }
1329 } else {
1330 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1331 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001332 }
Shuo Qian4a594052020-01-23 11:59:30 -08001333 break;
Hall Liu27d24262020-09-18 19:04:59 -07001334 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001335 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1336 ar = (AsyncResult) msg.obj;
1337 request = (MainThreadRequest) ar.userObj;
1338 CellNetworkScanResult cellScanResult;
1339 if (ar.exception == null && ar.result != null) {
1340 cellScanResult = new CellNetworkScanResult(
1341 CellNetworkScanResult.STATUS_SUCCESS,
1342 (List<OperatorInfo>) ar.result);
1343 } else {
1344 if (ar.result == null) {
1345 loge("getCellNetworkScanResults: Empty response");
1346 }
1347 if (ar.exception != null) {
1348 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1349 }
1350 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1351 if (ar.exception instanceof CommandException) {
1352 CommandException.Error error =
1353 ((CommandException) (ar.exception)).getCommandError();
1354 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1355 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1356 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1357 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1358 }
1359 }
1360 cellScanResult = new CellNetworkScanResult(errorCode, null);
1361 }
1362 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001363 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001364 break;
1365
1366 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1367 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001368 ManualNetworkSelectionArgument selArg =
1369 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001370 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1371 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001372 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1373 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001374 break;
1375
1376 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001377 ar = (AsyncResult) msg.obj;
1378 request = (MainThreadRequest) ar.userObj;
1379 if (ar.exception == null) {
1380 request.result = true;
1381 } else {
1382 request.result = false;
1383 loge("setNetworkSelectionModeManual " + ar.exception);
1384 }
1385 notifyRequester(request);
1386 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001387 break;
1388
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001389 case CMD_GET_MODEM_ACTIVITY_INFO:
1390 request = (MainThreadRequest) msg.obj;
1391 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001392 if (defaultPhone != null) {
1393 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001394 } else {
1395 ResultReceiver result = (ResultReceiver) request.argument;
1396 Bundle bundle = new Bundle();
1397 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001398 new ModemActivityInfo(0, 0, 0,
1399 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001400 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001401 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001402 break;
1403
Hall Liud0f208c2020-10-14 16:54:44 -07001404 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001405 ar = (AsyncResult) msg.obj;
1406 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001407 ResultReceiver result = (ResultReceiver) request.argument;
1408
Hall Liud0f208c2020-10-14 16:54:44 -07001409 ModemActivityInfo ret = null;
1410 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001411 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001412 // Update the last modem activity info and the result of the request.
1413 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1414 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001415 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001416 int[] txTimeMs = info.getTransmitTimeMillis();
1417 int[] lastModemTxTimeMs = mLastModemActivityInfo
1418 .getTransmitTimeMillis();
1419 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1420 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1421 }
Hall Liu49656c02020-10-09 19:00:11 -07001422 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001423 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1424 + mLastModemActivityInfo.getSleepTimeMillis());
1425 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1426 + mLastModemActivityInfo.getIdleTimeMillis());
1427 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1428 mLastModemActivityInfo.setReceiveTimeMillis(
1429 info.getReceiveTimeMillis()
1430 + mLastModemActivityInfo.getReceiveTimeMillis());
1431 }
Hall Liu49656c02020-10-09 19:00:11 -07001432 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001433 mLastModemActivityInfo.getSleepTimeMillis(),
1434 mLastModemActivityInfo.getIdleTimeMillis(),
1435 mLastModemActivityInfo.getTransmitTimeMillis(),
1436 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001437 } else {
1438 if (ar.result == null) {
1439 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001440 error = TelephonyManager.ModemActivityInfoException
1441 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001442 } else if (ar.exception instanceof CommandException) {
1443 loge("queryModemActivityInfo: CommandException: " +
1444 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001445 error = TelephonyManager.ModemActivityInfoException
1446 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001447 } else {
1448 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001449 error = TelephonyManager.ModemActivityInfoException
1450 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001451 }
1452 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001453 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001454 if (ret != null) {
1455 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1456 } else {
1457 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1458 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001459 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001460 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001461 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001462 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001463
Meng Wang1a7c35a2016-05-05 20:56:15 -07001464 case CMD_SET_ALLOWED_CARRIERS:
1465 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001466 CarrierRestrictionRules argument =
1467 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001468 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001469 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001470 break;
1471
1472 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1473 ar = (AsyncResult) msg.obj;
1474 request = (MainThreadRequest) ar.userObj;
1475 if (ar.exception == null && ar.result != null) {
1476 request.result = ar.result;
1477 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001478 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1479 if (ar.exception instanceof CommandException) {
1480 loge("setAllowedCarriers: CommandException: " + ar.exception);
1481 CommandException.Error error =
1482 ((CommandException) (ar.exception)).getCommandError();
1483 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1484 request.result =
1485 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1486 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001487 } else {
1488 loge("setAllowedCarriers: Unknown exception");
1489 }
1490 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001491 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001492 break;
1493
1494 case CMD_GET_ALLOWED_CARRIERS:
1495 request = (MainThreadRequest) msg.obj;
1496 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001497 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001498 break;
1499
1500 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1501 ar = (AsyncResult) msg.obj;
1502 request = (MainThreadRequest) ar.userObj;
1503 if (ar.exception == null && ar.result != null) {
1504 request.result = ar.result;
1505 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001506 request.result = new IllegalStateException(
1507 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001508 if (ar.result == null) {
1509 loge("getAllowedCarriers: Empty response");
1510 } else if (ar.exception instanceof CommandException) {
1511 loge("getAllowedCarriers: CommandException: " +
1512 ar.exception);
1513 } else {
1514 loge("getAllowedCarriers: Unknown exception");
1515 }
1516 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001517 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001518 break;
1519
Nathan Haroldb3014052017-01-25 15:57:32 -08001520 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1521 ar = (AsyncResult) msg.obj;
1522 request = (MainThreadRequest) ar.userObj;
1523 if (ar.exception == null && ar.result != null) {
1524 request.result = ar.result;
1525 } else {
1526 request.result = new IllegalArgumentException(
1527 "Failed to retrieve Forbidden Plmns");
1528 if (ar.result == null) {
1529 loge("getForbiddenPlmns: Empty response");
1530 } else {
1531 loge("getForbiddenPlmns: Unknown exception");
1532 }
1533 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001534 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001535 break;
1536
1537 case CMD_GET_FORBIDDEN_PLMNS:
1538 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001539 uiccPort = getUiccPortFromRequest(request);
1540 if (uiccPort == null) {
1541 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001542 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001543 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001544 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001545 break;
1546 }
1547 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001548 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001549 if (uiccApp == null) {
1550 loge("getForbiddenPlmns() no app with specified type -- "
1551 + appType);
1552 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001553 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001554 break;
1555 } else {
1556 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1557 + " specified type -- " + appType);
1558 }
1559 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1560 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1561 onCompleted);
1562 break;
1563
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001564 case CMD_SWITCH_SLOTS:
1565 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001566 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001567 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001568 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001569 break;
1570
1571 case EVENT_SWITCH_SLOTS_DONE:
1572 ar = (AsyncResult) msg.obj;
1573 request = (MainThreadRequest) ar.userObj;
1574 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001575 notifyRequester(request);
1576 break;
1577 case CMD_GET_NETWORK_SELECTION_MODE:
1578 request = (MainThreadRequest) msg.obj;
1579 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1580 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1581 break;
1582
1583 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1584 ar = (AsyncResult) msg.obj;
1585 request = (MainThreadRequest) ar.userObj;
1586 if (ar.exception != null) {
1587 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1588 } else {
1589 int mode = ((int[]) ar.result)[0];
1590 if (mode == 0) {
1591 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1592 } else {
1593 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1594 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001595 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001596 notifyRequester(request);
1597 break;
1598 case CMD_GET_CDMA_ROAMING_MODE:
1599 request = (MainThreadRequest) msg.obj;
1600 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1601 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1602 break;
1603 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1604 ar = (AsyncResult) msg.obj;
1605 request = (MainThreadRequest) ar.userObj;
1606 if (ar.exception != null) {
1607 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1608 } else {
1609 request.result = ((int[]) ar.result)[0];
1610 }
1611 notifyRequester(request);
1612 break;
1613 case CMD_SET_CDMA_ROAMING_MODE:
1614 request = (MainThreadRequest) msg.obj;
1615 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1616 int mode = (int) request.argument;
1617 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1618 break;
1619 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1620 ar = (AsyncResult) msg.obj;
1621 request = (MainThreadRequest) ar.userObj;
1622 request.result = ar.exception == null;
1623 notifyRequester(request);
1624 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001625 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1626 request = (MainThreadRequest) msg.obj;
1627 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1628 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1629 break;
1630 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1631 ar = (AsyncResult) msg.obj;
1632 request = (MainThreadRequest) ar.userObj;
1633 if (ar.exception != null) {
1634 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1635 } else {
1636 request.result = ((int[]) ar.result)[0];
1637 }
1638 notifyRequester(request);
1639 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001640 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1641 request = (MainThreadRequest) msg.obj;
1642 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1643 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001644 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1645 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001646 break;
1647 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1648 ar = (AsyncResult) msg.obj;
1649 request = (MainThreadRequest) ar.userObj;
1650 request.result = ar.exception == null;
1651 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001652 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001653 case CMD_GET_ALL_CELL_INFO:
1654 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001655 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001656 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001657 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001658 case EVENT_GET_ALL_CELL_INFO_DONE:
1659 ar = (AsyncResult) msg.obj;
1660 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001661 // If a timeout occurs, the response will be null
1662 request.result = (ar.exception == null && ar.result != null)
1663 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001664 synchronized (request) {
1665 request.notifyAll();
1666 }
1667 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001668 case CMD_REQUEST_CELL_INFO_UPDATE:
1669 request = (MainThreadRequest) msg.obj;
1670 request.phone.requestCellInfoUpdate(request.workSource,
1671 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1672 break;
1673 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1674 ar = (AsyncResult) msg.obj;
1675 request = (MainThreadRequest) ar.userObj;
1676 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1677 try {
1678 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001679 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001680 cb.onError(
1681 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1682 ar.exception.getClass().getName(),
1683 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001684 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001685 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001686 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001687 } else {
1688 // use the result as returned
1689 cb.onCellInfo((List<CellInfo>) ar.result);
1690 }
1691 } catch (RemoteException re) {
1692 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1693 }
1694 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001695 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001696 request = (MainThreadRequest) msg.obj;
1697 WorkSource ws = (WorkSource) request.argument;
1698 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001699 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001700 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001701 }
1702 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001703 ar = (AsyncResult) msg.obj;
1704 request = (MainThreadRequest) ar.userObj;
1705 if (ar.exception == null) {
1706 request.result = ar.result;
1707 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001708 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001709 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001710 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001711 }
1712
1713 synchronized (request) {
1714 request.notifyAll();
1715 }
1716 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001717 }
chen xu6dac5ab2018-10-26 17:39:23 -07001718 case CMD_MODEM_REBOOT:
1719 request = (MainThreadRequest) msg.obj;
1720 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001721 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001722 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001723 case EVENT_CMD_MODEM_REBOOT_DONE:
1724 handleNullReturnEvent(msg, "rebootModem");
1725 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001726 case CMD_REQUEST_ENABLE_MODEM:
1727 request = (MainThreadRequest) msg.obj;
1728 boolean enable = (boolean) request.argument;
1729 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001730 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001731 PhoneConfigurationManager.getInstance()
1732 .enablePhone(request.phone, enable, onCompleted);
1733 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001734 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001735 ar = (AsyncResult) msg.obj;
1736 request = (MainThreadRequest) ar.userObj;
1737 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001738 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001739 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001740 if ((boolean) request.result) {
1741 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1742 updateModemStateMetrics();
1743 } else {
1744 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1745 + ar.exception);
1746 }
1747 notifyRequester(request);
1748 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001749 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001750 case CMD_GET_MODEM_STATUS:
1751 request = (MainThreadRequest) msg.obj;
1752 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1753 PhoneConfigurationManager.getInstance()
1754 .getPhoneStatusFromModem(request.phone, onCompleted);
1755 break;
1756 case EVENT_GET_MODEM_STATUS_DONE:
1757 ar = (AsyncResult) msg.obj;
1758 request = (MainThreadRequest) ar.userObj;
1759 int id = request.phone.getPhoneId();
1760 if (ar.exception == null && ar.result != null) {
1761 request.result = ar.result;
1762 //update the cache as modem status has changed
1763 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1764 (boolean) request.result);
1765 } else {
1766 // Return true if modem status cannot be retrieved. For most cases,
1767 // modem status is on. And for older version modems, GET_MODEM_STATUS
1768 // and disable modem are not supported. Modem is always on.
1769 // TODO: this should be fixed in R to support a third
1770 // status UNKNOWN b/131631629
1771 request.result = true;
1772 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1773 + ar.exception);
1774 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001775 notifyRequester(request);
1776 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001777 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1778 request = (MainThreadRequest) msg.obj;
1779 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1780 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1781 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1782 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1783 break;
1784 }
1785 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1786 ar = (AsyncResult) msg.obj;
1787 request = (MainThreadRequest) ar.userObj;
1788 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1789 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1790 args.second.accept(ar.exception == null);
1791 notifyRequester(request);
1792 break;
1793 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001794 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1795 request = (MainThreadRequest) msg.obj;
1796 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1797 Phone phone = getPhoneFromRequest(request);
1798 if (phone != null) {
1799 phone.getSystemSelectionChannels(onCompleted);
1800 } else {
1801 loge("getSystemSelectionChannels: No phone object");
1802 request.result = new ArrayList<RadioAccessSpecifier>();
1803 notifyRequester(request);
1804 }
1805 break;
1806 }
1807 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1808 ar = (AsyncResult) msg.obj;
1809 request = (MainThreadRequest) ar.userObj;
1810 if (ar.exception == null && ar.result != null) {
1811 request.result = ar.result;
1812 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001813 request.result = new IllegalStateException(
1814 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001815 if (ar.result == null) {
1816 loge("getSystemSelectionChannels: Empty response");
1817 } else {
1818 loge("getSystemSelectionChannels: Unknown exception");
1819 }
1820 }
1821 notifyRequester(request);
1822 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001823 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1824 ar = (AsyncResult) msg.obj;
1825 request = (MainThreadRequest) ar.userObj;
1826 if (ar.exception == null && ar.result != null) {
1827 request.result = ar.result;
1828 } else {
1829 request.result = -1;
1830 loge("Failed to set Forbidden Plmns");
1831 if (ar.result == null) {
1832 loge("setForbidenPlmns: Empty response");
1833 } else if (ar.exception != null) {
1834 loge("setForbiddenPlmns: Exception: " + ar.exception);
1835 request.result = -1;
1836 } else {
1837 loge("setForbiddenPlmns: Unknown exception");
1838 }
1839 }
1840 notifyRequester(request);
1841 break;
1842 case CMD_SET_FORBIDDEN_PLMNS:
1843 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001844 uiccPort = getUiccPortFromRequest(request);
1845 if (uiccPort == null) {
1846 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001847 request.result = -1;
1848 notifyRequester(request);
1849 break;
1850 }
1851 Pair<Integer, List<String>> setFplmnsArgs =
1852 (Pair<Integer, List<String>>) request.argument;
1853 appType = setFplmnsArgs.first;
1854 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001855 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001856 if (uiccApp == null) {
1857 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1858 request.result = -1;
1859 loge("Failed to get UICC App");
1860 notifyRequester(request);
1861 } else {
1862 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1863 ((SIMRecords) uiccApp.getIccRecords())
1864 .setForbiddenPlmns(onCompleted, fplmns);
1865 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001866 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001867 case CMD_ERASE_MODEM_CONFIG:
1868 request = (MainThreadRequest) msg.obj;
1869 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1870 defaultPhone.eraseModemConfig(onCompleted);
1871 break;
1872 case EVENT_ERASE_MODEM_CONFIG_DONE:
1873 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001874 break;
zoey chene02881a2019-12-30 16:11:23 +08001875
Kai Shif70f46f2021-03-03 13:59:46 -08001876 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1877 request = (MainThreadRequest) msg.obj;
1878 request.result = defaultPhone.eraseDataInSharedPreferences();
1879 notifyRequester(request);
1880 break;
1881
zoey chene02881a2019-12-30 16:11:23 +08001882 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1883 request = (MainThreadRequest) msg.obj;
1884 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1885 Pair<String, String> changed = (Pair<String, String>) request.argument;
1886 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1887 changed.first, changed.second, onCompleted);
1888 break;
1889 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1890 ar = (AsyncResult) msg.obj;
1891 request = (MainThreadRequest) ar.userObj;
1892 if (ar.exception == null) {
1893 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001894 // If the operation is successful, update the PIN storage
1895 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1896 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001897 UiccController.getInstance().getPinStorage()
1898 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001899 } else {
1900 request.result = msg.arg1;
1901 }
1902 notifyRequester(request);
1903 break;
1904
Michele Berionne5e411512020-11-13 02:36:59 +00001905 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001906 request = (MainThreadRequest) msg.obj;
1907 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1908 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1909 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1910 enabled.first, enabled.second, onCompleted);
1911 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001912 }
zoey chene02881a2019-12-30 16:11:23 +08001913 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1914 ar = (AsyncResult) msg.obj;
1915 request = (MainThreadRequest) ar.userObj;
1916 if (ar.exception == null) {
1917 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001918 // If the operation is successful, update the PIN storage
1919 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1920 int phoneId = getPhoneFromRequest(request).getPhoneId();
1921 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001922 UiccController.getInstance().getPinStorage()
1923 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001924 } else {
1925 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1926 }
zoey chene02881a2019-12-30 16:11:23 +08001927 } else {
1928 request.result = msg.arg1;
1929 }
Michele Berionne5e411512020-11-13 02:36:59 +00001930
1931
zoey chene02881a2019-12-30 16:11:23 +08001932 notifyRequester(request);
1933 break;
1934
Peter Wangdafb9ac2020-01-15 14:13:38 -08001935 case MSG_NOTIFY_USER_ACTIVITY:
1936 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001937 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001938 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1939 getDefaultPhone().getContext().sendBroadcastAsUser(
1940 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1941 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001942
1943 case CMD_SET_DATA_THROTTLING: {
1944 request = (MainThreadRequest) msg.obj;
1945 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1946 DataThrottlingRequest dataThrottlingRequest =
1947 (DataThrottlingRequest) request.argument;
1948 Phone phone = getPhoneFromRequest(request);
1949 if (phone != null) {
1950 phone.setDataThrottling(onCompleted,
1951 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1952 dataThrottlingRequest.getCompletionDurationMillis());
1953 } else {
1954 loge("setDataThrottling: No phone object");
1955 request.result =
1956 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1957 notifyRequester(request);
1958 }
1959
1960 break;
1961 }
1962 case EVENT_SET_DATA_THROTTLING_DONE:
1963 ar = (AsyncResult) msg.obj;
1964 request = (MainThreadRequest) ar.userObj;
1965
1966 if (ar.exception == null) {
1967 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1968 } else if (ar.exception instanceof CommandException) {
1969 loge("setDataThrottling: CommandException: " + ar.exception);
1970 CommandException.Error error =
1971 ((CommandException) (ar.exception)).getCommandError();
1972
1973 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1974 request.result = TelephonyManager
1975 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1976 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1977 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001978 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1979 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001980 } else {
1981 request.result =
1982 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1983 }
1984 } else {
1985 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1986 }
1987 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1988 notifyRequester(request);
1989 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001990
1991 case CMD_SET_SIM_POWER: {
1992 request = (MainThreadRequest) msg.obj;
1993 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1994 request = (MainThreadRequest) msg.obj;
1995 int stateToSet =
1996 ((Pair<Integer, IIntegerConsumer>)
1997 request.argument).first;
1998 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1999 break;
2000 }
2001 case EVENT_SET_SIM_POWER_DONE: {
2002 ar = (AsyncResult) msg.obj;
2003 request = (MainThreadRequest) ar.userObj;
2004 IIntegerConsumer callback =
2005 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2006 if (ar.exception != null) {
2007 loge("setSimPower exception: " + ar.exception);
2008 int errorCode = TelephonyManager.CallForwardingInfoCallback
2009 .RESULT_ERROR_UNKNOWN;
2010 if (ar.exception instanceof CommandException) {
2011 CommandException.Error error =
2012 ((CommandException) (ar.exception)).getCommandError();
2013 if (error == CommandException.Error.SIM_ERR) {
2014 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2015 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2016 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2017 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2018 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2019 } else {
2020 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2021 }
2022 }
2023 try {
2024 callback.accept(errorCode);
2025 } catch (RemoteException e) {
2026 // Ignore if the remote process is no longer available to call back.
2027 Log.w(LOG_TAG, "setSimPower: callback not available.");
2028 }
2029 } else {
2030 try {
2031 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2032 } catch (RemoteException e) {
2033 // Ignore if the remote process is no longer available to call back.
2034 Log.w(LOG_TAG, "setSimPower: callback not available.");
2035 }
2036 }
2037 break;
2038 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002039 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2040 request = (MainThreadRequest) msg.obj;
2041
2042 final Phone phone = getPhoneFromRequest(request);
2043 if (phone == null || phone.getServiceStateTracker() == null) {
2044 request.result = new IllegalStateException("Phone or SST is null");
2045 notifyRequester(request);
2046 break;
2047 }
2048
2049 Pair<Integer, SignalStrengthUpdateRequest> pair =
2050 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2051 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2052 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002053 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002054 request.subId, pair.first /*callingUid*/,
2055 pair.second /*request*/, onCompleted);
2056 break;
2057 }
2058 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2059 ar = (AsyncResult) msg.obj;
2060 request = (MainThreadRequest) ar.userObj;
2061 // request.result will be the exception of ar if present, true otherwise.
2062 // Be cautious not to leave result null which will wait() forever
2063 request.result = ar.exception != null ? ar.exception : true;
2064 notifyRequester(request);
2065 break;
2066 }
2067 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2068 request = (MainThreadRequest) msg.obj;
2069
2070 Phone phone = getPhoneFromRequest(request);
2071 if (phone == null || phone.getServiceStateTracker() == null) {
2072 request.result = new IllegalStateException("Phone or SST is null");
2073 notifyRequester(request);
2074 break;
2075 }
2076
2077 Pair<Integer, SignalStrengthUpdateRequest> pair =
2078 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2079 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2080 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002081 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002082 request.subId, pair.first /*callingUid*/,
2083 pair.second /*request*/, onCompleted);
2084 break;
2085 }
2086 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2087 ar = (AsyncResult) msg.obj;
2088 request = (MainThreadRequest) ar.userObj;
2089 request.result = ar.exception != null ? ar.exception : true;
2090 notifyRequester(request);
2091 break;
2092 }
Jordan Liu109698e2020-11-24 14:50:34 -08002093
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002094 case CMD_GET_SLICING_CONFIG: {
2095 request = (MainThreadRequest) msg.obj;
2096 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2097 request.phone.getSlicingConfig(onCompleted);
2098 break;
2099 }
2100 case EVENT_GET_SLICING_CONFIG_DONE: {
2101 ar = (AsyncResult) msg.obj;
2102 request = (MainThreadRequest) ar.userObj;
2103 ResultReceiver result = (ResultReceiver) request.argument;
2104
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002105 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002106 Bundle bundle = new Bundle();
2107 int resultCode = 0;
2108 if (ar.exception != null) {
2109 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2110 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002111 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002112 } else if (ar.result == null) {
2113 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002114 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002115 } else {
2116 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002117 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2118 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002119 }
2120
2121 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002122 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002123 }
2124 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2125 result.send(resultCode, bundle);
2126 notifyRequester(request);
2127 break;
2128 }
2129
Michele Berionne5e411512020-11-13 02:36:59 +00002130 case CMD_PREPARE_UNATTENDED_REBOOT:
2131 request = (MainThreadRequest) msg.obj;
2132 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002133 UiccController.getInstance().getPinStorage()
2134 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002135 notifyRequester(request);
2136 break;
2137
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002138 default:
2139 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2140 break;
2141 }
2142 }
Jake Hambye994d462014-02-03 13:10:13 -08002143
Pengquan Menga1bb6272018-09-06 09:59:22 -07002144 private void notifyRequester(MainThreadRequest request) {
2145 synchronized (request) {
2146 request.notifyAll();
2147 }
2148 }
2149
Jake Hambye994d462014-02-03 13:10:13 -08002150 private void handleNullReturnEvent(Message msg, String command) {
2151 AsyncResult ar = (AsyncResult) msg.obj;
2152 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2153 if (ar.exception == null) {
2154 request.result = true;
2155 } else {
2156 request.result = false;
2157 if (ar.exception instanceof CommandException) {
2158 loge(command + ": CommandException: " + ar.exception);
2159 } else {
2160 loge(command + ": Unknown exception");
2161 }
2162 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002163 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002164 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002165 }
2166
2167 /**
2168 * Posts the specified command to be executed on the main thread,
2169 * waits for the request to complete, and returns the result.
2170 * @see #sendRequestAsync
2171 */
2172 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002173 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2174 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002175 }
2176
2177 /**
2178 * Posts the specified command to be executed on the main thread,
2179 * waits for the request to complete, and returns the result.
2180 * @see #sendRequestAsync
2181 */
2182 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2183 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002184 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002185 }
2186
2187 /**
2188 * Posts the specified command to be executed on the main thread,
2189 * waits for the request to complete, and returns the result.
2190 * @see #sendRequestAsync
2191 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002192 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002193 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2194 }
2195
2196 /**
2197 * Posts the specified command to be executed on the main thread,
2198 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2199 * if not timeout or null otherwise.
2200 * @see #sendRequestAsync
2201 */
2202 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2203 long timeoutInMs) {
2204 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002205 }
2206
2207 /**
2208 * Posts the specified command to be executed on the main thread,
2209 * waits for the request to complete, and returns the result.
2210 * @see #sendRequestAsync
2211 */
Nathan Harold92bed182018-10-12 18:16:49 -07002212 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002213 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002214 }
2215
2216 /**
2217 * Posts the specified command to be executed on the main thread,
2218 * waits for the request to complete, and returns the result.
2219 * @see #sendRequestAsync
2220 */
2221 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002222 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2223 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002224 }
2225
2226 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002227 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2228 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2229 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002230 * @see #sendRequestAsync
2231 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002232 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2233 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002234 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2235 throw new RuntimeException("This method will deadlock if called from the main thread.");
2236 }
2237
Nathan Harold92bed182018-10-12 18:16:49 -07002238 MainThreadRequest request = null;
2239 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2240 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2241 } else if (phone != null) {
2242 request = new MainThreadRequest(argument, phone, workSource);
2243 } else {
2244 request = new MainThreadRequest(argument, subId, workSource);
2245 }
2246
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002247 Message msg = mMainThreadHandler.obtainMessage(command, request);
2248 msg.sendToTarget();
2249
Rambo Wang0f050d82021-02-12 11:43:36 -08002250
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002251 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002252 if (timeoutInMs >= 0) {
2253 // Wait for at least timeoutInMs before returning null request result
2254 long now = SystemClock.elapsedRealtime();
2255 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002256 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002257 try {
2258 request.wait(deadline - now);
2259 } catch (InterruptedException e) {
2260 // Do nothing, go back and check if request is completed or timeout
2261 } finally {
2262 now = SystemClock.elapsedRealtime();
2263 }
2264 }
2265 } else {
2266 // Wait for the request to complete
2267 while (request.result == null) {
2268 try {
2269 request.wait();
2270 } catch (InterruptedException e) {
2271 // Do nothing, go back and wait until the request is complete
2272 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002273 }
2274 }
2275 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002276 if (request.result == null) {
2277 Log.wtf(LOG_TAG,
2278 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2279 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002280 return request.result;
2281 }
2282
2283 /**
2284 * Asynchronous ("fire and forget") version of sendRequest():
2285 * Posts the specified command to be executed on the main thread, and
2286 * returns immediately.
2287 * @see #sendRequest
2288 */
2289 private void sendRequestAsync(int command) {
2290 mMainThreadHandler.sendEmptyMessage(command);
2291 }
2292
2293 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002294 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002295 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002296 */
2297 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002298 sendRequestAsync(command, argument, null, null);
2299 }
2300
2301 /**
2302 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2303 * @see {@link #sendRequest(int,Object)}
2304 */
2305 private void sendRequestAsync(
2306 int command, Object argument, Phone phone, WorkSource workSource) {
2307 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002308 Message msg = mMainThreadHandler.obtainMessage(command, request);
2309 msg.sendToTarget();
2310 }
2311
2312 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002313 * Initialize the singleton PhoneInterfaceManager instance.
2314 * This is only done once, at startup, from PhoneApp.onCreate().
2315 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002316 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002317 synchronized (PhoneInterfaceManager.class) {
2318 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002319 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002320 } else {
2321 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2322 }
2323 return sInstance;
2324 }
2325 }
2326
2327 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002328 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002329 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002330 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002331 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002332 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002333 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002334 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002335 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002336 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002337 mTelephonySharedPreferences =
2338 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002339 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002340 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002341 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002342 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002343
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002344 publish();
2345 }
2346
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002347 private Phone getDefaultPhone() {
2348 Phone thePhone = getPhone(getDefaultSubscription());
2349 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2350 }
2351
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002352 private void publish() {
2353 if (DBG) log("publish: " + this);
2354
Peter Wangc035ce42020-01-08 21:00:22 -08002355 TelephonyFrameworkInitializer
2356 .getTelephonyServiceManager()
2357 .getTelephonyServiceRegisterer()
2358 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002359 }
2360
Stuart Scott584921c2015-01-15 17:10:34 -08002361 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002362 if (request.phone != null) {
2363 return request.phone;
2364 } else {
2365 return getPhoneFromSubId(request.subId);
2366 }
2367 }
2368
2369 private Phone getPhoneFromSubId(int subId) {
2370 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2371 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002372 }
2373
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002374 private UiccPort getUiccPortFromRequest(MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002375 Phone phone = getPhoneFromRequest(request);
2376 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002377 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002378 }
2379
Wink Saville36469e72014-06-11 15:17:00 -07002380 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002381 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002382 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002383 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002384
Kai Shif70f46f2021-03-03 13:59:46 -08002385 private void sendEraseModemConfig(@NonNull Phone phone) {
2386 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2387 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2388 }
2389
2390 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2391 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2392 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002393 }
2394
Peter Wang44b186e2020-01-13 23:33:09 -08002395 private boolean isImsAvailableOnDevice() {
2396 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2397 if (pm == null) {
2398 // For some reason package manger is not available.. This will fail internally anyway,
2399 // so do not throw error and allow.
2400 return true;
2401 }
2402 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2403 }
2404
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002405 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002406 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002407 }
2408
Wink Savilleb564aae2014-10-23 10:18:09 -07002409 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002410 if (DBG) log("dial: " + number);
2411 // No permission check needed here: This is just a wrapper around the
2412 // ACTION_DIAL intent, which is available to any app since it puts up
2413 // the UI before it does anything.
2414
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002415 final long identity = Binder.clearCallingIdentity();
2416 try {
2417 String url = createTelUrl(number);
2418 if (url == null) {
2419 return;
2420 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002421
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002422 // PENDING: should we just silently fail if phone is offhook or ringing?
2423 PhoneConstants.State state = mCM.getState(subId);
2424 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2425 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2426 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2427 mApp.startActivity(intent);
2428 }
2429 } finally {
2430 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002431 }
2432 }
2433
2434 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002435 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002436 }
2437
Wink Savilleb564aae2014-10-23 10:18:09 -07002438 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002439 if (DBG) log("call: " + number);
2440
2441 // This is just a wrapper around the ACTION_CALL intent, but we still
2442 // need to do a permission check since we're calling startActivity()
2443 // from the context of the phone app.
2444 enforceCallPermission();
2445
Jordan Liu1617b712019-07-10 15:06:26 -07002446 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002447 != AppOpsManager.MODE_ALLOWED) {
2448 return;
2449 }
2450
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002451 final long identity = Binder.clearCallingIdentity();
2452 try {
2453 String url = createTelUrl(number);
2454 if (url == null) {
2455 return;
2456 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002457
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002458 boolean isValid = false;
2459 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2460 if (slist != null) {
2461 for (SubscriptionInfo subInfoRecord : slist) {
2462 if (subInfoRecord.getSubscriptionId() == subId) {
2463 isValid = true;
2464 break;
2465 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002466 }
Wink Saville08874612014-08-31 19:19:58 -07002467 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002468 if (!isValid) {
2469 return;
2470 }
Wink Saville08874612014-08-31 19:19:58 -07002471
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002472 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2473 intent.putExtra(SUBSCRIPTION_KEY, subId);
2474 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2475 mApp.startActivity(intent);
2476 } finally {
2477 Binder.restoreCallingIdentity(identity);
2478 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002479 }
2480
Wink Savilleb564aae2014-10-23 10:18:09 -07002481 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002482 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002483 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2484 }
2485
Wink Savilleb564aae2014-10-23 10:18:09 -07002486 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002487 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002488 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2489 }
2490
Wink Savilleb564aae2014-10-23 10:18:09 -07002491 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002492 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002493
2494 final long identity = Binder.clearCallingIdentity();
2495 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002496 Phone phone = getPhone(subId);
2497 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002498 checkSimPin.start();
2499 return checkSimPin.unlockSim(null, pin);
2500 } finally {
2501 Binder.restoreCallingIdentity(identity);
2502 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002503 }
2504
Wink Savilleb564aae2014-10-23 10:18:09 -07002505 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002506 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002507
2508 final long identity = Binder.clearCallingIdentity();
2509 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002510 Phone phone = getPhone(subId);
2511 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002512 checkSimPuk.start();
2513 return checkSimPuk.unlockSim(puk, pin);
2514 } finally {
2515 Binder.restoreCallingIdentity(identity);
2516 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002517 }
2518
2519 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002520 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002521 * a synchronous one.
2522 */
2523 private static class UnlockSim extends Thread {
2524
2525 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002526 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002527
2528 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002529 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2530 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002531
2532 // For replies from SimCard interface
2533 private Handler mHandler;
2534
2535 // For async handler to identify request type
2536 private static final int SUPPLY_PIN_COMPLETE = 100;
2537
Michele Berionne5e411512020-11-13 02:36:59 +00002538 UnlockSim(int phoneId, IccCard simCard) {
2539 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002540 mSimCard = simCard;
2541 }
2542
2543 @Override
2544 public void run() {
2545 Looper.prepare();
2546 synchronized (UnlockSim.this) {
2547 mHandler = new Handler() {
2548 @Override
2549 public void handleMessage(Message msg) {
2550 AsyncResult ar = (AsyncResult) msg.obj;
2551 switch (msg.what) {
2552 case SUPPLY_PIN_COMPLETE:
2553 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2554 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002555 mRetryCount = msg.arg1;
2556 if (ar.exception != null) {
2557 if (ar.exception instanceof CommandException &&
2558 ((CommandException)(ar.exception)).getCommandError()
2559 == CommandException.Error.PASSWORD_INCORRECT) {
2560 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002561 } //When UiccCardApp dispose,handle message and return exception
2562 else if (ar.exception instanceof CommandException &&
2563 ((CommandException) (ar.exception)).getCommandError()
2564 == CommandException.Error.ABORTED) {
2565 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002566 } else {
2567 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2568 }
2569 } else {
2570 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2571 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002572 mDone = true;
2573 UnlockSim.this.notifyAll();
2574 }
2575 break;
2576 }
2577 }
2578 };
2579 UnlockSim.this.notifyAll();
2580 }
2581 Looper.loop();
2582 }
2583
2584 /*
2585 * Use PIN or PUK to unlock SIM card
2586 *
2587 * If PUK is null, unlock SIM card with PIN
2588 *
2589 * If PUK is not null, unlock SIM card with PUK and set PIN code
2590 */
Wink Saville9de0f752013-10-22 19:04:03 -07002591 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002592
2593 while (mHandler == null) {
2594 try {
2595 wait();
2596 } catch (InterruptedException e) {
2597 Thread.currentThread().interrupt();
2598 }
2599 }
2600 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2601
2602 if (puk == null) {
2603 mSimCard.supplyPin(pin, callback);
2604 } else {
2605 mSimCard.supplyPuk(puk, pin, callback);
2606 }
2607
2608 while (!mDone) {
2609 try {
2610 Log.d(LOG_TAG, "wait for done");
2611 wait();
2612 } catch (InterruptedException e) {
2613 // Restore the interrupted status
2614 Thread.currentThread().interrupt();
2615 }
2616 }
2617 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002618 int[] resultArray = new int[2];
2619 resultArray[0] = mResult;
2620 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002621
2622 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002623 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002624 }
2625
Wink Saville9de0f752013-10-22 19:04:03 -07002626 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002627 }
2628 }
2629
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002630 /**
2631 * This method has been removed due to privacy and stability concerns.
2632 */
2633 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002634 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002635 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2636 return;
Wink Saville36469e72014-06-11 15:17:00 -07002637 }
2638
Nathan Harold1f889d82020-06-04 17:05:26 -07002639 @Override
2640 public void updateServiceLocationWithPackageName(String callingPackage) {
2641 mApp.getSystemService(AppOpsManager.class)
2642 .checkPackage(Binder.getCallingUid(), callingPackage);
2643
Nathan Haroldf096d982020-11-18 17:18:06 -08002644 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002645 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2646 // Callers targeting S have no business invoking this method.
2647 return;
2648 }
2649
2650 LocationAccessPolicy.LocationPermissionResult locationResult =
2651 LocationAccessPolicy.checkLocationPermission(mApp,
2652 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2653 .setCallingPackage(callingPackage)
2654 .setCallingFeatureId(null)
2655 .setCallingPid(Binder.getCallingPid())
2656 .setCallingUid(Binder.getCallingUid())
2657 .setMethod("updateServiceLocation")
2658 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2659 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2660 .build());
2661 // Apps that lack location permission have no business calling this method;
2662 // however, because no permission was declared in the public API, denials must
2663 // all be "soft".
2664 switch (locationResult) {
2665 case DENIED_HARD: /* fall through */
2666 case DENIED_SOFT:
2667 return;
2668 }
2669
2670 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002671 final long identity = Binder.clearCallingIdentity();
2672 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002673 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002674 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002675 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002676 }
2677 } finally {
2678 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002679 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002680 }
2681
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002682 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002683 @Override
2684 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002685 return isRadioOnWithFeature(callingPackage, null);
2686 }
2687
2688
2689 @Override
2690 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2691 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2692 callingFeatureId);
2693 }
2694
2695 @Deprecated
2696 @Override
2697 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2698 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002699 }
2700
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002701 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002702 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2703 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002704 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002705 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002706 return false;
2707 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002708
2709 final long identity = Binder.clearCallingIdentity();
2710 try {
2711 return isRadioOnForSubscriber(subId);
2712 } finally {
2713 Binder.restoreCallingIdentity(identity);
2714 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002715 }
2716
2717 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002718 final long identity = Binder.clearCallingIdentity();
2719 try {
2720 final Phone phone = getPhone(subId);
2721 if (phone != null) {
2722 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2723 } else {
2724 return false;
2725 }
2726 } finally {
2727 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002728 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002729 }
2730
2731 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002732 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002733 }
Wink Saville36469e72014-06-11 15:17:00 -07002734
Wink Savilleb564aae2014-10-23 10:18:09 -07002735 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002736 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002737
2738 final long identity = Binder.clearCallingIdentity();
2739 try {
2740 final Phone phone = getPhone(subId);
2741 if (phone != null) {
2742 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2743 }
2744 } finally {
2745 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002746 }
Wink Saville36469e72014-06-11 15:17:00 -07002747 }
2748
2749 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002750 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002751 }
2752
Wink Savilleb564aae2014-10-23 10:18:09 -07002753 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002754 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002755
2756 final long identity = Binder.clearCallingIdentity();
2757 try {
2758 final Phone phone = getPhone(subId);
2759 if (phone == null) {
2760 return false;
2761 }
2762 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2763 toggleRadioOnOffForSubscriber(subId);
2764 }
2765 return true;
2766 } finally {
2767 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002768 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002769 }
Wink Saville36469e72014-06-11 15:17:00 -07002770
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002771 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002772 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002773 /*
2774 * If any of the Radios are available, it will need to be
2775 * shutdown. So return true if any Radio is available.
2776 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002777 final long identity = Binder.clearCallingIdentity();
2778 try {
2779 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2780 Phone phone = PhoneFactory.getPhone(i);
2781 if (phone != null && phone.isRadioAvailable()) return true;
2782 }
2783 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2784 return false;
2785 } finally {
2786 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002787 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002788 }
2789
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002790 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002791 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002792 enforceModifyPermission();
2793
2794 final long identity = Binder.clearCallingIdentity();
2795 try {
2796 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2797 logv("Shutting down Phone " + i);
2798 shutdownRadioUsingPhoneId(i);
2799 }
2800 } finally {
2801 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002802 }
2803 }
2804
2805 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002806 Phone phone = PhoneFactory.getPhone(phoneId);
2807 if (phone != null && phone.isRadioAvailable()) {
2808 phone.shutdownRadio();
2809 }
2810 }
2811
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002812 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002813 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002814
2815 final long identity = Binder.clearCallingIdentity();
2816 try {
2817 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2818 if (defaultPhone != null) {
2819 defaultPhone.setRadioPower(turnOn);
2820 return true;
2821 } else {
2822 loge("There's no default phone.");
2823 return false;
2824 }
2825 } finally {
2826 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002827 }
Wink Saville36469e72014-06-11 15:17:00 -07002828 }
2829
Wink Savilleb564aae2014-10-23 10:18:09 -07002830 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002831 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002832
2833 final long identity = Binder.clearCallingIdentity();
2834 try {
2835 final Phone phone = getPhone(subId);
2836 if (phone != null) {
2837 phone.setRadioPower(turnOn);
2838 return true;
2839 } else {
2840 return false;
2841 }
2842 } finally {
2843 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002844 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002845 }
2846
Wink Saville36469e72014-06-11 15:17:00 -07002847 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002848 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002849 public boolean enableDataConnectivity() {
2850 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002851
2852 final long identity = Binder.clearCallingIdentity();
2853 try {
2854 int subId = mSubscriptionController.getDefaultDataSubId();
2855 final Phone phone = getPhone(subId);
2856 if (phone != null) {
Jack Yu99e87332021-12-17 23:14:15 -08002857 if (phone.isUsingNewDataStack()) {
2858 phone.getDataSettingsManager().setDataEnabled(
2859 TelephonyManager.DATA_ENABLED_REASON_USER, true);
2860 } else {
2861 phone.getDataEnabledSettings().setDataEnabled(
2862 TelephonyManager.DATA_ENABLED_REASON_USER, true);
2863 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002864 return true;
2865 } else {
2866 return false;
2867 }
2868 } finally {
2869 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002870 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002871 }
2872
Wink Saville36469e72014-06-11 15:17:00 -07002873 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002874 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002875 public boolean disableDataConnectivity() {
2876 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002877
2878 final long identity = Binder.clearCallingIdentity();
2879 try {
2880 int subId = mSubscriptionController.getDefaultDataSubId();
2881 final Phone phone = getPhone(subId);
2882 if (phone != null) {
Jack Yu99e87332021-12-17 23:14:15 -08002883 if (phone.isUsingNewDataStack()) {
2884 phone.getDataSettingsManager().setDataEnabled(
2885 TelephonyManager.DATA_ENABLED_REASON_USER, false);
2886 } else {
2887 phone.getDataEnabledSettings().setDataEnabled(
2888 TelephonyManager.DATA_ENABLED_REASON_USER, false);
2889 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002890 return true;
2891 } else {
2892 return false;
2893 }
2894 } finally {
2895 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002896 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002897 }
2898
Sanket Padawe356d7632015-06-22 14:03:32 -07002899 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002900 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002901 final long identity = Binder.clearCallingIdentity();
2902 try {
2903 final Phone phone = getPhone(subId);
2904 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002905 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002906 } else {
2907 return false;
2908 }
2909 } finally {
2910 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002911 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002912 }
2913
2914 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002915 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002916 }
2917
pkanwarae03a6b2016-11-06 20:37:09 -08002918 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002919 enforceCallPermission();
2920
2921 final long identity = Binder.clearCallingIdentity();
2922 try {
2923 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2924 return;
2925 }
2926 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2927 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2928 } finally {
2929 Binder.restoreCallingIdentity(identity);
2930 }
pkanwar32d516d2016-10-14 19:37:38 -07002931 };
2932
Wink Savilleb564aae2014-10-23 10:18:09 -07002933 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002934 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002935
2936 final long identity = Binder.clearCallingIdentity();
2937 try {
2938 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2939 return false;
2940 }
2941 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2942 } finally {
2943 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002944 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002945 }
2946
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002947 /**
2948 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2949 * tag on getCallState Binder call.
2950 */
2951 @Deprecated
2952 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002953 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002954 if (CompatChanges.isChangeEnabled(
2955 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2956 Binder.getCallingUid())) {
2957 // Do not allow this API to be called on API version 31+, it should only be
2958 // called on old apps using this Binder call directly.
2959 throw new SecurityException("This method can only be used for applications "
2960 + "targeting API version 30 or less.");
2961 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002962 final long identity = Binder.clearCallingIdentity();
2963 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002964 Phone phone = getPhone(getDefaultSubscription());
2965 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2966 PhoneConstantConversions.convertCallState(phone.getState());
2967 } finally {
2968 Binder.restoreCallingIdentity(identity);
2969 }
2970 }
2971
2972 @Override
2973 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2974 if (CompatChanges.isChangeEnabled(
2975 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2976 Binder.getCallingUid())) {
2977 // Check READ_PHONE_STATE for API version 31+
2978 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2979 featureId, "getCallStateForSubscription")) {
2980 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2981 + "targeting API level 31+.");
2982 }
2983 }
2984 final long identity = Binder.clearCallingIdentity();
2985 try {
2986 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002987 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2988 PhoneConstantConversions.convertCallState(phone.getState());
2989 } finally {
2990 Binder.restoreCallingIdentity(identity);
2991 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002992 }
2993
Sanket Padawe356d7632015-06-22 14:03:32 -07002994 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002995 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002996 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2997 }
2998
2999 @Override
3000 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003001 final long identity = Binder.clearCallingIdentity();
3002 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003003 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003004 if (phone != null) {
Jack Yu2c450952021-11-29 11:36:17 -08003005 if (phone.isUsingNewDataStack()) {
3006 return phone.getDataNetworkController().getInternetDataNetworkState();
3007 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003008 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
3009 } else {
3010 return PhoneConstantConversions.convertDataState(
3011 PhoneConstants.DataState.DISCONNECTED);
3012 }
3013 } finally {
3014 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003015 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003016 }
3017
Sanket Padawe356d7632015-06-22 14:03:32 -07003018 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003019 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003020 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
3021 }
3022
3023 @Override
3024 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003025 final long identity = Binder.clearCallingIdentity();
3026 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003027 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003028 if (phone != null) {
3029 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
3030 } else {
3031 return TelephonyManager.DATA_ACTIVITY_NONE;
3032 }
3033 } finally {
3034 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003035 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003036 }
3037
3038 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003039 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003040 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003041 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003042
3043 LocationAccessPolicy.LocationPermissionResult locationResult =
3044 LocationAccessPolicy.checkLocationPermission(mApp,
3045 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3046 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003047 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003048 .setCallingPid(Binder.getCallingPid())
3049 .setCallingUid(Binder.getCallingUid())
3050 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003051 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003052 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3053 .build());
3054 switch (locationResult) {
3055 case DENIED_HARD:
3056 throw new SecurityException("Not allowed to access cell location");
3057 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003058 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3059 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003060 }
3061
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003062 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003063 final long identity = Binder.clearCallingIdentity();
3064 try {
3065 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003066 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003067 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003068 } finally {
3069 Binder.restoreCallingIdentity(identity);
3070 }
Svetoslav64fad262015-04-14 14:35:21 -07003071 }
3072
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003073 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003074 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003075 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3076 // registered cell info, so return a NULL country instead.
3077 final long identity = Binder.clearCallingIdentity();
3078 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003079 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3080 // Get default phone in this case.
3081 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3082 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003083 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003084 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003085 if (phone == null) return "";
3086 ServiceStateTracker sst = phone.getServiceStateTracker();
3087 if (sst == null) return "";
3088 LocaleTracker lt = sst.getLocaleTracker();
3089 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003090 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003091 } finally {
3092 Binder.restoreCallingIdentity(identity);
3093 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003094 }
3095
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003096 /**
3097 * This method was removed due to potential issues caused by performing partial
3098 * updates of service state, and lack of a credible use case.
3099 *
3100 * This has the ability to break the telephony implementation by disabling notification of
3101 * changes in device connectivity. DO NOT USE THIS!
3102 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003103 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003104 public void enableLocationUpdates() {
3105 mApp.enforceCallingOrSelfPermission(
3106 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003107 }
3108
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003109 /**
3110 * This method was removed due to potential issues caused by performing partial
3111 * updates of service state, and lack of a credible use case.
3112 *
3113 * This has the ability to break the telephony implementation by disabling notification of
3114 * changes in device connectivity. DO NOT USE THIS!
3115 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003116 @Override
3117 public void disableLocationUpdates() {
3118 mApp.enforceCallingOrSelfPermission(
3119 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003120 }
3121
3122 @Override
3123 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003124 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3125 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003126 try {
3127 mApp.getSystemService(AppOpsManager.class)
3128 .checkPackage(Binder.getCallingUid(), callingPackage);
3129 } catch (SecurityException e) {
3130 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3131 throw e;
3132 }
3133
Nathan Haroldf096d982020-11-18 17:18:06 -08003134 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003135 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3136 throw new SecurityException(
3137 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3138 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003139
Jordan Liu1617b712019-07-10 15:06:26 -07003140 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003141 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3142 return null;
3143 }
Svetoslav64fad262015-04-14 14:35:21 -07003144
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003145 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003146
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003147 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003148 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003149
Nathan Haroldf180aac2018-06-01 18:43:55 -07003150 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3151 for (CellInfo ci : info) {
3152 if (ci instanceof CellInfoGsm) {
3153 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3154 } else if (ci instanceof CellInfoWcdma) {
3155 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3156 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003157 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003158 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003159 }
3160
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003161 private List<CellInfo> getCachedCellInfo() {
3162 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3163 for (Phone phone : PhoneFactory.getPhones()) {
3164 List<CellInfo> info = phone.getAllCellInfo();
3165 if (info != null) cellInfos.addAll(info);
3166 }
3167 return cellInfos;
3168 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003169
3170 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003171 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003172 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003173 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003174
3175 LocationAccessPolicy.LocationPermissionResult locationResult =
3176 LocationAccessPolicy.checkLocationPermission(mApp,
3177 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3178 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003179 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003180 .setCallingPid(Binder.getCallingPid())
3181 .setCallingUid(Binder.getCallingUid())
3182 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003183 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003184 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3185 .build());
3186 switch (locationResult) {
3187 case DENIED_HARD:
3188 throw new SecurityException("Not allowed to access cell info");
3189 case DENIED_SOFT:
3190 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003191 }
3192
Nathan Haroldf096d982020-11-18 17:18:06 -08003193 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003194 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3195 return getCachedCellInfo();
3196 }
3197
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003198 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003199 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003200 final long identity = Binder.clearCallingIdentity();
3201 try {
3202 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3203 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003204 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003205 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003206 if (info != null) cellInfos.addAll(info);
3207 }
3208 return cellInfos;
3209 } finally {
3210 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003211 }
3212 }
3213
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003214 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003215 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3216 String callingFeatureId) {
3217 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3218 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003219 }
3220
3221 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003222 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3223 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003224 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003225 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003226 }
3227
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003228 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3229 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003230 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003231 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003232
3233 LocationAccessPolicy.LocationPermissionResult locationResult =
3234 LocationAccessPolicy.checkLocationPermission(mApp,
3235 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3236 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003237 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003238 .setCallingPid(Binder.getCallingPid())
3239 .setCallingUid(Binder.getCallingUid())
3240 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003241 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3242 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003243 .build());
3244 switch (locationResult) {
3245 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003246 if (TelephonyPermissions
3247 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003248 // Safetynet logging for b/154934934
3249 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3250 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003251 throw new SecurityException("Not allowed to access cell info");
3252 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003253 if (TelephonyPermissions
3254 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003255 // Safetynet logging for b/154934934
3256 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3257 }
Nathan Harold5320c422019-05-09 10:26:08 -07003258 try {
3259 cb.onCellInfo(new ArrayList<CellInfo>());
3260 } catch (RemoteException re) {
3261 // Drop without consequences
3262 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003263 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003264 }
3265
Nathan Harolda939a962019-05-09 10:13:47 -07003266
3267 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003268 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3269
3270 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3271 }
3272
3273 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003274 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003275 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003276 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003277
3278 final long identity = Binder.clearCallingIdentity();
3279 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003280 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003281 } finally {
3282 Binder.restoreCallingIdentity(identity);
3283 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003284 }
3285
Shishir Agrawala9f32182016-04-12 12:00:16 -07003286 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003287 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003288 Phone phone = PhoneFactory.getPhone(slotIndex);
3289 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003290 return null;
3291 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003292 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003293 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003294 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003295 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003296 return null;
3297 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003298
3299 final long identity = Binder.clearCallingIdentity();
3300 try {
3301 return phone.getImei();
3302 } finally {
3303 Binder.restoreCallingIdentity(identity);
3304 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003305 }
3306
3307 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003308 public String getTypeAllocationCodeForSlot(int slotIndex) {
3309 Phone phone = PhoneFactory.getPhone(slotIndex);
3310 String tac = null;
3311 if (phone != null) {
3312 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003313 try {
3314 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3315 } catch (IndexOutOfBoundsException e) {
3316 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3317 return null;
3318 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003319 }
3320 return tac;
3321 }
3322
3323 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003324 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003325 try {
3326 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3327 } catch (SecurityException se) {
3328 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3329 throw new SecurityException("Package " + callingPackage + " does not belong to "
3330 + Binder.getCallingUid());
3331 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003332 Phone phone = PhoneFactory.getPhone(slotIndex);
3333 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003334 return null;
3335 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003336
Jeff Davidson913390f2018-02-23 17:11:49 -08003337 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003338 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003339 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003340 return null;
3341 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003342
3343 final long identity = Binder.clearCallingIdentity();
3344 try {
3345 return phone.getMeid();
3346 } finally {
3347 Binder.restoreCallingIdentity(identity);
3348 }
Jack Yu2af8d712017-03-15 17:14:14 -07003349 }
3350
3351 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003352 public String getManufacturerCodeForSlot(int slotIndex) {
3353 Phone phone = PhoneFactory.getPhone(slotIndex);
3354 String manufacturerCode = null;
3355 if (phone != null) {
3356 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003357 try {
3358 manufacturerCode =
3359 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3360 } catch (IndexOutOfBoundsException e) {
3361 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3362 return null;
3363 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003364 }
3365 return manufacturerCode;
3366 }
3367
3368 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003369 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3370 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003371 Phone phone = PhoneFactory.getPhone(slotIndex);
3372 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003373 return null;
3374 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003375 int subId = phone.getSubId();
3376 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003377 mApp, subId, callingPackage, callingFeatureId,
3378 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003379 return null;
3380 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003381
3382 final long identity = Binder.clearCallingIdentity();
3383 try {
3384 return phone.getDeviceSvn();
3385 } finally {
3386 Binder.restoreCallingIdentity(identity);
3387 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003388 }
3389
fionaxu43304da2017-11-27 22:51:16 -08003390 @Override
3391 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003392 final long identity = Binder.clearCallingIdentity();
3393 try {
3394 final Phone phone = getPhone(subId);
3395 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3396 } finally {
3397 Binder.restoreCallingIdentity(identity);
3398 }
fionaxu43304da2017-11-27 22:51:16 -08003399 }
3400
3401 @Override
3402 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003403 final long identity = Binder.clearCallingIdentity();
3404 try {
3405 final Phone phone = getPhone(subId);
3406 return phone == null ? null : phone.getCarrierName();
3407 } finally {
3408 Binder.restoreCallingIdentity(identity);
3409 }
fionaxu43304da2017-11-27 22:51:16 -08003410 }
3411
calvinpanffe225e2018-11-01 19:43:06 +08003412 @Override
chen xu0026ca62019-03-06 15:28:50 -08003413 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003414 final long identity = Binder.clearCallingIdentity();
3415 try {
3416 final Phone phone = getPhone(subId);
3417 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003418 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003419 } finally {
3420 Binder.restoreCallingIdentity(identity);
3421 }
3422 }
3423
3424 @Override
chen xu0026ca62019-03-06 15:28:50 -08003425 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003426 final long identity = Binder.clearCallingIdentity();
3427 try {
3428 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003429 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003430 } finally {
3431 Binder.restoreCallingIdentity(identity);
3432 }
3433 }
3434
chen xu651eec72018-11-11 19:03:44 -08003435 @Override
chen xu864e11c2018-12-06 22:10:03 -08003436 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3437 if (!isSubscriptionMccMnc) {
3438 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3439 }
chen xu651eec72018-11-11 19:03:44 -08003440 final Phone phone = PhoneFactory.getPhone(slotIndex);
3441 if (phone == null) {
3442 return TelephonyManager.UNKNOWN_CARRIER_ID;
3443 }
3444 final long identity = Binder.clearCallingIdentity();
3445 try {
3446 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3447 } finally {
3448 Binder.restoreCallingIdentity(identity);
3449 }
3450 }
3451
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003452 //
3453 // Internal helper methods.
3454 //
3455
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003456 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003457 * Make sure the caller is the calling package itself
3458 *
3459 * @throws SecurityException if the caller is not the calling package
3460 */
3461 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3462 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003463 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3464 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003465 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003466 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003467 } catch (PackageManager.NameNotFoundException e) {
3468 // packageUid is -1
3469 }
3470 if (packageUid != callingUid) {
3471 throw new SecurityException(message + ": Package " + callingPackage
3472 + " does not belong to " + callingUid);
3473 }
3474 }
3475
3476 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003477 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3478 *
3479 * @throws SecurityException if the caller does not have the required permission
3480 */
3481 private void enforceModifyPermission() {
3482 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3483 }
3484
Shuo Qian3b6ee772019-11-13 17:43:31 -08003485 private void enforceActiveEmergencySessionPermission() {
3486 mApp.enforceCallingOrSelfPermission(
3487 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3488 }
3489
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003490 /**
3491 * Make sure the caller has the CALL_PHONE permission.
3492 *
3493 * @throws SecurityException if the caller does not have the required permission
3494 */
3495 private void enforceCallPermission() {
3496 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3497 }
3498
paulhu5a773602019-08-23 19:17:33 +08003499 private void enforceSettingsPermission() {
3500 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003501 }
3502
Michele Berionne5e411512020-11-13 02:36:59 +00003503 private void enforceRebootPermission() {
3504 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3505 }
3506
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003507 private String createTelUrl(String number) {
3508 if (TextUtils.isEmpty(number)) {
3509 return null;
3510 }
3511
Jake Hambye994d462014-02-03 13:10:13 -08003512 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003513 }
3514
Ihab Awadf9e92732013-12-05 18:02:52 -08003515 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003516 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3517 }
3518
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003519 private static void logv(String msg) {
3520 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3521 }
3522
Ihab Awadf9e92732013-12-05 18:02:52 -08003523 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003524 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3525 }
3526
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003527 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003528 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003529 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003530 }
3531
Sanket Padawe356d7632015-06-22 14:03:32 -07003532 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003533 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003534 final long identity = Binder.clearCallingIdentity();
3535 try {
3536 final Phone phone = PhoneFactory.getPhone(slotIndex);
3537 if (phone == null) {
3538 return PhoneConstants.PHONE_TYPE_NONE;
3539 } else {
3540 return phone.getPhoneType();
3541 }
3542 } finally {
3543 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003544 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003545 }
3546
3547 /**
3548 * Returns the CDMA ERI icon index to display
3549 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003550 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003551 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3552 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3553 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003554 }
3555
Sanket Padawe356d7632015-06-22 14:03:32 -07003556 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003557 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3558 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003559 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003560 mApp, subId, callingPackage, callingFeatureId,
3561 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003562 return -1;
3563 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003564
3565 final long identity = Binder.clearCallingIdentity();
3566 try {
3567 final Phone phone = getPhone(subId);
3568 if (phone != null) {
3569 return phone.getCdmaEriIconIndex();
3570 } else {
3571 return -1;
3572 }
3573 } finally {
3574 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003575 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003576 }
3577
3578 /**
3579 * Returns the CDMA ERI icon mode,
3580 * 0 - ON
3581 * 1 - FLASHING
3582 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003583 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003584 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3585 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3586 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003587 }
3588
Sanket Padawe356d7632015-06-22 14:03:32 -07003589 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003590 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3591 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003592 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003593 mApp, subId, callingPackage, callingFeatureId,
3594 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003595 return -1;
3596 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003597
3598 final long identity = Binder.clearCallingIdentity();
3599 try {
3600 final Phone phone = getPhone(subId);
3601 if (phone != null) {
3602 return phone.getCdmaEriIconMode();
3603 } else {
3604 return -1;
3605 }
3606 } finally {
3607 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003608 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003609 }
3610
3611 /**
3612 * Returns the CDMA ERI text,
3613 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003614 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003615 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3616 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3617 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003618 }
3619
Sanket Padawe356d7632015-06-22 14:03:32 -07003620 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003621 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3622 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003623 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003624 mApp, subId, callingPackage, callingFeatureId,
3625 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003626 return null;
3627 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003628
3629 final long identity = Binder.clearCallingIdentity();
3630 try {
3631 final Phone phone = getPhone(subId);
3632 if (phone != null) {
3633 return phone.getCdmaEriText();
3634 } else {
3635 return null;
3636 }
3637 } finally {
3638 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003639 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003640 }
3641
3642 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003643 * Returns the CDMA MDN.
3644 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003645 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003646 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003647 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3648 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003649
3650 final long identity = Binder.clearCallingIdentity();
3651 try {
3652 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003653 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003654 return phone.getLine1Number();
3655 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003656 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003657 return null;
3658 }
3659 } finally {
3660 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003661 }
3662 }
3663
3664 /**
3665 * Returns the CDMA MIN.
3666 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003667 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003668 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003669 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3670 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003671
3672 final long identity = Binder.clearCallingIdentity();
3673 try {
3674 final Phone phone = getPhone(subId);
3675 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3676 return phone.getCdmaMin();
3677 } else {
3678 return null;
3679 }
3680 } finally {
3681 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003682 }
3683 }
3684
Hall Liud892bec2018-11-30 14:51:45 -08003685 @Override
3686 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3687 INumberVerificationCallback callback, String callingPackage) {
3688 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3689 != PERMISSION_GRANTED) {
3690 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3691 }
3692 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3693
3694 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3695 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003696 throw new SecurityException("Calling package must be configured in the device config: "
3697 + "calling package: " + callingPackage
3698 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003699 }
3700
3701 if (range == null) {
3702 throw new NullPointerException("Range must be non-null");
3703 }
3704
3705 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003706 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003707
3708 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3709 }
3710
Junda Liuca05d5d2014-08-14 22:36:34 -07003711 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003712 * Returns true if CDMA provisioning needs to run.
3713 */
3714 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003715 final long identity = Binder.clearCallingIdentity();
3716 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003717 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003718 } finally {
3719 Binder.restoreCallingIdentity(identity);
3720 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003721 }
3722
3723 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003724 * Sets the voice mail number of a given subId.
3725 */
3726 @Override
3727 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003728 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3729 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003730
3731 final long identity = Binder.clearCallingIdentity();
3732 try {
3733 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3734 new Pair<String, String>(alphaTag, number), new Integer(subId));
3735 return success;
3736 } finally {
3737 Binder.restoreCallingIdentity(identity);
3738 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003739 }
3740
Ta-wei Yen87c49842016-05-13 21:19:52 -07003741 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003742 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3743 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003744 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3745 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003746 if (!TextUtils.equals(callingPackage, systemDialer)) {
3747 throw new SecurityException("caller must be system dialer");
3748 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003749
3750 final long identity = Binder.clearCallingIdentity();
3751 try {
3752 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3753 if (phoneAccountHandle == null) {
3754 return null;
3755 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003756 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003757 } finally {
3758 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003759 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003760 }
3761
3762 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003763 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3764 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003765 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003766 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003767 mApp, subId, callingPackage, callingFeatureId,
3768 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003769 return null;
3770 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003771
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003772 final long identity = Binder.clearCallingIdentity();
3773 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003774 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003775 } finally {
3776 Binder.restoreCallingIdentity(identity);
3777 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003778 }
3779
3780 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003781 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3782 VisualVoicemailSmsFilterSettings settings) {
3783 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003784
3785 final long identity = Binder.clearCallingIdentity();
3786 try {
3787 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003788 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003789 } finally {
3790 Binder.restoreCallingIdentity(identity);
3791 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003792 }
3793
3794 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003795 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3796 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003797
3798 final long identity = Binder.clearCallingIdentity();
3799 try {
3800 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003801 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003802 } finally {
3803 Binder.restoreCallingIdentity(identity);
3804 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003805 }
3806
3807 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003808 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3809 String callingPackage, int subId) {
3810 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003811
3812 final long identity = Binder.clearCallingIdentity();
3813 try {
3814 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003815 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003816 } finally {
3817 Binder.restoreCallingIdentity(identity);
3818 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003819 }
3820
3821 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003822 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003823 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003824
3825 final long identity = Binder.clearCallingIdentity();
3826 try {
3827 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003828 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003829 } finally {
3830 Binder.restoreCallingIdentity(identity);
3831 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003832 }
3833
3834 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003835 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3836 String callingAttributionTag, int subId, String number, int port, String text,
3837 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003838 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003839 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003840 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003841 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003842 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3843 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003844 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003845
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003846 /**
fionaxu0152e512016-11-14 13:36:14 -08003847 * Sets the voice activation state of a given subId.
3848 */
3849 @Override
3850 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003851 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3852 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003853
3854 final long identity = Binder.clearCallingIdentity();
3855 try {
3856 final Phone phone = getPhone(subId);
3857 if (phone != null) {
3858 phone.setVoiceActivationState(activationState);
3859 } else {
3860 loge("setVoiceActivationState fails with invalid subId: " + subId);
3861 }
3862 } finally {
3863 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003864 }
3865 }
3866
3867 /**
3868 * Sets the data activation state of a given subId.
3869 */
3870 @Override
3871 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003872 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3873 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003874
3875 final long identity = Binder.clearCallingIdentity();
3876 try {
3877 final Phone phone = getPhone(subId);
3878 if (phone != null) {
3879 phone.setDataActivationState(activationState);
3880 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003881 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003882 }
3883 } finally {
3884 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003885 }
3886 }
3887
3888 /**
3889 * Returns the voice activation state of a given subId.
3890 */
3891 @Override
3892 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003893 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003894
fionaxu0152e512016-11-14 13:36:14 -08003895 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003896 final long identity = Binder.clearCallingIdentity();
3897 try {
3898 if (phone != null) {
3899 return phone.getVoiceActivationState();
3900 } else {
3901 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3902 }
3903 } finally {
3904 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003905 }
3906 }
3907
3908 /**
3909 * Returns the data activation state of a given subId.
3910 */
3911 @Override
3912 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003913 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003914
fionaxu0152e512016-11-14 13:36:14 -08003915 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003916 final long identity = Binder.clearCallingIdentity();
3917 try {
3918 if (phone != null) {
3919 return phone.getDataActivationState();
3920 } else {
3921 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3922 }
3923 } finally {
3924 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003925 }
3926 }
3927
3928 /**
Wink Saville36469e72014-06-11 15:17:00 -07003929 * Returns the unread count of voicemails for a subId
3930 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003931 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003932 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3933 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003934 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003935 mApp, subId, callingPackage, callingFeatureId,
3936 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003937 return 0;
3938 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003939 final long identity = Binder.clearCallingIdentity();
3940 try {
3941 final Phone phone = getPhone(subId);
3942 if (phone != null) {
3943 return phone.getVoiceMessageCount();
3944 } else {
3945 return 0;
3946 }
3947 } finally {
3948 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003949 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003950 }
3951
3952 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003953 * returns true, if the device is in a state where both voice and data
3954 * are supported simultaneously. This can change based on location or network condition.
3955 */
3956 @Override
3957 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003958 final long identity = Binder.clearCallingIdentity();
3959 try {
3960 final Phone phone = getPhone(subId);
3961 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3962 } finally {
3963 Binder.restoreCallingIdentity(identity);
3964 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003965 }
3966
3967 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003968 * Send the dialer code if called from the current default dialer or the caller has
3969 * carrier privilege.
3970 * @param inputCode The dialer code to send
3971 */
3972 @Override
3973 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003974 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003975 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003976 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3977 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003978 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003979 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003980 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003981 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003982
3983 final long identity = Binder.clearCallingIdentity();
3984 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003985 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003986 } finally {
3987 Binder.restoreCallingIdentity(identity);
3988 }
fionaxu235cc5e2017-03-06 22:25:57 -08003989 }
3990
Pengquan Menga1bb6272018-09-06 09:59:22 -07003991 @Override
3992 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003993 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003994 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003995 mApp, subId, "getNetworkSelectionMode");
3996 final long identity = Binder.clearCallingIdentity();
3997 try {
3998 if (!isActiveSubscription(subId)) {
3999 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4000 }
4001 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4002 } finally {
4003 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004004 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004005 }
4006
Brad Ebinger35c841c2018-10-01 10:40:55 -07004007 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004008 public boolean isInEmergencySmsMode() {
4009 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4010 final long identity = Binder.clearCallingIdentity();
4011 try {
4012 for (Phone phone : PhoneFactory.getPhones()) {
4013 if (phone.isInEmergencySmsMode()) {
4014 return true;
4015 }
4016 }
4017 } finally {
4018 Binder.restoreCallingIdentity(identity);
4019 }
4020 return false;
4021 }
4022
shilu366312e2019-12-17 09:28:10 -08004023 /**
4024 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4025 * @param subId The subscription to use to check the configuration.
4026 * @param c The callback that will be used to send the result.
4027 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004028 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004029 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4030 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004031 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004032 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08004033
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004034 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4035 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4036 "IMS not available on device.");
4037 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004038 final long token = Binder.clearCallingIdentity();
4039 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004040 int slotId = getSlotIndexOrException(subId);
4041 verifyImsMmTelConfiguredOrThrow(slotId);
4042 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004043 } catch (ImsException e) {
4044 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004045 } finally {
4046 Binder.restoreCallingIdentity(token);
4047 }
4048 }
4049
shilu366312e2019-12-17 09:28:10 -08004050 /**
4051 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4052 * @param subId The subscription to use to check the configuration.
4053 * @param c The callback that will be used to send the result.
4054 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004055 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004056 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004057 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004058 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004059 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4060 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4061 }
Meng Wangafbc5852019-09-19 17:37:13 -07004062 final long token = Binder.clearCallingIdentity();
4063 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004064 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4065 .removeRegistrationCallbackForSubscription(c, subId);
4066 } catch (ImsException e) {
4067 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4068 + "is inactive, ignoring unregister.");
4069 // If the subscription is no longer active, just return, since the callback
4070 // will already have been removed internally.
4071 } finally {
4072 Binder.restoreCallingIdentity(token);
4073 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004074 }
4075
Brad Ebingera34a6c22019-10-22 17:36:18 -07004076 /**
4077 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4078 */
4079 @Override
4080 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4081 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4082 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4083 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4084 "IMS not available on device.");
4085 }
4086 final long token = Binder.clearCallingIdentity();
4087 try {
4088 Phone phone = getPhone(subId);
4089 if (phone == null) {
4090 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4091 + subId + "'");
4092 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4093 }
4094 phone.getImsRegistrationState(regState -> {
4095 try {
4096 consumer.accept((regState == null)
4097 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4098 } catch (RemoteException e) {
4099 // Ignore if the remote process is no longer available to call back.
4100 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4101 }
4102 });
4103 } finally {
4104 Binder.restoreCallingIdentity(token);
4105 }
4106 }
4107
4108 /**
4109 * Get the transport type for the IMS service registration state.
4110 */
4111 @Override
4112 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004113 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004114 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004115 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4116 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4117 "IMS not available on device.");
4118 }
4119 final long token = Binder.clearCallingIdentity();
4120 try {
4121 Phone phone = getPhone(subId);
4122 if (phone == null) {
4123 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4124 + subId + "'");
4125 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4126 }
4127 phone.getImsRegistrationTech(regTech -> {
4128 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4129 int regTechConverted = (regTech == null)
4130 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4131 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4132 regTechConverted);
4133 try {
4134 consumer.accept(regTechConverted);
4135 } catch (RemoteException e) {
4136 // Ignore if the remote process is no longer available to call back.
4137 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4138 }
4139 });
4140 } finally {
4141 Binder.restoreCallingIdentity(token);
4142 }
4143 }
4144
shilu366312e2019-12-17 09:28:10 -08004145 /**
4146 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4147 * @param subId The subscription to use to check the configuration.
4148 * @param c The callback that will be used to send the result.
4149 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004150 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004151 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4152 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004153 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004154 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004155 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4156 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4157 "IMS not available on device.");
4158 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004159 final long token = Binder.clearCallingIdentity();
4160 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004161 int slotId = getSlotIndexOrException(subId);
4162 verifyImsMmTelConfiguredOrThrow(slotId);
4163 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004164 } catch (ImsException e) {
4165 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004166 } finally {
4167 Binder.restoreCallingIdentity(token);
4168 }
4169 }
4170
shilu366312e2019-12-17 09:28:10 -08004171 /**
4172 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4173 * @param subId The subscription to use to check the configuration.
4174 * @param c The callback that will be used to send the result.
4175 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004176 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004177 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004178 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004179 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004180 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4181 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4182 }
Meng Wangafbc5852019-09-19 17:37:13 -07004183
4184 final long token = Binder.clearCallingIdentity();
4185 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004186 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004187 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004188 } catch (ImsException e) {
4189 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4190 + "is inactive, ignoring unregister.");
4191 // If the subscription is no longer active, just return, since the callback
4192 // will already have been removed internally.
4193 } finally {
4194 Binder.restoreCallingIdentity(token);
4195 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004196 }
4197
4198 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004199 public boolean isCapable(int subId, int capability, int regTech) {
4200 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004201 final long token = Binder.clearCallingIdentity();
4202 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004203 int slotId = getSlotIndexOrException(subId);
4204 verifyImsMmTelConfiguredOrThrow(slotId);
4205 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004206 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004207 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4208 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004209 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004210 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4211 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004212 } finally {
4213 Binder.restoreCallingIdentity(token);
4214 }
4215 }
4216
4217 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004218 public boolean isAvailable(int subId, int capability, int regTech) {
4219 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004220 final long token = Binder.clearCallingIdentity();
4221 try {
4222 Phone phone = getPhone(subId);
4223 if (phone == null) return false;
4224 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004225 } catch (com.android.ims.ImsException e) {
4226 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4227 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004228 } finally {
4229 Binder.restoreCallingIdentity(token);
4230 }
4231 }
4232
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004233 /**
4234 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4235 * subscription.
4236 * @param subId The subscription to use to check the configuration.
4237 * @param callback The callback that will be used to send the result.
4238 * @param capability The MmTelFeature capability that will be used to send the result.
4239 * @param transportType The transport type of the MmTelFeature capability.
4240 */
4241 @Override
4242 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4243 int transportType) {
4244 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4245 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4246 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4247 "IMS not available on device.");
4248 }
4249 final long token = Binder.clearCallingIdentity();
4250 try {
4251 int slotId = getSlotIndex(subId);
4252 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4253 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4254 + subId + "'");
4255 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4256 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004257 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004258 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4259 transportType, aBoolean -> {
4260 try {
4261 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4262 } catch (RemoteException e) {
4263 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4264 + "running. Ignore");
4265 }
4266 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004267 } catch (ImsException e) {
4268 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004269 } finally {
4270 Binder.restoreCallingIdentity(token);
4271 }
4272 }
4273
shilu366312e2019-12-17 09:28:10 -08004274 /**
4275 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4276 * @param subId The subscription to use to check the configuration.
4277 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004278 @Override
4279 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004280 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004281 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004282
Brad Ebinger35c841c2018-10-01 10:40:55 -07004283 final long token = Binder.clearCallingIdentity();
4284 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004285 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004286 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004287 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004288 } catch (ImsException e) {
4289 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004290 } finally {
4291 Binder.restoreCallingIdentity(token);
4292 }
4293 }
4294
4295 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004296 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004297 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004298 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004299 final long identity = Binder.clearCallingIdentity();
4300 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004301 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004302 // This setting doesn't require an active ImsService connection, so do not verify. The
4303 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004304 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004305 } catch (ImsException e) {
4306 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004307 } finally {
4308 Binder.restoreCallingIdentity(identity);
4309 }
4310 }
4311
shilu366312e2019-12-17 09:28:10 -08004312 /**
4313 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4314 * @param subId The subscription to use to check the configuration.
4315 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004316 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004317 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004318 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004319 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004320 final long identity = Binder.clearCallingIdentity();
4321 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004322 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004323 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004324 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004325 } catch (ImsException e) {
4326 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004327 } finally {
4328 Binder.restoreCallingIdentity(identity);
4329 }
4330 }
4331
4332 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004333 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004334 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004335 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004336 final long identity = Binder.clearCallingIdentity();
4337 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004338 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004339 // This setting doesn't require an active ImsService connection, so do not verify. The
4340 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004341 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004342 } catch (ImsException e) {
4343 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004344 } finally {
4345 Binder.restoreCallingIdentity(identity);
4346 }
4347 }
4348
shilu366312e2019-12-17 09:28:10 -08004349 /**
4350 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4351 * @param subId The subscription to use to check the configuration.
4352 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004353 @Override
4354 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004355 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004356 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004357 final long identity = Binder.clearCallingIdentity();
4358 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004359 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004360 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004361 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004362 } catch (ImsException e) {
4363 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004364 } finally {
4365 Binder.restoreCallingIdentity(identity);
4366 }
4367 }
4368
4369 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004370 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004371 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004372 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004373 final long identity = Binder.clearCallingIdentity();
4374 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004375 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004376 // This setting doesn't require an active ImsService connection, so do not verify. The
4377 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004378 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004379 } catch (ImsException e) {
4380 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004381 } finally {
4382 Binder.restoreCallingIdentity(identity);
4383 }
4384 }
4385
shilu366312e2019-12-17 09:28:10 -08004386 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004387 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4388 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4389 * @param subId The subscription to use to check the configuration.
4390 */
4391 @Override
4392 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004393 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004394 mApp, subId, "isCrossSimCallingEnabledByUser");
4395 final long identity = Binder.clearCallingIdentity();
4396 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004397 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004398 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004399 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004400 } catch (ImsException e) {
4401 throw new ServiceSpecificException(e.getCode());
4402 } finally {
4403 Binder.restoreCallingIdentity(identity);
4404 }
4405 }
4406
4407 /**
4408 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4409 * Requires MODIFY_PHONE_STATE permission.
4410 * @param subId The subscription to use to check the configuration.
4411 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4412 * false otherwise
4413 */
4414 @Override
4415 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4416 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4417 "setCrossSimCallingEnabled");
4418 final long identity = Binder.clearCallingIdentity();
4419 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004420 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004421 // This setting doesn't require an active ImsService connection, so do not verify. The
4422 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004423 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004424 } catch (ImsException e) {
4425 throw new ServiceSpecificException(e.getCode());
4426 } finally {
4427 Binder.restoreCallingIdentity(identity);
4428 }
4429 }
4430
4431 /**
shilu366312e2019-12-17 09:28:10 -08004432 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4433 * @param subId The subscription to use to check the configuration.
4434 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004435 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004436
Brad Ebinger35c841c2018-10-01 10:40:55 -07004437 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004438 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004439 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004440 final long identity = Binder.clearCallingIdentity();
4441 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004442 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004443 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004444 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004445 } catch (ImsException e) {
4446 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004447 } finally {
4448 Binder.restoreCallingIdentity(identity);
4449 }
4450 }
4451
4452 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004453 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004454 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004455 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004456 final long identity = Binder.clearCallingIdentity();
4457 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004458 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004459 // This setting doesn't require an active ImsService connection, so do not verify. The
4460 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004461 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004462 } catch (ImsException e) {
4463 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004464 } finally {
4465 Binder.restoreCallingIdentity(identity);
4466 }
4467 }
4468
4469 @Override
4470 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4471 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4472 "setVoWiFiNonPersistent");
4473 final long identity = Binder.clearCallingIdentity();
4474 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004475 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004476 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004477 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004478 } catch (ImsException e) {
4479 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004480 } finally {
4481 Binder.restoreCallingIdentity(identity);
4482 }
4483 }
4484
shilu366312e2019-12-17 09:28:10 -08004485 /**
4486 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4487 * @param subId The subscription to use to check the configuration.
4488 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004489 @Override
4490 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004491 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004492 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004493 final long identity = Binder.clearCallingIdentity();
4494 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004495 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004496 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004497 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004498 } catch (ImsException e) {
4499 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004500 } finally {
4501 Binder.restoreCallingIdentity(identity);
4502 }
4503 }
4504
4505 @Override
4506 public void setVoWiFiModeSetting(int subId, int mode) {
4507 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4508 "setVoWiFiModeSetting");
4509 final long identity = Binder.clearCallingIdentity();
4510 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004511 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004512 // This setting doesn't require an active ImsService connection, so do not verify. The
4513 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004514 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004515 } catch (ImsException e) {
4516 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004517 } finally {
4518 Binder.restoreCallingIdentity(identity);
4519 }
4520 }
4521
4522 @Override
4523 public int getVoWiFiRoamingModeSetting(int subId) {
4524 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4525 final long identity = Binder.clearCallingIdentity();
4526 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004527 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004528 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004529 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004530 } catch (ImsException e) {
4531 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004532 } finally {
4533 Binder.restoreCallingIdentity(identity);
4534 }
4535 }
4536
4537 @Override
4538 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4539 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4540 "setVoWiFiRoamingModeSetting");
4541 final long identity = Binder.clearCallingIdentity();
4542 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004543 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004544 // This setting doesn't require an active ImsService connection, so do not verify. The
4545 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004546 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004547 } catch (ImsException e) {
4548 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004549 } finally {
4550 Binder.restoreCallingIdentity(identity);
4551 }
4552 }
4553
4554 @Override
4555 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4556 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4557 "setRttCapabilityEnabled");
4558 final long identity = Binder.clearCallingIdentity();
4559 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004560 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004561 // This setting doesn't require an active ImsService connection, so do not verify. The
4562 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004563 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004564 } catch (ImsException e) {
4565 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004566 } finally {
4567 Binder.restoreCallingIdentity(identity);
4568 }
4569 }
4570
shilu366312e2019-12-17 09:28:10 -08004571 /**
4572 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4573 * @param subId The subscription to use to check the configuration.
4574 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004575 @Override
4576 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004577 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004578 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004579 final long identity = Binder.clearCallingIdentity();
4580 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004581 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004582 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004583 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004584 } catch (ImsException e) {
4585 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004586 } finally {
4587 Binder.restoreCallingIdentity(identity);
4588 }
4589 }
4590
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004591 @Override
4592 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4593 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4594 final long identity = Binder.clearCallingIdentity();
4595 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004596 if (!isImsAvailableOnDevice()) {
4597 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4598 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004599 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004600 int slotId = getSlotIndexOrException(subId);
4601 verifyImsMmTelConfiguredOrThrow(slotId);
4602 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004603 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004604 } catch (ImsException e) {
4605 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004606 } finally {
4607 Binder.restoreCallingIdentity(identity);
4608 }
4609 }
4610
4611 @Override
4612 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4613 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4614 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004615 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4616 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4617 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004618 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004619 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004620 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004621 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004622 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4623 + "is inactive, ignoring unregister.");
4624 // If the subscription is no longer active, just return, since the callback will already
4625 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004626 } finally {
4627 Binder.restoreCallingIdentity(identity);
4628 }
4629 }
4630
allenwtsu99c623b2020-01-03 18:24:23 +08004631
4632 private void checkModifyPhoneStatePermission(int subId, String message) {
4633 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4634 message);
4635 }
4636
4637 private boolean isImsProvisioningRequired(int subId, int capability,
4638 boolean isMmtelCapability) {
4639 Phone phone = getPhone(subId);
4640 if (phone == null) {
4641 loge("phone instance null for subid " + subId);
4642 return false;
4643 }
4644 if (isMmtelCapability) {
4645 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4646 return false;
4647 }
4648 } else {
4649 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4650 return false;
4651 }
4652 }
4653 return true;
4654 }
4655
4656 @Override
4657 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4658 boolean isProvisioned) {
4659 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4660
4661 final long identity = Binder.clearCallingIdentity();
4662 try {
4663 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4664 if (!isImsProvisioningRequired(subId, capability, false)) {
4665 return;
4666 }
4667
4668 // this capability requires provisioning, route to the correct API.
4669 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4670 switch (capability) {
4671 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4672 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4673 ims.setEabProvisioned(isProvisioned);
4674 break;
4675 default: {
4676 throw new IllegalArgumentException("Tried to set provisioning for "
4677 + "rcs capability '" + capability + "', which does not require "
4678 + "provisioning.");
4679 }
4680 }
4681 } finally {
4682 Binder.restoreCallingIdentity(identity);
4683 }
4684
4685 }
4686
4687
4688 @Override
4689 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4690 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4691 final long identity = Binder.clearCallingIdentity();
4692 try {
4693 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4694 if (!isImsProvisioningRequired(subId, capability, false)) {
4695 return true;
4696 }
4697
4698 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4699 switch (capability) {
4700 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4701 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4702 return ims.isEabProvisionedOnDevice();
4703
4704 default: {
4705 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4706 + "capability '" + capability + "', which does not require "
4707 + "provisioning.");
4708 }
4709 }
4710
4711 } finally {
4712 Binder.restoreCallingIdentity(identity);
4713 }
4714 }
4715
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004716 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004717 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4718 boolean isProvisioned) {
4719 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004720 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4721 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4722 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004723 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4724 }
allenwtsu99c623b2020-01-03 18:24:23 +08004725 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004726 final long identity = Binder.clearCallingIdentity();
4727 try {
4728 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004729 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004730 return;
4731 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004732 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4733 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4734 loge("setImsProvisioningStatusForCapability: called for technology that does "
4735 + "not support provisioning - " + tech);
4736 return;
4737 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004738
4739 // this capability requires provisioning, route to the correct API.
4740 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4741 switch (capability) {
4742 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4743 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4744 ims.setVolteProvisioned(isProvisioned);
4745 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4746 ims.setWfcProvisioned(isProvisioned);
4747 }
4748 break;
4749 }
4750 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4751 // There is currently no difference in VT provisioning type.
4752 ims.setVtProvisioned(isProvisioned);
4753 break;
4754 }
4755 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4756 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4757 // change the capability of the feature instead if needed.
4758 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4759 == isProvisioned) {
4760 // No change in provisioning.
4761 return;
4762 }
4763 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4764 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004765 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004766 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004767 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4768 + ", Exception" + e.getMessage());
4769 }
4770 break;
4771 }
4772 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004773 throw new IllegalArgumentException("Tried to set provisioning for "
4774 + "MmTel capability '" + capability + "', which does not require "
4775 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004776 }
4777 }
4778
4779 } finally {
4780 Binder.restoreCallingIdentity(identity);
4781 }
4782 }
4783
4784 @Override
4785 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4786 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004787 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4788 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4789 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004790 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4791 }
4792 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4793 final long identity = Binder.clearCallingIdentity();
4794 try {
4795 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004796 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004797 return true;
4798 }
4799
Brad Ebinger0d79c572021-04-17 15:20:49 -07004800 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4801 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4802 loge("getImsProvisioningStatusForCapability: called for technology that does "
4803 + "not support provisioning - " + tech);
4804 return true;
4805 }
4806
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004807 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4808 switch (capability) {
4809 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4810 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4811 return ims.isVolteProvisionedOnDevice();
4812 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4813 return ims.isWfcProvisionedOnDevice();
4814 }
4815 // This should never happen, since we are checking tech above to make sure it
4816 // is either LTE or IWLAN.
4817 throw new IllegalArgumentException("Invalid radio technology for voice "
4818 + "capability.");
4819 }
4820 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4821 // There is currently no difference in VT provisioning type.
4822 return ims.isVtProvisionedOnDevice();
4823 }
4824 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4825 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4826 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4827 }
4828 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004829 throw new IllegalArgumentException(
4830 "Tried to get provisioning for MmTel capability '" + capability
4831 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004832 }
4833 }
4834
4835 } finally {
4836 Binder.restoreCallingIdentity(identity);
4837 }
4838 }
4839
4840 @Override
4841 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4842 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4843 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4844 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4845 }
4846 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4847 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4848 return (provisionedBits & capability) > 0;
4849 }
4850
4851 @Override
4852 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4853 boolean isProvisioned) {
4854 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4855 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4856 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4857 }
4858 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4859 "setProvisioningStatusForCapability");
4860 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4861 // If the current provisioning status for capability already matches isProvisioned,
4862 // do nothing.
4863 if (((provisionedBits & capability) > 0) == isProvisioned) {
4864 return;
4865 }
4866 if (isProvisioned) {
4867 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4868 } else {
4869 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4870 }
4871 }
4872
4873 /**
4874 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4875 * technology. The bitfield should mirror the bitfield defined by
4876 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4877 */
4878 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4879 String key = getMmTelProvisioningKey(subId, tech);
4880 // Default is no capabilities are provisioned.
4881 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4882 }
4883
4884 /**
4885 * Sets the MmTel capability provisioning bitfield (defined by
4886 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4887 * technology specified.
4888 *
4889 * Note: This is a synchronous command and should not be called on UI thread.
4890 */
4891 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4892 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4893 String key = getMmTelProvisioningKey(subId, tech);
4894 editor.putInt(key, newField);
4895 editor.commit();
4896 }
4897
4898 private static String getMmTelProvisioningKey(int subId, int tech) {
4899 // resulting key is provision_ims_mmtel_{subId}_{tech}
4900 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4901 }
4902
4903 /**
4904 * Query CarrierConfig to see if the specified capability requires provisioning for the
4905 * carrier associated with the subscription id.
4906 */
4907 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4908 int capability) {
4909 CarrierConfigManager configManager = new CarrierConfigManager(context);
4910 PersistableBundle c = configManager.getConfigForSubId(subId);
4911 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004912 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004913 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4914 false);
4915 boolean requireVoiceVtProvisioning = c.getBoolean(
4916 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4917
4918 // First check to make sure that the capability requires provisioning.
4919 switch (capability) {
4920 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4921 // intentional fallthrough
4922 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4923 if (requireVoiceVtProvisioning) {
4924 // Voice and Video requires provisioning
4925 return true;
4926 }
4927 break;
4928 }
4929 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4930 if (requireUtProvisioning) {
4931 // UT requires provisioning
4932 return true;
4933 }
4934 break;
4935 }
4936 }
4937 return false;
4938 }
4939
allenwtsu99c623b2020-01-03 18:24:23 +08004940 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4941 int capability) {
4942 CarrierConfigManager configManager = new CarrierConfigManager(context);
4943 PersistableBundle c = configManager.getConfigForSubId(subId);
4944
4945 boolean requireRcsProvisioning = c.getBoolean(
4946 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4947
4948 // First check to make sure that the capability requires provisioning.
4949 switch (capability) {
4950 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4951 // intentional fallthrough
4952 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4953 if (requireRcsProvisioning) {
4954 // OPTION or PRESENCE requires provisioning
4955 return true;
4956 }
4957 break;
4958 }
4959 }
4960 return false;
4961 }
4962
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004963 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004964 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004965 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4966 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4967 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004968 enforceReadPrivilegedPermission("getImsProvisioningInt");
4969 final long identity = Binder.clearCallingIdentity();
4970 try {
4971 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004972 int slotId = getSlotIndex(subId);
4973 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4974 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4975 + subId + "' for key:" + key);
4976 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4977 }
calvinpanb5a34062021-02-08 19:59:36 +08004978 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004979 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004980 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4981 + subId + "' for key:" + key);
4982 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004983 } finally {
4984 Binder.restoreCallingIdentity(identity);
4985 }
4986 }
4987
4988 @Override
4989 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004990 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4991 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4992 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004993 enforceReadPrivilegedPermission("getImsProvisioningString");
4994 final long identity = Binder.clearCallingIdentity();
4995 try {
4996 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004997 int slotId = getSlotIndex(subId);
4998 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4999 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5000 + subId + "' for key:" + key);
5001 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5002 }
calvinpanb5a34062021-02-08 19:59:36 +08005003 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005004 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005005 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5006 + subId + "' for key:" + key);
5007 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005008 } finally {
5009 Binder.restoreCallingIdentity(identity);
5010 }
5011 }
5012
5013 @Override
5014 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005015 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5016 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5017 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005018 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5019 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005020 final long identity = Binder.clearCallingIdentity();
5021 try {
5022 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005023 int slotId = getSlotIndex(subId);
5024 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5025 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5026 + subId + "' for key:" + key);
5027 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5028 }
calvinpanb5a34062021-02-08 19:59:36 +08005029 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5030 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005031 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005032 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005033 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005034 } finally {
5035 Binder.restoreCallingIdentity(identity);
5036 }
5037 }
5038
5039 @Override
5040 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005041 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5042 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5043 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005044 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5045 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005046 final long identity = Binder.clearCallingIdentity();
5047 try {
5048 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005049 int slotId = getSlotIndex(subId);
5050 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5051 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5052 + subId + "' for key:" + key);
5053 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5054 }
calvinpanb5a34062021-02-08 19:59:36 +08005055 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5056 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005057 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005058 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005059 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005060 } finally {
5061 Binder.restoreCallingIdentity(identity);
5062 }
5063 }
5064
Brad Ebinger919631e2021-06-02 17:46:35 -07005065 /**
5066 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5067 * for the given slot ID or no ImsResolver instance has been created.
5068 * @param slotId The slot ID that the IMS service is created for.
5069 * @throws ImsException If there is no ImsService configured for this slot.
5070 */
5071 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5072 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5073 ImsFeature.FEATURE_MMTEL)) {
5074 throw new ImsException("This subscription does not support MMTEL over IMS",
5075 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5076 }
5077 }
5078
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005079 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005080 int slotId = SubscriptionManager.getSlotIndex(subId);
5081 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005082 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5083 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005084 }
5085 return slotId;
5086 }
5087
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005088 private int getSlotIndex(int subId) {
5089 int slotId = SubscriptionManager.getSlotIndex(subId);
5090 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5091 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5092 }
5093 return slotId;
5094 }
5095
Wink Saville36469e72014-06-11 15:17:00 -07005096 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005097 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005098 */
5099 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005100 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5101 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005102 try {
5103 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5104 } catch (SecurityException se) {
5105 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5106 throw new SecurityException("Package " + callingPackage + " does not belong to "
5107 + Binder.getCallingUid());
5108 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005109 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005110 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005111 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005112 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005113 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005114 mApp, subId, callingPackage, callingFeatureId,
5115 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005116 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5117 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005118
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005119 final long identity = Binder.clearCallingIdentity();
5120 try {
5121 final Phone phone = getPhone(subId);
5122 if (phone != null) {
5123 return phone.getServiceState().getDataNetworkType();
5124 } else {
5125 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5126 }
5127 } finally {
5128 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005129 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005130 }
5131
5132 /**
5133 * Returns the data network type
5134 */
5135 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005136 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005137 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5138 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005139 }
5140
5141 /**
5142 * Returns the data network type for a subId
5143 */
5144 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005145 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5146 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005147 String functionName = "getDataNetworkTypeForSubscriber";
5148 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5149 mApp, functionName)) {
5150 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5151 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5152 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5153 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005154 }
5155
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005156 final long identity = Binder.clearCallingIdentity();
5157 try {
5158 final Phone phone = getPhone(subId);
5159 if (phone != null) {
5160 return phone.getServiceState().getDataNetworkType();
5161 } else {
5162 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5163 }
5164 } finally {
5165 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005166 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005167 }
5168
5169 /**
Wink Saville36469e72014-06-11 15:17:00 -07005170 * Returns the Voice network type for a subId
5171 */
5172 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005173 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5174 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005175 String functionName = "getVoiceNetworkTypeForSubscriber";
5176 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5177 mApp, functionName)) {
5178 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5179 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5180 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5181 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005182 }
5183
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005184 final long identity = Binder.clearCallingIdentity();
5185 try {
5186 final Phone phone = getPhone(subId);
5187 if (phone != null) {
5188 return phone.getServiceState().getVoiceNetworkType();
5189 } else {
5190 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5191 }
5192 } finally {
5193 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005194 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005195 }
5196
5197 /**
5198 * @return true if a ICC card is present
5199 */
5200 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005201 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005202 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5203 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005204 }
5205
5206 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005207 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005208 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005209 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005210 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005211 final long identity = Binder.clearCallingIdentity();
5212 try {
5213 final Phone phone = PhoneFactory.getPhone(slotIndex);
5214 if (phone != null) {
5215 return phone.getIccCard().hasIccCard();
5216 } else {
5217 return false;
5218 }
5219 } finally {
5220 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005221 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005222 }
5223
5224 /**
5225 * Return if the current radio is LTE on CDMA. This
5226 * is a tri-state return value as for a period of time
5227 * the mode may be unknown.
5228 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005229 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005230 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005231 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005232 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005233 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005234 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5235 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5236 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005237 }
5238
Sanket Padawe356d7632015-06-22 14:03:32 -07005239 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005240 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5241 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005242 try {
5243 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5244 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005245 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5246 }
5247
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005248 final long identity = Binder.clearCallingIdentity();
5249 try {
5250 final Phone phone = getPhone(subId);
5251 if (phone == null) {
5252 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5253 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005254 return TelephonyProperties.lte_on_cdma_device()
5255 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005256 }
5257 } finally {
5258 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005259 }
Wink Saville36469e72014-06-11 15:17:00 -07005260 }
5261
Wink Saville36469e72014-06-11 15:17:00 -07005262 /**
5263 * {@hide}
5264 * Returns Default subId, 0 in the case of single standby.
5265 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005266 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005267 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005268 }
5269
Shishir Agrawala9f32182016-04-12 12:00:16 -07005270 private int getSlotForDefaultSubscription() {
5271 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5272 }
5273
Wink Savilleb564aae2014-10-23 10:18:09 -07005274 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005275 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005276 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005277
Pengquan Menge92a50d2018-09-21 15:54:48 -07005278 private boolean isActiveSubscription(int subId) {
5279 return mSubscriptionController.isActiveSubId(subId);
5280 }
5281
Ihab Awadf2177b72013-11-25 13:33:23 -08005282 /**
5283 * @see android.telephony.TelephonyManager.WifiCallingChoices
5284 */
5285 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005286 final long identity = Binder.clearCallingIdentity();
5287 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005288 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005289 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5290 getWhenToMakeWifiCallsDefaultPreference());
5291 } finally {
5292 Binder.restoreCallingIdentity(identity);
5293 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005294 }
5295
5296 /**
5297 * @see android.telephony.TelephonyManager.WifiCallingChoices
5298 */
5299 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005300 final long identity = Binder.clearCallingIdentity();
5301 try {
5302 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005303 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005304 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5305 } finally {
5306 Binder.restoreCallingIdentity(identity);
5307 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005308 }
5309
Sailesh Nepald1e68152013-12-12 19:08:02 -08005310 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005311 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005312 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005313 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005314
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005315 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5316 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5317 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005318 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005319 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5320 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005321 }
5322 return PhoneFactory.getPhone(phoneId);
5323 }
5324
Shishir Agrawal566b7612013-10-28 14:41:00 -07005325 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005326 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005327 @NonNull IccLogicalChannelRequest request) {
5328 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5329 /*message=*/ "iccOpenLogicalChannel");
5330
5331 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5332 // Verify that the callingPackage in the request belongs to the calling UID
5333 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5334
5335 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005336 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005337
Rambo Wanga1782702021-11-10 20:15:19 -08005338 private Phone getPhoneFromValidIccLogicalChannelRequest(
5339 @NonNull IccLogicalChannelRequest request, String message) {
5340 Phone phone;
5341 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5342 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5343 mApp, request.subId, message);
5344 phone = getPhoneFromSubId(request.subId);
5345 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5346 enforceModifyPermission();
5347 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5348 } else {
5349 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005350 }
Rambo Wanga1782702021-11-10 20:15:19 -08005351 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005352 }
5353
5354 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005355 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005356 final long identity = Binder.clearCallingIdentity();
5357 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005358 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005359 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005360 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5361 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005362 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5363 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005364 loge("The calling package is not allowed to access ISD-R.");
5365 throw new SecurityException(
5366 "The calling package is not allowed to access ISD-R.");
5367 }
Derek Tan740e1672017-06-27 14:56:27 -07005368 }
Derek Tan740e1672017-06-27 14:56:27 -07005369
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005370 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005371 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5372 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005373 return response;
5374 } finally {
5375 Binder.restoreCallingIdentity(identity);
5376 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005377 }
5378
5379 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005380 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5381 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5382 /*message=*/"iccCloseLogicalChannel");
5383
5384 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5385
5386 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005387 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005388
Rambo Wanga1782702021-11-10 20:15:19 -08005389 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5390 IccLogicalChannelRequest request) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005391 final long identity = Binder.clearCallingIdentity();
5392 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005393 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005394 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005395 }
Rambo Wanga1782702021-11-10 20:15:19 -08005396 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005397 null /* workSource */);
Rambo Wanga1782702021-11-10 20:15:19 -08005398 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005399 return success;
5400 } finally {
5401 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005402 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005403 }
5404
5405 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005406 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005407 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005408 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5409 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005410 if (DBG) {
5411 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5412 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5413 + p3 + " data=" + data);
5414 }
5415 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5416 command, p1, p2, p3, data);
5417 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005418
Jordan Liu4c733742019-02-28 12:03:40 -08005419 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005420 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5421 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005422 enforceModifyPermission();
5423 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005424 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5425 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5426 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005427 }
5428 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005429 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5430 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005431 }
5432
5433 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5434 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005435 final long identity = Binder.clearCallingIdentity();
5436 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005437 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005438 return "";
5439 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005440
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005441 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005442 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5443 null /* workSource */);
5444 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005445
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005446 // Append the returned status code to the end of the response payload.
5447 String s = Integer.toHexString(
5448 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5449 if (response.payload != null) {
5450 s = IccUtils.bytesToHexString(response.payload) + s;
5451 }
5452 return s;
5453 } finally {
5454 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005455 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005456 }
Jake Hambye994d462014-02-03 13:10:13 -08005457
Evan Charltonc66da362014-05-16 14:06:40 -07005458 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005459 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5460 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005461 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5462 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005463 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005464 if (DBG) {
5465 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5466 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5467 }
5468 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5469 cla, command, p1, p2, p3, data);
5470 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005471
Jordan Liu4c733742019-02-28 12:03:40 -08005472 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005473 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5474 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005475 enforceModifyPermission();
5476 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5477 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005478 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5479 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5480 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005481 }
5482
5483 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005484 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5485 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005486 }
5487
5488 // open APDU basic channel assuming the caller has sufficient permissions
5489 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5490 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005491 final long identity = Binder.clearCallingIdentity();
5492 try {
5493 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5494 && TextUtils.equals(ISDR_AID, data)) {
5495 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005496 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5497 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005498 if (bestComponent == null
5499 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5500 loge("The calling package is not allowed to select ISD-R.");
5501 throw new SecurityException(
5502 "The calling package is not allowed to select ISD-R.");
5503 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005504 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005505
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005506 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005507 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5508 null /* workSource */);
5509 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005510
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005511 // Append the returned status code to the end of the response payload.
5512 String s = Integer.toHexString(
5513 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5514 if (response.payload != null) {
5515 s = IccUtils.bytesToHexString(response.payload) + s;
5516 }
5517 return s;
5518 } finally {
5519 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005520 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005521 }
5522
5523 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005524 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005525 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005526 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5527 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005528
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005529 final long identity = Binder.clearCallingIdentity();
5530 try {
5531 if (DBG) {
5532 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5533 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5534 }
5535
5536 IccIoResult response =
5537 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5538 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5539 subId);
5540
5541 if (DBG) {
5542 log("Exchange SIM_IO [R]" + response);
5543 }
5544
5545 byte[] result = null;
5546 int length = 2;
5547 if (response.payload != null) {
5548 length = 2 + response.payload.length;
5549 result = new byte[length];
5550 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5551 } else {
5552 result = new byte[length];
5553 }
5554
5555 result[length - 1] = (byte) response.sw2;
5556 result[length - 2] = (byte) response.sw1;
5557 return result;
5558 } finally {
5559 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005560 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005561 }
5562
Nathan Haroldb3014052017-01-25 15:57:32 -08005563 /**
5564 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5565 * on a particular subscription
5566 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005567 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5568 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005569 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005570 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005571 return null;
5572 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005573
5574 final long identity = Binder.clearCallingIdentity();
5575 try {
5576 if (appType != TelephonyManager.APPTYPE_USIM
5577 && appType != TelephonyManager.APPTYPE_SIM) {
5578 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5579 return null;
5580 }
5581 Object response = sendRequest(
5582 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5583 if (response instanceof String[]) {
5584 return (String[]) response;
5585 }
yincheng zhao2737e882019-09-06 17:06:54 -07005586 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005587 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005588 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005589 } finally {
5590 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005591 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005592 }
5593
yincheng zhao2737e882019-09-06 17:06:54 -07005594 /**
5595 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5596 * subscription.
5597 *
5598 * @param subId the id of the subscription.
5599 * @param appType the uicc app type, must be USIM or SIM.
5600 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5601 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005602 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005603 * @return number of fplmns that is successfully written to the SIM.
5604 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005605 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5606 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005607 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5608 mApp, subId, "setForbiddenPlmns");
5609
yincheng zhao2737e882019-09-06 17:06:54 -07005610 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5611 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5612 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5613 }
5614 if (fplmns == null) {
5615 throw new IllegalArgumentException("Fplmn List provided is null");
5616 }
5617 for (String fplmn : fplmns) {
5618 if (!CellIdentity.isValidPlmn(fplmn)) {
5619 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5620 }
5621 }
5622 final long identity = Binder.clearCallingIdentity();
5623 try {
5624 Object response = sendRequest(
5625 CMD_SET_FORBIDDEN_PLMNS,
5626 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5627 subId);
5628 return (int) response;
5629 } finally {
5630 Binder.restoreCallingIdentity(identity);
5631 }
5632 }
5633
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005634 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005635 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005636 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5637 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005638
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005639 final long identity = Binder.clearCallingIdentity();
5640 try {
5641 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5642 if (response.payload == null) {
5643 return "";
5644 }
Evan Charltonc66da362014-05-16 14:06:40 -07005645
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005646 // Append the returned status code to the end of the response payload.
5647 String s = Integer.toHexString(
5648 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5649 s = IccUtils.bytesToHexString(response.payload) + s;
5650 return s;
5651 } finally {
5652 Binder.restoreCallingIdentity(identity);
5653 }
Evan Charltonc66da362014-05-16 14:06:40 -07005654 }
5655
Jake Hambye994d462014-02-03 13:10:13 -08005656 /**
5657 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5658 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5659 *
5660 * @param itemID the ID of the item to read
5661 * @return the NV item as a String, or null on error.
5662 */
5663 @Override
5664 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005665 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005666 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5667 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005668
5669 final long identity = Binder.clearCallingIdentity();
5670 try {
5671 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005672 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005673 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5674 return value;
5675 } finally {
5676 Binder.restoreCallingIdentity(identity);
5677 }
Jake Hambye994d462014-02-03 13:10:13 -08005678 }
5679
5680 /**
5681 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5682 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5683 *
5684 * @param itemID the ID of the item to read
5685 * @param itemValue the value to write, as a String
5686 * @return true on success; false on any failure
5687 */
5688 @Override
5689 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005690 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005691 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5692 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005693
5694 final long identity = Binder.clearCallingIdentity();
5695 try {
5696 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5697 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005698 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005699 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5700 return success;
5701 } finally {
5702 Binder.restoreCallingIdentity(identity);
5703 }
Jake Hambye994d462014-02-03 13:10:13 -08005704 }
5705
5706 /**
5707 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5708 * Used for device configuration by some CDMA operators.
5709 *
5710 * @param preferredRoamingList byte array containing the new PRL
5711 * @return true on success; false on any failure
5712 */
5713 @Override
5714 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005715 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5716 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005717
5718 final long identity = Binder.clearCallingIdentity();
5719 try {
5720 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5721 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5722 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5723 return success;
5724 } finally {
5725 Binder.restoreCallingIdentity(identity);
5726 }
Jake Hambye994d462014-02-03 13:10:13 -08005727 }
5728
5729 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005730 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005731 * Used for device configuration by some CDMA operators.
5732 *
chen xu6dac5ab2018-10-26 17:39:23 -07005733 * @param slotIndex - device slot.
5734 *
Jake Hambye994d462014-02-03 13:10:13 -08005735 * @return true on success; false on any failure
5736 */
5737 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005738 public boolean resetModemConfig(int slotIndex) {
5739 Phone phone = PhoneFactory.getPhone(slotIndex);
5740 if (phone != null) {
5741 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5742 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005743
chen xu6dac5ab2018-10-26 17:39:23 -07005744 final long identity = Binder.clearCallingIdentity();
5745 try {
5746 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5747 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5748 return success;
5749 } finally {
5750 Binder.restoreCallingIdentity(identity);
5751 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005752 }
chen xu6dac5ab2018-10-26 17:39:23 -07005753 return false;
5754 }
5755
5756 /**
5757 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5758 *
5759 * @param slotIndex - device slot.
5760 *
5761 * @return true on success; false on any failure
5762 */
5763 @Override
5764 public boolean rebootModem(int slotIndex) {
5765 Phone phone = PhoneFactory.getPhone(slotIndex);
5766 if (phone != null) {
5767 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5768 mApp, phone.getSubId(), "rebootModem");
5769
5770 final long identity = Binder.clearCallingIdentity();
5771 try {
5772 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5773 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5774 return success;
5775 } finally {
5776 Binder.restoreCallingIdentity(identity);
5777 }
5778 }
5779 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005780 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005781
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005782 public String[] getPcscfAddress(String apnType, String callingPackage,
5783 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005784 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005785 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5786 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005787 return new String[0];
5788 }
5789
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005790 final long identity = Binder.clearCallingIdentity();
5791 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005792 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005793 } finally {
5794 Binder.restoreCallingIdentity(identity);
5795 }
Wink Saville36469e72014-06-11 15:17:00 -07005796 }
5797
Brad Ebinger51f743a2017-01-23 13:50:20 -08005798 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005799 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5800 * {@link #disableIms(int)}.
5801 * @param slotIndex device slot.
5802 */
5803 public void resetIms(int slotIndex) {
5804 enforceModifyPermission();
5805
5806 final long identity = Binder.clearCallingIdentity();
5807 try {
5808 if (mImsResolver == null) {
5809 // may happen if the does not support IMS.
5810 return;
5811 }
5812 mImsResolver.disableIms(slotIndex);
5813 mImsResolver.enableIms(slotIndex);
5814 } finally {
5815 Binder.restoreCallingIdentity(identity);
5816 }
5817 }
5818
5819 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005820 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5821 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005822 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005823 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005824 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005825
5826 final long identity = Binder.clearCallingIdentity();
5827 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005828 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005829 // may happen if the device does not support IMS.
5830 return;
5831 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005832 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005833 } finally {
5834 Binder.restoreCallingIdentity(identity);
5835 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005836 }
5837
5838 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005839 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5840 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005841 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005842 public void disableIms(int slotId) {
5843 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005844
5845 final long identity = Binder.clearCallingIdentity();
5846 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005847 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005848 // may happen if the device does not support IMS.
5849 return;
5850 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005851 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005852 } finally {
5853 Binder.restoreCallingIdentity(identity);
5854 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005855 }
5856
5857 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005858 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5859 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005860 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005861 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005862 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005863 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005864
5865 final long identity = Binder.clearCallingIdentity();
5866 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005867 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005868 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5869 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005870 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005871 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005872 } finally {
5873 Binder.restoreCallingIdentity(identity);
5874 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005875 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005876 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005877 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5878 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005879 @Override
5880 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005881 enforceModifyPermission();
5882
5883 final long identity = Binder.clearCallingIdentity();
5884 try {
5885 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005886 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005887 } finally {
5888 Binder.restoreCallingIdentity(identity);
5889 }
5890 }
5891
5892 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005893 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005894 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005895 */
5896 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5897 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005898
5899 final long identity = Binder.clearCallingIdentity();
5900 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005901 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005902 // may happen if the device does not support IMS.
5903 return null;
5904 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005905 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005906 } finally {
5907 Binder.restoreCallingIdentity(identity);
5908 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005909 }
5910
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005911 /**
5912 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005913 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005914 */
5915 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5916 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005917
5918 final long identity = Binder.clearCallingIdentity();
5919 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005920 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005921 // may happen if the device does not support IMS.
5922 return null;
5923 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005924 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005925 } finally {
5926 Binder.restoreCallingIdentity(identity);
5927 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005928 }
5929
Brad Ebinger884c07b2018-02-15 16:17:40 -08005930 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005931 * Sets the ImsService Package Name that Telephony will bind to.
5932 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005933 * @param slotIndex the slot ID that the ImsService should bind for.
5934 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005935 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005936 * @param featureTypes An integer array of feature types associated with a packageName.
5937 * @param packageName The name of the package that the current configuration will be replaced
5938 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005939 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005940 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005941 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5942 int[] featureTypes, String packageName) {
5943 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5944 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005945 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5946 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005947 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005948
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005949 final long identity = Binder.clearCallingIdentity();
5950 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005951 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005952 // may happen if the device does not support IMS.
5953 return false;
5954 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005955 Map<Integer, String> featureConfig = new HashMap<>();
5956 for (int featureType : featureTypes) {
5957 featureConfig.put(featureType, packageName);
5958 }
5959 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5960 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005961 } finally {
5962 Binder.restoreCallingIdentity(identity);
5963 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005964 }
5965
5966 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005967 * Clears any carrier ImsService overrides for the slot index specified that were previously
5968 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5969 *
5970 * This should only be used for testing.
5971 *
5972 * @param slotIndex the slot ID that the ImsService should bind for.
5973 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5974 */
5975 @Override
5976 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5977 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5978 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5979 "clearCarrierImsServiceOverride");
5980 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5981 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5982 "clearCarrierImsServiceOverride");
5983
5984 final long identity = Binder.clearCallingIdentity();
5985 try {
5986 if (mImsResolver == null) {
5987 // may happen if the device does not support IMS.
5988 return false;
5989 }
5990 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5991 } finally {
5992 Binder.restoreCallingIdentity(identity);
5993 }
5994 }
5995
5996 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005997 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005998 *
5999 * @param slotId The slot that the ImsService is associated with.
6000 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6001 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006002 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006003 * @return the package name of the ImsService configuration.
6004 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006005 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6006 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07006007 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08006008 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006009 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08006010 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
6011 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006012
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006013 final long identity = Binder.clearCallingIdentity();
6014 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006015 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006016 // may happen if the device does not support IMS.
6017 return "";
6018 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006019 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006020 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6021 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006022 } finally {
6023 Binder.restoreCallingIdentity(identity);
6024 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006025 }
6026
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006027 /**
6028 * Get the MmTelFeature state associated with the requested subscription id.
6029 * @param subId The subscription that the MmTelFeature is associated with.
6030 * @param callback A callback with an integer containing the
6031 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6032 */
6033 @Override
6034 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6035 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
6036 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6037 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6038 "IMS not available on device.");
6039 }
6040 final long token = Binder.clearCallingIdentity();
6041 try {
6042 int slotId = getSlotIndex(subId);
6043 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6044 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6045 + subId + "'");
6046 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6047 }
Brad Ebinger919631e2021-06-02 17:46:35 -07006048 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006049 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6050 try {
6051 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6052 } catch (RemoteException e) {
6053 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6054 + "Ignore");
6055 }
6056 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006057 } catch (ImsException e) {
6058 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006059 } finally {
6060 Binder.restoreCallingIdentity(token);
6061 }
6062 }
6063
Daniel Brightbb5840b2021-01-12 15:48:18 -08006064 /**
6065 * Sets the ims registration state on all valid {@link Phone}s.
6066 */
6067 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006068 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006069
6070 final long identity = Binder.clearCallingIdentity();
6071 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006072 // NOTE: Before S, this method only set the default phone.
6073 for (final Phone phone : PhoneFactory.getPhones()) {
6074 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6075 phone.setImsRegistrationState(registered);
6076 }
6077 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006078 } finally {
6079 Binder.restoreCallingIdentity(identity);
6080 }
Wink Saville36469e72014-06-11 15:17:00 -07006081 }
6082
6083 /**
Stuart Scott54788802015-03-30 13:18:01 -07006084 * Set the network selection mode to automatic.
6085 *
6086 */
6087 @Override
6088 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006089 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6090 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006091
6092 final long identity = Binder.clearCallingIdentity();
6093 try {
shilufc958392020-01-20 11:36:01 -08006094 if (!isActiveSubscription(subId)) {
6095 return;
6096 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006097 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006098 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6099 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006100 } finally {
6101 Binder.restoreCallingIdentity(identity);
6102 }
Stuart Scott54788802015-03-30 13:18:01 -07006103 }
6104
Jack Yud10cdd42020-09-28 20:28:01 -07006105 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006106 * Ask the radio to connect to the input network and change selection mode to manual.
6107 *
6108 * @param subId the id of the subscription.
6109 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6110 * the operator to attach to.
6111 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6112 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6113 * normal network selection next time.
6114 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006115 */
6116 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006117 public boolean setNetworkSelectionModeManual(
6118 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006119 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6120 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006121
6122 if (!isActiveSubscription(subId)) {
6123 return false;
6124 }
6125
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006126 final long identity = Binder.clearCallingIdentity();
6127 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006128 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006129 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006130 if (DBG) {
6131 log("setNetworkSelectionModeManual: subId: " + subId
6132 + " operator: " + operatorInfo);
6133 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006134 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6135 } finally {
6136 Binder.restoreCallingIdentity(identity);
6137 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006138 }
shilu84f6e8b2019-12-19 13:58:01 -08006139 /**
6140 * Get the manual network selection
6141 *
6142 * @param subId the id of the subscription.
6143 *
6144 * @return the previously saved user selected PLMN
6145 */
6146 @Override
6147 public String getManualNetworkSelectionPlmn(int subId) {
6148 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006149 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006150 mApp, subId, "getManualNetworkSelectionPlmn");
6151
6152 final long identity = Binder.clearCallingIdentity();
6153 try {
6154 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006155 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006156 }
6157
6158 final Phone phone = getPhone(subId);
6159 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006160 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006161 }
6162 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6163 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6164 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6165 } finally {
6166 Binder.restoreCallingIdentity(identity);
6167 }
6168 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006169
6170 /**
6171 * Scans for available networks.
6172 */
6173 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006174 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6175 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006176 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6177 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006178 LocationAccessPolicy.LocationPermissionResult locationResult =
6179 LocationAccessPolicy.checkLocationPermission(mApp,
6180 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6181 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006182 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006183 .setCallingPid(Binder.getCallingPid())
6184 .setCallingUid(Binder.getCallingUid())
6185 .setMethod("getCellNetworkScanResults")
6186 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006187 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6188 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006189 .build());
6190 switch (locationResult) {
6191 case DENIED_HARD:
6192 throw new SecurityException("Not allowed to access scan results -- location");
6193 case DENIED_SOFT:
6194 return null;
6195 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006196
Pengquan Menga1bb6272018-09-06 09:59:22 -07006197 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006198 try {
6199 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006200 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006201 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006202 } finally {
6203 Binder.restoreCallingIdentity(identity);
6204 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006205 }
6206
6207 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006208 * Get the call forwarding info, given the call forwarding reason.
6209 */
6210 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006211 public void getCallForwarding(int subId, int callForwardingReason,
6212 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006213 enforceReadPrivilegedPermission("getCallForwarding");
6214 long identity = Binder.clearCallingIdentity();
6215 try {
6216 if (DBG) {
6217 log("getCallForwarding: subId " + subId
6218 + " callForwardingReason" + callForwardingReason);
6219 }
Hall Liu27d24262020-09-18 19:04:59 -07006220
6221 Phone phone = getPhone(subId);
6222 if (phone == null) {
6223 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006224 callback.onError(
6225 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006226 } catch (RemoteException e) {
6227 // ignore
6228 }
6229 return;
6230 }
6231
6232 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6233 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6234 @Override
6235 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6236 try {
6237 callback.onCallForwardingInfoAvailable(info);
6238 } catch (RemoteException e) {
6239 // ignore
6240 }
6241 }
6242
6243 @Override
6244 public void onError(int error) {
6245 try {
6246 callback.onError(error);
6247 } catch (RemoteException e) {
6248 // ignore
6249 }
6250 }
6251 });
6252 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006253 } finally {
6254 Binder.restoreCallingIdentity(identity);
6255 }
6256 }
6257
6258 /**
6259 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6260 * reason, the number to forward, and the timeout before the forwarding is attempted.
6261 */
6262 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006263 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6264 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006265 enforceModifyPermission();
6266 long identity = Binder.clearCallingIdentity();
6267 try {
6268 if (DBG) {
6269 log("setCallForwarding: subId " + subId
6270 + " callForwardingInfo" + callForwardingInfo);
6271 }
Hall Liu27d24262020-09-18 19:04:59 -07006272
6273 Phone phone = getPhone(subId);
6274 if (phone == null) {
6275 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006276 callback.accept(
6277 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006278 } catch (RemoteException e) {
6279 // ignore
6280 }
6281 return;
6282 }
6283
6284 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6285 FunctionalUtils.ignoreRemoteException(callback::accept));
6286
6287 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006288 } finally {
6289 Binder.restoreCallingIdentity(identity);
6290 }
6291 }
6292
6293 /**
Hall Liu27d24262020-09-18 19:04:59 -07006294 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006295 */
6296 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006297 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006298 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006299 long identity = Binder.clearCallingIdentity();
6300 try {
Hall Liu27d24262020-09-18 19:04:59 -07006301 Phone phone = getPhone(subId);
6302 if (phone == null) {
6303 try {
6304 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6305 } catch (RemoteException e) {
6306 // ignore
6307 }
6308 return;
6309 }
SongFerngWang0e767992021-03-31 22:08:45 +08006310 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6311 PersistableBundle c = configManager.getConfigForSubId(subId);
6312 boolean requireUssd = c.getBoolean(
6313 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006314
Shuo Qian4a594052020-01-23 11:59:30 -08006315 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006316 if (requireUssd) {
6317 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6318 getSubscriptionCarrierId(subId));
6319 String newUssdCommand = "";
6320 try {
6321 newUssdCommand = carrierXmlParser.getFeature(
6322 CarrierXmlParser.FEATURE_CALL_WAITING)
6323 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6324 } catch (NullPointerException e) {
6325 loge("Failed to generate USSD number" + e);
6326 }
6327 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6328 mMainThreadHandler, callback, carrierXmlParser,
6329 CarrierXmlParser.SsEntry.SSAction.QUERY);
6330 final String ussdCommand = newUssdCommand;
6331 Executors.newSingleThreadExecutor().execute(() -> {
6332 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6333 });
6334 } else {
6335 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6336 callback::accept);
6337 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6338 }
Shuo Qian4a594052020-01-23 11:59:30 -08006339 } finally {
6340 Binder.restoreCallingIdentity(identity);
6341 }
6342 }
6343
6344 /**
Hall Liu27d24262020-09-18 19:04:59 -07006345 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006346 */
6347 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006348 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006349 enforceModifyPermission();
6350 long identity = Binder.clearCallingIdentity();
6351 try {
Hall Liu27d24262020-09-18 19:04:59 -07006352 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6353
6354 Phone phone = getPhone(subId);
6355 if (phone == null) {
6356 try {
6357 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6358 } catch (RemoteException e) {
6359 // ignore
6360 }
6361 return;
6362 }
6363
SongFerngWang0e767992021-03-31 22:08:45 +08006364 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6365 PersistableBundle c = configManager.getConfigForSubId(subId);
6366 boolean requireUssd = c.getBoolean(
6367 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006368
SongFerngWang0e767992021-03-31 22:08:45 +08006369 if (DBG) log("getCallWaitingStatus: subId " + subId);
6370 if (requireUssd) {
6371 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6372 getSubscriptionCarrierId(subId));
6373 CarrierXmlParser.SsEntry.SSAction ssAction =
6374 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6375 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6376 String newUssdCommand = "";
6377 try {
6378 newUssdCommand = carrierXmlParser.getFeature(
6379 CarrierXmlParser.FEATURE_CALL_WAITING)
6380 .makeCommand(ssAction, null);
6381 } catch (NullPointerException e) {
6382 loge("Failed to generate USSD number" + e);
6383 }
6384 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6385 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6386 final String ussdCommand = newUssdCommand;
6387 Executors.newSingleThreadExecutor().execute(() -> {
6388 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6389 });
6390 } else {
6391 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6392 FunctionalUtils.ignoreRemoteException(callback::accept));
6393
6394 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6395 }
Shuo Qian4a594052020-01-23 11:59:30 -08006396 } finally {
6397 Binder.restoreCallingIdentity(identity);
6398 }
6399 }
6400
6401 /**
yinxub1bed742017-04-17 11:45:04 -07006402 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006403 *
yinxub1bed742017-04-17 11:45:04 -07006404 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006405 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6406 * location related information which will be sent if the caller already possess
6407 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006408 * @param request contains the radio access networks with bands/channels to scan
6409 * @param messenger callback messenger for scan results or errors
6410 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006411 * @return the id of the requested scan which can be used to stop the scan.
6412 */
6413 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006414 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6415 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006416 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006417 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6418 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006419 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006420 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6421 if (!renounceFineLocationAccess) {
6422 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6423 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6424 .setCallingPackage(callingPackage)
6425 .setCallingFeatureId(callingFeatureId)
6426 .setCallingPid(Binder.getCallingPid())
6427 .setCallingUid(Binder.getCallingUid())
6428 .setMethod("requestNetworkScan")
6429 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6430 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6431 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6432 .build());
6433 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006434 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006435 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6436 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006437 if (e != null) {
6438 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6439 throw e;
6440 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006441 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006442 return TelephonyScanManager.INVALID_SCAN_ID;
6443 }
6444 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006445 }
Hall Liu912dfd32019-04-25 14:02:26 -07006446 int callingUid = Binder.getCallingUid();
6447 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006448 final long identity = Binder.clearCallingIdentity();
6449 try {
6450 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006451 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006452 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006453 } finally {
6454 Binder.restoreCallingIdentity(identity);
6455 }
yinxu504e1392017-04-12 16:03:22 -07006456 }
6457
Hall Liub2ac8ef2019-02-28 15:56:23 -08006458 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006459 NetworkScanRequest request, int subId, String callingPackage) {
6460 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006461 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6462 boolean hasNetworkScanPermission =
6463 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6464 == PERMISSION_GRANTED;
6465
6466 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6467 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6468 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006469 }
6470
6471 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6472 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006473 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6474 return new SecurityException("Specific channels must not be"
6475 + " scanned without location access.");
6476 }
6477 }
6478 }
6479
Hall Liub2ac8ef2019-02-28 15:56:23 -08006480 return null;
6481 }
6482
yinxu504e1392017-04-12 16:03:22 -07006483 /**
6484 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006485 *
6486 * @param subId id of the subscription
6487 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006488 */
6489 @Override
6490 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006491 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6492 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006493
Hall Liu912dfd32019-04-25 14:02:26 -07006494 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006495 final long identity = Binder.clearCallingIdentity();
6496 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006497 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006498 } finally {
6499 Binder.restoreCallingIdentity(identity);
6500 }
yinxu504e1392017-04-12 16:03:22 -07006501 }
6502
6503 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006504 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006505 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006506 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006507 */
6508 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006509 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006510 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006511 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006512 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006513
6514 final long identity = Binder.clearCallingIdentity();
6515 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006516 if (DBG) log("getAllowedNetworkTypesBitmask");
6517 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6518 int networkTypesBitmask = (result != null ? result[0] : -1);
6519 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6520 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006521 } finally {
6522 Binder.restoreCallingIdentity(identity);
6523 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006524 }
6525
6526 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006527 * Get the allowed network types for certain reason.
6528 *
6529 * @param subId the id of the subscription.
6530 * @param reason the reason the allowed network type change is taking place
6531 * @return the allowed network types.
6532 */
6533 @Override
6534 public long getAllowedNetworkTypesForReason(int subId,
6535 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006536 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006537 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006538 final long identity = Binder.clearCallingIdentity();
6539 try {
6540 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6541 } finally {
6542 Binder.restoreCallingIdentity(identity);
6543 }
6544 }
6545
6546 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006547 * Enable/Disable E-UTRA-NR Dual Connectivity
6548 * @param subId subscription id of the sim card
6549 * @param nrDualConnectivityState expected NR dual connectivity state
6550 * This can be passed following states
6551 * <ol>
6552 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6553 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6554 * <li>Disable NR dual connectivity and force secondary cell to be released
6555 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6556 * </ol>
6557 * @return operation result.
6558 */
6559 @Override
6560 public int setNrDualConnectivityState(int subId,
6561 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6562 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6563 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006564 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006565 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6566 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6567 }
6568
Sooraj Sasindran37444802020-08-11 10:40:43 -07006569 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6570 final long identity = Binder.clearCallingIdentity();
6571 try {
6572 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6573 nrDualConnectivityState, subId,
6574 workSource);
6575 if (DBG) log("enableNRDualConnectivity result: " + result);
6576 return result;
6577 } finally {
6578 Binder.restoreCallingIdentity(identity);
6579 }
6580 }
6581
6582 /**
6583 * Is E-UTRA-NR Dual Connectivity enabled
6584 * @return true if dual connectivity is enabled else false
6585 */
6586 @Override
6587 public boolean isNrDualConnectivityEnabled(int subId) {
6588 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006589 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006590 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006591 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006592 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6593 return false;
6594 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006595 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6596 final long identity = Binder.clearCallingIdentity();
6597 try {
6598 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6599 null, subId, workSource);
6600 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6601 return isEnabled;
6602 } finally {
6603 Binder.restoreCallingIdentity(identity);
6604 }
6605 }
6606
6607 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006608 * Set the allowed network types of the device and
6609 * provide the reason triggering the allowed network change.
6610 *
6611 * @param subId the id of the subscription.
6612 * @param reason the reason the allowed network type change is taking place
6613 * @param allowedNetworkTypes the allowed network types.
6614 * @return true on success; false on any failure.
6615 */
6616 @Override
6617 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006618 @TelephonyManager.AllowedNetworkTypesReason int reason,
6619 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006620 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6621 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006622 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006623 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6624 return false;
6625 }
6626 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6627 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006628 return false;
6629 }
6630
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006631 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6632 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6633
6634
6635 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6636 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6637 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006638 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006639
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006640 final long identity = Binder.clearCallingIdentity();
6641 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006642 Boolean success = (Boolean) sendRequest(
6643 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6644 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6645
6646 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6647 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006648 } finally {
6649 Binder.restoreCallingIdentity(identity);
6650 }
6651 }
6652
6653 /**
Miaoa84611c2019-03-15 09:21:10 +08006654 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006655 *
Miaoa84611c2019-03-15 09:21:10 +08006656 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006657 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006658 * @hide
6659 */
6660 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006661 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006662 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006663 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006664 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006665 try {
Miaoa84611c2019-03-15 09:21:10 +08006666 if (phone != null) {
6667 return phone.hasMatchedTetherApnSetting();
6668 } else {
6669 return false;
6670 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006671 } finally {
6672 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006673 }
Junda Liu475951f2014-11-07 16:45:03 -08006674 }
6675
6676 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006677 * Get the user enabled state of Mobile Data.
6678 *
6679 * TODO: remove and use isUserDataEnabled.
6680 * This can't be removed now because some vendor codes
6681 * calls through ITelephony directly while they should
6682 * use TelephonyManager.
6683 *
6684 * @return true on enabled
6685 */
6686 @Override
6687 public boolean getDataEnabled(int subId) {
6688 return isUserDataEnabled(subId);
6689 }
6690
6691 /**
6692 * Get whether mobile data is enabled per user setting.
6693 *
6694 * There are other factors deciding whether mobile data is actually enabled, but they are
6695 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006696 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006697 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6698 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006699 *
6700 * @return {@code true} if data is enabled else {@code false}
6701 */
6702 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006703 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006704 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006705 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006706 try {
6707 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6708 functionName);
6709 } catch (Exception e) {
6710 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6711 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006712 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006713 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006714 mApp, subId, functionName);
6715
Robert Greenwalt646120a2014-05-23 11:54:03 -07006716 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006717
6718 final long identity = Binder.clearCallingIdentity();
6719 try {
6720 int phoneId = mSubscriptionController.getPhoneId(subId);
6721 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6722 Phone phone = PhoneFactory.getPhone(phoneId);
6723 if (phone != null) {
6724 boolean retVal = phone.isUserDataEnabled();
6725 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6726 return retVal;
6727 } else {
6728 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6729 return false;
6730 }
6731 } finally {
6732 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006733 }
6734 }
6735
6736 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006737 * Checks if the device is capable of mobile data by considering whether whether the
6738 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6739 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006740 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006741 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006742 */
6743 @Override
6744 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006745 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006746 try {
6747 try {
6748 mApp.enforceCallingOrSelfPermission(
6749 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006750 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006751 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006752 try {
6753 mApp.enforceCallingOrSelfPermission(
6754 android.Manifest.permission.READ_PHONE_STATE,
6755 functionName);
6756 } catch (Exception e2) {
6757 mApp.enforceCallingOrSelfPermission(
6758 permission.READ_BASIC_PHONE_STATE, functionName);
6759 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006760 }
6761 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006762 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006763 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006764
6765 final long identity = Binder.clearCallingIdentity();
6766 try {
6767 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006768 Phone phone = PhoneFactory.getPhone(phoneId);
6769 if (phone != null) {
Jack Yu4ad64e52021-12-03 14:23:53 -08006770 boolean retVal;
6771 if (phone.isUsingNewDataStack()) {
6772 retVal = phone.getDataNetworkController().getDataSettingsManager()
6773 .isDataEnabled();
6774 } else {
6775 retVal = phone.getDataEnabledSettings().isDataEnabled();
6776 }
6777 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006778 return retVal;
6779 } else {
6780 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6781 return false;
6782 }
6783 } finally {
6784 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006785 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006786 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006787
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006788 /**
6789 * Check if data is enabled for a specific reason
6790 * @param subId Subscription index
6791 * @param reason the reason the data enable change is taking place
6792 * @return {@code true} if the overall data is enabled; {@code false} if not.
6793 */
6794 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006795 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006796 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006797 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006798 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006799 try {
6800 mApp.enforceCallingOrSelfPermission(
6801 android.Manifest.permission.ACCESS_NETWORK_STATE,
6802 functionName);
6803 } catch (Exception e) {
6804 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6805 functionName);
6806 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006807 } catch (Exception e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006808 try {
6809 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006810 functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006811 } catch (Exception e2) {
6812 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006813 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006814 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006815 }
6816
6817
6818 final long identity = Binder.clearCallingIdentity();
6819 try {
6820 int phoneId = mSubscriptionController.getPhoneId(subId);
6821 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006822 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006823 + " reason=" + reason);
6824 }
6825 Phone phone = PhoneFactory.getPhone(phoneId);
6826 if (phone != null) {
6827 boolean retVal;
Jack Yu99e87332021-12-17 23:14:15 -08006828 if (phone.isUsingNewDataStack()) {
6829 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006830 } else {
Jack Yu99e87332021-12-17 23:14:15 -08006831 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6832 retVal = phone.isUserDataEnabled();
6833 } else {
6834 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
6835 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006836 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006837 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006838 return retVal;
6839 } else {
6840 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006841 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006842 + subId + " retVal=false");
6843 }
6844 return false;
6845 }
6846 } finally {
6847 Binder.restoreCallingIdentity(identity);
6848 }
6849 }
6850
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006851 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006852 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006853 if (uid == Process.PHONE_UID) {
6854 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6855 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006856 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6857 }
6858
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006859 //load access rules from carrier configs, and check those as well: b/139133814
6860 SubscriptionController subController = SubscriptionController.getInstance();
6861 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6862 || subController == null) return privilegeFromSim;
6863
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006864 PackageManager pkgMgr = phone.getContext().getPackageManager();
6865 String[] packages = pkgMgr.getPackagesForUid(uid);
6866
6867 final long identity = Binder.clearCallingIdentity();
6868 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006869 int subId = phone.getSubId();
6870 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6871 // A test override is in place for the privileges for this subId, so don't try to
6872 // read the subscription privileges.
6873 return privilegeFromSim;
6874 }
6875 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006876 SubscriptionManager subManager = (SubscriptionManager)
6877 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6878 for (String pkg : packages) {
6879 if (subManager.canManageSubscription(subInfo, pkg)) {
6880 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6881 }
6882 }
6883 return privilegeFromSim;
6884 } finally {
6885 Binder.restoreCallingIdentity(identity);
6886 }
6887 }
6888
6889 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6890 String pkgName) {
6891 //load access rules from carrier configs, and check those as well: b/139133814
6892 SubscriptionController subController = SubscriptionController.getInstance();
6893 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6894 || subController == null) return privilegeFromSim;
6895
6896 final long identity = Binder.clearCallingIdentity();
6897 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006898 int subId = phone.getSubId();
6899 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6900 // A test override is in place for the privileges for this subId, so don't try to
6901 // read the subscription privileges.
6902 return privilegeFromSim;
6903 }
6904 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006905 SubscriptionManager subManager = (SubscriptionManager)
6906 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6907 return subManager.canManageSubscription(subInfo, pkgName)
6908 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6909 } finally {
6910 Binder.restoreCallingIdentity(identity);
6911 }
6912 }
6913
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006914 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006915 public int getCarrierPrivilegeStatus(int subId) {
6916 final Phone phone = getPhone(subId);
6917 if (phone == null) {
6918 loge("getCarrierPrivilegeStatus: Invalid subId");
6919 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6920 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006921 UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId());
6922 if (port == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006923 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006924 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6925 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006926
6927 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006928 port.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006929 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006930 }
Junda Liu29340342014-07-10 15:23:27 -07006931
6932 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006933 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006934 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006935 final Phone phone = getPhone(subId);
6936 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006937 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006938 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6939 }
6940 UiccProfile profile =
6941 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6942 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006943 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006944 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6945 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006946 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006947 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006948 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006949 }
6950
6951 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006952 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006953 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006954 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006955 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006956 }
6957
6958 int phoneId = SubscriptionManager.getPhoneId(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006959 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6960 if (port == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006961 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006962 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6963 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006964 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006965 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006966 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006967 }
6968
6969 @Override
6970 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006971 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006972 if (TextUtils.isEmpty(pkgName))
6973 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006974 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6975 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006976 UiccPort port = UiccController.getInstance().getUiccPort(i);
6977 if (port == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006978 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006979 continue;
6980 }
6981
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006982 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006983 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006984 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006985 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6986 break;
6987 }
6988 }
6989
6990 return result;
Junda Liu29340342014-07-10 15:23:27 -07006991 }
Derek Tan89e89d42014-07-08 17:00:10 -07006992
6993 @Override
Junda Liue64de782015-04-16 17:19:16 -07006994 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006995 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006996 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6997 loge("phoneId " + phoneId + " is not valid.");
6998 return null;
6999 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007000 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
7001 if (port == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007002 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007003 return null ;
7004 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007005 return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007006 }
7007
Amith Yamasani6e118872016-02-19 12:53:51 -08007008 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007009 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007010 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007011 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08007012 List<String> privilegedPackages = new ArrayList<>();
7013 List<PackageInfo> packages = null;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007014 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
chen xuf7e9fe82019-05-09 19:31:02 -07007015 // has UICC in that slot.
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007016 if (port != null) {
7017 if (port.hasCarrierPrivilegeRules()) {
Amith Yamasani6e118872016-02-19 12:53:51 -08007018 if (packages == null) {
7019 // Only check packages in user 0 for now
7020 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07007021 PackageManager.MATCH_DISABLED_COMPONENTS
7022 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09007023 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08007024 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08007025 }
7026 for (int p = packages.size() - 1; p >= 0; p--) {
7027 PackageInfo pkgInfo = packages.get(p);
7028 if (pkgInfo != null && pkgInfo.packageName != null
Sooraj Sasindran97bce6f2021-09-28 21:37:29 +00007029 && getCarrierPrivilegeStatusFromCarrierConfigRules(
7030 port.getCarrierPrivilegeStatus(pkgInfo),
7031 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07007032 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08007033 privilegedPackages.add(pkgInfo.packageName);
7034 }
7035 }
7036 }
7037 }
7038 return privilegedPackages;
7039 }
7040
chen xuf7e9fe82019-05-09 19:31:02 -07007041 @Override
7042 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007043 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
7044
7045 final long identity = Binder.clearCallingIdentity();
7046
chen xuf7e9fe82019-05-09 19:31:02 -07007047 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007048 try {
7049 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7050 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7051 }
7052 } finally {
7053 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007054 }
7055 return privilegedPackages;
7056 }
7057
Wink Savilleb564aae2014-10-23 10:18:09 -07007058 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007059 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007060 UiccPort port = phone == null ? null : phone.getUiccPort();
7061 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007062 return null;
7063 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007064 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007065 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007066 return null;
7067 }
7068 return iccId;
7069 }
7070
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007071 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007072 public void setCallComposerStatus(int subId, int status) {
7073 enforceModifyPermission();
7074
7075 final long identity = Binder.clearCallingIdentity();
7076 try {
7077 Phone phone = getPhone(subId);
7078 if (phone != null) {
7079 Phone defaultPhone = phone.getImsPhone();
7080 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7081 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7082 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007083 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7084 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007085 }
7086 }
Shuo Qian284ae752020-12-22 19:10:14 -08007087 } catch (ImsException e) {
7088 throw new ServiceSpecificException(e.getCode());
7089 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007090 Binder.restoreCallingIdentity(identity);
7091 }
7092 }
7093
7094 @Override
7095 public int getCallComposerStatus(int subId) {
7096 enforceReadPrivilegedPermission("getCallComposerStatus");
7097
7098 final long identity = Binder.clearCallingIdentity();
7099 try {
7100 Phone phone = getPhone(subId);
7101 if (phone != null) {
7102 Phone defaultPhone = phone.getImsPhone();
7103 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7104 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7105 return imsPhone.getCallComposerStatus();
7106 }
7107 }
7108 } finally {
7109 Binder.restoreCallingIdentity(identity);
7110 }
7111 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7112 }
7113
7114 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007115 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7116 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007117 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007118 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007119
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007120 final long identity = Binder.clearCallingIdentity();
7121 try {
7122 final String iccId = getIccId(subId);
7123 final Phone phone = getPhone(subId);
7124 if (phone == null) {
7125 return false;
7126 }
7127 final String subscriberId = phone.getSubscriberId();
7128
7129 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007130 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007131 + subscriberId + " to " + number);
7132 }
7133
7134 if (TextUtils.isEmpty(iccId)) {
7135 return false;
7136 }
7137
7138 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7139
7140 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7141 if (alphaTag == null) {
7142 editor.remove(alphaTagPrefKey);
7143 } else {
7144 editor.putString(alphaTagPrefKey, alphaTag);
7145 }
7146
7147 // Record both the line number and IMSI for this ICCID, since we need to
7148 // track all merged IMSIs based on line number
7149 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7150 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7151 if (number == null) {
7152 editor.remove(numberPrefKey);
7153 editor.remove(subscriberPrefKey);
7154 } else {
7155 editor.putString(numberPrefKey, number);
7156 editor.putString(subscriberPrefKey, subscriberId);
7157 }
7158
7159 editor.commit();
7160 return true;
7161 } finally {
7162 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007163 }
Derek Tan7226c842014-07-02 17:42:23 -07007164 }
7165
7166 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007167 public String getLine1NumberForDisplay(int subId, String callingPackage,
7168 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007169 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007170 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007171 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007172 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007173 return null;
7174 }
Derek Tan97ebb422014-09-05 16:55:38 -07007175
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007176 final long identity = Binder.clearCallingIdentity();
7177 try {
7178 String iccId = getIccId(subId);
7179 if (iccId != null) {
7180 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7181 if (DBG_MERGE) {
7182 log("getLine1NumberForDisplay returning "
7183 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7184 }
7185 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007186 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007187 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7188 return null;
7189 } finally {
7190 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007191 }
Derek Tan7226c842014-07-02 17:42:23 -07007192 }
7193
7194 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007195 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7196 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007197 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007198 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007199 return null;
7200 }
Derek Tan97ebb422014-09-05 16:55:38 -07007201
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007202 final long identity = Binder.clearCallingIdentity();
7203 try {
7204 String iccId = getIccId(subId);
7205 if (iccId != null) {
7206 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7207 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7208 }
7209 return null;
7210 } finally {
7211 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007212 }
Derek Tan7226c842014-07-02 17:42:23 -07007213 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007214
7215 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007216 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7217 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007218 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7219 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007220 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007221 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007222 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007223 return null;
7224 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007225
Jordan Liub49b04b2019-05-06 14:45:15 -07007226 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7227 // the process, where TelephonyManager was instantiated.
7228 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007229 final long identity = Binder.clearCallingIdentity();
7230 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007231 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007232 final TelephonyManager tele = TelephonyManager.from(context);
7233 final SubscriptionManager sub = SubscriptionManager.from(context);
7234
7235 // Figure out what subscribers are currently active
7236 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007237
Jordan Liub49b04b2019-05-06 14:45:15 -07007238 // Only consider subs which match the current subId
7239 // This logic can be simplified. See b/131189269 for progress.
7240 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007241 activeSubscriberIds.add(tele.getSubscriberId(subId));
7242 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007243
7244 // First pass, find a number override for an active subscriber
7245 String mergeNumber = null;
7246 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7247 for (String key : prefs.keySet()) {
7248 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7249 final String subscriberId = (String) prefs.get(key);
7250 if (activeSubscriberIds.contains(subscriberId)) {
7251 final String iccId = key.substring(
7252 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7253 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7254 mergeNumber = (String) prefs.get(numberKey);
7255 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007256 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007257 + " for active subscriber " + subscriberId);
7258 }
7259 if (!TextUtils.isEmpty(mergeNumber)) {
7260 break;
7261 }
7262 }
7263 }
7264 }
7265
7266 // Shortcut when no active merged subscribers
7267 if (TextUtils.isEmpty(mergeNumber)) {
7268 return null;
7269 }
7270
7271 // Second pass, find all subscribers under that line override
7272 final ArraySet<String> result = new ArraySet<>();
7273 for (String key : prefs.keySet()) {
7274 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7275 final String number = (String) prefs.get(key);
7276 if (mergeNumber.equals(number)) {
7277 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7278 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7279 final String subscriberId = (String) prefs.get(subscriberKey);
7280 if (!TextUtils.isEmpty(subscriberId)) {
7281 result.add(subscriberId);
7282 }
7283 }
7284 }
7285 }
7286
7287 final String[] resultArray = result.toArray(new String[result.size()]);
7288 Arrays.sort(resultArray);
7289 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007290 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007291 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7292 }
7293 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007294 } finally {
7295 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007296 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007297 }
7298
7299 @Override
zoey chen38003472019-12-13 17:16:31 +08007300 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7301 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007302
7303 final long identity = Binder.clearCallingIdentity();
7304 try {
7305 final TelephonyManager telephonyManager = mApp.getSystemService(
7306 TelephonyManager.class);
7307 String subscriberId = telephonyManager.getSubscriberId(subId);
7308 if (subscriberId == null) {
7309 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007310 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007311 + subId);
7312 }
7313 return null;
7314 }
7315
7316 final SubscriptionInfo info = SubscriptionController.getInstance()
7317 .getSubscriptionInfo(subId);
7318 final ParcelUuid groupUuid = info.getGroupUuid();
7319 // If it doesn't belong to any group, return just subscriberId of itself.
7320 if (groupUuid == null) {
7321 return new String[]{subscriberId};
7322 }
7323
7324 // Get all subscriberIds from the group.
7325 final List<String> mergedSubscriberIds = new ArrayList<>();
7326 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007327 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007328 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007329 for (SubscriptionInfo subInfo : groupInfos) {
7330 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7331 if (subscriberId != null) {
7332 mergedSubscriberIds.add(subscriberId);
7333 }
7334 }
7335
7336 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7337 } finally {
7338 Binder.restoreCallingIdentity(identity);
7339
7340 }
7341 }
7342
7343 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007344 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007345 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007346 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007347
7348 final long identity = Binder.clearCallingIdentity();
7349 try {
7350 final Phone phone = getPhone(subId);
7351 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7352 } finally {
7353 Binder.restoreCallingIdentity(identity);
7354 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007355 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007356
7357 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007358 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007359 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7360 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007361 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7362 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007363
7364 final long identity = Binder.clearCallingIdentity();
7365 try {
7366 final Phone phone = getPhone(subId);
7367 if (phone == null) {
7368 return false;
7369 }
7370 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7371 cdmaNonRoamingList);
7372 } finally {
7373 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007374 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007375 }
7376
7377 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007378 @Deprecated
7379 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7380 enforceModifyPermission();
7381
7382 int returnValue = 0;
7383 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007384 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007385 if(result.exception == null) {
7386 if (result.result != null) {
7387 byte[] responseData = (byte[])(result.result);
7388 if(responseData.length > oemResp.length) {
7389 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7390 responseData.length + "bytes. Buffer Size is " +
7391 oemResp.length + "bytes.");
7392 }
7393 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7394 returnValue = responseData.length;
7395 }
7396 } else {
7397 CommandException ex = (CommandException) result.exception;
7398 returnValue = ex.getCommandError().ordinal();
7399 if(returnValue > 0) returnValue *= -1;
7400 }
7401 } catch (RuntimeException e) {
7402 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7403 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7404 if(returnValue > 0) returnValue *= -1;
7405 }
7406
7407 return returnValue;
7408 }
7409
7410 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007411 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007412 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007413 try {
7414 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007415 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007416 mApp, phone.getSubId(), "getRadioAccessFamily");
7417 } catch (SecurityException e) {
7418 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7419 throw e;
7420 }
chen xub97461a2018-10-26 14:17:57 -07007421 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007422 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007423 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007424 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007425 final long identity = Binder.clearCallingIdentity();
7426 try {
chen xub97461a2018-10-26 14:17:57 -07007427 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007428 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007429 mApp, phone.getSubId(), "getRadioAccessFamily");
7430 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007431 } finally {
7432 Binder.restoreCallingIdentity(identity);
7433 }
chen xub97461a2018-10-26 14:17:57 -07007434 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007435 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007436
7437 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007438 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007439 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007440 try {
7441 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7442 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007443 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007444 }
7445 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007446 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007447 }
7448 RoleManager rm = mApp.getSystemService(RoleManager.class);
7449 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7450 if (!dialerRoleHolders.contains(callingPackage)) {
7451 throw new SecurityException("App must be the dialer role holder to"
7452 + " upload a call composer pic");
7453 }
7454
7455 Executors.newSingleThreadExecutor().execute(() -> {
7456 ByteArrayOutputStream output = new ByteArrayOutputStream(
7457 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7458 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7459 boolean readUntilEnd = false;
7460 int totalBytesRead = 0;
7461 byte[] buffer = new byte[16 * 1024];
7462 while (true) {
7463 int numRead;
7464 try {
7465 numRead = input.read(buffer);
7466 } catch (IOException e) {
7467 try {
7468 fd.checkError();
7469 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7470 null);
7471 } catch (IOException e1) {
7472 // This means that the other side closed explicitly with an error. If this
7473 // happens, log and ignore.
7474 loge("Remote end of call composer picture pipe closed: " + e1);
7475 }
7476 break;
7477 }
7478 if (numRead == -1) {
7479 readUntilEnd = true;
7480 break;
7481 }
7482 totalBytesRead += numRead;
7483 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7484 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7485 try {
7486 input.close();
7487 } catch (IOException e) {
7488 // ignore
7489 }
7490 break;
7491 }
7492 output.write(buffer, 0, numRead);
7493 }
7494 // Generally, the remote end will close the file descriptors. The only case where we
7495 // close is above, where the picture size is too big.
7496
7497 try {
7498 fd.checkError();
7499 } catch (IOException e) {
7500 loge("Remote end for call composer closed with an error: " + e);
7501 return;
7502 }
7503
Hall Liuaa4211e2021-01-20 15:43:39 -08007504 if (!readUntilEnd) {
7505 loge("Did not finish reading entire image; aborting");
7506 return;
7507 }
Hall Liu82694d52020-12-11 18:22:04 -08007508
Hall Liuaa4211e2021-01-20 15:43:39 -08007509 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7510 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7511 new CallComposerPictureTransfer.Factory() {},
7512 imageData,
7513 (result) -> {
7514 if (result.first != null) {
7515 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7516 Bundle outputResult = new Bundle();
7517 outputResult.putParcelable(
7518 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7519 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7520 outputResult);
7521 } else {
7522 callback.send(result.second, null);
7523 }
7524 }
7525 );
Hall Liu82694d52020-12-11 18:22:04 -08007526 });
7527 }
7528
7529 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007530 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007531 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007532 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007533
7534 final long identity = Binder.clearCallingIdentity();
7535 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007536 ImsManager.getInstance(defaultPhone.getContext(),
7537 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007538 } finally {
7539 Binder.restoreCallingIdentity(identity);
7540 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007541 }
7542
7543 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007544 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007545 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007546 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7547 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007548 return false;
7549 }
Svet Ganovb320e182015-04-16 12:30:10 -07007550
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007551 final long identity = Binder.clearCallingIdentity();
7552 try {
7553 // Check the user preference and the system-level IMS setting. Even if the user has
7554 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7555 // In the long run, we may instead need to check if there exists a connection service
7556 // which can support video calling.
7557 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007558 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007559 return imsManager.isVtEnabledByPlatform()
7560 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7561 && imsManager.isVtEnabledByUser();
7562 } finally {
7563 Binder.restoreCallingIdentity(identity);
7564 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007565 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007566
Andrew Leea1239f22015-03-02 17:44:07 -08007567 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007568 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7569 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007570 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007571 mApp, subId, callingPackage, callingFeatureId,
7572 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007573 return false;
7574 }
7575
7576 final long identity = Binder.clearCallingIdentity();
7577 try {
7578 CarrierConfigManager configManager =
7579 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007580 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007581 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7582 } finally {
7583 Binder.restoreCallingIdentity(identity);
7584 }
Andrew Leea1239f22015-03-02 17:44:07 -08007585 }
7586
7587 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007588 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007589 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007590 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007591 return false;
7592 }
7593
7594 final long identity = Binder.clearCallingIdentity();
7595 try {
7596 CarrierConfigManager configManager =
7597 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007598 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007599 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7600 } finally {
7601 Binder.restoreCallingIdentity(identity);
7602 }
Andrew Leea1239f22015-03-02 17:44:07 -08007603 }
7604
Andrew Lee9431b832015-03-09 18:46:45 -07007605 @Override
7606 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007607 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007608 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007609 }
7610
7611 @Override
7612 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007613 final long identity = Binder.clearCallingIdentity();
7614 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007615 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007616 } finally {
7617 Binder.restoreCallingIdentity(identity);
7618 }
Andrew Lee9431b832015-03-09 18:46:45 -07007619 }
7620
Hall Liuf6668912018-10-31 17:05:23 -07007621 /**
7622 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7623 * support for the feature and device firmware support.
7624 *
7625 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7626 */
7627 @Override
7628 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007629 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007630 final Phone phone = getPhone(subscriptionId);
7631 if (phone == null) {
7632 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7633 return false;
7634 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007635 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007636 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007637 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7638 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007639 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007640 return isCarrierSupported && isDeviceSupported;
7641 } finally {
7642 Binder.restoreCallingIdentity(identity);
7643 }
Hall Liu98187582018-01-22 19:15:32 -08007644 }
7645
Hall Liuf6668912018-10-31 17:05:23 -07007646 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007647 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7648 * RTT setting, will return true if the device and carrier both support RTT.
7649 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007650 */
7651 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007652 final long identity = Binder.clearCallingIdentity();
7653 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007654 boolean isRttSupported = isRttSupported(subscriptionId);
7655 boolean isUserRttSettingOn = Settings.Secure.getInt(
7656 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7657 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7658 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7659 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007660 } finally {
7661 Binder.restoreCallingIdentity(identity);
7662 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007663 }
7664
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007665 @Deprecated
7666 @Override
7667 public String getDeviceId(String callingPackage) {
7668 return getDeviceIdWithFeature(callingPackage, null);
7669 }
7670
Sanket Padawe7310cc72015-01-14 09:53:20 -08007671 /**
7672 * Returns the unique device ID of phone, for example, the IMEI for
7673 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7674 *
7675 * <p>Requires Permission:
7676 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7677 */
7678 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007679 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007680 try {
7681 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7682 } catch (SecurityException se) {
7683 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7684 throw new SecurityException("Package " + callingPackage + " does not belong to "
7685 + Binder.getCallingUid());
7686 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007687 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007688 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007689 return null;
7690 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007691 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007692 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007693 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007694 return null;
7695 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007696
7697 final long identity = Binder.clearCallingIdentity();
7698 try {
7699 return phone.getDeviceId();
7700 } finally {
7701 Binder.restoreCallingIdentity(identity);
7702 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007703 }
7704
Ping Sunc67b7c22016-03-02 19:16:45 +08007705 /**
7706 * {@hide}
7707 * Returns the IMS Registration Status on a particular subid
7708 *
7709 * @param subId
7710 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007711 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007712 Phone phone = getPhone(subId);
7713 if (phone != null) {
7714 return phone.isImsRegistered();
7715 } else {
7716 return false;
7717 }
7718 }
7719
Santos Cordon7a1885b2015-02-03 11:15:19 -08007720 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007721 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007722 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007723 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007724 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007725 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7726 }
7727 final long identity = Binder.clearCallingIdentity();
7728 try {
7729 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7730 } finally {
7731 Binder.restoreCallingIdentity(identity);
7732 }
7733 }
7734
7735 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007736 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007737 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007738 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007739 mApp,
7740 subscriptionId,
7741 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007742 final long identity = Binder.clearCallingIdentity();
7743 try {
7744 Phone phone = getPhone(subscriptionId);
7745 if (phone == null) {
7746 return null;
7747 }
7748 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7749 } finally {
7750 Binder.restoreCallingIdentity(identity);
7751 }
7752 }
7753
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007754 /**
7755 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007756 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007757 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007758 final long identity = Binder.clearCallingIdentity();
7759 try {
7760 Phone phone = getPhone(subId);
7761 if (phone != null) {
7762 return phone.isWifiCallingEnabled();
7763 } else {
7764 return false;
7765 }
7766 } finally {
7767 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007768 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007769 }
7770
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007771 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007772 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007773 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007774 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007775 final long identity = Binder.clearCallingIdentity();
7776 try {
7777 Phone phone = getPhone(subId);
7778 if (phone != null) {
7779 return phone.isVideoEnabled();
7780 } else {
7781 return false;
7782 }
7783 } finally {
7784 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007785 }
7786 }
7787
7788 /**
7789 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7790 * defined in {@link ImsRegistrationImplBase}.
7791 */
7792 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007793 final long identity = Binder.clearCallingIdentity();
7794 try {
7795 Phone phone = getPhone(subId);
7796 if (phone != null) {
7797 return phone.getImsRegistrationTech();
7798 } else {
7799 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7800 }
7801 } finally {
7802 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007803 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007804 }
7805
Stuart Scott8eef64f2015-04-08 15:13:54 -07007806 @Override
7807 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007808 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007809 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7810 return;
7811 }
Kai Shif70f46f2021-03-03 13:59:46 -08007812 Phone defaultPhone = getDefaultPhone();
7813 if (defaultPhone != null) {
7814 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7815 mApp, getDefaultPhone().getSubId(), "factoryReset");
7816 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007817 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007818
Svet Ganovcc087f82015-05-12 20:35:54 -07007819 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007820 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7821 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007822 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007823 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007824 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007825 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007826 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007827 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007828 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007829 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007830 // There has been issues when Sms raw table somehow stores orphan
7831 // fragments. They lead to garbled message when new fragments come
7832 // in and combined with those stale ones. In case this happens again,
7833 // user can reset all network settings which will clean up this table.
7834 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007835 // Clean up IMS settings as well here.
7836 int slotId = getSlotIndex(subId);
7837 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7838 ImsManager.getInstance(mApp, slotId).factoryReset();
7839 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007840
Kai Shif70f46f2021-03-03 13:59:46 -08007841 if (defaultPhone == null) {
7842 return;
7843 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007844 // Erase modem config if erase modem on network setting is enabled.
7845 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7846 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7847 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007848 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007849 }
Kai Shif70f46f2021-03-03 13:59:46 -08007850
7851 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007852 } finally {
7853 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007854 }
7855 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007856
SongFerngWangfd89b102021-05-27 22:44:54 +08007857 @VisibleForTesting
7858 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7859 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7860 return;
7861 }
7862 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7863 RILConstants.PREFERRED_NETWORK_MODE);
7864 SubscriptionManager.setSubscriptionProperty(subId,
7865 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7866 "user=" + defaultNetworkType);
7867 phone.loadAllowedNetworksFromSubscriptionDatabase();
7868 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7869 defaultNetworkType, null);
7870 }
7871
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007872 private void cleanUpSmsRawTable(Context context) {
7873 ContentResolver resolver = context.getContentResolver();
7874 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7875 resolver.delete(uri, null, null);
7876 }
7877
Narayan Kamath1c496c22015-04-16 14:40:19 +01007878 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007879 public String getSimLocaleForSubscriber(int subId) {
7880 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7881 final Phone phone = getPhone(subId);
7882 if (phone == null) {
7883 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007884 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007885 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007886 final long identity = Binder.clearCallingIdentity();
7887 try {
chen xu5d3637b2019-01-21 23:31:38 -08007888 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007889 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007890 if (info == null) {
7891 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7892 return null;
7893 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007894 // Try and fetch the locale from the carrier properties or from the SIM language
7895 // preferences (EF-PL and EF-LI)...
7896 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007897 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007898 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7899 if (localeFromDefaultSim != null) {
7900 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7901 if (DBG) log("Using locale from subId: " + subId + " locale: "
7902 + localeFromDefaultSim);
7903 return localeFromDefaultSim.toLanguageTag();
7904 } else {
7905 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007906 }
7907 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007908
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007909 // The SIM language preferences only store a language (e.g. fr = French), not an
7910 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7911 // the SIM and carrier preferences does not include a country we add the country
7912 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007913 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007914 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007915 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007916 return mccLocale.toLanguageTag();
7917 }
7918
7919 if (DBG) log("No locale found - returning null");
7920 return null;
7921 } finally {
7922 Binder.restoreCallingIdentity(identity);
7923 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007924 }
7925
7926 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007927 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007928 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007929 }
7930
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007931 /**
7932 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7933 */
7934 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007935 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007936 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007937 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007938
Chenjie Yu1ba97252018-01-11 18:16:20 -08007939 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007940 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007941
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007942 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007943 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7944 * representing the state of the modem.
7945 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007946 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7947 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007948 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007949 */
7950 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007951 public void requestModemActivityInfo(ResultReceiver result) {
7952 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007953 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007954
7955 final long identity = Binder.clearCallingIdentity();
7956 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007957 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007958 } finally {
7959 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007960 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007961 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007962
Siddharth Rayb8114062018-06-17 15:02:38 -07007963 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7964 // less than total activity duration.
7965 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7966 if (info == null) {
7967 return false;
7968 }
7969 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007970 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7971 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7972
Siddharth Rayb8114062018-06-17 15:02:38 -07007973 return (info.isValid()
7974 && (info.getSleepTimeMillis() <= activityDurationMs)
7975 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007976 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007977 && (totalTxTimeMs <= activityDurationMs));
7978 }
7979
Jack Yu85bd38a2015-11-09 11:34:32 -08007980 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007981 * Returns the service state information on specified subscription.
7982 */
7983 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007984 public ServiceState getServiceStateForSubscriber(int subId,
7985 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7986 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007987 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007988 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007989 return null;
7990 }
7991
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007992 boolean hasFinePermission = false;
7993 boolean hasCoarsePermission = false;
7994 if (!renounceFineLocationAccess) {
7995 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7996 LocationAccessPolicy.checkLocationPermission(mApp,
7997 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7998 .setCallingPackage(callingPackage)
7999 .setCallingFeatureId(callingFeatureId)
8000 .setCallingPid(Binder.getCallingPid())
8001 .setCallingUid(Binder.getCallingUid())
8002 .setMethod("getServiceStateForSubscriber")
8003 .setLogAsInfo(true)
8004 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8005 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8006 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8007 .build());
8008 hasFinePermission =
8009 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8010 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008011
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008012 if (!renounceCoarseLocationAccess) {
8013 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8014 LocationAccessPolicy.checkLocationPermission(mApp,
8015 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8016 .setCallingPackage(callingPackage)
8017 .setCallingFeatureId(callingFeatureId)
8018 .setCallingPid(Binder.getCallingPid())
8019 .setCallingUid(Binder.getCallingUid())
8020 .setMethod("getServiceStateForSubscriber")
8021 .setLogAsInfo(true)
8022 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8023 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8024 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8025 .build());
8026 hasCoarsePermission =
8027 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8028 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008029
Jack Yu479f40e2020-10-27 21:29:25 -07008030 final Phone phone = getPhone(subId);
8031 if (phone == null) {
8032 return null;
8033 }
8034
Jordan Liu0f2bc442020-11-18 16:47:37 -08008035 final long identity = Binder.clearCallingIdentity();
8036
Jack Yu479f40e2020-10-27 21:29:25 -07008037 boolean isCallingPackageDataService = phone.getDataServicePackages()
8038 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008039 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008040 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
8041 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
8042 Rlog.d(LOG_TAG,
8043 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
8044 return null;
8045 }
8046
Hall Liuf19c44f2018-11-27 14:38:17 -08008047 ServiceState ss = phone.getServiceState();
8048
8049 // Scrub out the location info in ServiceState depending on what level of access
8050 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008051 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008052 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8053 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008054 } finally {
8055 Binder.restoreCallingIdentity(identity);
8056 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008057 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008058
8059 /**
8060 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8061 *
8062 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8063 * voicemail ringtone.
8064 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8065 * PhoneAccount.
8066 */
8067 @Override
8068 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008069 final long identity = Binder.clearCallingIdentity();
8070 try {
8071 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8072 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008073 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008074 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008075
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008076 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8077 } finally {
8078 Binder.restoreCallingIdentity(identity);
8079 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008080 }
8081
8082 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008083 * Sets the per-account voicemail ringtone.
8084 *
8085 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8086 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8087 *
8088 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8089 * voicemail ringtone.
8090 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8091 * PhoneAccount.
8092 */
8093 @Override
8094 public void setVoicemailRingtoneUri(String callingPackage,
8095 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008096 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008097 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008098 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8099 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008100 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8101 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8102 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008103 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008104
8105 final long identity = Binder.clearCallingIdentity();
8106 try {
8107 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8108 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008109 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008110 }
8111 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8112 } finally {
8113 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008114 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008115 }
8116
8117 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008118 * Returns whether vibration is set for voicemail notification in Phone settings.
8119 *
8120 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8121 * voicemail vibration setting.
8122 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8123 */
8124 @Override
8125 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008126 final long identity = Binder.clearCallingIdentity();
8127 try {
8128 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8129 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008130 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008131 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008132
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008133 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8134 } finally {
8135 Binder.restoreCallingIdentity(identity);
8136 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008137 }
8138
Youhan Wange64578a2016-05-02 15:32:42 -07008139 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008140 * Sets the per-account voicemail vibration.
8141 *
8142 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8143 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8144 *
8145 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8146 * voicemail vibration setting.
8147 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8148 * specific PhoneAccount.
8149 */
8150 @Override
8151 public void setVoicemailVibrationEnabled(String callingPackage,
8152 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008153 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008154 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008155 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8156 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008157 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8158 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8159 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008160 }
8161
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008162 final long identity = Binder.clearCallingIdentity();
8163 try {
8164 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8165 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008166 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008167 }
8168 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8169 } finally {
8170 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008171 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008172 }
8173
8174 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008175 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8176 *
8177 * @throws SecurityException if the caller does not have the required permission
8178 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008179 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008180 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008181 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008182 }
8183
8184 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008185 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8186 * permission.
8187 *
8188 * @throws SecurityException if the caller does not have the required permission
8189 */
8190 private void enforceSendSmsPermission() {
8191 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8192 }
8193
8194 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008195 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008196 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008197 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008198 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008199 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008200 final long identity = Binder.clearCallingIdentity();
8201 try {
8202 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008203 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008204 if (componentName == null) {
8205 throw new SecurityException(
8206 "Caller not current active visual voicemail package[null]");
8207 }
8208 String vvmPackage = componentName.getPackageName();
8209 if (!callingPackage.equals(vvmPackage)) {
8210 throw new SecurityException("Caller not current active visual voicemail package["
8211 + vvmPackage + "]");
8212 }
8213 } finally {
8214 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008215 }
8216 }
8217
8218 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008219 * Return the application ID for the app type.
8220 *
8221 * @param subId the subscription ID that this request applies to.
8222 * @param appType the uicc app type.
8223 * @return Application ID for specificied app type, or null if no uicc.
8224 */
8225 @Override
8226 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008227 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008228 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008229
8230 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008231 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008232 if (phone == null) {
8233 return null;
8234 }
8235 String aid = null;
8236 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008237 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008238 .getApplicationByType(appType).getAid();
8239 } catch (Exception e) {
8240 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8241 }
8242 return aid;
8243 } finally {
8244 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008245 }
Youhan Wange64578a2016-05-02 15:32:42 -07008246 }
8247
Youhan Wang4001d252016-05-11 10:29:41 -07008248 /**
8249 * Return the Electronic Serial Number.
8250 *
8251 * @param subId the subscription ID that this request applies to.
8252 * @return ESN or null if error.
8253 */
8254 @Override
8255 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008256 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008257 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008258
8259 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008260 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008261 if (phone == null) {
8262 return null;
8263 }
8264 String esn = null;
8265 try {
8266 esn = phone.getEsn();
8267 } catch (Exception e) {
8268 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8269 }
8270 return esn;
8271 } finally {
8272 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008273 }
Youhan Wang4001d252016-05-11 10:29:41 -07008274 }
8275
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008276 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008277 * Return the Preferred Roaming List Version.
8278 *
8279 * @param subId the subscription ID that this request applies to.
8280 * @return PRLVersion or null if error.
8281 */
8282 @Override
8283 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008284 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008285 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008286
8287 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008288 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008289 if (phone == null) {
8290 return null;
8291 }
8292 String cdmaPrlVersion = null;
8293 try {
8294 cdmaPrlVersion = phone.getCdmaPrlVersion();
8295 } catch (Exception e) {
8296 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8297 }
8298 return cdmaPrlVersion;
8299 } finally {
8300 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008301 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008302 }
8303
8304 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008305 * Get snapshot of Telephony histograms
8306 * @return List of Telephony histograms
8307 * @hide
8308 */
8309 @Override
8310 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008311 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8312 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008313
8314 final long identity = Binder.clearCallingIdentity();
8315 try {
8316 return RIL.getTelephonyRILTimingHistograms();
8317 } finally {
8318 Binder.restoreCallingIdentity(identity);
8319 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008320 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008321
8322 /**
8323 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008324 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8325 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008326 * Require system privileges. In the future we may add this to carrier APIs.
8327 *
Michele Berionne482f8202018-11-27 18:57:59 -08008328 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008329 */
8330 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008331 @TelephonyManager.SetCarrierRestrictionResult
8332 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008333 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008334 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008335
Michele Berionne482f8202018-11-27 18:57:59 -08008336 if (carrierRestrictionRules == null) {
8337 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008338 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008339
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008340 final long identity = Binder.clearCallingIdentity();
8341 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008342 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008343 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008344 } finally {
8345 Binder.restoreCallingIdentity(identity);
8346 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008347 }
8348
8349 /**
8350 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008351 * Get the allowed carrier list and the excluded carrier list, including the priority between
8352 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008353 * Require system privileges. In the future we may add this to carrier APIs.
8354 *
Michele Berionne482f8202018-11-27 18:57:59 -08008355 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008356 */
8357 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008358 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008359 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008360 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008361
8362 final long identity = Binder.clearCallingIdentity();
8363 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008364 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8365 if (response instanceof CarrierRestrictionRules) {
8366 return (CarrierRestrictionRules) response;
8367 }
8368 // Response is an Exception of some kind,
8369 // which is signalled to the user as a NULL retval
8370 return null;
8371 } catch (Exception e) {
8372 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8373 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008374 } finally {
8375 Binder.restoreCallingIdentity(identity);
8376 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008377 }
8378
fionaxu59545b42016-05-25 15:53:37 -07008379 /**
fionaxu59545b42016-05-25 15:53:37 -07008380 * Action set from carrier signalling broadcast receivers to enable/disable radio
8381 * @param subId the subscription ID that this action applies to.
8382 * @param enabled control enable or disable radio.
8383 * {@hide}
8384 */
8385 @Override
8386 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8387 enforceModifyPermission();
8388 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008389
8390 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008391 if (phone == null) {
8392 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8393 return;
8394 }
8395 try {
8396 phone.carrierActionSetRadioEnabled(enabled);
8397 } catch (Exception e) {
8398 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008399 } finally {
8400 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008401 }
8402 }
8403
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008404 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008405 * Enable or disable Voice over NR (VoNR)
8406 * @param subId the subscription ID that this action applies to.
8407 * @param enabled enable or disable VoNR.
8408 * @return operation result.
8409 */
8410 @Override
8411 public int setVoNrEnabled(int subId, boolean enabled) {
8412 enforceModifyPermission();
8413 final Phone phone = getPhone(subId);
8414
8415 final long identity = Binder.clearCallingIdentity();
8416 if (phone == null) {
8417 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8418 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8419 }
8420
8421 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8422 try {
8423 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8424 workSource);
8425 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008426
8427 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8428 if (DBG) {
8429 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8430 }
8431 SubscriptionManager.setSubscriptionProperty(
8432 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8433 (enabled ? "1" : "0"));
8434 }
8435
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008436 return result;
8437 } finally {
8438 Binder.restoreCallingIdentity(identity);
8439 }
8440 }
8441
8442 /**
8443 * Is voice over NR enabled
8444 * @return true if VoNR is enabled else false
8445 */
8446 @Override
8447 public boolean isVoNrEnabled(int subId) {
8448 enforceReadPrivilegedPermission("isVoNrEnabled");
8449 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8450 final long identity = Binder.clearCallingIdentity();
8451 try {
8452 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8453 null, subId, workSource);
8454 if (DBG) log("isVoNrEnabled: " + isEnabled);
8455 return isEnabled;
8456 } finally {
8457 Binder.restoreCallingIdentity(identity);
8458 }
8459 }
8460
8461 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008462 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8463 * network status based on which carrier apps could apply actions accordingly,
8464 * enable/disable default url handler for example.
8465 *
8466 * @param subId the subscription ID that this action applies to.
8467 * @param report control start/stop reporting the default network status.
8468 * {@hide}
8469 */
8470 @Override
8471 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8472 enforceModifyPermission();
8473 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008474
8475 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008476 if (phone == null) {
8477 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8478 return;
8479 }
8480 try {
8481 phone.carrierActionReportDefaultNetworkStatus(report);
8482 } catch (Exception e) {
8483 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008484 } finally {
8485 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008486 }
8487 }
8488
8489 /**
fionaxud9622282017-07-17 17:51:30 -07008490 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8491 * @param subId the subscription ID that this action applies to.
8492 * {@hide}
8493 */
8494 @Override
8495 public void carrierActionResetAll(int subId) {
8496 enforceModifyPermission();
8497 final Phone phone = getPhone(subId);
8498 if (phone == null) {
8499 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8500 return;
8501 }
8502 try {
8503 phone.carrierActionResetAll();
8504 } catch (Exception e) {
8505 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8506 }
8507 }
8508
8509 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008510 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8511 * bug report is being generated.
8512 */
8513 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008514 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008515 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8516 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008517 writer.println("Permission Denial: can't dump Phone from pid="
8518 + Binder.getCallingPid()
8519 + ", uid=" + Binder.getCallingUid()
8520 + "without permission "
8521 + android.Manifest.permission.DUMP);
8522 return;
8523 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008524 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008525 }
Jack Yueb89b242016-06-22 13:27:47 -07008526
Brad Ebingerdac2f002018-04-03 15:17:52 -07008527 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008528 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8529 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8530 @NonNull String[] args) {
8531 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8532 this, in.getFileDescriptor(), out.getFileDescriptor(),
8533 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008534 }
8535
Jack Yueb89b242016-06-22 13:27:47 -07008536 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008537 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008538 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008539 * @param reason the reason the data enable change is taking place
8540 * @param enabled True if enabling the data, otherwise disabling.
8541 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008542 */
8543 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008544 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008545 boolean enabled) {
8546 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8547 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8548 try {
8549 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008550 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008551 } catch (SecurityException se) {
8552 enforceModifyPermission();
8553 }
8554 } else {
8555 enforceModifyPermission();
8556 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008557
8558 final long identity = Binder.clearCallingIdentity();
8559 try {
8560 Phone phone = getPhone(subId);
8561 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008562 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8563 phone.carrierActionSetMeteredApnsEnabled(enabled);
8564 } else {
Jack Yu99e87332021-12-17 23:14:15 -08008565 if (phone.isUsingNewDataStack()) {
8566 phone.getDataSettingsManager().setDataEnabled(reason, enabled);
8567 } else {
8568 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8569 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008570 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008571 }
8572 } finally {
8573 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008574 }
8575 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008576
8577 /**
8578 * Get Client request stats
8579 * @return List of Client Request Stats
8580 * @hide
8581 */
8582 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008583 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8584 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008585 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008586 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008587 return null;
8588 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008589 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008590
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008591 final long identity = Binder.clearCallingIdentity();
8592 try {
8593 if (phone != null) {
8594 return phone.getClientRequestStats();
8595 }
8596
8597 return null;
8598 } finally {
8599 Binder.restoreCallingIdentity(identity);
8600 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008601 }
8602
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008603 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008604 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008605 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008606 }
Jack Yueb4124c2017-02-16 15:32:43 -08008607
8608 /**
Grace Chen70990072017-03-24 17:21:30 -07008609 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008610 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008611 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008612 * @param state State of SIM (power down, power up, pass through)
8613 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8614 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8615 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008616 *
8617 **/
8618 @Override
Grace Chen70990072017-03-24 17:21:30 -07008619 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008620 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008621 Phone phone = PhoneFactory.getPhone(slotIndex);
8622
vagdeviaf9a5b92018-08-15 16:01:53 -07008623 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8624
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008625 final long identity = Binder.clearCallingIdentity();
8626 try {
8627 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008628 phone.setSimPowerState(state, null, workSource);
8629 }
8630 } finally {
8631 Binder.restoreCallingIdentity(identity);
8632 }
8633 }
8634
8635 /**
8636 * Set SIM card power state.
8637 *
8638 * @param slotIndex SIM slot id.
8639 * @param state State of SIM (power down, power up, pass through)
8640 * @param callback callback to trigger after success or failure
8641 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8642 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8643 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8644 *
8645 **/
8646 @Override
8647 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8648 IIntegerConsumer callback) {
8649 enforceModifyPermission();
8650 Phone phone = PhoneFactory.getPhone(slotIndex);
8651
8652 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8653
8654 final long identity = Binder.clearCallingIdentity();
8655 try {
8656 if (phone != null) {
8657 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8658 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008659 }
8660 } finally {
8661 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008662 }
8663 }
Shuo Qiandd210312017-04-12 22:11:33 +00008664
Tyler Gunn65d45c22017-06-05 11:22:26 -07008665 private boolean isUssdApiAllowed(int subId) {
8666 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008667 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008668 if (configManager == null) {
8669 return false;
8670 }
8671 PersistableBundle pb = configManager.getConfigForSubId(subId);
8672 if (pb == null) {
8673 return false;
8674 }
8675 return pb.getBoolean(
8676 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8677 }
8678
Shuo Qiandd210312017-04-12 22:11:33 +00008679 /**
8680 * Check if phone is in emergency callback mode
8681 * @return true if phone is in emergency callback mode
8682 * @param subId sub id
8683 */
goneil9c5f4872017-12-05 14:07:56 -08008684 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008685 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008686 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008687 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008688
8689 final long identity = Binder.clearCallingIdentity();
8690 try {
8691 if (phone != null) {
8692 return phone.isInEcm();
8693 } else {
8694 return false;
8695 }
8696 } finally {
8697 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008698 }
8699 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008700
8701 /**
8702 * Get the current signal strength information for the given subscription.
8703 * Because this information is not updated when the device is in a low power state
8704 * it should not be relied-upon to be current.
8705 * @param subId Subscription index
8706 * @return the most recent cached signal strength info from the modem
8707 */
8708 @Override
8709 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008710 final long identity = Binder.clearCallingIdentity();
8711 try {
8712 Phone p = getPhone(subId);
8713 if (p == null) {
8714 return null;
8715 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008716
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008717 return p.getSignalStrength();
8718 } finally {
8719 Binder.restoreCallingIdentity(identity);
8720 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008721 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008722
Pengquan Meng77b7f132018-08-22 14:49:57 -07008723 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008724 * Get the current modem radio state for the given slot.
8725 * @param slotIndex slot index.
8726 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008727 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008728 * @return the current radio power state from the modem
8729 */
8730 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008731 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008732 Phone phone = PhoneFactory.getPhone(slotIndex);
8733 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008734 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8735 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008736 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8737 }
8738
8739 final long identity = Binder.clearCallingIdentity();
8740 try {
8741 return phone.getRadioPowerState();
8742 } finally {
8743 Binder.restoreCallingIdentity(identity);
8744 }
8745 }
8746 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8747 }
8748
8749 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008750 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8751 *
8752 * <p>Requires one of the following permissions:
8753 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008754 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008755 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8756 * privileges.
8757 *
8758 * @param subId subscription id
8759 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8760 * {@code false}.
8761 */
8762 @Override
8763 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008764 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008765 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008766 try {
8767 mApp.enforceCallingOrSelfPermission(
8768 android.Manifest.permission.ACCESS_NETWORK_STATE,
8769 functionName);
8770 } catch (Exception e) {
8771 mApp.enforceCallingOrSelfPermission(
8772 permission.READ_BASIC_PHONE_STATE, functionName);
8773 }
Shuo Qian093013d2020-08-13 15:42:55 -07008774 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008775 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008776 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008777 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008778
Pengquan Menga1bb6272018-09-06 09:59:22 -07008779 boolean isEnabled = false;
8780 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008781 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008782 Phone phone = getPhone(subId);
8783 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008784 } finally {
8785 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008786 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008787 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008788 }
8789
8790
8791 /**
8792 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8793 *
8794 * <p> Requires permission:
8795 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8796 * privileges.
8797 *
8798 * @param subId subscription id
8799 * @param isEnabled {@code true} means enable, {@code false} means disable.
8800 */
8801 @Override
8802 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008803 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8804 mApp, subId, "setDataRoamingEnabled");
8805
Pengquan Menga1bb6272018-09-06 09:59:22 -07008806 final long identity = Binder.clearCallingIdentity();
8807 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008808 Phone phone = getPhone(subId);
8809 if (phone != null) {
8810 phone.setDataRoamingEnabled(isEnabled);
8811 }
8812 } finally {
8813 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008814 }
8815 }
8816
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008817 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008818 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008819 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008820 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008821 mApp, subId, "isManualNetworkSelectionAllowed");
8822
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008823 boolean isAllowed = true;
8824 final long identity = Binder.clearCallingIdentity();
8825 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008826 Phone phone = getPhone(subId);
8827 if (phone != null) {
8828 isAllowed = phone.isCspPlmnEnabled();
8829 }
8830 } finally {
8831 Binder.restoreCallingIdentity(identity);
8832 }
8833 return isAllowed;
8834 }
8835
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008836 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8837 UiccProfile profile = port.getUiccProfile();
8838 if (profile == null ||
8839 profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8840 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8841 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008842 }
8843 return true;
8844 }
8845
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008846 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008847 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008848 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008849 mApp.getSystemService(AppOpsManager.class)
8850 .checkPackage(Binder.getCallingUid(), callingPackage);
8851
Jordan Liu1e142fc2019-04-22 15:10:43 -07008852 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008853 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008854 try {
8855 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008856 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008857 } catch (SecurityException e) {
8858 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8859 // has carrier privileges on an active UICC
8860 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8861 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008862 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008863 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008864 }
sandeepjsb6c87872021-09-27 15:34:44 +00008865 // checking compatibility, if calling app's target SDK is T and beyond.
8866 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8867 Binder.getCallingUid())) {
8868 isIccIdAccessRestricted = true;
8869 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008870 final long identity = Binder.clearCallingIdentity();
8871 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008872 UiccController uiccController = UiccController.getInstance();
8873 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008874 if (hasReadPermission) {
8875 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008876 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008877
8878 // Remove private info if the caller doesn't have access
8879 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8880 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008881 //setting the value after compatibility check
8882 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008883 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8884 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008885 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008886 if (card == null) {
8887 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008888 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008889 continue;
8890 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008891 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8892 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008893 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008894 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008895 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008896 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8897 for (UiccPortInfo portInfo : portInfos) {
8898 UiccPort port = uiccController.getUiccPortForSlot(
8899 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8900 if (port == null) {
8901 // assume no access if port is null
8902 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8903 continue;
8904 }
8905 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8906 uiccPortInfos.add(portInfo);
8907 } else {
8908 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8909 }
8910 }
8911 filteredInfos.add(new UiccCardInfo(
8912 cardInfo.isEuicc(),
8913 cardInfo.getCardId(),
8914 null,
8915 cardInfo.getPhysicalSlotIndex(),
8916 cardInfo.isRemovable(),
8917 cardInfo.isMultipleEnabledProfilesSupported(),
8918 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008919 }
8920 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008921 } finally {
8922 Binder.restoreCallingIdentity(identity);
8923 }
8924 }
8925
sandeepjsb6c87872021-09-27 15:34:44 +00008926 /**
8927 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8928 * generally private and require carrier privileges to view.
8929 *
8930 * @hide
8931 */
8932 @NonNull
8933 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8934 List<UiccPortInfo> portinfo = new ArrayList<>();
8935 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8936 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8937 }
8938 return new UiccCardInfo(
8939 cardInfo.isEuicc(),
8940 cardInfo.getCardId(),
8941 null,
8942 cardInfo.getPhysicalSlotIndex(),
8943 cardInfo.isRemovable(),
8944 cardInfo.isMultipleEnabledProfilesSupported(),
8945 portinfo
8946 );
8947 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008948
sandeepjsb6c87872021-09-27 15:34:44 +00008949 /**
8950 * @hide
8951 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8952 * These values are generally private and require carrier privileges to view.
8953 */
8954 @NonNull
8955 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8956 return new UiccPortInfo(
8957 UiccPortInfo.ICCID_REDACTED,
8958 portInfo.getPortIndex(),
8959 portInfo.getLogicalSlotIndex(),
8960 portInfo.isActive()
8961 );
8962 }
8963 @Override
8964 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008965 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00008966 mApp.getSystemService(AppOpsManager.class)
8967 .checkPackage(Binder.getCallingUid(), callingPackage);
8968
8969 boolean hasReadPermission = false;
8970 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008971
8972 try {
8973 enforceReadPrivilegedPermission("getUiccSlotsInfo");
8974 hasReadPermission = true;
8975 } catch (SecurityException e) {
8976 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8977 // has carrier privileges on an active UICC
8978 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8979 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8980 hasReadPermission = true;
8981 }
8982 }
8983
8984 // checking compatibility, if calling app's target SDK is T and beyond.
8985 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8986 Binder.getCallingUid())) {
8987 isLogicalSlotAccessRestricted = true;
8988 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008989 final long identity = Binder.clearCallingIdentity();
8990 try {
8991 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8992 if (slots == null) {
8993 Rlog.i(LOG_TAG, "slots is null.");
8994 return null;
8995 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008996 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8997 for (int i = 0; i < slots.length; i++) {
8998 UiccSlot slot = slots[i];
8999 if (slot == null) {
9000 continue;
9001 }
9002
Jordan Liu7be7e652019-05-06 18:55:02 +00009003 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009004 UiccCard card = slot.getUiccCard();
9005 if (card != null) {
9006 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009007 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009008 cardId = slot.getEid();
9009 if (TextUtils.isEmpty(cardId)) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009010 // If cardId is null, use iccId of default port as cardId. Check if has
9011 // read permission otherwise set to null.(card is null which means no
9012 // carrier permission)
9013 cardId = hasReadPermission ? slot.getIccId(
9014 TelephonyManager.DEFAULT_PORT_INDEX) : null;
Jordan Liu01bd00d2019-09-12 16:19:43 -07009015 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009016 }
9017
Jordan Liu857451f2019-05-09 16:35:35 -07009018 if (cardId != null) {
9019 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9020 // if cardId is an EID, it's all digits so this is fine
9021 cardId = IccUtils.stripTrailingFs(cardId);
9022 }
9023
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009024 int cardState = 0;
9025 switch (slot.getCardState()) {
9026 case CARDSTATE_ABSENT:
9027 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9028 break;
9029 case CARDSTATE_PRESENT:
9030 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9031 break;
9032 case CARDSTATE_ERROR:
9033 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9034 break;
9035 case CARDSTATE_RESTRICTED:
9036 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9037 break;
9038 default:
9039 break;
9040
9041 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009042 List<UiccPortInfo> portInfos = new ArrayList<>();
9043 int[] portIndexes = slot.getPortList();
9044 for (int portIdx : portIndexes) {
9045 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
9046 callingPackage, hasReadPermission));
9047 if (slot.isPortActive(portIdx)) {
9048 UiccPort port = slot.getUiccCard().getUiccPort(portIdx);
9049 portInfos.add(new UiccPortInfo(iccId, port.getPortIdx(),
9050 port.getPhoneId(), true));
9051 } else {
9052 portInfos.add(new UiccPortInfo(iccId, portIdx, -1, false));
9053 }
9054 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009055 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009056 slot.isEuicc(),
9057 cardId,
9058 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009059 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009060 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009061 //setting the value after compatibility check
9062 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009063 }
9064 return infos;
9065 } finally {
9066 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009067 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009068 }
9069
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009070 /* Returns null if doesn't have read permission or carrier privilege access. */
9071 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9072 boolean hasReadPermission) {
9073 String iccId = slot.getIccId(portIndex);
9074 if (hasReadPermission) { // if has read permission
9075 return iccId;
9076 } else {
9077 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9078 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9079 // if no read permission, checking carrier privilege access
9080 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9081 return iccId;
9082 }
9083 }
9084 }
9085 // No read permission or carrier privilege access.
9086 return UiccPortInfo.ICCID_REDACTED;
9087 }
9088
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009089 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009090 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009091 public boolean switchSlots(int[] physicalSlots) {
9092 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009093
9094 final long identity = Binder.clearCallingIdentity();
9095 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009096 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9097 for (int i = 0; i < physicalSlots.length; i++) {
9098 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9099 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9100 physicalSlots[i], i));
9101 }
9102 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009103 } finally {
9104 Binder.restoreCallingIdentity(identity);
9105 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009106 }
Jack Yu4c988042018-02-27 15:30:01 -08009107
9108 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009109 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9110 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9111 enforceModifyPermission();
9112
9113 final long identity = Binder.clearCallingIdentity();
9114 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009115 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009116 } finally {
9117 Binder.restoreCallingIdentity(identity);
9118 }
9119 }
9120
9121 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009122 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009123 final long identity = Binder.clearCallingIdentity();
9124 try {
9125 return UiccController.getInstance().getCardIdForDefaultEuicc();
9126 } finally {
9127 Binder.restoreCallingIdentity(identity);
9128 }
9129 }
9130
Pengquan Meng85728fb2018-03-12 16:31:21 -07009131 /**
goneil47ffb6e2018-04-06 15:40:58 -07009132 * A test API to reload the UICC profile.
9133 *
9134 * <p>Requires that the calling app has permission
9135 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9136 * @hide
9137 */
9138 @Override
9139 public void refreshUiccProfile(int subId) {
9140 enforceModifyPermission();
9141
9142 final long identity = Binder.clearCallingIdentity();
9143 try {
9144 Phone phone = getPhone(subId);
9145 if (phone == null) {
9146 return;
9147 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009148 UiccPort uiccPort = phone.getUiccPort();
9149 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009150 return;
9151 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009152 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009153 if (uiccProfile == null) {
9154 return;
9155 }
9156 uiccProfile.refresh();
9157 } finally {
9158 Binder.restoreCallingIdentity(identity);
9159 }
9160 }
9161
9162 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009163 * Returns false if the mobile data is disabled by default, otherwise return true.
9164 */
9165 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009166 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009167 }
9168
9169 /**
9170 * Returns true if the data roaming is enabled by default, i.e the system property
9171 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9172 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9173 */
9174 private boolean getDefaultDataRoamingEnabled(int subId) {
9175 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009176 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009177 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009178 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9179 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9180 return isDataRoamingEnabled;
9181 }
9182
9183 /**
9184 * Returns the default network type for the given {@code subId}, if the default network type is
9185 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9186 */
9187 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009188 List<Integer> list = TelephonyProperties.default_network();
9189 int phoneId = mSubscriptionController.getPhoneId(subId);
9190 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9191 return list.get(phoneId);
9192 }
9193 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009194 }
fionaxua13278b2018-03-21 00:08:13 -07009195
9196 @Override
9197 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009198 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009199 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009200
9201 final long identity = Binder.clearCallingIdentity();
9202 try {
9203 final Phone phone = getPhone(subId);
9204 if (phone == null) {
9205 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9206 return;
9207 }
chen xueaba88a2019-03-15 13:15:10 -07009208 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9209 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009210 if (carrierPrivilegeRules == null) {
9211 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9212 } else {
9213 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9214 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009215 } finally {
9216 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009217 }
fionaxua13278b2018-03-21 00:08:13 -07009218 }
9219
9220 @Override
9221 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009222 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009223
9224 final long identity = Binder.clearCallingIdentity();
9225 try {
9226 final Phone phone = getPhone(subId);
9227 if (phone == null) {
9228 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9229 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9230 }
9231 return phone.getCarrierIdListVersion();
9232 } finally {
9233 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009234 }
fionaxua13278b2018-03-21 00:08:13 -07009235 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009236
9237 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009238 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9239 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009240 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009241 mApp, subId, callingPackage, callingFeatureId,
9242 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009243 return -1;
9244 }
9245
9246 final long identity = Binder.clearCallingIdentity();
9247 try {
9248 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9249 } finally {
9250 Binder.restoreCallingIdentity(identity);
9251 }
9252 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009253
9254 @Override
9255 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009256 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009257 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009258 mApp, subId, "getCdmaRoamingMode");
9259
9260 final long identity = Binder.clearCallingIdentity();
9261 try {
9262 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9263 } finally {
9264 Binder.restoreCallingIdentity(identity);
9265 }
9266 }
9267
9268 @Override
9269 public boolean setCdmaRoamingMode(int subId, int mode) {
9270 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9271 mApp, subId, "setCdmaRoamingMode");
9272
9273 final long identity = Binder.clearCallingIdentity();
9274 try {
9275 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9276 } finally {
9277 Binder.restoreCallingIdentity(identity);
9278 }
9279 }
9280
9281 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009282 public int getCdmaSubscriptionMode(int subId) {
9283 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009284 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009285 mApp, subId, "getCdmaSubscriptionMode");
9286
9287 final long identity = Binder.clearCallingIdentity();
9288 try {
9289 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9290 } finally {
9291 Binder.restoreCallingIdentity(identity);
9292 }
9293 }
9294
9295 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009296 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9297 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9298 mApp, subId, "setCdmaSubscriptionMode");
9299
9300 final long identity = Binder.clearCallingIdentity();
9301 try {
9302 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9303 } finally {
9304 Binder.restoreCallingIdentity(identity);
9305 }
9306 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009307
sqianc5eccab2018-10-19 18:46:41 -07009308 @Override
sqian8c685422019-02-22 15:55:18 -08009309 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009310 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009311 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009312 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9313 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009314 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9315 }
9316 final long identity = Binder.clearCallingIdentity();
9317 try {
sqian854d44b2018-12-12 16:48:18 -08009318 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9319 for (Phone phone: PhoneFactory.getPhones()) {
9320 if (phone.getEmergencyNumberTracker() != null
9321 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9322 emergencyNumberListInternal.put(
9323 phone.getSubId(),
9324 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9325 }
sqian11b7a0e2018-12-05 18:48:28 -08009326 }
sqian854d44b2018-12-12 16:48:18 -08009327 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009328 } finally {
9329 Binder.restoreCallingIdentity(identity);
9330 }
sqianc5eccab2018-10-19 18:46:41 -07009331 }
9332
9333 @Override
sqian8c685422019-02-22 15:55:18 -08009334 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009335 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009336 if (!exactMatch) {
9337 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009338 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009339 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009340 }
9341 final long identity = Binder.clearCallingIdentity();
9342 try {
sqian854d44b2018-12-12 16:48:18 -08009343 for (Phone phone: PhoneFactory.getPhones()) {
9344 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009345 && phone.getEmergencyNumberTracker()
9346 .isEmergencyNumber(number, exactMatch)) {
9347 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009348 }
sqian11b7a0e2018-12-05 18:48:28 -08009349 }
9350 return false;
9351 } finally {
9352 Binder.restoreCallingIdentity(identity);
9353 }
9354 }
9355
sqianf4ca7ed2019-01-15 18:32:07 -08009356 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009357 * Start emergency callback mode for GsmCdmaPhone for testing.
9358 */
9359 @Override
9360 public void startEmergencyCallbackMode() {
9361 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9362 "startEmergencyCallbackMode");
9363 enforceModifyPermission();
9364 final long identity = Binder.clearCallingIdentity();
9365 try {
9366 for (Phone phone : PhoneFactory.getPhones()) {
9367 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9368 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9369 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9370 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9371 gsmCdmaPhone.obtainMessage(
9372 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9373 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9374 }
9375 }
9376 } finally {
9377 Binder.restoreCallingIdentity(identity);
9378 }
9379 }
9380
9381 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009382 * Update emergency number list for test mode.
9383 */
9384 @Override
9385 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9386 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9387 "updateEmergencyNumberListTestMode");
9388
9389 final long identity = Binder.clearCallingIdentity();
9390 try {
9391 for (Phone phone: PhoneFactory.getPhones()) {
9392 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9393 if (tracker != null) {
9394 tracker.executeEmergencyNumberTestModeCommand(action, num);
9395 }
9396 }
9397 } finally {
9398 Binder.restoreCallingIdentity(identity);
9399 }
9400 }
9401
9402 /**
9403 * Get the full emergency number list for test mode.
9404 */
9405 @Override
9406 public List<String> getEmergencyNumberListTestMode() {
9407 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9408 "getEmergencyNumberListTestMode");
9409
9410 final long identity = Binder.clearCallingIdentity();
9411 try {
9412 Set<String> emergencyNumbers = new HashSet<>();
9413 for (Phone phone: PhoneFactory.getPhones()) {
9414 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9415 if (tracker != null) {
9416 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9417 emergencyNumbers.add(num.getNumber());
9418 }
9419 }
9420 }
9421 return new ArrayList<>(emergencyNumbers);
9422 } finally {
9423 Binder.restoreCallingIdentity(identity);
9424 }
9425 }
9426
chen xud6b45bd2018-10-30 22:27:10 -07009427 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009428 public int getEmergencyNumberDbVersion(int subId) {
9429 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9430
9431 final long identity = Binder.clearCallingIdentity();
9432 try {
9433 final Phone phone = getPhone(subId);
9434 if (phone == null) {
9435 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9436 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9437 }
9438 return phone.getEmergencyNumberDbVersion();
9439 } finally {
9440 Binder.restoreCallingIdentity(identity);
9441 }
9442 }
9443
9444 @Override
9445 public void notifyOtaEmergencyNumberDbInstalled() {
9446 enforceModifyPermission();
9447
9448 final long identity = Binder.clearCallingIdentity();
9449 try {
9450 for (Phone phone: PhoneFactory.getPhones()) {
9451 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9452 if (tracker != null) {
9453 tracker.updateOtaEmergencyNumberDatabase();
9454 }
9455 }
9456 } finally {
9457 Binder.restoreCallingIdentity(identity);
9458 }
9459 }
9460
9461 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009462 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009463 enforceActiveEmergencySessionPermission();
9464
9465 final long identity = Binder.clearCallingIdentity();
9466 try {
9467 for (Phone phone: PhoneFactory.getPhones()) {
9468 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9469 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009470 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9471 }
9472 }
9473 } finally {
9474 Binder.restoreCallingIdentity(identity);
9475 }
9476 }
9477
9478 @Override
9479 public void resetOtaEmergencyNumberDbFilePath() {
9480 enforceActiveEmergencySessionPermission();
9481
9482 final long identity = Binder.clearCallingIdentity();
9483 try {
9484 for (Phone phone: PhoneFactory.getPhones()) {
9485 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9486 if (tracker != null) {
9487 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009488 }
9489 }
9490 } finally {
9491 Binder.restoreCallingIdentity(identity);
9492 }
9493 }
9494
9495 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009496 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9497 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9498 Phone phone = getPhone(subId);
9499 if (phone == null) {
9500 return null;
9501 }
9502 final long identity = Binder.clearCallingIdentity();
9503 try {
9504 UiccProfile profile = UiccController.getInstance()
9505 .getUiccProfileForPhone(phone.getPhoneId());
9506 if (profile != null) {
9507 return profile.getCertsFromCarrierPrivilegeAccessRules();
9508 }
9509 } finally {
9510 Binder.restoreCallingIdentity(identity);
9511 }
9512 return null;
9513 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009514
9515 /**
9516 * Enable or disable a modem stack.
9517 */
9518 @Override
9519 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9520 enforceModifyPermission();
9521
9522 final long identity = Binder.clearCallingIdentity();
9523 try {
9524 Phone phone = PhoneFactory.getPhone(slotIndex);
9525 if (phone == null) {
9526 return false;
9527 } else {
9528 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9529 }
9530 } finally {
9531 Binder.restoreCallingIdentity(identity);
9532 }
9533 }
Michelecea4cf22018-12-21 15:00:11 -08009534
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009535 /**
9536 * Whether a modem stack is enabled or not.
9537 */
9538 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009539 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9540 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009541 Phone phone = PhoneFactory.getPhone(slotIndex);
9542 if (phone == null) return false;
9543
9544 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009545 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9546 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009547 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9548 }
9549
9550 final long identity = Binder.clearCallingIdentity();
9551 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009552 try {
9553 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9554 } catch (NoSuchElementException ex) {
9555 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9556 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009557 } finally {
9558 Binder.restoreCallingIdentity(identity);
9559 }
9560 }
9561
Michelecea4cf22018-12-21 15:00:11 -08009562 @Override
Michele0ea7d782019-03-19 14:58:42 -07009563 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009564 enforceModifyPermission();
9565
9566 final long identity = Binder.clearCallingIdentity();
9567 try {
9568 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009569 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009570 .commit();
9571 } finally {
9572 Binder.restoreCallingIdentity(identity);
9573 }
9574 }
9575
9576 @Override
Michele0ea7d782019-03-19 14:58:42 -07009577 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009578 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009579 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009580 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9581 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009582 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009583 }
Michelecea4cf22018-12-21 15:00:11 -08009584
9585 final long identity = Binder.clearCallingIdentity();
9586 try {
Michele0ea7d782019-03-19 14:58:42 -07009587 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009588 } finally {
9589 Binder.restoreCallingIdentity(identity);
9590 }
9591 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009592
Michele0ea7d782019-03-19 14:58:42 -07009593 @TelephonyManager.IsMultiSimSupportedResult
9594 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009595 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9596 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9597 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009598 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9599 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009600 }
9601 // Check if the hardware supports multisim functionality. If usage of multisim is not
9602 // supported by the modem, indicate that it is restricted.
9603 PhoneCapability staticCapability =
9604 mPhoneConfigurationManager.getStaticPhoneCapability();
9605 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009606 loge("isMultiSimSupportedInternal: no static configuration available");
9607 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009608 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009609 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009610 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9611 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009612 }
9613 // Check if support of multiple SIMs is restricted by carrier
9614 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009615 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009616 }
9617
Michele0ea7d782019-03-19 14:58:42 -07009618 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009619 }
9620
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009621 /**
9622 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009623 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9624 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9625 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009626 * @param numOfSims number of active sims we want to switch to
9627 */
9628 @Override
9629 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009630 if (numOfSims == 1) {
9631 enforceModifyPermission();
9632 } else {
9633 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9634 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9635 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009636 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009637
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009638 try {
Michele30b57b22019-03-01 12:01:14 -08009639 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009640 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009641 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9642 return;
9643 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009644 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9645 } finally {
9646 Binder.restoreCallingIdentity(identity);
9647 }
9648 }
9649
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009650 @Override
9651 public boolean isApplicationOnUicc(int subId, int appType) {
9652 enforceReadPrivilegedPermission("isApplicationOnUicc");
9653 Phone phone = getPhone(subId);
9654 if (phone == null) {
9655 return false;
9656 }
9657 final long identity = Binder.clearCallingIdentity();
9658 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009659 UiccPort uiccPort = phone.getUiccPort();
9660 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009661 return false;
9662 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009663 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009664 if (uiccProfile == null) {
9665 return false;
9666 }
9667 if (TelephonyManager.APPTYPE_SIM <= appType
9668 && appType <= TelephonyManager.APPTYPE_ISIM) {
9669 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9670 }
9671 return false;
9672 } finally {
9673 Binder.restoreCallingIdentity(identity);
9674 }
9675 }
9676
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009677 /**
chen xub4baa772019-04-03 10:23:41 -07009678 * Get whether making changes to modem configurations will trigger reboot.
9679 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009680 */
9681 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009682 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9683 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009684 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009685 mApp, subId, callingPackage, callingFeatureId,
9686 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009687 return false;
9688 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009689 final long identity = Binder.clearCallingIdentity();
9690 try {
9691 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9692 } finally {
9693 Binder.restoreCallingIdentity(identity);
9694 }
9695 }
9696
Nathan Harold29f5f052019-02-15 13:41:57 -08009697 private void updateModemStateMetrics() {
9698 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9699 // TODO: check the state for each modem if the api is ready.
9700 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9701 }
9702
Pengquan Meng3889a572019-01-23 11:16:29 -08009703 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009704 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009705 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009706 // Verify that the callingPackage belongs to the calling UID
9707 mApp.getSystemService(AppOpsManager.class)
9708 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009709 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009710 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009711 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009712 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9713 if (slotInfos != null) {
9714 for (int i = 0; i < slotInfos.length; i++) {
9715 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9716 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9717 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9718 portInfo.getLogicalSlotIndex()));
9719 }
9720 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009721 }
9722 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009723 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009724 } finally {
9725 Binder.restoreCallingIdentity(identity);
9726 }
9727 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009728
9729 /**
9730 * Get the IRadio HAL Version
9731 */
9732 @Override
9733 public int getRadioHalVersion() {
9734 Phone phone = getDefaultPhone();
9735 if (phone == null) return -1;
9736 HalVersion hv = phone.getHalVersion();
9737 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9738 return hv.major * 100 + hv.minor;
9739 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009740
9741 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009742 * Get the current calling package name.
9743 * @return the current calling package name
9744 */
9745 @Override
9746 public String getCurrentPackageName() {
9747 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9748 }
9749
9750 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009751 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9752 * corresponding network requests on a subId.
9753 *
9754 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009755 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009756 * 2) APN is un-metered for this subscription, or
9757 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009758 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009759 *
9760 * @return whether data is allowed for a apn type.
9761 *
9762 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009763 */
9764 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009765 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009766 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9767 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009768
9769 // Now that all security checks passes, perform the operation as ourselves.
9770 final long identity = Binder.clearCallingIdentity();
9771 try {
9772 Phone phone = getPhone(subId);
9773 if (phone == null) return false;
9774
Jack Yu41407ee2019-05-13 16:54:09 -07009775 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Jack Yu99e87332021-12-17 23:14:15 -08009776 boolean isDataEnabled;
9777 if (phone.isUsingNewDataStack()) {
9778 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
9779 } else {
9780 isDataEnabled = phone.getDataEnabledSettings().isDataEnabled(apnType);
9781 }
9782 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009783 } finally {
9784 Binder.restoreCallingIdentity(identity);
9785 }
9786 }
9787
9788 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009789 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009790 enforceReadPrivilegedPermission("isApnMetered");
9791
9792 // Now that all security checks passes, perform the operation as ourselves.
9793 final long identity = Binder.clearCallingIdentity();
9794 try {
9795 Phone phone = getPhone(subId);
9796 if (phone == null) return true; // By default return true.
9797
Jack Yu41407ee2019-05-13 16:54:09 -07009798 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009799 } finally {
9800 Binder.restoreCallingIdentity(identity);
9801 }
9802 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009803
9804 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009805 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9806 int subscriptionId, IBooleanConsumer resultCallback) {
9807 enforceModifyPermission();
9808 long token = Binder.clearCallingIdentity();
9809 try {
9810 Phone phone = getPhone(subscriptionId);
9811 if (phone == null) {
9812 try {
9813 if (resultCallback != null) {
9814 resultCallback.accept(false);
9815 }
9816 } catch (RemoteException e) {
9817 // ignore
9818 }
9819 return;
9820 }
9821 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9822 Pair.create(specifiers, (x) -> {
9823 try {
9824 if (resultCallback != null) {
9825 resultCallback.accept(x);
9826 }
9827 } catch (RemoteException e) {
9828 // ignore
9829 }
9830 });
9831 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9832 } finally {
9833 Binder.restoreCallingIdentity(token);
9834 }
9835 }
9836
9837 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009838 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9839 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009840 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009841 mApp, subId, "getSystemSelectionChannels");
9842 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9843 final long identity = Binder.clearCallingIdentity();
9844 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009845 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9846 if (result instanceof IllegalStateException) {
9847 throw (IllegalStateException) result;
9848 }
9849 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009850 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9851 return specifiers;
9852 } finally {
9853 Binder.restoreCallingIdentity(identity);
9854 }
9855 }
9856
9857 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009858 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009859 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009860 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9861 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9862 if (iccRecords == null) {
9863 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9864 return false;
9865 }
9866 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9867 }
9868
9869 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009870 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9871 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009872 if (callingPackage == null) {
9873 callingPackage = getCurrentPackageName();
9874 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009875 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9876 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009877 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9878 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009879 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9880 }
9881 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9882 Intent intent = new Intent();
9883 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9884 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9885 // Bring up choose default SMS subscription dialog right now
9886 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9887 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9888 mApp.startActivity(intent);
9889 }
chen xud5ca2d52019-05-28 15:20:57 -07009890
9891 @Override
9892 public String getMmsUAProfUrl(int subId) {
9893 //TODO investigate if this API should require proper permission check in R b/133791609
9894 final long identity = Binder.clearCallingIdentity();
9895 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009896 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9897 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9898 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9899 return carrierUAProfUrl;
9900 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009901 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9902 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009903 } finally {
9904 Binder.restoreCallingIdentity(identity);
9905 }
9906 }
9907
9908 @Override
9909 public String getMmsUserAgent(int subId) {
9910 //TODO investigate if this API should require proper permission check in R b/133791609
9911 final long identity = Binder.clearCallingIdentity();
9912 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009913 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9914 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9915 if (!TextUtils.isEmpty(carrierUserAgent)) {
9916 return carrierUserAgent;
9917 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009918 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9919 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009920 } finally {
9921 Binder.restoreCallingIdentity(identity);
9922 }
9923 }
Jack Yub07d4972019-05-28 16:12:25 -07009924
9925 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009926 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9927 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009928
Jack Yub07d4972019-05-28 16:12:25 -07009929 final long identity = Binder.clearCallingIdentity();
9930 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009931 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009932 if (phone == null) return false;
9933
Hall Liua62f5da2020-09-25 10:42:19 -07009934 switch (policy) {
9935 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu99e87332021-12-17 23:14:15 -08009936 if (phone.isUsingNewDataStack()) {
9937 return phone.getDataSettingsManager().isDataAllowedInVoiceCall();
9938 } else {
9939 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9940 }
Hall Liua62f5da2020-09-25 10:42:19 -07009941 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu99e87332021-12-17 23:14:15 -08009942 if (phone.isUsingNewDataStack()) {
9943 return phone.getDataSettingsManager().isMmsAlwaysAllowed();
9944 } else {
9945 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9946 }
Hall Liua62f5da2020-09-25 10:42:19 -07009947 default:
9948 throw new IllegalArgumentException(policy + " is not a valid policy");
9949 }
Jack Yub07d4972019-05-28 16:12:25 -07009950 } finally {
9951 Binder.restoreCallingIdentity(identity);
9952 }
9953 }
9954
9955 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009956 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009957 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009958 enforceModifyPermission();
9959
changbettyd5c246e2019-12-24 15:40:37 +08009960 final long identity = Binder.clearCallingIdentity();
9961 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009962 Phone phone = getPhone(subscriptionId);
9963 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009964
Hall Liua62f5da2020-09-25 10:42:19 -07009965 switch (policy) {
9966 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu99e87332021-12-17 23:14:15 -08009967 if (phone.isUsingNewDataStack()) {
9968 phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled);
9969 } else {
9970 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9971 }
Hall Liua62f5da2020-09-25 10:42:19 -07009972 break;
9973 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu99e87332021-12-17 23:14:15 -08009974 if (phone.isUsingNewDataStack()) {
9975 phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled);
9976 } else {
9977 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9978 }
Hall Liua62f5da2020-09-25 10:42:19 -07009979 break;
9980 default:
9981 throw new IllegalArgumentException(policy + " is not a valid policy");
9982 }
changbettyd5c246e2019-12-24 15:40:37 +08009983 } finally {
9984 Binder.restoreCallingIdentity(identity);
9985 }
9986 }
9987
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009988 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009989 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009990 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9991 * otherwise.
9992 */
9993 @Override
9994 public void setCepEnabled(boolean isCepEnabled) {
9995 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9996
9997 final long identity = Binder.clearCallingIdentity();
9998 try {
9999 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10000 for (Phone phone : PhoneFactory.getPhones()) {
10001 Phone defaultPhone = phone.getImsPhone();
10002 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10003 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10004 ImsPhoneCallTracker imsPhoneCallTracker =
10005 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10006 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10007 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10008 + imsPhone.getMsisdn());
10009 }
10010 }
10011 } finally {
10012 Binder.restoreCallingIdentity(identity);
10013 }
10014 }
allenwtsu46dcc572020-01-08 18:24:03 +080010015
10016 /**
10017 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10018 *
10019 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10020 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10021 * before being read.
10022 */
10023 @Override
10024 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10025 isCompressed) {
10026 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10027 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010028 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10029 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10030 }
10031 if (!isImsAvailableOnDevice()) {
10032 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10033 "IMS not available on device.");
10034 }
10035
10036 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010037 try {
Hui Wang761a6682020-10-31 05:12:53 +000010038 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10039 } finally {
10040 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010041 }
10042 }
zoey chene02881a2019-12-30 16:11:23 +080010043
10044 @Override
10045 public boolean isIccLockEnabled(int subId) {
10046 enforceReadPrivilegedPermission("isIccLockEnabled");
10047
10048 // Now that all security checks passes, perform the operation as ourselves.
10049 final long identity = Binder.clearCallingIdentity();
10050 try {
10051 Phone phone = getPhone(subId);
10052 if (phone != null && phone.getIccCard() != null) {
10053 return phone.getIccCard().getIccLockEnabled();
10054 } else {
10055 return false;
10056 }
10057 } finally {
10058 Binder.restoreCallingIdentity(identity);
10059 }
10060 }
10061
10062 /**
10063 * Set the ICC pin lock enabled or disabled.
10064 *
10065 * @return an integer representing the status of IccLock enabled or disabled in the following
10066 * three cases:
10067 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10068 * successfully.
10069 * - Positive number and zero for remaining password attempts.
10070 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10071 *
10072 */
10073 @Override
10074 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10075 enforceModifyPermission();
10076
10077 Phone phone = getPhone(subId);
10078 if (phone == null) {
10079 return 0;
10080 }
10081 // Now that all security checks passes, perform the operation as ourselves.
10082 final long identity = Binder.clearCallingIdentity();
10083 try {
10084 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10085 new Pair<Boolean, String>(enabled, password), phone, null);
10086 return attemptsRemaining;
10087
10088 } catch (Exception e) {
10089 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10090 } finally {
10091 Binder.restoreCallingIdentity(identity);
10092 }
10093 return 0;
10094 }
10095
10096 /**
10097 * Change the ICC password used in ICC pin lock.
10098 *
10099 * @return an integer representing the status of IccLock changed in the following three cases:
10100 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10101 * - Positive number and zero for remaining password attempts.
10102 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10103 *
10104 */
10105 @Override
10106 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10107 enforceModifyPermission();
10108
10109 Phone phone = getPhone(subId);
10110 if (phone == null) {
10111 return 0;
10112 }
10113 // Now that all security checks passes, perform the operation as ourselves.
10114 final long identity = Binder.clearCallingIdentity();
10115 try {
10116 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10117 new Pair<String, String>(oldPassword, newPassword), phone, null);
10118 return attemptsRemaining;
10119
10120 } catch (Exception e) {
10121 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10122 } finally {
10123 Binder.restoreCallingIdentity(identity);
10124 }
10125 return 0;
10126 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010127
10128 /**
10129 * Request for receiving user activity notification
10130 */
10131 @Override
10132 public void requestUserActivityNotification() {
10133 if (!mNotifyUserActivity.get()
10134 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10135 mNotifyUserActivity.set(true);
10136 }
10137 }
10138
10139 /**
10140 * Called when userActivity is signalled in the power manager.
10141 * This is safe to call from any thread, with any window manager locks held or not.
10142 */
10143 @Override
10144 public void userActivity() {
10145 // ***************************************
10146 // * Inherited from PhoneWindowManager *
10147 // ***************************************
10148 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10149 // WITH ITS LOCKS HELD.
10150 //
10151 // This code must be VERY careful about the locks
10152 // it acquires.
10153 // In fact, the current code acquires way too many,
10154 // and probably has lurking deadlocks.
10155
10156 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10157 throw new SecurityException("Only the OS may call notifyUserActivity()");
10158 }
10159
10160 if (mNotifyUserActivity.getAndSet(false)) {
10161 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10162 USER_ACTIVITY_NOTIFICATION_DELAY);
10163 }
10164 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010165
10166 @Override
10167 public boolean canConnectTo5GInDsdsMode() {
10168 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10169 }
Jack Yud10cdd42020-09-28 20:28:01 -070010170
10171 @Override
10172 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10173 String callingFeatureId) {
10174 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10175 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10176 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10177 }
10178
10179 Phone phone = getPhone(subId);
10180 if (phone == null) {
10181 throw new RuntimeException("phone is not available");
10182 }
10183 // Now that all security checks passes, perform the operation as ourselves.
10184 final long identity = Binder.clearCallingIdentity();
10185 try {
10186 return phone.getEquivalentHomePlmns();
10187 } finally {
10188 Binder.restoreCallingIdentity(identity);
10189 }
10190 }
Daniel Bright59e67312020-11-13 11:49:37 -080010191
10192 @Override
10193 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010194 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10195 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010196 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010197 if (radioInterfaceCapabilities == null) {
10198 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010199 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010200 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010201 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010202
Hui Wang641e81c2020-10-12 12:14:23 -070010203 @Override
10204 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10205 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010206 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10207 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10208 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10209 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10210 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010211 if (DBG) {
10212 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10213 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10214 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10215 }
10216
10217 if (!SubscriptionManager.isValidSubscriptionId(subId)
10218 || appType < TelephonyManager.APPTYPE_UNKNOWN
10219 || appType > TelephonyManager.APPTYPE_ISIM
10220 || nafUrl == null || securityProtocol == null || callback == null) {
10221 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10222 if (callback != null) {
10223 try {
10224 callback.onAuthenticationFailure(
10225 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10226 } catch (RemoteException exception) {
10227 log("Fail to notify onAuthenticationFailure due to " + exception);
10228 }
10229 return;
10230 }
10231 }
10232
10233 final long token = Binder.clearCallingIdentity();
10234 try {
10235 getGbaManager(subId).bootstrapAuthenticationRequest(
10236 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10237 forceBootStrapping, callback));
10238 } finally {
10239 Binder.restoreCallingIdentity(token);
10240 }
10241 }
10242
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010243 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010244 * Attempts to set the radio power state for all phones for thermal reason.
10245 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010246 * requested radio power state will actually be set. See {@link
10247 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10248 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010249 * @param enable {@code true} if trying to turn radio on.
10250 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10251 * false}.
10252 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010253 private boolean setRadioPowerForThermal(boolean enable) {
10254 boolean isPhoneAvailable = false;
10255 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10256 Phone phone = PhoneFactory.getPhone(i);
10257 if (phone != null) {
10258 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10259 isPhoneAvailable = true;
10260 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010261 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010262
10263 // return true if successfully informed the phone object about the thermal radio power
10264 // request.
10265 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010266 }
10267
10268 private int handleDataThrottlingRequest(int subId,
10269 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010270 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10271 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10272 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10273 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10274 throw new IllegalArgumentException("modem does not support data throttling");
10275 }
10276
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010277 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10278 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010279 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010280 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10281 }
10282
10283 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10284
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010285 if (isDataThrottlingSupported) {
10286 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010287 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010288 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10289 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10290 } else if (thermalMitigationResult
10291 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010292 log("Modem likely does not support data throttling on secondary carrier. Data " +
10293 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10294 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010295 }
10296 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010297 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010298
10299 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010300 }
10301
Jack Nudelman644b91a2021-03-12 14:09:48 -080010302 private static List<String> getThermalMitigationAllowlist(Context context) {
10303 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10304 for (String pckg : context.getResources()
10305 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10306 sThermalMitigationAllowlistedPackages.add(pckg);
10307 }
10308 }
10309
10310 return sThermalMitigationAllowlistedPackages;
10311 }
10312
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010313 private boolean isAnyPhoneInEmergencyState() {
10314 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10315 if (tm.isInEmergencyCall()) {
10316 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10317 return true;
10318 }
10319 for (Phone phone : PhoneFactory.getPhones()) {
10320 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10321 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10322 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10323 + phone.isInEcm());
10324 return true;
10325 }
10326 }
10327
10328 return false;
10329 }
10330
Jack Nudelman644b91a2021-03-12 14:09:48 -080010331 /**
10332 * Used by shell commands to add an authorized package name for thermal mitigation.
10333 * @param packageName name of package to be allowlisted
10334 * @param context
10335 */
10336 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10337 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10338 sThermalMitigationAllowlistedPackages.add(packageName);
10339 }
10340
10341 /**
10342 * Used by shell commands to remove an authorized package name for thermal mitigation.
10343 * @param packageName name of package to remove from allowlist
10344 * @param context
10345 */
10346 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10347 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10348 sThermalMitigationAllowlistedPackages.remove(packageName);
10349 }
10350
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010351 /**
10352 * Thermal mitigation request to control functionalities at modem.
10353 *
10354 * @param subId the id of the subscription.
10355 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010356 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010357 *
10358 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10359 */
10360 @Override
10361 @ThermalMitigationResult
10362 public int sendThermalMitigationRequest(
10363 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010364 ThermalMitigationRequest thermalMitigationRequest,
10365 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010366 enforceModifyPermission();
10367
Jack Nudelman644b91a2021-03-12 14:09:48 -080010368 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10369 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10370 .contains(callingPackage)) {
10371 throw new SecurityException("Calling package must be configured in the device config. "
10372 + "calling package: " + callingPackage);
10373 }
10374
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010375 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10376 final long identity = Binder.clearCallingIdentity();
10377
10378 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10379 try {
10380 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10381 switch (thermalMitigationAction) {
10382 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10383 thermalMitigationResult =
10384 handleDataThrottlingRequest(subId,
10385 thermalMitigationRequest.getDataThrottlingRequest());
10386 break;
10387 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10388 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10389 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10390 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10391 }
10392
10393 // Ensure that radio is on. If not able to power on due to phone being
10394 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010395 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010396 thermalMitigationResult =
10397 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10398 break;
10399 }
10400
10401 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10402 false);
10403 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10404 break;
10405 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10406 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10407 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10408 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10409 }
10410
10411 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10412 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010413 Phone phone = getPhone(subId);
10414 if (phone == null) {
10415 thermalMitigationResult =
10416 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10417 break;
10418 }
10419
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010420 TelephonyConnectionService service =
10421 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010422 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010423 Log.e(LOG_TAG, "An emergency call is pending");
10424 thermalMitigationResult =
10425 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10426 break;
10427 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010428 thermalMitigationResult =
10429 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10430 break;
10431 }
10432 } else {
10433 thermalMitigationResult =
10434 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10435 break;
10436 }
10437
10438 // Turn radio off. If not able to power off due to phone being unavailable,
10439 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010440 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010441 thermalMitigationResult =
10442 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10443 break;
10444 }
10445 thermalMitigationResult =
10446 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10447 break;
10448 default:
10449 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10450 + "not exist. Requested action: " + thermalMitigationAction);
10451 }
10452 } catch (IllegalArgumentException e) {
10453 throw e;
10454 } catch (Exception e) {
10455 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10456 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10457 } finally {
10458 Binder.restoreCallingIdentity(identity);
10459 }
10460
10461 if (DBG) {
10462 log("thermalMitigationRequest returning with thermalMitigationResult: "
10463 + thermalMitigationResult);
10464 }
10465
10466 return thermalMitigationResult;
10467 }
Hui Wang641e81c2020-10-12 12:14:23 -070010468
10469 /**
10470 * Set the GbaService Package Name that Telephony will bind to.
10471 *
10472 * @param subId The sim that the GbaService is associated with.
10473 * @param packageName The name of the package to be replaced with.
10474 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10475 */
10476 @Override
10477 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10478 enforceModifyPermission();
10479
10480 final long identity = Binder.clearCallingIdentity();
10481 try {
10482 return getGbaManager(subId).overrideServicePackage(packageName);
10483 } finally {
10484 Binder.restoreCallingIdentity(identity);
10485 }
10486 }
10487
10488 /**
10489 * Return the package name of the currently bound GbaService.
10490 *
10491 * @param subId The sim that the GbaService is associated with.
10492 * @return the package name of the GbaService configuration, null if GBA is not supported.
10493 */
10494 @Override
10495 public String getBoundGbaService(int subId) {
10496 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10497
10498 final long identity = Binder.clearCallingIdentity();
10499 try {
10500 return getGbaManager(subId).getServicePackage();
10501 } finally {
10502 Binder.restoreCallingIdentity(identity);
10503 }
10504 }
10505
10506 /**
10507 * Set the release time for telephony to unbind GbaService.
10508 *
10509 * @param subId The sim that the GbaService is associated with.
10510 * @param interval The release time to unbind GbaService by millisecond.
10511 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10512 */
10513 @Override
10514 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10515 enforceModifyPermission();
10516
10517 final long identity = Binder.clearCallingIdentity();
10518 try {
10519 return getGbaManager(subId).overrideReleaseTime(interval);
10520 } finally {
10521 Binder.restoreCallingIdentity(identity);
10522 }
10523 }
10524
10525 /**
10526 * Return the release time for telephony to unbind GbaService.
10527 *
10528 * @param subId The sim that the GbaService is associated with.
10529 * @return The release time to unbind GbaService by millisecond.
10530 */
10531 @Override
10532 public int getGbaReleaseTime(int subId) {
10533 enforceReadPrivilegedPermission("getGbaReleaseTime");
10534
10535 final long identity = Binder.clearCallingIdentity();
10536 try {
10537 return getGbaManager(subId).getReleaseTime();
10538 } finally {
10539 Binder.restoreCallingIdentity(identity);
10540 }
10541 }
10542
10543 private GbaManager getGbaManager(int subId) {
10544 GbaManager instance = GbaManager.getInstance(subId);
10545 if (instance == null) {
10546 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10547 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10548 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10549 }
10550 return instance;
10551 }
Hui Wang761a6682020-10-31 05:12:53 +000010552
10553 /**
10554 * indicate whether the device and the carrier can support
10555 * RCS VoLTE single registration.
10556 */
10557 @Override
10558 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010559 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10560 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10561 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10562 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010563
10564 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10565 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10566 }
10567
10568 final long identity = Binder.clearCallingIdentity();
10569 try {
10570 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10571 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010572 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10573 if (isCapable != null) {
10574 return isCapable;
10575 }
Hui Wang761a6682020-10-31 05:12:53 +000010576 }
Hui Wang67af90e2021-06-04 16:57:15 -070010577 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10578 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010579 } finally {
10580 Binder.restoreCallingIdentity(identity);
10581 }
10582 }
10583
10584 /**
10585 * Register RCS provisioning callback.
10586 */
10587 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010588 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010589 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010590 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010591 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010592 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10593 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010594
10595 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10596 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10597 }
10598 if (!isImsAvailableOnDevice()) {
10599 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10600 "IMS not available on device.");
10601 }
10602
10603 final long identity = Binder.clearCallingIdentity();
10604 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010605 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010606 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010607 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10608 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010609 }
Hui Wang761a6682020-10-31 05:12:53 +000010610 } finally {
10611 Binder.restoreCallingIdentity(identity);
10612 }
10613 }
10614
10615 /**
10616 * Unregister RCS provisioning callback.
10617 */
10618 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010619 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010620 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010621 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010622 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010623 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10624 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010625
10626 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10627 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10628 }
10629 if (!isImsAvailableOnDevice()) {
10630 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10631 "IMS not available on device.");
10632 }
10633
10634 final long identity = Binder.clearCallingIdentity();
10635 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010636 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010637 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010638 } finally {
10639 Binder.restoreCallingIdentity(identity);
10640 }
10641 }
10642
10643 /**
10644 * trigger RCS reconfiguration.
10645 */
10646 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010647 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10648 "triggerRcsReconfiguration",
10649 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010650
10651 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10652 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10653 }
10654 if (!isImsAvailableOnDevice()) {
10655 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10656 "IMS not available on device.");
10657 }
10658
10659 final long identity = Binder.clearCallingIdentity();
10660 try {
10661 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10662 } finally {
10663 Binder.restoreCallingIdentity(identity);
10664 }
10665 }
10666
10667 /**
10668 * Provide the client configuration parameters of the RCS application.
10669 */
10670 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010671 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10672 "setRcsClientConfiguration",
10673 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010674
10675 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10676 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10677 }
10678 if (!isImsAvailableOnDevice()) {
10679 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10680 "IMS not available on device.");
10681 }
10682
10683 final long identity = Binder.clearCallingIdentity();
10684
10685 try {
10686 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10687 if (configBinder == null) {
10688 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010689 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10690 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010691 } else {
10692 configBinder.setRcsClientConfiguration(rcc);
10693 }
joonhunshin3e154242021-09-17 06:33:39 +000010694
10695 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10696 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010697 } catch (RemoteException e) {
10698 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010699 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10700 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010701 } finally {
10702 Binder.restoreCallingIdentity(identity);
10703 }
10704 }
10705
10706 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010707 * Enables or disables the test mode for RCS VoLTE single registration.
10708 */
10709 @Override
10710 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10711 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10712 "setRcsSingleRegistrationTestModeEnabled");
10713
10714 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10715 }
10716
10717 /**
10718 * Gets the test mode for RCS VoLTE single registration.
10719 */
10720 @Override
10721 public boolean getRcsSingleRegistrationTestModeEnabled() {
10722 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10723 "getRcsSingleRegistrationTestModeEnabled");
10724
10725 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10726 }
10727
10728 /**
Hui Wang761a6682020-10-31 05:12:53 +000010729 * Overrides the config of RCS VoLTE single registration enabled for the device.
10730 */
10731 @Override
10732 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10733 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10734 "setDeviceSingleRegistrationEnabledOverride");
10735 enforceModifyPermission();
10736
10737 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10738 : Boolean.parseBoolean(enabledStr);
10739 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010740 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010741 }
10742
10743 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010744 * Sends a device to device communication message. Only usable via shell.
10745 * @param message message to send.
10746 * @param value message value.
10747 */
10748 @Override
10749 public void sendDeviceToDeviceMessage(int message, int value) {
10750 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010751 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010752 enforceModifyPermission();
10753
10754 final long identity = Binder.clearCallingIdentity();
10755 try {
10756 TelephonyConnectionService service =
10757 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10758 if (service == null) {
10759 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10760 return;
10761 }
10762 service.sendTestDeviceToDeviceMessage(message, value);
10763 } finally {
10764 Binder.restoreCallingIdentity(identity);
10765 }
10766 }
10767
Tyler Gunnbabbda02021-02-10 11:05:02 -080010768 /**
10769 * Sets the specified device to device transport active.
10770 * @param transport The transport to set active.
10771 */
10772 @Override
10773 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10774 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10775 "setActiveDeviceToDeviceTransport");
10776 enforceModifyPermission();
10777
10778 final long identity = Binder.clearCallingIdentity();
10779 try {
10780 TelephonyConnectionService service =
10781 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10782 if (service == null) {
10783 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10784 return;
10785 }
10786 service.setActiveDeviceToDeviceTransport(transport);
10787 } finally {
10788 Binder.restoreCallingIdentity(identity);
10789 }
10790 }
Tyler Gunn92479152021-01-20 16:30:10 -080010791
Tyler Gunnd4339262021-05-03 14:46:49 -070010792 @Override
10793 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10794 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10795 "setDeviceToDeviceForceEnabled");
10796
10797 final long identity = Binder.clearCallingIdentity();
10798 try {
10799 Arrays.stream(PhoneFactory.getPhones()).forEach(
10800 p -> {
10801 Phone thePhone = p.getImsPhone();
10802 if (thePhone != null && thePhone instanceof ImsPhone) {
10803 ImsPhone imsPhone = (ImsPhone) thePhone;
10804 CallTracker tracker = imsPhone.getCallTracker();
10805 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10806 ImsPhoneCallTracker imsPhoneCallTracker =
10807 (ImsPhoneCallTracker) tracker;
10808 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10809 }
10810 }
10811 }
10812 );
10813 } finally {
10814 Binder.restoreCallingIdentity(identity);
10815 }
10816 }
10817
Tyler Gunn92479152021-01-20 16:30:10 -080010818 /**
Hui Wang761a6682020-10-31 05:12:53 +000010819 * Gets the config of RCS VoLTE single registration enabled for the device.
10820 */
10821 @Override
10822 public boolean getDeviceSingleRegistrationEnabled() {
10823 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10824 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10825 }
10826
10827 /**
10828 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10829 */
10830 @Override
10831 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10832 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10833 "setCarrierSingleRegistrationEnabledOverride");
10834 enforceModifyPermission();
10835
10836 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10837 : Boolean.parseBoolean(enabledStr);
10838 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10839 subId, enabled);
10840 }
10841
10842 /**
10843 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10844 */
10845 @Override
10846 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10847 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10848 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10849 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010850
10851 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010852 * Overrides the ims feature validation result
10853 */
10854 @Override
10855 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10856 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10857 "setImsFeatureValidationOverride");
10858
10859 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10860 : Boolean.parseBoolean(enabledStr);
10861 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10862 subId, enabled);
10863 }
10864
10865 /**
10866 * Gets the ims feature validation override value
10867 */
10868 @Override
10869 public boolean getImsFeatureValidationOverride(int subId) {
10870 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10871 "getImsFeatureValidationOverride");
10872 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10873 }
10874
10875 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010876 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10877 * their mobile plan.
10878 */
10879 @Override
10880 public String getMobileProvisioningUrl() {
10881 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10882 final long identity = Binder.clearCallingIdentity();
10883 try {
10884 return getDefaultPhone().getMobileProvisioningUrl();
10885 } finally {
10886 Binder.restoreCallingIdentity(identity);
10887 }
10888 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010889
James.cf Linbcdf8b32021-01-14 16:44:13 +080010890 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010891 * Get the EAB contact from the EAB database.
10892 */
10893 @Override
10894 public String getContactFromEab(String contact) {
10895 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10896 enforceModifyPermission();
10897 final long identity = Binder.clearCallingIdentity();
10898 try {
10899 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10900 } finally {
10901 Binder.restoreCallingIdentity(identity);
10902 }
10903 }
10904
10905 /**
Calvin Pana1434322021-07-01 19:27:01 +080010906 * Get the EAB capability from the EAB database.
10907 */
10908 @Override
10909 public String getCapabilityFromEab(String contact) {
10910 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10911 enforceModifyPermission();
10912 final long identity = Binder.clearCallingIdentity();
10913 try {
10914 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10915 } finally {
10916 Binder.restoreCallingIdentity(identity);
10917 }
10918 }
10919
10920 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010921 * Remove the EAB contacts from the EAB database.
10922 */
10923 @Override
10924 public int removeContactFromEab(int subId, String contacts) {
10925 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10926 enforceModifyPermission();
10927 final long identity = Binder.clearCallingIdentity();
10928 try {
10929 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10930 } finally {
10931 Binder.restoreCallingIdentity(identity);
10932 }
10933 }
10934
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010935 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010936 public boolean getDeviceUceEnabled() {
10937 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10938 final long identity = Binder.clearCallingIdentity();
10939 try {
10940 return mApp.getDeviceUceEnabled();
10941 } finally {
10942 Binder.restoreCallingIdentity(identity);
10943 }
10944 }
10945
10946 @Override
10947 public void setDeviceUceEnabled(boolean isEnabled) {
10948 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10949 final long identity = Binder.clearCallingIdentity();
10950 try {
10951 mApp.setDeviceUceEnabled(isEnabled);
10952 } finally {
10953 Binder.restoreCallingIdentity(identity);
10954 }
10955 }
10956
Brad Ebinger14d467f2021-02-12 06:18:28 +000010957 /**
10958 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10959 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10960 */
10961 // Used for SHELL command only right now.
10962 @Override
10963 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10964 List<String> featureTags) {
10965 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10966 "addUceRegistrationOverrideShell");
10967 final long identity = Binder.clearCallingIdentity();
10968 try {
10969 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10970 new ArraySet<>(featureTags));
10971 } catch (ImsException e) {
10972 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10973 } finally {
10974 Binder.restoreCallingIdentity(identity);
10975 }
10976 }
10977
10978 /**
10979 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10980 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10981 */
10982 // Used for SHELL command only right now.
10983 @Override
10984 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10985 List<String> featureTags) {
10986 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10987 "removeUceRegistrationOverrideShell");
10988 final long identity = Binder.clearCallingIdentity();
10989 try {
10990 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10991 new ArraySet<>(featureTags));
10992 } catch (ImsException e) {
10993 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10994 } finally {
10995 Binder.restoreCallingIdentity(identity);
10996 }
10997 }
10998
10999 /**
11000 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11001 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11002 */
11003 // Used for SHELL command only right now.
11004 @Override
11005 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11006 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11007 "clearUceRegistrationOverrideShell");
11008 final long identity = Binder.clearCallingIdentity();
11009 try {
11010 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11011 } catch (ImsException e) {
11012 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11013 } finally {
11014 Binder.restoreCallingIdentity(identity);
11015 }
11016 }
11017
11018 /**
11019 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11020 */
11021 // Used for SHELL command only right now.
11022 @Override
11023 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11024 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11025 "getLatestRcsContactUceCapabilityShell");
11026 final long identity = Binder.clearCallingIdentity();
11027 try {
11028 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11029 } catch (ImsException e) {
11030 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11031 } finally {
11032 Binder.restoreCallingIdentity(identity);
11033 }
11034 }
11035
11036 /**
11037 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11038 * device does not have an active PUBLISH.
11039 */
11040 // Used for SHELL command only right now.
11041 @Override
11042 public String getLastUcePidfXmlShell(int subId) {
11043 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11044 final long identity = Binder.clearCallingIdentity();
11045 try {
11046 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11047 } catch (ImsException e) {
11048 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11049 } finally {
11050 Binder.restoreCallingIdentity(identity);
11051 }
11052 }
11053
James.cf Line8713a42021-04-29 16:04:26 +080011054 /**
11055 * Remove UCE requests cannot be sent to the network status.
11056 */
11057 // Used for SHELL command only right now.
11058 @Override
11059 public boolean removeUceRequestDisallowedStatus(int subId) {
11060 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11061 final long identity = Binder.clearCallingIdentity();
11062 try {
11063 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11064 } catch (ImsException e) {
11065 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11066 } finally {
11067 Binder.restoreCallingIdentity(identity);
11068 }
11069 }
11070
James.cf Lin18bb9002021-05-25 01:37:38 +080011071 /**
11072 * Remove UCE requests cannot be sent to the network status.
11073 */
11074 // Used for SHELL command only.
11075 @Override
11076 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11077 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11078 final long identity = Binder.clearCallingIdentity();
11079 try {
11080 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11081 } catch (ImsException e) {
11082 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11083 } finally {
11084 Binder.restoreCallingIdentity(identity);
11085 }
11086 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011087
James.cf Lin4b784aa2021-01-31 03:25:15 +080011088 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011089 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11090 String callingPackage) {
11091 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11092 mApp, subId, "setSignalStrengthUpdateRequest");
11093
11094 final int callingUid = Binder.getCallingUid();
11095 // Verify that tha callingPackage belongs to the calling UID
11096 mApp.getSystemService(AppOpsManager.class)
11097 .checkPackage(callingUid, callingPackage);
11098
Rambo Wang3607f502021-02-01 21:51:40 -080011099 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011100
11101 final long identity = Binder.clearCallingIdentity();
11102 try {
11103 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11104 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11105
11106 if (result instanceof IllegalStateException) {
11107 throw (IllegalStateException) result;
11108 }
11109 } finally {
11110 Binder.restoreCallingIdentity(identity);
11111 }
11112 }
11113
11114 @Override
11115 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11116 String callingPackage) {
11117 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11118 mApp, subId, "clearSignalStrengthUpdateRequest");
11119
11120 final int callingUid = Binder.getCallingUid();
11121 // Verify that tha callingPackage belongs to the calling UID
11122 mApp.getSystemService(AppOpsManager.class)
11123 .checkPackage(callingUid, callingPackage);
11124
11125 final long identity = Binder.clearCallingIdentity();
11126 try {
11127 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11128 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11129
11130 if (result instanceof IllegalStateException) {
11131 throw (IllegalStateException) result;
11132 }
11133 } finally {
11134 Binder.restoreCallingIdentity(identity);
11135 }
11136 }
11137
Rambo Wang3607f502021-02-01 21:51:40 -080011138 private static void validateSignalStrengthUpdateRequest(Context context,
11139 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011140 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11141 // phone/system process do not have further restriction on request
11142 return;
11143 }
11144
11145 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011146 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011147 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011148 context.enforceCallingOrSelfPermission(
11149 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11150 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011151 }
11152
11153 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11154 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11155 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11156 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11157 || info.isEnabled()) {
11158 throw new IllegalArgumentException(
11159 "Only system can set hide fields in SignalThresholdInfo");
11160 }
11161
11162 // Thresholds length for each RAN need in range. This has been validated in
11163 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11164 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11165 final int[] thresholds = info.getThresholds();
11166 Objects.requireNonNull(thresholds);
11167 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11168 || thresholds.length
11169 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11170 throw new IllegalArgumentException(
11171 "thresholds length is out of range: " + thresholds.length);
11172 }
11173 }
11174 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011175
11176 /**
11177 * Gets the current phone capability.
11178 *
11179 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11180 * @return the PhoneCapability which describes the data connection capability of modem.
11181 * It's used to evaluate possible phone config change, for example from single
11182 * SIM device to multi-SIM device.
11183 */
11184 @Override
11185 public PhoneCapability getPhoneCapability() {
11186 enforceReadPrivilegedPermission("getPhoneCapability");
11187 final long identity = Binder.clearCallingIdentity();
11188 try {
11189 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11190 } finally {
11191 Binder.restoreCallingIdentity(identity);
11192 }
11193 }
Michele Berionne5e411512020-11-13 02:36:59 +000011194
11195 /**
11196 * Prepare TelephonyManager for an unattended reboot. The reboot is
11197 * required to be done shortly after the API is invoked.
11198 */
11199 @Override
11200 @TelephonyManager.PrepareUnattendedRebootResult
11201 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011202 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011203 enforceRebootPermission();
11204
11205 final long identity = Binder.clearCallingIdentity();
11206 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011207 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011208 } finally {
11209 Binder.restoreCallingIdentity(identity);
11210 }
11211 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011212
11213 /**
11214 * Request to get the current slicing configuration including URSP rules and
11215 * NSSAIs (configured, allowed and rejected).
11216 *
11217 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11218 */
11219 @Override
11220 public void getSlicingConfig(ResultReceiver callback) {
11221 enforceReadPrivilegedPermission("getSlicingConfig");
11222
11223 final long identity = Binder.clearCallingIdentity();
11224 try {
11225 Phone phone = getDefaultPhone();
11226 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11227 } finally {
11228 Binder.restoreCallingIdentity(identity);
11229 }
11230 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011231
11232 /**
11233 * Register an IMS connection state callback
11234 */
11235 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011236 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11237 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011238 if (feature == ImsFeature.FEATURE_MMTEL) {
11239 // ImsMmTelManager
11240 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11241 TelephonyPermissions
11242 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11243 mApp, subId, "registerImsStateCallback");
11244 } else if (feature == ImsFeature.FEATURE_RCS) {
11245 // ImsRcsManager or SipDelegateManager
11246 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11247 Binder.getCallingUid(), "registerImsStateCallback",
11248 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11249 Manifest.permission.READ_PRECISE_PHONE_STATE,
11250 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11251 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11252 }
11253
11254 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11255 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11256 "IMS not available on device.");
11257 }
11258
11259 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11260 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11261 }
11262
11263 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11264 if (controller == null) {
11265 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11266 "IMS not available on device.");
11267 }
11268
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011269 if (callingPackage == null) {
11270 callingPackage = getCurrentPackageName();
11271 }
11272
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011273 final long token = Binder.clearCallingIdentity();
11274 try {
11275 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011276 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011277 } catch (ImsException e) {
11278 throw new ServiceSpecificException(e.getCode());
11279 } finally {
11280 Binder.restoreCallingIdentity(token);
11281 }
11282 }
11283
11284 /**
11285 * Unregister an IMS connection state callback
11286 */
11287 @Override
11288 public void unregisterImsStateCallback(IImsStateCallback cb) {
11289 final long token = Binder.clearCallingIdentity();
11290 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11291 if (controller == null) {
11292 return;
11293 }
11294 try {
11295 controller.unregisterImsStateCallback(cb);
11296 } finally {
11297 Binder.restoreCallingIdentity(token);
11298 }
11299 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011300
11301 /**
11302 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11303 *
11304 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11305 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11306 * SecurityException.
11307 * If there is current registered network this value will be same as the registered cell
11308 * identity. If the device goes out of service the previous cell identity is cached and
11309 * will be returned. If the cache age of the Cell identity is more than 24 hours
11310 * it will be cleared and null will be returned.
11311 *
11312 */
11313 @Override
11314 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11315 String callingFeatureId) {
11316 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11317 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11318 LocationAccessPolicy.checkLocationPermission(mApp,
11319 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11320 .setCallingPackage(callingPackage)
11321 .setCallingFeatureId(callingFeatureId)
11322 .setCallingPid(Binder.getCallingPid())
11323 .setCallingUid(Binder.getCallingUid())
11324 .setMethod("getLastKnownCellIdentity")
11325 .setLogAsInfo(true)
11326 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11327 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11328 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11329 .build());
11330
11331 boolean hasFinePermission =
11332 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11333 if (!hasFinePermission
11334 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11335 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
11336 + "and BIND_CONNECTION_SERVICE permission.");
11337 }
11338
11339 final long identity = Binder.clearCallingIdentity();
11340 try {
11341 Phone phone = getPhone(subId);
11342 if (phone == null) return null;
11343 ServiceStateTracker sst = phone.getServiceStateTracker();
11344 if (sst == null) return null;
11345 return sst.getLastKnownCellIdentity();
11346 } finally {
11347 Binder.restoreCallingIdentity(identity);
11348 }
11349 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011350
11351 @Override
11352 public boolean isUsingNewDataStack() {
11353 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "isUsingNewDataStack");
11354 return getDefaultPhone().isUsingNewDataStack();
11355 }
jimsun3b9ccac2021-10-26 15:01:23 +080011356
11357 /**
11358 * Sets the modem service class Name that Telephony will bind to.
11359 *
11360 * @param serviceName The class name of the modem service.
11361 * @return true if the operation is succeed, otherwise false.
11362 */
11363 public boolean setModemService(String serviceName) {
11364 Log.d(LOG_TAG, "setModemService - " + serviceName);
11365 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11366 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11367 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11368 "setModemService");
11369 return mPhoneConfigurationManager.setModemService(serviceName);
11370 }
11371
11372 /**
11373 * Return the class name of the currently bounded modem service.
11374 *
11375 * @return the class name of the modem service.
11376 */
11377 public String getModemService() {
11378 String result;
11379 Log.d(LOG_TAG, "getModemService");
11380 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11381 TelephonyPermissions
11382 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11383 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11384 "getModemService");
11385 result = mPhoneConfigurationManager.getModemService();
11386 Log.d(LOG_TAG, "result = " + result);
11387 return result;
11388 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011389}