blob: 2eea80d372ecb394d48ba155a2ed5fb913ed8f46 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Shuo Qianccbaf742021-02-22 18:32:21 -080021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
22import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070024import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000025import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070026
Brad Ebinger34c09a52021-02-17 23:23:21 +000027import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080029import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070030import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000031import android.annotation.RequiresPermission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080033import android.app.PendingIntent;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000034import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080035import android.app.role.RoleManager;
Chen Xu540470b2021-12-14 17:15:47 -080036import android.compat.Compatibility;
sandeepjsb6c87872021-09-27 15:34:44 +000037import android.compat.annotation.ChangeId;
38import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070039import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070040import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.content.Context;
42import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070043import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070044import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080045import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070046import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.net.Uri;
48import android.os.AsyncResult;
49import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080050import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070051import android.os.Bundle;
52import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070053import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054import android.os.Looper;
55import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070056import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080057import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070058import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070059import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080060import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080061import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070062import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070063import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080064import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070065import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070066import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070067import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070068import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070069import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080070import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070071import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090072import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080073import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080074import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070075import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070076import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080077import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080078import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070079import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080080import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070081import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080082import android.telephony.CellIdentityCdma;
83import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070084import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070085import android.telephony.CellInfoGsm;
86import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070087import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080088import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070089import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070090import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070091import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080092import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070093import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080094import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070095import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080096import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080097import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070098import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080099import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700100import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800101import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800102import android.telephony.SignalStrengthUpdateRequest;
103import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800104import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800105import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800106import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700107import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700108import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800109import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800110import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800111import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000112import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000113import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000114import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700115import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700116import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800117import android.telephony.data.ApnSetting;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800118import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800119import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700120import android.telephony.gba.GbaAuthRequest;
121import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700122import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800123import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000124import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000125import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700126import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700127import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800128import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700129import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800130import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700131import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000132import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700133import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800134import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800135import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800136import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800137import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800139import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700140import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700141import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800142import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800143
Andrew Lee312e8172014-10-23 17:01:36 -0700144import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800145import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800146import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800147import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800148import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700149import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700150import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700151import com.android.internal.telephony.CallTracker;
chen xu651eec72018-11-11 19:03:44 -0800152import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700153import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700154import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800155import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700156import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700157import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800158import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800159import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800160import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700161import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000162import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700163import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800164import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700165import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800166import com.android.internal.telephony.IccCard;
Rambo Wanga1782702021-11-10 20:15:19 -0800167import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700168import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700169import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700170import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700171import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700172import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800173import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700174import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700175import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700176import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700177import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800178import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800179import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700180import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700181import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700182import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800183import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800184import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800185import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700186import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800187import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700188import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800189import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700190import com.android.internal.telephony.imsphone.ImsPhone;
191import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000192import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800193import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700194import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700195import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800196import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700197import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800198import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700199import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800200import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700201import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000202import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800203import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000204import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800205import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700206import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700207import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800208import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800209import com.android.phone.callcomposer.CallComposerPictureManager;
210import com.android.phone.callcomposer.CallComposerPictureTransfer;
211import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700212import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700213import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800214import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700215import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700216import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800217import com.android.services.telephony.TelecomAccountRegistry;
218import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800219import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800220
Hall Liu82694d52020-12-11 18:22:04 -0800221import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700222import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800223import java.io.IOException;
224import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700225import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700226import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800227import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000228import java.util.Collection;
sqian11b7a0e2018-12-05 18:48:28 -0800229import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800230import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800231import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100232import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800233import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700234import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800235import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800236import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800237import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800238import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800239import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700240
241/**
242 * Implementation of the ITelephony interface.
243 */
Santos Cordon117fee72014-05-16 17:56:12 -0700244public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700245 private static final String LOG_TAG = "PhoneInterfaceManager";
246 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
247 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800248 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700249
250 // Message codes used with mMainThreadHandler
251 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700252 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
253 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700254 private static final int CMD_OPEN_CHANNEL = 9;
255 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
256 private static final int CMD_CLOSE_CHANNEL = 11;
257 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800258 private static final int CMD_NV_READ_ITEM = 13;
259 private static final int EVENT_NV_READ_ITEM_DONE = 14;
260 private static final int CMD_NV_WRITE_ITEM = 15;
261 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
262 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
263 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700264 private static final int CMD_RESET_MODEM_CONFIG = 19;
265 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800266 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
267 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800268 private static final int CMD_SEND_ENVELOPE = 25;
269 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000270 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
271 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700272 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
273 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
274 private static final int CMD_EXCHANGE_SIM_IO = 31;
275 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800276 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
277 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700278 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
279 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700280 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
281 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700282 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
283 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
284 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
285 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700286 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
287 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
288 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
289 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700290 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800291 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
292 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000293 private static final int CMD_SWITCH_SLOTS = 50;
294 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700295 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
296 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
297 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
298 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
299 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
300 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
301 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
302 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700303 private static final int CMD_GET_ALL_CELL_INFO = 60;
304 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
305 private static final int CMD_GET_CELL_LOCATION = 62;
306 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700307 private static final int CMD_MODEM_REBOOT = 64;
308 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700309 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
310 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800311 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
312 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700313 private static final int CMD_GET_MODEM_STATUS = 70;
314 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700315 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
316 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700317 private static final int CMD_ERASE_MODEM_CONFIG = 74;
318 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800319 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
320 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
321 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
322 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800323 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
324 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800325 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800326 private static final int CMD_GET_CALL_FORWARDING = 83;
327 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
328 private static final int CMD_SET_CALL_FORWARDING = 85;
329 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
330 private static final int CMD_GET_CALL_WAITING = 87;
331 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
332 private static final int CMD_SET_CALL_WAITING = 89;
333 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700334 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
335 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
336 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
337 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700338 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
339 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800340 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
341 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800342 private static final int CMD_SET_DATA_THROTTLING = 99;
343 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800344 private static final int CMD_SET_SIM_POWER = 101;
345 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800346 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
347 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
348 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
349 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800350 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
351 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000352 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800353 private static final int CMD_GET_SLICING_CONFIG = 110;
354 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800355 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700356 private static final int CMD_ENABLE_VONR = 113;
357 private static final int EVENT_ENABLE_VONR_DONE = 114;
358 private static final int CMD_IS_VONR_ENABLED = 115;
359 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700360
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800361 // Parameters of select command.
362 private static final int SELECT_COMMAND = 0xA4;
363 private static final int SELECT_P1 = 0x04;
364 private static final int SELECT_P2 = 0;
365 private static final int SELECT_P3 = 0x10;
366
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700367 /** The singleton instance. */
368 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800369 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700370
Wink Saville3ab207e2014-11-20 13:07:20 -0800371 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800372 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800373 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700374 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800375 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700376 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800377 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800378 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800379 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700380 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800381 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700382
Peter Wangdafb9ac2020-01-15 14:13:38 -0800383 /** User Activity */
384 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800385 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
386
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700387 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
388
Derek Tan97ebb422014-09-05 16:55:38 -0700389 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
390 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800391 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800392 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700393
Michelecea4cf22018-12-21 15:00:11 -0800394 // String to store multi SIM allowed
395 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
396
Derek Tan740e1672017-06-27 14:56:27 -0700397 // The AID of ISD-R.
398 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
399
yinxub1bed742017-04-17 11:45:04 -0700400 private NetworkScanRequestTracker mNetworkScanRequestTracker;
401
David Kelly5e06a7f2018-03-12 14:10:59 +0000402 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
403 private static final int MANUFACTURER_CODE_LENGTH = 8;
404
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800405 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800406 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800407
Derek Tan89e89d42014-07-08 17:00:10 -0700408 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700409 * Experiment flag to enable erase modem config on reset network, default value is false
410 */
411 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
412 "reset_network_erase_modem_config_enabled";
413
Rambo Wang0f050d82021-02-12 11:43:36 -0800414 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800415
sandeepjsb6c87872021-09-27 15:34:44 +0000416 /**
417 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
418 * one ICCID active at the same time.
419 * Apps should use below API signatures if targeting SDK is T and beyond.
420 *
421 * @hide
422 */
423 @ChangeId
424 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
425 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800426
Naina Nallurid63128d2019-09-17 14:10:30 -0700427 /**
Chen Xu540470b2021-12-14 17:15:47 -0800428 * Apps targeting on Android T and beyond will get exception whenever icc close channel
429 * operation fails.
430 */
431 @ChangeId
432 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
433 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
434
435 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700436 * A request object to use for transmitting data to an ICC.
437 */
438 private static final class IccAPDUArgument {
439 public int channel, cla, command, p1, p2, p3;
440 public String data;
441
442 public IccAPDUArgument(int channel, int cla, int command,
443 int p1, int p2, int p3, String data) {
444 this.channel = channel;
445 this.cla = cla;
446 this.command = command;
447 this.p1 = p1;
448 this.p2 = p2;
449 this.p3 = p3;
450 this.data = data;
451 }
452 }
453
454 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700455 * A request object to use for transmitting data to an ICC.
456 */
457 private static final class ManualNetworkSelectionArgument {
458 public OperatorInfo operatorInfo;
459 public boolean persistSelection;
460
461 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
462 this.operatorInfo = operatorInfo;
463 this.persistSelection = persistSelection;
464 }
465 }
466
467 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700468 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
469 * request after sending. The main thread will notify the request when it is complete.
470 */
471 private static final class MainThreadRequest {
472 /** The argument to use for the request */
473 public Object argument;
474 /** The result of the request that is run on the main thread */
475 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800476 // The subscriber id that this request applies to. Defaults to
477 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
478 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700479
Nathan Harold92bed182018-10-12 18:16:49 -0700480 // In cases where subId is unavailable, the caller needs to specify the phone.
481 public Phone phone;
482
vagdeviaf9a5b92018-08-15 16:01:53 -0700483 public WorkSource workSource;
484
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700485 public MainThreadRequest(Object argument) {
486 this.argument = argument;
487 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800488
Nathan Harold92bed182018-10-12 18:16:49 -0700489 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
490 this.argument = argument;
491 if (phone != null) {
492 this.phone = phone;
493 }
494 this.workSource = workSource;
495 }
496
vagdeviaf9a5b92018-08-15 16:01:53 -0700497 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800498 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800499 if (subId != null) {
500 this.subId = subId;
501 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700502 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800503 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700504 }
505
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800506 private static final class IncomingThirdPartyCallArgs {
507 public final ComponentName component;
508 public final String callId;
509 public final String callerDisplayName;
510
511 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
512 String callerDisplayName) {
513 this.component = component;
514 this.callId = callId;
515 this.callerDisplayName = callerDisplayName;
516 }
517 }
518
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700519 /**
520 * A handler that processes messages on the main thread in the phone process. Since many
521 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
522 * inbound binder threads to the main thread in the phone process. The Binder thread
523 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
524 * on, which will be notified when the operation completes and will contain the result of the
525 * request.
526 *
527 * <p>If a MainThreadRequest object is provided in the msg.obj field,
528 * note that request.result must be set to something non-null for the calling thread to
529 * unblock.
530 */
531 private final class MainThreadHandler extends Handler {
532 @Override
533 public void handleMessage(Message msg) {
534 MainThreadRequest request;
535 Message onCompleted;
536 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000537 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700538 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800539 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700540
541 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700542 case CMD_HANDLE_USSD_REQUEST: {
543 request = (MainThreadRequest) msg.obj;
544 final Phone phone = getPhoneFromRequest(request);
545 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
546 String ussdRequest = ussdObject.first;
547 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700548
Pengquan Menga1bb6272018-09-06 09:59:22 -0700549 if (!isUssdApiAllowed(request.subId)) {
550 // Carrier does not support use of this API, return failure.
551 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
552 UssdResponse response = new UssdResponse(ussdRequest, null);
553 Bundle returnData = new Bundle();
554 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
555 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700556
Pengquan Menga1bb6272018-09-06 09:59:22 -0700557 request.result = true;
558 notifyRequester(request);
559 return;
560 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700561
Pengquan Menga1bb6272018-09-06 09:59:22 -0700562 try {
563 request.result = phone != null
564 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
565 } catch (CallStateException cse) {
566 request.result = false;
567 }
568 // Wake up the requesting thread
569 notifyRequester(request);
570 break;
pkanwar32d516d2016-10-14 19:37:38 -0700571 }
572
Yorke Lee716f67e2015-06-17 15:39:16 -0700573 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700574 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700575 final Phone phone = getPhoneFromRequest(request);
576 request.result = phone != null ?
577 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
578 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700579 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700580 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700581 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700582 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700583
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700584 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700585 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700586 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000587 uiccPort = getUiccPortFromRequest(request);
588 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700589 loge("iccTransmitApduLogicalChannel: No UICC");
590 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700591 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700592 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700593 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
594 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000595 uiccPort.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700596 iccArgument.channel, iccArgument.cla, iccArgument.command,
597 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700598 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700599 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700600 break;
601
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700602 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700603 ar = (AsyncResult) msg.obj;
604 request = (MainThreadRequest) ar.userObj;
605 if (ar.exception == null && ar.result != null) {
606 request.result = ar.result;
607 } else {
608 request.result = new IccIoResult(0x6F, 0, (byte[])null);
609 if (ar.result == null) {
610 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800611 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700612 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800613 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700614 } else {
615 loge("iccTransmitApduLogicalChannel: Unknown exception");
616 }
617 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700618 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700619 break;
620
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700621 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
622 request = (MainThreadRequest) msg.obj;
623 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000624 uiccPort = getUiccPortFromRequest(request);
625 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700626 loge("iccTransmitApduBasicChannel: No UICC");
627 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700628 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700629 } else {
630 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
631 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000632 uiccPort.iccTransmitApduBasicChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700633 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
634 iccArgument.p3, iccArgument.data, onCompleted);
635 }
636 break;
637
638 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
639 ar = (AsyncResult) msg.obj;
640 request = (MainThreadRequest) ar.userObj;
641 if (ar.exception == null && ar.result != null) {
642 request.result = ar.result;
643 } else {
644 request.result = new IccIoResult(0x6F, 0, (byte[])null);
645 if (ar.result == null) {
646 loge("iccTransmitApduBasicChannel: Empty response");
647 } else if (ar.exception instanceof CommandException) {
648 loge("iccTransmitApduBasicChannel: CommandException: " +
649 ar.exception);
650 } else {
651 loge("iccTransmitApduBasicChannel: Unknown exception");
652 }
653 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700654 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700655 break;
656
657 case CMD_EXCHANGE_SIM_IO:
658 request = (MainThreadRequest) msg.obj;
659 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000660 uiccPort = getUiccPortFromRequest(request);
661 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700662 loge("iccExchangeSimIO: No UICC");
663 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700664 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700665 } else {
666 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
667 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000668 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700669 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
670 iccArgument.data, onCompleted);
671 }
672 break;
673
674 case EVENT_EXCHANGE_SIM_IO_DONE:
675 ar = (AsyncResult) msg.obj;
676 request = (MainThreadRequest) ar.userObj;
677 if (ar.exception == null && ar.result != null) {
678 request.result = ar.result;
679 } else {
680 request.result = new IccIoResult(0x6f, 0, (byte[])null);
681 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700682 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700683 break;
684
Derek Tan4d5e5c12014-02-04 11:54:58 -0800685 case CMD_SEND_ENVELOPE:
686 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000687 uiccPort = getUiccPortFromRequest(request);
688 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700689 loge("sendEnvelopeWithStatus: No UICC");
690 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700691 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700692 } else {
693 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000694 uiccPort.sendEnvelopeWithStatus((String)request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700695 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800696 break;
697
698 case EVENT_SEND_ENVELOPE_DONE:
699 ar = (AsyncResult) msg.obj;
700 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700701 if (ar.exception == null && ar.result != null) {
702 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800703 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700704 request.result = new IccIoResult(0x6F, 0, (byte[])null);
705 if (ar.result == null) {
706 loge("sendEnvelopeWithStatus: Empty response");
707 } else if (ar.exception instanceof CommandException) {
708 loge("sendEnvelopeWithStatus: CommandException: " +
709 ar.exception);
710 } else {
711 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
712 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800713 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700714 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800715 break;
716
Shishir Agrawal566b7612013-10-28 14:41:00 -0700717 case CMD_OPEN_CHANNEL:
718 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000719 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800720 IccLogicalChannelRequest openChannelRequest =
721 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000722 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700723 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800724 request.result = new IccOpenLogicalChannelResponse(-1,
725 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700726 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700727 } else {
728 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800729 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
730 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700731 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700732 break;
733
734 case EVENT_OPEN_CHANNEL_DONE:
735 ar = (AsyncResult) msg.obj;
736 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700737 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700738 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700739 int[] result = (int[]) ar.result;
740 int channelId = result[0];
741 byte[] selectResponse = null;
742 if (result.length > 1) {
743 selectResponse = new byte[result.length - 1];
744 for (int i = 1; i < result.length; ++i) {
745 selectResponse[i - 1] = (byte) result[i];
746 }
747 }
748 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700749 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800750
751 uiccPort = getUiccPortFromRequest(request);
752 IccLogicalChannelRequest channelRequest =
753 (IccLogicalChannelRequest) request.argument;
754 channelRequest.channel = channelId;
755 uiccPort.onLogicalChannelOpened(channelRequest);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700756 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700757 if (ar.result == null) {
758 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700759 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700760 if (ar.exception != null) {
761 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
762 }
763
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700764 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700765 if (ar.exception instanceof CommandException) {
766 CommandException.Error error =
767 ((CommandException) (ar.exception)).getCommandError();
768 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700769 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700770 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700771 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700772 }
773 }
774 openChannelResp = new IccOpenLogicalChannelResponse(
775 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700776 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700777 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700778 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700779 break;
780
781 case CMD_CLOSE_CHANNEL:
782 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000783 uiccPort = getUiccPortFromRequest(request);
784 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700785 loge("iccCloseLogicalChannel: No UICC");
Chen Xu540470b2021-12-14 17:15:47 -0800786 throw new IllegalArgumentException("iccCloseLogicalChannel: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700787 } else {
788 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000789 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700790 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700791 break;
792
793 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800794 ar = (AsyncResult) msg.obj;
795 request = (MainThreadRequest) ar.userObj;
796 if (ar.exception == null) {
797 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800798 uiccPort = getUiccPortFromRequest(request);
799 final int channelId = (Integer) request.argument;
800 uiccPort.onLogicalChannelClosed(channelId);
Chen Xu540470b2021-12-14 17:15:47 -0800801 } else {
802 request.result = false;
803 if (ar.exception instanceof CommandException) {
804 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
805 CommandException.Error error =
806 ((CommandException) (ar.exception)).getCommandError();
807 // before this feature is enabled, this API should only return false if
808 // the operation fails instead of throwing runtime exception for
809 // backward-compatibility.
810 if (Compatibility.isChangeEnabled(
811 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE)
812 && error == CommandException.Error.INVALID_ARGUMENTS) {
813 throw new IllegalArgumentException(
814 "iccCloseLogicalChannel: invalid argument ");
815 }
816 } else {
817 loge("iccCloseLogicalChannel: Unknown exception");
818 }
819 if (Compatibility.isChangeEnabled(ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE)) {
820 throw new IllegalStateException(
821 "exception from modem to close iccLogical Channel");
822 }
823 }
824 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800825 break;
826
827 case CMD_NV_READ_ITEM:
828 request = (MainThreadRequest) msg.obj;
829 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800830 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
831 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800832 break;
833
834 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700835 ar = (AsyncResult) msg.obj;
836 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800837 if (ar.exception == null && ar.result != null) {
838 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700839 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800840 request.result = "";
841 if (ar.result == null) {
842 loge("nvReadItem: Empty response");
843 } else if (ar.exception instanceof CommandException) {
844 loge("nvReadItem: CommandException: " +
845 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700846 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800847 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700848 }
849 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700850 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700851 break;
852
Jake Hambye994d462014-02-03 13:10:13 -0800853 case CMD_NV_WRITE_ITEM:
854 request = (MainThreadRequest) msg.obj;
855 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
856 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800857 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700858 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800859 break;
860
861 case EVENT_NV_WRITE_ITEM_DONE:
862 handleNullReturnEvent(msg, "nvWriteItem");
863 break;
864
865 case CMD_NV_WRITE_CDMA_PRL:
866 request = (MainThreadRequest) msg.obj;
867 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800868 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800869 break;
870
871 case EVENT_NV_WRITE_CDMA_PRL_DONE:
872 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
873 break;
874
chen xu6dac5ab2018-10-26 17:39:23 -0700875 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800876 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700877 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800878 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800879 break;
880
chen xu6dac5ab2018-10-26 17:39:23 -0700881 case EVENT_RESET_MODEM_CONFIG_DONE:
882 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800883 break;
884
Sooraj Sasindran37444802020-08-11 10:40:43 -0700885 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
886 request = (MainThreadRequest) msg.obj;
887 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
888 request);
889 Phone phone = getPhoneFromRequest(request);
890 if (phone != null) {
891 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
892 } else {
893 loge("isNRDualConnectivityEnabled: No phone object");
894 request.result = false;
895 notifyRequester(request);
896 }
897 break;
898 }
899
900 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
901 ar = (AsyncResult) msg.obj;
902 request = (MainThreadRequest) ar.userObj;
903 if (ar.exception == null && ar.result != null) {
904 request.result = ar.result;
905 } else {
906 // request.result must be set to something non-null
907 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700908 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700909 request.result = ar.result;
910 } else {
911 request.result = false;
912 }
913 if (ar.result == null) {
914 loge("isNRDualConnectivityEnabled: Empty response");
915 } else if (ar.exception instanceof CommandException) {
916 loge("isNRDualConnectivityEnabled: CommandException: "
917 + ar.exception);
918 } else {
919 loge("isNRDualConnectivityEnabled: Unknown exception");
920 }
921 }
922 notifyRequester(request);
923 break;
924
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700925 case CMD_IS_VONR_ENABLED: {
926 request = (MainThreadRequest) msg.obj;
927 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
928 request);
929 Phone phone = getPhoneFromRequest(request);
930 if (phone != null) {
931 phone.isVoNrEnabled(onCompleted, request.workSource);
932 } else {
933 loge("isVoNrEnabled: No phone object");
934 request.result = false;
935 notifyRequester(request);
936 }
937 break;
938 }
939
940 case EVENT_IS_VONR_ENABLED_DONE:
941 ar = (AsyncResult) msg.obj;
942 request = (MainThreadRequest) ar.userObj;
943 if (ar.exception == null && ar.result != null) {
944 request.result = ar.result;
945 } else {
946 // request.result must be set to something non-null
947 // for the calling thread to unblock
948 if (ar.result != null) {
949 request.result = ar.result;
950 } else {
951 request.result = false;
952 }
953 if (ar.result == null) {
954 loge("isVoNrEnabled: Empty response");
955 } else if (ar.exception instanceof CommandException) {
956 loge("isVoNrEnabled: CommandException: "
957 + ar.exception);
958 } else {
959 loge("isVoNrEnabled: Unknown exception");
960 }
961 }
962 notifyRequester(request);
963 break;
964
Sooraj Sasindran37444802020-08-11 10:40:43 -0700965 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
966 request = (MainThreadRequest) msg.obj;
967 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
968 Phone phone = getPhoneFromRequest(request);
969 if (phone != null) {
970 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
971 request.workSource);
972 } else {
973 loge("enableNrDualConnectivity: No phone object");
974 request.result =
975 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
976 notifyRequester(request);
977 }
978 break;
979 }
980
981 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
982 ar = (AsyncResult) msg.obj;
983 request = (MainThreadRequest) ar.userObj;
984 if (ar.exception == null) {
985 request.result =
986 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
987 } else {
988 request.result =
989 TelephonyManager
990 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
991 if (ar.exception instanceof CommandException) {
992 CommandException.Error error =
993 ((CommandException) (ar.exception)).getCommandError();
994 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
995 request.result =
996 TelephonyManager
997 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000998 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
999 request.result =
1000 TelephonyManager
1001 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001002 }
1003 loge("enableNrDualConnectivity" + ": CommandException: "
1004 + ar.exception);
1005 } else {
1006 loge("enableNrDualConnectivity" + ": Unknown exception");
1007 }
1008 }
1009 notifyRequester(request);
1010 break;
1011 }
1012
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001013 case CMD_ENABLE_VONR: {
1014 request = (MainThreadRequest) msg.obj;
1015 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1016 Phone phone = getPhoneFromRequest(request);
1017 if (phone != null) {
1018 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1019 request.workSource);
1020 } else {
1021 loge("setVoNrEnabled: No phone object");
1022 request.result =
1023 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1024 notifyRequester(request);
1025 }
1026 break;
1027 }
1028
1029 case EVENT_ENABLE_VONR_DONE: {
1030 ar = (AsyncResult) msg.obj;
1031 request = (MainThreadRequest) ar.userObj;
1032 if (ar.exception == null) {
1033 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1034 } else {
1035 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1036 if (ar.exception instanceof CommandException) {
1037 CommandException.Error error =
1038 ((CommandException) (ar.exception)).getCommandError();
1039 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1040 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1041 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1042 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1043 } else {
1044 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1045 }
1046 loge("setVoNrEnabled" + ": CommandException: "
1047 + ar.exception);
1048 } else {
1049 loge("setVoNrEnabled" + ": Unknown exception");
1050 }
1051 }
1052 notifyRequester(request);
1053 break;
1054 }
1055
SongFerngWang3ef3e072020-12-21 16:41:52 +08001056 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001057 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001058 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1059 request);
1060 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001061 break;
1062
SongFerngWang3ef3e072020-12-21 16:41:52 +08001063 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001064 ar = (AsyncResult) msg.obj;
1065 request = (MainThreadRequest) ar.userObj;
1066 if (ar.exception == null && ar.result != null) {
1067 request.result = ar.result; // Integer
1068 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301069 // request.result must be set to something non-null
1070 // for the calling thread to unblock
1071 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001072 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001073 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001074 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001075 loge("getAllowedNetworkTypesBitmask: CommandException: "
1076 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001077 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001078 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001079 }
1080 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001081 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001082 break;
1083
SongFerngWang3ef3e072020-12-21 16:41:52 +08001084 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001085 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001086 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1087 request);
1088 Pair<Integer, Long> reasonWithNetworkTypes =
1089 (Pair<Integer, Long>) request.argument;
1090 getPhoneFromRequest(request).setAllowedNetworkTypes(
1091 reasonWithNetworkTypes.first,
1092 reasonWithNetworkTypes.second,
1093 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001094 break;
1095
SongFerngWang3ef3e072020-12-21 16:41:52 +08001096 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1097 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001098 break;
1099
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001100 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1101 request = (MainThreadRequest)msg.obj;
1102 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001103 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001104 break;
1105
1106 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1107 ar = (AsyncResult)msg.obj;
1108 request = (MainThreadRequest)ar.userObj;
1109 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001110 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001111 break;
1112
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001113 case CMD_SET_VOICEMAIL_NUMBER:
1114 request = (MainThreadRequest) msg.obj;
1115 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1116 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001117 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1118 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001119 break;
1120
1121 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1122 handleNullReturnEvent(msg, "setVoicemailNumber");
1123 break;
1124
Stuart Scott54788802015-03-30 13:18:01 -07001125 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1126 request = (MainThreadRequest) msg.obj;
1127 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1128 request);
1129 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1130 break;
1131
1132 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1133 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1134 break;
1135
Shishir Agrawal302c8692015-06-19 13:49:39 -07001136 case CMD_PERFORM_NETWORK_SCAN:
1137 request = (MainThreadRequest) msg.obj;
1138 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1139 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1140 break;
1141
Hall Liu27d24262020-09-18 19:04:59 -07001142 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001143 request = (MainThreadRequest) msg.obj;
1144 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001145 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1146 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1147 request.argument;
1148 int callForwardingReason = args.first;
1149 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001150 break;
Hall Liu27d24262020-09-18 19:04:59 -07001151 }
1152 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001153 ar = (AsyncResult) msg.obj;
1154 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001155 TelephonyManager.CallForwardingInfoCallback callback =
1156 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1157 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001158 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001159 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001160 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1161 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1162 // Service Class is a bit mask per 3gpp 27.007. Search for
1163 // any service for voice call.
1164 if ((callForwardInfo.serviceClass
1165 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001166 callForwardingInfo = new CallForwardingInfo(
1167 callForwardInfo.status
1168 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001169 callForwardInfo.reason,
1170 callForwardInfo.number,
1171 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001172 break;
1173 }
1174 }
1175 // Didn't find a call forward info for voice call.
1176 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001177 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1178 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001179 }
Hall Liu27d24262020-09-18 19:04:59 -07001180 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001181 } else {
1182 if (ar.result == null) {
1183 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1184 }
1185 if (ar.exception != null) {
1186 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1187 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001188 int errorCode = TelephonyManager
1189 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001190 if (ar.exception instanceof CommandException) {
1191 CommandException.Error error =
1192 ((CommandException) (ar.exception)).getCommandError();
1193 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001194 errorCode = TelephonyManager
1195 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001196 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001197 errorCode = TelephonyManager
1198 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001199 }
1200 }
Hall Liu27d24262020-09-18 19:04:59 -07001201 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001202 }
Shuo Qian4a594052020-01-23 11:59:30 -08001203 break;
Hall Liu27d24262020-09-18 19:04:59 -07001204 }
Shuo Qian4a594052020-01-23 11:59:30 -08001205
Hall Liu27d24262020-09-18 19:04:59 -07001206 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001207 request = (MainThreadRequest) msg.obj;
1208 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001209 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001210 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001211 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1212 request.argument).first;
1213 request.phone.setCallForwardingOption(
1214 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001215 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001216 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001217 callForwardingInfoToSet.getReason(),
1218 callForwardingInfoToSet.getNumber(),
1219 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1220 break;
Hall Liu27d24262020-09-18 19:04:59 -07001221 }
Shuo Qian4a594052020-01-23 11:59:30 -08001222
Hall Liu27d24262020-09-18 19:04:59 -07001223 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001224 ar = (AsyncResult) msg.obj;
1225 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001226 Consumer<Integer> callback =
1227 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1228 request.argument).second;
1229 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001230 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001231 int errorCode = TelephonyManager.CallForwardingInfoCallback
1232 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001233 if (ar.exception instanceof CommandException) {
1234 CommandException.Error error =
1235 ((CommandException) (ar.exception)).getCommandError();
1236 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001237 errorCode = TelephonyManager.CallForwardingInfoCallback
1238 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001239 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001240 errorCode = TelephonyManager.CallForwardingInfoCallback
1241 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001242 }
1243 }
1244 callback.accept(errorCode);
1245 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001246 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001247 }
Shuo Qian4a594052020-01-23 11:59:30 -08001248 break;
Hall Liu27d24262020-09-18 19:04:59 -07001249 }
Shuo Qian4a594052020-01-23 11:59:30 -08001250
Hall Liu27d24262020-09-18 19:04:59 -07001251 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001252 request = (MainThreadRequest) msg.obj;
1253 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1254 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1255 break;
Hall Liu27d24262020-09-18 19:04:59 -07001256 }
Shuo Qian4a594052020-01-23 11:59:30 -08001257
Hall Liu27d24262020-09-18 19:04:59 -07001258 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001259 ar = (AsyncResult) msg.obj;
1260 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001261 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001262 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1263 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001264 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001265 // Service Class is a bit mask per 3gpp 27.007.
1266 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001267 if (callForwardResults.length > 1
1268 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001269 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001270 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001271 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1272 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001273 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001274 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001275 }
1276 } else {
1277 if (ar.result == null) {
1278 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1279 }
1280 if (ar.exception != null) {
1281 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1282 }
1283 if (ar.exception instanceof CommandException) {
1284 CommandException.Error error =
1285 ((CommandException) (ar.exception)).getCommandError();
1286 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1287 callForwardingStatus =
1288 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1289 }
1290 }
1291 }
Hall Liu27d24262020-09-18 19:04:59 -07001292 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001293 break;
Hall Liu27d24262020-09-18 19:04:59 -07001294 }
Shuo Qian4a594052020-01-23 11:59:30 -08001295
Hall Liu27d24262020-09-18 19:04:59 -07001296 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001297 request = (MainThreadRequest) msg.obj;
1298 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001299 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1300 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001301 break;
Hall Liu27d24262020-09-18 19:04:59 -07001302 }
Shuo Qian4a594052020-01-23 11:59:30 -08001303
Hall Liu27d24262020-09-18 19:04:59 -07001304 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001305 ar = (AsyncResult) msg.obj;
1306 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001307 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1308 Consumer<Integer> callback =
1309 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1310 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001311 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001312 if (ar.exception instanceof CommandException) {
1313 CommandException.Error error =
1314 ((CommandException) (ar.exception)).getCommandError();
1315 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1316 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1317 } else {
1318 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1319 }
1320 } else {
1321 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1322 }
1323 } else {
1324 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1325 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001326 }
Shuo Qian4a594052020-01-23 11:59:30 -08001327 break;
Hall Liu27d24262020-09-18 19:04:59 -07001328 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001329 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1330 ar = (AsyncResult) msg.obj;
1331 request = (MainThreadRequest) ar.userObj;
1332 CellNetworkScanResult cellScanResult;
1333 if (ar.exception == null && ar.result != null) {
1334 cellScanResult = new CellNetworkScanResult(
1335 CellNetworkScanResult.STATUS_SUCCESS,
1336 (List<OperatorInfo>) ar.result);
1337 } else {
1338 if (ar.result == null) {
1339 loge("getCellNetworkScanResults: Empty response");
1340 }
1341 if (ar.exception != null) {
1342 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1343 }
1344 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1345 if (ar.exception instanceof CommandException) {
1346 CommandException.Error error =
1347 ((CommandException) (ar.exception)).getCommandError();
1348 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1349 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1350 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1351 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1352 }
1353 }
1354 cellScanResult = new CellNetworkScanResult(errorCode, null);
1355 }
1356 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001357 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001358 break;
1359
1360 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1361 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001362 ManualNetworkSelectionArgument selArg =
1363 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001364 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1365 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001366 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1367 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001368 break;
1369
1370 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001371 ar = (AsyncResult) msg.obj;
1372 request = (MainThreadRequest) ar.userObj;
1373 if (ar.exception == null) {
1374 request.result = true;
1375 } else {
1376 request.result = false;
1377 loge("setNetworkSelectionModeManual " + ar.exception);
1378 }
1379 notifyRequester(request);
1380 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001381 break;
1382
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001383 case CMD_GET_MODEM_ACTIVITY_INFO:
1384 request = (MainThreadRequest) msg.obj;
1385 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001386 if (defaultPhone != null) {
1387 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001388 } else {
1389 ResultReceiver result = (ResultReceiver) request.argument;
1390 Bundle bundle = new Bundle();
1391 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001392 new ModemActivityInfo(0, 0, 0,
1393 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001394 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001395 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001396 break;
1397
Hall Liud0f208c2020-10-14 16:54:44 -07001398 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001399 ar = (AsyncResult) msg.obj;
1400 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001401 ResultReceiver result = (ResultReceiver) request.argument;
1402
Hall Liud0f208c2020-10-14 16:54:44 -07001403 ModemActivityInfo ret = null;
1404 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001405 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001406 // Update the last modem activity info and the result of the request.
1407 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1408 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001409 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001410 int[] txTimeMs = info.getTransmitTimeMillis();
1411 int[] lastModemTxTimeMs = mLastModemActivityInfo
1412 .getTransmitTimeMillis();
1413 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1414 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1415 }
Hall Liu49656c02020-10-09 19:00:11 -07001416 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001417 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1418 + mLastModemActivityInfo.getSleepTimeMillis());
1419 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1420 + mLastModemActivityInfo.getIdleTimeMillis());
1421 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1422 mLastModemActivityInfo.setReceiveTimeMillis(
1423 info.getReceiveTimeMillis()
1424 + mLastModemActivityInfo.getReceiveTimeMillis());
1425 }
Hall Liu49656c02020-10-09 19:00:11 -07001426 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001427 mLastModemActivityInfo.getSleepTimeMillis(),
1428 mLastModemActivityInfo.getIdleTimeMillis(),
1429 mLastModemActivityInfo.getTransmitTimeMillis(),
1430 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001431 } else {
1432 if (ar.result == null) {
1433 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001434 error = TelephonyManager.ModemActivityInfoException
1435 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001436 } else if (ar.exception instanceof CommandException) {
1437 loge("queryModemActivityInfo: CommandException: " +
1438 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001439 error = TelephonyManager.ModemActivityInfoException
1440 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001441 } else {
1442 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001443 error = TelephonyManager.ModemActivityInfoException
1444 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001445 }
1446 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001447 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001448 if (ret != null) {
1449 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1450 } else {
1451 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1452 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001453 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001454 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001455 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001456 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001457
Meng Wang1a7c35a2016-05-05 20:56:15 -07001458 case CMD_SET_ALLOWED_CARRIERS:
1459 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001460 CarrierRestrictionRules argument =
1461 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001462 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001463 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001464 break;
1465
1466 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1467 ar = (AsyncResult) msg.obj;
1468 request = (MainThreadRequest) ar.userObj;
1469 if (ar.exception == null && ar.result != null) {
1470 request.result = ar.result;
1471 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001472 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1473 if (ar.exception instanceof CommandException) {
1474 loge("setAllowedCarriers: CommandException: " + ar.exception);
1475 CommandException.Error error =
1476 ((CommandException) (ar.exception)).getCommandError();
1477 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1478 request.result =
1479 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1480 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001481 } else {
1482 loge("setAllowedCarriers: Unknown exception");
1483 }
1484 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001485 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001486 break;
1487
1488 case CMD_GET_ALLOWED_CARRIERS:
1489 request = (MainThreadRequest) msg.obj;
1490 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001491 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001492 break;
1493
1494 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1495 ar = (AsyncResult) msg.obj;
1496 request = (MainThreadRequest) ar.userObj;
1497 if (ar.exception == null && ar.result != null) {
1498 request.result = ar.result;
1499 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001500 request.result = new IllegalStateException(
1501 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001502 if (ar.result == null) {
1503 loge("getAllowedCarriers: Empty response");
1504 } else if (ar.exception instanceof CommandException) {
1505 loge("getAllowedCarriers: CommandException: " +
1506 ar.exception);
1507 } else {
1508 loge("getAllowedCarriers: Unknown exception");
1509 }
1510 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001511 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001512 break;
1513
Nathan Haroldb3014052017-01-25 15:57:32 -08001514 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1515 ar = (AsyncResult) msg.obj;
1516 request = (MainThreadRequest) ar.userObj;
1517 if (ar.exception == null && ar.result != null) {
1518 request.result = ar.result;
1519 } else {
1520 request.result = new IllegalArgumentException(
1521 "Failed to retrieve Forbidden Plmns");
1522 if (ar.result == null) {
1523 loge("getForbiddenPlmns: Empty response");
1524 } else {
1525 loge("getForbiddenPlmns: Unknown exception");
1526 }
1527 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001528 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001529 break;
1530
1531 case CMD_GET_FORBIDDEN_PLMNS:
1532 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001533 uiccPort = getUiccPortFromRequest(request);
1534 if (uiccPort == null) {
1535 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001536 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001537 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001538 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001539 break;
1540 }
1541 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001542 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001543 if (uiccApp == null) {
1544 loge("getForbiddenPlmns() no app with specified type -- "
1545 + appType);
1546 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001547 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001548 break;
1549 } else {
1550 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1551 + " specified type -- " + appType);
1552 }
1553 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1554 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1555 onCompleted);
1556 break;
1557
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001558 case CMD_SWITCH_SLOTS:
1559 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001560 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001561 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001562 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001563 break;
1564
1565 case EVENT_SWITCH_SLOTS_DONE:
1566 ar = (AsyncResult) msg.obj;
1567 request = (MainThreadRequest) ar.userObj;
1568 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001569 notifyRequester(request);
1570 break;
1571 case CMD_GET_NETWORK_SELECTION_MODE:
1572 request = (MainThreadRequest) msg.obj;
1573 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1574 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1575 break;
1576
1577 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1578 ar = (AsyncResult) msg.obj;
1579 request = (MainThreadRequest) ar.userObj;
1580 if (ar.exception != null) {
1581 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1582 } else {
1583 int mode = ((int[]) ar.result)[0];
1584 if (mode == 0) {
1585 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1586 } else {
1587 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1588 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001589 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001590 notifyRequester(request);
1591 break;
1592 case CMD_GET_CDMA_ROAMING_MODE:
1593 request = (MainThreadRequest) msg.obj;
1594 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1595 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1596 break;
1597 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1598 ar = (AsyncResult) msg.obj;
1599 request = (MainThreadRequest) ar.userObj;
1600 if (ar.exception != null) {
1601 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1602 } else {
1603 request.result = ((int[]) ar.result)[0];
1604 }
1605 notifyRequester(request);
1606 break;
1607 case CMD_SET_CDMA_ROAMING_MODE:
1608 request = (MainThreadRequest) msg.obj;
1609 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1610 int mode = (int) request.argument;
1611 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1612 break;
1613 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1614 ar = (AsyncResult) msg.obj;
1615 request = (MainThreadRequest) ar.userObj;
1616 request.result = ar.exception == null;
1617 notifyRequester(request);
1618 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001619 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1620 request = (MainThreadRequest) msg.obj;
1621 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1622 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1623 break;
1624 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1625 ar = (AsyncResult) msg.obj;
1626 request = (MainThreadRequest) ar.userObj;
1627 if (ar.exception != null) {
1628 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1629 } else {
1630 request.result = ((int[]) ar.result)[0];
1631 }
1632 notifyRequester(request);
1633 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001634 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1635 request = (MainThreadRequest) msg.obj;
1636 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1637 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001638 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1639 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001640 break;
1641 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1642 ar = (AsyncResult) msg.obj;
1643 request = (MainThreadRequest) ar.userObj;
1644 request.result = ar.exception == null;
1645 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001646 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001647 case CMD_GET_ALL_CELL_INFO:
1648 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001649 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001650 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001651 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001652 case EVENT_GET_ALL_CELL_INFO_DONE:
1653 ar = (AsyncResult) msg.obj;
1654 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001655 // If a timeout occurs, the response will be null
1656 request.result = (ar.exception == null && ar.result != null)
1657 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001658 synchronized (request) {
1659 request.notifyAll();
1660 }
1661 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001662 case CMD_REQUEST_CELL_INFO_UPDATE:
1663 request = (MainThreadRequest) msg.obj;
1664 request.phone.requestCellInfoUpdate(request.workSource,
1665 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1666 break;
1667 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1668 ar = (AsyncResult) msg.obj;
1669 request = (MainThreadRequest) ar.userObj;
1670 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1671 try {
1672 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001673 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001674 cb.onError(
1675 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1676 ar.exception.getClass().getName(),
1677 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001678 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001679 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001680 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001681 } else {
1682 // use the result as returned
1683 cb.onCellInfo((List<CellInfo>) ar.result);
1684 }
1685 } catch (RemoteException re) {
1686 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1687 }
1688 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001689 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001690 request = (MainThreadRequest) msg.obj;
1691 WorkSource ws = (WorkSource) request.argument;
1692 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001693 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001694 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001695 }
1696 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001697 ar = (AsyncResult) msg.obj;
1698 request = (MainThreadRequest) ar.userObj;
1699 if (ar.exception == null) {
1700 request.result = ar.result;
1701 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001702 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001703 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001704 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001705 }
1706
1707 synchronized (request) {
1708 request.notifyAll();
1709 }
1710 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001711 }
chen xu6dac5ab2018-10-26 17:39:23 -07001712 case CMD_MODEM_REBOOT:
1713 request = (MainThreadRequest) msg.obj;
1714 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001715 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001716 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001717 case EVENT_CMD_MODEM_REBOOT_DONE:
1718 handleNullReturnEvent(msg, "rebootModem");
1719 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001720 case CMD_REQUEST_ENABLE_MODEM:
1721 request = (MainThreadRequest) msg.obj;
1722 boolean enable = (boolean) request.argument;
1723 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001724 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001725 PhoneConfigurationManager.getInstance()
1726 .enablePhone(request.phone, enable, onCompleted);
1727 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001728 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001729 ar = (AsyncResult) msg.obj;
1730 request = (MainThreadRequest) ar.userObj;
1731 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001732 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001733 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001734 if ((boolean) request.result) {
1735 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1736 updateModemStateMetrics();
1737 } else {
1738 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1739 + ar.exception);
1740 }
1741 notifyRequester(request);
1742 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001743 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001744 case CMD_GET_MODEM_STATUS:
1745 request = (MainThreadRequest) msg.obj;
1746 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1747 PhoneConfigurationManager.getInstance()
1748 .getPhoneStatusFromModem(request.phone, onCompleted);
1749 break;
1750 case EVENT_GET_MODEM_STATUS_DONE:
1751 ar = (AsyncResult) msg.obj;
1752 request = (MainThreadRequest) ar.userObj;
1753 int id = request.phone.getPhoneId();
1754 if (ar.exception == null && ar.result != null) {
1755 request.result = ar.result;
1756 //update the cache as modem status has changed
1757 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1758 (boolean) request.result);
1759 } else {
1760 // Return true if modem status cannot be retrieved. For most cases,
1761 // modem status is on. And for older version modems, GET_MODEM_STATUS
1762 // and disable modem are not supported. Modem is always on.
1763 // TODO: this should be fixed in R to support a third
1764 // status UNKNOWN b/131631629
1765 request.result = true;
1766 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1767 + ar.exception);
1768 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001769 notifyRequester(request);
1770 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001771 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1772 request = (MainThreadRequest) msg.obj;
1773 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1774 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1775 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1776 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1777 break;
1778 }
1779 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1780 ar = (AsyncResult) msg.obj;
1781 request = (MainThreadRequest) ar.userObj;
1782 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1783 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1784 args.second.accept(ar.exception == null);
1785 notifyRequester(request);
1786 break;
1787 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001788 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1789 request = (MainThreadRequest) msg.obj;
1790 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1791 Phone phone = getPhoneFromRequest(request);
1792 if (phone != null) {
1793 phone.getSystemSelectionChannels(onCompleted);
1794 } else {
1795 loge("getSystemSelectionChannels: No phone object");
1796 request.result = new ArrayList<RadioAccessSpecifier>();
1797 notifyRequester(request);
1798 }
1799 break;
1800 }
1801 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1802 ar = (AsyncResult) msg.obj;
1803 request = (MainThreadRequest) ar.userObj;
1804 if (ar.exception == null && ar.result != null) {
1805 request.result = ar.result;
1806 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001807 request.result = new IllegalStateException(
1808 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001809 if (ar.result == null) {
1810 loge("getSystemSelectionChannels: Empty response");
1811 } else {
1812 loge("getSystemSelectionChannels: Unknown exception");
1813 }
1814 }
1815 notifyRequester(request);
1816 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001817 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1818 ar = (AsyncResult) msg.obj;
1819 request = (MainThreadRequest) ar.userObj;
1820 if (ar.exception == null && ar.result != null) {
1821 request.result = ar.result;
1822 } else {
1823 request.result = -1;
1824 loge("Failed to set Forbidden Plmns");
1825 if (ar.result == null) {
1826 loge("setForbidenPlmns: Empty response");
1827 } else if (ar.exception != null) {
1828 loge("setForbiddenPlmns: Exception: " + ar.exception);
1829 request.result = -1;
1830 } else {
1831 loge("setForbiddenPlmns: Unknown exception");
1832 }
1833 }
1834 notifyRequester(request);
1835 break;
1836 case CMD_SET_FORBIDDEN_PLMNS:
1837 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001838 uiccPort = getUiccPortFromRequest(request);
1839 if (uiccPort == null) {
1840 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001841 request.result = -1;
1842 notifyRequester(request);
1843 break;
1844 }
1845 Pair<Integer, List<String>> setFplmnsArgs =
1846 (Pair<Integer, List<String>>) request.argument;
1847 appType = setFplmnsArgs.first;
1848 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001849 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001850 if (uiccApp == null) {
1851 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1852 request.result = -1;
1853 loge("Failed to get UICC App");
1854 notifyRequester(request);
1855 } else {
1856 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1857 ((SIMRecords) uiccApp.getIccRecords())
1858 .setForbiddenPlmns(onCompleted, fplmns);
1859 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001860 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001861 case CMD_ERASE_MODEM_CONFIG:
1862 request = (MainThreadRequest) msg.obj;
1863 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1864 defaultPhone.eraseModemConfig(onCompleted);
1865 break;
1866 case EVENT_ERASE_MODEM_CONFIG_DONE:
1867 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001868 break;
zoey chene02881a2019-12-30 16:11:23 +08001869
Kai Shif70f46f2021-03-03 13:59:46 -08001870 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1871 request = (MainThreadRequest) msg.obj;
1872 request.result = defaultPhone.eraseDataInSharedPreferences();
1873 notifyRequester(request);
1874 break;
1875
zoey chene02881a2019-12-30 16:11:23 +08001876 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1877 request = (MainThreadRequest) msg.obj;
1878 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1879 Pair<String, String> changed = (Pair<String, String>) request.argument;
1880 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1881 changed.first, changed.second, onCompleted);
1882 break;
1883 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1884 ar = (AsyncResult) msg.obj;
1885 request = (MainThreadRequest) ar.userObj;
1886 if (ar.exception == null) {
1887 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001888 // If the operation is successful, update the PIN storage
1889 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1890 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001891 UiccController.getInstance().getPinStorage()
1892 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001893 } else {
1894 request.result = msg.arg1;
1895 }
1896 notifyRequester(request);
1897 break;
1898
Michele Berionne5e411512020-11-13 02:36:59 +00001899 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001900 request = (MainThreadRequest) msg.obj;
1901 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1902 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1903 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1904 enabled.first, enabled.second, onCompleted);
1905 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001906 }
zoey chene02881a2019-12-30 16:11:23 +08001907 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1908 ar = (AsyncResult) msg.obj;
1909 request = (MainThreadRequest) ar.userObj;
1910 if (ar.exception == null) {
1911 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001912 // If the operation is successful, update the PIN storage
1913 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1914 int phoneId = getPhoneFromRequest(request).getPhoneId();
1915 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001916 UiccController.getInstance().getPinStorage()
1917 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001918 } else {
1919 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1920 }
zoey chene02881a2019-12-30 16:11:23 +08001921 } else {
1922 request.result = msg.arg1;
1923 }
Michele Berionne5e411512020-11-13 02:36:59 +00001924
1925
zoey chene02881a2019-12-30 16:11:23 +08001926 notifyRequester(request);
1927 break;
1928
Peter Wangdafb9ac2020-01-15 14:13:38 -08001929 case MSG_NOTIFY_USER_ACTIVITY:
1930 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001931 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001932 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1933 getDefaultPhone().getContext().sendBroadcastAsUser(
1934 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1935 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001936
1937 case CMD_SET_DATA_THROTTLING: {
1938 request = (MainThreadRequest) msg.obj;
1939 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1940 DataThrottlingRequest dataThrottlingRequest =
1941 (DataThrottlingRequest) request.argument;
1942 Phone phone = getPhoneFromRequest(request);
1943 if (phone != null) {
1944 phone.setDataThrottling(onCompleted,
1945 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1946 dataThrottlingRequest.getCompletionDurationMillis());
1947 } else {
1948 loge("setDataThrottling: No phone object");
1949 request.result =
1950 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1951 notifyRequester(request);
1952 }
1953
1954 break;
1955 }
1956 case EVENT_SET_DATA_THROTTLING_DONE:
1957 ar = (AsyncResult) msg.obj;
1958 request = (MainThreadRequest) ar.userObj;
1959
1960 if (ar.exception == null) {
1961 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1962 } else if (ar.exception instanceof CommandException) {
1963 loge("setDataThrottling: CommandException: " + ar.exception);
1964 CommandException.Error error =
1965 ((CommandException) (ar.exception)).getCommandError();
1966
1967 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1968 request.result = TelephonyManager
1969 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1970 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1971 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001972 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1973 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001974 } else {
1975 request.result =
1976 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1977 }
1978 } else {
1979 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1980 }
1981 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1982 notifyRequester(request);
1983 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001984
1985 case CMD_SET_SIM_POWER: {
1986 request = (MainThreadRequest) msg.obj;
1987 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1988 request = (MainThreadRequest) msg.obj;
1989 int stateToSet =
1990 ((Pair<Integer, IIntegerConsumer>)
1991 request.argument).first;
1992 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1993 break;
1994 }
1995 case EVENT_SET_SIM_POWER_DONE: {
1996 ar = (AsyncResult) msg.obj;
1997 request = (MainThreadRequest) ar.userObj;
1998 IIntegerConsumer callback =
1999 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2000 if (ar.exception != null) {
2001 loge("setSimPower exception: " + ar.exception);
2002 int errorCode = TelephonyManager.CallForwardingInfoCallback
2003 .RESULT_ERROR_UNKNOWN;
2004 if (ar.exception instanceof CommandException) {
2005 CommandException.Error error =
2006 ((CommandException) (ar.exception)).getCommandError();
2007 if (error == CommandException.Error.SIM_ERR) {
2008 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2009 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2010 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2011 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2012 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2013 } else {
2014 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2015 }
2016 }
2017 try {
2018 callback.accept(errorCode);
2019 } catch (RemoteException e) {
2020 // Ignore if the remote process is no longer available to call back.
2021 Log.w(LOG_TAG, "setSimPower: callback not available.");
2022 }
2023 } else {
2024 try {
2025 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2026 } catch (RemoteException e) {
2027 // Ignore if the remote process is no longer available to call back.
2028 Log.w(LOG_TAG, "setSimPower: callback not available.");
2029 }
2030 }
2031 break;
2032 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002033 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2034 request = (MainThreadRequest) msg.obj;
2035
2036 final Phone phone = getPhoneFromRequest(request);
2037 if (phone == null || phone.getServiceStateTracker() == null) {
2038 request.result = new IllegalStateException("Phone or SST is null");
2039 notifyRequester(request);
2040 break;
2041 }
2042
2043 Pair<Integer, SignalStrengthUpdateRequest> pair =
2044 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2045 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2046 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002047 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002048 request.subId, pair.first /*callingUid*/,
2049 pair.second /*request*/, onCompleted);
2050 break;
2051 }
2052 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2053 ar = (AsyncResult) msg.obj;
2054 request = (MainThreadRequest) ar.userObj;
2055 // request.result will be the exception of ar if present, true otherwise.
2056 // Be cautious not to leave result null which will wait() forever
2057 request.result = ar.exception != null ? ar.exception : true;
2058 notifyRequester(request);
2059 break;
2060 }
2061 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2062 request = (MainThreadRequest) msg.obj;
2063
2064 Phone phone = getPhoneFromRequest(request);
2065 if (phone == null || phone.getServiceStateTracker() == null) {
2066 request.result = new IllegalStateException("Phone or SST is null");
2067 notifyRequester(request);
2068 break;
2069 }
2070
2071 Pair<Integer, SignalStrengthUpdateRequest> pair =
2072 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2073 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2074 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002075 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002076 request.subId, pair.first /*callingUid*/,
2077 pair.second /*request*/, onCompleted);
2078 break;
2079 }
2080 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2081 ar = (AsyncResult) msg.obj;
2082 request = (MainThreadRequest) ar.userObj;
2083 request.result = ar.exception != null ? ar.exception : true;
2084 notifyRequester(request);
2085 break;
2086 }
Jordan Liu109698e2020-11-24 14:50:34 -08002087
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002088 case CMD_GET_SLICING_CONFIG: {
2089 request = (MainThreadRequest) msg.obj;
2090 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2091 request.phone.getSlicingConfig(onCompleted);
2092 break;
2093 }
2094 case EVENT_GET_SLICING_CONFIG_DONE: {
2095 ar = (AsyncResult) msg.obj;
2096 request = (MainThreadRequest) ar.userObj;
2097 ResultReceiver result = (ResultReceiver) request.argument;
2098
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002099 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002100 Bundle bundle = new Bundle();
2101 int resultCode = 0;
2102 if (ar.exception != null) {
2103 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2104 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002105 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002106 } else if (ar.result == null) {
2107 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002108 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002109 } else {
2110 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002111 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2112 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002113 }
2114
2115 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002116 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002117 }
2118 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2119 result.send(resultCode, bundle);
2120 notifyRequester(request);
2121 break;
2122 }
2123
Michele Berionne5e411512020-11-13 02:36:59 +00002124 case CMD_PREPARE_UNATTENDED_REBOOT:
2125 request = (MainThreadRequest) msg.obj;
2126 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002127 UiccController.getInstance().getPinStorage()
2128 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002129 notifyRequester(request);
2130 break;
2131
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002132 default:
2133 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2134 break;
2135 }
2136 }
Jake Hambye994d462014-02-03 13:10:13 -08002137
Pengquan Menga1bb6272018-09-06 09:59:22 -07002138 private void notifyRequester(MainThreadRequest request) {
2139 synchronized (request) {
2140 request.notifyAll();
2141 }
2142 }
2143
Jake Hambye994d462014-02-03 13:10:13 -08002144 private void handleNullReturnEvent(Message msg, String command) {
2145 AsyncResult ar = (AsyncResult) msg.obj;
2146 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2147 if (ar.exception == null) {
2148 request.result = true;
2149 } else {
2150 request.result = false;
2151 if (ar.exception instanceof CommandException) {
2152 loge(command + ": CommandException: " + ar.exception);
2153 } else {
2154 loge(command + ": Unknown exception");
2155 }
2156 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002157 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002158 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002159 }
2160
2161 /**
2162 * Posts the specified command to be executed on the main thread,
2163 * waits for the request to complete, and returns the result.
2164 * @see #sendRequestAsync
2165 */
2166 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002167 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2168 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002169 }
2170
2171 /**
2172 * Posts the specified command to be executed on the main thread,
2173 * waits for the request to complete, and returns the result.
2174 * @see #sendRequestAsync
2175 */
2176 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2177 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002178 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002179 }
2180
2181 /**
2182 * Posts the specified command to be executed on the main thread,
2183 * waits for the request to complete, and returns the result.
2184 * @see #sendRequestAsync
2185 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002186 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002187 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2188 }
2189
2190 /**
2191 * Posts the specified command to be executed on the main thread,
2192 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2193 * if not timeout or null otherwise.
2194 * @see #sendRequestAsync
2195 */
2196 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2197 long timeoutInMs) {
2198 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002199 }
2200
2201 /**
2202 * Posts the specified command to be executed on the main thread,
2203 * waits for the request to complete, and returns the result.
2204 * @see #sendRequestAsync
2205 */
Nathan Harold92bed182018-10-12 18:16:49 -07002206 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002207 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002208 }
2209
2210 /**
2211 * Posts the specified command to be executed on the main thread,
2212 * waits for the request to complete, and returns the result.
2213 * @see #sendRequestAsync
2214 */
2215 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002216 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2217 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002218 }
2219
2220 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002221 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2222 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2223 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002224 * @see #sendRequestAsync
2225 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002226 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2227 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002228 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2229 throw new RuntimeException("This method will deadlock if called from the main thread.");
2230 }
2231
Nathan Harold92bed182018-10-12 18:16:49 -07002232 MainThreadRequest request = null;
2233 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2234 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2235 } else if (phone != null) {
2236 request = new MainThreadRequest(argument, phone, workSource);
2237 } else {
2238 request = new MainThreadRequest(argument, subId, workSource);
2239 }
2240
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002241 Message msg = mMainThreadHandler.obtainMessage(command, request);
2242 msg.sendToTarget();
2243
Rambo Wang0f050d82021-02-12 11:43:36 -08002244
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002245 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002246 if (timeoutInMs >= 0) {
2247 // Wait for at least timeoutInMs before returning null request result
2248 long now = SystemClock.elapsedRealtime();
2249 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002250 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002251 try {
2252 request.wait(deadline - now);
2253 } catch (InterruptedException e) {
2254 // Do nothing, go back and check if request is completed or timeout
2255 } finally {
2256 now = SystemClock.elapsedRealtime();
2257 }
2258 }
2259 } else {
2260 // Wait for the request to complete
2261 while (request.result == null) {
2262 try {
2263 request.wait();
2264 } catch (InterruptedException e) {
2265 // Do nothing, go back and wait until the request is complete
2266 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002267 }
2268 }
2269 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002270 if (request.result == null) {
2271 Log.wtf(LOG_TAG,
2272 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2273 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002274 return request.result;
2275 }
2276
2277 /**
2278 * Asynchronous ("fire and forget") version of sendRequest():
2279 * Posts the specified command to be executed on the main thread, and
2280 * returns immediately.
2281 * @see #sendRequest
2282 */
2283 private void sendRequestAsync(int command) {
2284 mMainThreadHandler.sendEmptyMessage(command);
2285 }
2286
2287 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002288 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002289 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002290 */
2291 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002292 sendRequestAsync(command, argument, null, null);
2293 }
2294
2295 /**
2296 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2297 * @see {@link #sendRequest(int,Object)}
2298 */
2299 private void sendRequestAsync(
2300 int command, Object argument, Phone phone, WorkSource workSource) {
2301 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002302 Message msg = mMainThreadHandler.obtainMessage(command, request);
2303 msg.sendToTarget();
2304 }
2305
2306 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002307 * Initialize the singleton PhoneInterfaceManager instance.
2308 * This is only done once, at startup, from PhoneApp.onCreate().
2309 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002310 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002311 synchronized (PhoneInterfaceManager.class) {
2312 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002313 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002314 } else {
2315 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2316 }
2317 return sInstance;
2318 }
2319 }
2320
2321 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002322 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002323 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002324 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002325 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002326 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002327 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002328 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002329 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002330 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002331 mTelephonySharedPreferences =
2332 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002333 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002334 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002335 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002336 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002337
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002338 publish();
2339 }
2340
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002341 private Phone getDefaultPhone() {
2342 Phone thePhone = getPhone(getDefaultSubscription());
2343 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2344 }
2345
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002346 private void publish() {
2347 if (DBG) log("publish: " + this);
2348
Peter Wangc035ce42020-01-08 21:00:22 -08002349 TelephonyFrameworkInitializer
2350 .getTelephonyServiceManager()
2351 .getTelephonyServiceRegisterer()
2352 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002353 }
2354
Stuart Scott584921c2015-01-15 17:10:34 -08002355 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002356 if (request.phone != null) {
2357 return request.phone;
2358 } else {
2359 return getPhoneFromSubId(request.subId);
2360 }
2361 }
2362
2363 private Phone getPhoneFromSubId(int subId) {
2364 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2365 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002366 }
2367
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002368 private UiccPort getUiccPortFromRequest(MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002369 Phone phone = getPhoneFromRequest(request);
2370 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002371 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002372 }
2373
Wink Saville36469e72014-06-11 15:17:00 -07002374 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002375 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002376 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002377 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002378
Kai Shif70f46f2021-03-03 13:59:46 -08002379 private void sendEraseModemConfig(@NonNull Phone phone) {
2380 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2381 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2382 }
2383
2384 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2385 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2386 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002387 }
2388
Peter Wang44b186e2020-01-13 23:33:09 -08002389 private boolean isImsAvailableOnDevice() {
2390 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2391 if (pm == null) {
2392 // For some reason package manger is not available.. This will fail internally anyway,
2393 // so do not throw error and allow.
2394 return true;
2395 }
2396 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2397 }
2398
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002399 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002400 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002401 }
2402
Wink Savilleb564aae2014-10-23 10:18:09 -07002403 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002404 if (DBG) log("dial: " + number);
2405 // No permission check needed here: This is just a wrapper around the
2406 // ACTION_DIAL intent, which is available to any app since it puts up
2407 // the UI before it does anything.
2408
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002409 final long identity = Binder.clearCallingIdentity();
2410 try {
2411 String url = createTelUrl(number);
2412 if (url == null) {
2413 return;
2414 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002415
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002416 // PENDING: should we just silently fail if phone is offhook or ringing?
2417 PhoneConstants.State state = mCM.getState(subId);
2418 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2419 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2420 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2421 mApp.startActivity(intent);
2422 }
2423 } finally {
2424 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002425 }
2426 }
2427
2428 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002429 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002430 }
2431
Wink Savilleb564aae2014-10-23 10:18:09 -07002432 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002433 if (DBG) log("call: " + number);
2434
2435 // This is just a wrapper around the ACTION_CALL intent, but we still
2436 // need to do a permission check since we're calling startActivity()
2437 // from the context of the phone app.
2438 enforceCallPermission();
2439
Jordan Liu1617b712019-07-10 15:06:26 -07002440 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002441 != AppOpsManager.MODE_ALLOWED) {
2442 return;
2443 }
2444
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002445 final long identity = Binder.clearCallingIdentity();
2446 try {
2447 String url = createTelUrl(number);
2448 if (url == null) {
2449 return;
2450 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002451
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002452 boolean isValid = false;
2453 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2454 if (slist != null) {
2455 for (SubscriptionInfo subInfoRecord : slist) {
2456 if (subInfoRecord.getSubscriptionId() == subId) {
2457 isValid = true;
2458 break;
2459 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002460 }
Wink Saville08874612014-08-31 19:19:58 -07002461 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002462 if (!isValid) {
2463 return;
2464 }
Wink Saville08874612014-08-31 19:19:58 -07002465
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002466 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2467 intent.putExtra(SUBSCRIPTION_KEY, subId);
2468 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2469 mApp.startActivity(intent);
2470 } finally {
2471 Binder.restoreCallingIdentity(identity);
2472 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002473 }
2474
Wink Savilleb564aae2014-10-23 10:18:09 -07002475 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002476 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002477 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2478 }
2479
Wink Savilleb564aae2014-10-23 10:18:09 -07002480 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002481 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002482 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2483 }
2484
Wink Savilleb564aae2014-10-23 10:18:09 -07002485 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002486 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002487
2488 final long identity = Binder.clearCallingIdentity();
2489 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002490 Phone phone = getPhone(subId);
2491 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002492 checkSimPin.start();
2493 return checkSimPin.unlockSim(null, pin);
2494 } finally {
2495 Binder.restoreCallingIdentity(identity);
2496 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002497 }
2498
Wink Savilleb564aae2014-10-23 10:18:09 -07002499 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002500 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002501
2502 final long identity = Binder.clearCallingIdentity();
2503 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002504 Phone phone = getPhone(subId);
2505 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002506 checkSimPuk.start();
2507 return checkSimPuk.unlockSim(puk, pin);
2508 } finally {
2509 Binder.restoreCallingIdentity(identity);
2510 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002511 }
2512
2513 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002514 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002515 * a synchronous one.
2516 */
2517 private static class UnlockSim extends Thread {
2518
2519 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002520 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002521
2522 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002523 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2524 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002525
2526 // For replies from SimCard interface
2527 private Handler mHandler;
2528
2529 // For async handler to identify request type
2530 private static final int SUPPLY_PIN_COMPLETE = 100;
2531
Michele Berionne5e411512020-11-13 02:36:59 +00002532 UnlockSim(int phoneId, IccCard simCard) {
2533 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002534 mSimCard = simCard;
2535 }
2536
2537 @Override
2538 public void run() {
2539 Looper.prepare();
2540 synchronized (UnlockSim.this) {
2541 mHandler = new Handler() {
2542 @Override
2543 public void handleMessage(Message msg) {
2544 AsyncResult ar = (AsyncResult) msg.obj;
2545 switch (msg.what) {
2546 case SUPPLY_PIN_COMPLETE:
2547 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2548 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002549 mRetryCount = msg.arg1;
2550 if (ar.exception != null) {
2551 if (ar.exception instanceof CommandException &&
2552 ((CommandException)(ar.exception)).getCommandError()
2553 == CommandException.Error.PASSWORD_INCORRECT) {
2554 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002555 } //When UiccCardApp dispose,handle message and return exception
2556 else if (ar.exception instanceof CommandException &&
2557 ((CommandException) (ar.exception)).getCommandError()
2558 == CommandException.Error.ABORTED) {
2559 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002560 } else {
2561 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2562 }
2563 } else {
2564 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2565 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002566 mDone = true;
2567 UnlockSim.this.notifyAll();
2568 }
2569 break;
2570 }
2571 }
2572 };
2573 UnlockSim.this.notifyAll();
2574 }
2575 Looper.loop();
2576 }
2577
2578 /*
2579 * Use PIN or PUK to unlock SIM card
2580 *
2581 * If PUK is null, unlock SIM card with PIN
2582 *
2583 * If PUK is not null, unlock SIM card with PUK and set PIN code
2584 */
Wink Saville9de0f752013-10-22 19:04:03 -07002585 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002586
2587 while (mHandler == null) {
2588 try {
2589 wait();
2590 } catch (InterruptedException e) {
2591 Thread.currentThread().interrupt();
2592 }
2593 }
2594 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2595
2596 if (puk == null) {
2597 mSimCard.supplyPin(pin, callback);
2598 } else {
2599 mSimCard.supplyPuk(puk, pin, callback);
2600 }
2601
2602 while (!mDone) {
2603 try {
2604 Log.d(LOG_TAG, "wait for done");
2605 wait();
2606 } catch (InterruptedException e) {
2607 // Restore the interrupted status
2608 Thread.currentThread().interrupt();
2609 }
2610 }
2611 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002612 int[] resultArray = new int[2];
2613 resultArray[0] = mResult;
2614 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002615
2616 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002617 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002618 }
2619
Wink Saville9de0f752013-10-22 19:04:03 -07002620 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002621 }
2622 }
2623
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002624 /**
2625 * This method has been removed due to privacy and stability concerns.
2626 */
2627 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002628 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002629 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2630 return;
Wink Saville36469e72014-06-11 15:17:00 -07002631 }
2632
Nathan Harold1f889d82020-06-04 17:05:26 -07002633 @Override
2634 public void updateServiceLocationWithPackageName(String callingPackage) {
2635 mApp.getSystemService(AppOpsManager.class)
2636 .checkPackage(Binder.getCallingUid(), callingPackage);
2637
Nathan Haroldf096d982020-11-18 17:18:06 -08002638 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002639 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2640 // Callers targeting S have no business invoking this method.
2641 return;
2642 }
2643
2644 LocationAccessPolicy.LocationPermissionResult locationResult =
2645 LocationAccessPolicy.checkLocationPermission(mApp,
2646 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2647 .setCallingPackage(callingPackage)
2648 .setCallingFeatureId(null)
2649 .setCallingPid(Binder.getCallingPid())
2650 .setCallingUid(Binder.getCallingUid())
2651 .setMethod("updateServiceLocation")
2652 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2653 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2654 .build());
2655 // Apps that lack location permission have no business calling this method;
2656 // however, because no permission was declared in the public API, denials must
2657 // all be "soft".
2658 switch (locationResult) {
2659 case DENIED_HARD: /* fall through */
2660 case DENIED_SOFT:
2661 return;
2662 }
2663
2664 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002665 final long identity = Binder.clearCallingIdentity();
2666 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002667 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002668 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002669 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002670 }
2671 } finally {
2672 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002673 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002674 }
2675
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002676 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002677 @Override
2678 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002679 return isRadioOnWithFeature(callingPackage, null);
2680 }
2681
2682
2683 @Override
2684 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2685 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2686 callingFeatureId);
2687 }
2688
2689 @Deprecated
2690 @Override
2691 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2692 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002693 }
2694
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002695 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002696 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2697 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002698 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002699 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002700 return false;
2701 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002702
2703 final long identity = Binder.clearCallingIdentity();
2704 try {
2705 return isRadioOnForSubscriber(subId);
2706 } finally {
2707 Binder.restoreCallingIdentity(identity);
2708 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002709 }
2710
2711 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002712 final long identity = Binder.clearCallingIdentity();
2713 try {
2714 final Phone phone = getPhone(subId);
2715 if (phone != null) {
2716 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2717 } else {
2718 return false;
2719 }
2720 } finally {
2721 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002722 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002723 }
2724
2725 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002726 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002727 }
Wink Saville36469e72014-06-11 15:17:00 -07002728
Wink Savilleb564aae2014-10-23 10:18:09 -07002729 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002730 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002731
2732 final long identity = Binder.clearCallingIdentity();
2733 try {
2734 final Phone phone = getPhone(subId);
2735 if (phone != null) {
2736 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2737 }
2738 } finally {
2739 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002740 }
Wink Saville36469e72014-06-11 15:17:00 -07002741 }
2742
2743 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002744 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002745 }
2746
Wink Savilleb564aae2014-10-23 10:18:09 -07002747 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002748 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002749
2750 final long identity = Binder.clearCallingIdentity();
2751 try {
2752 final Phone phone = getPhone(subId);
2753 if (phone == null) {
2754 return false;
2755 }
2756 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2757 toggleRadioOnOffForSubscriber(subId);
2758 }
2759 return true;
2760 } finally {
2761 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002762 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002763 }
Wink Saville36469e72014-06-11 15:17:00 -07002764
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002765 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002766 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002767 /*
2768 * If any of the Radios are available, it will need to be
2769 * shutdown. So return true if any Radio is available.
2770 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002771 final long identity = Binder.clearCallingIdentity();
2772 try {
2773 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2774 Phone phone = PhoneFactory.getPhone(i);
2775 if (phone != null && phone.isRadioAvailable()) return true;
2776 }
2777 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2778 return false;
2779 } finally {
2780 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002781 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002782 }
2783
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002784 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002785 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002786 enforceModifyPermission();
2787
2788 final long identity = Binder.clearCallingIdentity();
2789 try {
2790 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2791 logv("Shutting down Phone " + i);
2792 shutdownRadioUsingPhoneId(i);
2793 }
2794 } finally {
2795 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002796 }
2797 }
2798
2799 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002800 Phone phone = PhoneFactory.getPhone(phoneId);
2801 if (phone != null && phone.isRadioAvailable()) {
2802 phone.shutdownRadio();
2803 }
2804 }
2805
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002806 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002807 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002808
2809 final long identity = Binder.clearCallingIdentity();
2810 try {
2811 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2812 if (defaultPhone != null) {
2813 defaultPhone.setRadioPower(turnOn);
2814 return true;
2815 } else {
2816 loge("There's no default phone.");
2817 return false;
2818 }
2819 } finally {
2820 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002821 }
Wink Saville36469e72014-06-11 15:17:00 -07002822 }
2823
Wink Savilleb564aae2014-10-23 10:18:09 -07002824 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002825 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002826
2827 final long identity = Binder.clearCallingIdentity();
2828 try {
2829 final Phone phone = getPhone(subId);
2830 if (phone != null) {
2831 phone.setRadioPower(turnOn);
2832 return true;
2833 } else {
2834 return false;
2835 }
2836 } finally {
2837 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002838 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002839 }
2840
Wink Saville36469e72014-06-11 15:17:00 -07002841 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002842 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002843 public boolean enableDataConnectivity() {
2844 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002845
2846 final long identity = Binder.clearCallingIdentity();
2847 try {
2848 int subId = mSubscriptionController.getDefaultDataSubId();
2849 final Phone phone = getPhone(subId);
2850 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002851 phone.getDataEnabledSettings().setDataEnabled(
2852 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002853 return true;
2854 } else {
2855 return false;
2856 }
2857 } finally {
2858 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002859 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002860 }
2861
Wink Saville36469e72014-06-11 15:17:00 -07002862 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002863 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002864 public boolean disableDataConnectivity() {
2865 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002866
2867 final long identity = Binder.clearCallingIdentity();
2868 try {
2869 int subId = mSubscriptionController.getDefaultDataSubId();
2870 final Phone phone = getPhone(subId);
2871 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002872 phone.getDataEnabledSettings().setDataEnabled(
2873 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002874 return true;
2875 } else {
2876 return false;
2877 }
2878 } finally {
2879 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002880 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002881 }
2882
Sanket Padawe356d7632015-06-22 14:03:32 -07002883 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002884 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002885 final long identity = Binder.clearCallingIdentity();
2886 try {
2887 final Phone phone = getPhone(subId);
2888 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002889 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002890 } else {
2891 return false;
2892 }
2893 } finally {
2894 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002895 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002896 }
2897
2898 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002899 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002900 }
2901
pkanwarae03a6b2016-11-06 20:37:09 -08002902 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002903 enforceCallPermission();
2904
2905 final long identity = Binder.clearCallingIdentity();
2906 try {
2907 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2908 return;
2909 }
2910 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2911 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2912 } finally {
2913 Binder.restoreCallingIdentity(identity);
2914 }
pkanwar32d516d2016-10-14 19:37:38 -07002915 };
2916
Wink Savilleb564aae2014-10-23 10:18:09 -07002917 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002918 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002919
2920 final long identity = Binder.clearCallingIdentity();
2921 try {
2922 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2923 return false;
2924 }
2925 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2926 } finally {
2927 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002928 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002929 }
2930
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002931 /**
2932 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2933 * tag on getCallState Binder call.
2934 */
2935 @Deprecated
2936 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002937 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002938 if (CompatChanges.isChangeEnabled(
2939 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2940 Binder.getCallingUid())) {
2941 // Do not allow this API to be called on API version 31+, it should only be
2942 // called on old apps using this Binder call directly.
2943 throw new SecurityException("This method can only be used for applications "
2944 + "targeting API version 30 or less.");
2945 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002946 final long identity = Binder.clearCallingIdentity();
2947 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002948 Phone phone = getPhone(getDefaultSubscription());
2949 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2950 PhoneConstantConversions.convertCallState(phone.getState());
2951 } finally {
2952 Binder.restoreCallingIdentity(identity);
2953 }
2954 }
2955
2956 @Override
2957 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2958 if (CompatChanges.isChangeEnabled(
2959 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2960 Binder.getCallingUid())) {
2961 // Check READ_PHONE_STATE for API version 31+
2962 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2963 featureId, "getCallStateForSubscription")) {
2964 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2965 + "targeting API level 31+.");
2966 }
2967 }
2968 final long identity = Binder.clearCallingIdentity();
2969 try {
2970 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002971 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2972 PhoneConstantConversions.convertCallState(phone.getState());
2973 } finally {
2974 Binder.restoreCallingIdentity(identity);
2975 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002976 }
2977
Sanket Padawe356d7632015-06-22 14:03:32 -07002978 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002979 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002980 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2981 }
2982
2983 @Override
2984 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002985 final long identity = Binder.clearCallingIdentity();
2986 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002987 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002988 if (phone != null) {
Jack Yu2c450952021-11-29 11:36:17 -08002989 if (phone.isUsingNewDataStack()) {
2990 return phone.getDataNetworkController().getInternetDataNetworkState();
2991 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002992 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2993 } else {
2994 return PhoneConstantConversions.convertDataState(
2995 PhoneConstants.DataState.DISCONNECTED);
2996 }
2997 } finally {
2998 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002999 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003000 }
3001
Sanket Padawe356d7632015-06-22 14:03:32 -07003002 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003003 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003004 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
3005 }
3006
3007 @Override
3008 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003009 final long identity = Binder.clearCallingIdentity();
3010 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003011 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003012 if (phone != null) {
3013 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
3014 } else {
3015 return TelephonyManager.DATA_ACTIVITY_NONE;
3016 }
3017 } finally {
3018 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003019 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003020 }
3021
3022 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003023 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003024 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003025 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003026
3027 LocationAccessPolicy.LocationPermissionResult locationResult =
3028 LocationAccessPolicy.checkLocationPermission(mApp,
3029 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3030 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003031 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003032 .setCallingPid(Binder.getCallingPid())
3033 .setCallingUid(Binder.getCallingUid())
3034 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003035 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003036 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3037 .build());
3038 switch (locationResult) {
3039 case DENIED_HARD:
3040 throw new SecurityException("Not allowed to access cell location");
3041 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003042 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3043 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003044 }
3045
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003046 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003047 final long identity = Binder.clearCallingIdentity();
3048 try {
3049 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003050 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003051 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003052 } finally {
3053 Binder.restoreCallingIdentity(identity);
3054 }
Svetoslav64fad262015-04-14 14:35:21 -07003055 }
3056
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003057 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003058 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003059 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3060 // registered cell info, so return a NULL country instead.
3061 final long identity = Binder.clearCallingIdentity();
3062 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003063 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3064 // Get default phone in this case.
3065 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3066 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003067 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003068 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003069 if (phone == null) return "";
3070 ServiceStateTracker sst = phone.getServiceStateTracker();
3071 if (sst == null) return "";
3072 LocaleTracker lt = sst.getLocaleTracker();
3073 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003074 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003075 } finally {
3076 Binder.restoreCallingIdentity(identity);
3077 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003078 }
3079
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003080 /**
3081 * This method was removed due to potential issues caused by performing partial
3082 * updates of service state, and lack of a credible use case.
3083 *
3084 * This has the ability to break the telephony implementation by disabling notification of
3085 * changes in device connectivity. DO NOT USE THIS!
3086 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003087 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003088 public void enableLocationUpdates() {
3089 mApp.enforceCallingOrSelfPermission(
3090 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003091 }
3092
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003093 /**
3094 * This method was removed due to potential issues caused by performing partial
3095 * updates of service state, and lack of a credible use case.
3096 *
3097 * This has the ability to break the telephony implementation by disabling notification of
3098 * changes in device connectivity. DO NOT USE THIS!
3099 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003100 @Override
3101 public void disableLocationUpdates() {
3102 mApp.enforceCallingOrSelfPermission(
3103 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003104 }
3105
3106 @Override
3107 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003108 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3109 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003110 try {
3111 mApp.getSystemService(AppOpsManager.class)
3112 .checkPackage(Binder.getCallingUid(), callingPackage);
3113 } catch (SecurityException e) {
3114 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3115 throw e;
3116 }
3117
Nathan Haroldf096d982020-11-18 17:18:06 -08003118 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003119 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3120 throw new SecurityException(
3121 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3122 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003123
Jordan Liu1617b712019-07-10 15:06:26 -07003124 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003125 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3126 return null;
3127 }
Svetoslav64fad262015-04-14 14:35:21 -07003128
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003129 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003130
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003131 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003132 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003133
Nathan Haroldf180aac2018-06-01 18:43:55 -07003134 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3135 for (CellInfo ci : info) {
3136 if (ci instanceof CellInfoGsm) {
3137 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3138 } else if (ci instanceof CellInfoWcdma) {
3139 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3140 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003141 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003142 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003143 }
3144
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003145 private List<CellInfo> getCachedCellInfo() {
3146 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3147 for (Phone phone : PhoneFactory.getPhones()) {
3148 List<CellInfo> info = phone.getAllCellInfo();
3149 if (info != null) cellInfos.addAll(info);
3150 }
3151 return cellInfos;
3152 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003153
3154 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003155 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003156 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003157 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003158
3159 LocationAccessPolicy.LocationPermissionResult locationResult =
3160 LocationAccessPolicy.checkLocationPermission(mApp,
3161 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3162 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003163 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003164 .setCallingPid(Binder.getCallingPid())
3165 .setCallingUid(Binder.getCallingUid())
3166 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003167 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003168 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3169 .build());
3170 switch (locationResult) {
3171 case DENIED_HARD:
3172 throw new SecurityException("Not allowed to access cell info");
3173 case DENIED_SOFT:
3174 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003175 }
3176
Nathan Haroldf096d982020-11-18 17:18:06 -08003177 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003178 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3179 return getCachedCellInfo();
3180 }
3181
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003182 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003183 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003184 final long identity = Binder.clearCallingIdentity();
3185 try {
3186 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3187 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003188 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003189 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003190 if (info != null) cellInfos.addAll(info);
3191 }
3192 return cellInfos;
3193 } finally {
3194 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003195 }
3196 }
3197
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003198 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003199 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3200 String callingFeatureId) {
3201 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3202 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003203 }
3204
3205 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003206 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3207 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003208 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003209 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003210 }
3211
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003212 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3213 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003214 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003215 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003216
3217 LocationAccessPolicy.LocationPermissionResult locationResult =
3218 LocationAccessPolicy.checkLocationPermission(mApp,
3219 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3220 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003221 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003222 .setCallingPid(Binder.getCallingPid())
3223 .setCallingUid(Binder.getCallingUid())
3224 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003225 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3226 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003227 .build());
3228 switch (locationResult) {
3229 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003230 if (TelephonyPermissions
3231 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003232 // Safetynet logging for b/154934934
3233 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3234 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003235 throw new SecurityException("Not allowed to access cell info");
3236 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003237 if (TelephonyPermissions
3238 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003239 // Safetynet logging for b/154934934
3240 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3241 }
Nathan Harold5320c422019-05-09 10:26:08 -07003242 try {
3243 cb.onCellInfo(new ArrayList<CellInfo>());
3244 } catch (RemoteException re) {
3245 // Drop without consequences
3246 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003247 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003248 }
3249
Nathan Harolda939a962019-05-09 10:13:47 -07003250
3251 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003252 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3253
3254 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3255 }
3256
3257 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003258 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003259 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003260 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003261
3262 final long identity = Binder.clearCallingIdentity();
3263 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003264 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003265 } finally {
3266 Binder.restoreCallingIdentity(identity);
3267 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003268 }
3269
Shishir Agrawala9f32182016-04-12 12:00:16 -07003270 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003271 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003272 Phone phone = PhoneFactory.getPhone(slotIndex);
3273 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003274 return null;
3275 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003276 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003277 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003278 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003279 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003280 return null;
3281 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003282
3283 final long identity = Binder.clearCallingIdentity();
3284 try {
3285 return phone.getImei();
3286 } finally {
3287 Binder.restoreCallingIdentity(identity);
3288 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003289 }
3290
3291 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003292 public String getTypeAllocationCodeForSlot(int slotIndex) {
3293 Phone phone = PhoneFactory.getPhone(slotIndex);
3294 String tac = null;
3295 if (phone != null) {
3296 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003297 try {
3298 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3299 } catch (IndexOutOfBoundsException e) {
3300 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3301 return null;
3302 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003303 }
3304 return tac;
3305 }
3306
3307 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003308 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003309 try {
3310 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3311 } catch (SecurityException se) {
3312 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3313 throw new SecurityException("Package " + callingPackage + " does not belong to "
3314 + Binder.getCallingUid());
3315 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003316 Phone phone = PhoneFactory.getPhone(slotIndex);
3317 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003318 return null;
3319 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003320
Jeff Davidson913390f2018-02-23 17:11:49 -08003321 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003322 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003323 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003324 return null;
3325 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003326
3327 final long identity = Binder.clearCallingIdentity();
3328 try {
3329 return phone.getMeid();
3330 } finally {
3331 Binder.restoreCallingIdentity(identity);
3332 }
Jack Yu2af8d712017-03-15 17:14:14 -07003333 }
3334
3335 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003336 public String getManufacturerCodeForSlot(int slotIndex) {
3337 Phone phone = PhoneFactory.getPhone(slotIndex);
3338 String manufacturerCode = null;
3339 if (phone != null) {
3340 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003341 try {
3342 manufacturerCode =
3343 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3344 } catch (IndexOutOfBoundsException e) {
3345 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3346 return null;
3347 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003348 }
3349 return manufacturerCode;
3350 }
3351
3352 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003353 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3354 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003355 Phone phone = PhoneFactory.getPhone(slotIndex);
3356 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003357 return null;
3358 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003359 int subId = phone.getSubId();
3360 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003361 mApp, subId, callingPackage, callingFeatureId,
3362 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003363 return null;
3364 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003365
3366 final long identity = Binder.clearCallingIdentity();
3367 try {
3368 return phone.getDeviceSvn();
3369 } finally {
3370 Binder.restoreCallingIdentity(identity);
3371 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003372 }
3373
fionaxu43304da2017-11-27 22:51:16 -08003374 @Override
3375 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003376 final long identity = Binder.clearCallingIdentity();
3377 try {
3378 final Phone phone = getPhone(subId);
3379 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3380 } finally {
3381 Binder.restoreCallingIdentity(identity);
3382 }
fionaxu43304da2017-11-27 22:51:16 -08003383 }
3384
3385 @Override
3386 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003387 final long identity = Binder.clearCallingIdentity();
3388 try {
3389 final Phone phone = getPhone(subId);
3390 return phone == null ? null : phone.getCarrierName();
3391 } finally {
3392 Binder.restoreCallingIdentity(identity);
3393 }
fionaxu43304da2017-11-27 22:51:16 -08003394 }
3395
calvinpanffe225e2018-11-01 19:43:06 +08003396 @Override
chen xu0026ca62019-03-06 15:28:50 -08003397 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003398 final long identity = Binder.clearCallingIdentity();
3399 try {
3400 final Phone phone = getPhone(subId);
3401 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003402 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003403 } finally {
3404 Binder.restoreCallingIdentity(identity);
3405 }
3406 }
3407
3408 @Override
chen xu0026ca62019-03-06 15:28:50 -08003409 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003410 final long identity = Binder.clearCallingIdentity();
3411 try {
3412 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003413 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003414 } finally {
3415 Binder.restoreCallingIdentity(identity);
3416 }
3417 }
3418
chen xu651eec72018-11-11 19:03:44 -08003419 @Override
chen xu864e11c2018-12-06 22:10:03 -08003420 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3421 if (!isSubscriptionMccMnc) {
3422 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3423 }
chen xu651eec72018-11-11 19:03:44 -08003424 final Phone phone = PhoneFactory.getPhone(slotIndex);
3425 if (phone == null) {
3426 return TelephonyManager.UNKNOWN_CARRIER_ID;
3427 }
3428 final long identity = Binder.clearCallingIdentity();
3429 try {
3430 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3431 } finally {
3432 Binder.restoreCallingIdentity(identity);
3433 }
3434 }
3435
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003436 //
3437 // Internal helper methods.
3438 //
3439
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003440 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003441 * Make sure the caller is the calling package itself
3442 *
3443 * @throws SecurityException if the caller is not the calling package
3444 */
3445 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3446 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003447 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3448 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003449 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003450 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003451 } catch (PackageManager.NameNotFoundException e) {
3452 // packageUid is -1
3453 }
3454 if (packageUid != callingUid) {
3455 throw new SecurityException(message + ": Package " + callingPackage
3456 + " does not belong to " + callingUid);
3457 }
3458 }
3459
3460 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003461 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3462 *
3463 * @throws SecurityException if the caller does not have the required permission
3464 */
3465 private void enforceModifyPermission() {
3466 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3467 }
3468
Shuo Qian3b6ee772019-11-13 17:43:31 -08003469 private void enforceActiveEmergencySessionPermission() {
3470 mApp.enforceCallingOrSelfPermission(
3471 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3472 }
3473
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003474 /**
3475 * Make sure the caller has the CALL_PHONE permission.
3476 *
3477 * @throws SecurityException if the caller does not have the required permission
3478 */
3479 private void enforceCallPermission() {
3480 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3481 }
3482
paulhu5a773602019-08-23 19:17:33 +08003483 private void enforceSettingsPermission() {
3484 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003485 }
3486
Michele Berionne5e411512020-11-13 02:36:59 +00003487 private void enforceRebootPermission() {
3488 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3489 }
3490
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003491 private String createTelUrl(String number) {
3492 if (TextUtils.isEmpty(number)) {
3493 return null;
3494 }
3495
Jake Hambye994d462014-02-03 13:10:13 -08003496 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003497 }
3498
Ihab Awadf9e92732013-12-05 18:02:52 -08003499 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003500 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3501 }
3502
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003503 private static void logv(String msg) {
3504 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3505 }
3506
Ihab Awadf9e92732013-12-05 18:02:52 -08003507 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003508 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3509 }
3510
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003511 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003512 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003513 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003514 }
3515
Sanket Padawe356d7632015-06-22 14:03:32 -07003516 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003517 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003518 final long identity = Binder.clearCallingIdentity();
3519 try {
3520 final Phone phone = PhoneFactory.getPhone(slotIndex);
3521 if (phone == null) {
3522 return PhoneConstants.PHONE_TYPE_NONE;
3523 } else {
3524 return phone.getPhoneType();
3525 }
3526 } finally {
3527 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003528 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003529 }
3530
3531 /**
3532 * Returns the CDMA ERI icon index to display
3533 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003534 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003535 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3536 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3537 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003538 }
3539
Sanket Padawe356d7632015-06-22 14:03:32 -07003540 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003541 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3542 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003543 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003544 mApp, subId, callingPackage, callingFeatureId,
3545 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003546 return -1;
3547 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003548
3549 final long identity = Binder.clearCallingIdentity();
3550 try {
3551 final Phone phone = getPhone(subId);
3552 if (phone != null) {
3553 return phone.getCdmaEriIconIndex();
3554 } else {
3555 return -1;
3556 }
3557 } finally {
3558 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003559 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003560 }
3561
3562 /**
3563 * Returns the CDMA ERI icon mode,
3564 * 0 - ON
3565 * 1 - FLASHING
3566 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003567 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003568 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3569 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3570 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003571 }
3572
Sanket Padawe356d7632015-06-22 14:03:32 -07003573 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003574 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3575 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003576 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003577 mApp, subId, callingPackage, callingFeatureId,
3578 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003579 return -1;
3580 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003581
3582 final long identity = Binder.clearCallingIdentity();
3583 try {
3584 final Phone phone = getPhone(subId);
3585 if (phone != null) {
3586 return phone.getCdmaEriIconMode();
3587 } else {
3588 return -1;
3589 }
3590 } finally {
3591 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003592 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003593 }
3594
3595 /**
3596 * Returns the CDMA ERI text,
3597 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003598 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003599 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3600 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3601 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003602 }
3603
Sanket Padawe356d7632015-06-22 14:03:32 -07003604 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003605 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3606 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003607 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003608 mApp, subId, callingPackage, callingFeatureId,
3609 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003610 return null;
3611 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003612
3613 final long identity = Binder.clearCallingIdentity();
3614 try {
3615 final Phone phone = getPhone(subId);
3616 if (phone != null) {
3617 return phone.getCdmaEriText();
3618 } else {
3619 return null;
3620 }
3621 } finally {
3622 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003623 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003624 }
3625
3626 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003627 * Returns the CDMA MDN.
3628 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003629 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003630 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003631 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3632 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003633
3634 final long identity = Binder.clearCallingIdentity();
3635 try {
3636 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003637 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003638 return phone.getLine1Number();
3639 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003640 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003641 return null;
3642 }
3643 } finally {
3644 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003645 }
3646 }
3647
3648 /**
3649 * Returns the CDMA MIN.
3650 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003651 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003652 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003653 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3654 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003655
3656 final long identity = Binder.clearCallingIdentity();
3657 try {
3658 final Phone phone = getPhone(subId);
3659 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3660 return phone.getCdmaMin();
3661 } else {
3662 return null;
3663 }
3664 } finally {
3665 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003666 }
3667 }
3668
Hall Liud892bec2018-11-30 14:51:45 -08003669 @Override
3670 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3671 INumberVerificationCallback callback, String callingPackage) {
3672 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3673 != PERMISSION_GRANTED) {
3674 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3675 }
3676 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3677
3678 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3679 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003680 throw new SecurityException("Calling package must be configured in the device config: "
3681 + "calling package: " + callingPackage
3682 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003683 }
3684
3685 if (range == null) {
3686 throw new NullPointerException("Range must be non-null");
3687 }
3688
3689 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003690 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003691
3692 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3693 }
3694
Junda Liuca05d5d2014-08-14 22:36:34 -07003695 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003696 * Returns true if CDMA provisioning needs to run.
3697 */
3698 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003699 final long identity = Binder.clearCallingIdentity();
3700 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003701 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003702 } finally {
3703 Binder.restoreCallingIdentity(identity);
3704 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003705 }
3706
3707 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003708 * Sets the voice mail number of a given subId.
3709 */
3710 @Override
3711 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003712 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3713 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003714
3715 final long identity = Binder.clearCallingIdentity();
3716 try {
3717 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3718 new Pair<String, String>(alphaTag, number), new Integer(subId));
3719 return success;
3720 } finally {
3721 Binder.restoreCallingIdentity(identity);
3722 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003723 }
3724
Ta-wei Yen87c49842016-05-13 21:19:52 -07003725 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003726 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3727 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003728 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3729 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003730 if (!TextUtils.equals(callingPackage, systemDialer)) {
3731 throw new SecurityException("caller must be system dialer");
3732 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003733
3734 final long identity = Binder.clearCallingIdentity();
3735 try {
3736 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3737 if (phoneAccountHandle == null) {
3738 return null;
3739 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003740 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003741 } finally {
3742 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003743 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003744 }
3745
3746 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003747 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3748 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003749 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003750 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003751 mApp, subId, callingPackage, callingFeatureId,
3752 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003753 return null;
3754 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003755
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003756 final long identity = Binder.clearCallingIdentity();
3757 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003758 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003759 } finally {
3760 Binder.restoreCallingIdentity(identity);
3761 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003762 }
3763
3764 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003765 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3766 VisualVoicemailSmsFilterSettings settings) {
3767 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003768
3769 final long identity = Binder.clearCallingIdentity();
3770 try {
3771 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003772 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003773 } finally {
3774 Binder.restoreCallingIdentity(identity);
3775 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003776 }
3777
3778 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003779 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3780 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003781
3782 final long identity = Binder.clearCallingIdentity();
3783 try {
3784 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003785 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003786 } finally {
3787 Binder.restoreCallingIdentity(identity);
3788 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003789 }
3790
3791 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003792 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3793 String callingPackage, int subId) {
3794 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003795
3796 final long identity = Binder.clearCallingIdentity();
3797 try {
3798 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003799 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003800 } finally {
3801 Binder.restoreCallingIdentity(identity);
3802 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003803 }
3804
3805 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003806 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003807 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003808
3809 final long identity = Binder.clearCallingIdentity();
3810 try {
3811 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003812 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003813 } finally {
3814 Binder.restoreCallingIdentity(identity);
3815 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003816 }
3817
3818 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003819 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3820 String callingAttributionTag, int subId, String number, int port, String text,
3821 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003822 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003823 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003824 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003825 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003826 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3827 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003828 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003829
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003830 /**
fionaxu0152e512016-11-14 13:36:14 -08003831 * Sets the voice activation state of a given subId.
3832 */
3833 @Override
3834 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003835 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3836 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003837
3838 final long identity = Binder.clearCallingIdentity();
3839 try {
3840 final Phone phone = getPhone(subId);
3841 if (phone != null) {
3842 phone.setVoiceActivationState(activationState);
3843 } else {
3844 loge("setVoiceActivationState fails with invalid subId: " + subId);
3845 }
3846 } finally {
3847 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003848 }
3849 }
3850
3851 /**
3852 * Sets the data activation state of a given subId.
3853 */
3854 @Override
3855 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003856 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3857 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003858
3859 final long identity = Binder.clearCallingIdentity();
3860 try {
3861 final Phone phone = getPhone(subId);
3862 if (phone != null) {
3863 phone.setDataActivationState(activationState);
3864 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003865 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003866 }
3867 } finally {
3868 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003869 }
3870 }
3871
3872 /**
3873 * Returns the voice activation state of a given subId.
3874 */
3875 @Override
3876 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003877 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003878
fionaxu0152e512016-11-14 13:36:14 -08003879 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003880 final long identity = Binder.clearCallingIdentity();
3881 try {
3882 if (phone != null) {
3883 return phone.getVoiceActivationState();
3884 } else {
3885 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3886 }
3887 } finally {
3888 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003889 }
3890 }
3891
3892 /**
3893 * Returns the data activation state of a given subId.
3894 */
3895 @Override
3896 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003897 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003898
fionaxu0152e512016-11-14 13:36:14 -08003899 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003900 final long identity = Binder.clearCallingIdentity();
3901 try {
3902 if (phone != null) {
3903 return phone.getDataActivationState();
3904 } else {
3905 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3906 }
3907 } finally {
3908 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003909 }
3910 }
3911
3912 /**
Wink Saville36469e72014-06-11 15:17:00 -07003913 * Returns the unread count of voicemails for a subId
3914 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003915 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003916 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3917 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003918 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003919 mApp, subId, callingPackage, callingFeatureId,
3920 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003921 return 0;
3922 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003923 final long identity = Binder.clearCallingIdentity();
3924 try {
3925 final Phone phone = getPhone(subId);
3926 if (phone != null) {
3927 return phone.getVoiceMessageCount();
3928 } else {
3929 return 0;
3930 }
3931 } finally {
3932 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003933 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003934 }
3935
3936 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003937 * returns true, if the device is in a state where both voice and data
3938 * are supported simultaneously. This can change based on location or network condition.
3939 */
3940 @Override
3941 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003942 final long identity = Binder.clearCallingIdentity();
3943 try {
3944 final Phone phone = getPhone(subId);
3945 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3946 } finally {
3947 Binder.restoreCallingIdentity(identity);
3948 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003949 }
3950
3951 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003952 * Send the dialer code if called from the current default dialer or the caller has
3953 * carrier privilege.
3954 * @param inputCode The dialer code to send
3955 */
3956 @Override
3957 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003958 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003959 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003960 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3961 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003962 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003963 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003964 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003965 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003966
3967 final long identity = Binder.clearCallingIdentity();
3968 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003969 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003970 } finally {
3971 Binder.restoreCallingIdentity(identity);
3972 }
fionaxu235cc5e2017-03-06 22:25:57 -08003973 }
3974
Pengquan Menga1bb6272018-09-06 09:59:22 -07003975 @Override
3976 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003977 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003978 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003979 mApp, subId, "getNetworkSelectionMode");
3980 final long identity = Binder.clearCallingIdentity();
3981 try {
3982 if (!isActiveSubscription(subId)) {
3983 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3984 }
3985 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3986 } finally {
3987 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003988 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003989 }
3990
Brad Ebinger35c841c2018-10-01 10:40:55 -07003991 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003992 public boolean isInEmergencySmsMode() {
3993 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3994 final long identity = Binder.clearCallingIdentity();
3995 try {
3996 for (Phone phone : PhoneFactory.getPhones()) {
3997 if (phone.isInEmergencySmsMode()) {
3998 return true;
3999 }
4000 }
4001 } finally {
4002 Binder.restoreCallingIdentity(identity);
4003 }
4004 return false;
4005 }
4006
shilu366312e2019-12-17 09:28:10 -08004007 /**
4008 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4009 * @param subId The subscription to use to check the configuration.
4010 * @param c The callback that will be used to send the result.
4011 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004012 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004013 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4014 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004015 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004016 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08004017
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004018 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4019 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4020 "IMS not available on device.");
4021 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004022 final long token = Binder.clearCallingIdentity();
4023 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004024 int slotId = getSlotIndexOrException(subId);
4025 verifyImsMmTelConfiguredOrThrow(slotId);
4026 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004027 } catch (ImsException e) {
4028 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004029 } finally {
4030 Binder.restoreCallingIdentity(token);
4031 }
4032 }
4033
shilu366312e2019-12-17 09:28:10 -08004034 /**
4035 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4036 * @param subId The subscription to use to check the configuration.
4037 * @param c The callback that will be used to send the result.
4038 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004039 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004040 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004041 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004042 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004043 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4044 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4045 }
Meng Wangafbc5852019-09-19 17:37:13 -07004046 final long token = Binder.clearCallingIdentity();
4047 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004048 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4049 .removeRegistrationCallbackForSubscription(c, subId);
4050 } catch (ImsException e) {
4051 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4052 + "is inactive, ignoring unregister.");
4053 // If the subscription is no longer active, just return, since the callback
4054 // will already have been removed internally.
4055 } finally {
4056 Binder.restoreCallingIdentity(token);
4057 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004058 }
4059
Brad Ebingera34a6c22019-10-22 17:36:18 -07004060 /**
4061 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4062 */
4063 @Override
4064 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4065 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4066 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4067 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4068 "IMS not available on device.");
4069 }
4070 final long token = Binder.clearCallingIdentity();
4071 try {
4072 Phone phone = getPhone(subId);
4073 if (phone == null) {
4074 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4075 + subId + "'");
4076 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4077 }
4078 phone.getImsRegistrationState(regState -> {
4079 try {
4080 consumer.accept((regState == null)
4081 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4082 } catch (RemoteException e) {
4083 // Ignore if the remote process is no longer available to call back.
4084 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4085 }
4086 });
4087 } finally {
4088 Binder.restoreCallingIdentity(token);
4089 }
4090 }
4091
4092 /**
4093 * Get the transport type for the IMS service registration state.
4094 */
4095 @Override
4096 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004097 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004098 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004099 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4100 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4101 "IMS not available on device.");
4102 }
4103 final long token = Binder.clearCallingIdentity();
4104 try {
4105 Phone phone = getPhone(subId);
4106 if (phone == null) {
4107 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4108 + subId + "'");
4109 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4110 }
4111 phone.getImsRegistrationTech(regTech -> {
4112 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4113 int regTechConverted = (regTech == null)
4114 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4115 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4116 regTechConverted);
4117 try {
4118 consumer.accept(regTechConverted);
4119 } catch (RemoteException e) {
4120 // Ignore if the remote process is no longer available to call back.
4121 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4122 }
4123 });
4124 } finally {
4125 Binder.restoreCallingIdentity(token);
4126 }
4127 }
4128
shilu366312e2019-12-17 09:28:10 -08004129 /**
4130 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4131 * @param subId The subscription to use to check the configuration.
4132 * @param c The callback that will be used to send the result.
4133 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004134 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004135 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4136 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004137 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004138 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004139 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4140 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4141 "IMS not available on device.");
4142 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004143 final long token = Binder.clearCallingIdentity();
4144 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004145 int slotId = getSlotIndexOrException(subId);
4146 verifyImsMmTelConfiguredOrThrow(slotId);
4147 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004148 } catch (ImsException e) {
4149 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004150 } finally {
4151 Binder.restoreCallingIdentity(token);
4152 }
4153 }
4154
shilu366312e2019-12-17 09:28:10 -08004155 /**
4156 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4157 * @param subId The subscription to use to check the configuration.
4158 * @param c The callback that will be used to send the result.
4159 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004160 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004161 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004162 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004163 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004164 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4165 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4166 }
Meng Wangafbc5852019-09-19 17:37:13 -07004167
4168 final long token = Binder.clearCallingIdentity();
4169 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004170 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004171 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004172 } catch (ImsException e) {
4173 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4174 + "is inactive, ignoring unregister.");
4175 // If the subscription is no longer active, just return, since the callback
4176 // will already have been removed internally.
4177 } finally {
4178 Binder.restoreCallingIdentity(token);
4179 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004180 }
4181
4182 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004183 public boolean isCapable(int subId, int capability, int regTech) {
4184 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004185 final long token = Binder.clearCallingIdentity();
4186 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004187 int slotId = getSlotIndexOrException(subId);
4188 verifyImsMmTelConfiguredOrThrow(slotId);
4189 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004190 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004191 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4192 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004193 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004194 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4195 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004196 } finally {
4197 Binder.restoreCallingIdentity(token);
4198 }
4199 }
4200
4201 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004202 public boolean isAvailable(int subId, int capability, int regTech) {
4203 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004204 final long token = Binder.clearCallingIdentity();
4205 try {
4206 Phone phone = getPhone(subId);
4207 if (phone == null) return false;
4208 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004209 } catch (com.android.ims.ImsException e) {
4210 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4211 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004212 } finally {
4213 Binder.restoreCallingIdentity(token);
4214 }
4215 }
4216
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004217 /**
4218 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4219 * subscription.
4220 * @param subId The subscription to use to check the configuration.
4221 * @param callback The callback that will be used to send the result.
4222 * @param capability The MmTelFeature capability that will be used to send the result.
4223 * @param transportType The transport type of the MmTelFeature capability.
4224 */
4225 @Override
4226 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4227 int transportType) {
4228 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4229 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4230 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4231 "IMS not available on device.");
4232 }
4233 final long token = Binder.clearCallingIdentity();
4234 try {
4235 int slotId = getSlotIndex(subId);
4236 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4237 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4238 + subId + "'");
4239 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4240 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004241 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004242 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4243 transportType, aBoolean -> {
4244 try {
4245 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4246 } catch (RemoteException e) {
4247 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4248 + "running. Ignore");
4249 }
4250 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004251 } catch (ImsException e) {
4252 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004253 } finally {
4254 Binder.restoreCallingIdentity(token);
4255 }
4256 }
4257
shilu366312e2019-12-17 09:28:10 -08004258 /**
4259 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4260 * @param subId The subscription to use to check the configuration.
4261 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004262 @Override
4263 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004264 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004265 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004266
Brad Ebinger35c841c2018-10-01 10:40:55 -07004267 final long token = Binder.clearCallingIdentity();
4268 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004269 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004270 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004271 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004272 } catch (ImsException e) {
4273 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004274 } finally {
4275 Binder.restoreCallingIdentity(token);
4276 }
4277 }
4278
4279 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004280 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004281 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004282 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004283 final long identity = 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. The
4287 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004288 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004289 } catch (ImsException e) {
4290 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004291 } finally {
4292 Binder.restoreCallingIdentity(identity);
4293 }
4294 }
4295
shilu366312e2019-12-17 09:28:10 -08004296 /**
4297 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4298 * @param subId The subscription to use to check the configuration.
4299 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004300 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004301 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004302 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004303 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004304 final long identity = Binder.clearCallingIdentity();
4305 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004306 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004307 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004308 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004309 } catch (ImsException e) {
4310 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004311 } finally {
4312 Binder.restoreCallingIdentity(identity);
4313 }
4314 }
4315
4316 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004317 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004318 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004319 "setVtSettingEnabled");
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. The
4324 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004325 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004326 } catch (ImsException e) {
4327 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004328 } finally {
4329 Binder.restoreCallingIdentity(identity);
4330 }
4331 }
4332
shilu366312e2019-12-17 09:28:10 -08004333 /**
4334 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4335 * @param subId The subscription to use to check the configuration.
4336 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004337 @Override
4338 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004339 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004340 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004341 final long identity = Binder.clearCallingIdentity();
4342 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004343 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004344 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004345 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004346 } catch (ImsException e) {
4347 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004348 } finally {
4349 Binder.restoreCallingIdentity(identity);
4350 }
4351 }
4352
4353 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004354 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004355 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004356 "setVoWiFiSettingEnabled");
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. The
4361 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004362 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004363 } catch (ImsException e) {
4364 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004365 } finally {
4366 Binder.restoreCallingIdentity(identity);
4367 }
4368 }
4369
shilu366312e2019-12-17 09:28:10 -08004370 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004371 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4372 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4373 * @param subId The subscription to use to check the configuration.
4374 */
4375 @Override
4376 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004377 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004378 mApp, subId, "isCrossSimCallingEnabledByUser");
4379 final long identity = Binder.clearCallingIdentity();
4380 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004381 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004382 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004383 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004384 } catch (ImsException e) {
4385 throw new ServiceSpecificException(e.getCode());
4386 } finally {
4387 Binder.restoreCallingIdentity(identity);
4388 }
4389 }
4390
4391 /**
4392 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4393 * Requires MODIFY_PHONE_STATE permission.
4394 * @param subId The subscription to use to check the configuration.
4395 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4396 * false otherwise
4397 */
4398 @Override
4399 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4400 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4401 "setCrossSimCallingEnabled");
4402 final long identity = Binder.clearCallingIdentity();
4403 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004404 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004405 // This setting doesn't require an active ImsService connection, so do not verify. The
4406 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004407 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004408 } catch (ImsException e) {
4409 throw new ServiceSpecificException(e.getCode());
4410 } finally {
4411 Binder.restoreCallingIdentity(identity);
4412 }
4413 }
4414
4415 /**
shilu366312e2019-12-17 09:28:10 -08004416 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4417 * @param subId The subscription to use to check the configuration.
4418 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004419 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004420
Brad Ebinger35c841c2018-10-01 10:40:55 -07004421 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004422 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004423 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004424 final long identity = Binder.clearCallingIdentity();
4425 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004426 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004427 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004428 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004429 } catch (ImsException e) {
4430 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004431 } finally {
4432 Binder.restoreCallingIdentity(identity);
4433 }
4434 }
4435
4436 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004437 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004438 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004439 "setVoWiFiRoamingSettingEnabled");
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. The
4444 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004445 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004446 } catch (ImsException e) {
4447 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004448 } finally {
4449 Binder.restoreCallingIdentity(identity);
4450 }
4451 }
4452
4453 @Override
4454 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4455 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4456 "setVoWiFiNonPersistent");
4457 final long identity = Binder.clearCallingIdentity();
4458 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004459 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004460 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004461 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
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
shilu366312e2019-12-17 09:28:10 -08004469 /**
4470 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4471 * @param subId The subscription to use to check the configuration.
4472 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004473 @Override
4474 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004475 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004476 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004477 final long identity = Binder.clearCallingIdentity();
4478 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004479 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004480 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004481 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004482 } catch (ImsException e) {
4483 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004484 } finally {
4485 Binder.restoreCallingIdentity(identity);
4486 }
4487 }
4488
4489 @Override
4490 public void setVoWiFiModeSetting(int subId, int mode) {
4491 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4492 "setVoWiFiModeSetting");
4493 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. The
4497 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004498 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004499 } catch (ImsException e) {
4500 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004501 } finally {
4502 Binder.restoreCallingIdentity(identity);
4503 }
4504 }
4505
4506 @Override
4507 public int getVoWiFiRoamingModeSetting(int subId) {
4508 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
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.
Brad Ebinger919631e2021-06-02 17:46:35 -07004513 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004514 } catch (ImsException e) {
4515 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004516 } finally {
4517 Binder.restoreCallingIdentity(identity);
4518 }
4519 }
4520
4521 @Override
4522 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4523 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4524 "setVoWiFiRoamingModeSetting");
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. The
4529 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004530 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004531 } catch (ImsException e) {
4532 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004533 } finally {
4534 Binder.restoreCallingIdentity(identity);
4535 }
4536 }
4537
4538 @Override
4539 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4540 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4541 "setRttCapabilityEnabled");
4542 final long identity = Binder.clearCallingIdentity();
4543 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004544 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004545 // This setting doesn't require an active ImsService connection, so do not verify. The
4546 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004547 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004548 } catch (ImsException e) {
4549 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004550 } finally {
4551 Binder.restoreCallingIdentity(identity);
4552 }
4553 }
4554
shilu366312e2019-12-17 09:28:10 -08004555 /**
4556 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4557 * @param subId The subscription to use to check the configuration.
4558 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004559 @Override
4560 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004561 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004562 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004563 final long identity = Binder.clearCallingIdentity();
4564 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004565 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004566 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004567 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004568 } catch (ImsException e) {
4569 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004570 } finally {
4571 Binder.restoreCallingIdentity(identity);
4572 }
4573 }
4574
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004575 @Override
4576 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4577 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4578 final long identity = Binder.clearCallingIdentity();
4579 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004580 if (!isImsAvailableOnDevice()) {
4581 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4582 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004583 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004584 int slotId = getSlotIndexOrException(subId);
4585 verifyImsMmTelConfiguredOrThrow(slotId);
4586 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004587 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004588 } catch (ImsException e) {
4589 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004590 } finally {
4591 Binder.restoreCallingIdentity(identity);
4592 }
4593 }
4594
4595 @Override
4596 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4597 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4598 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004599 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4600 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4601 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004602 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004603 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004604 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004605 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004606 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4607 + "is inactive, ignoring unregister.");
4608 // If the subscription is no longer active, just return, since the callback will already
4609 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004610 } finally {
4611 Binder.restoreCallingIdentity(identity);
4612 }
4613 }
4614
allenwtsu99c623b2020-01-03 18:24:23 +08004615
4616 private void checkModifyPhoneStatePermission(int subId, String message) {
4617 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4618 message);
4619 }
4620
4621 private boolean isImsProvisioningRequired(int subId, int capability,
4622 boolean isMmtelCapability) {
4623 Phone phone = getPhone(subId);
4624 if (phone == null) {
4625 loge("phone instance null for subid " + subId);
4626 return false;
4627 }
4628 if (isMmtelCapability) {
4629 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4630 return false;
4631 }
4632 } else {
4633 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4634 return false;
4635 }
4636 }
4637 return true;
4638 }
4639
4640 @Override
4641 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4642 boolean isProvisioned) {
4643 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4644
4645 final long identity = Binder.clearCallingIdentity();
4646 try {
4647 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4648 if (!isImsProvisioningRequired(subId, capability, false)) {
4649 return;
4650 }
4651
4652 // this capability requires provisioning, route to the correct API.
4653 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4654 switch (capability) {
4655 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4656 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4657 ims.setEabProvisioned(isProvisioned);
4658 break;
4659 default: {
4660 throw new IllegalArgumentException("Tried to set provisioning for "
4661 + "rcs capability '" + capability + "', which does not require "
4662 + "provisioning.");
4663 }
4664 }
4665 } finally {
4666 Binder.restoreCallingIdentity(identity);
4667 }
4668
4669 }
4670
4671
4672 @Override
4673 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4674 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4675 final long identity = Binder.clearCallingIdentity();
4676 try {
4677 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4678 if (!isImsProvisioningRequired(subId, capability, false)) {
4679 return true;
4680 }
4681
4682 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4683 switch (capability) {
4684 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4685 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4686 return ims.isEabProvisionedOnDevice();
4687
4688 default: {
4689 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4690 + "capability '" + capability + "', which does not require "
4691 + "provisioning.");
4692 }
4693 }
4694
4695 } finally {
4696 Binder.restoreCallingIdentity(identity);
4697 }
4698 }
4699
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004700 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004701 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4702 boolean isProvisioned) {
4703 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004704 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4705 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4706 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004707 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4708 }
allenwtsu99c623b2020-01-03 18:24:23 +08004709 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004710 final long identity = Binder.clearCallingIdentity();
4711 try {
4712 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004713 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004714 return;
4715 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004716 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4717 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4718 loge("setImsProvisioningStatusForCapability: called for technology that does "
4719 + "not support provisioning - " + tech);
4720 return;
4721 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004722
4723 // this capability requires provisioning, route to the correct API.
4724 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4725 switch (capability) {
4726 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4727 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4728 ims.setVolteProvisioned(isProvisioned);
4729 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4730 ims.setWfcProvisioned(isProvisioned);
4731 }
4732 break;
4733 }
4734 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4735 // There is currently no difference in VT provisioning type.
4736 ims.setVtProvisioned(isProvisioned);
4737 break;
4738 }
4739 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4740 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4741 // change the capability of the feature instead if needed.
4742 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4743 == isProvisioned) {
4744 // No change in provisioning.
4745 return;
4746 }
4747 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4748 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004749 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004750 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004751 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4752 + ", Exception" + e.getMessage());
4753 }
4754 break;
4755 }
4756 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004757 throw new IllegalArgumentException("Tried to set provisioning for "
4758 + "MmTel capability '" + capability + "', which does not require "
4759 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004760 }
4761 }
4762
4763 } finally {
4764 Binder.restoreCallingIdentity(identity);
4765 }
4766 }
4767
4768 @Override
4769 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4770 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004771 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4772 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4773 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004774 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4775 }
4776 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4777 final long identity = Binder.clearCallingIdentity();
4778 try {
4779 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004780 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004781 return true;
4782 }
4783
Brad Ebinger0d79c572021-04-17 15:20:49 -07004784 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4785 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4786 loge("getImsProvisioningStatusForCapability: called for technology that does "
4787 + "not support provisioning - " + tech);
4788 return true;
4789 }
4790
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004791 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4792 switch (capability) {
4793 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4794 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4795 return ims.isVolteProvisionedOnDevice();
4796 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4797 return ims.isWfcProvisionedOnDevice();
4798 }
4799 // This should never happen, since we are checking tech above to make sure it
4800 // is either LTE or IWLAN.
4801 throw new IllegalArgumentException("Invalid radio technology for voice "
4802 + "capability.");
4803 }
4804 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4805 // There is currently no difference in VT provisioning type.
4806 return ims.isVtProvisionedOnDevice();
4807 }
4808 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4809 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4810 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4811 }
4812 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004813 throw new IllegalArgumentException(
4814 "Tried to get provisioning for MmTel capability '" + capability
4815 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004816 }
4817 }
4818
4819 } finally {
4820 Binder.restoreCallingIdentity(identity);
4821 }
4822 }
4823
4824 @Override
4825 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4826 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4827 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4828 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4829 }
4830 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4831 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4832 return (provisionedBits & capability) > 0;
4833 }
4834
4835 @Override
4836 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4837 boolean isProvisioned) {
4838 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4839 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4840 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4841 }
4842 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4843 "setProvisioningStatusForCapability");
4844 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4845 // If the current provisioning status for capability already matches isProvisioned,
4846 // do nothing.
4847 if (((provisionedBits & capability) > 0) == isProvisioned) {
4848 return;
4849 }
4850 if (isProvisioned) {
4851 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4852 } else {
4853 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4854 }
4855 }
4856
4857 /**
4858 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4859 * technology. The bitfield should mirror the bitfield defined by
4860 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4861 */
4862 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4863 String key = getMmTelProvisioningKey(subId, tech);
4864 // Default is no capabilities are provisioned.
4865 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4866 }
4867
4868 /**
4869 * Sets the MmTel capability provisioning bitfield (defined by
4870 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4871 * technology specified.
4872 *
4873 * Note: This is a synchronous command and should not be called on UI thread.
4874 */
4875 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4876 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4877 String key = getMmTelProvisioningKey(subId, tech);
4878 editor.putInt(key, newField);
4879 editor.commit();
4880 }
4881
4882 private static String getMmTelProvisioningKey(int subId, int tech) {
4883 // resulting key is provision_ims_mmtel_{subId}_{tech}
4884 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4885 }
4886
4887 /**
4888 * Query CarrierConfig to see if the specified capability requires provisioning for the
4889 * carrier associated with the subscription id.
4890 */
4891 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4892 int capability) {
4893 CarrierConfigManager configManager = new CarrierConfigManager(context);
4894 PersistableBundle c = configManager.getConfigForSubId(subId);
4895 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004896 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004897 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4898 false);
4899 boolean requireVoiceVtProvisioning = c.getBoolean(
4900 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4901
4902 // First check to make sure that the capability requires provisioning.
4903 switch (capability) {
4904 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4905 // intentional fallthrough
4906 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4907 if (requireVoiceVtProvisioning) {
4908 // Voice and Video requires provisioning
4909 return true;
4910 }
4911 break;
4912 }
4913 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4914 if (requireUtProvisioning) {
4915 // UT requires provisioning
4916 return true;
4917 }
4918 break;
4919 }
4920 }
4921 return false;
4922 }
4923
allenwtsu99c623b2020-01-03 18:24:23 +08004924 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4925 int capability) {
4926 CarrierConfigManager configManager = new CarrierConfigManager(context);
4927 PersistableBundle c = configManager.getConfigForSubId(subId);
4928
4929 boolean requireRcsProvisioning = c.getBoolean(
4930 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4931
4932 // First check to make sure that the capability requires provisioning.
4933 switch (capability) {
4934 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4935 // intentional fallthrough
4936 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4937 if (requireRcsProvisioning) {
4938 // OPTION or PRESENCE requires provisioning
4939 return true;
4940 }
4941 break;
4942 }
4943 }
4944 return false;
4945 }
4946
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004947 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004948 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004949 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4950 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4951 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004952 enforceReadPrivilegedPermission("getImsProvisioningInt");
4953 final long identity = Binder.clearCallingIdentity();
4954 try {
4955 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004956 int slotId = getSlotIndex(subId);
4957 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4958 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4959 + subId + "' for key:" + key);
4960 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4961 }
calvinpanb5a34062021-02-08 19:59:36 +08004962 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004963 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004964 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4965 + subId + "' for key:" + key);
4966 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004967 } finally {
4968 Binder.restoreCallingIdentity(identity);
4969 }
4970 }
4971
4972 @Override
4973 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004974 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4975 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4976 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004977 enforceReadPrivilegedPermission("getImsProvisioningString");
4978 final long identity = Binder.clearCallingIdentity();
4979 try {
4980 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004981 int slotId = getSlotIndex(subId);
4982 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4983 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4984 + subId + "' for key:" + key);
4985 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4986 }
calvinpanb5a34062021-02-08 19:59:36 +08004987 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004988 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004989 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4990 + subId + "' for key:" + key);
4991 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004992 } finally {
4993 Binder.restoreCallingIdentity(identity);
4994 }
4995 }
4996
4997 @Override
4998 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004999 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5000 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5001 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005002 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5003 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005004 final long identity = Binder.clearCallingIdentity();
5005 try {
5006 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005007 int slotId = getSlotIndex(subId);
5008 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5009 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5010 + subId + "' for key:" + key);
5011 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5012 }
calvinpanb5a34062021-02-08 19:59:36 +08005013 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5014 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005015 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005016 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005017 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005018 } finally {
5019 Binder.restoreCallingIdentity(identity);
5020 }
5021 }
5022
5023 @Override
5024 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005025 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5026 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5027 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005028 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5029 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005030 final long identity = Binder.clearCallingIdentity();
5031 try {
5032 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005033 int slotId = getSlotIndex(subId);
5034 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5035 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5036 + subId + "' for key:" + key);
5037 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5038 }
calvinpanb5a34062021-02-08 19:59:36 +08005039 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5040 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005041 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005042 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005043 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005044 } finally {
5045 Binder.restoreCallingIdentity(identity);
5046 }
5047 }
5048
Brad Ebinger919631e2021-06-02 17:46:35 -07005049 /**
5050 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5051 * for the given slot ID or no ImsResolver instance has been created.
5052 * @param slotId The slot ID that the IMS service is created for.
5053 * @throws ImsException If there is no ImsService configured for this slot.
5054 */
5055 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5056 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5057 ImsFeature.FEATURE_MMTEL)) {
5058 throw new ImsException("This subscription does not support MMTEL over IMS",
5059 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5060 }
5061 }
5062
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005063 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005064 int slotId = SubscriptionManager.getSlotIndex(subId);
5065 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005066 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5067 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005068 }
5069 return slotId;
5070 }
5071
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005072 private int getSlotIndex(int subId) {
5073 int slotId = SubscriptionManager.getSlotIndex(subId);
5074 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5075 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5076 }
5077 return slotId;
5078 }
5079
Wink Saville36469e72014-06-11 15:17:00 -07005080 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005081 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005082 */
5083 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005084 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5085 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005086 try {
5087 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5088 } catch (SecurityException se) {
5089 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5090 throw new SecurityException("Package " + callingPackage + " does not belong to "
5091 + Binder.getCallingUid());
5092 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005093 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005094 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005095 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005096 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005097 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005098 mApp, subId, callingPackage, callingFeatureId,
5099 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005100 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5101 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005102
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005103 final long identity = Binder.clearCallingIdentity();
5104 try {
5105 final Phone phone = getPhone(subId);
5106 if (phone != null) {
5107 return phone.getServiceState().getDataNetworkType();
5108 } else {
5109 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5110 }
5111 } finally {
5112 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005113 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005114 }
5115
5116 /**
5117 * Returns the data network type
5118 */
5119 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005120 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005121 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5122 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005123 }
5124
5125 /**
5126 * Returns the data network type for a subId
5127 */
5128 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005129 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5130 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005131 String functionName = "getDataNetworkTypeForSubscriber";
5132 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5133 mApp, functionName)) {
5134 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5135 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5136 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5137 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005138 }
5139
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005140 final long identity = Binder.clearCallingIdentity();
5141 try {
5142 final Phone phone = getPhone(subId);
5143 if (phone != null) {
5144 return phone.getServiceState().getDataNetworkType();
5145 } else {
5146 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5147 }
5148 } finally {
5149 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005150 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005151 }
5152
5153 /**
Wink Saville36469e72014-06-11 15:17:00 -07005154 * Returns the Voice network type for a subId
5155 */
5156 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005157 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5158 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005159 String functionName = "getVoiceNetworkTypeForSubscriber";
5160 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5161 mApp, functionName)) {
5162 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5163 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5164 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5165 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005166 }
5167
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005168 final long identity = Binder.clearCallingIdentity();
5169 try {
5170 final Phone phone = getPhone(subId);
5171 if (phone != null) {
5172 return phone.getServiceState().getVoiceNetworkType();
5173 } else {
5174 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5175 }
5176 } finally {
5177 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005178 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005179 }
5180
5181 /**
5182 * @return true if a ICC card is present
5183 */
5184 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005185 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005186 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5187 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005188 }
5189
5190 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005191 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005192 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005193 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005194 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005195 final long identity = Binder.clearCallingIdentity();
5196 try {
5197 final Phone phone = PhoneFactory.getPhone(slotIndex);
5198 if (phone != null) {
5199 return phone.getIccCard().hasIccCard();
5200 } else {
5201 return false;
5202 }
5203 } finally {
5204 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005205 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005206 }
5207
5208 /**
5209 * Return if the current radio is LTE on CDMA. This
5210 * is a tri-state return value as for a period of time
5211 * the mode may be unknown.
5212 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005213 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005214 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005215 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005216 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005217 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005218 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5219 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5220 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005221 }
5222
Sanket Padawe356d7632015-06-22 14:03:32 -07005223 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005224 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5225 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005226 try {
5227 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5228 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005229 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5230 }
5231
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005232 final long identity = Binder.clearCallingIdentity();
5233 try {
5234 final Phone phone = getPhone(subId);
5235 if (phone == null) {
5236 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5237 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005238 return TelephonyProperties.lte_on_cdma_device()
5239 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005240 }
5241 } finally {
5242 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005243 }
Wink Saville36469e72014-06-11 15:17:00 -07005244 }
5245
Wink Saville36469e72014-06-11 15:17:00 -07005246 /**
5247 * {@hide}
5248 * Returns Default subId, 0 in the case of single standby.
5249 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005250 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005251 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005252 }
5253
Shishir Agrawala9f32182016-04-12 12:00:16 -07005254 private int getSlotForDefaultSubscription() {
5255 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5256 }
5257
Wink Savilleb564aae2014-10-23 10:18:09 -07005258 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005259 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005260 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005261
Pengquan Menge92a50d2018-09-21 15:54:48 -07005262 private boolean isActiveSubscription(int subId) {
5263 return mSubscriptionController.isActiveSubId(subId);
5264 }
5265
Ihab Awadf2177b72013-11-25 13:33:23 -08005266 /**
5267 * @see android.telephony.TelephonyManager.WifiCallingChoices
5268 */
5269 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005270 final long identity = Binder.clearCallingIdentity();
5271 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005272 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005273 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5274 getWhenToMakeWifiCallsDefaultPreference());
5275 } finally {
5276 Binder.restoreCallingIdentity(identity);
5277 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005278 }
5279
5280 /**
5281 * @see android.telephony.TelephonyManager.WifiCallingChoices
5282 */
5283 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005284 final long identity = Binder.clearCallingIdentity();
5285 try {
5286 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005287 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005288 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5289 } finally {
5290 Binder.restoreCallingIdentity(identity);
5291 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005292 }
5293
Sailesh Nepald1e68152013-12-12 19:08:02 -08005294 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005295 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005296 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005297 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005298
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005299 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5300 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5301 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005302 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005303 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5304 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005305 }
5306 return PhoneFactory.getPhone(phoneId);
5307 }
5308
Shishir Agrawal566b7612013-10-28 14:41:00 -07005309 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005310 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005311 @NonNull IccLogicalChannelRequest request) {
5312 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5313 /*message=*/ "iccOpenLogicalChannel");
5314
5315 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5316 // Verify that the callingPackage in the request belongs to the calling UID
5317 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5318
5319 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005320 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005321
Rambo Wanga1782702021-11-10 20:15:19 -08005322 private Phone getPhoneFromValidIccLogicalChannelRequest(
5323 @NonNull IccLogicalChannelRequest request, String message) {
5324 Phone phone;
5325 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5326 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5327 mApp, request.subId, message);
5328 phone = getPhoneFromSubId(request.subId);
5329 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5330 enforceModifyPermission();
5331 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5332 } else {
5333 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005334 }
Rambo Wanga1782702021-11-10 20:15:19 -08005335 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005336 }
5337
5338 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005339 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005340 final long identity = Binder.clearCallingIdentity();
5341 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005342 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005343 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005344 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5345 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005346 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5347 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005348 loge("The calling package is not allowed to access ISD-R.");
5349 throw new SecurityException(
5350 "The calling package is not allowed to access ISD-R.");
5351 }
Derek Tan740e1672017-06-27 14:56:27 -07005352 }
Derek Tan740e1672017-06-27 14:56:27 -07005353
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005354 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005355 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5356 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005357 return response;
5358 } finally {
5359 Binder.restoreCallingIdentity(identity);
5360 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005361 }
5362
5363 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005364 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5365 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5366 /*message=*/"iccCloseLogicalChannel");
5367
5368 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5369
5370 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005371 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005372
Rambo Wanga1782702021-11-10 20:15:19 -08005373 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5374 IccLogicalChannelRequest request) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005375 final long identity = Binder.clearCallingIdentity();
5376 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005377 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005378 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005379 }
Rambo Wanga1782702021-11-10 20:15:19 -08005380 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005381 null /* workSource */);
Rambo Wanga1782702021-11-10 20:15:19 -08005382 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005383 return success;
5384 } finally {
5385 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005386 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005387 }
5388
5389 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005390 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005391 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005392 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5393 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005394 if (DBG) {
5395 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5396 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5397 + p3 + " data=" + data);
5398 }
5399 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5400 command, p1, p2, p3, data);
5401 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005402
Jordan Liu4c733742019-02-28 12:03:40 -08005403 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005404 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5405 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005406 enforceModifyPermission();
5407 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005408 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5409 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5410 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005411 }
5412 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005413 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5414 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005415 }
5416
5417 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5418 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005419 final long identity = Binder.clearCallingIdentity();
5420 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005421 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005422 return "";
5423 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005424
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005425 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005426 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5427 null /* workSource */);
5428 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005429
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005430 // Append the returned status code to the end of the response payload.
5431 String s = Integer.toHexString(
5432 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5433 if (response.payload != null) {
5434 s = IccUtils.bytesToHexString(response.payload) + s;
5435 }
5436 return s;
5437 } finally {
5438 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005439 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005440 }
Jake Hambye994d462014-02-03 13:10:13 -08005441
Evan Charltonc66da362014-05-16 14:06:40 -07005442 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005443 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5444 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005445 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5446 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005447 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005448 if (DBG) {
5449 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5450 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5451 }
5452 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5453 cla, command, p1, p2, p3, data);
5454 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005455
Jordan Liu4c733742019-02-28 12:03:40 -08005456 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005457 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5458 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005459 enforceModifyPermission();
5460 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5461 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005462 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5463 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5464 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005465 }
5466
5467 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005468 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5469 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005470 }
5471
5472 // open APDU basic channel assuming the caller has sufficient permissions
5473 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5474 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005475 final long identity = Binder.clearCallingIdentity();
5476 try {
5477 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5478 && TextUtils.equals(ISDR_AID, data)) {
5479 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005480 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5481 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005482 if (bestComponent == null
5483 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5484 loge("The calling package is not allowed to select ISD-R.");
5485 throw new SecurityException(
5486 "The calling package is not allowed to select ISD-R.");
5487 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005488 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005489
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005490 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005491 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5492 null /* workSource */);
5493 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005494
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005495 // Append the returned status code to the end of the response payload.
5496 String s = Integer.toHexString(
5497 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5498 if (response.payload != null) {
5499 s = IccUtils.bytesToHexString(response.payload) + s;
5500 }
5501 return s;
5502 } finally {
5503 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005504 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005505 }
5506
5507 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005508 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005509 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005510 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5511 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005512
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005513 final long identity = Binder.clearCallingIdentity();
5514 try {
5515 if (DBG) {
5516 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5517 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5518 }
5519
5520 IccIoResult response =
5521 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5522 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5523 subId);
5524
5525 if (DBG) {
5526 log("Exchange SIM_IO [R]" + response);
5527 }
5528
5529 byte[] result = null;
5530 int length = 2;
5531 if (response.payload != null) {
5532 length = 2 + response.payload.length;
5533 result = new byte[length];
5534 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5535 } else {
5536 result = new byte[length];
5537 }
5538
5539 result[length - 1] = (byte) response.sw2;
5540 result[length - 2] = (byte) response.sw1;
5541 return result;
5542 } finally {
5543 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005544 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005545 }
5546
Nathan Haroldb3014052017-01-25 15:57:32 -08005547 /**
5548 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5549 * on a particular subscription
5550 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005551 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5552 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005553 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005554 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005555 return null;
5556 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005557
5558 final long identity = Binder.clearCallingIdentity();
5559 try {
5560 if (appType != TelephonyManager.APPTYPE_USIM
5561 && appType != TelephonyManager.APPTYPE_SIM) {
5562 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5563 return null;
5564 }
5565 Object response = sendRequest(
5566 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5567 if (response instanceof String[]) {
5568 return (String[]) response;
5569 }
yincheng zhao2737e882019-09-06 17:06:54 -07005570 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005571 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005572 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005573 } finally {
5574 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005575 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005576 }
5577
yincheng zhao2737e882019-09-06 17:06:54 -07005578 /**
5579 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5580 * subscription.
5581 *
5582 * @param subId the id of the subscription.
5583 * @param appType the uicc app type, must be USIM or SIM.
5584 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5585 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005586 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005587 * @return number of fplmns that is successfully written to the SIM.
5588 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005589 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5590 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005591 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5592 mApp, subId, "setForbiddenPlmns");
5593
yincheng zhao2737e882019-09-06 17:06:54 -07005594 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5595 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5596 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5597 }
5598 if (fplmns == null) {
5599 throw new IllegalArgumentException("Fplmn List provided is null");
5600 }
5601 for (String fplmn : fplmns) {
5602 if (!CellIdentity.isValidPlmn(fplmn)) {
5603 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5604 }
5605 }
5606 final long identity = Binder.clearCallingIdentity();
5607 try {
5608 Object response = sendRequest(
5609 CMD_SET_FORBIDDEN_PLMNS,
5610 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5611 subId);
5612 return (int) response;
5613 } finally {
5614 Binder.restoreCallingIdentity(identity);
5615 }
5616 }
5617
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005618 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005619 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005620 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5621 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005622
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005623 final long identity = Binder.clearCallingIdentity();
5624 try {
5625 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5626 if (response.payload == null) {
5627 return "";
5628 }
Evan Charltonc66da362014-05-16 14:06:40 -07005629
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005630 // Append the returned status code to the end of the response payload.
5631 String s = Integer.toHexString(
5632 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5633 s = IccUtils.bytesToHexString(response.payload) + s;
5634 return s;
5635 } finally {
5636 Binder.restoreCallingIdentity(identity);
5637 }
Evan Charltonc66da362014-05-16 14:06:40 -07005638 }
5639
Jake Hambye994d462014-02-03 13:10:13 -08005640 /**
5641 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5642 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5643 *
5644 * @param itemID the ID of the item to read
5645 * @return the NV item as a String, or null on error.
5646 */
5647 @Override
5648 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005649 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005650 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5651 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005652
5653 final long identity = Binder.clearCallingIdentity();
5654 try {
5655 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005656 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005657 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5658 return value;
5659 } finally {
5660 Binder.restoreCallingIdentity(identity);
5661 }
Jake Hambye994d462014-02-03 13:10:13 -08005662 }
5663
5664 /**
5665 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5666 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5667 *
5668 * @param itemID the ID of the item to read
5669 * @param itemValue the value to write, as a String
5670 * @return true on success; false on any failure
5671 */
5672 @Override
5673 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005674 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005675 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5676 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005677
5678 final long identity = Binder.clearCallingIdentity();
5679 try {
5680 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5681 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005682 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005683 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5684 return success;
5685 } finally {
5686 Binder.restoreCallingIdentity(identity);
5687 }
Jake Hambye994d462014-02-03 13:10:13 -08005688 }
5689
5690 /**
5691 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5692 * Used for device configuration by some CDMA operators.
5693 *
5694 * @param preferredRoamingList byte array containing the new PRL
5695 * @return true on success; false on any failure
5696 */
5697 @Override
5698 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005699 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5700 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005701
5702 final long identity = Binder.clearCallingIdentity();
5703 try {
5704 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5705 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5706 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5707 return success;
5708 } finally {
5709 Binder.restoreCallingIdentity(identity);
5710 }
Jake Hambye994d462014-02-03 13:10:13 -08005711 }
5712
5713 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005714 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005715 * Used for device configuration by some CDMA operators.
5716 *
chen xu6dac5ab2018-10-26 17:39:23 -07005717 * @param slotIndex - device slot.
5718 *
Jake Hambye994d462014-02-03 13:10:13 -08005719 * @return true on success; false on any failure
5720 */
5721 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005722 public boolean resetModemConfig(int slotIndex) {
5723 Phone phone = PhoneFactory.getPhone(slotIndex);
5724 if (phone != null) {
5725 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5726 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005727
chen xu6dac5ab2018-10-26 17:39:23 -07005728 final long identity = Binder.clearCallingIdentity();
5729 try {
5730 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5731 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5732 return success;
5733 } finally {
5734 Binder.restoreCallingIdentity(identity);
5735 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005736 }
chen xu6dac5ab2018-10-26 17:39:23 -07005737 return false;
5738 }
5739
5740 /**
5741 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5742 *
5743 * @param slotIndex - device slot.
5744 *
5745 * @return true on success; false on any failure
5746 */
5747 @Override
5748 public boolean rebootModem(int slotIndex) {
5749 Phone phone = PhoneFactory.getPhone(slotIndex);
5750 if (phone != null) {
5751 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5752 mApp, phone.getSubId(), "rebootModem");
5753
5754 final long identity = Binder.clearCallingIdentity();
5755 try {
5756 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5757 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5758 return success;
5759 } finally {
5760 Binder.restoreCallingIdentity(identity);
5761 }
5762 }
5763 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005764 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005765
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005766 public String[] getPcscfAddress(String apnType, String callingPackage,
5767 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005768 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005769 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5770 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005771 return new String[0];
5772 }
5773
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005774 final long identity = Binder.clearCallingIdentity();
5775 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005776 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005777 } finally {
5778 Binder.restoreCallingIdentity(identity);
5779 }
Wink Saville36469e72014-06-11 15:17:00 -07005780 }
5781
Brad Ebinger51f743a2017-01-23 13:50:20 -08005782 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005783 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5784 * {@link #disableIms(int)}.
5785 * @param slotIndex device slot.
5786 */
5787 public void resetIms(int slotIndex) {
5788 enforceModifyPermission();
5789
5790 final long identity = Binder.clearCallingIdentity();
5791 try {
5792 if (mImsResolver == null) {
5793 // may happen if the does not support IMS.
5794 return;
5795 }
5796 mImsResolver.disableIms(slotIndex);
5797 mImsResolver.enableIms(slotIndex);
5798 } finally {
5799 Binder.restoreCallingIdentity(identity);
5800 }
5801 }
5802
5803 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005804 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5805 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005806 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005807 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005808 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005809
5810 final long identity = Binder.clearCallingIdentity();
5811 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005812 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005813 // may happen if the device does not support IMS.
5814 return;
5815 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005816 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005817 } finally {
5818 Binder.restoreCallingIdentity(identity);
5819 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005820 }
5821
5822 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005823 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5824 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005825 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005826 public void disableIms(int slotId) {
5827 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005828
5829 final long identity = Binder.clearCallingIdentity();
5830 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005831 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005832 // may happen if the device does not support IMS.
5833 return;
5834 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005835 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005836 } finally {
5837 Binder.restoreCallingIdentity(identity);
5838 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005839 }
5840
5841 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005842 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5843 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005844 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005845 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005846 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005847 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005848
5849 final long identity = Binder.clearCallingIdentity();
5850 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005851 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005852 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5853 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005854 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005855 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005856 } finally {
5857 Binder.restoreCallingIdentity(identity);
5858 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005859 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005860 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005861 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5862 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005863 @Override
5864 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005865 enforceModifyPermission();
5866
5867 final long identity = Binder.clearCallingIdentity();
5868 try {
5869 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005870 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005871 } finally {
5872 Binder.restoreCallingIdentity(identity);
5873 }
5874 }
5875
5876 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005877 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005878 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005879 */
5880 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5881 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005882
5883 final long identity = Binder.clearCallingIdentity();
5884 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005885 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005886 // may happen if the device does not support IMS.
5887 return null;
5888 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005889 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005890 } finally {
5891 Binder.restoreCallingIdentity(identity);
5892 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005893 }
5894
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005895 /**
5896 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005897 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005898 */
5899 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5900 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005901
5902 final long identity = Binder.clearCallingIdentity();
5903 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005904 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005905 // may happen if the device does not support IMS.
5906 return null;
5907 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005908 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005909 } finally {
5910 Binder.restoreCallingIdentity(identity);
5911 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005912 }
5913
Brad Ebinger884c07b2018-02-15 16:17:40 -08005914 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005915 * Sets the ImsService Package Name that Telephony will bind to.
5916 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005917 * @param slotIndex the slot ID that the ImsService should bind for.
5918 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005919 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005920 * @param featureTypes An integer array of feature types associated with a packageName.
5921 * @param packageName The name of the package that the current configuration will be replaced
5922 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005923 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005924 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005925 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5926 int[] featureTypes, String packageName) {
5927 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5928 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005929 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5930 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005931 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005932
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005933 final long identity = Binder.clearCallingIdentity();
5934 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005935 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005936 // may happen if the device does not support IMS.
5937 return false;
5938 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005939 Map<Integer, String> featureConfig = new HashMap<>();
5940 for (int featureType : featureTypes) {
5941 featureConfig.put(featureType, packageName);
5942 }
5943 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5944 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005945 } finally {
5946 Binder.restoreCallingIdentity(identity);
5947 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005948 }
5949
5950 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005951 * Clears any carrier ImsService overrides for the slot index specified that were previously
5952 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5953 *
5954 * This should only be used for testing.
5955 *
5956 * @param slotIndex the slot ID that the ImsService should bind for.
5957 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5958 */
5959 @Override
5960 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5961 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5962 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5963 "clearCarrierImsServiceOverride");
5964 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5965 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5966 "clearCarrierImsServiceOverride");
5967
5968 final long identity = Binder.clearCallingIdentity();
5969 try {
5970 if (mImsResolver == null) {
5971 // may happen if the device does not support IMS.
5972 return false;
5973 }
5974 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5975 } finally {
5976 Binder.restoreCallingIdentity(identity);
5977 }
5978 }
5979
5980 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005981 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005982 *
5983 * @param slotId The slot that the ImsService is associated with.
5984 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5985 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005986 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005987 * @return the package name of the ImsService configuration.
5988 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005989 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5990 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005991 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005992 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005993 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005994 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5995 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005996
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005997 final long identity = Binder.clearCallingIdentity();
5998 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005999 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006000 // may happen if the device does not support IMS.
6001 return "";
6002 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006003 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006004 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6005 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006006 } finally {
6007 Binder.restoreCallingIdentity(identity);
6008 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006009 }
6010
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006011 /**
6012 * Get the MmTelFeature state associated with the requested subscription id.
6013 * @param subId The subscription that the MmTelFeature is associated with.
6014 * @param callback A callback with an integer containing the
6015 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6016 */
6017 @Override
6018 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6019 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
6020 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6021 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6022 "IMS not available on device.");
6023 }
6024 final long token = Binder.clearCallingIdentity();
6025 try {
6026 int slotId = getSlotIndex(subId);
6027 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6028 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6029 + subId + "'");
6030 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6031 }
Brad Ebinger919631e2021-06-02 17:46:35 -07006032 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006033 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6034 try {
6035 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6036 } catch (RemoteException e) {
6037 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6038 + "Ignore");
6039 }
6040 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006041 } catch (ImsException e) {
6042 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006043 } finally {
6044 Binder.restoreCallingIdentity(token);
6045 }
6046 }
6047
Daniel Brightbb5840b2021-01-12 15:48:18 -08006048 /**
6049 * Sets the ims registration state on all valid {@link Phone}s.
6050 */
6051 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006052 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006053
6054 final long identity = Binder.clearCallingIdentity();
6055 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006056 // NOTE: Before S, this method only set the default phone.
6057 for (final Phone phone : PhoneFactory.getPhones()) {
6058 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6059 phone.setImsRegistrationState(registered);
6060 }
6061 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006062 } finally {
6063 Binder.restoreCallingIdentity(identity);
6064 }
Wink Saville36469e72014-06-11 15:17:00 -07006065 }
6066
6067 /**
Stuart Scott54788802015-03-30 13:18:01 -07006068 * Set the network selection mode to automatic.
6069 *
6070 */
6071 @Override
6072 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006073 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6074 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006075
6076 final long identity = Binder.clearCallingIdentity();
6077 try {
shilufc958392020-01-20 11:36:01 -08006078 if (!isActiveSubscription(subId)) {
6079 return;
6080 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006081 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006082 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6083 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006084 } finally {
6085 Binder.restoreCallingIdentity(identity);
6086 }
Stuart Scott54788802015-03-30 13:18:01 -07006087 }
6088
Jack Yud10cdd42020-09-28 20:28:01 -07006089 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006090 * Ask the radio to connect to the input network and change selection mode to manual.
6091 *
6092 * @param subId the id of the subscription.
6093 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6094 * the operator to attach to.
6095 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6096 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6097 * normal network selection next time.
6098 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006099 */
6100 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006101 public boolean setNetworkSelectionModeManual(
6102 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006103 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6104 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006105
6106 if (!isActiveSubscription(subId)) {
6107 return false;
6108 }
6109
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006110 final long identity = Binder.clearCallingIdentity();
6111 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006112 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006113 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006114 if (DBG) {
6115 log("setNetworkSelectionModeManual: subId: " + subId
6116 + " operator: " + operatorInfo);
6117 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006118 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6119 } finally {
6120 Binder.restoreCallingIdentity(identity);
6121 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006122 }
shilu84f6e8b2019-12-19 13:58:01 -08006123 /**
6124 * Get the manual network selection
6125 *
6126 * @param subId the id of the subscription.
6127 *
6128 * @return the previously saved user selected PLMN
6129 */
6130 @Override
6131 public String getManualNetworkSelectionPlmn(int subId) {
6132 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006133 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006134 mApp, subId, "getManualNetworkSelectionPlmn");
6135
6136 final long identity = Binder.clearCallingIdentity();
6137 try {
6138 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006139 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006140 }
6141
6142 final Phone phone = getPhone(subId);
6143 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006144 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006145 }
6146 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6147 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6148 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6149 } finally {
6150 Binder.restoreCallingIdentity(identity);
6151 }
6152 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006153
6154 /**
6155 * Scans for available networks.
6156 */
6157 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006158 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6159 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006160 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6161 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006162 LocationAccessPolicy.LocationPermissionResult locationResult =
6163 LocationAccessPolicy.checkLocationPermission(mApp,
6164 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6165 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006166 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006167 .setCallingPid(Binder.getCallingPid())
6168 .setCallingUid(Binder.getCallingUid())
6169 .setMethod("getCellNetworkScanResults")
6170 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006171 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6172 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006173 .build());
6174 switch (locationResult) {
6175 case DENIED_HARD:
6176 throw new SecurityException("Not allowed to access scan results -- location");
6177 case DENIED_SOFT:
6178 return null;
6179 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006180
Pengquan Menga1bb6272018-09-06 09:59:22 -07006181 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006182 try {
6183 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006184 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006185 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006186 } finally {
6187 Binder.restoreCallingIdentity(identity);
6188 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006189 }
6190
6191 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006192 * Get the call forwarding info, given the call forwarding reason.
6193 */
6194 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006195 public void getCallForwarding(int subId, int callForwardingReason,
6196 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006197 enforceReadPrivilegedPermission("getCallForwarding");
6198 long identity = Binder.clearCallingIdentity();
6199 try {
6200 if (DBG) {
6201 log("getCallForwarding: subId " + subId
6202 + " callForwardingReason" + callForwardingReason);
6203 }
Hall Liu27d24262020-09-18 19:04:59 -07006204
6205 Phone phone = getPhone(subId);
6206 if (phone == null) {
6207 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006208 callback.onError(
6209 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006210 } catch (RemoteException e) {
6211 // ignore
6212 }
6213 return;
6214 }
6215
6216 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6217 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6218 @Override
6219 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6220 try {
6221 callback.onCallForwardingInfoAvailable(info);
6222 } catch (RemoteException e) {
6223 // ignore
6224 }
6225 }
6226
6227 @Override
6228 public void onError(int error) {
6229 try {
6230 callback.onError(error);
6231 } catch (RemoteException e) {
6232 // ignore
6233 }
6234 }
6235 });
6236 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006237 } finally {
6238 Binder.restoreCallingIdentity(identity);
6239 }
6240 }
6241
6242 /**
6243 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6244 * reason, the number to forward, and the timeout before the forwarding is attempted.
6245 */
6246 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006247 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6248 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006249 enforceModifyPermission();
6250 long identity = Binder.clearCallingIdentity();
6251 try {
6252 if (DBG) {
6253 log("setCallForwarding: subId " + subId
6254 + " callForwardingInfo" + callForwardingInfo);
6255 }
Hall Liu27d24262020-09-18 19:04:59 -07006256
6257 Phone phone = getPhone(subId);
6258 if (phone == null) {
6259 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006260 callback.accept(
6261 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006262 } catch (RemoteException e) {
6263 // ignore
6264 }
6265 return;
6266 }
6267
6268 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6269 FunctionalUtils.ignoreRemoteException(callback::accept));
6270
6271 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006272 } finally {
6273 Binder.restoreCallingIdentity(identity);
6274 }
6275 }
6276
6277 /**
Hall Liu27d24262020-09-18 19:04:59 -07006278 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006279 */
6280 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006281 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006282 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006283 long identity = Binder.clearCallingIdentity();
6284 try {
Hall Liu27d24262020-09-18 19:04:59 -07006285 Phone phone = getPhone(subId);
6286 if (phone == null) {
6287 try {
6288 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6289 } catch (RemoteException e) {
6290 // ignore
6291 }
6292 return;
6293 }
SongFerngWang0e767992021-03-31 22:08:45 +08006294 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6295 PersistableBundle c = configManager.getConfigForSubId(subId);
6296 boolean requireUssd = c.getBoolean(
6297 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006298
Shuo Qian4a594052020-01-23 11:59:30 -08006299 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006300 if (requireUssd) {
6301 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6302 getSubscriptionCarrierId(subId));
6303 String newUssdCommand = "";
6304 try {
6305 newUssdCommand = carrierXmlParser.getFeature(
6306 CarrierXmlParser.FEATURE_CALL_WAITING)
6307 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6308 } catch (NullPointerException e) {
6309 loge("Failed to generate USSD number" + e);
6310 }
6311 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6312 mMainThreadHandler, callback, carrierXmlParser,
6313 CarrierXmlParser.SsEntry.SSAction.QUERY);
6314 final String ussdCommand = newUssdCommand;
6315 Executors.newSingleThreadExecutor().execute(() -> {
6316 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6317 });
6318 } else {
6319 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6320 callback::accept);
6321 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6322 }
Shuo Qian4a594052020-01-23 11:59:30 -08006323 } finally {
6324 Binder.restoreCallingIdentity(identity);
6325 }
6326 }
6327
6328 /**
Hall Liu27d24262020-09-18 19:04:59 -07006329 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006330 */
6331 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006332 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006333 enforceModifyPermission();
6334 long identity = Binder.clearCallingIdentity();
6335 try {
Hall Liu27d24262020-09-18 19:04:59 -07006336 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6337
6338 Phone phone = getPhone(subId);
6339 if (phone == null) {
6340 try {
6341 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6342 } catch (RemoteException e) {
6343 // ignore
6344 }
6345 return;
6346 }
6347
SongFerngWang0e767992021-03-31 22:08:45 +08006348 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6349 PersistableBundle c = configManager.getConfigForSubId(subId);
6350 boolean requireUssd = c.getBoolean(
6351 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006352
SongFerngWang0e767992021-03-31 22:08:45 +08006353 if (DBG) log("getCallWaitingStatus: subId " + subId);
6354 if (requireUssd) {
6355 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6356 getSubscriptionCarrierId(subId));
6357 CarrierXmlParser.SsEntry.SSAction ssAction =
6358 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6359 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6360 String newUssdCommand = "";
6361 try {
6362 newUssdCommand = carrierXmlParser.getFeature(
6363 CarrierXmlParser.FEATURE_CALL_WAITING)
6364 .makeCommand(ssAction, null);
6365 } catch (NullPointerException e) {
6366 loge("Failed to generate USSD number" + e);
6367 }
6368 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6369 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6370 final String ussdCommand = newUssdCommand;
6371 Executors.newSingleThreadExecutor().execute(() -> {
6372 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6373 });
6374 } else {
6375 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6376 FunctionalUtils.ignoreRemoteException(callback::accept));
6377
6378 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6379 }
Shuo Qian4a594052020-01-23 11:59:30 -08006380 } finally {
6381 Binder.restoreCallingIdentity(identity);
6382 }
6383 }
6384
6385 /**
yinxub1bed742017-04-17 11:45:04 -07006386 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006387 *
yinxub1bed742017-04-17 11:45:04 -07006388 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006389 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6390 * location related information which will be sent if the caller already possess
6391 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006392 * @param request contains the radio access networks with bands/channels to scan
6393 * @param messenger callback messenger for scan results or errors
6394 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006395 * @return the id of the requested scan which can be used to stop the scan.
6396 */
6397 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006398 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6399 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006400 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006401 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6402 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006403 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006404 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6405 if (!renounceFineLocationAccess) {
6406 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6407 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6408 .setCallingPackage(callingPackage)
6409 .setCallingFeatureId(callingFeatureId)
6410 .setCallingPid(Binder.getCallingPid())
6411 .setCallingUid(Binder.getCallingUid())
6412 .setMethod("requestNetworkScan")
6413 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6414 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6415 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6416 .build());
6417 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006418 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006419 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6420 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006421 if (e != null) {
6422 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6423 throw e;
6424 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006425 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006426 return TelephonyScanManager.INVALID_SCAN_ID;
6427 }
6428 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006429 }
Hall Liu912dfd32019-04-25 14:02:26 -07006430 int callingUid = Binder.getCallingUid();
6431 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006432 final long identity = Binder.clearCallingIdentity();
6433 try {
6434 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006435 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006436 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006437 } finally {
6438 Binder.restoreCallingIdentity(identity);
6439 }
yinxu504e1392017-04-12 16:03:22 -07006440 }
6441
Hall Liub2ac8ef2019-02-28 15:56:23 -08006442 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006443 NetworkScanRequest request, int subId, String callingPackage) {
6444 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006445 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6446 boolean hasNetworkScanPermission =
6447 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6448 == PERMISSION_GRANTED;
6449
6450 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6451 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6452 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006453 }
6454
6455 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6456 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006457 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6458 return new SecurityException("Specific channels must not be"
6459 + " scanned without location access.");
6460 }
6461 }
6462 }
6463
Hall Liub2ac8ef2019-02-28 15:56:23 -08006464 return null;
6465 }
6466
yinxu504e1392017-04-12 16:03:22 -07006467 /**
6468 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006469 *
6470 * @param subId id of the subscription
6471 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006472 */
6473 @Override
6474 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006475 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6476 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006477
Hall Liu912dfd32019-04-25 14:02:26 -07006478 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006479 final long identity = Binder.clearCallingIdentity();
6480 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006481 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006482 } finally {
6483 Binder.restoreCallingIdentity(identity);
6484 }
yinxu504e1392017-04-12 16:03:22 -07006485 }
6486
6487 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006488 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006489 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006490 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006491 */
6492 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006493 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006494 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006495 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006496 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006497
6498 final long identity = Binder.clearCallingIdentity();
6499 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006500 if (DBG) log("getAllowedNetworkTypesBitmask");
6501 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6502 int networkTypesBitmask = (result != null ? result[0] : -1);
6503 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6504 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006505 } finally {
6506 Binder.restoreCallingIdentity(identity);
6507 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006508 }
6509
6510 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006511 * Get the allowed network types for certain reason.
6512 *
6513 * @param subId the id of the subscription.
6514 * @param reason the reason the allowed network type change is taking place
6515 * @return the allowed network types.
6516 */
6517 @Override
6518 public long getAllowedNetworkTypesForReason(int subId,
6519 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006520 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006521 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006522 final long identity = Binder.clearCallingIdentity();
6523 try {
6524 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6525 } finally {
6526 Binder.restoreCallingIdentity(identity);
6527 }
6528 }
6529
6530 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006531 * Enable/Disable E-UTRA-NR Dual Connectivity
6532 * @param subId subscription id of the sim card
6533 * @param nrDualConnectivityState expected NR dual connectivity state
6534 * This can be passed following states
6535 * <ol>
6536 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6537 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6538 * <li>Disable NR dual connectivity and force secondary cell to be released
6539 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6540 * </ol>
6541 * @return operation result.
6542 */
6543 @Override
6544 public int setNrDualConnectivityState(int subId,
6545 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6546 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6547 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006548 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006549 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6550 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6551 }
6552
Sooraj Sasindran37444802020-08-11 10:40:43 -07006553 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6554 final long identity = Binder.clearCallingIdentity();
6555 try {
6556 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6557 nrDualConnectivityState, subId,
6558 workSource);
6559 if (DBG) log("enableNRDualConnectivity result: " + result);
6560 return result;
6561 } finally {
6562 Binder.restoreCallingIdentity(identity);
6563 }
6564 }
6565
6566 /**
6567 * Is E-UTRA-NR Dual Connectivity enabled
6568 * @return true if dual connectivity is enabled else false
6569 */
6570 @Override
6571 public boolean isNrDualConnectivityEnabled(int subId) {
6572 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006573 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006574 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006575 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006576 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6577 return false;
6578 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006579 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6580 final long identity = Binder.clearCallingIdentity();
6581 try {
6582 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6583 null, subId, workSource);
6584 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6585 return isEnabled;
6586 } finally {
6587 Binder.restoreCallingIdentity(identity);
6588 }
6589 }
6590
6591 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006592 * Set the allowed network types of the device and
6593 * provide the reason triggering the allowed network change.
6594 *
6595 * @param subId the id of the subscription.
6596 * @param reason the reason the allowed network type change is taking place
6597 * @param allowedNetworkTypes the allowed network types.
6598 * @return true on success; false on any failure.
6599 */
6600 @Override
6601 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006602 @TelephonyManager.AllowedNetworkTypesReason int reason,
6603 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006604 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6605 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006606 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006607 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6608 return false;
6609 }
6610 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6611 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006612 return false;
6613 }
6614
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006615 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6616 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6617
6618
6619 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6620 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6621 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006622 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006623
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006624 final long identity = Binder.clearCallingIdentity();
6625 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006626 Boolean success = (Boolean) sendRequest(
6627 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6628 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6629
6630 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6631 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006632 } finally {
6633 Binder.restoreCallingIdentity(identity);
6634 }
6635 }
6636
6637 /**
Miaoa84611c2019-03-15 09:21:10 +08006638 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006639 *
Miaoa84611c2019-03-15 09:21:10 +08006640 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006641 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006642 * @hide
6643 */
6644 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006645 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006646 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006647 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006648 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006649 try {
Miaoa84611c2019-03-15 09:21:10 +08006650 if (phone != null) {
6651 return phone.hasMatchedTetherApnSetting();
6652 } else {
6653 return false;
6654 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006655 } finally {
6656 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006657 }
Junda Liu475951f2014-11-07 16:45:03 -08006658 }
6659
6660 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006661 * Get the user enabled state of Mobile Data.
6662 *
6663 * TODO: remove and use isUserDataEnabled.
6664 * This can't be removed now because some vendor codes
6665 * calls through ITelephony directly while they should
6666 * use TelephonyManager.
6667 *
6668 * @return true on enabled
6669 */
6670 @Override
6671 public boolean getDataEnabled(int subId) {
6672 return isUserDataEnabled(subId);
6673 }
6674
6675 /**
6676 * Get whether mobile data is enabled per user setting.
6677 *
6678 * There are other factors deciding whether mobile data is actually enabled, but they are
6679 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006680 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006681 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6682 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006683 *
6684 * @return {@code true} if data is enabled else {@code false}
6685 */
6686 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006687 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006688 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006689 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006690 try {
6691 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6692 functionName);
6693 } catch (Exception e) {
6694 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6695 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006696 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006697 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006698 mApp, subId, functionName);
6699
Robert Greenwalt646120a2014-05-23 11:54:03 -07006700 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006701
6702 final long identity = Binder.clearCallingIdentity();
6703 try {
6704 int phoneId = mSubscriptionController.getPhoneId(subId);
6705 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6706 Phone phone = PhoneFactory.getPhone(phoneId);
6707 if (phone != null) {
6708 boolean retVal = phone.isUserDataEnabled();
6709 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6710 return retVal;
6711 } else {
6712 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6713 return false;
6714 }
6715 } finally {
6716 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006717 }
6718 }
6719
6720 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006721 * Checks if the device is capable of mobile data by considering whether whether the
6722 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6723 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006724 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006725 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006726 */
6727 @Override
6728 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006729 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006730 try {
6731 try {
6732 mApp.enforceCallingOrSelfPermission(
6733 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006734 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006735 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006736 try {
6737 mApp.enforceCallingOrSelfPermission(
6738 android.Manifest.permission.READ_PHONE_STATE,
6739 functionName);
6740 } catch (Exception e2) {
6741 mApp.enforceCallingOrSelfPermission(
6742 permission.READ_BASIC_PHONE_STATE, functionName);
6743 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006744 }
6745 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006746 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006747 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006748
6749 final long identity = Binder.clearCallingIdentity();
6750 try {
6751 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006752 Phone phone = PhoneFactory.getPhone(phoneId);
6753 if (phone != null) {
Jack Yu4ad64e52021-12-03 14:23:53 -08006754 boolean retVal;
6755 if (phone.isUsingNewDataStack()) {
6756 retVal = phone.getDataNetworkController().getDataSettingsManager()
6757 .isDataEnabled();
6758 } else {
6759 retVal = phone.getDataEnabledSettings().isDataEnabled();
6760 }
6761 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006762 return retVal;
6763 } else {
6764 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6765 return false;
6766 }
6767 } finally {
6768 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006769 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006770 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006771
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006772 /**
6773 * Check if data is enabled for a specific reason
6774 * @param subId Subscription index
6775 * @param reason the reason the data enable change is taking place
6776 * @return {@code true} if the overall data is enabled; {@code false} if not.
6777 */
6778 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006779 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006780 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006781 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006782 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006783 try {
6784 mApp.enforceCallingOrSelfPermission(
6785 android.Manifest.permission.ACCESS_NETWORK_STATE,
6786 functionName);
6787 } catch (Exception e) {
6788 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6789 functionName);
6790 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006791 } catch (Exception e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006792 try {
6793 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006794 functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006795 } catch (Exception e2) {
6796 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006797 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006798 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006799 }
6800
6801
6802 final long identity = Binder.clearCallingIdentity();
6803 try {
6804 int phoneId = mSubscriptionController.getPhoneId(subId);
6805 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006806 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006807 + " reason=" + reason);
6808 }
6809 Phone phone = PhoneFactory.getPhone(phoneId);
6810 if (phone != null) {
6811 boolean retVal;
6812 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6813 retVal = phone.isUserDataEnabled();
6814 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006815 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006816 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006817 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006818 return retVal;
6819 } else {
6820 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006821 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006822 + subId + " retVal=false");
6823 }
6824 return false;
6825 }
6826 } finally {
6827 Binder.restoreCallingIdentity(identity);
6828 }
6829 }
6830
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006831 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006832 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006833 if (uid == Process.PHONE_UID) {
6834 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6835 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006836 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6837 }
6838
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006839 //load access rules from carrier configs, and check those as well: b/139133814
6840 SubscriptionController subController = SubscriptionController.getInstance();
6841 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6842 || subController == null) return privilegeFromSim;
6843
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006844 PackageManager pkgMgr = phone.getContext().getPackageManager();
6845 String[] packages = pkgMgr.getPackagesForUid(uid);
6846
6847 final long identity = Binder.clearCallingIdentity();
6848 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006849 int subId = phone.getSubId();
6850 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6851 // A test override is in place for the privileges for this subId, so don't try to
6852 // read the subscription privileges.
6853 return privilegeFromSim;
6854 }
6855 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006856 SubscriptionManager subManager = (SubscriptionManager)
6857 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6858 for (String pkg : packages) {
6859 if (subManager.canManageSubscription(subInfo, pkg)) {
6860 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6861 }
6862 }
6863 return privilegeFromSim;
6864 } finally {
6865 Binder.restoreCallingIdentity(identity);
6866 }
6867 }
6868
6869 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6870 String pkgName) {
6871 //load access rules from carrier configs, and check those as well: b/139133814
6872 SubscriptionController subController = SubscriptionController.getInstance();
6873 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6874 || subController == null) return privilegeFromSim;
6875
6876 final long identity = Binder.clearCallingIdentity();
6877 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006878 int subId = phone.getSubId();
6879 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6880 // A test override is in place for the privileges for this subId, so don't try to
6881 // read the subscription privileges.
6882 return privilegeFromSim;
6883 }
6884 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006885 SubscriptionManager subManager = (SubscriptionManager)
6886 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6887 return subManager.canManageSubscription(subInfo, pkgName)
6888 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6889 } finally {
6890 Binder.restoreCallingIdentity(identity);
6891 }
6892 }
6893
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006894 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006895 public int getCarrierPrivilegeStatus(int subId) {
6896 final Phone phone = getPhone(subId);
6897 if (phone == null) {
6898 loge("getCarrierPrivilegeStatus: Invalid subId");
6899 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6900 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006901 UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId());
6902 if (port == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006903 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006904 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6905 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006906
6907 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006908 port.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006909 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006910 }
Junda Liu29340342014-07-10 15:23:27 -07006911
6912 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006913 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006914 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006915 final Phone phone = getPhone(subId);
6916 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006917 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006918 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6919 }
6920 UiccProfile profile =
6921 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6922 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006923 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006924 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6925 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006926 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006927 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006928 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006929 }
6930
6931 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006932 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006933 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006934 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006935 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006936 }
6937
6938 int phoneId = SubscriptionManager.getPhoneId(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006939 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6940 if (port == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006941 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006942 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6943 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006944 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006945 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006946 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006947 }
6948
6949 @Override
6950 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006951 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006952 if (TextUtils.isEmpty(pkgName))
6953 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006954 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6955 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006956 UiccPort port = UiccController.getInstance().getUiccPort(i);
6957 if (port == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006958 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006959 continue;
6960 }
6961
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006962 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006963 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006964 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006965 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6966 break;
6967 }
6968 }
6969
6970 return result;
Junda Liu29340342014-07-10 15:23:27 -07006971 }
Derek Tan89e89d42014-07-08 17:00:10 -07006972
6973 @Override
Junda Liue64de782015-04-16 17:19:16 -07006974 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006975 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006976 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6977 loge("phoneId " + phoneId + " is not valid.");
6978 return null;
6979 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006980 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6981 if (port == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006982 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006983 return null ;
6984 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006985 return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006986 }
6987
Amith Yamasani6e118872016-02-19 12:53:51 -08006988 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006989 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006990 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006991 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006992 List<String> privilegedPackages = new ArrayList<>();
6993 List<PackageInfo> packages = null;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006994 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
chen xuf7e9fe82019-05-09 19:31:02 -07006995 // has UICC in that slot.
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006996 if (port != null) {
6997 if (port.hasCarrierPrivilegeRules()) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006998 if (packages == null) {
6999 // Only check packages in user 0 for now
7000 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07007001 PackageManager.MATCH_DISABLED_COMPONENTS
7002 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09007003 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08007004 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08007005 }
7006 for (int p = packages.size() - 1; p >= 0; p--) {
7007 PackageInfo pkgInfo = packages.get(p);
7008 if (pkgInfo != null && pkgInfo.packageName != null
Sooraj Sasindran97bce6f2021-09-28 21:37:29 +00007009 && getCarrierPrivilegeStatusFromCarrierConfigRules(
7010 port.getCarrierPrivilegeStatus(pkgInfo),
7011 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07007012 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08007013 privilegedPackages.add(pkgInfo.packageName);
7014 }
7015 }
7016 }
7017 }
7018 return privilegedPackages;
7019 }
7020
chen xuf7e9fe82019-05-09 19:31:02 -07007021 @Override
7022 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007023 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
7024
7025 final long identity = Binder.clearCallingIdentity();
7026
chen xuf7e9fe82019-05-09 19:31:02 -07007027 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007028 try {
7029 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7030 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7031 }
7032 } finally {
7033 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007034 }
7035 return privilegedPackages;
7036 }
7037
Wink Savilleb564aae2014-10-23 10:18:09 -07007038 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007039 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007040 UiccPort port = phone == null ? null : phone.getUiccPort();
7041 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007042 return null;
7043 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007044 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007045 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007046 return null;
7047 }
7048 return iccId;
7049 }
7050
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007051 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007052 public void setCallComposerStatus(int subId, int status) {
7053 enforceModifyPermission();
7054
7055 final long identity = Binder.clearCallingIdentity();
7056 try {
7057 Phone phone = getPhone(subId);
7058 if (phone != null) {
7059 Phone defaultPhone = phone.getImsPhone();
7060 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7061 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7062 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007063 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7064 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007065 }
7066 }
Shuo Qian284ae752020-12-22 19:10:14 -08007067 } catch (ImsException e) {
7068 throw new ServiceSpecificException(e.getCode());
7069 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007070 Binder.restoreCallingIdentity(identity);
7071 }
7072 }
7073
7074 @Override
7075 public int getCallComposerStatus(int subId) {
7076 enforceReadPrivilegedPermission("getCallComposerStatus");
7077
7078 final long identity = Binder.clearCallingIdentity();
7079 try {
7080 Phone phone = getPhone(subId);
7081 if (phone != null) {
7082 Phone defaultPhone = phone.getImsPhone();
7083 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7084 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7085 return imsPhone.getCallComposerStatus();
7086 }
7087 }
7088 } finally {
7089 Binder.restoreCallingIdentity(identity);
7090 }
7091 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7092 }
7093
7094 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007095 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7096 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007097 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007098 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007099
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007100 final long identity = Binder.clearCallingIdentity();
7101 try {
7102 final String iccId = getIccId(subId);
7103 final Phone phone = getPhone(subId);
7104 if (phone == null) {
7105 return false;
7106 }
7107 final String subscriberId = phone.getSubscriberId();
7108
7109 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007110 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007111 + subscriberId + " to " + number);
7112 }
7113
7114 if (TextUtils.isEmpty(iccId)) {
7115 return false;
7116 }
7117
7118 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7119
7120 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7121 if (alphaTag == null) {
7122 editor.remove(alphaTagPrefKey);
7123 } else {
7124 editor.putString(alphaTagPrefKey, alphaTag);
7125 }
7126
7127 // Record both the line number and IMSI for this ICCID, since we need to
7128 // track all merged IMSIs based on line number
7129 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7130 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7131 if (number == null) {
7132 editor.remove(numberPrefKey);
7133 editor.remove(subscriberPrefKey);
7134 } else {
7135 editor.putString(numberPrefKey, number);
7136 editor.putString(subscriberPrefKey, subscriberId);
7137 }
7138
7139 editor.commit();
7140 return true;
7141 } finally {
7142 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007143 }
Derek Tan7226c842014-07-02 17:42:23 -07007144 }
7145
7146 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007147 public String getLine1NumberForDisplay(int subId, String callingPackage,
7148 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007149 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007150 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007151 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007152 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007153 return null;
7154 }
Derek Tan97ebb422014-09-05 16:55:38 -07007155
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007156 final long identity = Binder.clearCallingIdentity();
7157 try {
7158 String iccId = getIccId(subId);
7159 if (iccId != null) {
7160 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7161 if (DBG_MERGE) {
7162 log("getLine1NumberForDisplay returning "
7163 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7164 }
7165 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007166 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007167 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7168 return null;
7169 } finally {
7170 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007171 }
Derek Tan7226c842014-07-02 17:42:23 -07007172 }
7173
7174 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007175 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7176 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007177 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007178 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007179 return null;
7180 }
Derek Tan97ebb422014-09-05 16:55:38 -07007181
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007182 final long identity = Binder.clearCallingIdentity();
7183 try {
7184 String iccId = getIccId(subId);
7185 if (iccId != null) {
7186 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7187 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7188 }
7189 return null;
7190 } finally {
7191 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007192 }
Derek Tan7226c842014-07-02 17:42:23 -07007193 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007194
7195 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007196 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7197 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007198 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7199 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007200 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007201 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007202 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007203 return null;
7204 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007205
Jordan Liub49b04b2019-05-06 14:45:15 -07007206 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7207 // the process, where TelephonyManager was instantiated.
7208 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007209 final long identity = Binder.clearCallingIdentity();
7210 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007211 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007212 final TelephonyManager tele = TelephonyManager.from(context);
7213 final SubscriptionManager sub = SubscriptionManager.from(context);
7214
7215 // Figure out what subscribers are currently active
7216 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007217
Jordan Liub49b04b2019-05-06 14:45:15 -07007218 // Only consider subs which match the current subId
7219 // This logic can be simplified. See b/131189269 for progress.
7220 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007221 activeSubscriberIds.add(tele.getSubscriberId(subId));
7222 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007223
7224 // First pass, find a number override for an active subscriber
7225 String mergeNumber = null;
7226 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7227 for (String key : prefs.keySet()) {
7228 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7229 final String subscriberId = (String) prefs.get(key);
7230 if (activeSubscriberIds.contains(subscriberId)) {
7231 final String iccId = key.substring(
7232 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7233 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7234 mergeNumber = (String) prefs.get(numberKey);
7235 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007236 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007237 + " for active subscriber " + subscriberId);
7238 }
7239 if (!TextUtils.isEmpty(mergeNumber)) {
7240 break;
7241 }
7242 }
7243 }
7244 }
7245
7246 // Shortcut when no active merged subscribers
7247 if (TextUtils.isEmpty(mergeNumber)) {
7248 return null;
7249 }
7250
7251 // Second pass, find all subscribers under that line override
7252 final ArraySet<String> result = new ArraySet<>();
7253 for (String key : prefs.keySet()) {
7254 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7255 final String number = (String) prefs.get(key);
7256 if (mergeNumber.equals(number)) {
7257 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7258 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7259 final String subscriberId = (String) prefs.get(subscriberKey);
7260 if (!TextUtils.isEmpty(subscriberId)) {
7261 result.add(subscriberId);
7262 }
7263 }
7264 }
7265 }
7266
7267 final String[] resultArray = result.toArray(new String[result.size()]);
7268 Arrays.sort(resultArray);
7269 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007270 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007271 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7272 }
7273 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007274 } finally {
7275 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007276 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007277 }
7278
7279 @Override
zoey chen38003472019-12-13 17:16:31 +08007280 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7281 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007282
7283 final long identity = Binder.clearCallingIdentity();
7284 try {
7285 final TelephonyManager telephonyManager = mApp.getSystemService(
7286 TelephonyManager.class);
7287 String subscriberId = telephonyManager.getSubscriberId(subId);
7288 if (subscriberId == null) {
7289 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007290 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007291 + subId);
7292 }
7293 return null;
7294 }
7295
7296 final SubscriptionInfo info = SubscriptionController.getInstance()
7297 .getSubscriptionInfo(subId);
7298 final ParcelUuid groupUuid = info.getGroupUuid();
7299 // If it doesn't belong to any group, return just subscriberId of itself.
7300 if (groupUuid == null) {
7301 return new String[]{subscriberId};
7302 }
7303
7304 // Get all subscriberIds from the group.
7305 final List<String> mergedSubscriberIds = new ArrayList<>();
7306 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007307 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007308 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007309 for (SubscriptionInfo subInfo : groupInfos) {
7310 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7311 if (subscriberId != null) {
7312 mergedSubscriberIds.add(subscriberId);
7313 }
7314 }
7315
7316 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7317 } finally {
7318 Binder.restoreCallingIdentity(identity);
7319
7320 }
7321 }
7322
7323 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007324 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007325 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007326 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007327
7328 final long identity = Binder.clearCallingIdentity();
7329 try {
7330 final Phone phone = getPhone(subId);
7331 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7332 } finally {
7333 Binder.restoreCallingIdentity(identity);
7334 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007335 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007336
7337 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007338 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007339 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7340 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007341 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7342 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007343
7344 final long identity = Binder.clearCallingIdentity();
7345 try {
7346 final Phone phone = getPhone(subId);
7347 if (phone == null) {
7348 return false;
7349 }
7350 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7351 cdmaNonRoamingList);
7352 } finally {
7353 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007354 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007355 }
7356
7357 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007358 @Deprecated
7359 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7360 enforceModifyPermission();
7361
7362 int returnValue = 0;
7363 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007364 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007365 if(result.exception == null) {
7366 if (result.result != null) {
7367 byte[] responseData = (byte[])(result.result);
7368 if(responseData.length > oemResp.length) {
7369 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7370 responseData.length + "bytes. Buffer Size is " +
7371 oemResp.length + "bytes.");
7372 }
7373 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7374 returnValue = responseData.length;
7375 }
7376 } else {
7377 CommandException ex = (CommandException) result.exception;
7378 returnValue = ex.getCommandError().ordinal();
7379 if(returnValue > 0) returnValue *= -1;
7380 }
7381 } catch (RuntimeException e) {
7382 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7383 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7384 if(returnValue > 0) returnValue *= -1;
7385 }
7386
7387 return returnValue;
7388 }
7389
7390 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007391 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007392 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007393 try {
7394 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007395 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007396 mApp, phone.getSubId(), "getRadioAccessFamily");
7397 } catch (SecurityException e) {
7398 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7399 throw e;
7400 }
chen xub97461a2018-10-26 14:17:57 -07007401 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007402 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007403 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007404 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007405 final long identity = Binder.clearCallingIdentity();
7406 try {
chen xub97461a2018-10-26 14:17:57 -07007407 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007408 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007409 mApp, phone.getSubId(), "getRadioAccessFamily");
7410 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007411 } finally {
7412 Binder.restoreCallingIdentity(identity);
7413 }
chen xub97461a2018-10-26 14:17:57 -07007414 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007415 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007416
7417 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007418 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007419 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007420 try {
7421 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7422 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007423 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007424 }
7425 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007426 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007427 }
7428 RoleManager rm = mApp.getSystemService(RoleManager.class);
7429 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7430 if (!dialerRoleHolders.contains(callingPackage)) {
7431 throw new SecurityException("App must be the dialer role holder to"
7432 + " upload a call composer pic");
7433 }
7434
7435 Executors.newSingleThreadExecutor().execute(() -> {
7436 ByteArrayOutputStream output = new ByteArrayOutputStream(
7437 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7438 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7439 boolean readUntilEnd = false;
7440 int totalBytesRead = 0;
7441 byte[] buffer = new byte[16 * 1024];
7442 while (true) {
7443 int numRead;
7444 try {
7445 numRead = input.read(buffer);
7446 } catch (IOException e) {
7447 try {
7448 fd.checkError();
7449 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7450 null);
7451 } catch (IOException e1) {
7452 // This means that the other side closed explicitly with an error. If this
7453 // happens, log and ignore.
7454 loge("Remote end of call composer picture pipe closed: " + e1);
7455 }
7456 break;
7457 }
7458 if (numRead == -1) {
7459 readUntilEnd = true;
7460 break;
7461 }
7462 totalBytesRead += numRead;
7463 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7464 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7465 try {
7466 input.close();
7467 } catch (IOException e) {
7468 // ignore
7469 }
7470 break;
7471 }
7472 output.write(buffer, 0, numRead);
7473 }
7474 // Generally, the remote end will close the file descriptors. The only case where we
7475 // close is above, where the picture size is too big.
7476
7477 try {
7478 fd.checkError();
7479 } catch (IOException e) {
7480 loge("Remote end for call composer closed with an error: " + e);
7481 return;
7482 }
7483
Hall Liuaa4211e2021-01-20 15:43:39 -08007484 if (!readUntilEnd) {
7485 loge("Did not finish reading entire image; aborting");
7486 return;
7487 }
Hall Liu82694d52020-12-11 18:22:04 -08007488
Hall Liuaa4211e2021-01-20 15:43:39 -08007489 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7490 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7491 new CallComposerPictureTransfer.Factory() {},
7492 imageData,
7493 (result) -> {
7494 if (result.first != null) {
7495 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7496 Bundle outputResult = new Bundle();
7497 outputResult.putParcelable(
7498 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7499 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7500 outputResult);
7501 } else {
7502 callback.send(result.second, null);
7503 }
7504 }
7505 );
Hall Liu82694d52020-12-11 18:22:04 -08007506 });
7507 }
7508
7509 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007510 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007511 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007512 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007513
7514 final long identity = Binder.clearCallingIdentity();
7515 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007516 ImsManager.getInstance(defaultPhone.getContext(),
7517 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007518 } finally {
7519 Binder.restoreCallingIdentity(identity);
7520 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007521 }
7522
7523 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007524 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007525 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007526 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7527 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007528 return false;
7529 }
Svet Ganovb320e182015-04-16 12:30:10 -07007530
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007531 final long identity = Binder.clearCallingIdentity();
7532 try {
7533 // Check the user preference and the system-level IMS setting. Even if the user has
7534 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7535 // In the long run, we may instead need to check if there exists a connection service
7536 // which can support video calling.
7537 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007538 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007539 return imsManager.isVtEnabledByPlatform()
7540 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7541 && imsManager.isVtEnabledByUser();
7542 } finally {
7543 Binder.restoreCallingIdentity(identity);
7544 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007545 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007546
Andrew Leea1239f22015-03-02 17:44:07 -08007547 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007548 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7549 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007550 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007551 mApp, subId, callingPackage, callingFeatureId,
7552 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007553 return false;
7554 }
7555
7556 final long identity = Binder.clearCallingIdentity();
7557 try {
7558 CarrierConfigManager configManager =
7559 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007560 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007561 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7562 } finally {
7563 Binder.restoreCallingIdentity(identity);
7564 }
Andrew Leea1239f22015-03-02 17:44:07 -08007565 }
7566
7567 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007568 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007569 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007570 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007571 return false;
7572 }
7573
7574 final long identity = Binder.clearCallingIdentity();
7575 try {
7576 CarrierConfigManager configManager =
7577 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007578 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007579 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7580 } finally {
7581 Binder.restoreCallingIdentity(identity);
7582 }
Andrew Leea1239f22015-03-02 17:44:07 -08007583 }
7584
Andrew Lee9431b832015-03-09 18:46:45 -07007585 @Override
7586 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007587 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007588 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007589 }
7590
7591 @Override
7592 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007593 final long identity = Binder.clearCallingIdentity();
7594 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007595 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007596 } finally {
7597 Binder.restoreCallingIdentity(identity);
7598 }
Andrew Lee9431b832015-03-09 18:46:45 -07007599 }
7600
Hall Liuf6668912018-10-31 17:05:23 -07007601 /**
7602 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7603 * support for the feature and device firmware support.
7604 *
7605 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7606 */
7607 @Override
7608 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007609 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007610 final Phone phone = getPhone(subscriptionId);
7611 if (phone == null) {
7612 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7613 return false;
7614 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007615 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007616 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007617 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7618 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007619 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007620 return isCarrierSupported && isDeviceSupported;
7621 } finally {
7622 Binder.restoreCallingIdentity(identity);
7623 }
Hall Liu98187582018-01-22 19:15:32 -08007624 }
7625
Hall Liuf6668912018-10-31 17:05:23 -07007626 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007627 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7628 * RTT setting, will return true if the device and carrier both support RTT.
7629 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007630 */
7631 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007632 final long identity = Binder.clearCallingIdentity();
7633 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007634 boolean isRttSupported = isRttSupported(subscriptionId);
7635 boolean isUserRttSettingOn = Settings.Secure.getInt(
7636 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7637 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7638 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7639 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007640 } finally {
7641 Binder.restoreCallingIdentity(identity);
7642 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007643 }
7644
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007645 @Deprecated
7646 @Override
7647 public String getDeviceId(String callingPackage) {
7648 return getDeviceIdWithFeature(callingPackage, null);
7649 }
7650
Sanket Padawe7310cc72015-01-14 09:53:20 -08007651 /**
7652 * Returns the unique device ID of phone, for example, the IMEI for
7653 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7654 *
7655 * <p>Requires Permission:
7656 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7657 */
7658 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007659 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007660 try {
7661 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7662 } catch (SecurityException se) {
7663 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7664 throw new SecurityException("Package " + callingPackage + " does not belong to "
7665 + Binder.getCallingUid());
7666 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007667 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007668 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007669 return null;
7670 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007671 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007672 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007673 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007674 return null;
7675 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007676
7677 final long identity = Binder.clearCallingIdentity();
7678 try {
7679 return phone.getDeviceId();
7680 } finally {
7681 Binder.restoreCallingIdentity(identity);
7682 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007683 }
7684
Ping Sunc67b7c22016-03-02 19:16:45 +08007685 /**
7686 * {@hide}
7687 * Returns the IMS Registration Status on a particular subid
7688 *
7689 * @param subId
7690 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007691 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007692 Phone phone = getPhone(subId);
7693 if (phone != null) {
7694 return phone.isImsRegistered();
7695 } else {
7696 return false;
7697 }
7698 }
7699
Santos Cordon7a1885b2015-02-03 11:15:19 -08007700 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007701 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007702 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007703 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007704 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007705 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7706 }
7707 final long identity = Binder.clearCallingIdentity();
7708 try {
7709 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7710 } finally {
7711 Binder.restoreCallingIdentity(identity);
7712 }
7713 }
7714
7715 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007716 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007717 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007718 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007719 mApp,
7720 subscriptionId,
7721 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007722 final long identity = Binder.clearCallingIdentity();
7723 try {
7724 Phone phone = getPhone(subscriptionId);
7725 if (phone == null) {
7726 return null;
7727 }
7728 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7729 } finally {
7730 Binder.restoreCallingIdentity(identity);
7731 }
7732 }
7733
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007734 /**
7735 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007736 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007737 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007738 final long identity = Binder.clearCallingIdentity();
7739 try {
7740 Phone phone = getPhone(subId);
7741 if (phone != null) {
7742 return phone.isWifiCallingEnabled();
7743 } else {
7744 return false;
7745 }
7746 } finally {
7747 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007748 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007749 }
7750
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007751 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007752 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007753 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007754 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007755 final long identity = Binder.clearCallingIdentity();
7756 try {
7757 Phone phone = getPhone(subId);
7758 if (phone != null) {
7759 return phone.isVideoEnabled();
7760 } else {
7761 return false;
7762 }
7763 } finally {
7764 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007765 }
7766 }
7767
7768 /**
7769 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7770 * defined in {@link ImsRegistrationImplBase}.
7771 */
7772 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007773 final long identity = Binder.clearCallingIdentity();
7774 try {
7775 Phone phone = getPhone(subId);
7776 if (phone != null) {
7777 return phone.getImsRegistrationTech();
7778 } else {
7779 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7780 }
7781 } finally {
7782 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007783 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007784 }
7785
Stuart Scott8eef64f2015-04-08 15:13:54 -07007786 @Override
7787 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007788 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007789 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7790 return;
7791 }
Kai Shif70f46f2021-03-03 13:59:46 -08007792 Phone defaultPhone = getDefaultPhone();
7793 if (defaultPhone != null) {
7794 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7795 mApp, getDefaultPhone().getSubId(), "factoryReset");
7796 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007797 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007798
Svet Ganovcc087f82015-05-12 20:35:54 -07007799 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007800 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7801 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007802 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007803 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007804 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007805 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007806 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007807 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007808 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007809 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007810 // There has been issues when Sms raw table somehow stores orphan
7811 // fragments. They lead to garbled message when new fragments come
7812 // in and combined with those stale ones. In case this happens again,
7813 // user can reset all network settings which will clean up this table.
7814 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007815 // Clean up IMS settings as well here.
7816 int slotId = getSlotIndex(subId);
7817 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7818 ImsManager.getInstance(mApp, slotId).factoryReset();
7819 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007820
Kai Shif70f46f2021-03-03 13:59:46 -08007821 if (defaultPhone == null) {
7822 return;
7823 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007824 // Erase modem config if erase modem on network setting is enabled.
7825 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7826 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7827 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007828 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007829 }
Kai Shif70f46f2021-03-03 13:59:46 -08007830
7831 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007832 } finally {
7833 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007834 }
7835 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007836
SongFerngWangfd89b102021-05-27 22:44:54 +08007837 @VisibleForTesting
7838 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7839 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7840 return;
7841 }
7842 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7843 RILConstants.PREFERRED_NETWORK_MODE);
7844 SubscriptionManager.setSubscriptionProperty(subId,
7845 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7846 "user=" + defaultNetworkType);
7847 phone.loadAllowedNetworksFromSubscriptionDatabase();
7848 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7849 defaultNetworkType, null);
7850 }
7851
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007852 private void cleanUpSmsRawTable(Context context) {
7853 ContentResolver resolver = context.getContentResolver();
7854 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7855 resolver.delete(uri, null, null);
7856 }
7857
Narayan Kamath1c496c22015-04-16 14:40:19 +01007858 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007859 public String getSimLocaleForSubscriber(int subId) {
7860 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7861 final Phone phone = getPhone(subId);
7862 if (phone == null) {
7863 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007864 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007865 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007866 final long identity = Binder.clearCallingIdentity();
7867 try {
chen xu5d3637b2019-01-21 23:31:38 -08007868 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007869 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007870 if (info == null) {
7871 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7872 return null;
7873 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007874 // Try and fetch the locale from the carrier properties or from the SIM language
7875 // preferences (EF-PL and EF-LI)...
7876 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007877 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007878 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7879 if (localeFromDefaultSim != null) {
7880 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7881 if (DBG) log("Using locale from subId: " + subId + " locale: "
7882 + localeFromDefaultSim);
7883 return localeFromDefaultSim.toLanguageTag();
7884 } else {
7885 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007886 }
7887 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007888
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007889 // The SIM language preferences only store a language (e.g. fr = French), not an
7890 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7891 // the SIM and carrier preferences does not include a country we add the country
7892 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007893 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007894 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007895 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007896 return mccLocale.toLanguageTag();
7897 }
7898
7899 if (DBG) log("No locale found - returning null");
7900 return null;
7901 } finally {
7902 Binder.restoreCallingIdentity(identity);
7903 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007904 }
7905
7906 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007907 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007908 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007909 }
7910
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007911 /**
7912 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7913 */
7914 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007915 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007916 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007917 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007918
Chenjie Yu1ba97252018-01-11 18:16:20 -08007919 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007920 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007921
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007922 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007923 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7924 * representing the state of the modem.
7925 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007926 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7927 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007928 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007929 */
7930 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007931 public void requestModemActivityInfo(ResultReceiver result) {
7932 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007933 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007934
7935 final long identity = Binder.clearCallingIdentity();
7936 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007937 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007938 } finally {
7939 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007940 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007941 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007942
Siddharth Rayb8114062018-06-17 15:02:38 -07007943 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7944 // less than total activity duration.
7945 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7946 if (info == null) {
7947 return false;
7948 }
7949 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007950 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7951 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7952
Siddharth Rayb8114062018-06-17 15:02:38 -07007953 return (info.isValid()
7954 && (info.getSleepTimeMillis() <= activityDurationMs)
7955 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007956 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007957 && (totalTxTimeMs <= activityDurationMs));
7958 }
7959
Jack Yu85bd38a2015-11-09 11:34:32 -08007960 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007961 * Returns the service state information on specified subscription.
7962 */
7963 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007964 public ServiceState getServiceStateForSubscriber(int subId,
7965 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7966 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007967 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007968 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007969 return null;
7970 }
7971
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007972 boolean hasFinePermission = false;
7973 boolean hasCoarsePermission = false;
7974 if (!renounceFineLocationAccess) {
7975 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7976 LocationAccessPolicy.checkLocationPermission(mApp,
7977 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7978 .setCallingPackage(callingPackage)
7979 .setCallingFeatureId(callingFeatureId)
7980 .setCallingPid(Binder.getCallingPid())
7981 .setCallingUid(Binder.getCallingUid())
7982 .setMethod("getServiceStateForSubscriber")
7983 .setLogAsInfo(true)
7984 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7985 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7986 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7987 .build());
7988 hasFinePermission =
7989 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7990 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007991
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007992 if (!renounceCoarseLocationAccess) {
7993 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7994 LocationAccessPolicy.checkLocationPermission(mApp,
7995 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7996 .setCallingPackage(callingPackage)
7997 .setCallingFeatureId(callingFeatureId)
7998 .setCallingPid(Binder.getCallingPid())
7999 .setCallingUid(Binder.getCallingUid())
8000 .setMethod("getServiceStateForSubscriber")
8001 .setLogAsInfo(true)
8002 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8003 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8004 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8005 .build());
8006 hasCoarsePermission =
8007 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8008 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008009
Jack Yu479f40e2020-10-27 21:29:25 -07008010 final Phone phone = getPhone(subId);
8011 if (phone == null) {
8012 return null;
8013 }
8014
Jordan Liu0f2bc442020-11-18 16:47:37 -08008015 final long identity = Binder.clearCallingIdentity();
8016
Jack Yu479f40e2020-10-27 21:29:25 -07008017 boolean isCallingPackageDataService = phone.getDataServicePackages()
8018 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008019 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008020 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
8021 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
8022 Rlog.d(LOG_TAG,
8023 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
8024 return null;
8025 }
8026
Hall Liuf19c44f2018-11-27 14:38:17 -08008027 ServiceState ss = phone.getServiceState();
8028
8029 // Scrub out the location info in ServiceState depending on what level of access
8030 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008031 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008032 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8033 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008034 } finally {
8035 Binder.restoreCallingIdentity(identity);
8036 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008037 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008038
8039 /**
8040 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8041 *
8042 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8043 * voicemail ringtone.
8044 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8045 * PhoneAccount.
8046 */
8047 @Override
8048 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008049 final long identity = Binder.clearCallingIdentity();
8050 try {
8051 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8052 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008053 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008054 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008055
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008056 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8057 } finally {
8058 Binder.restoreCallingIdentity(identity);
8059 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008060 }
8061
8062 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008063 * Sets the per-account voicemail ringtone.
8064 *
8065 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8066 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8067 *
8068 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8069 * voicemail ringtone.
8070 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8071 * PhoneAccount.
8072 */
8073 @Override
8074 public void setVoicemailRingtoneUri(String callingPackage,
8075 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008076 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008077 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008078 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8079 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008080 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8081 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8082 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008083 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008084
8085 final long identity = Binder.clearCallingIdentity();
8086 try {
8087 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8088 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008089 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008090 }
8091 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8092 } finally {
8093 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008094 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008095 }
8096
8097 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008098 * Returns whether vibration is set for voicemail notification in Phone settings.
8099 *
8100 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8101 * voicemail vibration setting.
8102 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8103 */
8104 @Override
8105 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008106 final long identity = Binder.clearCallingIdentity();
8107 try {
8108 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8109 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008110 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008111 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008112
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008113 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8114 } finally {
8115 Binder.restoreCallingIdentity(identity);
8116 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008117 }
8118
Youhan Wange64578a2016-05-02 15:32:42 -07008119 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008120 * Sets the per-account voicemail vibration.
8121 *
8122 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8123 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8124 *
8125 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8126 * voicemail vibration setting.
8127 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8128 * specific PhoneAccount.
8129 */
8130 @Override
8131 public void setVoicemailVibrationEnabled(String callingPackage,
8132 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008133 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008134 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008135 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8136 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008137 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8138 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8139 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008140 }
8141
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008142 final long identity = Binder.clearCallingIdentity();
8143 try {
8144 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8145 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008146 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008147 }
8148 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8149 } finally {
8150 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008151 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008152 }
8153
8154 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008155 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8156 *
8157 * @throws SecurityException if the caller does not have the required permission
8158 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008159 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008160 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008161 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008162 }
8163
8164 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008165 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8166 * permission.
8167 *
8168 * @throws SecurityException if the caller does not have the required permission
8169 */
8170 private void enforceSendSmsPermission() {
8171 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8172 }
8173
8174 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008175 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008176 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008177 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008178 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008179 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008180 final long identity = Binder.clearCallingIdentity();
8181 try {
8182 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008183 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008184 if (componentName == null) {
8185 throw new SecurityException(
8186 "Caller not current active visual voicemail package[null]");
8187 }
8188 String vvmPackage = componentName.getPackageName();
8189 if (!callingPackage.equals(vvmPackage)) {
8190 throw new SecurityException("Caller not current active visual voicemail package["
8191 + vvmPackage + "]");
8192 }
8193 } finally {
8194 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008195 }
8196 }
8197
8198 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008199 * Return the application ID for the app type.
8200 *
8201 * @param subId the subscription ID that this request applies to.
8202 * @param appType the uicc app type.
8203 * @return Application ID for specificied app type, or null if no uicc.
8204 */
8205 @Override
8206 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008207 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008208 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008209
8210 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008211 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008212 if (phone == null) {
8213 return null;
8214 }
8215 String aid = null;
8216 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008217 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008218 .getApplicationByType(appType).getAid();
8219 } catch (Exception e) {
8220 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8221 }
8222 return aid;
8223 } finally {
8224 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008225 }
Youhan Wange64578a2016-05-02 15:32:42 -07008226 }
8227
Youhan Wang4001d252016-05-11 10:29:41 -07008228 /**
8229 * Return the Electronic Serial Number.
8230 *
8231 * @param subId the subscription ID that this request applies to.
8232 * @return ESN or null if error.
8233 */
8234 @Override
8235 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008236 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008237 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008238
8239 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008240 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008241 if (phone == null) {
8242 return null;
8243 }
8244 String esn = null;
8245 try {
8246 esn = phone.getEsn();
8247 } catch (Exception e) {
8248 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8249 }
8250 return esn;
8251 } finally {
8252 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008253 }
Youhan Wang4001d252016-05-11 10:29:41 -07008254 }
8255
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008256 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008257 * Return the Preferred Roaming List Version.
8258 *
8259 * @param subId the subscription ID that this request applies to.
8260 * @return PRLVersion or null if error.
8261 */
8262 @Override
8263 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008264 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008265 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008266
8267 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008268 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008269 if (phone == null) {
8270 return null;
8271 }
8272 String cdmaPrlVersion = null;
8273 try {
8274 cdmaPrlVersion = phone.getCdmaPrlVersion();
8275 } catch (Exception e) {
8276 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8277 }
8278 return cdmaPrlVersion;
8279 } finally {
8280 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008281 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008282 }
8283
8284 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008285 * Get snapshot of Telephony histograms
8286 * @return List of Telephony histograms
8287 * @hide
8288 */
8289 @Override
8290 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008291 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8292 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008293
8294 final long identity = Binder.clearCallingIdentity();
8295 try {
8296 return RIL.getTelephonyRILTimingHistograms();
8297 } finally {
8298 Binder.restoreCallingIdentity(identity);
8299 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008300 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008301
8302 /**
8303 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008304 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8305 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008306 * Require system privileges. In the future we may add this to carrier APIs.
8307 *
Michele Berionne482f8202018-11-27 18:57:59 -08008308 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008309 */
8310 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008311 @TelephonyManager.SetCarrierRestrictionResult
8312 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008313 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008314 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008315
Michele Berionne482f8202018-11-27 18:57:59 -08008316 if (carrierRestrictionRules == null) {
8317 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008318 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008319
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008320 final long identity = Binder.clearCallingIdentity();
8321 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008322 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008323 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008324 } finally {
8325 Binder.restoreCallingIdentity(identity);
8326 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008327 }
8328
8329 /**
8330 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008331 * Get the allowed carrier list and the excluded carrier list, including the priority between
8332 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008333 * Require system privileges. In the future we may add this to carrier APIs.
8334 *
Michele Berionne482f8202018-11-27 18:57:59 -08008335 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008336 */
8337 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008338 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008339 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008340 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008341
8342 final long identity = Binder.clearCallingIdentity();
8343 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008344 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8345 if (response instanceof CarrierRestrictionRules) {
8346 return (CarrierRestrictionRules) response;
8347 }
8348 // Response is an Exception of some kind,
8349 // which is signalled to the user as a NULL retval
8350 return null;
8351 } catch (Exception e) {
8352 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8353 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008354 } finally {
8355 Binder.restoreCallingIdentity(identity);
8356 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008357 }
8358
fionaxu59545b42016-05-25 15:53:37 -07008359 /**
fionaxu59545b42016-05-25 15:53:37 -07008360 * Action set from carrier signalling broadcast receivers to enable/disable radio
8361 * @param subId the subscription ID that this action applies to.
8362 * @param enabled control enable or disable radio.
8363 * {@hide}
8364 */
8365 @Override
8366 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8367 enforceModifyPermission();
8368 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008369
8370 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008371 if (phone == null) {
8372 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8373 return;
8374 }
8375 try {
8376 phone.carrierActionSetRadioEnabled(enabled);
8377 } catch (Exception e) {
8378 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008379 } finally {
8380 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008381 }
8382 }
8383
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008384 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008385 * Enable or disable Voice over NR (VoNR)
8386 * @param subId the subscription ID that this action applies to.
8387 * @param enabled enable or disable VoNR.
8388 * @return operation result.
8389 */
8390 @Override
8391 public int setVoNrEnabled(int subId, boolean enabled) {
8392 enforceModifyPermission();
8393 final Phone phone = getPhone(subId);
8394
8395 final long identity = Binder.clearCallingIdentity();
8396 if (phone == null) {
8397 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8398 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8399 }
8400
8401 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8402 try {
8403 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8404 workSource);
8405 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008406
8407 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8408 if (DBG) {
8409 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8410 }
8411 SubscriptionManager.setSubscriptionProperty(
8412 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8413 (enabled ? "1" : "0"));
8414 }
8415
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008416 return result;
8417 } finally {
8418 Binder.restoreCallingIdentity(identity);
8419 }
8420 }
8421
8422 /**
8423 * Is voice over NR enabled
8424 * @return true if VoNR is enabled else false
8425 */
8426 @Override
8427 public boolean isVoNrEnabled(int subId) {
8428 enforceReadPrivilegedPermission("isVoNrEnabled");
8429 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8430 final long identity = Binder.clearCallingIdentity();
8431 try {
8432 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8433 null, subId, workSource);
8434 if (DBG) log("isVoNrEnabled: " + isEnabled);
8435 return isEnabled;
8436 } finally {
8437 Binder.restoreCallingIdentity(identity);
8438 }
8439 }
8440
8441 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008442 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8443 * network status based on which carrier apps could apply actions accordingly,
8444 * enable/disable default url handler for example.
8445 *
8446 * @param subId the subscription ID that this action applies to.
8447 * @param report control start/stop reporting the default network status.
8448 * {@hide}
8449 */
8450 @Override
8451 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8452 enforceModifyPermission();
8453 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008454
8455 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008456 if (phone == null) {
8457 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8458 return;
8459 }
8460 try {
8461 phone.carrierActionReportDefaultNetworkStatus(report);
8462 } catch (Exception e) {
8463 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008464 } finally {
8465 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008466 }
8467 }
8468
8469 /**
fionaxud9622282017-07-17 17:51:30 -07008470 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8471 * @param subId the subscription ID that this action applies to.
8472 * {@hide}
8473 */
8474 @Override
8475 public void carrierActionResetAll(int subId) {
8476 enforceModifyPermission();
8477 final Phone phone = getPhone(subId);
8478 if (phone == null) {
8479 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8480 return;
8481 }
8482 try {
8483 phone.carrierActionResetAll();
8484 } catch (Exception e) {
8485 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8486 }
8487 }
8488
8489 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008490 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8491 * bug report is being generated.
8492 */
8493 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008494 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008495 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8496 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008497 writer.println("Permission Denial: can't dump Phone from pid="
8498 + Binder.getCallingPid()
8499 + ", uid=" + Binder.getCallingUid()
8500 + "without permission "
8501 + android.Manifest.permission.DUMP);
8502 return;
8503 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008504 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008505 }
Jack Yueb89b242016-06-22 13:27:47 -07008506
Brad Ebingerdac2f002018-04-03 15:17:52 -07008507 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008508 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8509 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8510 @NonNull String[] args) {
8511 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8512 this, in.getFileDescriptor(), out.getFileDescriptor(),
8513 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008514 }
8515
Jack Yueb89b242016-06-22 13:27:47 -07008516 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008517 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008518 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008519 * @param reason the reason the data enable change is taking place
8520 * @param enabled True if enabling the data, otherwise disabling.
8521 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008522 */
8523 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008524 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008525 boolean enabled) {
8526 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8527 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8528 try {
8529 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008530 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008531 } catch (SecurityException se) {
8532 enforceModifyPermission();
8533 }
8534 } else {
8535 enforceModifyPermission();
8536 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008537
8538 final long identity = Binder.clearCallingIdentity();
8539 try {
8540 Phone phone = getPhone(subId);
8541 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008542 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8543 phone.carrierActionSetMeteredApnsEnabled(enabled);
8544 } else {
8545 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8546 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008547 }
8548 } finally {
8549 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008550 }
8551 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008552
8553 /**
8554 * Get Client request stats
8555 * @return List of Client Request Stats
8556 * @hide
8557 */
8558 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008559 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8560 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008561 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008562 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008563 return null;
8564 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008565 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008566
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008567 final long identity = Binder.clearCallingIdentity();
8568 try {
8569 if (phone != null) {
8570 return phone.getClientRequestStats();
8571 }
8572
8573 return null;
8574 } finally {
8575 Binder.restoreCallingIdentity(identity);
8576 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008577 }
8578
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008579 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008580 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008581 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008582 }
Jack Yueb4124c2017-02-16 15:32:43 -08008583
8584 /**
Grace Chen70990072017-03-24 17:21:30 -07008585 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008586 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008587 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008588 * @param state State of SIM (power down, power up, pass through)
8589 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8590 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8591 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008592 *
8593 **/
8594 @Override
Grace Chen70990072017-03-24 17:21:30 -07008595 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008596 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008597 Phone phone = PhoneFactory.getPhone(slotIndex);
8598
vagdeviaf9a5b92018-08-15 16:01:53 -07008599 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8600
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008601 final long identity = Binder.clearCallingIdentity();
8602 try {
8603 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008604 phone.setSimPowerState(state, null, workSource);
8605 }
8606 } finally {
8607 Binder.restoreCallingIdentity(identity);
8608 }
8609 }
8610
8611 /**
8612 * Set SIM card power state.
8613 *
8614 * @param slotIndex SIM slot id.
8615 * @param state State of SIM (power down, power up, pass through)
8616 * @param callback callback to trigger after success or failure
8617 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8618 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8619 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8620 *
8621 **/
8622 @Override
8623 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8624 IIntegerConsumer callback) {
8625 enforceModifyPermission();
8626 Phone phone = PhoneFactory.getPhone(slotIndex);
8627
8628 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8629
8630 final long identity = Binder.clearCallingIdentity();
8631 try {
8632 if (phone != null) {
8633 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8634 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008635 }
8636 } finally {
8637 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008638 }
8639 }
Shuo Qiandd210312017-04-12 22:11:33 +00008640
Tyler Gunn65d45c22017-06-05 11:22:26 -07008641 private boolean isUssdApiAllowed(int subId) {
8642 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008643 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008644 if (configManager == null) {
8645 return false;
8646 }
8647 PersistableBundle pb = configManager.getConfigForSubId(subId);
8648 if (pb == null) {
8649 return false;
8650 }
8651 return pb.getBoolean(
8652 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8653 }
8654
Shuo Qiandd210312017-04-12 22:11:33 +00008655 /**
8656 * Check if phone is in emergency callback mode
8657 * @return true if phone is in emergency callback mode
8658 * @param subId sub id
8659 */
goneil9c5f4872017-12-05 14:07:56 -08008660 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008661 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008662 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008663 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008664
8665 final long identity = Binder.clearCallingIdentity();
8666 try {
8667 if (phone != null) {
8668 return phone.isInEcm();
8669 } else {
8670 return false;
8671 }
8672 } finally {
8673 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008674 }
8675 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008676
8677 /**
8678 * Get the current signal strength information for the given subscription.
8679 * Because this information is not updated when the device is in a low power state
8680 * it should not be relied-upon to be current.
8681 * @param subId Subscription index
8682 * @return the most recent cached signal strength info from the modem
8683 */
8684 @Override
8685 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008686 final long identity = Binder.clearCallingIdentity();
8687 try {
8688 Phone p = getPhone(subId);
8689 if (p == null) {
8690 return null;
8691 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008692
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008693 return p.getSignalStrength();
8694 } finally {
8695 Binder.restoreCallingIdentity(identity);
8696 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008697 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008698
Pengquan Meng77b7f132018-08-22 14:49:57 -07008699 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008700 * Get the current modem radio state for the given slot.
8701 * @param slotIndex slot index.
8702 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008703 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008704 * @return the current radio power state from the modem
8705 */
8706 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008707 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008708 Phone phone = PhoneFactory.getPhone(slotIndex);
8709 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008710 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8711 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008712 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8713 }
8714
8715 final long identity = Binder.clearCallingIdentity();
8716 try {
8717 return phone.getRadioPowerState();
8718 } finally {
8719 Binder.restoreCallingIdentity(identity);
8720 }
8721 }
8722 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8723 }
8724
8725 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008726 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8727 *
8728 * <p>Requires one of the following permissions:
8729 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008730 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008731 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8732 * privileges.
8733 *
8734 * @param subId subscription id
8735 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8736 * {@code false}.
8737 */
8738 @Override
8739 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008740 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008741 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008742 try {
8743 mApp.enforceCallingOrSelfPermission(
8744 android.Manifest.permission.ACCESS_NETWORK_STATE,
8745 functionName);
8746 } catch (Exception e) {
8747 mApp.enforceCallingOrSelfPermission(
8748 permission.READ_BASIC_PHONE_STATE, functionName);
8749 }
Shuo Qian093013d2020-08-13 15:42:55 -07008750 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008751 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008752 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008753 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008754
Pengquan Menga1bb6272018-09-06 09:59:22 -07008755 boolean isEnabled = false;
8756 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008757 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008758 Phone phone = getPhone(subId);
8759 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008760 } finally {
8761 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008762 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008763 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008764 }
8765
8766
8767 /**
8768 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8769 *
8770 * <p> Requires permission:
8771 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8772 * privileges.
8773 *
8774 * @param subId subscription id
8775 * @param isEnabled {@code true} means enable, {@code false} means disable.
8776 */
8777 @Override
8778 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008779 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8780 mApp, subId, "setDataRoamingEnabled");
8781
Pengquan Menga1bb6272018-09-06 09:59:22 -07008782 final long identity = Binder.clearCallingIdentity();
8783 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008784 Phone phone = getPhone(subId);
8785 if (phone != null) {
8786 phone.setDataRoamingEnabled(isEnabled);
8787 }
8788 } finally {
8789 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008790 }
8791 }
8792
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008793 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008794 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008795 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008796 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008797 mApp, subId, "isManualNetworkSelectionAllowed");
8798
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008799 boolean isAllowed = true;
8800 final long identity = Binder.clearCallingIdentity();
8801 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008802 Phone phone = getPhone(subId);
8803 if (phone != null) {
8804 isAllowed = phone.isCspPlmnEnabled();
8805 }
8806 } finally {
8807 Binder.restoreCallingIdentity(identity);
8808 }
8809 return isAllowed;
8810 }
8811
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008812 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8813 UiccProfile profile = port.getUiccProfile();
8814 if (profile == null ||
8815 profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8816 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8817 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008818 }
8819 return true;
8820 }
8821
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008822 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008823 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008824 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008825 mApp.getSystemService(AppOpsManager.class)
8826 .checkPackage(Binder.getCallingUid(), callingPackage);
8827
Jordan Liu1e142fc2019-04-22 15:10:43 -07008828 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008829 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008830 try {
8831 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008832 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008833 } catch (SecurityException e) {
8834 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8835 // has carrier privileges on an active UICC
8836 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8837 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008838 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008839 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008840 }
sandeepjsb6c87872021-09-27 15:34:44 +00008841 // checking compatibility, if calling app's target SDK is T and beyond.
8842 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8843 Binder.getCallingUid())) {
8844 isIccIdAccessRestricted = true;
8845 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008846 final long identity = Binder.clearCallingIdentity();
8847 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008848 UiccController uiccController = UiccController.getInstance();
8849 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008850 if (hasReadPermission) {
8851 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008852 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008853
8854 // Remove private info if the caller doesn't have access
8855 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8856 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008857 //setting the value after compatibility check
8858 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008859 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8860 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008861 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008862 if (card == null) {
8863 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008864 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008865 continue;
8866 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008867 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8868 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008869 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008870 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008871 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008872 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8873 for (UiccPortInfo portInfo : portInfos) {
8874 UiccPort port = uiccController.getUiccPortForSlot(
8875 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8876 if (port == null) {
8877 // assume no access if port is null
8878 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8879 continue;
8880 }
8881 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8882 uiccPortInfos.add(portInfo);
8883 } else {
8884 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8885 }
8886 }
8887 filteredInfos.add(new UiccCardInfo(
8888 cardInfo.isEuicc(),
8889 cardInfo.getCardId(),
8890 null,
8891 cardInfo.getPhysicalSlotIndex(),
8892 cardInfo.isRemovable(),
8893 cardInfo.isMultipleEnabledProfilesSupported(),
8894 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008895 }
8896 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008897 } finally {
8898 Binder.restoreCallingIdentity(identity);
8899 }
8900 }
8901
sandeepjsb6c87872021-09-27 15:34:44 +00008902 /**
8903 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8904 * generally private and require carrier privileges to view.
8905 *
8906 * @hide
8907 */
8908 @NonNull
8909 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8910 List<UiccPortInfo> portinfo = new ArrayList<>();
8911 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8912 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8913 }
8914 return new UiccCardInfo(
8915 cardInfo.isEuicc(),
8916 cardInfo.getCardId(),
8917 null,
8918 cardInfo.getPhysicalSlotIndex(),
8919 cardInfo.isRemovable(),
8920 cardInfo.isMultipleEnabledProfilesSupported(),
8921 portinfo
8922 );
8923 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008924
sandeepjsb6c87872021-09-27 15:34:44 +00008925 /**
8926 * @hide
8927 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8928 * These values are generally private and require carrier privileges to view.
8929 */
8930 @NonNull
8931 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8932 return new UiccPortInfo(
8933 UiccPortInfo.ICCID_REDACTED,
8934 portInfo.getPortIndex(),
8935 portInfo.getLogicalSlotIndex(),
8936 portInfo.isActive()
8937 );
8938 }
8939 @Override
8940 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008941 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00008942 mApp.getSystemService(AppOpsManager.class)
8943 .checkPackage(Binder.getCallingUid(), callingPackage);
8944
8945 boolean hasReadPermission = false;
8946 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008947
8948 try {
8949 enforceReadPrivilegedPermission("getUiccSlotsInfo");
8950 hasReadPermission = true;
8951 } catch (SecurityException e) {
8952 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8953 // has carrier privileges on an active UICC
8954 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8955 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8956 hasReadPermission = true;
8957 }
8958 }
8959
8960 // checking compatibility, if calling app's target SDK is T and beyond.
8961 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8962 Binder.getCallingUid())) {
8963 isLogicalSlotAccessRestricted = true;
8964 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008965 final long identity = Binder.clearCallingIdentity();
8966 try {
8967 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8968 if (slots == null) {
8969 Rlog.i(LOG_TAG, "slots is null.");
8970 return null;
8971 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008972 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8973 for (int i = 0; i < slots.length; i++) {
8974 UiccSlot slot = slots[i];
8975 if (slot == null) {
8976 continue;
8977 }
8978
Jordan Liu7be7e652019-05-06 18:55:02 +00008979 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008980 UiccCard card = slot.getUiccCard();
8981 if (card != null) {
8982 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008983 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008984 cardId = slot.getEid();
8985 if (TextUtils.isEmpty(cardId)) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008986 // If cardId is null, use iccId of default port as cardId. Check if has
8987 // read permission otherwise set to null.(card is null which means no
8988 // carrier permission)
8989 cardId = hasReadPermission ? slot.getIccId(
8990 TelephonyManager.DEFAULT_PORT_INDEX) : null;
Jordan Liu01bd00d2019-09-12 16:19:43 -07008991 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008992 }
8993
Jordan Liu857451f2019-05-09 16:35:35 -07008994 if (cardId != null) {
8995 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8996 // if cardId is an EID, it's all digits so this is fine
8997 cardId = IccUtils.stripTrailingFs(cardId);
8998 }
8999
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009000 int cardState = 0;
9001 switch (slot.getCardState()) {
9002 case CARDSTATE_ABSENT:
9003 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9004 break;
9005 case CARDSTATE_PRESENT:
9006 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9007 break;
9008 case CARDSTATE_ERROR:
9009 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9010 break;
9011 case CARDSTATE_RESTRICTED:
9012 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9013 break;
9014 default:
9015 break;
9016
9017 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009018 List<UiccPortInfo> portInfos = new ArrayList<>();
9019 int[] portIndexes = slot.getPortList();
9020 for (int portIdx : portIndexes) {
9021 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
9022 callingPackage, hasReadPermission));
9023 if (slot.isPortActive(portIdx)) {
9024 UiccPort port = slot.getUiccCard().getUiccPort(portIdx);
9025 portInfos.add(new UiccPortInfo(iccId, port.getPortIdx(),
9026 port.getPhoneId(), true));
9027 } else {
9028 portInfos.add(new UiccPortInfo(iccId, portIdx, -1, false));
9029 }
9030 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009031 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009032 slot.isEuicc(),
9033 cardId,
9034 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009035 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009036 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009037 //setting the value after compatibility check
9038 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009039 }
9040 return infos;
9041 } finally {
9042 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009043 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009044 }
9045
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009046 /* Returns null if doesn't have read permission or carrier privilege access. */
9047 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9048 boolean hasReadPermission) {
9049 String iccId = slot.getIccId(portIndex);
9050 if (hasReadPermission) { // if has read permission
9051 return iccId;
9052 } else {
9053 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9054 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9055 // if no read permission, checking carrier privilege access
9056 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9057 return iccId;
9058 }
9059 }
9060 }
9061 // No read permission or carrier privilege access.
9062 return UiccPortInfo.ICCID_REDACTED;
9063 }
9064
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009065 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009066 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009067 public boolean switchSlots(int[] physicalSlots) {
9068 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009069
9070 final long identity = Binder.clearCallingIdentity();
9071 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009072 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9073 for (int i = 0; i < physicalSlots.length; i++) {
9074 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9075 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9076 physicalSlots[i], i));
9077 }
9078 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009079 } finally {
9080 Binder.restoreCallingIdentity(identity);
9081 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009082 }
Jack Yu4c988042018-02-27 15:30:01 -08009083
9084 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009085 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9086 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9087 enforceModifyPermission();
9088
9089 final long identity = Binder.clearCallingIdentity();
9090 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009091 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009092 } finally {
9093 Binder.restoreCallingIdentity(identity);
9094 }
9095 }
9096
9097 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009098 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009099 final long identity = Binder.clearCallingIdentity();
9100 try {
9101 return UiccController.getInstance().getCardIdForDefaultEuicc();
9102 } finally {
9103 Binder.restoreCallingIdentity(identity);
9104 }
9105 }
9106
Pengquan Meng85728fb2018-03-12 16:31:21 -07009107 /**
goneil47ffb6e2018-04-06 15:40:58 -07009108 * A test API to reload the UICC profile.
9109 *
9110 * <p>Requires that the calling app has permission
9111 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9112 * @hide
9113 */
9114 @Override
9115 public void refreshUiccProfile(int subId) {
9116 enforceModifyPermission();
9117
9118 final long identity = Binder.clearCallingIdentity();
9119 try {
9120 Phone phone = getPhone(subId);
9121 if (phone == null) {
9122 return;
9123 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009124 UiccPort uiccPort = phone.getUiccPort();
9125 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009126 return;
9127 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009128 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009129 if (uiccProfile == null) {
9130 return;
9131 }
9132 uiccProfile.refresh();
9133 } finally {
9134 Binder.restoreCallingIdentity(identity);
9135 }
9136 }
9137
9138 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009139 * Returns false if the mobile data is disabled by default, otherwise return true.
9140 */
9141 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009142 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009143 }
9144
9145 /**
9146 * Returns true if the data roaming is enabled by default, i.e the system property
9147 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9148 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9149 */
9150 private boolean getDefaultDataRoamingEnabled(int subId) {
9151 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009152 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009153 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009154 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9155 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9156 return isDataRoamingEnabled;
9157 }
9158
9159 /**
9160 * Returns the default network type for the given {@code subId}, if the default network type is
9161 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9162 */
9163 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009164 List<Integer> list = TelephonyProperties.default_network();
9165 int phoneId = mSubscriptionController.getPhoneId(subId);
9166 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9167 return list.get(phoneId);
9168 }
9169 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009170 }
fionaxua13278b2018-03-21 00:08:13 -07009171
9172 @Override
9173 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009174 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009175 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009176
9177 final long identity = Binder.clearCallingIdentity();
9178 try {
9179 final Phone phone = getPhone(subId);
9180 if (phone == null) {
9181 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9182 return;
9183 }
chen xueaba88a2019-03-15 13:15:10 -07009184 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9185 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009186 if (carrierPrivilegeRules == null) {
9187 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9188 } else {
9189 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9190 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009191 } finally {
9192 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009193 }
fionaxua13278b2018-03-21 00:08:13 -07009194 }
9195
9196 @Override
9197 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009198 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009199
9200 final long identity = Binder.clearCallingIdentity();
9201 try {
9202 final Phone phone = getPhone(subId);
9203 if (phone == null) {
9204 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9205 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9206 }
9207 return phone.getCarrierIdListVersion();
9208 } finally {
9209 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009210 }
fionaxua13278b2018-03-21 00:08:13 -07009211 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009212
9213 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009214 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9215 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009216 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009217 mApp, subId, callingPackage, callingFeatureId,
9218 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009219 return -1;
9220 }
9221
9222 final long identity = Binder.clearCallingIdentity();
9223 try {
9224 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9225 } finally {
9226 Binder.restoreCallingIdentity(identity);
9227 }
9228 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009229
9230 @Override
9231 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009232 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009233 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009234 mApp, subId, "getCdmaRoamingMode");
9235
9236 final long identity = Binder.clearCallingIdentity();
9237 try {
9238 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9239 } finally {
9240 Binder.restoreCallingIdentity(identity);
9241 }
9242 }
9243
9244 @Override
9245 public boolean setCdmaRoamingMode(int subId, int mode) {
9246 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9247 mApp, subId, "setCdmaRoamingMode");
9248
9249 final long identity = Binder.clearCallingIdentity();
9250 try {
9251 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9252 } finally {
9253 Binder.restoreCallingIdentity(identity);
9254 }
9255 }
9256
9257 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009258 public int getCdmaSubscriptionMode(int subId) {
9259 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009260 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009261 mApp, subId, "getCdmaSubscriptionMode");
9262
9263 final long identity = Binder.clearCallingIdentity();
9264 try {
9265 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9266 } finally {
9267 Binder.restoreCallingIdentity(identity);
9268 }
9269 }
9270
9271 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009272 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9273 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9274 mApp, subId, "setCdmaSubscriptionMode");
9275
9276 final long identity = Binder.clearCallingIdentity();
9277 try {
9278 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9279 } finally {
9280 Binder.restoreCallingIdentity(identity);
9281 }
9282 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009283
sqianc5eccab2018-10-19 18:46:41 -07009284 @Override
sqian8c685422019-02-22 15:55:18 -08009285 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009286 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009287 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009288 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9289 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009290 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9291 }
9292 final long identity = Binder.clearCallingIdentity();
9293 try {
sqian854d44b2018-12-12 16:48:18 -08009294 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9295 for (Phone phone: PhoneFactory.getPhones()) {
9296 if (phone.getEmergencyNumberTracker() != null
9297 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9298 emergencyNumberListInternal.put(
9299 phone.getSubId(),
9300 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9301 }
sqian11b7a0e2018-12-05 18:48:28 -08009302 }
sqian854d44b2018-12-12 16:48:18 -08009303 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009304 } finally {
9305 Binder.restoreCallingIdentity(identity);
9306 }
sqianc5eccab2018-10-19 18:46:41 -07009307 }
9308
9309 @Override
sqian8c685422019-02-22 15:55:18 -08009310 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009311 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009312 if (!exactMatch) {
9313 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009314 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009315 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009316 }
9317 final long identity = Binder.clearCallingIdentity();
9318 try {
sqian854d44b2018-12-12 16:48:18 -08009319 for (Phone phone: PhoneFactory.getPhones()) {
9320 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009321 && phone.getEmergencyNumberTracker()
9322 .isEmergencyNumber(number, exactMatch)) {
9323 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009324 }
sqian11b7a0e2018-12-05 18:48:28 -08009325 }
9326 return false;
9327 } finally {
9328 Binder.restoreCallingIdentity(identity);
9329 }
9330 }
9331
sqianf4ca7ed2019-01-15 18:32:07 -08009332 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009333 * Start emergency callback mode for GsmCdmaPhone for testing.
9334 */
9335 @Override
9336 public void startEmergencyCallbackMode() {
9337 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9338 "startEmergencyCallbackMode");
9339 enforceModifyPermission();
9340 final long identity = Binder.clearCallingIdentity();
9341 try {
9342 for (Phone phone : PhoneFactory.getPhones()) {
9343 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9344 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9345 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9346 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9347 gsmCdmaPhone.obtainMessage(
9348 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9349 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9350 }
9351 }
9352 } finally {
9353 Binder.restoreCallingIdentity(identity);
9354 }
9355 }
9356
9357 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009358 * Update emergency number list for test mode.
9359 */
9360 @Override
9361 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9362 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9363 "updateEmergencyNumberListTestMode");
9364
9365 final long identity = Binder.clearCallingIdentity();
9366 try {
9367 for (Phone phone: PhoneFactory.getPhones()) {
9368 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9369 if (tracker != null) {
9370 tracker.executeEmergencyNumberTestModeCommand(action, num);
9371 }
9372 }
9373 } finally {
9374 Binder.restoreCallingIdentity(identity);
9375 }
9376 }
9377
9378 /**
9379 * Get the full emergency number list for test mode.
9380 */
9381 @Override
9382 public List<String> getEmergencyNumberListTestMode() {
9383 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9384 "getEmergencyNumberListTestMode");
9385
9386 final long identity = Binder.clearCallingIdentity();
9387 try {
9388 Set<String> emergencyNumbers = new HashSet<>();
9389 for (Phone phone: PhoneFactory.getPhones()) {
9390 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9391 if (tracker != null) {
9392 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9393 emergencyNumbers.add(num.getNumber());
9394 }
9395 }
9396 }
9397 return new ArrayList<>(emergencyNumbers);
9398 } finally {
9399 Binder.restoreCallingIdentity(identity);
9400 }
9401 }
9402
chen xud6b45bd2018-10-30 22:27:10 -07009403 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009404 public int getEmergencyNumberDbVersion(int subId) {
9405 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9406
9407 final long identity = Binder.clearCallingIdentity();
9408 try {
9409 final Phone phone = getPhone(subId);
9410 if (phone == null) {
9411 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9412 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9413 }
9414 return phone.getEmergencyNumberDbVersion();
9415 } finally {
9416 Binder.restoreCallingIdentity(identity);
9417 }
9418 }
9419
9420 @Override
9421 public void notifyOtaEmergencyNumberDbInstalled() {
9422 enforceModifyPermission();
9423
9424 final long identity = Binder.clearCallingIdentity();
9425 try {
9426 for (Phone phone: PhoneFactory.getPhones()) {
9427 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9428 if (tracker != null) {
9429 tracker.updateOtaEmergencyNumberDatabase();
9430 }
9431 }
9432 } finally {
9433 Binder.restoreCallingIdentity(identity);
9434 }
9435 }
9436
9437 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009438 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009439 enforceActiveEmergencySessionPermission();
9440
9441 final long identity = Binder.clearCallingIdentity();
9442 try {
9443 for (Phone phone: PhoneFactory.getPhones()) {
9444 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9445 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009446 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9447 }
9448 }
9449 } finally {
9450 Binder.restoreCallingIdentity(identity);
9451 }
9452 }
9453
9454 @Override
9455 public void resetOtaEmergencyNumberDbFilePath() {
9456 enforceActiveEmergencySessionPermission();
9457
9458 final long identity = Binder.clearCallingIdentity();
9459 try {
9460 for (Phone phone: PhoneFactory.getPhones()) {
9461 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9462 if (tracker != null) {
9463 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009464 }
9465 }
9466 } finally {
9467 Binder.restoreCallingIdentity(identity);
9468 }
9469 }
9470
9471 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009472 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9473 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9474 Phone phone = getPhone(subId);
9475 if (phone == null) {
9476 return null;
9477 }
9478 final long identity = Binder.clearCallingIdentity();
9479 try {
9480 UiccProfile profile = UiccController.getInstance()
9481 .getUiccProfileForPhone(phone.getPhoneId());
9482 if (profile != null) {
9483 return profile.getCertsFromCarrierPrivilegeAccessRules();
9484 }
9485 } finally {
9486 Binder.restoreCallingIdentity(identity);
9487 }
9488 return null;
9489 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009490
9491 /**
9492 * Enable or disable a modem stack.
9493 */
9494 @Override
9495 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9496 enforceModifyPermission();
9497
9498 final long identity = Binder.clearCallingIdentity();
9499 try {
9500 Phone phone = PhoneFactory.getPhone(slotIndex);
9501 if (phone == null) {
9502 return false;
9503 } else {
9504 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9505 }
9506 } finally {
9507 Binder.restoreCallingIdentity(identity);
9508 }
9509 }
Michelecea4cf22018-12-21 15:00:11 -08009510
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009511 /**
9512 * Whether a modem stack is enabled or not.
9513 */
9514 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009515 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9516 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009517 Phone phone = PhoneFactory.getPhone(slotIndex);
9518 if (phone == null) return false;
9519
9520 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009521 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9522 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009523 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9524 }
9525
9526 final long identity = Binder.clearCallingIdentity();
9527 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009528 try {
9529 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9530 } catch (NoSuchElementException ex) {
9531 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9532 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009533 } finally {
9534 Binder.restoreCallingIdentity(identity);
9535 }
9536 }
9537
Michelecea4cf22018-12-21 15:00:11 -08009538 @Override
Michele0ea7d782019-03-19 14:58:42 -07009539 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009540 enforceModifyPermission();
9541
9542 final long identity = Binder.clearCallingIdentity();
9543 try {
9544 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009545 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009546 .commit();
9547 } finally {
9548 Binder.restoreCallingIdentity(identity);
9549 }
9550 }
9551
9552 @Override
Michele0ea7d782019-03-19 14:58:42 -07009553 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009554 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009555 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009556 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9557 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009558 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009559 }
Michelecea4cf22018-12-21 15:00:11 -08009560
9561 final long identity = Binder.clearCallingIdentity();
9562 try {
Michele0ea7d782019-03-19 14:58:42 -07009563 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009564 } finally {
9565 Binder.restoreCallingIdentity(identity);
9566 }
9567 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009568
Michele0ea7d782019-03-19 14:58:42 -07009569 @TelephonyManager.IsMultiSimSupportedResult
9570 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009571 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9572 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9573 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009574 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9575 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009576 }
9577 // Check if the hardware supports multisim functionality. If usage of multisim is not
9578 // supported by the modem, indicate that it is restricted.
9579 PhoneCapability staticCapability =
9580 mPhoneConfigurationManager.getStaticPhoneCapability();
9581 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009582 loge("isMultiSimSupportedInternal: no static configuration available");
9583 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009584 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009585 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009586 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9587 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009588 }
9589 // Check if support of multiple SIMs is restricted by carrier
9590 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009591 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009592 }
9593
Michele0ea7d782019-03-19 14:58:42 -07009594 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009595 }
9596
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009597 /**
9598 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009599 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9600 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9601 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009602 * @param numOfSims number of active sims we want to switch to
9603 */
9604 @Override
9605 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009606 if (numOfSims == 1) {
9607 enforceModifyPermission();
9608 } else {
9609 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9610 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9611 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009612 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009613
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009614 try {
Michele30b57b22019-03-01 12:01:14 -08009615 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009616 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009617 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9618 return;
9619 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009620 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9621 } finally {
9622 Binder.restoreCallingIdentity(identity);
9623 }
9624 }
9625
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009626 @Override
9627 public boolean isApplicationOnUicc(int subId, int appType) {
9628 enforceReadPrivilegedPermission("isApplicationOnUicc");
9629 Phone phone = getPhone(subId);
9630 if (phone == null) {
9631 return false;
9632 }
9633 final long identity = Binder.clearCallingIdentity();
9634 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009635 UiccPort uiccPort = phone.getUiccPort();
9636 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009637 return false;
9638 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009639 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009640 if (uiccProfile == null) {
9641 return false;
9642 }
9643 if (TelephonyManager.APPTYPE_SIM <= appType
9644 && appType <= TelephonyManager.APPTYPE_ISIM) {
9645 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9646 }
9647 return false;
9648 } finally {
9649 Binder.restoreCallingIdentity(identity);
9650 }
9651 }
9652
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009653 /**
chen xub4baa772019-04-03 10:23:41 -07009654 * Get whether making changes to modem configurations will trigger reboot.
9655 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009656 */
9657 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009658 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9659 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009660 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009661 mApp, subId, callingPackage, callingFeatureId,
9662 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009663 return false;
9664 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009665 final long identity = Binder.clearCallingIdentity();
9666 try {
9667 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9668 } finally {
9669 Binder.restoreCallingIdentity(identity);
9670 }
9671 }
9672
Nathan Harold29f5f052019-02-15 13:41:57 -08009673 private void updateModemStateMetrics() {
9674 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9675 // TODO: check the state for each modem if the api is ready.
9676 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9677 }
9678
Pengquan Meng3889a572019-01-23 11:16:29 -08009679 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009680 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009681 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009682 // Verify that the callingPackage belongs to the calling UID
9683 mApp.getSystemService(AppOpsManager.class)
9684 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009685 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009686 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009687 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009688 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9689 if (slotInfos != null) {
9690 for (int i = 0; i < slotInfos.length; i++) {
9691 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9692 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9693 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9694 portInfo.getLogicalSlotIndex()));
9695 }
9696 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009697 }
9698 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009699 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009700 } finally {
9701 Binder.restoreCallingIdentity(identity);
9702 }
9703 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009704
9705 /**
9706 * Get the IRadio HAL Version
9707 */
9708 @Override
9709 public int getRadioHalVersion() {
9710 Phone phone = getDefaultPhone();
9711 if (phone == null) return -1;
9712 HalVersion hv = phone.getHalVersion();
9713 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9714 return hv.major * 100 + hv.minor;
9715 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009716
9717 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009718 * Get the current calling package name.
9719 * @return the current calling package name
9720 */
9721 @Override
9722 public String getCurrentPackageName() {
9723 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9724 }
9725
9726 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009727 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9728 * corresponding network requests on a subId.
9729 *
9730 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009731 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009732 * 2) APN is un-metered for this subscription, or
9733 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009734 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009735 *
9736 * @return whether data is allowed for a apn type.
9737 *
9738 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009739 */
9740 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009741 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009742 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9743 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009744
9745 // Now that all security checks passes, perform the operation as ourselves.
9746 final long identity = Binder.clearCallingIdentity();
9747 try {
9748 Phone phone = getPhone(subId);
9749 if (phone == null) return false;
9750
Jack Yu41407ee2019-05-13 16:54:09 -07009751 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009752 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9753 } finally {
9754 Binder.restoreCallingIdentity(identity);
9755 }
9756 }
9757
9758 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009759 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009760 enforceReadPrivilegedPermission("isApnMetered");
9761
9762 // Now that all security checks passes, perform the operation as ourselves.
9763 final long identity = Binder.clearCallingIdentity();
9764 try {
9765 Phone phone = getPhone(subId);
9766 if (phone == null) return true; // By default return true.
9767
Jack Yu41407ee2019-05-13 16:54:09 -07009768 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009769 } finally {
9770 Binder.restoreCallingIdentity(identity);
9771 }
9772 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009773
9774 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009775 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9776 int subscriptionId, IBooleanConsumer resultCallback) {
9777 enforceModifyPermission();
9778 long token = Binder.clearCallingIdentity();
9779 try {
9780 Phone phone = getPhone(subscriptionId);
9781 if (phone == null) {
9782 try {
9783 if (resultCallback != null) {
9784 resultCallback.accept(false);
9785 }
9786 } catch (RemoteException e) {
9787 // ignore
9788 }
9789 return;
9790 }
9791 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9792 Pair.create(specifiers, (x) -> {
9793 try {
9794 if (resultCallback != null) {
9795 resultCallback.accept(x);
9796 }
9797 } catch (RemoteException e) {
9798 // ignore
9799 }
9800 });
9801 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9802 } finally {
9803 Binder.restoreCallingIdentity(token);
9804 }
9805 }
9806
9807 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009808 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9809 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009810 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009811 mApp, subId, "getSystemSelectionChannels");
9812 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9813 final long identity = Binder.clearCallingIdentity();
9814 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009815 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9816 if (result instanceof IllegalStateException) {
9817 throw (IllegalStateException) result;
9818 }
9819 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009820 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9821 return specifiers;
9822 } finally {
9823 Binder.restoreCallingIdentity(identity);
9824 }
9825 }
9826
9827 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009828 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009829 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009830 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9831 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9832 if (iccRecords == null) {
9833 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9834 return false;
9835 }
9836 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9837 }
9838
9839 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009840 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9841 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009842 if (callingPackage == null) {
9843 callingPackage = getCurrentPackageName();
9844 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009845 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9846 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009847 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9848 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009849 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9850 }
9851 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9852 Intent intent = new Intent();
9853 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9854 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9855 // Bring up choose default SMS subscription dialog right now
9856 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9857 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9858 mApp.startActivity(intent);
9859 }
chen xud5ca2d52019-05-28 15:20:57 -07009860
9861 @Override
9862 public String getMmsUAProfUrl(int subId) {
9863 //TODO investigate if this API should require proper permission check in R b/133791609
9864 final long identity = Binder.clearCallingIdentity();
9865 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009866 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9867 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9868 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9869 return carrierUAProfUrl;
9870 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009871 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9872 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009873 } finally {
9874 Binder.restoreCallingIdentity(identity);
9875 }
9876 }
9877
9878 @Override
9879 public String getMmsUserAgent(int subId) {
9880 //TODO investigate if this API should require proper permission check in R b/133791609
9881 final long identity = Binder.clearCallingIdentity();
9882 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009883 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9884 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9885 if (!TextUtils.isEmpty(carrierUserAgent)) {
9886 return carrierUserAgent;
9887 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009888 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9889 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009890 } finally {
9891 Binder.restoreCallingIdentity(identity);
9892 }
9893 }
Jack Yub07d4972019-05-28 16:12:25 -07009894
9895 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009896 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9897 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009898
Jack Yub07d4972019-05-28 16:12:25 -07009899 final long identity = Binder.clearCallingIdentity();
9900 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009901 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009902 if (phone == null) return false;
9903
Hall Liua62f5da2020-09-25 10:42:19 -07009904 switch (policy) {
9905 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9906 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9907 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9908 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9909 default:
9910 throw new IllegalArgumentException(policy + " is not a valid policy");
9911 }
Jack Yub07d4972019-05-28 16:12:25 -07009912 } finally {
9913 Binder.restoreCallingIdentity(identity);
9914 }
9915 }
9916
9917 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009918 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009919 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009920 enforceModifyPermission();
9921
changbettyd5c246e2019-12-24 15:40:37 +08009922 final long identity = Binder.clearCallingIdentity();
9923 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009924 Phone phone = getPhone(subscriptionId);
9925 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009926
Hall Liua62f5da2020-09-25 10:42:19 -07009927 switch (policy) {
9928 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9929 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9930 break;
9931 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9932 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9933 break;
9934 default:
9935 throw new IllegalArgumentException(policy + " is not a valid policy");
9936 }
changbettyd5c246e2019-12-24 15:40:37 +08009937 } finally {
9938 Binder.restoreCallingIdentity(identity);
9939 }
9940 }
9941
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009942 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009943 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009944 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9945 * otherwise.
9946 */
9947 @Override
9948 public void setCepEnabled(boolean isCepEnabled) {
9949 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9950
9951 final long identity = Binder.clearCallingIdentity();
9952 try {
9953 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9954 for (Phone phone : PhoneFactory.getPhones()) {
9955 Phone defaultPhone = phone.getImsPhone();
9956 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9957 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9958 ImsPhoneCallTracker imsPhoneCallTracker =
9959 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9960 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9961 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9962 + imsPhone.getMsisdn());
9963 }
9964 }
9965 } finally {
9966 Binder.restoreCallingIdentity(identity);
9967 }
9968 }
allenwtsu46dcc572020-01-08 18:24:03 +08009969
9970 /**
9971 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9972 *
9973 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9974 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9975 * before being read.
9976 */
9977 @Override
9978 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9979 isCompressed) {
9980 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9981 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009982 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9983 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9984 }
9985 if (!isImsAvailableOnDevice()) {
9986 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9987 "IMS not available on device.");
9988 }
9989
9990 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009991 try {
Hui Wang761a6682020-10-31 05:12:53 +00009992 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9993 } finally {
9994 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009995 }
9996 }
zoey chene02881a2019-12-30 16:11:23 +08009997
9998 @Override
9999 public boolean isIccLockEnabled(int subId) {
10000 enforceReadPrivilegedPermission("isIccLockEnabled");
10001
10002 // Now that all security checks passes, perform the operation as ourselves.
10003 final long identity = Binder.clearCallingIdentity();
10004 try {
10005 Phone phone = getPhone(subId);
10006 if (phone != null && phone.getIccCard() != null) {
10007 return phone.getIccCard().getIccLockEnabled();
10008 } else {
10009 return false;
10010 }
10011 } finally {
10012 Binder.restoreCallingIdentity(identity);
10013 }
10014 }
10015
10016 /**
10017 * Set the ICC pin lock enabled or disabled.
10018 *
10019 * @return an integer representing the status of IccLock enabled or disabled in the following
10020 * three cases:
10021 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10022 * successfully.
10023 * - Positive number and zero for remaining password attempts.
10024 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10025 *
10026 */
10027 @Override
10028 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10029 enforceModifyPermission();
10030
10031 Phone phone = getPhone(subId);
10032 if (phone == null) {
10033 return 0;
10034 }
10035 // Now that all security checks passes, perform the operation as ourselves.
10036 final long identity = Binder.clearCallingIdentity();
10037 try {
10038 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10039 new Pair<Boolean, String>(enabled, password), phone, null);
10040 return attemptsRemaining;
10041
10042 } catch (Exception e) {
10043 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10044 } finally {
10045 Binder.restoreCallingIdentity(identity);
10046 }
10047 return 0;
10048 }
10049
10050 /**
10051 * Change the ICC password used in ICC pin lock.
10052 *
10053 * @return an integer representing the status of IccLock changed in the following three cases:
10054 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10055 * - Positive number and zero for remaining password attempts.
10056 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10057 *
10058 */
10059 @Override
10060 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10061 enforceModifyPermission();
10062
10063 Phone phone = getPhone(subId);
10064 if (phone == null) {
10065 return 0;
10066 }
10067 // Now that all security checks passes, perform the operation as ourselves.
10068 final long identity = Binder.clearCallingIdentity();
10069 try {
10070 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10071 new Pair<String, String>(oldPassword, newPassword), phone, null);
10072 return attemptsRemaining;
10073
10074 } catch (Exception e) {
10075 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10076 } finally {
10077 Binder.restoreCallingIdentity(identity);
10078 }
10079 return 0;
10080 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010081
10082 /**
10083 * Request for receiving user activity notification
10084 */
10085 @Override
10086 public void requestUserActivityNotification() {
10087 if (!mNotifyUserActivity.get()
10088 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10089 mNotifyUserActivity.set(true);
10090 }
10091 }
10092
10093 /**
10094 * Called when userActivity is signalled in the power manager.
10095 * This is safe to call from any thread, with any window manager locks held or not.
10096 */
10097 @Override
10098 public void userActivity() {
10099 // ***************************************
10100 // * Inherited from PhoneWindowManager *
10101 // ***************************************
10102 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10103 // WITH ITS LOCKS HELD.
10104 //
10105 // This code must be VERY careful about the locks
10106 // it acquires.
10107 // In fact, the current code acquires way too many,
10108 // and probably has lurking deadlocks.
10109
10110 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10111 throw new SecurityException("Only the OS may call notifyUserActivity()");
10112 }
10113
10114 if (mNotifyUserActivity.getAndSet(false)) {
10115 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10116 USER_ACTIVITY_NOTIFICATION_DELAY);
10117 }
10118 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010119
10120 @Override
10121 public boolean canConnectTo5GInDsdsMode() {
10122 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10123 }
Jack Yud10cdd42020-09-28 20:28:01 -070010124
10125 @Override
10126 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10127 String callingFeatureId) {
10128 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10129 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10130 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10131 }
10132
10133 Phone phone = getPhone(subId);
10134 if (phone == null) {
10135 throw new RuntimeException("phone is not available");
10136 }
10137 // Now that all security checks passes, perform the operation as ourselves.
10138 final long identity = Binder.clearCallingIdentity();
10139 try {
10140 return phone.getEquivalentHomePlmns();
10141 } finally {
10142 Binder.restoreCallingIdentity(identity);
10143 }
10144 }
Daniel Bright59e67312020-11-13 11:49:37 -080010145
10146 @Override
10147 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010148 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10149 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010150 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010151 if (radioInterfaceCapabilities == null) {
10152 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010153 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010154 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010155 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010156
Hui Wang641e81c2020-10-12 12:14:23 -070010157 @Override
10158 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10159 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010160 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10161 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10162 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10163 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10164 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010165 if (DBG) {
10166 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10167 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10168 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10169 }
10170
10171 if (!SubscriptionManager.isValidSubscriptionId(subId)
10172 || appType < TelephonyManager.APPTYPE_UNKNOWN
10173 || appType > TelephonyManager.APPTYPE_ISIM
10174 || nafUrl == null || securityProtocol == null || callback == null) {
10175 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10176 if (callback != null) {
10177 try {
10178 callback.onAuthenticationFailure(
10179 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10180 } catch (RemoteException exception) {
10181 log("Fail to notify onAuthenticationFailure due to " + exception);
10182 }
10183 return;
10184 }
10185 }
10186
10187 final long token = Binder.clearCallingIdentity();
10188 try {
10189 getGbaManager(subId).bootstrapAuthenticationRequest(
10190 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10191 forceBootStrapping, callback));
10192 } finally {
10193 Binder.restoreCallingIdentity(token);
10194 }
10195 }
10196
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010197 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010198 * Attempts to set the radio power state for all phones for thermal reason.
10199 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010200 * requested radio power state will actually be set. See {@link
10201 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10202 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010203 * @param enable {@code true} if trying to turn radio on.
10204 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10205 * false}.
10206 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010207 private boolean setRadioPowerForThermal(boolean enable) {
10208 boolean isPhoneAvailable = false;
10209 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10210 Phone phone = PhoneFactory.getPhone(i);
10211 if (phone != null) {
10212 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10213 isPhoneAvailable = true;
10214 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010215 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010216
10217 // return true if successfully informed the phone object about the thermal radio power
10218 // request.
10219 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010220 }
10221
10222 private int handleDataThrottlingRequest(int subId,
10223 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010224 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10225 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10226 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10227 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10228 throw new IllegalArgumentException("modem does not support data throttling");
10229 }
10230
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010231 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10232 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010233 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010234 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10235 }
10236
10237 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10238
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010239 if (isDataThrottlingSupported) {
10240 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010241 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010242 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10243 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10244 } else if (thermalMitigationResult
10245 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010246 log("Modem likely does not support data throttling on secondary carrier. Data " +
10247 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10248 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010249 }
10250 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010251 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010252
10253 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010254 }
10255
Jack Nudelman644b91a2021-03-12 14:09:48 -080010256 private static List<String> getThermalMitigationAllowlist(Context context) {
10257 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10258 for (String pckg : context.getResources()
10259 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10260 sThermalMitigationAllowlistedPackages.add(pckg);
10261 }
10262 }
10263
10264 return sThermalMitigationAllowlistedPackages;
10265 }
10266
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010267 private boolean isAnyPhoneInEmergencyState() {
10268 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10269 if (tm.isInEmergencyCall()) {
10270 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10271 return true;
10272 }
10273 for (Phone phone : PhoneFactory.getPhones()) {
10274 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10275 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10276 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10277 + phone.isInEcm());
10278 return true;
10279 }
10280 }
10281
10282 return false;
10283 }
10284
Jack Nudelman644b91a2021-03-12 14:09:48 -080010285 /**
10286 * Used by shell commands to add an authorized package name for thermal mitigation.
10287 * @param packageName name of package to be allowlisted
10288 * @param context
10289 */
10290 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10291 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10292 sThermalMitigationAllowlistedPackages.add(packageName);
10293 }
10294
10295 /**
10296 * Used by shell commands to remove an authorized package name for thermal mitigation.
10297 * @param packageName name of package to remove from allowlist
10298 * @param context
10299 */
10300 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10301 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10302 sThermalMitigationAllowlistedPackages.remove(packageName);
10303 }
10304
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010305 /**
10306 * Thermal mitigation request to control functionalities at modem.
10307 *
10308 * @param subId the id of the subscription.
10309 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010310 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010311 *
10312 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10313 */
10314 @Override
10315 @ThermalMitigationResult
10316 public int sendThermalMitigationRequest(
10317 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010318 ThermalMitigationRequest thermalMitigationRequest,
10319 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010320 enforceModifyPermission();
10321
Jack Nudelman644b91a2021-03-12 14:09:48 -080010322 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10323 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10324 .contains(callingPackage)) {
10325 throw new SecurityException("Calling package must be configured in the device config. "
10326 + "calling package: " + callingPackage);
10327 }
10328
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010329 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10330 final long identity = Binder.clearCallingIdentity();
10331
10332 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10333 try {
10334 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10335 switch (thermalMitigationAction) {
10336 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10337 thermalMitigationResult =
10338 handleDataThrottlingRequest(subId,
10339 thermalMitigationRequest.getDataThrottlingRequest());
10340 break;
10341 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10342 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10343 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10344 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10345 }
10346
10347 // Ensure that radio is on. If not able to power on due to phone being
10348 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010349 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010350 thermalMitigationResult =
10351 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10352 break;
10353 }
10354
10355 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10356 false);
10357 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10358 break;
10359 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10360 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10361 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10362 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10363 }
10364
10365 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10366 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010367 Phone phone = getPhone(subId);
10368 if (phone == null) {
10369 thermalMitigationResult =
10370 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10371 break;
10372 }
10373
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010374 TelephonyConnectionService service =
10375 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010376 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010377 Log.e(LOG_TAG, "An emergency call is pending");
10378 thermalMitigationResult =
10379 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10380 break;
10381 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010382 thermalMitigationResult =
10383 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10384 break;
10385 }
10386 } else {
10387 thermalMitigationResult =
10388 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10389 break;
10390 }
10391
10392 // Turn radio off. If not able to power off due to phone being unavailable,
10393 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010394 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010395 thermalMitigationResult =
10396 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10397 break;
10398 }
10399 thermalMitigationResult =
10400 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10401 break;
10402 default:
10403 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10404 + "not exist. Requested action: " + thermalMitigationAction);
10405 }
10406 } catch (IllegalArgumentException e) {
10407 throw e;
10408 } catch (Exception e) {
10409 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10410 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10411 } finally {
10412 Binder.restoreCallingIdentity(identity);
10413 }
10414
10415 if (DBG) {
10416 log("thermalMitigationRequest returning with thermalMitigationResult: "
10417 + thermalMitigationResult);
10418 }
10419
10420 return thermalMitigationResult;
10421 }
Hui Wang641e81c2020-10-12 12:14:23 -070010422
10423 /**
10424 * Set the GbaService Package Name that Telephony will bind to.
10425 *
10426 * @param subId The sim that the GbaService is associated with.
10427 * @param packageName The name of the package to be replaced with.
10428 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10429 */
10430 @Override
10431 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10432 enforceModifyPermission();
10433
10434 final long identity = Binder.clearCallingIdentity();
10435 try {
10436 return getGbaManager(subId).overrideServicePackage(packageName);
10437 } finally {
10438 Binder.restoreCallingIdentity(identity);
10439 }
10440 }
10441
10442 /**
10443 * Return the package name of the currently bound GbaService.
10444 *
10445 * @param subId The sim that the GbaService is associated with.
10446 * @return the package name of the GbaService configuration, null if GBA is not supported.
10447 */
10448 @Override
10449 public String getBoundGbaService(int subId) {
10450 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10451
10452 final long identity = Binder.clearCallingIdentity();
10453 try {
10454 return getGbaManager(subId).getServicePackage();
10455 } finally {
10456 Binder.restoreCallingIdentity(identity);
10457 }
10458 }
10459
10460 /**
10461 * Set the release time for telephony to unbind GbaService.
10462 *
10463 * @param subId The sim that the GbaService is associated with.
10464 * @param interval The release time to unbind GbaService by millisecond.
10465 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10466 */
10467 @Override
10468 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10469 enforceModifyPermission();
10470
10471 final long identity = Binder.clearCallingIdentity();
10472 try {
10473 return getGbaManager(subId).overrideReleaseTime(interval);
10474 } finally {
10475 Binder.restoreCallingIdentity(identity);
10476 }
10477 }
10478
10479 /**
10480 * Return the release time for telephony to unbind GbaService.
10481 *
10482 * @param subId The sim that the GbaService is associated with.
10483 * @return The release time to unbind GbaService by millisecond.
10484 */
10485 @Override
10486 public int getGbaReleaseTime(int subId) {
10487 enforceReadPrivilegedPermission("getGbaReleaseTime");
10488
10489 final long identity = Binder.clearCallingIdentity();
10490 try {
10491 return getGbaManager(subId).getReleaseTime();
10492 } finally {
10493 Binder.restoreCallingIdentity(identity);
10494 }
10495 }
10496
10497 private GbaManager getGbaManager(int subId) {
10498 GbaManager instance = GbaManager.getInstance(subId);
10499 if (instance == null) {
10500 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10501 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10502 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10503 }
10504 return instance;
10505 }
Hui Wang761a6682020-10-31 05:12:53 +000010506
10507 /**
10508 * indicate whether the device and the carrier can support
10509 * RCS VoLTE single registration.
10510 */
10511 @Override
10512 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010513 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10514 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10515 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10516 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010517
10518 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10519 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10520 }
10521
10522 final long identity = Binder.clearCallingIdentity();
10523 try {
10524 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10525 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010526 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10527 if (isCapable != null) {
10528 return isCapable;
10529 }
Hui Wang761a6682020-10-31 05:12:53 +000010530 }
Hui Wang67af90e2021-06-04 16:57:15 -070010531 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10532 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010533 } finally {
10534 Binder.restoreCallingIdentity(identity);
10535 }
10536 }
10537
10538 /**
10539 * Register RCS provisioning callback.
10540 */
10541 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010542 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010543 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010544 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010545 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010546 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10547 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010548
10549 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10550 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10551 }
10552 if (!isImsAvailableOnDevice()) {
10553 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10554 "IMS not available on device.");
10555 }
10556
10557 final long identity = Binder.clearCallingIdentity();
10558 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010559 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010560 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010561 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10562 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010563 }
Hui Wang761a6682020-10-31 05:12:53 +000010564 } finally {
10565 Binder.restoreCallingIdentity(identity);
10566 }
10567 }
10568
10569 /**
10570 * Unregister RCS provisioning callback.
10571 */
10572 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010573 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010574 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010575 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010576 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010577 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10578 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010579
10580 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10581 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10582 }
10583 if (!isImsAvailableOnDevice()) {
10584 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10585 "IMS not available on device.");
10586 }
10587
10588 final long identity = Binder.clearCallingIdentity();
10589 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010590 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010591 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010592 } finally {
10593 Binder.restoreCallingIdentity(identity);
10594 }
10595 }
10596
10597 /**
10598 * trigger RCS reconfiguration.
10599 */
10600 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010601 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10602 "triggerRcsReconfiguration",
10603 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010604
10605 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10606 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10607 }
10608 if (!isImsAvailableOnDevice()) {
10609 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10610 "IMS not available on device.");
10611 }
10612
10613 final long identity = Binder.clearCallingIdentity();
10614 try {
10615 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10616 } finally {
10617 Binder.restoreCallingIdentity(identity);
10618 }
10619 }
10620
10621 /**
10622 * Provide the client configuration parameters of the RCS application.
10623 */
10624 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010625 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10626 "setRcsClientConfiguration",
10627 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010628
10629 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10630 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10631 }
10632 if (!isImsAvailableOnDevice()) {
10633 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10634 "IMS not available on device.");
10635 }
10636
10637 final long identity = Binder.clearCallingIdentity();
10638
10639 try {
10640 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10641 if (configBinder == null) {
10642 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010643 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10644 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010645 } else {
10646 configBinder.setRcsClientConfiguration(rcc);
10647 }
joonhunshin3e154242021-09-17 06:33:39 +000010648
10649 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10650 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010651 } catch (RemoteException e) {
10652 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010653 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10654 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010655 } finally {
10656 Binder.restoreCallingIdentity(identity);
10657 }
10658 }
10659
10660 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010661 * Enables or disables the test mode for RCS VoLTE single registration.
10662 */
10663 @Override
10664 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10665 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10666 "setRcsSingleRegistrationTestModeEnabled");
10667
10668 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10669 }
10670
10671 /**
10672 * Gets the test mode for RCS VoLTE single registration.
10673 */
10674 @Override
10675 public boolean getRcsSingleRegistrationTestModeEnabled() {
10676 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10677 "getRcsSingleRegistrationTestModeEnabled");
10678
10679 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10680 }
10681
10682 /**
Hui Wang761a6682020-10-31 05:12:53 +000010683 * Overrides the config of RCS VoLTE single registration enabled for the device.
10684 */
10685 @Override
10686 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10687 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10688 "setDeviceSingleRegistrationEnabledOverride");
10689 enforceModifyPermission();
10690
10691 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10692 : Boolean.parseBoolean(enabledStr);
10693 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010694 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010695 }
10696
10697 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010698 * Sends a device to device communication message. Only usable via shell.
10699 * @param message message to send.
10700 * @param value message value.
10701 */
10702 @Override
10703 public void sendDeviceToDeviceMessage(int message, int value) {
10704 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010705 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010706 enforceModifyPermission();
10707
10708 final long identity = Binder.clearCallingIdentity();
10709 try {
10710 TelephonyConnectionService service =
10711 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10712 if (service == null) {
10713 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10714 return;
10715 }
10716 service.sendTestDeviceToDeviceMessage(message, value);
10717 } finally {
10718 Binder.restoreCallingIdentity(identity);
10719 }
10720 }
10721
Tyler Gunnbabbda02021-02-10 11:05:02 -080010722 /**
10723 * Sets the specified device to device transport active.
10724 * @param transport The transport to set active.
10725 */
10726 @Override
10727 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10728 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10729 "setActiveDeviceToDeviceTransport");
10730 enforceModifyPermission();
10731
10732 final long identity = Binder.clearCallingIdentity();
10733 try {
10734 TelephonyConnectionService service =
10735 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10736 if (service == null) {
10737 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10738 return;
10739 }
10740 service.setActiveDeviceToDeviceTransport(transport);
10741 } finally {
10742 Binder.restoreCallingIdentity(identity);
10743 }
10744 }
Tyler Gunn92479152021-01-20 16:30:10 -080010745
Tyler Gunnd4339262021-05-03 14:46:49 -070010746 @Override
10747 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10748 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10749 "setDeviceToDeviceForceEnabled");
10750
10751 final long identity = Binder.clearCallingIdentity();
10752 try {
10753 Arrays.stream(PhoneFactory.getPhones()).forEach(
10754 p -> {
10755 Phone thePhone = p.getImsPhone();
10756 if (thePhone != null && thePhone instanceof ImsPhone) {
10757 ImsPhone imsPhone = (ImsPhone) thePhone;
10758 CallTracker tracker = imsPhone.getCallTracker();
10759 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10760 ImsPhoneCallTracker imsPhoneCallTracker =
10761 (ImsPhoneCallTracker) tracker;
10762 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10763 }
10764 }
10765 }
10766 );
10767 } finally {
10768 Binder.restoreCallingIdentity(identity);
10769 }
10770 }
10771
Tyler Gunn92479152021-01-20 16:30:10 -080010772 /**
Hui Wang761a6682020-10-31 05:12:53 +000010773 * Gets the config of RCS VoLTE single registration enabled for the device.
10774 */
10775 @Override
10776 public boolean getDeviceSingleRegistrationEnabled() {
10777 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10778 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10779 }
10780
10781 /**
10782 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10783 */
10784 @Override
10785 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10786 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10787 "setCarrierSingleRegistrationEnabledOverride");
10788 enforceModifyPermission();
10789
10790 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10791 : Boolean.parseBoolean(enabledStr);
10792 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10793 subId, enabled);
10794 }
10795
10796 /**
10797 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10798 */
10799 @Override
10800 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10801 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10802 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10803 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010804
10805 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010806 * Overrides the ims feature validation result
10807 */
10808 @Override
10809 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10810 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10811 "setImsFeatureValidationOverride");
10812
10813 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10814 : Boolean.parseBoolean(enabledStr);
10815 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10816 subId, enabled);
10817 }
10818
10819 /**
10820 * Gets the ims feature validation override value
10821 */
10822 @Override
10823 public boolean getImsFeatureValidationOverride(int subId) {
10824 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10825 "getImsFeatureValidationOverride");
10826 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10827 }
10828
10829 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010830 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10831 * their mobile plan.
10832 */
10833 @Override
10834 public String getMobileProvisioningUrl() {
10835 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10836 final long identity = Binder.clearCallingIdentity();
10837 try {
10838 return getDefaultPhone().getMobileProvisioningUrl();
10839 } finally {
10840 Binder.restoreCallingIdentity(identity);
10841 }
10842 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010843
James.cf Linbcdf8b32021-01-14 16:44:13 +080010844 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010845 * Get the EAB contact from the EAB database.
10846 */
10847 @Override
10848 public String getContactFromEab(String contact) {
10849 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10850 enforceModifyPermission();
10851 final long identity = Binder.clearCallingIdentity();
10852 try {
10853 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10854 } finally {
10855 Binder.restoreCallingIdentity(identity);
10856 }
10857 }
10858
10859 /**
Calvin Pana1434322021-07-01 19:27:01 +080010860 * Get the EAB capability from the EAB database.
10861 */
10862 @Override
10863 public String getCapabilityFromEab(String contact) {
10864 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10865 enforceModifyPermission();
10866 final long identity = Binder.clearCallingIdentity();
10867 try {
10868 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10869 } finally {
10870 Binder.restoreCallingIdentity(identity);
10871 }
10872 }
10873
10874 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010875 * Remove the EAB contacts from the EAB database.
10876 */
10877 @Override
10878 public int removeContactFromEab(int subId, String contacts) {
10879 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10880 enforceModifyPermission();
10881 final long identity = Binder.clearCallingIdentity();
10882 try {
10883 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10884 } finally {
10885 Binder.restoreCallingIdentity(identity);
10886 }
10887 }
10888
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010889 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010890 public boolean getDeviceUceEnabled() {
10891 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10892 final long identity = Binder.clearCallingIdentity();
10893 try {
10894 return mApp.getDeviceUceEnabled();
10895 } finally {
10896 Binder.restoreCallingIdentity(identity);
10897 }
10898 }
10899
10900 @Override
10901 public void setDeviceUceEnabled(boolean isEnabled) {
10902 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10903 final long identity = Binder.clearCallingIdentity();
10904 try {
10905 mApp.setDeviceUceEnabled(isEnabled);
10906 } finally {
10907 Binder.restoreCallingIdentity(identity);
10908 }
10909 }
10910
Brad Ebinger14d467f2021-02-12 06:18:28 +000010911 /**
10912 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10913 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10914 */
10915 // Used for SHELL command only right now.
10916 @Override
10917 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10918 List<String> featureTags) {
10919 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10920 "addUceRegistrationOverrideShell");
10921 final long identity = Binder.clearCallingIdentity();
10922 try {
10923 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10924 new ArraySet<>(featureTags));
10925 } catch (ImsException e) {
10926 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10927 } finally {
10928 Binder.restoreCallingIdentity(identity);
10929 }
10930 }
10931
10932 /**
10933 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10934 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10935 */
10936 // Used for SHELL command only right now.
10937 @Override
10938 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10939 List<String> featureTags) {
10940 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10941 "removeUceRegistrationOverrideShell");
10942 final long identity = Binder.clearCallingIdentity();
10943 try {
10944 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10945 new ArraySet<>(featureTags));
10946 } catch (ImsException e) {
10947 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10948 } finally {
10949 Binder.restoreCallingIdentity(identity);
10950 }
10951 }
10952
10953 /**
10954 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10955 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10956 */
10957 // Used for SHELL command only right now.
10958 @Override
10959 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10960 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10961 "clearUceRegistrationOverrideShell");
10962 final long identity = Binder.clearCallingIdentity();
10963 try {
10964 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10965 } catch (ImsException e) {
10966 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10967 } finally {
10968 Binder.restoreCallingIdentity(identity);
10969 }
10970 }
10971
10972 /**
10973 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10974 */
10975 // Used for SHELL command only right now.
10976 @Override
10977 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10978 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10979 "getLatestRcsContactUceCapabilityShell");
10980 final long identity = Binder.clearCallingIdentity();
10981 try {
10982 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10983 } catch (ImsException e) {
10984 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10985 } finally {
10986 Binder.restoreCallingIdentity(identity);
10987 }
10988 }
10989
10990 /**
10991 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10992 * device does not have an active PUBLISH.
10993 */
10994 // Used for SHELL command only right now.
10995 @Override
10996 public String getLastUcePidfXmlShell(int subId) {
10997 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10998 final long identity = Binder.clearCallingIdentity();
10999 try {
11000 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11001 } catch (ImsException e) {
11002 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11003 } finally {
11004 Binder.restoreCallingIdentity(identity);
11005 }
11006 }
11007
James.cf Line8713a42021-04-29 16:04:26 +080011008 /**
11009 * Remove UCE requests cannot be sent to the network status.
11010 */
11011 // Used for SHELL command only right now.
11012 @Override
11013 public boolean removeUceRequestDisallowedStatus(int subId) {
11014 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11015 final long identity = Binder.clearCallingIdentity();
11016 try {
11017 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11018 } catch (ImsException e) {
11019 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11020 } finally {
11021 Binder.restoreCallingIdentity(identity);
11022 }
11023 }
11024
James.cf Lin18bb9002021-05-25 01:37:38 +080011025 /**
11026 * Remove UCE requests cannot be sent to the network status.
11027 */
11028 // Used for SHELL command only.
11029 @Override
11030 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11031 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11032 final long identity = Binder.clearCallingIdentity();
11033 try {
11034 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11035 } catch (ImsException e) {
11036 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11037 } finally {
11038 Binder.restoreCallingIdentity(identity);
11039 }
11040 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011041
James.cf Lin4b784aa2021-01-31 03:25:15 +080011042 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011043 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11044 String callingPackage) {
11045 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11046 mApp, subId, "setSignalStrengthUpdateRequest");
11047
11048 final int callingUid = Binder.getCallingUid();
11049 // Verify that tha callingPackage belongs to the calling UID
11050 mApp.getSystemService(AppOpsManager.class)
11051 .checkPackage(callingUid, callingPackage);
11052
Rambo Wang3607f502021-02-01 21:51:40 -080011053 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011054
11055 final long identity = Binder.clearCallingIdentity();
11056 try {
11057 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11058 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11059
11060 if (result instanceof IllegalStateException) {
11061 throw (IllegalStateException) result;
11062 }
11063 } finally {
11064 Binder.restoreCallingIdentity(identity);
11065 }
11066 }
11067
11068 @Override
11069 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11070 String callingPackage) {
11071 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11072 mApp, subId, "clearSignalStrengthUpdateRequest");
11073
11074 final int callingUid = Binder.getCallingUid();
11075 // Verify that tha callingPackage belongs to the calling UID
11076 mApp.getSystemService(AppOpsManager.class)
11077 .checkPackage(callingUid, callingPackage);
11078
11079 final long identity = Binder.clearCallingIdentity();
11080 try {
11081 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11082 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11083
11084 if (result instanceof IllegalStateException) {
11085 throw (IllegalStateException) result;
11086 }
11087 } finally {
11088 Binder.restoreCallingIdentity(identity);
11089 }
11090 }
11091
Rambo Wang3607f502021-02-01 21:51:40 -080011092 private static void validateSignalStrengthUpdateRequest(Context context,
11093 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011094 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11095 // phone/system process do not have further restriction on request
11096 return;
11097 }
11098
11099 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011100 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011101 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011102 context.enforceCallingOrSelfPermission(
11103 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11104 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011105 }
11106
11107 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11108 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11109 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11110 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11111 || info.isEnabled()) {
11112 throw new IllegalArgumentException(
11113 "Only system can set hide fields in SignalThresholdInfo");
11114 }
11115
11116 // Thresholds length for each RAN need in range. This has been validated in
11117 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11118 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11119 final int[] thresholds = info.getThresholds();
11120 Objects.requireNonNull(thresholds);
11121 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11122 || thresholds.length
11123 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11124 throw new IllegalArgumentException(
11125 "thresholds length is out of range: " + thresholds.length);
11126 }
11127 }
11128 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011129
11130 /**
11131 * Gets the current phone capability.
11132 *
11133 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11134 * @return the PhoneCapability which describes the data connection capability of modem.
11135 * It's used to evaluate possible phone config change, for example from single
11136 * SIM device to multi-SIM device.
11137 */
11138 @Override
11139 public PhoneCapability getPhoneCapability() {
11140 enforceReadPrivilegedPermission("getPhoneCapability");
11141 final long identity = Binder.clearCallingIdentity();
11142 try {
11143 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11144 } finally {
11145 Binder.restoreCallingIdentity(identity);
11146 }
11147 }
Michele Berionne5e411512020-11-13 02:36:59 +000011148
11149 /**
11150 * Prepare TelephonyManager for an unattended reboot. The reboot is
11151 * required to be done shortly after the API is invoked.
11152 */
11153 @Override
11154 @TelephonyManager.PrepareUnattendedRebootResult
11155 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011156 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011157 enforceRebootPermission();
11158
11159 final long identity = Binder.clearCallingIdentity();
11160 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011161 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011162 } finally {
11163 Binder.restoreCallingIdentity(identity);
11164 }
11165 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011166
11167 /**
11168 * Request to get the current slicing configuration including URSP rules and
11169 * NSSAIs (configured, allowed and rejected).
11170 *
11171 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11172 */
11173 @Override
11174 public void getSlicingConfig(ResultReceiver callback) {
11175 enforceReadPrivilegedPermission("getSlicingConfig");
11176
11177 final long identity = Binder.clearCallingIdentity();
11178 try {
11179 Phone phone = getDefaultPhone();
11180 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11181 } finally {
11182 Binder.restoreCallingIdentity(identity);
11183 }
11184 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011185
11186 /**
11187 * Register an IMS connection state callback
11188 */
11189 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011190 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11191 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011192 if (feature == ImsFeature.FEATURE_MMTEL) {
11193 // ImsMmTelManager
11194 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11195 TelephonyPermissions
11196 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11197 mApp, subId, "registerImsStateCallback");
11198 } else if (feature == ImsFeature.FEATURE_RCS) {
11199 // ImsRcsManager or SipDelegateManager
11200 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11201 Binder.getCallingUid(), "registerImsStateCallback",
11202 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11203 Manifest.permission.READ_PRECISE_PHONE_STATE,
11204 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11205 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11206 }
11207
11208 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11209 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11210 "IMS not available on device.");
11211 }
11212
11213 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11214 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11215 }
11216
11217 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11218 if (controller == null) {
11219 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11220 "IMS not available on device.");
11221 }
11222
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011223 if (callingPackage == null) {
11224 callingPackage = getCurrentPackageName();
11225 }
11226
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011227 final long token = Binder.clearCallingIdentity();
11228 try {
11229 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011230 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011231 } catch (ImsException e) {
11232 throw new ServiceSpecificException(e.getCode());
11233 } finally {
11234 Binder.restoreCallingIdentity(token);
11235 }
11236 }
11237
11238 /**
11239 * Unregister an IMS connection state callback
11240 */
11241 @Override
11242 public void unregisterImsStateCallback(IImsStateCallback cb) {
11243 final long token = Binder.clearCallingIdentity();
11244 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11245 if (controller == null) {
11246 return;
11247 }
11248 try {
11249 controller.unregisterImsStateCallback(cb);
11250 } finally {
11251 Binder.restoreCallingIdentity(token);
11252 }
11253 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011254
11255 /**
11256 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11257 *
11258 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11259 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11260 * SecurityException.
11261 * If there is current registered network this value will be same as the registered cell
11262 * identity. If the device goes out of service the previous cell identity is cached and
11263 * will be returned. If the cache age of the Cell identity is more than 24 hours
11264 * it will be cleared and null will be returned.
11265 *
11266 */
11267 @Override
11268 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11269 String callingFeatureId) {
11270 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11271 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11272 LocationAccessPolicy.checkLocationPermission(mApp,
11273 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11274 .setCallingPackage(callingPackage)
11275 .setCallingFeatureId(callingFeatureId)
11276 .setCallingPid(Binder.getCallingPid())
11277 .setCallingUid(Binder.getCallingUid())
11278 .setMethod("getLastKnownCellIdentity")
11279 .setLogAsInfo(true)
11280 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11281 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11282 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11283 .build());
11284
11285 boolean hasFinePermission =
11286 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11287 if (!hasFinePermission
11288 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11289 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
11290 + "and BIND_CONNECTION_SERVICE permission.");
11291 }
11292
11293 final long identity = Binder.clearCallingIdentity();
11294 try {
11295 Phone phone = getPhone(subId);
11296 if (phone == null) return null;
11297 ServiceStateTracker sst = phone.getServiceStateTracker();
11298 if (sst == null) return null;
11299 return sst.getLastKnownCellIdentity();
11300 } finally {
11301 Binder.restoreCallingIdentity(identity);
11302 }
11303 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011304
11305 @Override
11306 public boolean isUsingNewDataStack() {
11307 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "isUsingNewDataStack");
11308 return getDefaultPhone().isUsingNewDataStack();
11309 }
jimsun3b9ccac2021-10-26 15:01:23 +080011310
11311 /**
11312 * Sets the modem service class Name that Telephony will bind to.
11313 *
11314 * @param serviceName The class name of the modem service.
11315 * @return true if the operation is succeed, otherwise false.
11316 */
11317 public boolean setModemService(String serviceName) {
11318 Log.d(LOG_TAG, "setModemService - " + serviceName);
11319 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11320 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11321 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11322 "setModemService");
11323 return mPhoneConfigurationManager.setModemService(serviceName);
11324 }
11325
11326 /**
11327 * Return the class name of the currently bounded modem service.
11328 *
11329 * @return the class name of the modem service.
11330 */
11331 public String getModemService() {
11332 String result;
11333 Log.d(LOG_TAG, "getModemService");
11334 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11335 TelephonyPermissions
11336 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11337 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11338 "getModemService");
11339 result = mPhoneConfigurationManager.getModemService();
11340 Log.d(LOG_TAG, "result = " + result);
11341 return result;
11342 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011343}