blob: bcbbeac43443f162c80e0abb35bf2cd106704f9e [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;
joonhunshincffb7fc2021-11-28 07:32:01 +0000127import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700128import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800129import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700130import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800131import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700132import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000133import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700134import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800135import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800136import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800137import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800138import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700139import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800140import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700141import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700142import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800143import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800144
Andrew Lee312e8172014-10-23 17:01:36 -0700145import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800146import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800147import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800148import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800149import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700150import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700151import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700152import com.android.internal.telephony.CallTracker;
chen xu651eec72018-11-11 19:03:44 -0800153import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700154import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700155import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800156import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700157import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700158import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800159import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800160import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800161import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700162import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000163import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700164import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800165import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700166import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800167import com.android.internal.telephony.IccCard;
Rambo Wanga1782702021-11-10 20:15:19 -0800168import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700169import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700170import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700171import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700172import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700173import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800174import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700175import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700176import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700177import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700178import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800179import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800180import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700181import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700182import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700183import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800184import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800185import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800186import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700187import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800188import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700189import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800190import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700191import com.android.internal.telephony.imsphone.ImsPhone;
192import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000193import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800194import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700195import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700196import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800197import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700198import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800199import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700200import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800201import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700202import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000203import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800204import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000205import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800206import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700207import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700208import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800209import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800210import com.android.phone.callcomposer.CallComposerPictureManager;
211import com.android.phone.callcomposer.CallComposerPictureTransfer;
212import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700213import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700214import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800215import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700216import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700217import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800218import com.android.services.telephony.TelecomAccountRegistry;
219import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800220import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800221
Hall Liu82694d52020-12-11 18:22:04 -0800222import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700223import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800224import java.io.IOException;
225import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700226import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700227import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800228import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000229import java.util.Collection;
sqian11b7a0e2018-12-05 18:48:28 -0800230import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800231import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800232import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100233import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800234import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700235import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800236import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800237import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800238import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800239import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800240import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700241
242/**
243 * Implementation of the ITelephony interface.
244 */
Santos Cordon117fee72014-05-16 17:56:12 -0700245public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700246 private static final String LOG_TAG = "PhoneInterfaceManager";
247 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
248 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800249 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700250
251 // Message codes used with mMainThreadHandler
252 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700253 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
254 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700255 private static final int CMD_OPEN_CHANNEL = 9;
256 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
257 private static final int CMD_CLOSE_CHANNEL = 11;
258 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800259 private static final int CMD_NV_READ_ITEM = 13;
260 private static final int EVENT_NV_READ_ITEM_DONE = 14;
261 private static final int CMD_NV_WRITE_ITEM = 15;
262 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
263 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
264 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700265 private static final int CMD_RESET_MODEM_CONFIG = 19;
266 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800267 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
268 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800269 private static final int CMD_SEND_ENVELOPE = 25;
270 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000271 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
272 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700273 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
274 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
275 private static final int CMD_EXCHANGE_SIM_IO = 31;
276 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800277 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
278 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700279 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
280 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700281 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
282 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700283 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
284 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
285 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
286 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700287 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
288 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
289 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
290 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700291 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800292 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
293 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000294 private static final int CMD_SWITCH_SLOTS = 50;
295 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700296 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
297 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
298 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
299 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
300 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
301 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
302 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
303 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700304 private static final int CMD_GET_ALL_CELL_INFO = 60;
305 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
306 private static final int CMD_GET_CELL_LOCATION = 62;
307 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700308 private static final int CMD_MODEM_REBOOT = 64;
309 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700310 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
311 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800312 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
313 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700314 private static final int CMD_GET_MODEM_STATUS = 70;
315 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700316 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
317 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700318 private static final int CMD_ERASE_MODEM_CONFIG = 74;
319 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800320 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
321 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
322 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
323 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800324 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
325 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800326 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800327 private static final int CMD_GET_CALL_FORWARDING = 83;
328 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
329 private static final int CMD_SET_CALL_FORWARDING = 85;
330 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
331 private static final int CMD_GET_CALL_WAITING = 87;
332 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
333 private static final int CMD_SET_CALL_WAITING = 89;
334 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700335 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
336 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
337 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
338 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700339 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
340 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800341 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
342 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800343 private static final int CMD_SET_DATA_THROTTLING = 99;
344 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800345 private static final int CMD_SET_SIM_POWER = 101;
346 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800347 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
348 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
349 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
350 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800351 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
352 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000353 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800354 private static final int CMD_GET_SLICING_CONFIG = 110;
355 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800356 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700357 private static final int CMD_ENABLE_VONR = 113;
358 private static final int EVENT_ENABLE_VONR_DONE = 114;
359 private static final int CMD_IS_VONR_ENABLED = 115;
360 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700361
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800362 // Parameters of select command.
363 private static final int SELECT_COMMAND = 0xA4;
364 private static final int SELECT_P1 = 0x04;
365 private static final int SELECT_P2 = 0;
366 private static final int SELECT_P3 = 0x10;
367
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700368 /** The singleton instance. */
369 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800370 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371
Wink Saville3ab207e2014-11-20 13:07:20 -0800372 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800373 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800374 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700375 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800376 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700377 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800378 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800379 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800380 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700381 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800382 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700383
Peter Wangdafb9ac2020-01-15 14:13:38 -0800384 /** User Activity */
385 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800386 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
387
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700388 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
389
Derek Tan97ebb422014-09-05 16:55:38 -0700390 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
391 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800392 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800393 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700394
Michelecea4cf22018-12-21 15:00:11 -0800395 // String to store multi SIM allowed
396 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
397
Derek Tan740e1672017-06-27 14:56:27 -0700398 // The AID of ISD-R.
399 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
400
yinxub1bed742017-04-17 11:45:04 -0700401 private NetworkScanRequestTracker mNetworkScanRequestTracker;
402
David Kelly5e06a7f2018-03-12 14:10:59 +0000403 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
404 private static final int MANUFACTURER_CODE_LENGTH = 8;
405
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800406 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800407 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800408
Derek Tan89e89d42014-07-08 17:00:10 -0700409 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700410 * Experiment flag to enable erase modem config on reset network, default value is false
411 */
412 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
413 "reset_network_erase_modem_config_enabled";
414
Rambo Wang0f050d82021-02-12 11:43:36 -0800415 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800416
sandeepjsb6c87872021-09-27 15:34:44 +0000417 /**
418 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
419 * one ICCID active at the same time.
420 * Apps should use below API signatures if targeting SDK is T and beyond.
421 *
422 * @hide
423 */
424 @ChangeId
425 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
426 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800427
Naina Nallurid63128d2019-09-17 14:10:30 -0700428 /**
Chen Xu540470b2021-12-14 17:15:47 -0800429 * Apps targeting on Android T and beyond will get exception whenever icc close channel
430 * operation fails.
431 */
432 @ChangeId
433 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
434 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
435
436 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700437 * A request object to use for transmitting data to an ICC.
438 */
439 private static final class IccAPDUArgument {
440 public int channel, cla, command, p1, p2, p3;
441 public String data;
442
443 public IccAPDUArgument(int channel, int cla, int command,
444 int p1, int p2, int p3, String data) {
445 this.channel = channel;
446 this.cla = cla;
447 this.command = command;
448 this.p1 = p1;
449 this.p2 = p2;
450 this.p3 = p3;
451 this.data = data;
452 }
453 }
454
455 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700456 * A request object to use for transmitting data to an ICC.
457 */
458 private static final class ManualNetworkSelectionArgument {
459 public OperatorInfo operatorInfo;
460 public boolean persistSelection;
461
462 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
463 this.operatorInfo = operatorInfo;
464 this.persistSelection = persistSelection;
465 }
466 }
467
468 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700469 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
470 * request after sending. The main thread will notify the request when it is complete.
471 */
472 private static final class MainThreadRequest {
473 /** The argument to use for the request */
474 public Object argument;
475 /** The result of the request that is run on the main thread */
476 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800477 // The subscriber id that this request applies to. Defaults to
478 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
479 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700480
Nathan Harold92bed182018-10-12 18:16:49 -0700481 // In cases where subId is unavailable, the caller needs to specify the phone.
482 public Phone phone;
483
vagdeviaf9a5b92018-08-15 16:01:53 -0700484 public WorkSource workSource;
485
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700486 public MainThreadRequest(Object argument) {
487 this.argument = argument;
488 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800489
Nathan Harold92bed182018-10-12 18:16:49 -0700490 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
491 this.argument = argument;
492 if (phone != null) {
493 this.phone = phone;
494 }
495 this.workSource = workSource;
496 }
497
vagdeviaf9a5b92018-08-15 16:01:53 -0700498 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800499 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800500 if (subId != null) {
501 this.subId = subId;
502 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700503 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800504 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700505 }
506
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800507 private static final class IncomingThirdPartyCallArgs {
508 public final ComponentName component;
509 public final String callId;
510 public final String callerDisplayName;
511
512 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
513 String callerDisplayName) {
514 this.component = component;
515 this.callId = callId;
516 this.callerDisplayName = callerDisplayName;
517 }
518 }
519
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700520 /**
521 * A handler that processes messages on the main thread in the phone process. Since many
522 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
523 * inbound binder threads to the main thread in the phone process. The Binder thread
524 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
525 * on, which will be notified when the operation completes and will contain the result of the
526 * request.
527 *
528 * <p>If a MainThreadRequest object is provided in the msg.obj field,
529 * note that request.result must be set to something non-null for the calling thread to
530 * unblock.
531 */
532 private final class MainThreadHandler extends Handler {
533 @Override
534 public void handleMessage(Message msg) {
535 MainThreadRequest request;
536 Message onCompleted;
537 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000538 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700539 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800540 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700541
542 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700543 case CMD_HANDLE_USSD_REQUEST: {
544 request = (MainThreadRequest) msg.obj;
545 final Phone phone = getPhoneFromRequest(request);
546 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800547 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700548 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700549
Pengquan Menga1bb6272018-09-06 09:59:22 -0700550 if (!isUssdApiAllowed(request.subId)) {
551 // Carrier does not support use of this API, return failure.
552 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
553 UssdResponse response = new UssdResponse(ussdRequest, null);
554 Bundle returnData = new Bundle();
555 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
556 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700557
Pengquan Menga1bb6272018-09-06 09:59:22 -0700558 request.result = true;
559 notifyRequester(request);
560 return;
561 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700562
Pengquan Menga1bb6272018-09-06 09:59:22 -0700563 try {
564 request.result = phone != null
565 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
566 } catch (CallStateException cse) {
567 request.result = false;
568 }
569 // Wake up the requesting thread
570 notifyRequester(request);
571 break;
pkanwar32d516d2016-10-14 19:37:38 -0700572 }
573
Yorke Lee716f67e2015-06-17 15:39:16 -0700574 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700575 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700576 final Phone phone = getPhoneFromRequest(request);
577 request.result = phone != null ?
578 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
579 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700580 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700581 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700582 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700583 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700584
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700585 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700586 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700587 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000588 uiccPort = getUiccPortFromRequest(request);
589 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700590 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800591 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700592 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700593 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700594 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800595 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000596 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800597 iccArgument.channel, iccArgument.cla, iccArgument.command,
598 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
599 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700600 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700601 break;
602
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700603 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700604 ar = (AsyncResult) msg.obj;
605 request = (MainThreadRequest) ar.userObj;
606 if (ar.exception == null && ar.result != null) {
607 request.result = ar.result;
608 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800609 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700610 if (ar.result == null) {
611 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800612 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700613 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800614 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700615 } else {
616 loge("iccTransmitApduLogicalChannel: Unknown exception");
617 }
618 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700619 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700620 break;
621
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700622 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
623 request = (MainThreadRequest) msg.obj;
624 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000625 uiccPort = getUiccPortFromRequest(request);
626 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700627 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800628 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700629 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700630 } else {
631 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800632 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000633 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800634 iccArgument.cla, iccArgument.command, iccArgument.p1,
635 iccArgument.p2,
636 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700637 }
638 break;
639
640 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
641 ar = (AsyncResult) msg.obj;
642 request = (MainThreadRequest) ar.userObj;
643 if (ar.exception == null && ar.result != null) {
644 request.result = ar.result;
645 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800646 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700647 if (ar.result == null) {
648 loge("iccTransmitApduBasicChannel: Empty response");
649 } else if (ar.exception instanceof CommandException) {
650 loge("iccTransmitApduBasicChannel: CommandException: " +
651 ar.exception);
652 } else {
653 loge("iccTransmitApduBasicChannel: Unknown exception");
654 }
655 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700656 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700657 break;
658
659 case CMD_EXCHANGE_SIM_IO:
660 request = (MainThreadRequest) msg.obj;
661 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000662 uiccPort = getUiccPortFromRequest(request);
663 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700664 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800665 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700666 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700667 } else {
668 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
669 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000670 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700671 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
672 iccArgument.data, onCompleted);
673 }
674 break;
675
676 case EVENT_EXCHANGE_SIM_IO_DONE:
677 ar = (AsyncResult) msg.obj;
678 request = (MainThreadRequest) ar.userObj;
679 if (ar.exception == null && ar.result != null) {
680 request.result = ar.result;
681 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800682 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700683 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700684 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700685 break;
686
Derek Tan4d5e5c12014-02-04 11:54:58 -0800687 case CMD_SEND_ENVELOPE:
688 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000689 uiccPort = getUiccPortFromRequest(request);
690 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700691 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800692 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700693 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700694 } else {
695 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800696 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700697 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800698 break;
699
700 case EVENT_SEND_ENVELOPE_DONE:
701 ar = (AsyncResult) msg.obj;
702 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700703 if (ar.exception == null && ar.result != null) {
704 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800705 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800706 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700707 if (ar.result == null) {
708 loge("sendEnvelopeWithStatus: Empty response");
709 } else if (ar.exception instanceof CommandException) {
710 loge("sendEnvelopeWithStatus: CommandException: " +
711 ar.exception);
712 } else {
713 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
714 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800715 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700716 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800717 break;
718
Shishir Agrawal566b7612013-10-28 14:41:00 -0700719 case CMD_OPEN_CHANNEL:
720 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000721 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800722 IccLogicalChannelRequest openChannelRequest =
723 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000724 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700725 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800726 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800727 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700728 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700729 } else {
730 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800731 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
732 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700733 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700734 break;
735
736 case EVENT_OPEN_CHANNEL_DONE:
737 ar = (AsyncResult) msg.obj;
738 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700739 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700740 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700741 int[] result = (int[]) ar.result;
742 int channelId = result[0];
743 byte[] selectResponse = null;
744 if (result.length > 1) {
745 selectResponse = new byte[result.length - 1];
746 for (int i = 1; i < result.length; ++i) {
747 selectResponse[i - 1] = (byte) result[i];
748 }
749 }
750 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800751 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800752
753 uiccPort = getUiccPortFromRequest(request);
754 IccLogicalChannelRequest channelRequest =
755 (IccLogicalChannelRequest) request.argument;
756 channelRequest.channel = channelId;
757 uiccPort.onLogicalChannelOpened(channelRequest);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700758 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700759 if (ar.result == null) {
760 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700761 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700762 if (ar.exception != null) {
763 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
764 }
765
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700766 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700767 if (ar.exception instanceof CommandException) {
768 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800769 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700770 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700771 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700772 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700773 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700774 }
775 }
776 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800777 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700778 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700779 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700780 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700781 break;
782
783 case CMD_CLOSE_CHANNEL:
784 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000785 uiccPort = getUiccPortFromRequest(request);
786 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700787 loge("iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800788 // before this feature is enabled, this API should only return false if
789 // the operation fails instead of throwing runtime exception for
790 // backward-compatibility.
791 if (Compatibility.isChangeEnabled(ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE)) {
792 request.result = new IllegalArgumentException(
793 "iccCloseLogicalChannel: No UICC");
794 } else {
795 request.result = false;
796 }
797 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700798 } else {
799 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000800 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700801 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700802 break;
803
804 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800805 ar = (AsyncResult) msg.obj;
806 request = (MainThreadRequest) ar.userObj;
807 if (ar.exception == null) {
808 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800809 uiccPort = getUiccPortFromRequest(request);
810 final int channelId = (Integer) request.argument;
811 uiccPort.onLogicalChannelClosed(channelId);
Chen Xu540470b2021-12-14 17:15:47 -0800812 } else {
813 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800814 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800815 if (ar.exception instanceof CommandException) {
816 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
817 CommandException.Error error =
818 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800819 if (error == CommandException.Error.INVALID_ARGUMENTS) {
820 // should only throw exceptions from the binder threads.
821 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800822 "iccCloseLogicalChannel: invalid argument ");
823 }
824 } else {
825 loge("iccCloseLogicalChannel: Unknown exception");
826 }
Chen Xue9d737e2022-01-01 23:41:31 -0800827 // before this feature is enabled, this API should only return false if
828 // the operation fails instead of throwing runtime exception for
829 // backward-compatibility.
830 if (Compatibility.isChangeEnabled(ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE))
831 request.result = (exception != null) ? exception :
832 new IllegalStateException(
833 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800834 }
835 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800836 break;
837
838 case CMD_NV_READ_ITEM:
839 request = (MainThreadRequest) msg.obj;
840 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800841 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
842 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800843 break;
844
845 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700846 ar = (AsyncResult) msg.obj;
847 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800848 if (ar.exception == null && ar.result != null) {
849 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700850 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800851 request.result = "";
852 if (ar.result == null) {
853 loge("nvReadItem: Empty response");
854 } else if (ar.exception instanceof CommandException) {
855 loge("nvReadItem: CommandException: " +
856 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700857 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800858 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700859 }
860 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700861 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700862 break;
863
Jake Hambye994d462014-02-03 13:10:13 -0800864 case CMD_NV_WRITE_ITEM:
865 request = (MainThreadRequest) msg.obj;
866 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
867 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800868 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700869 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800870 break;
871
872 case EVENT_NV_WRITE_ITEM_DONE:
873 handleNullReturnEvent(msg, "nvWriteItem");
874 break;
875
876 case CMD_NV_WRITE_CDMA_PRL:
877 request = (MainThreadRequest) msg.obj;
878 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800879 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800880 break;
881
882 case EVENT_NV_WRITE_CDMA_PRL_DONE:
883 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
884 break;
885
chen xu6dac5ab2018-10-26 17:39:23 -0700886 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800887 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700888 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800889 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800890 break;
891
chen xu6dac5ab2018-10-26 17:39:23 -0700892 case EVENT_RESET_MODEM_CONFIG_DONE:
893 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800894 break;
895
Sooraj Sasindran37444802020-08-11 10:40:43 -0700896 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
897 request = (MainThreadRequest) msg.obj;
898 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
899 request);
900 Phone phone = getPhoneFromRequest(request);
901 if (phone != null) {
902 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
903 } else {
904 loge("isNRDualConnectivityEnabled: No phone object");
905 request.result = false;
906 notifyRequester(request);
907 }
908 break;
909 }
910
911 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
912 ar = (AsyncResult) msg.obj;
913 request = (MainThreadRequest) ar.userObj;
914 if (ar.exception == null && ar.result != null) {
915 request.result = ar.result;
916 } else {
917 // request.result must be set to something non-null
918 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700919 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700920 request.result = ar.result;
921 } else {
922 request.result = false;
923 }
924 if (ar.result == null) {
925 loge("isNRDualConnectivityEnabled: Empty response");
926 } else if (ar.exception instanceof CommandException) {
927 loge("isNRDualConnectivityEnabled: CommandException: "
928 + ar.exception);
929 } else {
930 loge("isNRDualConnectivityEnabled: Unknown exception");
931 }
932 }
933 notifyRequester(request);
934 break;
935
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700936 case CMD_IS_VONR_ENABLED: {
937 request = (MainThreadRequest) msg.obj;
938 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
939 request);
940 Phone phone = getPhoneFromRequest(request);
941 if (phone != null) {
942 phone.isVoNrEnabled(onCompleted, request.workSource);
943 } else {
944 loge("isVoNrEnabled: No phone object");
945 request.result = false;
946 notifyRequester(request);
947 }
948 break;
949 }
950
951 case EVENT_IS_VONR_ENABLED_DONE:
952 ar = (AsyncResult) msg.obj;
953 request = (MainThreadRequest) ar.userObj;
954 if (ar.exception == null && ar.result != null) {
955 request.result = ar.result;
956 } else {
957 // request.result must be set to something non-null
958 // for the calling thread to unblock
959 if (ar.result != null) {
960 request.result = ar.result;
961 } else {
962 request.result = false;
963 }
964 if (ar.result == null) {
965 loge("isVoNrEnabled: Empty response");
966 } else if (ar.exception instanceof CommandException) {
967 loge("isVoNrEnabled: CommandException: "
968 + ar.exception);
969 } else {
970 loge("isVoNrEnabled: Unknown exception");
971 }
972 }
973 notifyRequester(request);
974 break;
975
Sooraj Sasindran37444802020-08-11 10:40:43 -0700976 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
977 request = (MainThreadRequest) msg.obj;
978 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
979 Phone phone = getPhoneFromRequest(request);
980 if (phone != null) {
981 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
982 request.workSource);
983 } else {
984 loge("enableNrDualConnectivity: No phone object");
985 request.result =
986 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
987 notifyRequester(request);
988 }
989 break;
990 }
991
992 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
993 ar = (AsyncResult) msg.obj;
994 request = (MainThreadRequest) ar.userObj;
995 if (ar.exception == null) {
996 request.result =
997 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
998 } else {
999 request.result =
1000 TelephonyManager
1001 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1002 if (ar.exception instanceof CommandException) {
1003 CommandException.Error error =
1004 ((CommandException) (ar.exception)).getCommandError();
1005 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1006 request.result =
1007 TelephonyManager
1008 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001009 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1010 request.result =
1011 TelephonyManager
1012 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001013 }
1014 loge("enableNrDualConnectivity" + ": CommandException: "
1015 + ar.exception);
1016 } else {
1017 loge("enableNrDualConnectivity" + ": Unknown exception");
1018 }
1019 }
1020 notifyRequester(request);
1021 break;
1022 }
1023
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001024 case CMD_ENABLE_VONR: {
1025 request = (MainThreadRequest) msg.obj;
1026 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1027 Phone phone = getPhoneFromRequest(request);
1028 if (phone != null) {
1029 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1030 request.workSource);
1031 } else {
1032 loge("setVoNrEnabled: No phone object");
1033 request.result =
1034 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1035 notifyRequester(request);
1036 }
1037 break;
1038 }
1039
1040 case EVENT_ENABLE_VONR_DONE: {
1041 ar = (AsyncResult) msg.obj;
1042 request = (MainThreadRequest) ar.userObj;
1043 if (ar.exception == null) {
1044 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1045 } else {
1046 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1047 if (ar.exception instanceof CommandException) {
1048 CommandException.Error error =
1049 ((CommandException) (ar.exception)).getCommandError();
1050 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1051 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1052 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1053 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1054 } else {
1055 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1056 }
1057 loge("setVoNrEnabled" + ": CommandException: "
1058 + ar.exception);
1059 } else {
1060 loge("setVoNrEnabled" + ": Unknown exception");
1061 }
1062 }
1063 notifyRequester(request);
1064 break;
1065 }
1066
SongFerngWang3ef3e072020-12-21 16:41:52 +08001067 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001068 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001069 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1070 request);
1071 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001072 break;
1073
SongFerngWang3ef3e072020-12-21 16:41:52 +08001074 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001075 ar = (AsyncResult) msg.obj;
1076 request = (MainThreadRequest) ar.userObj;
1077 if (ar.exception == null && ar.result != null) {
1078 request.result = ar.result; // Integer
1079 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301080 // request.result must be set to something non-null
1081 // for the calling thread to unblock
1082 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001083 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001084 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001085 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001086 loge("getAllowedNetworkTypesBitmask: CommandException: "
1087 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001088 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001089 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001090 }
1091 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001092 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001093 break;
1094
SongFerngWang3ef3e072020-12-21 16:41:52 +08001095 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001096 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001097 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1098 request);
1099 Pair<Integer, Long> reasonWithNetworkTypes =
1100 (Pair<Integer, Long>) request.argument;
1101 getPhoneFromRequest(request).setAllowedNetworkTypes(
1102 reasonWithNetworkTypes.first,
1103 reasonWithNetworkTypes.second,
1104 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001105 break;
1106
SongFerngWang3ef3e072020-12-21 16:41:52 +08001107 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1108 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001109 break;
1110
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001111 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1112 request = (MainThreadRequest)msg.obj;
1113 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001114 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001115 break;
1116
1117 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1118 ar = (AsyncResult)msg.obj;
1119 request = (MainThreadRequest)ar.userObj;
1120 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001121 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001122 break;
1123
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001124 case CMD_SET_VOICEMAIL_NUMBER:
1125 request = (MainThreadRequest) msg.obj;
1126 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1127 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001128 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1129 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001130 break;
1131
1132 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1133 handleNullReturnEvent(msg, "setVoicemailNumber");
1134 break;
1135
Stuart Scott54788802015-03-30 13:18:01 -07001136 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1137 request = (MainThreadRequest) msg.obj;
1138 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1139 request);
1140 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1141 break;
1142
1143 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1144 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1145 break;
1146
Shishir Agrawal302c8692015-06-19 13:49:39 -07001147 case CMD_PERFORM_NETWORK_SCAN:
1148 request = (MainThreadRequest) msg.obj;
1149 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1150 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1151 break;
1152
Hall Liu27d24262020-09-18 19:04:59 -07001153 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001154 request = (MainThreadRequest) msg.obj;
1155 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001156 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1157 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1158 request.argument;
1159 int callForwardingReason = args.first;
1160 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001161 break;
Hall Liu27d24262020-09-18 19:04:59 -07001162 }
1163 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001164 ar = (AsyncResult) msg.obj;
1165 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001166 TelephonyManager.CallForwardingInfoCallback callback =
1167 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1168 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001169 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001170 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001171 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1172 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1173 // Service Class is a bit mask per 3gpp 27.007. Search for
1174 // any service for voice call.
1175 if ((callForwardInfo.serviceClass
1176 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001177 callForwardingInfo = new CallForwardingInfo(
1178 callForwardInfo.status
1179 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001180 callForwardInfo.reason,
1181 callForwardInfo.number,
1182 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001183 break;
1184 }
1185 }
1186 // Didn't find a call forward info for voice call.
1187 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001188 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1189 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001190 }
Hall Liu27d24262020-09-18 19:04:59 -07001191 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001192 } else {
1193 if (ar.result == null) {
1194 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1195 }
1196 if (ar.exception != null) {
1197 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1198 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001199 int errorCode = TelephonyManager
1200 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001201 if (ar.exception instanceof CommandException) {
1202 CommandException.Error error =
1203 ((CommandException) (ar.exception)).getCommandError();
1204 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001205 errorCode = TelephonyManager
1206 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001207 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001208 errorCode = TelephonyManager
1209 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001210 }
1211 }
Hall Liu27d24262020-09-18 19:04:59 -07001212 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001213 }
Shuo Qian4a594052020-01-23 11:59:30 -08001214 break;
Hall Liu27d24262020-09-18 19:04:59 -07001215 }
Shuo Qian4a594052020-01-23 11:59:30 -08001216
Hall Liu27d24262020-09-18 19:04:59 -07001217 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001218 request = (MainThreadRequest) msg.obj;
1219 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001220 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001221 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001222 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1223 request.argument).first;
1224 request.phone.setCallForwardingOption(
1225 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001226 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001227 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001228 callForwardingInfoToSet.getReason(),
1229 callForwardingInfoToSet.getNumber(),
1230 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1231 break;
Hall Liu27d24262020-09-18 19:04:59 -07001232 }
Shuo Qian4a594052020-01-23 11:59:30 -08001233
Hall Liu27d24262020-09-18 19:04:59 -07001234 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001235 ar = (AsyncResult) msg.obj;
1236 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001237 Consumer<Integer> callback =
1238 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1239 request.argument).second;
1240 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001241 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001242 int errorCode = TelephonyManager.CallForwardingInfoCallback
1243 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001244 if (ar.exception instanceof CommandException) {
1245 CommandException.Error error =
1246 ((CommandException) (ar.exception)).getCommandError();
1247 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001248 errorCode = TelephonyManager.CallForwardingInfoCallback
1249 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001250 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001251 errorCode = TelephonyManager.CallForwardingInfoCallback
1252 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001253 }
1254 }
1255 callback.accept(errorCode);
1256 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001257 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001258 }
Shuo Qian4a594052020-01-23 11:59:30 -08001259 break;
Hall Liu27d24262020-09-18 19:04:59 -07001260 }
Shuo Qian4a594052020-01-23 11:59:30 -08001261
Hall Liu27d24262020-09-18 19:04:59 -07001262 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001263 request = (MainThreadRequest) msg.obj;
1264 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1265 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1266 break;
Hall Liu27d24262020-09-18 19:04:59 -07001267 }
Shuo Qian4a594052020-01-23 11:59:30 -08001268
Hall Liu27d24262020-09-18 19:04:59 -07001269 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001270 ar = (AsyncResult) msg.obj;
1271 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001272 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001273 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1274 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001275 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001276 // Service Class is a bit mask per 3gpp 27.007.
1277 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001278 if (callForwardResults.length > 1
1279 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001280 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001281 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001282 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1283 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001284 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001285 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001286 }
1287 } else {
1288 if (ar.result == null) {
1289 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1290 }
1291 if (ar.exception != null) {
1292 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1293 }
1294 if (ar.exception instanceof CommandException) {
1295 CommandException.Error error =
1296 ((CommandException) (ar.exception)).getCommandError();
1297 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1298 callForwardingStatus =
1299 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1300 }
1301 }
1302 }
Hall Liu27d24262020-09-18 19:04:59 -07001303 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001304 break;
Hall Liu27d24262020-09-18 19:04:59 -07001305 }
Shuo Qian4a594052020-01-23 11:59:30 -08001306
Hall Liu27d24262020-09-18 19:04:59 -07001307 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001308 request = (MainThreadRequest) msg.obj;
1309 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001310 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1311 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001312 break;
Hall Liu27d24262020-09-18 19:04:59 -07001313 }
Shuo Qian4a594052020-01-23 11:59:30 -08001314
Hall Liu27d24262020-09-18 19:04:59 -07001315 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001316 ar = (AsyncResult) msg.obj;
1317 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001318 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1319 Consumer<Integer> callback =
1320 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1321 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001322 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001323 if (ar.exception instanceof CommandException) {
1324 CommandException.Error error =
1325 ((CommandException) (ar.exception)).getCommandError();
1326 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1327 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1328 } else {
1329 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1330 }
1331 } else {
1332 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1333 }
1334 } else {
1335 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1336 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001337 }
Shuo Qian4a594052020-01-23 11:59:30 -08001338 break;
Hall Liu27d24262020-09-18 19:04:59 -07001339 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001340 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1341 ar = (AsyncResult) msg.obj;
1342 request = (MainThreadRequest) ar.userObj;
1343 CellNetworkScanResult cellScanResult;
1344 if (ar.exception == null && ar.result != null) {
1345 cellScanResult = new CellNetworkScanResult(
1346 CellNetworkScanResult.STATUS_SUCCESS,
1347 (List<OperatorInfo>) ar.result);
1348 } else {
1349 if (ar.result == null) {
1350 loge("getCellNetworkScanResults: Empty response");
1351 }
1352 if (ar.exception != null) {
1353 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1354 }
1355 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1356 if (ar.exception instanceof CommandException) {
1357 CommandException.Error error =
1358 ((CommandException) (ar.exception)).getCommandError();
1359 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1360 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1361 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1362 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1363 }
1364 }
1365 cellScanResult = new CellNetworkScanResult(errorCode, null);
1366 }
1367 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001368 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001369 break;
1370
1371 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1372 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001373 ManualNetworkSelectionArgument selArg =
1374 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001375 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1376 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001377 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1378 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001379 break;
1380
1381 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001382 ar = (AsyncResult) msg.obj;
1383 request = (MainThreadRequest) ar.userObj;
1384 if (ar.exception == null) {
1385 request.result = true;
1386 } else {
1387 request.result = false;
1388 loge("setNetworkSelectionModeManual " + ar.exception);
1389 }
1390 notifyRequester(request);
1391 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001392 break;
1393
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001394 case CMD_GET_MODEM_ACTIVITY_INFO:
1395 request = (MainThreadRequest) msg.obj;
1396 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001397 if (defaultPhone != null) {
1398 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001399 } else {
1400 ResultReceiver result = (ResultReceiver) request.argument;
1401 Bundle bundle = new Bundle();
1402 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001403 new ModemActivityInfo(0, 0, 0,
1404 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001405 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001406 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001407 break;
1408
Hall Liud0f208c2020-10-14 16:54:44 -07001409 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001410 ar = (AsyncResult) msg.obj;
1411 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001412 ResultReceiver result = (ResultReceiver) request.argument;
1413
Hall Liud0f208c2020-10-14 16:54:44 -07001414 ModemActivityInfo ret = null;
1415 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001416 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001417 // Update the last modem activity info and the result of the request.
1418 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1419 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001420 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001421 int[] txTimeMs = info.getTransmitTimeMillis();
1422 int[] lastModemTxTimeMs = mLastModemActivityInfo
1423 .getTransmitTimeMillis();
1424 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1425 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1426 }
Hall Liu49656c02020-10-09 19:00:11 -07001427 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001428 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1429 + mLastModemActivityInfo.getSleepTimeMillis());
1430 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1431 + mLastModemActivityInfo.getIdleTimeMillis());
1432 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1433 mLastModemActivityInfo.setReceiveTimeMillis(
1434 info.getReceiveTimeMillis()
1435 + mLastModemActivityInfo.getReceiveTimeMillis());
1436 }
Hall Liu49656c02020-10-09 19:00:11 -07001437 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001438 mLastModemActivityInfo.getSleepTimeMillis(),
1439 mLastModemActivityInfo.getIdleTimeMillis(),
1440 mLastModemActivityInfo.getTransmitTimeMillis(),
1441 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001442 } else {
1443 if (ar.result == null) {
1444 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001445 error = TelephonyManager.ModemActivityInfoException
1446 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001447 } else if (ar.exception instanceof CommandException) {
1448 loge("queryModemActivityInfo: CommandException: " +
1449 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001450 error = TelephonyManager.ModemActivityInfoException
1451 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001452 } else {
1453 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001454 error = TelephonyManager.ModemActivityInfoException
1455 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001456 }
1457 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001458 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001459 if (ret != null) {
1460 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1461 } else {
1462 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1463 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001464 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001465 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001466 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001467 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001468
Meng Wang1a7c35a2016-05-05 20:56:15 -07001469 case CMD_SET_ALLOWED_CARRIERS:
1470 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001471 CarrierRestrictionRules argument =
1472 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001473 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001474 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001475 break;
1476
1477 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1478 ar = (AsyncResult) msg.obj;
1479 request = (MainThreadRequest) ar.userObj;
1480 if (ar.exception == null && ar.result != null) {
1481 request.result = ar.result;
1482 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001483 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1484 if (ar.exception instanceof CommandException) {
1485 loge("setAllowedCarriers: CommandException: " + ar.exception);
1486 CommandException.Error error =
1487 ((CommandException) (ar.exception)).getCommandError();
1488 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1489 request.result =
1490 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1491 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001492 } else {
1493 loge("setAllowedCarriers: Unknown exception");
1494 }
1495 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001496 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001497 break;
1498
1499 case CMD_GET_ALLOWED_CARRIERS:
1500 request = (MainThreadRequest) msg.obj;
1501 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001502 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001503 break;
1504
1505 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1506 ar = (AsyncResult) msg.obj;
1507 request = (MainThreadRequest) ar.userObj;
1508 if (ar.exception == null && ar.result != null) {
1509 request.result = ar.result;
1510 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001511 request.result = new IllegalStateException(
1512 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001513 if (ar.result == null) {
1514 loge("getAllowedCarriers: Empty response");
1515 } else if (ar.exception instanceof CommandException) {
1516 loge("getAllowedCarriers: CommandException: " +
1517 ar.exception);
1518 } else {
1519 loge("getAllowedCarriers: Unknown exception");
1520 }
1521 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001522 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001523 break;
1524
Nathan Haroldb3014052017-01-25 15:57:32 -08001525 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1526 ar = (AsyncResult) msg.obj;
1527 request = (MainThreadRequest) ar.userObj;
1528 if (ar.exception == null && ar.result != null) {
1529 request.result = ar.result;
1530 } else {
1531 request.result = new IllegalArgumentException(
1532 "Failed to retrieve Forbidden Plmns");
1533 if (ar.result == null) {
1534 loge("getForbiddenPlmns: Empty response");
1535 } else {
1536 loge("getForbiddenPlmns: Unknown exception");
1537 }
1538 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001539 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001540 break;
1541
1542 case CMD_GET_FORBIDDEN_PLMNS:
1543 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001544 uiccPort = getUiccPortFromRequest(request);
1545 if (uiccPort == null) {
1546 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001547 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001548 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001549 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001550 break;
1551 }
1552 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001553 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001554 if (uiccApp == null) {
1555 loge("getForbiddenPlmns() no app with specified type -- "
1556 + appType);
1557 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001558 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001559 break;
1560 } else {
1561 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1562 + " specified type -- " + appType);
1563 }
1564 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1565 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1566 onCompleted);
1567 break;
1568
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001569 case CMD_SWITCH_SLOTS:
1570 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001571 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001572 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001573 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001574 break;
1575
1576 case EVENT_SWITCH_SLOTS_DONE:
1577 ar = (AsyncResult) msg.obj;
1578 request = (MainThreadRequest) ar.userObj;
1579 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001580 notifyRequester(request);
1581 break;
1582 case CMD_GET_NETWORK_SELECTION_MODE:
1583 request = (MainThreadRequest) msg.obj;
1584 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1585 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1586 break;
1587
1588 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1589 ar = (AsyncResult) msg.obj;
1590 request = (MainThreadRequest) ar.userObj;
1591 if (ar.exception != null) {
1592 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1593 } else {
1594 int mode = ((int[]) ar.result)[0];
1595 if (mode == 0) {
1596 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1597 } else {
1598 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1599 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001600 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001601 notifyRequester(request);
1602 break;
1603 case CMD_GET_CDMA_ROAMING_MODE:
1604 request = (MainThreadRequest) msg.obj;
1605 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1606 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1607 break;
1608 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1609 ar = (AsyncResult) msg.obj;
1610 request = (MainThreadRequest) ar.userObj;
1611 if (ar.exception != null) {
1612 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1613 } else {
1614 request.result = ((int[]) ar.result)[0];
1615 }
1616 notifyRequester(request);
1617 break;
1618 case CMD_SET_CDMA_ROAMING_MODE:
1619 request = (MainThreadRequest) msg.obj;
1620 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1621 int mode = (int) request.argument;
1622 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1623 break;
1624 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1625 ar = (AsyncResult) msg.obj;
1626 request = (MainThreadRequest) ar.userObj;
1627 request.result = ar.exception == null;
1628 notifyRequester(request);
1629 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001630 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1631 request = (MainThreadRequest) msg.obj;
1632 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1633 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1634 break;
1635 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1636 ar = (AsyncResult) msg.obj;
1637 request = (MainThreadRequest) ar.userObj;
1638 if (ar.exception != null) {
1639 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1640 } else {
1641 request.result = ((int[]) ar.result)[0];
1642 }
1643 notifyRequester(request);
1644 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001645 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1646 request = (MainThreadRequest) msg.obj;
1647 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1648 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001649 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1650 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001651 break;
1652 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1653 ar = (AsyncResult) msg.obj;
1654 request = (MainThreadRequest) ar.userObj;
1655 request.result = ar.exception == null;
1656 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001657 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001658 case CMD_GET_ALL_CELL_INFO:
1659 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001660 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001661 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001662 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001663 case EVENT_GET_ALL_CELL_INFO_DONE:
1664 ar = (AsyncResult) msg.obj;
1665 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001666 // If a timeout occurs, the response will be null
1667 request.result = (ar.exception == null && ar.result != null)
1668 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001669 synchronized (request) {
1670 request.notifyAll();
1671 }
1672 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001673 case CMD_REQUEST_CELL_INFO_UPDATE:
1674 request = (MainThreadRequest) msg.obj;
1675 request.phone.requestCellInfoUpdate(request.workSource,
1676 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1677 break;
1678 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1679 ar = (AsyncResult) msg.obj;
1680 request = (MainThreadRequest) ar.userObj;
1681 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1682 try {
1683 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001684 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001685 cb.onError(
1686 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1687 ar.exception.getClass().getName(),
1688 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001689 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001690 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001691 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001692 } else {
1693 // use the result as returned
1694 cb.onCellInfo((List<CellInfo>) ar.result);
1695 }
1696 } catch (RemoteException re) {
1697 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1698 }
1699 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001700 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001701 request = (MainThreadRequest) msg.obj;
1702 WorkSource ws = (WorkSource) request.argument;
1703 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001704 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001705 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001706 }
1707 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001708 ar = (AsyncResult) msg.obj;
1709 request = (MainThreadRequest) ar.userObj;
1710 if (ar.exception == null) {
1711 request.result = ar.result;
1712 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001713 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001714 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001715 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001716 }
1717
1718 synchronized (request) {
1719 request.notifyAll();
1720 }
1721 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001722 }
chen xu6dac5ab2018-10-26 17:39:23 -07001723 case CMD_MODEM_REBOOT:
1724 request = (MainThreadRequest) msg.obj;
1725 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001726 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001727 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001728 case EVENT_CMD_MODEM_REBOOT_DONE:
1729 handleNullReturnEvent(msg, "rebootModem");
1730 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001731 case CMD_REQUEST_ENABLE_MODEM:
1732 request = (MainThreadRequest) msg.obj;
1733 boolean enable = (boolean) request.argument;
1734 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001735 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001736 PhoneConfigurationManager.getInstance()
1737 .enablePhone(request.phone, enable, onCompleted);
1738 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001739 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001740 ar = (AsyncResult) msg.obj;
1741 request = (MainThreadRequest) ar.userObj;
1742 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001743 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001744 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001745 if ((boolean) request.result) {
1746 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1747 updateModemStateMetrics();
1748 } else {
1749 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1750 + ar.exception);
1751 }
1752 notifyRequester(request);
1753 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001754 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001755 case CMD_GET_MODEM_STATUS:
1756 request = (MainThreadRequest) msg.obj;
1757 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1758 PhoneConfigurationManager.getInstance()
1759 .getPhoneStatusFromModem(request.phone, onCompleted);
1760 break;
1761 case EVENT_GET_MODEM_STATUS_DONE:
1762 ar = (AsyncResult) msg.obj;
1763 request = (MainThreadRequest) ar.userObj;
1764 int id = request.phone.getPhoneId();
1765 if (ar.exception == null && ar.result != null) {
1766 request.result = ar.result;
1767 //update the cache as modem status has changed
1768 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1769 (boolean) request.result);
1770 } else {
1771 // Return true if modem status cannot be retrieved. For most cases,
1772 // modem status is on. And for older version modems, GET_MODEM_STATUS
1773 // and disable modem are not supported. Modem is always on.
1774 // TODO: this should be fixed in R to support a third
1775 // status UNKNOWN b/131631629
1776 request.result = true;
1777 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1778 + ar.exception);
1779 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001780 notifyRequester(request);
1781 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001782 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1783 request = (MainThreadRequest) msg.obj;
1784 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1785 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1786 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1787 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1788 break;
1789 }
1790 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1791 ar = (AsyncResult) msg.obj;
1792 request = (MainThreadRequest) ar.userObj;
1793 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1794 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1795 args.second.accept(ar.exception == null);
1796 notifyRequester(request);
1797 break;
1798 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001799 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1800 request = (MainThreadRequest) msg.obj;
1801 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1802 Phone phone = getPhoneFromRequest(request);
1803 if (phone != null) {
1804 phone.getSystemSelectionChannels(onCompleted);
1805 } else {
1806 loge("getSystemSelectionChannels: No phone object");
1807 request.result = new ArrayList<RadioAccessSpecifier>();
1808 notifyRequester(request);
1809 }
1810 break;
1811 }
1812 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1813 ar = (AsyncResult) msg.obj;
1814 request = (MainThreadRequest) ar.userObj;
1815 if (ar.exception == null && ar.result != null) {
1816 request.result = ar.result;
1817 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001818 request.result = new IllegalStateException(
1819 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001820 if (ar.result == null) {
1821 loge("getSystemSelectionChannels: Empty response");
1822 } else {
1823 loge("getSystemSelectionChannels: Unknown exception");
1824 }
1825 }
1826 notifyRequester(request);
1827 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001828 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1829 ar = (AsyncResult) msg.obj;
1830 request = (MainThreadRequest) ar.userObj;
1831 if (ar.exception == null && ar.result != null) {
1832 request.result = ar.result;
1833 } else {
1834 request.result = -1;
1835 loge("Failed to set Forbidden Plmns");
1836 if (ar.result == null) {
1837 loge("setForbidenPlmns: Empty response");
1838 } else if (ar.exception != null) {
1839 loge("setForbiddenPlmns: Exception: " + ar.exception);
1840 request.result = -1;
1841 } else {
1842 loge("setForbiddenPlmns: Unknown exception");
1843 }
1844 }
1845 notifyRequester(request);
1846 break;
1847 case CMD_SET_FORBIDDEN_PLMNS:
1848 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001849 uiccPort = getUiccPortFromRequest(request);
1850 if (uiccPort == null) {
1851 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001852 request.result = -1;
1853 notifyRequester(request);
1854 break;
1855 }
1856 Pair<Integer, List<String>> setFplmnsArgs =
1857 (Pair<Integer, List<String>>) request.argument;
1858 appType = setFplmnsArgs.first;
1859 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001860 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001861 if (uiccApp == null) {
1862 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1863 request.result = -1;
1864 loge("Failed to get UICC App");
1865 notifyRequester(request);
1866 } else {
1867 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1868 ((SIMRecords) uiccApp.getIccRecords())
1869 .setForbiddenPlmns(onCompleted, fplmns);
1870 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001871 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001872 case CMD_ERASE_MODEM_CONFIG:
1873 request = (MainThreadRequest) msg.obj;
1874 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1875 defaultPhone.eraseModemConfig(onCompleted);
1876 break;
1877 case EVENT_ERASE_MODEM_CONFIG_DONE:
1878 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001879 break;
zoey chene02881a2019-12-30 16:11:23 +08001880
Kai Shif70f46f2021-03-03 13:59:46 -08001881 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1882 request = (MainThreadRequest) msg.obj;
1883 request.result = defaultPhone.eraseDataInSharedPreferences();
1884 notifyRequester(request);
1885 break;
1886
zoey chene02881a2019-12-30 16:11:23 +08001887 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1888 request = (MainThreadRequest) msg.obj;
1889 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1890 Pair<String, String> changed = (Pair<String, String>) request.argument;
1891 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1892 changed.first, changed.second, onCompleted);
1893 break;
1894 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1895 ar = (AsyncResult) msg.obj;
1896 request = (MainThreadRequest) ar.userObj;
1897 if (ar.exception == null) {
1898 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001899 // If the operation is successful, update the PIN storage
1900 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1901 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001902 UiccController.getInstance().getPinStorage()
1903 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001904 } else {
1905 request.result = msg.arg1;
1906 }
1907 notifyRequester(request);
1908 break;
1909
Michele Berionne5e411512020-11-13 02:36:59 +00001910 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001911 request = (MainThreadRequest) msg.obj;
1912 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1913 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1914 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1915 enabled.first, enabled.second, onCompleted);
1916 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001917 }
zoey chene02881a2019-12-30 16:11:23 +08001918 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1919 ar = (AsyncResult) msg.obj;
1920 request = (MainThreadRequest) ar.userObj;
1921 if (ar.exception == null) {
1922 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001923 // If the operation is successful, update the PIN storage
1924 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1925 int phoneId = getPhoneFromRequest(request).getPhoneId();
1926 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001927 UiccController.getInstance().getPinStorage()
1928 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001929 } else {
1930 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1931 }
zoey chene02881a2019-12-30 16:11:23 +08001932 } else {
1933 request.result = msg.arg1;
1934 }
Michele Berionne5e411512020-11-13 02:36:59 +00001935
1936
zoey chene02881a2019-12-30 16:11:23 +08001937 notifyRequester(request);
1938 break;
1939
Peter Wangdafb9ac2020-01-15 14:13:38 -08001940 case MSG_NOTIFY_USER_ACTIVITY:
1941 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001942 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001943 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1944 getDefaultPhone().getContext().sendBroadcastAsUser(
1945 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1946 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001947
1948 case CMD_SET_DATA_THROTTLING: {
1949 request = (MainThreadRequest) msg.obj;
1950 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1951 DataThrottlingRequest dataThrottlingRequest =
1952 (DataThrottlingRequest) request.argument;
1953 Phone phone = getPhoneFromRequest(request);
1954 if (phone != null) {
1955 phone.setDataThrottling(onCompleted,
1956 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1957 dataThrottlingRequest.getCompletionDurationMillis());
1958 } else {
1959 loge("setDataThrottling: No phone object");
1960 request.result =
1961 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1962 notifyRequester(request);
1963 }
1964
1965 break;
1966 }
1967 case EVENT_SET_DATA_THROTTLING_DONE:
1968 ar = (AsyncResult) msg.obj;
1969 request = (MainThreadRequest) ar.userObj;
1970
1971 if (ar.exception == null) {
1972 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1973 } else if (ar.exception instanceof CommandException) {
1974 loge("setDataThrottling: CommandException: " + ar.exception);
1975 CommandException.Error error =
1976 ((CommandException) (ar.exception)).getCommandError();
1977
1978 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1979 request.result = TelephonyManager
1980 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1981 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1982 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001983 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1984 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001985 } else {
1986 request.result =
1987 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1988 }
1989 } else {
1990 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1991 }
1992 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1993 notifyRequester(request);
1994 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001995
1996 case CMD_SET_SIM_POWER: {
1997 request = (MainThreadRequest) msg.obj;
1998 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1999 request = (MainThreadRequest) msg.obj;
2000 int stateToSet =
2001 ((Pair<Integer, IIntegerConsumer>)
2002 request.argument).first;
2003 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2004 break;
2005 }
2006 case EVENT_SET_SIM_POWER_DONE: {
2007 ar = (AsyncResult) msg.obj;
2008 request = (MainThreadRequest) ar.userObj;
2009 IIntegerConsumer callback =
2010 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2011 if (ar.exception != null) {
2012 loge("setSimPower exception: " + ar.exception);
2013 int errorCode = TelephonyManager.CallForwardingInfoCallback
2014 .RESULT_ERROR_UNKNOWN;
2015 if (ar.exception instanceof CommandException) {
2016 CommandException.Error error =
2017 ((CommandException) (ar.exception)).getCommandError();
2018 if (error == CommandException.Error.SIM_ERR) {
2019 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2020 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2021 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2022 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2023 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2024 } else {
2025 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2026 }
2027 }
2028 try {
2029 callback.accept(errorCode);
2030 } catch (RemoteException e) {
2031 // Ignore if the remote process is no longer available to call back.
2032 Log.w(LOG_TAG, "setSimPower: callback not available.");
2033 }
2034 } else {
2035 try {
2036 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2037 } catch (RemoteException e) {
2038 // Ignore if the remote process is no longer available to call back.
2039 Log.w(LOG_TAG, "setSimPower: callback not available.");
2040 }
2041 }
2042 break;
2043 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002044 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2045 request = (MainThreadRequest) msg.obj;
2046
2047 final Phone phone = getPhoneFromRequest(request);
2048 if (phone == null || phone.getServiceStateTracker() == null) {
2049 request.result = new IllegalStateException("Phone or SST is null");
2050 notifyRequester(request);
2051 break;
2052 }
2053
2054 Pair<Integer, SignalStrengthUpdateRequest> pair =
2055 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2056 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2057 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002058 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002059 request.subId, pair.first /*callingUid*/,
2060 pair.second /*request*/, onCompleted);
2061 break;
2062 }
2063 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2064 ar = (AsyncResult) msg.obj;
2065 request = (MainThreadRequest) ar.userObj;
2066 // request.result will be the exception of ar if present, true otherwise.
2067 // Be cautious not to leave result null which will wait() forever
2068 request.result = ar.exception != null ? ar.exception : true;
2069 notifyRequester(request);
2070 break;
2071 }
2072 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2073 request = (MainThreadRequest) msg.obj;
2074
2075 Phone phone = getPhoneFromRequest(request);
2076 if (phone == null || phone.getServiceStateTracker() == null) {
2077 request.result = new IllegalStateException("Phone or SST is null");
2078 notifyRequester(request);
2079 break;
2080 }
2081
2082 Pair<Integer, SignalStrengthUpdateRequest> pair =
2083 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2084 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2085 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002086 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002087 request.subId, pair.first /*callingUid*/,
2088 pair.second /*request*/, onCompleted);
2089 break;
2090 }
2091 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2092 ar = (AsyncResult) msg.obj;
2093 request = (MainThreadRequest) ar.userObj;
2094 request.result = ar.exception != null ? ar.exception : true;
2095 notifyRequester(request);
2096 break;
2097 }
Jordan Liu109698e2020-11-24 14:50:34 -08002098
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002099 case CMD_GET_SLICING_CONFIG: {
2100 request = (MainThreadRequest) msg.obj;
2101 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2102 request.phone.getSlicingConfig(onCompleted);
2103 break;
2104 }
2105 case EVENT_GET_SLICING_CONFIG_DONE: {
2106 ar = (AsyncResult) msg.obj;
2107 request = (MainThreadRequest) ar.userObj;
2108 ResultReceiver result = (ResultReceiver) request.argument;
2109
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002110 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002111 Bundle bundle = new Bundle();
2112 int resultCode = 0;
2113 if (ar.exception != null) {
2114 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2115 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002116 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002117 } else if (ar.result == null) {
2118 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002119 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002120 } else {
2121 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002122 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2123 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002124 }
2125
2126 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002127 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002128 }
2129 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2130 result.send(resultCode, bundle);
2131 notifyRequester(request);
2132 break;
2133 }
2134
Michele Berionne5e411512020-11-13 02:36:59 +00002135 case CMD_PREPARE_UNATTENDED_REBOOT:
2136 request = (MainThreadRequest) msg.obj;
2137 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002138 UiccController.getInstance().getPinStorage()
2139 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002140 notifyRequester(request);
2141 break;
2142
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002143 default:
2144 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2145 break;
2146 }
2147 }
Jake Hambye994d462014-02-03 13:10:13 -08002148
Pengquan Menga1bb6272018-09-06 09:59:22 -07002149 private void notifyRequester(MainThreadRequest request) {
2150 synchronized (request) {
2151 request.notifyAll();
2152 }
2153 }
2154
Jake Hambye994d462014-02-03 13:10:13 -08002155 private void handleNullReturnEvent(Message msg, String command) {
2156 AsyncResult ar = (AsyncResult) msg.obj;
2157 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2158 if (ar.exception == null) {
2159 request.result = true;
2160 } else {
2161 request.result = false;
2162 if (ar.exception instanceof CommandException) {
2163 loge(command + ": CommandException: " + ar.exception);
2164 } else {
2165 loge(command + ": Unknown exception");
2166 }
2167 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002168 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002169 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002170 }
2171
2172 /**
2173 * Posts the specified command to be executed on the main thread,
2174 * waits for the request to complete, and returns the result.
2175 * @see #sendRequestAsync
2176 */
2177 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002178 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2179 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002180 }
2181
2182 /**
2183 * Posts the specified command to be executed on the main thread,
2184 * waits for the request to complete, and returns the result.
2185 * @see #sendRequestAsync
2186 */
2187 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2188 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002189 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002190 }
2191
2192 /**
2193 * Posts the specified command to be executed on the main thread,
2194 * waits for the request to complete, and returns the result.
2195 * @see #sendRequestAsync
2196 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002197 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002198 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2199 }
2200
2201 /**
2202 * Posts the specified command to be executed on the main thread,
2203 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2204 * if not timeout or null otherwise.
2205 * @see #sendRequestAsync
2206 */
2207 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2208 long timeoutInMs) {
2209 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002210 }
2211
2212 /**
2213 * Posts the specified command to be executed on the main thread,
2214 * waits for the request to complete, and returns the result.
2215 * @see #sendRequestAsync
2216 */
Nathan Harold92bed182018-10-12 18:16:49 -07002217 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002218 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002219 }
2220
2221 /**
2222 * Posts the specified command to be executed on the main thread,
2223 * waits for the request to complete, and returns the result.
2224 * @see #sendRequestAsync
2225 */
2226 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002227 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2228 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002229 }
2230
2231 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002232 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2233 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2234 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002235 * @see #sendRequestAsync
2236 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002237 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2238 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002239 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2240 throw new RuntimeException("This method will deadlock if called from the main thread.");
2241 }
2242
Nathan Harold92bed182018-10-12 18:16:49 -07002243 MainThreadRequest request = null;
2244 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2245 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2246 } else if (phone != null) {
2247 request = new MainThreadRequest(argument, phone, workSource);
2248 } else {
2249 request = new MainThreadRequest(argument, subId, workSource);
2250 }
2251
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002252 Message msg = mMainThreadHandler.obtainMessage(command, request);
2253 msg.sendToTarget();
2254
Rambo Wang0f050d82021-02-12 11:43:36 -08002255
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002256 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002257 if (timeoutInMs >= 0) {
2258 // Wait for at least timeoutInMs before returning null request result
2259 long now = SystemClock.elapsedRealtime();
2260 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002261 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002262 try {
2263 request.wait(deadline - now);
2264 } catch (InterruptedException e) {
2265 // Do nothing, go back and check if request is completed or timeout
2266 } finally {
2267 now = SystemClock.elapsedRealtime();
2268 }
2269 }
2270 } else {
2271 // Wait for the request to complete
2272 while (request.result == null) {
2273 try {
2274 request.wait();
2275 } catch (InterruptedException e) {
2276 // Do nothing, go back and wait until the request is complete
2277 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002278 }
2279 }
2280 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002281 if (request.result == null) {
2282 Log.wtf(LOG_TAG,
2283 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2284 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002285 return request.result;
2286 }
2287
2288 /**
2289 * Asynchronous ("fire and forget") version of sendRequest():
2290 * Posts the specified command to be executed on the main thread, and
2291 * returns immediately.
2292 * @see #sendRequest
2293 */
2294 private void sendRequestAsync(int command) {
2295 mMainThreadHandler.sendEmptyMessage(command);
2296 }
2297
2298 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002299 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002300 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002301 */
2302 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002303 sendRequestAsync(command, argument, null, null);
2304 }
2305
2306 /**
2307 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2308 * @see {@link #sendRequest(int,Object)}
2309 */
2310 private void sendRequestAsync(
2311 int command, Object argument, Phone phone, WorkSource workSource) {
2312 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002313 Message msg = mMainThreadHandler.obtainMessage(command, request);
2314 msg.sendToTarget();
2315 }
2316
2317 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002318 * Initialize the singleton PhoneInterfaceManager instance.
2319 * This is only done once, at startup, from PhoneApp.onCreate().
2320 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002321 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002322 synchronized (PhoneInterfaceManager.class) {
2323 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002324 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002325 } else {
2326 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2327 }
2328 return sInstance;
2329 }
2330 }
2331
2332 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002333 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002334 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002335 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002336 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002337 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002338 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002339 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002340 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002341 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002342 mTelephonySharedPreferences =
2343 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002344 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002345 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002346 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002347 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002348
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002349 publish();
2350 }
2351
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002352 private Phone getDefaultPhone() {
2353 Phone thePhone = getPhone(getDefaultSubscription());
2354 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2355 }
2356
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002357 private void publish() {
2358 if (DBG) log("publish: " + this);
2359
Peter Wangc035ce42020-01-08 21:00:22 -08002360 TelephonyFrameworkInitializer
2361 .getTelephonyServiceManager()
2362 .getTelephonyServiceRegisterer()
2363 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002364 }
2365
Stuart Scott584921c2015-01-15 17:10:34 -08002366 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002367 if (request.phone != null) {
2368 return request.phone;
2369 } else {
2370 return getPhoneFromSubId(request.subId);
2371 }
2372 }
2373
2374 private Phone getPhoneFromSubId(int subId) {
2375 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2376 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002377 }
2378
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002379 private UiccPort getUiccPortFromRequest(MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002380 Phone phone = getPhoneFromRequest(request);
2381 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002382 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002383 }
2384
Wink Saville36469e72014-06-11 15:17:00 -07002385 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002386 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002387 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002388 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002389
Kai Shif70f46f2021-03-03 13:59:46 -08002390 private void sendEraseModemConfig(@NonNull Phone phone) {
2391 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2392 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2393 }
2394
2395 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2396 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2397 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002398 }
2399
Peter Wang44b186e2020-01-13 23:33:09 -08002400 private boolean isImsAvailableOnDevice() {
2401 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2402 if (pm == null) {
2403 // For some reason package manger is not available.. This will fail internally anyway,
2404 // so do not throw error and allow.
2405 return true;
2406 }
2407 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2408 }
2409
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002410 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002411 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002412 }
2413
Wink Savilleb564aae2014-10-23 10:18:09 -07002414 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002415 if (DBG) log("dial: " + number);
2416 // No permission check needed here: This is just a wrapper around the
2417 // ACTION_DIAL intent, which is available to any app since it puts up
2418 // the UI before it does anything.
2419
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002420 final long identity = Binder.clearCallingIdentity();
2421 try {
2422 String url = createTelUrl(number);
2423 if (url == null) {
2424 return;
2425 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002426
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002427 // PENDING: should we just silently fail if phone is offhook or ringing?
2428 PhoneConstants.State state = mCM.getState(subId);
2429 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2430 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2431 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2432 mApp.startActivity(intent);
2433 }
2434 } finally {
2435 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002436 }
2437 }
2438
2439 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002440 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002441 }
2442
Wink Savilleb564aae2014-10-23 10:18:09 -07002443 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002444 if (DBG) log("call: " + number);
2445
2446 // This is just a wrapper around the ACTION_CALL intent, but we still
2447 // need to do a permission check since we're calling startActivity()
2448 // from the context of the phone app.
2449 enforceCallPermission();
2450
Jordan Liu1617b712019-07-10 15:06:26 -07002451 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002452 != AppOpsManager.MODE_ALLOWED) {
2453 return;
2454 }
2455
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002456 final long identity = Binder.clearCallingIdentity();
2457 try {
2458 String url = createTelUrl(number);
2459 if (url == null) {
2460 return;
2461 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002462
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002463 boolean isValid = false;
2464 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2465 if (slist != null) {
2466 for (SubscriptionInfo subInfoRecord : slist) {
2467 if (subInfoRecord.getSubscriptionId() == subId) {
2468 isValid = true;
2469 break;
2470 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002471 }
Wink Saville08874612014-08-31 19:19:58 -07002472 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002473 if (!isValid) {
2474 return;
2475 }
Wink Saville08874612014-08-31 19:19:58 -07002476
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002477 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2478 intent.putExtra(SUBSCRIPTION_KEY, subId);
2479 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2480 mApp.startActivity(intent);
2481 } finally {
2482 Binder.restoreCallingIdentity(identity);
2483 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002484 }
2485
Wink Savilleb564aae2014-10-23 10:18:09 -07002486 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002487 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002488 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2489 }
2490
Wink Savilleb564aae2014-10-23 10:18:09 -07002491 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002492 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002493 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2494 }
2495
Wink Savilleb564aae2014-10-23 10:18:09 -07002496 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002497 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002498
2499 final long identity = Binder.clearCallingIdentity();
2500 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002501 Phone phone = getPhone(subId);
2502 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002503 checkSimPin.start();
2504 return checkSimPin.unlockSim(null, pin);
2505 } finally {
2506 Binder.restoreCallingIdentity(identity);
2507 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002508 }
2509
Wink Savilleb564aae2014-10-23 10:18:09 -07002510 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002511 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002512
2513 final long identity = Binder.clearCallingIdentity();
2514 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002515 Phone phone = getPhone(subId);
2516 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002517 checkSimPuk.start();
2518 return checkSimPuk.unlockSim(puk, pin);
2519 } finally {
2520 Binder.restoreCallingIdentity(identity);
2521 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002522 }
2523
2524 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002525 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002526 * a synchronous one.
2527 */
2528 private static class UnlockSim extends Thread {
2529
2530 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002531 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002532
2533 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002534 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2535 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002536
2537 // For replies from SimCard interface
2538 private Handler mHandler;
2539
2540 // For async handler to identify request type
2541 private static final int SUPPLY_PIN_COMPLETE = 100;
2542
Michele Berionne5e411512020-11-13 02:36:59 +00002543 UnlockSim(int phoneId, IccCard simCard) {
2544 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002545 mSimCard = simCard;
2546 }
2547
2548 @Override
2549 public void run() {
2550 Looper.prepare();
2551 synchronized (UnlockSim.this) {
2552 mHandler = new Handler() {
2553 @Override
2554 public void handleMessage(Message msg) {
2555 AsyncResult ar = (AsyncResult) msg.obj;
2556 switch (msg.what) {
2557 case SUPPLY_PIN_COMPLETE:
2558 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2559 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002560 mRetryCount = msg.arg1;
2561 if (ar.exception != null) {
2562 if (ar.exception instanceof CommandException &&
2563 ((CommandException)(ar.exception)).getCommandError()
2564 == CommandException.Error.PASSWORD_INCORRECT) {
2565 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002566 } //When UiccCardApp dispose,handle message and return exception
2567 else if (ar.exception instanceof CommandException &&
2568 ((CommandException) (ar.exception)).getCommandError()
2569 == CommandException.Error.ABORTED) {
2570 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002571 } else {
2572 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2573 }
2574 } else {
2575 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2576 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002577 mDone = true;
2578 UnlockSim.this.notifyAll();
2579 }
2580 break;
2581 }
2582 }
2583 };
2584 UnlockSim.this.notifyAll();
2585 }
2586 Looper.loop();
2587 }
2588
2589 /*
2590 * Use PIN or PUK to unlock SIM card
2591 *
2592 * If PUK is null, unlock SIM card with PIN
2593 *
2594 * If PUK is not null, unlock SIM card with PUK and set PIN code
2595 */
Wink Saville9de0f752013-10-22 19:04:03 -07002596 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002597
2598 while (mHandler == null) {
2599 try {
2600 wait();
2601 } catch (InterruptedException e) {
2602 Thread.currentThread().interrupt();
2603 }
2604 }
2605 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2606
2607 if (puk == null) {
2608 mSimCard.supplyPin(pin, callback);
2609 } else {
2610 mSimCard.supplyPuk(puk, pin, callback);
2611 }
2612
2613 while (!mDone) {
2614 try {
2615 Log.d(LOG_TAG, "wait for done");
2616 wait();
2617 } catch (InterruptedException e) {
2618 // Restore the interrupted status
2619 Thread.currentThread().interrupt();
2620 }
2621 }
2622 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002623 int[] resultArray = new int[2];
2624 resultArray[0] = mResult;
2625 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002626
2627 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002628 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002629 }
2630
Wink Saville9de0f752013-10-22 19:04:03 -07002631 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002632 }
2633 }
2634
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002635 /**
2636 * This method has been removed due to privacy and stability concerns.
2637 */
2638 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002639 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002640 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2641 return;
Wink Saville36469e72014-06-11 15:17:00 -07002642 }
2643
Nathan Harold1f889d82020-06-04 17:05:26 -07002644 @Override
2645 public void updateServiceLocationWithPackageName(String callingPackage) {
2646 mApp.getSystemService(AppOpsManager.class)
2647 .checkPackage(Binder.getCallingUid(), callingPackage);
2648
Nathan Haroldf096d982020-11-18 17:18:06 -08002649 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002650 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2651 // Callers targeting S have no business invoking this method.
2652 return;
2653 }
2654
2655 LocationAccessPolicy.LocationPermissionResult locationResult =
2656 LocationAccessPolicy.checkLocationPermission(mApp,
2657 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2658 .setCallingPackage(callingPackage)
2659 .setCallingFeatureId(null)
2660 .setCallingPid(Binder.getCallingPid())
2661 .setCallingUid(Binder.getCallingUid())
2662 .setMethod("updateServiceLocation")
2663 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2664 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2665 .build());
2666 // Apps that lack location permission have no business calling this method;
2667 // however, because no permission was declared in the public API, denials must
2668 // all be "soft".
2669 switch (locationResult) {
2670 case DENIED_HARD: /* fall through */
2671 case DENIED_SOFT:
2672 return;
2673 }
2674
2675 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002676 final long identity = Binder.clearCallingIdentity();
2677 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002678 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002679 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002680 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002681 }
2682 } finally {
2683 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002684 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002685 }
2686
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002687 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002688 @Override
2689 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002690 return isRadioOnWithFeature(callingPackage, null);
2691 }
2692
2693
2694 @Override
2695 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2696 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2697 callingFeatureId);
2698 }
2699
2700 @Deprecated
2701 @Override
2702 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2703 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002704 }
2705
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002706 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002707 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2708 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002709 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002710 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002711 return false;
2712 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002713
2714 final long identity = Binder.clearCallingIdentity();
2715 try {
2716 return isRadioOnForSubscriber(subId);
2717 } finally {
2718 Binder.restoreCallingIdentity(identity);
2719 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002720 }
2721
2722 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002723 final long identity = Binder.clearCallingIdentity();
2724 try {
2725 final Phone phone = getPhone(subId);
2726 if (phone != null) {
2727 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2728 } else {
2729 return false;
2730 }
2731 } finally {
2732 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002733 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002734 }
2735
2736 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002737 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002738 }
Wink Saville36469e72014-06-11 15:17:00 -07002739
Wink Savilleb564aae2014-10-23 10:18:09 -07002740 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002741 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002742
2743 final long identity = Binder.clearCallingIdentity();
2744 try {
2745 final Phone phone = getPhone(subId);
2746 if (phone != null) {
2747 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2748 }
2749 } finally {
2750 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002751 }
Wink Saville36469e72014-06-11 15:17:00 -07002752 }
2753
2754 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002755 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002756 }
2757
Wink Savilleb564aae2014-10-23 10:18:09 -07002758 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002759 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002760
2761 final long identity = Binder.clearCallingIdentity();
2762 try {
2763 final Phone phone = getPhone(subId);
2764 if (phone == null) {
2765 return false;
2766 }
2767 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2768 toggleRadioOnOffForSubscriber(subId);
2769 }
2770 return true;
2771 } finally {
2772 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002773 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002774 }
Wink Saville36469e72014-06-11 15:17:00 -07002775
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002776 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002777 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002778 /*
2779 * If any of the Radios are available, it will need to be
2780 * shutdown. So return true if any Radio is available.
2781 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002782 final long identity = Binder.clearCallingIdentity();
2783 try {
2784 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2785 Phone phone = PhoneFactory.getPhone(i);
2786 if (phone != null && phone.isRadioAvailable()) return true;
2787 }
2788 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2789 return false;
2790 } finally {
2791 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002792 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002793 }
2794
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002795 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002796 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002797 enforceModifyPermission();
2798
2799 final long identity = Binder.clearCallingIdentity();
2800 try {
2801 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2802 logv("Shutting down Phone " + i);
2803 shutdownRadioUsingPhoneId(i);
2804 }
2805 } finally {
2806 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002807 }
2808 }
2809
2810 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002811 Phone phone = PhoneFactory.getPhone(phoneId);
2812 if (phone != null && phone.isRadioAvailable()) {
2813 phone.shutdownRadio();
2814 }
2815 }
2816
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002817 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002818 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002819
2820 final long identity = Binder.clearCallingIdentity();
2821 try {
2822 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2823 if (defaultPhone != null) {
2824 defaultPhone.setRadioPower(turnOn);
2825 return true;
2826 } else {
2827 loge("There's no default phone.");
2828 return false;
2829 }
2830 } finally {
2831 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002832 }
Wink Saville36469e72014-06-11 15:17:00 -07002833 }
2834
Wink Savilleb564aae2014-10-23 10:18:09 -07002835 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002836 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002837
2838 final long identity = Binder.clearCallingIdentity();
2839 try {
2840 final Phone phone = getPhone(subId);
2841 if (phone != null) {
2842 phone.setRadioPower(turnOn);
2843 return true;
2844 } else {
2845 return false;
2846 }
2847 } finally {
2848 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002849 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002850 }
2851
Wink Saville36469e72014-06-11 15:17:00 -07002852 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002853 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002854 public boolean enableDataConnectivity() {
2855 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002856
2857 final long identity = Binder.clearCallingIdentity();
2858 try {
2859 int subId = mSubscriptionController.getDefaultDataSubId();
2860 final Phone phone = getPhone(subId);
2861 if (phone != null) {
Jack Yu99e87332021-12-17 23:14:15 -08002862 if (phone.isUsingNewDataStack()) {
2863 phone.getDataSettingsManager().setDataEnabled(
2864 TelephonyManager.DATA_ENABLED_REASON_USER, true);
2865 } else {
2866 phone.getDataEnabledSettings().setDataEnabled(
2867 TelephonyManager.DATA_ENABLED_REASON_USER, true);
2868 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002869 return true;
2870 } else {
2871 return false;
2872 }
2873 } finally {
2874 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002875 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002876 }
2877
Wink Saville36469e72014-06-11 15:17:00 -07002878 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002879 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002880 public boolean disableDataConnectivity() {
2881 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002882
2883 final long identity = Binder.clearCallingIdentity();
2884 try {
2885 int subId = mSubscriptionController.getDefaultDataSubId();
2886 final Phone phone = getPhone(subId);
2887 if (phone != null) {
Jack Yu99e87332021-12-17 23:14:15 -08002888 if (phone.isUsingNewDataStack()) {
2889 phone.getDataSettingsManager().setDataEnabled(
2890 TelephonyManager.DATA_ENABLED_REASON_USER, false);
2891 } else {
2892 phone.getDataEnabledSettings().setDataEnabled(
2893 TelephonyManager.DATA_ENABLED_REASON_USER, false);
2894 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002895 return true;
2896 } else {
2897 return false;
2898 }
2899 } finally {
2900 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002901 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002902 }
2903
Sanket Padawe356d7632015-06-22 14:03:32 -07002904 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002905 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002906 final long identity = Binder.clearCallingIdentity();
2907 try {
2908 final Phone phone = getPhone(subId);
2909 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002910 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002911 } else {
2912 return false;
2913 }
2914 } finally {
2915 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002916 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002917 }
2918
2919 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002920 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002921 }
2922
pkanwarae03a6b2016-11-06 20:37:09 -08002923 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002924 enforceCallPermission();
2925
2926 final long identity = Binder.clearCallingIdentity();
2927 try {
2928 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2929 return;
2930 }
2931 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2932 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2933 } finally {
2934 Binder.restoreCallingIdentity(identity);
2935 }
pkanwar32d516d2016-10-14 19:37:38 -07002936 };
2937
Wink Savilleb564aae2014-10-23 10:18:09 -07002938 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002939 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002940
2941 final long identity = Binder.clearCallingIdentity();
2942 try {
2943 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2944 return false;
2945 }
2946 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2947 } finally {
2948 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002949 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002950 }
2951
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002952 /**
2953 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2954 * tag on getCallState Binder call.
2955 */
2956 @Deprecated
2957 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002958 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002959 if (CompatChanges.isChangeEnabled(
2960 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2961 Binder.getCallingUid())) {
2962 // Do not allow this API to be called on API version 31+, it should only be
2963 // called on old apps using this Binder call directly.
2964 throw new SecurityException("This method can only be used for applications "
2965 + "targeting API version 30 or less.");
2966 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002967 final long identity = Binder.clearCallingIdentity();
2968 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002969 Phone phone = getPhone(getDefaultSubscription());
2970 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2971 PhoneConstantConversions.convertCallState(phone.getState());
2972 } finally {
2973 Binder.restoreCallingIdentity(identity);
2974 }
2975 }
2976
2977 @Override
2978 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2979 if (CompatChanges.isChangeEnabled(
2980 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2981 Binder.getCallingUid())) {
2982 // Check READ_PHONE_STATE for API version 31+
2983 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2984 featureId, "getCallStateForSubscription")) {
2985 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2986 + "targeting API level 31+.");
2987 }
2988 }
2989 final long identity = Binder.clearCallingIdentity();
2990 try {
2991 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002992 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2993 PhoneConstantConversions.convertCallState(phone.getState());
2994 } finally {
2995 Binder.restoreCallingIdentity(identity);
2996 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002997 }
2998
Sanket Padawe356d7632015-06-22 14:03:32 -07002999 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003000 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003001 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
3002 }
3003
3004 @Override
3005 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003006 final long identity = Binder.clearCallingIdentity();
3007 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003008 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003009 if (phone != null) {
Jack Yu2c450952021-11-29 11:36:17 -08003010 if (phone.isUsingNewDataStack()) {
3011 return phone.getDataNetworkController().getInternetDataNetworkState();
3012 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003013 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
3014 } else {
3015 return PhoneConstantConversions.convertDataState(
3016 PhoneConstants.DataState.DISCONNECTED);
3017 }
3018 } finally {
3019 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003020 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003021 }
3022
Sanket Padawe356d7632015-06-22 14:03:32 -07003023 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003024 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003025 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
3026 }
3027
3028 @Override
3029 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003030 final long identity = Binder.clearCallingIdentity();
3031 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003032 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003033 if (phone != null) {
3034 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
3035 } else {
3036 return TelephonyManager.DATA_ACTIVITY_NONE;
3037 }
3038 } finally {
3039 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003040 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003041 }
3042
3043 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003044 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003045 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003046 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003047
3048 LocationAccessPolicy.LocationPermissionResult locationResult =
3049 LocationAccessPolicy.checkLocationPermission(mApp,
3050 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3051 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003052 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003053 .setCallingPid(Binder.getCallingPid())
3054 .setCallingUid(Binder.getCallingUid())
3055 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003056 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003057 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3058 .build());
3059 switch (locationResult) {
3060 case DENIED_HARD:
3061 throw new SecurityException("Not allowed to access cell location");
3062 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003063 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3064 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003065 }
3066
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003067 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003068 final long identity = Binder.clearCallingIdentity();
3069 try {
3070 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003071 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003072 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003073 } finally {
3074 Binder.restoreCallingIdentity(identity);
3075 }
Svetoslav64fad262015-04-14 14:35:21 -07003076 }
3077
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003078 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003079 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003080 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3081 // registered cell info, so return a NULL country instead.
3082 final long identity = Binder.clearCallingIdentity();
3083 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003084 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3085 // Get default phone in this case.
3086 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3087 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003088 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003089 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003090 if (phone == null) return "";
3091 ServiceStateTracker sst = phone.getServiceStateTracker();
3092 if (sst == null) return "";
3093 LocaleTracker lt = sst.getLocaleTracker();
3094 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003095 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003096 } finally {
3097 Binder.restoreCallingIdentity(identity);
3098 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003099 }
3100
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003101 /**
3102 * This method was removed due to potential issues caused by performing partial
3103 * updates of service state, and lack of a credible use case.
3104 *
3105 * This has the ability to break the telephony implementation by disabling notification of
3106 * changes in device connectivity. DO NOT USE THIS!
3107 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003108 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003109 public void enableLocationUpdates() {
3110 mApp.enforceCallingOrSelfPermission(
3111 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003112 }
3113
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003114 /**
3115 * This method was removed due to potential issues caused by performing partial
3116 * updates of service state, and lack of a credible use case.
3117 *
3118 * This has the ability to break the telephony implementation by disabling notification of
3119 * changes in device connectivity. DO NOT USE THIS!
3120 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003121 @Override
3122 public void disableLocationUpdates() {
3123 mApp.enforceCallingOrSelfPermission(
3124 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003125 }
3126
3127 @Override
3128 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003129 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3130 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003131 try {
3132 mApp.getSystemService(AppOpsManager.class)
3133 .checkPackage(Binder.getCallingUid(), callingPackage);
3134 } catch (SecurityException e) {
3135 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3136 throw e;
3137 }
3138
Nathan Haroldf096d982020-11-18 17:18:06 -08003139 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003140 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3141 throw new SecurityException(
3142 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3143 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003144
Jordan Liu1617b712019-07-10 15:06:26 -07003145 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003146 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3147 return null;
3148 }
Svetoslav64fad262015-04-14 14:35:21 -07003149
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003150 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003151
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003152 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003153 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003154
Nathan Haroldf180aac2018-06-01 18:43:55 -07003155 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3156 for (CellInfo ci : info) {
3157 if (ci instanceof CellInfoGsm) {
3158 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3159 } else if (ci instanceof CellInfoWcdma) {
3160 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3161 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003162 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003163 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003164 }
3165
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003166 private List<CellInfo> getCachedCellInfo() {
3167 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3168 for (Phone phone : PhoneFactory.getPhones()) {
3169 List<CellInfo> info = phone.getAllCellInfo();
3170 if (info != null) cellInfos.addAll(info);
3171 }
3172 return cellInfos;
3173 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003174
3175 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003176 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003177 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003178 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003179
3180 LocationAccessPolicy.LocationPermissionResult locationResult =
3181 LocationAccessPolicy.checkLocationPermission(mApp,
3182 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3183 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003184 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003185 .setCallingPid(Binder.getCallingPid())
3186 .setCallingUid(Binder.getCallingUid())
3187 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003188 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003189 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3190 .build());
3191 switch (locationResult) {
3192 case DENIED_HARD:
3193 throw new SecurityException("Not allowed to access cell info");
3194 case DENIED_SOFT:
3195 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003196 }
3197
Nathan Haroldf096d982020-11-18 17:18:06 -08003198 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003199 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3200 return getCachedCellInfo();
3201 }
3202
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003203 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003204 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003205 final long identity = Binder.clearCallingIdentity();
3206 try {
3207 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3208 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003209 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003210 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003211 if (info != null) cellInfos.addAll(info);
3212 }
3213 return cellInfos;
3214 } finally {
3215 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003216 }
3217 }
3218
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003219 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003220 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3221 String callingFeatureId) {
3222 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3223 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003224 }
3225
3226 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003227 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3228 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003229 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003230 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003231 }
3232
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003233 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3234 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003235 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003236 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003237
3238 LocationAccessPolicy.LocationPermissionResult locationResult =
3239 LocationAccessPolicy.checkLocationPermission(mApp,
3240 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3241 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003242 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003243 .setCallingPid(Binder.getCallingPid())
3244 .setCallingUid(Binder.getCallingUid())
3245 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003246 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3247 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003248 .build());
3249 switch (locationResult) {
3250 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003251 if (TelephonyPermissions
3252 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003253 // Safetynet logging for b/154934934
3254 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3255 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003256 throw new SecurityException("Not allowed to access cell info");
3257 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003258 if (TelephonyPermissions
3259 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003260 // Safetynet logging for b/154934934
3261 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3262 }
Nathan Harold5320c422019-05-09 10:26:08 -07003263 try {
3264 cb.onCellInfo(new ArrayList<CellInfo>());
3265 } catch (RemoteException re) {
3266 // Drop without consequences
3267 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003268 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003269 }
3270
Nathan Harolda939a962019-05-09 10:13:47 -07003271
3272 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003273 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3274
3275 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3276 }
3277
3278 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003279 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003280 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003281 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003282
3283 final long identity = Binder.clearCallingIdentity();
3284 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003285 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003286 } finally {
3287 Binder.restoreCallingIdentity(identity);
3288 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003289 }
3290
Shishir Agrawala9f32182016-04-12 12:00:16 -07003291 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003292 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003293 Phone phone = PhoneFactory.getPhone(slotIndex);
3294 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003295 return null;
3296 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003297 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003298 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003299 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003300 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003301 return null;
3302 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003303
3304 final long identity = Binder.clearCallingIdentity();
3305 try {
3306 return phone.getImei();
3307 } finally {
3308 Binder.restoreCallingIdentity(identity);
3309 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003310 }
3311
3312 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003313 public String getTypeAllocationCodeForSlot(int slotIndex) {
3314 Phone phone = PhoneFactory.getPhone(slotIndex);
3315 String tac = null;
3316 if (phone != null) {
3317 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003318 try {
3319 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3320 } catch (IndexOutOfBoundsException e) {
3321 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3322 return null;
3323 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003324 }
3325 return tac;
3326 }
3327
3328 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003329 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003330 try {
3331 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3332 } catch (SecurityException se) {
3333 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3334 throw new SecurityException("Package " + callingPackage + " does not belong to "
3335 + Binder.getCallingUid());
3336 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003337 Phone phone = PhoneFactory.getPhone(slotIndex);
3338 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003339 return null;
3340 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003341
Jeff Davidson913390f2018-02-23 17:11:49 -08003342 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003343 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003344 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003345 return null;
3346 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003347
3348 final long identity = Binder.clearCallingIdentity();
3349 try {
3350 return phone.getMeid();
3351 } finally {
3352 Binder.restoreCallingIdentity(identity);
3353 }
Jack Yu2af8d712017-03-15 17:14:14 -07003354 }
3355
3356 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003357 public String getManufacturerCodeForSlot(int slotIndex) {
3358 Phone phone = PhoneFactory.getPhone(slotIndex);
3359 String manufacturerCode = null;
3360 if (phone != null) {
3361 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003362 try {
3363 manufacturerCode =
3364 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3365 } catch (IndexOutOfBoundsException e) {
3366 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3367 return null;
3368 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003369 }
3370 return manufacturerCode;
3371 }
3372
3373 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003374 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3375 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003376 Phone phone = PhoneFactory.getPhone(slotIndex);
3377 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003378 return null;
3379 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003380 int subId = phone.getSubId();
3381 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003382 mApp, subId, callingPackage, callingFeatureId,
3383 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003384 return null;
3385 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003386
3387 final long identity = Binder.clearCallingIdentity();
3388 try {
3389 return phone.getDeviceSvn();
3390 } finally {
3391 Binder.restoreCallingIdentity(identity);
3392 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003393 }
3394
fionaxu43304da2017-11-27 22:51:16 -08003395 @Override
3396 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003397 final long identity = Binder.clearCallingIdentity();
3398 try {
3399 final Phone phone = getPhone(subId);
3400 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3401 } finally {
3402 Binder.restoreCallingIdentity(identity);
3403 }
fionaxu43304da2017-11-27 22:51:16 -08003404 }
3405
3406 @Override
3407 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003408 final long identity = Binder.clearCallingIdentity();
3409 try {
3410 final Phone phone = getPhone(subId);
3411 return phone == null ? null : phone.getCarrierName();
3412 } finally {
3413 Binder.restoreCallingIdentity(identity);
3414 }
fionaxu43304da2017-11-27 22:51:16 -08003415 }
3416
calvinpanffe225e2018-11-01 19:43:06 +08003417 @Override
chen xu0026ca62019-03-06 15:28:50 -08003418 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003419 final long identity = Binder.clearCallingIdentity();
3420 try {
3421 final Phone phone = getPhone(subId);
3422 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003423 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003424 } finally {
3425 Binder.restoreCallingIdentity(identity);
3426 }
3427 }
3428
3429 @Override
chen xu0026ca62019-03-06 15:28:50 -08003430 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003431 final long identity = Binder.clearCallingIdentity();
3432 try {
3433 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003434 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003435 } finally {
3436 Binder.restoreCallingIdentity(identity);
3437 }
3438 }
3439
chen xu651eec72018-11-11 19:03:44 -08003440 @Override
chen xu864e11c2018-12-06 22:10:03 -08003441 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3442 if (!isSubscriptionMccMnc) {
3443 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3444 }
chen xu651eec72018-11-11 19:03:44 -08003445 final Phone phone = PhoneFactory.getPhone(slotIndex);
3446 if (phone == null) {
3447 return TelephonyManager.UNKNOWN_CARRIER_ID;
3448 }
3449 final long identity = Binder.clearCallingIdentity();
3450 try {
3451 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3452 } finally {
3453 Binder.restoreCallingIdentity(identity);
3454 }
3455 }
3456
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003457 //
3458 // Internal helper methods.
3459 //
3460
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003461 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003462 * Make sure the caller is the calling package itself
3463 *
3464 * @throws SecurityException if the caller is not the calling package
3465 */
3466 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3467 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003468 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3469 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003470 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003471 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003472 } catch (PackageManager.NameNotFoundException e) {
3473 // packageUid is -1
3474 }
3475 if (packageUid != callingUid) {
3476 throw new SecurityException(message + ": Package " + callingPackage
3477 + " does not belong to " + callingUid);
3478 }
3479 }
3480
3481 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003482 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3483 *
3484 * @throws SecurityException if the caller does not have the required permission
3485 */
3486 private void enforceModifyPermission() {
3487 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3488 }
3489
Shuo Qian3b6ee772019-11-13 17:43:31 -08003490 private void enforceActiveEmergencySessionPermission() {
3491 mApp.enforceCallingOrSelfPermission(
3492 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3493 }
3494
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003495 /**
3496 * Make sure the caller has the CALL_PHONE permission.
3497 *
3498 * @throws SecurityException if the caller does not have the required permission
3499 */
3500 private void enforceCallPermission() {
3501 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3502 }
3503
paulhu5a773602019-08-23 19:17:33 +08003504 private void enforceSettingsPermission() {
3505 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003506 }
3507
Michele Berionne5e411512020-11-13 02:36:59 +00003508 private void enforceRebootPermission() {
3509 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3510 }
3511
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003512 private String createTelUrl(String number) {
3513 if (TextUtils.isEmpty(number)) {
3514 return null;
3515 }
3516
Jake Hambye994d462014-02-03 13:10:13 -08003517 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003518 }
3519
Ihab Awadf9e92732013-12-05 18:02:52 -08003520 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003521 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3522 }
3523
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003524 private static void logv(String msg) {
3525 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3526 }
3527
Ihab Awadf9e92732013-12-05 18:02:52 -08003528 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003529 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3530 }
3531
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003532 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003533 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003534 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003535 }
3536
Sanket Padawe356d7632015-06-22 14:03:32 -07003537 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003538 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003539 final long identity = Binder.clearCallingIdentity();
3540 try {
3541 final Phone phone = PhoneFactory.getPhone(slotIndex);
3542 if (phone == null) {
3543 return PhoneConstants.PHONE_TYPE_NONE;
3544 } else {
3545 return phone.getPhoneType();
3546 }
3547 } finally {
3548 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003549 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003550 }
3551
3552 /**
3553 * Returns the CDMA ERI icon index to display
3554 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003555 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003556 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3557 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3558 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003559 }
3560
Sanket Padawe356d7632015-06-22 14:03:32 -07003561 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003562 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3563 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003564 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003565 mApp, subId, callingPackage, callingFeatureId,
3566 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003567 return -1;
3568 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003569
3570 final long identity = Binder.clearCallingIdentity();
3571 try {
3572 final Phone phone = getPhone(subId);
3573 if (phone != null) {
3574 return phone.getCdmaEriIconIndex();
3575 } else {
3576 return -1;
3577 }
3578 } finally {
3579 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003580 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003581 }
3582
3583 /**
3584 * Returns the CDMA ERI icon mode,
3585 * 0 - ON
3586 * 1 - FLASHING
3587 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003588 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003589 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3590 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3591 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003592 }
3593
Sanket Padawe356d7632015-06-22 14:03:32 -07003594 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003595 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3596 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003597 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003598 mApp, subId, callingPackage, callingFeatureId,
3599 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003600 return -1;
3601 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003602
3603 final long identity = Binder.clearCallingIdentity();
3604 try {
3605 final Phone phone = getPhone(subId);
3606 if (phone != null) {
3607 return phone.getCdmaEriIconMode();
3608 } else {
3609 return -1;
3610 }
3611 } finally {
3612 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003613 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003614 }
3615
3616 /**
3617 * Returns the CDMA ERI text,
3618 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003619 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003620 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3621 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3622 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003623 }
3624
Sanket Padawe356d7632015-06-22 14:03:32 -07003625 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003626 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3627 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003628 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003629 mApp, subId, callingPackage, callingFeatureId,
3630 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003631 return null;
3632 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003633
3634 final long identity = Binder.clearCallingIdentity();
3635 try {
3636 final Phone phone = getPhone(subId);
3637 if (phone != null) {
3638 return phone.getCdmaEriText();
3639 } else {
3640 return null;
3641 }
3642 } finally {
3643 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003644 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003645 }
3646
3647 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003648 * Returns the CDMA MDN.
3649 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003650 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003651 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003652 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3653 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003654
3655 final long identity = Binder.clearCallingIdentity();
3656 try {
3657 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003658 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003659 return phone.getLine1Number();
3660 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003661 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003662 return null;
3663 }
3664 } finally {
3665 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003666 }
3667 }
3668
3669 /**
3670 * Returns the CDMA MIN.
3671 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003672 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003673 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003674 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3675 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003676
3677 final long identity = Binder.clearCallingIdentity();
3678 try {
3679 final Phone phone = getPhone(subId);
3680 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3681 return phone.getCdmaMin();
3682 } else {
3683 return null;
3684 }
3685 } finally {
3686 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003687 }
3688 }
3689
Hall Liud892bec2018-11-30 14:51:45 -08003690 @Override
3691 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3692 INumberVerificationCallback callback, String callingPackage) {
3693 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3694 != PERMISSION_GRANTED) {
3695 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3696 }
3697 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3698
3699 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3700 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003701 throw new SecurityException("Calling package must be configured in the device config: "
3702 + "calling package: " + callingPackage
3703 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003704 }
3705
3706 if (range == null) {
3707 throw new NullPointerException("Range must be non-null");
3708 }
3709
3710 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003711 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003712
3713 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3714 }
3715
Junda Liuca05d5d2014-08-14 22:36:34 -07003716 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003717 * Returns true if CDMA provisioning needs to run.
3718 */
3719 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003720 final long identity = Binder.clearCallingIdentity();
3721 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003722 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003723 } finally {
3724 Binder.restoreCallingIdentity(identity);
3725 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003726 }
3727
3728 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003729 * Sets the voice mail number of a given subId.
3730 */
3731 @Override
3732 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003733 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3734 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003735
3736 final long identity = Binder.clearCallingIdentity();
3737 try {
3738 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3739 new Pair<String, String>(alphaTag, number), new Integer(subId));
3740 return success;
3741 } finally {
3742 Binder.restoreCallingIdentity(identity);
3743 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003744 }
3745
Ta-wei Yen87c49842016-05-13 21:19:52 -07003746 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003747 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3748 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003749 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3750 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003751 if (!TextUtils.equals(callingPackage, systemDialer)) {
3752 throw new SecurityException("caller must be system dialer");
3753 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003754
3755 final long identity = Binder.clearCallingIdentity();
3756 try {
3757 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3758 if (phoneAccountHandle == null) {
3759 return null;
3760 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003761 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003762 } finally {
3763 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003764 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003765 }
3766
3767 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003768 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3769 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003770 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003771 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003772 mApp, subId, callingPackage, callingFeatureId,
3773 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003774 return null;
3775 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003776
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003777 final long identity = Binder.clearCallingIdentity();
3778 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003779 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003780 } finally {
3781 Binder.restoreCallingIdentity(identity);
3782 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003783 }
3784
3785 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003786 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3787 VisualVoicemailSmsFilterSettings settings) {
3788 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003789
3790 final long identity = Binder.clearCallingIdentity();
3791 try {
3792 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003793 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003794 } finally {
3795 Binder.restoreCallingIdentity(identity);
3796 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003797 }
3798
3799 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003800 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3801 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003802
3803 final long identity = Binder.clearCallingIdentity();
3804 try {
3805 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003806 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003807 } finally {
3808 Binder.restoreCallingIdentity(identity);
3809 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003810 }
3811
3812 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003813 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3814 String callingPackage, int subId) {
3815 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003816
3817 final long identity = Binder.clearCallingIdentity();
3818 try {
3819 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003820 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003821 } finally {
3822 Binder.restoreCallingIdentity(identity);
3823 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003824 }
3825
3826 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003827 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003828 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003829
3830 final long identity = Binder.clearCallingIdentity();
3831 try {
3832 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003833 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003834 } finally {
3835 Binder.restoreCallingIdentity(identity);
3836 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003837 }
3838
3839 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003840 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3841 String callingAttributionTag, int subId, String number, int port, String text,
3842 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003843 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003844 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003845 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003846 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003847 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3848 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003849 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003850
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003851 /**
fionaxu0152e512016-11-14 13:36:14 -08003852 * Sets the voice activation state of a given subId.
3853 */
3854 @Override
3855 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003856 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3857 mApp, subId, "setVoiceActivationState");
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.setVoiceActivationState(activationState);
3864 } else {
3865 loge("setVoiceActivationState fails with invalid subId: " + subId);
3866 }
3867 } finally {
3868 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003869 }
3870 }
3871
3872 /**
3873 * Sets the data activation state of a given subId.
3874 */
3875 @Override
3876 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003877 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3878 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003879
3880 final long identity = Binder.clearCallingIdentity();
3881 try {
3882 final Phone phone = getPhone(subId);
3883 if (phone != null) {
3884 phone.setDataActivationState(activationState);
3885 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003886 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003887 }
3888 } finally {
3889 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003890 }
3891 }
3892
3893 /**
3894 * Returns the voice activation state of a given subId.
3895 */
3896 @Override
3897 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003898 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003899
fionaxu0152e512016-11-14 13:36:14 -08003900 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003901 final long identity = Binder.clearCallingIdentity();
3902 try {
3903 if (phone != null) {
3904 return phone.getVoiceActivationState();
3905 } else {
3906 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3907 }
3908 } finally {
3909 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003910 }
3911 }
3912
3913 /**
3914 * Returns the data activation state of a given subId.
3915 */
3916 @Override
3917 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003918 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003919
fionaxu0152e512016-11-14 13:36:14 -08003920 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003921 final long identity = Binder.clearCallingIdentity();
3922 try {
3923 if (phone != null) {
3924 return phone.getDataActivationState();
3925 } else {
3926 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3927 }
3928 } finally {
3929 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003930 }
3931 }
3932
3933 /**
Wink Saville36469e72014-06-11 15:17:00 -07003934 * Returns the unread count of voicemails for a subId
3935 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003936 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003937 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3938 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003939 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003940 mApp, subId, callingPackage, callingFeatureId,
3941 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003942 return 0;
3943 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003944 final long identity = Binder.clearCallingIdentity();
3945 try {
3946 final Phone phone = getPhone(subId);
3947 if (phone != null) {
3948 return phone.getVoiceMessageCount();
3949 } else {
3950 return 0;
3951 }
3952 } finally {
3953 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003954 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003955 }
3956
3957 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003958 * returns true, if the device is in a state where both voice and data
3959 * are supported simultaneously. This can change based on location or network condition.
3960 */
3961 @Override
3962 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003963 final long identity = Binder.clearCallingIdentity();
3964 try {
3965 final Phone phone = getPhone(subId);
3966 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3967 } finally {
3968 Binder.restoreCallingIdentity(identity);
3969 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003970 }
3971
3972 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003973 * Send the dialer code if called from the current default dialer or the caller has
3974 * carrier privilege.
3975 * @param inputCode The dialer code to send
3976 */
3977 @Override
3978 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003979 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003980 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003981 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3982 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003983 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003984 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003985 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003986 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003987
3988 final long identity = Binder.clearCallingIdentity();
3989 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003990 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003991 } finally {
3992 Binder.restoreCallingIdentity(identity);
3993 }
fionaxu235cc5e2017-03-06 22:25:57 -08003994 }
3995
Pengquan Menga1bb6272018-09-06 09:59:22 -07003996 @Override
3997 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003998 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003999 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08004000 mApp, subId, "getNetworkSelectionMode");
4001 final long identity = Binder.clearCallingIdentity();
4002 try {
4003 if (!isActiveSubscription(subId)) {
4004 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4005 }
4006 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4007 } finally {
4008 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004009 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004010 }
4011
Brad Ebinger35c841c2018-10-01 10:40:55 -07004012 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004013 public boolean isInEmergencySmsMode() {
4014 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4015 final long identity = Binder.clearCallingIdentity();
4016 try {
4017 for (Phone phone : PhoneFactory.getPhones()) {
4018 if (phone.isInEmergencySmsMode()) {
4019 return true;
4020 }
4021 }
4022 } finally {
4023 Binder.restoreCallingIdentity(identity);
4024 }
4025 return false;
4026 }
4027
shilu366312e2019-12-17 09:28:10 -08004028 /**
4029 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4030 * @param subId The subscription to use to check the configuration.
4031 * @param c The callback that will be used to send the result.
4032 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004033 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004034 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4035 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004036 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004037 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08004038
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004039 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4040 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4041 "IMS not available on device.");
4042 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004043 final long token = Binder.clearCallingIdentity();
4044 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004045 int slotId = getSlotIndexOrException(subId);
4046 verifyImsMmTelConfiguredOrThrow(slotId);
4047 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004048 } catch (ImsException e) {
4049 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004050 } finally {
4051 Binder.restoreCallingIdentity(token);
4052 }
4053 }
4054
shilu366312e2019-12-17 09:28:10 -08004055 /**
4056 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4057 * @param subId The subscription to use to check the configuration.
4058 * @param c The callback that will be used to send the result.
4059 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004060 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004061 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004062 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004063 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004064 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4065 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4066 }
Meng Wangafbc5852019-09-19 17:37:13 -07004067 final long token = Binder.clearCallingIdentity();
4068 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004069 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4070 .removeRegistrationCallbackForSubscription(c, subId);
4071 } catch (ImsException e) {
4072 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4073 + "is inactive, ignoring unregister.");
4074 // If the subscription is no longer active, just return, since the callback
4075 // will already have been removed internally.
4076 } finally {
4077 Binder.restoreCallingIdentity(token);
4078 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004079 }
4080
Brad Ebingera34a6c22019-10-22 17:36:18 -07004081 /**
4082 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4083 */
4084 @Override
4085 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4086 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4087 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4088 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4089 "IMS not available on device.");
4090 }
4091 final long token = Binder.clearCallingIdentity();
4092 try {
4093 Phone phone = getPhone(subId);
4094 if (phone == null) {
4095 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4096 + subId + "'");
4097 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4098 }
4099 phone.getImsRegistrationState(regState -> {
4100 try {
4101 consumer.accept((regState == null)
4102 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4103 } catch (RemoteException e) {
4104 // Ignore if the remote process is no longer available to call back.
4105 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4106 }
4107 });
4108 } finally {
4109 Binder.restoreCallingIdentity(token);
4110 }
4111 }
4112
4113 /**
4114 * Get the transport type for the IMS service registration state.
4115 */
4116 @Override
4117 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004118 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004119 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004120 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4121 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4122 "IMS not available on device.");
4123 }
4124 final long token = Binder.clearCallingIdentity();
4125 try {
4126 Phone phone = getPhone(subId);
4127 if (phone == null) {
4128 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4129 + subId + "'");
4130 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4131 }
4132 phone.getImsRegistrationTech(regTech -> {
4133 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4134 int regTechConverted = (regTech == null)
4135 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4136 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4137 regTechConverted);
4138 try {
4139 consumer.accept(regTechConverted);
4140 } catch (RemoteException e) {
4141 // Ignore if the remote process is no longer available to call back.
4142 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4143 }
4144 });
4145 } finally {
4146 Binder.restoreCallingIdentity(token);
4147 }
4148 }
4149
shilu366312e2019-12-17 09:28:10 -08004150 /**
4151 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4152 * @param subId The subscription to use to check the configuration.
4153 * @param c The callback that will be used to send the result.
4154 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004155 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004156 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4157 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004158 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004159 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004160 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4161 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4162 "IMS not available on device.");
4163 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004164 final long token = Binder.clearCallingIdentity();
4165 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004166 int slotId = getSlotIndexOrException(subId);
4167 verifyImsMmTelConfiguredOrThrow(slotId);
4168 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004169 } catch (ImsException e) {
4170 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004171 } finally {
4172 Binder.restoreCallingIdentity(token);
4173 }
4174 }
4175
shilu366312e2019-12-17 09:28:10 -08004176 /**
4177 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4178 * @param subId The subscription to use to check the configuration.
4179 * @param c The callback that will be used to send the result.
4180 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004181 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004182 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004183 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004184 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004185 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4186 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4187 }
Meng Wangafbc5852019-09-19 17:37:13 -07004188
4189 final long token = Binder.clearCallingIdentity();
4190 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004191 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004192 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004193 } catch (ImsException e) {
4194 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4195 + "is inactive, ignoring unregister.");
4196 // If the subscription is no longer active, just return, since the callback
4197 // will already have been removed internally.
4198 } finally {
4199 Binder.restoreCallingIdentity(token);
4200 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004201 }
4202
4203 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004204 public boolean isCapable(int subId, int capability, int regTech) {
4205 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004206 final long token = Binder.clearCallingIdentity();
4207 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004208 int slotId = getSlotIndexOrException(subId);
4209 verifyImsMmTelConfiguredOrThrow(slotId);
4210 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004211 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004212 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4213 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004214 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004215 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4216 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004217 } finally {
4218 Binder.restoreCallingIdentity(token);
4219 }
4220 }
4221
4222 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004223 public boolean isAvailable(int subId, int capability, int regTech) {
4224 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004225 final long token = Binder.clearCallingIdentity();
4226 try {
4227 Phone phone = getPhone(subId);
4228 if (phone == null) return false;
4229 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004230 } catch (com.android.ims.ImsException e) {
4231 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4232 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004233 } finally {
4234 Binder.restoreCallingIdentity(token);
4235 }
4236 }
4237
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004238 /**
4239 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4240 * subscription.
4241 * @param subId The subscription to use to check the configuration.
4242 * @param callback The callback that will be used to send the result.
4243 * @param capability The MmTelFeature capability that will be used to send the result.
4244 * @param transportType The transport type of the MmTelFeature capability.
4245 */
4246 @Override
4247 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4248 int transportType) {
4249 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4250 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4251 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4252 "IMS not available on device.");
4253 }
4254 final long token = Binder.clearCallingIdentity();
4255 try {
4256 int slotId = getSlotIndex(subId);
4257 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4258 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4259 + subId + "'");
4260 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4261 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004262 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004263 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4264 transportType, aBoolean -> {
4265 try {
4266 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4267 } catch (RemoteException e) {
4268 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4269 + "running. Ignore");
4270 }
4271 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004272 } catch (ImsException e) {
4273 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004274 } finally {
4275 Binder.restoreCallingIdentity(token);
4276 }
4277 }
4278
shilu366312e2019-12-17 09:28:10 -08004279 /**
4280 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4281 * @param subId The subscription to use to check the configuration.
4282 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004283 @Override
4284 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004285 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004286 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004287
Brad Ebinger35c841c2018-10-01 10:40:55 -07004288 final long token = Binder.clearCallingIdentity();
4289 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004290 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004291 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004292 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004293 } catch (ImsException e) {
4294 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004295 } finally {
4296 Binder.restoreCallingIdentity(token);
4297 }
4298 }
4299
4300 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004301 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004302 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004303 "setAdvancedCallingSettingEnabled");
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. The
4308 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004309 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004310 } catch (ImsException e) {
4311 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004312 } finally {
4313 Binder.restoreCallingIdentity(identity);
4314 }
4315 }
4316
shilu366312e2019-12-17 09:28:10 -08004317 /**
4318 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4319 * @param subId The subscription to use to check the configuration.
4320 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004321 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004322 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004323 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004324 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004325 final long identity = Binder.clearCallingIdentity();
4326 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004327 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004328 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004329 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004330 } catch (ImsException e) {
4331 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004332 } finally {
4333 Binder.restoreCallingIdentity(identity);
4334 }
4335 }
4336
4337 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004338 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004339 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004340 "setVtSettingEnabled");
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. The
4345 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004346 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004347 } catch (ImsException e) {
4348 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004349 } finally {
4350 Binder.restoreCallingIdentity(identity);
4351 }
4352 }
4353
shilu366312e2019-12-17 09:28:10 -08004354 /**
4355 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4356 * @param subId The subscription to use to check the configuration.
4357 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004358 @Override
4359 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004360 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004361 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004362 final long identity = Binder.clearCallingIdentity();
4363 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004364 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004365 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004366 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004367 } catch (ImsException e) {
4368 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004369 } finally {
4370 Binder.restoreCallingIdentity(identity);
4371 }
4372 }
4373
4374 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004375 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004376 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004377 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004378 final long identity = Binder.clearCallingIdentity();
4379 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004380 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004381 // This setting doesn't require an active ImsService connection, so do not verify. The
4382 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004383 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004384 } catch (ImsException e) {
4385 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004386 } finally {
4387 Binder.restoreCallingIdentity(identity);
4388 }
4389 }
4390
shilu366312e2019-12-17 09:28:10 -08004391 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004392 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4393 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4394 * @param subId The subscription to use to check the configuration.
4395 */
4396 @Override
4397 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004398 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004399 mApp, subId, "isCrossSimCallingEnabledByUser");
4400 final long identity = Binder.clearCallingIdentity();
4401 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004402 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004403 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004404 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004405 } catch (ImsException e) {
4406 throw new ServiceSpecificException(e.getCode());
4407 } finally {
4408 Binder.restoreCallingIdentity(identity);
4409 }
4410 }
4411
4412 /**
4413 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4414 * Requires MODIFY_PHONE_STATE permission.
4415 * @param subId The subscription to use to check the configuration.
4416 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4417 * false otherwise
4418 */
4419 @Override
4420 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4421 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4422 "setCrossSimCallingEnabled");
4423 final long identity = Binder.clearCallingIdentity();
4424 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004425 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004426 // This setting doesn't require an active ImsService connection, so do not verify. The
4427 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004428 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004429 } catch (ImsException e) {
4430 throw new ServiceSpecificException(e.getCode());
4431 } finally {
4432 Binder.restoreCallingIdentity(identity);
4433 }
4434 }
4435
4436 /**
shilu366312e2019-12-17 09:28:10 -08004437 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4438 * @param subId The subscription to use to check the configuration.
4439 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004440 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004441
Brad Ebinger35c841c2018-10-01 10:40:55 -07004442 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004443 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004444 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004445 final long identity = Binder.clearCallingIdentity();
4446 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004447 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004448 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004449 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004450 } catch (ImsException e) {
4451 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004452 } finally {
4453 Binder.restoreCallingIdentity(identity);
4454 }
4455 }
4456
4457 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004458 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004459 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004460 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004461 final long identity = Binder.clearCallingIdentity();
4462 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004463 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004464 // This setting doesn't require an active ImsService connection, so do not verify. The
4465 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004466 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004467 } catch (ImsException e) {
4468 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004469 } finally {
4470 Binder.restoreCallingIdentity(identity);
4471 }
4472 }
4473
4474 @Override
4475 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4476 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4477 "setVoWiFiNonPersistent");
4478 final long identity = Binder.clearCallingIdentity();
4479 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004480 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004481 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004482 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004483 } catch (ImsException e) {
4484 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004485 } finally {
4486 Binder.restoreCallingIdentity(identity);
4487 }
4488 }
4489
shilu366312e2019-12-17 09:28:10 -08004490 /**
4491 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4492 * @param subId The subscription to use to check the configuration.
4493 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004494 @Override
4495 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004496 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004497 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004498 final long identity = Binder.clearCallingIdentity();
4499 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004500 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004501 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004502 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004503 } catch (ImsException e) {
4504 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004505 } finally {
4506 Binder.restoreCallingIdentity(identity);
4507 }
4508 }
4509
4510 @Override
4511 public void setVoWiFiModeSetting(int subId, int mode) {
4512 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4513 "setVoWiFiModeSetting");
4514 final long identity = Binder.clearCallingIdentity();
4515 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004516 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004517 // This setting doesn't require an active ImsService connection, so do not verify. The
4518 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004519 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004520 } catch (ImsException e) {
4521 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004522 } finally {
4523 Binder.restoreCallingIdentity(identity);
4524 }
4525 }
4526
4527 @Override
4528 public int getVoWiFiRoamingModeSetting(int subId) {
4529 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4530 final long identity = Binder.clearCallingIdentity();
4531 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004532 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004533 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004534 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004535 } catch (ImsException e) {
4536 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004537 } finally {
4538 Binder.restoreCallingIdentity(identity);
4539 }
4540 }
4541
4542 @Override
4543 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4544 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4545 "setVoWiFiRoamingModeSetting");
4546 final long identity = Binder.clearCallingIdentity();
4547 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004548 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004549 // This setting doesn't require an active ImsService connection, so do not verify. The
4550 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004551 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004552 } catch (ImsException e) {
4553 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004554 } finally {
4555 Binder.restoreCallingIdentity(identity);
4556 }
4557 }
4558
4559 @Override
4560 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4561 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4562 "setRttCapabilityEnabled");
4563 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. The
4567 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004568 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004569 } catch (ImsException e) {
4570 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004571 } finally {
4572 Binder.restoreCallingIdentity(identity);
4573 }
4574 }
4575
shilu366312e2019-12-17 09:28:10 -08004576 /**
4577 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4578 * @param subId The subscription to use to check the configuration.
4579 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004580 @Override
4581 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004582 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004583 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004584 final long identity = Binder.clearCallingIdentity();
4585 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004586 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004587 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004588 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004589 } catch (ImsException e) {
4590 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004591 } finally {
4592 Binder.restoreCallingIdentity(identity);
4593 }
4594 }
4595
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004596 @Override
4597 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4598 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004599
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004600 final long identity = Binder.clearCallingIdentity();
4601 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004602 if (!isImsAvailableOnDevice()) {
4603 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4604 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004605 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004606 int slotId = getSlotIndexOrException(subId);
4607 verifyImsMmTelConfiguredOrThrow(slotId);
4608 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004609 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004610 } catch (ImsException e) {
4611 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004612 } finally {
4613 Binder.restoreCallingIdentity(identity);
4614 }
4615 }
4616
4617 @Override
4618 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4619 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004620
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004621 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004622 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4623 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4624 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004625 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004626 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004627 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004628 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004629 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4630 + "is inactive, ignoring unregister.");
4631 // If the subscription is no longer active, just return, since the callback will already
4632 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004633 } finally {
4634 Binder.restoreCallingIdentity(identity);
4635 }
4636 }
4637
joonhunshincffb7fc2021-11-28 07:32:01 +00004638 @Override
4639 public void registerFeatureProvisioningChangedCallback(int subId,
4640 IFeatureProvisioningCallback callback) {
4641 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4642 mApp, subId, "registerFeatureProvisioningChangedCallback");
4643
4644 final long identity = Binder.clearCallingIdentity();
4645 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4646 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4647 }
4648
4649 ImsProvisioningController.getInstance()
4650 .addFeatureProvisioningChangedCallback(subId, callback);
4651
4652 Binder.restoreCallingIdentity(identity);
4653 }
4654
4655 @Override
4656 public void unregisterFeatureProvisioningChangedCallback(int subId,
4657 IFeatureProvisioningCallback callback) {
4658 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4659 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4660
4661 final long identity = Binder.clearCallingIdentity();
4662 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4663 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4664 }
4665
4666 ImsProvisioningController.getInstance()
4667 .removeFeatureProvisioningChangedCallback(subId, callback);
4668
4669 Binder.restoreCallingIdentity(identity);
4670 }
allenwtsu99c623b2020-01-03 18:24:23 +08004671
4672 private void checkModifyPhoneStatePermission(int subId, String message) {
4673 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4674 message);
4675 }
4676
4677 private boolean isImsProvisioningRequired(int subId, int capability,
4678 boolean isMmtelCapability) {
4679 Phone phone = getPhone(subId);
4680 if (phone == null) {
4681 loge("phone instance null for subid " + subId);
4682 return false;
4683 }
4684 if (isMmtelCapability) {
4685 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4686 return false;
4687 }
4688 } else {
4689 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4690 return false;
4691 }
4692 }
4693 return true;
4694 }
4695
4696 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004697 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004698 boolean isProvisioned) {
4699 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4700
4701 final long identity = Binder.clearCallingIdentity();
4702 try {
joonhunshincffb7fc2021-11-28 07:32:01 +00004703 ImsProvisioningController.getInstance()
4704 .setRcsProvisioningStatusForCapability(subId, capability, tech, isProvisioned);
4705 return;
allenwtsu99c623b2020-01-03 18:24:23 +08004706 } finally {
4707 Binder.restoreCallingIdentity(identity);
4708 }
allenwtsu99c623b2020-01-03 18:24:23 +08004709 }
4710
4711
4712 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004713 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4714 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4715 mApp, subId, "getRcsProvisioningStatusForCapability");
4716
allenwtsu99c623b2020-01-03 18:24:23 +08004717 final long identity = Binder.clearCallingIdentity();
4718 try {
joonhunshincffb7fc2021-11-28 07:32:01 +00004719 return ImsProvisioningController.getInstance()
4720 .getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004721 } finally {
4722 Binder.restoreCallingIdentity(identity);
4723 }
4724 }
4725
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004726 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004727 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4728 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004729 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004730
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004731 final long identity = Binder.clearCallingIdentity();
4732 try {
joonhunshincffb7fc2021-11-28 07:32:01 +00004733 ImsProvisioningController.getInstance()
4734 .setImsProvisioningStatusForCapability(subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004735 } finally {
4736 Binder.restoreCallingIdentity(identity);
4737 }
4738 }
4739
4740 @Override
4741 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00004742 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4743 mApp, subId, "getProvisioningStatusForCapability");
4744
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004745 final long identity = Binder.clearCallingIdentity();
4746 try {
joonhunshincffb7fc2021-11-28 07:32:01 +00004747 return ImsProvisioningController.getInstance()
4748 .getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004749
4750 } finally {
4751 Binder.restoreCallingIdentity(identity);
4752 }
4753 }
4754
4755 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004756 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4757 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4758 mApp, subId, "isProvisioningRequiredForCapability");
4759
4760 final long identity = Binder.clearCallingIdentity();
4761 try {
4762 return ImsProvisioningController.getInstance()
4763 .isImsProvisioningRequiredForCapability(subId, capability, tech);
4764 } finally {
4765 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004766 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004767 }
4768
4769 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004770 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4771 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4772 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004773
joonhunshincffb7fc2021-11-28 07:32:01 +00004774 final long identity = Binder.clearCallingIdentity();
4775 try {
4776 return ImsProvisioningController.getInstance()
4777 .isRcsProvisioningRequiredForCapability(subId, capability, tech);
4778 } finally {
4779 Binder.restoreCallingIdentity(identity);
4780 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004781 }
4782
4783 private static String getMmTelProvisioningKey(int subId, int tech) {
4784 // resulting key is provision_ims_mmtel_{subId}_{tech}
4785 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4786 }
4787
4788 /**
4789 * Query CarrierConfig to see if the specified capability requires provisioning for the
4790 * carrier associated with the subscription id.
4791 */
4792 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4793 int capability) {
4794 CarrierConfigManager configManager = new CarrierConfigManager(context);
4795 PersistableBundle c = configManager.getConfigForSubId(subId);
4796 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004797 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004798 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4799 false);
4800 boolean requireVoiceVtProvisioning = c.getBoolean(
4801 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4802
4803 // First check to make sure that the capability requires provisioning.
4804 switch (capability) {
4805 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4806 // intentional fallthrough
4807 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4808 if (requireVoiceVtProvisioning) {
4809 // Voice and Video requires provisioning
4810 return true;
4811 }
4812 break;
4813 }
4814 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4815 if (requireUtProvisioning) {
4816 // UT requires provisioning
4817 return true;
4818 }
4819 break;
4820 }
4821 }
4822 return false;
4823 }
4824
allenwtsu99c623b2020-01-03 18:24:23 +08004825 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4826 int capability) {
4827 CarrierConfigManager configManager = new CarrierConfigManager(context);
4828 PersistableBundle c = configManager.getConfigForSubId(subId);
4829
4830 boolean requireRcsProvisioning = c.getBoolean(
4831 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4832
4833 // First check to make sure that the capability requires provisioning.
4834 switch (capability) {
4835 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4836 // intentional fallthrough
4837 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4838 if (requireRcsProvisioning) {
4839 // OPTION or PRESENCE requires provisioning
4840 return true;
4841 }
4842 break;
4843 }
4844 }
4845 return false;
4846 }
4847
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004848 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004849 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004850 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4851 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4852 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004853 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4854 mApp, subId, "getImsProvisioningInt");
4855
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004856 final long identity = Binder.clearCallingIdentity();
4857 try {
4858 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004859 int slotId = getSlotIndex(subId);
4860 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4861 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4862 + subId + "' for key:" + key);
4863 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4864 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004865
4866 int retVal = ImsProvisioningController.getInstance().getProvisioningValue(subId, key);
4867 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4868 return retVal;
4869 }
4870
calvinpanb5a34062021-02-08 19:59:36 +08004871 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004872 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004873 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4874 + subId + "' for key:" + key);
4875 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004876 } finally {
4877 Binder.restoreCallingIdentity(identity);
4878 }
4879 }
4880
4881 @Override
4882 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004883 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4884 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4885 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004886 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4887 mApp, subId, "getImsProvisioningString");
4888
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004889 final long identity = Binder.clearCallingIdentity();
4890 try {
4891 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004892 int slotId = getSlotIndex(subId);
4893 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4894 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4895 + subId + "' for key:" + key);
4896 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4897 }
calvinpanb5a34062021-02-08 19:59:36 +08004898 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004899 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004900 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4901 + subId + "' for key:" + key);
4902 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004903 } finally {
4904 Binder.restoreCallingIdentity(identity);
4905 }
4906 }
4907
4908 @Override
4909 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004910 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4911 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4912 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004913 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4914 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00004915
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004916 final long identity = Binder.clearCallingIdentity();
4917 try {
4918 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004919 int slotId = getSlotIndex(subId);
4920 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4921 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4922 + subId + "' for key:" + key);
4923 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4924 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004925
4926 int retVal = ImsProvisioningController.getInstance()
4927 .setProvisioningValue(subId, key, value);
4928 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4929 return retVal;
4930 }
4931
calvinpanb5a34062021-02-08 19:59:36 +08004932 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4933 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004934 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004935 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004936 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004937 } finally {
4938 Binder.restoreCallingIdentity(identity);
4939 }
4940 }
4941
4942 @Override
4943 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004944 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4945 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4946 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004947 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4948 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004949 final long identity = Binder.clearCallingIdentity();
4950 try {
4951 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004952 int slotId = getSlotIndex(subId);
4953 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4954 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4955 + subId + "' for key:" + key);
4956 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4957 }
calvinpanb5a34062021-02-08 19:59:36 +08004958 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4959 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004960 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004961 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004962 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004963 } finally {
4964 Binder.restoreCallingIdentity(identity);
4965 }
4966 }
4967
Brad Ebinger919631e2021-06-02 17:46:35 -07004968 /**
4969 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4970 * for the given slot ID or no ImsResolver instance has been created.
4971 * @param slotId The slot ID that the IMS service is created for.
4972 * @throws ImsException If there is no ImsService configured for this slot.
4973 */
4974 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4975 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4976 ImsFeature.FEATURE_MMTEL)) {
4977 throw new ImsException("This subscription does not support MMTEL over IMS",
4978 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4979 }
4980 }
4981
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004982 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004983 int slotId = SubscriptionManager.getSlotIndex(subId);
4984 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004985 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4986 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004987 }
4988 return slotId;
4989 }
4990
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004991 private int getSlotIndex(int subId) {
4992 int slotId = SubscriptionManager.getSlotIndex(subId);
4993 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4994 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4995 }
4996 return slotId;
4997 }
4998
Wink Saville36469e72014-06-11 15:17:00 -07004999 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005000 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005001 */
5002 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005003 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5004 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005005 try {
5006 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5007 } catch (SecurityException se) {
5008 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5009 throw new SecurityException("Package " + callingPackage + " does not belong to "
5010 + Binder.getCallingUid());
5011 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005012 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005013 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005014 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005015 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005016 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005017 mApp, subId, callingPackage, callingFeatureId,
5018 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005019 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5020 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005021
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005022 final long identity = Binder.clearCallingIdentity();
5023 try {
5024 final Phone phone = getPhone(subId);
5025 if (phone != null) {
5026 return phone.getServiceState().getDataNetworkType();
5027 } else {
5028 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5029 }
5030 } finally {
5031 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005032 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005033 }
5034
5035 /**
5036 * Returns the data network type
5037 */
5038 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005039 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005040 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5041 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005042 }
5043
5044 /**
5045 * Returns the data network type for a subId
5046 */
5047 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005048 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5049 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005050 String functionName = "getDataNetworkTypeForSubscriber";
5051 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5052 mApp, functionName)) {
5053 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5054 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5055 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5056 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005057 }
5058
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005059 final long identity = Binder.clearCallingIdentity();
5060 try {
5061 final Phone phone = getPhone(subId);
5062 if (phone != null) {
5063 return phone.getServiceState().getDataNetworkType();
5064 } else {
5065 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5066 }
5067 } finally {
5068 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005069 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005070 }
5071
5072 /**
Wink Saville36469e72014-06-11 15:17:00 -07005073 * Returns the Voice network type for a subId
5074 */
5075 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005076 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5077 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005078 String functionName = "getVoiceNetworkTypeForSubscriber";
5079 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5080 mApp, functionName)) {
5081 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5082 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5083 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5084 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005085 }
5086
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005087 final long identity = Binder.clearCallingIdentity();
5088 try {
5089 final Phone phone = getPhone(subId);
5090 if (phone != null) {
5091 return phone.getServiceState().getVoiceNetworkType();
5092 } else {
5093 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5094 }
5095 } finally {
5096 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005097 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005098 }
5099
5100 /**
5101 * @return true if a ICC card is present
5102 */
5103 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005104 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005105 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5106 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005107 }
5108
5109 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005110 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005111 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005112 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005113 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005114 final long identity = Binder.clearCallingIdentity();
5115 try {
5116 final Phone phone = PhoneFactory.getPhone(slotIndex);
5117 if (phone != null) {
5118 return phone.getIccCard().hasIccCard();
5119 } else {
5120 return false;
5121 }
5122 } finally {
5123 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005124 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005125 }
5126
5127 /**
5128 * Return if the current radio is LTE on CDMA. This
5129 * is a tri-state return value as for a period of time
5130 * the mode may be unknown.
5131 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005132 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005133 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005134 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005135 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005136 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005137 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5138 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5139 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005140 }
5141
Sanket Padawe356d7632015-06-22 14:03:32 -07005142 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005143 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5144 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005145 try {
5146 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5147 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005148 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5149 }
5150
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005151 final long identity = Binder.clearCallingIdentity();
5152 try {
5153 final Phone phone = getPhone(subId);
5154 if (phone == null) {
5155 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5156 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005157 return TelephonyProperties.lte_on_cdma_device()
5158 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005159 }
5160 } finally {
5161 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005162 }
Wink Saville36469e72014-06-11 15:17:00 -07005163 }
5164
Wink Saville36469e72014-06-11 15:17:00 -07005165 /**
5166 * {@hide}
5167 * Returns Default subId, 0 in the case of single standby.
5168 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005169 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005170 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005171 }
5172
Shishir Agrawala9f32182016-04-12 12:00:16 -07005173 private int getSlotForDefaultSubscription() {
5174 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5175 }
5176
Wink Savilleb564aae2014-10-23 10:18:09 -07005177 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005178 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005179 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005180
Pengquan Menge92a50d2018-09-21 15:54:48 -07005181 private boolean isActiveSubscription(int subId) {
5182 return mSubscriptionController.isActiveSubId(subId);
5183 }
5184
Ihab Awadf2177b72013-11-25 13:33:23 -08005185 /**
5186 * @see android.telephony.TelephonyManager.WifiCallingChoices
5187 */
5188 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005189 final long identity = Binder.clearCallingIdentity();
5190 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005191 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005192 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5193 getWhenToMakeWifiCallsDefaultPreference());
5194 } finally {
5195 Binder.restoreCallingIdentity(identity);
5196 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005197 }
5198
5199 /**
5200 * @see android.telephony.TelephonyManager.WifiCallingChoices
5201 */
5202 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005203 final long identity = Binder.clearCallingIdentity();
5204 try {
5205 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005206 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005207 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5208 } finally {
5209 Binder.restoreCallingIdentity(identity);
5210 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005211 }
5212
Sailesh Nepald1e68152013-12-12 19:08:02 -08005213 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005214 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005215 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005216 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005217
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005218 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5219 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5220 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005221 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005222 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5223 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005224 }
5225 return PhoneFactory.getPhone(phoneId);
5226 }
5227
Shishir Agrawal566b7612013-10-28 14:41:00 -07005228 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005229 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005230 @NonNull IccLogicalChannelRequest request) {
5231 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5232 /*message=*/ "iccOpenLogicalChannel");
5233
5234 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5235 // Verify that the callingPackage in the request belongs to the calling UID
5236 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5237
5238 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005239 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005240
Rambo Wanga1782702021-11-10 20:15:19 -08005241 private Phone getPhoneFromValidIccLogicalChannelRequest(
5242 @NonNull IccLogicalChannelRequest request, String message) {
5243 Phone phone;
5244 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5245 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5246 mApp, request.subId, message);
5247 phone = getPhoneFromSubId(request.subId);
5248 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5249 enforceModifyPermission();
5250 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5251 } else {
5252 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005253 }
Rambo Wanga1782702021-11-10 20:15:19 -08005254 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005255 }
5256
5257 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005258 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005259 final long identity = Binder.clearCallingIdentity();
5260 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005261 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005262 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005263 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5264 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005265 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5266 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005267 loge("The calling package is not allowed to access ISD-R.");
5268 throw new SecurityException(
5269 "The calling package is not allowed to access ISD-R.");
5270 }
Derek Tan740e1672017-06-27 14:56:27 -07005271 }
Derek Tan740e1672017-06-27 14:56:27 -07005272
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005273 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005274 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5275 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005276 return response;
5277 } finally {
5278 Binder.restoreCallingIdentity(identity);
5279 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005280 }
5281
5282 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005283 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5284 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5285 /*message=*/"iccCloseLogicalChannel");
5286
5287 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5288
5289 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005290 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005291
Rambo Wanga1782702021-11-10 20:15:19 -08005292 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5293 IccLogicalChannelRequest request) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005294 final long identity = Binder.clearCallingIdentity();
5295 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005296 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005297 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005298 }
Chen Xue9d737e2022-01-01 23:41:31 -08005299 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005300 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005301 Boolean success = false;
5302 if (result instanceof RuntimeException) {
5303 // if there is an exception returned, throw from the binder thread here.
5304 throw (RuntimeException) result;
5305 } else if (result instanceof Boolean) {
5306 success = (Boolean) result;
5307 } else {
5308 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5309 }
Rambo Wanga1782702021-11-10 20:15:19 -08005310 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005311 return success;
5312 } finally {
5313 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005314 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005315 }
5316
5317 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005318 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005319 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005320 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5321 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005322 if (DBG) {
5323 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5324 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5325 + p3 + " data=" + data);
5326 }
5327 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5328 command, p1, p2, p3, data);
5329 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005330
Jordan Liu4c733742019-02-28 12:03:40 -08005331 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005332 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5333 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005334 enforceModifyPermission();
5335 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005336 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5337 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5338 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005339 }
5340 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005341 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5342 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005343 }
5344
5345 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5346 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005347 final long identity = Binder.clearCallingIdentity();
5348 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005349 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005350 return "";
5351 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005352
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005353 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005354 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5355 null /* workSource */);
5356 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005357
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005358 // Append the returned status code to the end of the response payload.
5359 String s = Integer.toHexString(
5360 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5361 if (response.payload != null) {
5362 s = IccUtils.bytesToHexString(response.payload) + s;
5363 }
5364 return s;
5365 } finally {
5366 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005367 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005368 }
Jake Hambye994d462014-02-03 13:10:13 -08005369
Evan Charltonc66da362014-05-16 14:06:40 -07005370 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005371 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5372 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005373 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5374 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005375 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005376 if (DBG) {
5377 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5378 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5379 }
5380 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5381 cla, command, p1, p2, p3, data);
5382 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005383
Jordan Liu4c733742019-02-28 12:03:40 -08005384 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005385 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5386 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005387 enforceModifyPermission();
5388 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5389 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005390 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5391 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5392 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005393 }
5394
5395 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005396 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5397 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005398 }
5399
5400 // open APDU basic channel assuming the caller has sufficient permissions
5401 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5402 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005403 final long identity = Binder.clearCallingIdentity();
5404 try {
5405 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5406 && TextUtils.equals(ISDR_AID, data)) {
5407 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005408 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5409 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005410 if (bestComponent == null
5411 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5412 loge("The calling package is not allowed to select ISD-R.");
5413 throw new SecurityException(
5414 "The calling package is not allowed to select ISD-R.");
5415 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005416 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005417
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005418 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005419 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5420 null /* workSource */);
5421 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005422
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005423 // Append the returned status code to the end of the response payload.
5424 String s = Integer.toHexString(
5425 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5426 if (response.payload != null) {
5427 s = IccUtils.bytesToHexString(response.payload) + s;
5428 }
5429 return s;
5430 } finally {
5431 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005432 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005433 }
5434
5435 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005436 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005437 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005438 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5439 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005440
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005441 final long identity = Binder.clearCallingIdentity();
5442 try {
5443 if (DBG) {
5444 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5445 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5446 }
5447
5448 IccIoResult response =
5449 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5450 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5451 subId);
5452
5453 if (DBG) {
5454 log("Exchange SIM_IO [R]" + response);
5455 }
5456
5457 byte[] result = null;
5458 int length = 2;
5459 if (response.payload != null) {
5460 length = 2 + response.payload.length;
5461 result = new byte[length];
5462 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5463 } else {
5464 result = new byte[length];
5465 }
5466
5467 result[length - 1] = (byte) response.sw2;
5468 result[length - 2] = (byte) response.sw1;
5469 return result;
5470 } finally {
5471 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005472 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005473 }
5474
Nathan Haroldb3014052017-01-25 15:57:32 -08005475 /**
5476 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5477 * on a particular subscription
5478 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005479 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5480 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005481 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005482 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005483 return null;
5484 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005485
5486 final long identity = Binder.clearCallingIdentity();
5487 try {
5488 if (appType != TelephonyManager.APPTYPE_USIM
5489 && appType != TelephonyManager.APPTYPE_SIM) {
5490 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5491 return null;
5492 }
5493 Object response = sendRequest(
5494 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5495 if (response instanceof String[]) {
5496 return (String[]) response;
5497 }
yincheng zhao2737e882019-09-06 17:06:54 -07005498 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005499 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005500 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005501 } finally {
5502 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005503 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005504 }
5505
yincheng zhao2737e882019-09-06 17:06:54 -07005506 /**
5507 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5508 * subscription.
5509 *
5510 * @param subId the id of the subscription.
5511 * @param appType the uicc app type, must be USIM or SIM.
5512 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5513 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005514 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005515 * @return number of fplmns that is successfully written to the SIM.
5516 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005517 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5518 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005519 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5520 mApp, subId, "setForbiddenPlmns");
5521
yincheng zhao2737e882019-09-06 17:06:54 -07005522 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5523 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5524 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5525 }
5526 if (fplmns == null) {
5527 throw new IllegalArgumentException("Fplmn List provided is null");
5528 }
5529 for (String fplmn : fplmns) {
5530 if (!CellIdentity.isValidPlmn(fplmn)) {
5531 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5532 }
5533 }
5534 final long identity = Binder.clearCallingIdentity();
5535 try {
5536 Object response = sendRequest(
5537 CMD_SET_FORBIDDEN_PLMNS,
5538 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5539 subId);
5540 return (int) response;
5541 } finally {
5542 Binder.restoreCallingIdentity(identity);
5543 }
5544 }
5545
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005546 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005547 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005548 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5549 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005550
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005551 final long identity = Binder.clearCallingIdentity();
5552 try {
5553 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5554 if (response.payload == null) {
5555 return "";
5556 }
Evan Charltonc66da362014-05-16 14:06:40 -07005557
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005558 // Append the returned status code to the end of the response payload.
5559 String s = Integer.toHexString(
5560 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5561 s = IccUtils.bytesToHexString(response.payload) + s;
5562 return s;
5563 } finally {
5564 Binder.restoreCallingIdentity(identity);
5565 }
Evan Charltonc66da362014-05-16 14:06:40 -07005566 }
5567
Jake Hambye994d462014-02-03 13:10:13 -08005568 /**
5569 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5570 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5571 *
5572 * @param itemID the ID of the item to read
5573 * @return the NV item as a String, or null on error.
5574 */
5575 @Override
5576 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005577 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005578 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5579 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005580
5581 final long identity = Binder.clearCallingIdentity();
5582 try {
5583 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005584 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005585 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5586 return value;
5587 } finally {
5588 Binder.restoreCallingIdentity(identity);
5589 }
Jake Hambye994d462014-02-03 13:10:13 -08005590 }
5591
5592 /**
5593 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5594 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5595 *
5596 * @param itemID the ID of the item to read
5597 * @param itemValue the value to write, as a String
5598 * @return true on success; false on any failure
5599 */
5600 @Override
5601 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005602 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005603 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5604 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005605
5606 final long identity = Binder.clearCallingIdentity();
5607 try {
5608 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5609 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005610 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005611 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5612 return success;
5613 } finally {
5614 Binder.restoreCallingIdentity(identity);
5615 }
Jake Hambye994d462014-02-03 13:10:13 -08005616 }
5617
5618 /**
5619 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5620 * Used for device configuration by some CDMA operators.
5621 *
5622 * @param preferredRoamingList byte array containing the new PRL
5623 * @return true on success; false on any failure
5624 */
5625 @Override
5626 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005627 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5628 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005629
5630 final long identity = Binder.clearCallingIdentity();
5631 try {
5632 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5633 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5634 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5635 return success;
5636 } finally {
5637 Binder.restoreCallingIdentity(identity);
5638 }
Jake Hambye994d462014-02-03 13:10:13 -08005639 }
5640
5641 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005642 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005643 * Used for device configuration by some CDMA operators.
5644 *
chen xu6dac5ab2018-10-26 17:39:23 -07005645 * @param slotIndex - device slot.
5646 *
Jake Hambye994d462014-02-03 13:10:13 -08005647 * @return true on success; false on any failure
5648 */
5649 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005650 public boolean resetModemConfig(int slotIndex) {
5651 Phone phone = PhoneFactory.getPhone(slotIndex);
5652 if (phone != null) {
5653 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5654 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005655
chen xu6dac5ab2018-10-26 17:39:23 -07005656 final long identity = Binder.clearCallingIdentity();
5657 try {
5658 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5659 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5660 return success;
5661 } finally {
5662 Binder.restoreCallingIdentity(identity);
5663 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005664 }
chen xu6dac5ab2018-10-26 17:39:23 -07005665 return false;
5666 }
5667
5668 /**
5669 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5670 *
5671 * @param slotIndex - device slot.
5672 *
5673 * @return true on success; false on any failure
5674 */
5675 @Override
5676 public boolean rebootModem(int slotIndex) {
5677 Phone phone = PhoneFactory.getPhone(slotIndex);
5678 if (phone != null) {
5679 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5680 mApp, phone.getSubId(), "rebootModem");
5681
5682 final long identity = Binder.clearCallingIdentity();
5683 try {
5684 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5685 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5686 return success;
5687 } finally {
5688 Binder.restoreCallingIdentity(identity);
5689 }
5690 }
5691 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005692 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005693
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005694 public String[] getPcscfAddress(String apnType, String callingPackage,
5695 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005696 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005697 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5698 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005699 return new String[0];
5700 }
5701
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005702 final long identity = Binder.clearCallingIdentity();
5703 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005704 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005705 } finally {
5706 Binder.restoreCallingIdentity(identity);
5707 }
Wink Saville36469e72014-06-11 15:17:00 -07005708 }
5709
Brad Ebinger51f743a2017-01-23 13:50:20 -08005710 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005711 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5712 * {@link #disableIms(int)}.
5713 * @param slotIndex device slot.
5714 */
5715 public void resetIms(int slotIndex) {
5716 enforceModifyPermission();
5717
5718 final long identity = Binder.clearCallingIdentity();
5719 try {
5720 if (mImsResolver == null) {
5721 // may happen if the does not support IMS.
5722 return;
5723 }
5724 mImsResolver.disableIms(slotIndex);
5725 mImsResolver.enableIms(slotIndex);
5726 } finally {
5727 Binder.restoreCallingIdentity(identity);
5728 }
5729 }
5730
5731 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005732 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5733 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005734 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005735 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005736 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005737
5738 final long identity = Binder.clearCallingIdentity();
5739 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005740 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005741 // may happen if the device does not support IMS.
5742 return;
5743 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005744 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005745 } finally {
5746 Binder.restoreCallingIdentity(identity);
5747 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005748 }
5749
5750 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005751 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5752 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005753 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005754 public void disableIms(int slotId) {
5755 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005756
5757 final long identity = Binder.clearCallingIdentity();
5758 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005759 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005760 // may happen if the device does not support IMS.
5761 return;
5762 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005763 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005764 } finally {
5765 Binder.restoreCallingIdentity(identity);
5766 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005767 }
5768
5769 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005770 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5771 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005772 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005773 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005774 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005775 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005776
5777 final long identity = Binder.clearCallingIdentity();
5778 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005779 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005780 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5781 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005782 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005783 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005784 } finally {
5785 Binder.restoreCallingIdentity(identity);
5786 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005787 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005788 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005789 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5790 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005791 @Override
5792 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005793 enforceModifyPermission();
5794
5795 final long identity = Binder.clearCallingIdentity();
5796 try {
5797 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005798 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005799 } finally {
5800 Binder.restoreCallingIdentity(identity);
5801 }
5802 }
5803
5804 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005805 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005806 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005807 */
5808 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5809 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005810
5811 final long identity = Binder.clearCallingIdentity();
5812 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005813 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005814 // may happen if the device does not support IMS.
5815 return null;
5816 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005817 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005818 } finally {
5819 Binder.restoreCallingIdentity(identity);
5820 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005821 }
5822
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005823 /**
5824 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005825 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005826 */
5827 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5828 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005829
5830 final long identity = Binder.clearCallingIdentity();
5831 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005832 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005833 // may happen if the device does not support IMS.
5834 return null;
5835 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005836 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005837 } finally {
5838 Binder.restoreCallingIdentity(identity);
5839 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005840 }
5841
Brad Ebinger884c07b2018-02-15 16:17:40 -08005842 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005843 * Sets the ImsService Package Name that Telephony will bind to.
5844 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005845 * @param slotIndex the slot ID that the ImsService should bind for.
5846 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005847 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005848 * @param featureTypes An integer array of feature types associated with a packageName.
5849 * @param packageName The name of the package that the current configuration will be replaced
5850 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005851 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005852 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005853 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5854 int[] featureTypes, String packageName) {
5855 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5856 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005857 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5858 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005859 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005860
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005861 final long identity = Binder.clearCallingIdentity();
5862 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005863 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005864 // may happen if the device does not support IMS.
5865 return false;
5866 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005867 Map<Integer, String> featureConfig = new HashMap<>();
5868 for (int featureType : featureTypes) {
5869 featureConfig.put(featureType, packageName);
5870 }
5871 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5872 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005873 } finally {
5874 Binder.restoreCallingIdentity(identity);
5875 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005876 }
5877
5878 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005879 * Clears any carrier ImsService overrides for the slot index specified that were previously
5880 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5881 *
5882 * This should only be used for testing.
5883 *
5884 * @param slotIndex the slot ID that the ImsService should bind for.
5885 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5886 */
5887 @Override
5888 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5889 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5890 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5891 "clearCarrierImsServiceOverride");
5892 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5893 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5894 "clearCarrierImsServiceOverride");
5895
5896 final long identity = Binder.clearCallingIdentity();
5897 try {
5898 if (mImsResolver == null) {
5899 // may happen if the device does not support IMS.
5900 return false;
5901 }
5902 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5903 } finally {
5904 Binder.restoreCallingIdentity(identity);
5905 }
5906 }
5907
5908 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005909 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005910 *
5911 * @param slotId The slot that the ImsService is associated with.
5912 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5913 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005914 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005915 * @return the package name of the ImsService configuration.
5916 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005917 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5918 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005919 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005920 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005921 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005922 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5923 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005924
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005925 final long identity = Binder.clearCallingIdentity();
5926 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005927 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005928 // may happen if the device does not support IMS.
5929 return "";
5930 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005931 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005932 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5933 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005934 } finally {
5935 Binder.restoreCallingIdentity(identity);
5936 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005937 }
5938
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005939 /**
5940 * Get the MmTelFeature state associated with the requested subscription id.
5941 * @param subId The subscription that the MmTelFeature is associated with.
5942 * @param callback A callback with an integer containing the
5943 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5944 */
5945 @Override
5946 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5947 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5948 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5949 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5950 "IMS not available on device.");
5951 }
5952 final long token = Binder.clearCallingIdentity();
5953 try {
5954 int slotId = getSlotIndex(subId);
5955 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5956 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5957 + subId + "'");
5958 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5959 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005960 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005961 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5962 try {
5963 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5964 } catch (RemoteException e) {
5965 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5966 + "Ignore");
5967 }
5968 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005969 } catch (ImsException e) {
5970 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005971 } finally {
5972 Binder.restoreCallingIdentity(token);
5973 }
5974 }
5975
Daniel Brightbb5840b2021-01-12 15:48:18 -08005976 /**
5977 * Sets the ims registration state on all valid {@link Phone}s.
5978 */
5979 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005980 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005981
5982 final long identity = Binder.clearCallingIdentity();
5983 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005984 // NOTE: Before S, this method only set the default phone.
5985 for (final Phone phone : PhoneFactory.getPhones()) {
5986 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5987 phone.setImsRegistrationState(registered);
5988 }
5989 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005990 } finally {
5991 Binder.restoreCallingIdentity(identity);
5992 }
Wink Saville36469e72014-06-11 15:17:00 -07005993 }
5994
5995 /**
Stuart Scott54788802015-03-30 13:18:01 -07005996 * Set the network selection mode to automatic.
5997 *
5998 */
5999 @Override
6000 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006001 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6002 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006003
6004 final long identity = Binder.clearCallingIdentity();
6005 try {
shilufc958392020-01-20 11:36:01 -08006006 if (!isActiveSubscription(subId)) {
6007 return;
6008 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006009 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006010 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6011 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006012 } finally {
6013 Binder.restoreCallingIdentity(identity);
6014 }
Stuart Scott54788802015-03-30 13:18:01 -07006015 }
6016
Jack Yud10cdd42020-09-28 20:28:01 -07006017 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006018 * Ask the radio to connect to the input network and change selection mode to manual.
6019 *
6020 * @param subId the id of the subscription.
6021 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6022 * the operator to attach to.
6023 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6024 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6025 * normal network selection next time.
6026 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006027 */
6028 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006029 public boolean setNetworkSelectionModeManual(
6030 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006031 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6032 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006033
6034 if (!isActiveSubscription(subId)) {
6035 return false;
6036 }
6037
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006038 final long identity = Binder.clearCallingIdentity();
6039 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006040 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006041 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006042 if (DBG) {
6043 log("setNetworkSelectionModeManual: subId: " + subId
6044 + " operator: " + operatorInfo);
6045 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006046 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6047 } finally {
6048 Binder.restoreCallingIdentity(identity);
6049 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006050 }
shilu84f6e8b2019-12-19 13:58:01 -08006051 /**
6052 * Get the manual network selection
6053 *
6054 * @param subId the id of the subscription.
6055 *
6056 * @return the previously saved user selected PLMN
6057 */
6058 @Override
6059 public String getManualNetworkSelectionPlmn(int subId) {
6060 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006061 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006062 mApp, subId, "getManualNetworkSelectionPlmn");
6063
6064 final long identity = Binder.clearCallingIdentity();
6065 try {
6066 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006067 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006068 }
6069
6070 final Phone phone = getPhone(subId);
6071 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006072 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006073 }
6074 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6075 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6076 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6077 } finally {
6078 Binder.restoreCallingIdentity(identity);
6079 }
6080 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006081
6082 /**
6083 * Scans for available networks.
6084 */
6085 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006086 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6087 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006088 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6089 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006090 LocationAccessPolicy.LocationPermissionResult locationResult =
6091 LocationAccessPolicy.checkLocationPermission(mApp,
6092 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6093 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006094 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006095 .setCallingPid(Binder.getCallingPid())
6096 .setCallingUid(Binder.getCallingUid())
6097 .setMethod("getCellNetworkScanResults")
6098 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006099 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6100 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006101 .build());
6102 switch (locationResult) {
6103 case DENIED_HARD:
6104 throw new SecurityException("Not allowed to access scan results -- location");
6105 case DENIED_SOFT:
6106 return null;
6107 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006108
Pengquan Menga1bb6272018-09-06 09:59:22 -07006109 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006110 try {
6111 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006112 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006113 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006114 } finally {
6115 Binder.restoreCallingIdentity(identity);
6116 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006117 }
6118
6119 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006120 * Get the call forwarding info, given the call forwarding reason.
6121 */
6122 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006123 public void getCallForwarding(int subId, int callForwardingReason,
6124 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006125 enforceReadPrivilegedPermission("getCallForwarding");
6126 long identity = Binder.clearCallingIdentity();
6127 try {
6128 if (DBG) {
6129 log("getCallForwarding: subId " + subId
6130 + " callForwardingReason" + callForwardingReason);
6131 }
Hall Liu27d24262020-09-18 19:04:59 -07006132
6133 Phone phone = getPhone(subId);
6134 if (phone == null) {
6135 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006136 callback.onError(
6137 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006138 } catch (RemoteException e) {
6139 // ignore
6140 }
6141 return;
6142 }
6143
6144 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6145 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6146 @Override
6147 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6148 try {
6149 callback.onCallForwardingInfoAvailable(info);
6150 } catch (RemoteException e) {
6151 // ignore
6152 }
6153 }
6154
6155 @Override
6156 public void onError(int error) {
6157 try {
6158 callback.onError(error);
6159 } catch (RemoteException e) {
6160 // ignore
6161 }
6162 }
6163 });
6164 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006165 } finally {
6166 Binder.restoreCallingIdentity(identity);
6167 }
6168 }
6169
6170 /**
6171 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6172 * reason, the number to forward, and the timeout before the forwarding is attempted.
6173 */
6174 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006175 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6176 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006177 enforceModifyPermission();
6178 long identity = Binder.clearCallingIdentity();
6179 try {
6180 if (DBG) {
6181 log("setCallForwarding: subId " + subId
6182 + " callForwardingInfo" + callForwardingInfo);
6183 }
Hall Liu27d24262020-09-18 19:04:59 -07006184
6185 Phone phone = getPhone(subId);
6186 if (phone == null) {
6187 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006188 callback.accept(
6189 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006190 } catch (RemoteException e) {
6191 // ignore
6192 }
6193 return;
6194 }
6195
6196 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6197 FunctionalUtils.ignoreRemoteException(callback::accept));
6198
6199 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006200 } finally {
6201 Binder.restoreCallingIdentity(identity);
6202 }
6203 }
6204
6205 /**
Hall Liu27d24262020-09-18 19:04:59 -07006206 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006207 */
6208 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006209 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006210 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006211 long identity = Binder.clearCallingIdentity();
6212 try {
Hall Liu27d24262020-09-18 19:04:59 -07006213 Phone phone = getPhone(subId);
6214 if (phone == null) {
6215 try {
6216 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6217 } catch (RemoteException e) {
6218 // ignore
6219 }
6220 return;
6221 }
SongFerngWang0e767992021-03-31 22:08:45 +08006222 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6223 PersistableBundle c = configManager.getConfigForSubId(subId);
6224 boolean requireUssd = c.getBoolean(
6225 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006226
Shuo Qian4a594052020-01-23 11:59:30 -08006227 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006228 if (requireUssd) {
6229 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6230 getSubscriptionCarrierId(subId));
6231 String newUssdCommand = "";
6232 try {
6233 newUssdCommand = carrierXmlParser.getFeature(
6234 CarrierXmlParser.FEATURE_CALL_WAITING)
6235 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6236 } catch (NullPointerException e) {
6237 loge("Failed to generate USSD number" + e);
6238 }
6239 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6240 mMainThreadHandler, callback, carrierXmlParser,
6241 CarrierXmlParser.SsEntry.SSAction.QUERY);
6242 final String ussdCommand = newUssdCommand;
6243 Executors.newSingleThreadExecutor().execute(() -> {
6244 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6245 });
6246 } else {
6247 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6248 callback::accept);
6249 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6250 }
Shuo Qian4a594052020-01-23 11:59:30 -08006251 } finally {
6252 Binder.restoreCallingIdentity(identity);
6253 }
6254 }
6255
6256 /**
Hall Liu27d24262020-09-18 19:04:59 -07006257 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006258 */
6259 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006260 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006261 enforceModifyPermission();
6262 long identity = Binder.clearCallingIdentity();
6263 try {
Hall Liu27d24262020-09-18 19:04:59 -07006264 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6265
6266 Phone phone = getPhone(subId);
6267 if (phone == null) {
6268 try {
6269 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6270 } catch (RemoteException e) {
6271 // ignore
6272 }
6273 return;
6274 }
6275
SongFerngWang0e767992021-03-31 22:08:45 +08006276 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6277 PersistableBundle c = configManager.getConfigForSubId(subId);
6278 boolean requireUssd = c.getBoolean(
6279 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006280
SongFerngWang0e767992021-03-31 22:08:45 +08006281 if (DBG) log("getCallWaitingStatus: subId " + subId);
6282 if (requireUssd) {
6283 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6284 getSubscriptionCarrierId(subId));
6285 CarrierXmlParser.SsEntry.SSAction ssAction =
6286 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6287 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6288 String newUssdCommand = "";
6289 try {
6290 newUssdCommand = carrierXmlParser.getFeature(
6291 CarrierXmlParser.FEATURE_CALL_WAITING)
6292 .makeCommand(ssAction, null);
6293 } catch (NullPointerException e) {
6294 loge("Failed to generate USSD number" + e);
6295 }
6296 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6297 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6298 final String ussdCommand = newUssdCommand;
6299 Executors.newSingleThreadExecutor().execute(() -> {
6300 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6301 });
6302 } else {
6303 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6304 FunctionalUtils.ignoreRemoteException(callback::accept));
6305
6306 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6307 }
Shuo Qian4a594052020-01-23 11:59:30 -08006308 } finally {
6309 Binder.restoreCallingIdentity(identity);
6310 }
6311 }
6312
6313 /**
yinxub1bed742017-04-17 11:45:04 -07006314 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006315 *
yinxub1bed742017-04-17 11:45:04 -07006316 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006317 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6318 * location related information which will be sent if the caller already possess
6319 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006320 * @param request contains the radio access networks with bands/channels to scan
6321 * @param messenger callback messenger for scan results or errors
6322 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006323 * @return the id of the requested scan which can be used to stop the scan.
6324 */
6325 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006326 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6327 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006328 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006329 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6330 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006331 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006332 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6333 if (!renounceFineLocationAccess) {
6334 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6335 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6336 .setCallingPackage(callingPackage)
6337 .setCallingFeatureId(callingFeatureId)
6338 .setCallingPid(Binder.getCallingPid())
6339 .setCallingUid(Binder.getCallingUid())
6340 .setMethod("requestNetworkScan")
6341 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6342 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6343 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6344 .build());
6345 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006346 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006347 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6348 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006349 if (e != null) {
6350 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6351 throw e;
6352 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006353 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006354 return TelephonyScanManager.INVALID_SCAN_ID;
6355 }
6356 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006357 }
Hall Liu912dfd32019-04-25 14:02:26 -07006358 int callingUid = Binder.getCallingUid();
6359 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006360 final long identity = Binder.clearCallingIdentity();
6361 try {
6362 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006363 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006364 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006365 } finally {
6366 Binder.restoreCallingIdentity(identity);
6367 }
yinxu504e1392017-04-12 16:03:22 -07006368 }
6369
Hall Liub2ac8ef2019-02-28 15:56:23 -08006370 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006371 NetworkScanRequest request, int subId, String callingPackage) {
6372 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006373 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6374 boolean hasNetworkScanPermission =
6375 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6376 == PERMISSION_GRANTED;
6377
6378 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6379 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6380 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006381 }
6382
6383 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6384 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006385 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6386 return new SecurityException("Specific channels must not be"
6387 + " scanned without location access.");
6388 }
6389 }
6390 }
6391
Hall Liub2ac8ef2019-02-28 15:56:23 -08006392 return null;
6393 }
6394
yinxu504e1392017-04-12 16:03:22 -07006395 /**
6396 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006397 *
6398 * @param subId id of the subscription
6399 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006400 */
6401 @Override
6402 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006403 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6404 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006405
Hall Liu912dfd32019-04-25 14:02:26 -07006406 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006407 final long identity = Binder.clearCallingIdentity();
6408 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006409 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006410 } finally {
6411 Binder.restoreCallingIdentity(identity);
6412 }
yinxu504e1392017-04-12 16:03:22 -07006413 }
6414
6415 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006416 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006417 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006418 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006419 */
6420 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006421 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006422 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006423 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006424 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006425
6426 final long identity = Binder.clearCallingIdentity();
6427 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006428 if (DBG) log("getAllowedNetworkTypesBitmask");
6429 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6430 int networkTypesBitmask = (result != null ? result[0] : -1);
6431 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6432 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006433 } finally {
6434 Binder.restoreCallingIdentity(identity);
6435 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006436 }
6437
6438 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006439 * Get the allowed network types for certain reason.
6440 *
6441 * @param subId the id of the subscription.
6442 * @param reason the reason the allowed network type change is taking place
6443 * @return the allowed network types.
6444 */
6445 @Override
6446 public long getAllowedNetworkTypesForReason(int subId,
6447 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006448 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006449 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006450 final long identity = Binder.clearCallingIdentity();
6451 try {
6452 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6453 } finally {
6454 Binder.restoreCallingIdentity(identity);
6455 }
6456 }
6457
6458 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006459 * Enable/Disable E-UTRA-NR Dual Connectivity
6460 * @param subId subscription id of the sim card
6461 * @param nrDualConnectivityState expected NR dual connectivity state
6462 * This can be passed following states
6463 * <ol>
6464 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6465 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6466 * <li>Disable NR dual connectivity and force secondary cell to be released
6467 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6468 * </ol>
6469 * @return operation result.
6470 */
6471 @Override
6472 public int setNrDualConnectivityState(int subId,
6473 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6474 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6475 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006476 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006477 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6478 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6479 }
6480
Sooraj Sasindran37444802020-08-11 10:40:43 -07006481 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6482 final long identity = Binder.clearCallingIdentity();
6483 try {
6484 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6485 nrDualConnectivityState, subId,
6486 workSource);
6487 if (DBG) log("enableNRDualConnectivity result: " + result);
6488 return result;
6489 } finally {
6490 Binder.restoreCallingIdentity(identity);
6491 }
6492 }
6493
6494 /**
6495 * Is E-UTRA-NR Dual Connectivity enabled
6496 * @return true if dual connectivity is enabled else false
6497 */
6498 @Override
6499 public boolean isNrDualConnectivityEnabled(int subId) {
6500 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006501 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006502 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006503 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006504 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6505 return false;
6506 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006507 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6508 final long identity = Binder.clearCallingIdentity();
6509 try {
6510 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6511 null, subId, workSource);
6512 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6513 return isEnabled;
6514 } finally {
6515 Binder.restoreCallingIdentity(identity);
6516 }
6517 }
6518
6519 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006520 * Set the allowed network types of the device and
6521 * provide the reason triggering the allowed network change.
6522 *
6523 * @param subId the id of the subscription.
6524 * @param reason the reason the allowed network type change is taking place
6525 * @param allowedNetworkTypes the allowed network types.
6526 * @return true on success; false on any failure.
6527 */
6528 @Override
6529 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006530 @TelephonyManager.AllowedNetworkTypesReason int reason,
6531 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006532 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6533 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006534 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006535 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6536 return false;
6537 }
6538 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6539 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006540 return false;
6541 }
6542
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006543 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6544 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6545
6546
6547 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6548 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6549 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006550 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006551
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006552 final long identity = Binder.clearCallingIdentity();
6553 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006554 Boolean success = (Boolean) sendRequest(
6555 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6556 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6557
6558 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6559 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006560 } finally {
6561 Binder.restoreCallingIdentity(identity);
6562 }
6563 }
6564
6565 /**
Miaoa84611c2019-03-15 09:21:10 +08006566 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006567 *
Miaoa84611c2019-03-15 09:21:10 +08006568 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006569 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006570 * @hide
6571 */
6572 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006573 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006574 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006575 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006576 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006577 try {
Miaoa84611c2019-03-15 09:21:10 +08006578 if (phone != null) {
6579 return phone.hasMatchedTetherApnSetting();
6580 } else {
6581 return false;
6582 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006583 } finally {
6584 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006585 }
Junda Liu475951f2014-11-07 16:45:03 -08006586 }
6587
6588 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006589 * Get the user enabled state of Mobile Data.
6590 *
6591 * TODO: remove and use isUserDataEnabled.
6592 * This can't be removed now because some vendor codes
6593 * calls through ITelephony directly while they should
6594 * use TelephonyManager.
6595 *
6596 * @return true on enabled
6597 */
6598 @Override
6599 public boolean getDataEnabled(int subId) {
6600 return isUserDataEnabled(subId);
6601 }
6602
6603 /**
6604 * Get whether mobile data is enabled per user setting.
6605 *
6606 * There are other factors deciding whether mobile data is actually enabled, but they are
6607 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006608 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006609 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6610 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006611 *
6612 * @return {@code true} if data is enabled else {@code false}
6613 */
6614 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006615 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006616 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006617 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006618 try {
6619 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6620 functionName);
6621 } catch (Exception e) {
6622 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6623 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006624 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006625 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006626 mApp, subId, functionName);
6627
Robert Greenwalt646120a2014-05-23 11:54:03 -07006628 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006629
6630 final long identity = Binder.clearCallingIdentity();
6631 try {
6632 int phoneId = mSubscriptionController.getPhoneId(subId);
6633 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6634 Phone phone = PhoneFactory.getPhone(phoneId);
6635 if (phone != null) {
6636 boolean retVal = phone.isUserDataEnabled();
6637 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6638 return retVal;
6639 } else {
6640 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6641 return false;
6642 }
6643 } finally {
6644 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006645 }
6646 }
6647
6648 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006649 * Checks if the device is capable of mobile data by considering whether whether the
6650 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6651 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006652 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006653 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006654 */
6655 @Override
6656 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006657 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006658 try {
6659 try {
6660 mApp.enforceCallingOrSelfPermission(
6661 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006662 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006663 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006664 try {
6665 mApp.enforceCallingOrSelfPermission(
6666 android.Manifest.permission.READ_PHONE_STATE,
6667 functionName);
6668 } catch (Exception e2) {
6669 mApp.enforceCallingOrSelfPermission(
6670 permission.READ_BASIC_PHONE_STATE, functionName);
6671 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006672 }
6673 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006674 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006675 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006676
6677 final long identity = Binder.clearCallingIdentity();
6678 try {
6679 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006680 Phone phone = PhoneFactory.getPhone(phoneId);
6681 if (phone != null) {
Jack Yu4ad64e52021-12-03 14:23:53 -08006682 boolean retVal;
6683 if (phone.isUsingNewDataStack()) {
6684 retVal = phone.getDataNetworkController().getDataSettingsManager()
6685 .isDataEnabled();
6686 } else {
6687 retVal = phone.getDataEnabledSettings().isDataEnabled();
6688 }
6689 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006690 return retVal;
6691 } else {
6692 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6693 return false;
6694 }
6695 } finally {
6696 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006697 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006698 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006699
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006700 /**
6701 * Check if data is enabled for a specific reason
6702 * @param subId Subscription index
6703 * @param reason the reason the data enable change is taking place
6704 * @return {@code true} if the overall data is enabled; {@code false} if not.
6705 */
6706 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006707 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006708 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006709 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006710 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006711 try {
6712 mApp.enforceCallingOrSelfPermission(
6713 android.Manifest.permission.ACCESS_NETWORK_STATE,
6714 functionName);
6715 } catch (Exception e) {
6716 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6717 functionName);
6718 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006719 } catch (Exception e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006720 try {
6721 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006722 functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006723 } catch (Exception e2) {
6724 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006725 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006726 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006727 }
6728
6729
6730 final long identity = Binder.clearCallingIdentity();
6731 try {
6732 int phoneId = mSubscriptionController.getPhoneId(subId);
6733 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006734 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006735 + " reason=" + reason);
6736 }
6737 Phone phone = PhoneFactory.getPhone(phoneId);
6738 if (phone != null) {
6739 boolean retVal;
Jack Yu99e87332021-12-17 23:14:15 -08006740 if (phone.isUsingNewDataStack()) {
6741 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006742 } else {
Jack Yu99e87332021-12-17 23:14:15 -08006743 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6744 retVal = phone.isUserDataEnabled();
6745 } else {
6746 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
6747 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006748 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006749 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006750 return retVal;
6751 } else {
6752 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006753 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006754 + subId + " retVal=false");
6755 }
6756 return false;
6757 }
6758 } finally {
6759 Binder.restoreCallingIdentity(identity);
6760 }
6761 }
6762
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006763 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006764 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006765 if (uid == Process.PHONE_UID) {
6766 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6767 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006768 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6769 }
6770
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006771 //load access rules from carrier configs, and check those as well: b/139133814
6772 SubscriptionController subController = SubscriptionController.getInstance();
6773 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6774 || subController == null) return privilegeFromSim;
6775
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006776 PackageManager pkgMgr = phone.getContext().getPackageManager();
6777 String[] packages = pkgMgr.getPackagesForUid(uid);
6778
6779 final long identity = Binder.clearCallingIdentity();
6780 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006781 int subId = phone.getSubId();
6782 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6783 // A test override is in place for the privileges for this subId, so don't try to
6784 // read the subscription privileges.
6785 return privilegeFromSim;
6786 }
6787 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006788 SubscriptionManager subManager = (SubscriptionManager)
6789 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6790 for (String pkg : packages) {
6791 if (subManager.canManageSubscription(subInfo, pkg)) {
6792 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6793 }
6794 }
6795 return privilegeFromSim;
6796 } finally {
6797 Binder.restoreCallingIdentity(identity);
6798 }
6799 }
6800
6801 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6802 String pkgName) {
6803 //load access rules from carrier configs, and check those as well: b/139133814
6804 SubscriptionController subController = SubscriptionController.getInstance();
6805 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6806 || subController == null) return privilegeFromSim;
6807
6808 final long identity = Binder.clearCallingIdentity();
6809 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006810 int subId = phone.getSubId();
6811 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6812 // A test override is in place for the privileges for this subId, so don't try to
6813 // read the subscription privileges.
6814 return privilegeFromSim;
6815 }
6816 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006817 SubscriptionManager subManager = (SubscriptionManager)
6818 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6819 return subManager.canManageSubscription(subInfo, pkgName)
6820 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6821 } finally {
6822 Binder.restoreCallingIdentity(identity);
6823 }
6824 }
6825
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006826 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006827 public int getCarrierPrivilegeStatus(int subId) {
6828 final Phone phone = getPhone(subId);
6829 if (phone == null) {
6830 loge("getCarrierPrivilegeStatus: Invalid subId");
6831 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6832 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006833 UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId());
6834 if (port == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006835 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006836 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6837 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006838
6839 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006840 port.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006841 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006842 }
Junda Liu29340342014-07-10 15:23:27 -07006843
6844 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006845 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006846 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006847 final Phone phone = getPhone(subId);
6848 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006849 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006850 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6851 }
6852 UiccProfile profile =
6853 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6854 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006855 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006856 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6857 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006858 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006859 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006860 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006861 }
6862
6863 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006864 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006865 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006866 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006867 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006868 }
6869
6870 int phoneId = SubscriptionManager.getPhoneId(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006871 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6872 if (port == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006873 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006874 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6875 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006876 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006877 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006878 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006879 }
6880
6881 @Override
6882 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006883 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006884 if (TextUtils.isEmpty(pkgName))
6885 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006886 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6887 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006888 UiccPort port = UiccController.getInstance().getUiccPort(i);
6889 if (port == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006890 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006891 continue;
6892 }
6893
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006894 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006895 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006896 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006897 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6898 break;
6899 }
6900 }
6901
6902 return result;
Junda Liu29340342014-07-10 15:23:27 -07006903 }
Derek Tan89e89d42014-07-08 17:00:10 -07006904
6905 @Override
Junda Liue64de782015-04-16 17:19:16 -07006906 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006907 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006908 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6909 loge("phoneId " + phoneId + " is not valid.");
6910 return null;
6911 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006912 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6913 if (port == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006914 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006915 return null ;
6916 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006917 return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006918 }
6919
Amith Yamasani6e118872016-02-19 12:53:51 -08006920 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006921 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006922 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006923 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006924 List<String> privilegedPackages = new ArrayList<>();
6925 List<PackageInfo> packages = null;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006926 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
chen xuf7e9fe82019-05-09 19:31:02 -07006927 // has UICC in that slot.
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006928 if (port != null) {
6929 if (port.hasCarrierPrivilegeRules()) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006930 if (packages == null) {
6931 // Only check packages in user 0 for now
6932 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006933 PackageManager.MATCH_DISABLED_COMPONENTS
6934 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006935 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006936 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006937 }
6938 for (int p = packages.size() - 1; p >= 0; p--) {
6939 PackageInfo pkgInfo = packages.get(p);
6940 if (pkgInfo != null && pkgInfo.packageName != null
Sooraj Sasindran97bce6f2021-09-28 21:37:29 +00006941 && getCarrierPrivilegeStatusFromCarrierConfigRules(
6942 port.getCarrierPrivilegeStatus(pkgInfo),
6943 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07006944 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006945 privilegedPackages.add(pkgInfo.packageName);
6946 }
6947 }
6948 }
6949 }
6950 return privilegedPackages;
6951 }
6952
chen xuf7e9fe82019-05-09 19:31:02 -07006953 @Override
6954 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006955 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6956
6957 final long identity = Binder.clearCallingIdentity();
6958
chen xuf7e9fe82019-05-09 19:31:02 -07006959 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006960 try {
6961 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6962 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6963 }
6964 } finally {
6965 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006966 }
6967 return privilegedPackages;
6968 }
6969
Wink Savilleb564aae2014-10-23 10:18:09 -07006970 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006971 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006972 UiccPort port = phone == null ? null : phone.getUiccPort();
6973 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006974 return null;
6975 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006976 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006977 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006978 return null;
6979 }
6980 return iccId;
6981 }
6982
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006983 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006984 public void setCallComposerStatus(int subId, int status) {
6985 enforceModifyPermission();
6986
6987 final long identity = Binder.clearCallingIdentity();
6988 try {
6989 Phone phone = getPhone(subId);
6990 if (phone != null) {
6991 Phone defaultPhone = phone.getImsPhone();
6992 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6993 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6994 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006995 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6996 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006997 }
6998 }
Shuo Qian284ae752020-12-22 19:10:14 -08006999 } catch (ImsException e) {
7000 throw new ServiceSpecificException(e.getCode());
7001 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007002 Binder.restoreCallingIdentity(identity);
7003 }
7004 }
7005
7006 @Override
7007 public int getCallComposerStatus(int subId) {
7008 enforceReadPrivilegedPermission("getCallComposerStatus");
7009
7010 final long identity = Binder.clearCallingIdentity();
7011 try {
7012 Phone phone = getPhone(subId);
7013 if (phone != null) {
7014 Phone defaultPhone = phone.getImsPhone();
7015 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7016 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7017 return imsPhone.getCallComposerStatus();
7018 }
7019 }
7020 } finally {
7021 Binder.restoreCallingIdentity(identity);
7022 }
7023 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7024 }
7025
7026 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007027 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7028 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007029 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007030 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007031
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007032 final long identity = Binder.clearCallingIdentity();
7033 try {
7034 final String iccId = getIccId(subId);
7035 final Phone phone = getPhone(subId);
7036 if (phone == null) {
7037 return false;
7038 }
7039 final String subscriberId = phone.getSubscriberId();
7040
7041 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007042 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007043 + subscriberId + " to " + number);
7044 }
7045
7046 if (TextUtils.isEmpty(iccId)) {
7047 return false;
7048 }
7049
7050 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7051
7052 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7053 if (alphaTag == null) {
7054 editor.remove(alphaTagPrefKey);
7055 } else {
7056 editor.putString(alphaTagPrefKey, alphaTag);
7057 }
7058
7059 // Record both the line number and IMSI for this ICCID, since we need to
7060 // track all merged IMSIs based on line number
7061 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7062 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7063 if (number == null) {
7064 editor.remove(numberPrefKey);
7065 editor.remove(subscriberPrefKey);
7066 } else {
7067 editor.putString(numberPrefKey, number);
7068 editor.putString(subscriberPrefKey, subscriberId);
7069 }
7070
7071 editor.commit();
7072 return true;
7073 } finally {
7074 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007075 }
Derek Tan7226c842014-07-02 17:42:23 -07007076 }
7077
7078 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007079 public String getLine1NumberForDisplay(int subId, String callingPackage,
7080 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007081 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007082 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007083 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007084 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007085 return null;
7086 }
Derek Tan97ebb422014-09-05 16:55:38 -07007087
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007088 final long identity = Binder.clearCallingIdentity();
7089 try {
7090 String iccId = getIccId(subId);
7091 if (iccId != null) {
7092 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7093 if (DBG_MERGE) {
7094 log("getLine1NumberForDisplay returning "
7095 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7096 }
7097 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007098 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007099 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7100 return null;
7101 } finally {
7102 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007103 }
Derek Tan7226c842014-07-02 17:42:23 -07007104 }
7105
7106 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007107 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7108 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007109 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007110 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007111 return null;
7112 }
Derek Tan97ebb422014-09-05 16:55:38 -07007113
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007114 final long identity = Binder.clearCallingIdentity();
7115 try {
7116 String iccId = getIccId(subId);
7117 if (iccId != null) {
7118 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7119 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7120 }
7121 return null;
7122 } finally {
7123 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007124 }
Derek Tan7226c842014-07-02 17:42:23 -07007125 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007126
7127 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007128 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7129 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007130 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7131 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007132 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007133 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007134 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007135 return null;
7136 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007137
Jordan Liub49b04b2019-05-06 14:45:15 -07007138 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7139 // the process, where TelephonyManager was instantiated.
7140 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007141 final long identity = Binder.clearCallingIdentity();
7142 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007143 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007144 final TelephonyManager tele = TelephonyManager.from(context);
7145 final SubscriptionManager sub = SubscriptionManager.from(context);
7146
7147 // Figure out what subscribers are currently active
7148 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007149
Jordan Liub49b04b2019-05-06 14:45:15 -07007150 // Only consider subs which match the current subId
7151 // This logic can be simplified. See b/131189269 for progress.
7152 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007153 activeSubscriberIds.add(tele.getSubscriberId(subId));
7154 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007155
7156 // First pass, find a number override for an active subscriber
7157 String mergeNumber = null;
7158 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7159 for (String key : prefs.keySet()) {
7160 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7161 final String subscriberId = (String) prefs.get(key);
7162 if (activeSubscriberIds.contains(subscriberId)) {
7163 final String iccId = key.substring(
7164 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7165 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7166 mergeNumber = (String) prefs.get(numberKey);
7167 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007168 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007169 + " for active subscriber " + subscriberId);
7170 }
7171 if (!TextUtils.isEmpty(mergeNumber)) {
7172 break;
7173 }
7174 }
7175 }
7176 }
7177
7178 // Shortcut when no active merged subscribers
7179 if (TextUtils.isEmpty(mergeNumber)) {
7180 return null;
7181 }
7182
7183 // Second pass, find all subscribers under that line override
7184 final ArraySet<String> result = new ArraySet<>();
7185 for (String key : prefs.keySet()) {
7186 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7187 final String number = (String) prefs.get(key);
7188 if (mergeNumber.equals(number)) {
7189 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7190 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7191 final String subscriberId = (String) prefs.get(subscriberKey);
7192 if (!TextUtils.isEmpty(subscriberId)) {
7193 result.add(subscriberId);
7194 }
7195 }
7196 }
7197 }
7198
7199 final String[] resultArray = result.toArray(new String[result.size()]);
7200 Arrays.sort(resultArray);
7201 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007202 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007203 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7204 }
7205 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007206 } finally {
7207 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007208 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007209 }
7210
7211 @Override
zoey chen38003472019-12-13 17:16:31 +08007212 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7213 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007214
7215 final long identity = Binder.clearCallingIdentity();
7216 try {
7217 final TelephonyManager telephonyManager = mApp.getSystemService(
7218 TelephonyManager.class);
7219 String subscriberId = telephonyManager.getSubscriberId(subId);
7220 if (subscriberId == null) {
7221 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007222 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007223 + subId);
7224 }
7225 return null;
7226 }
7227
7228 final SubscriptionInfo info = SubscriptionController.getInstance()
7229 .getSubscriptionInfo(subId);
7230 final ParcelUuid groupUuid = info.getGroupUuid();
7231 // If it doesn't belong to any group, return just subscriberId of itself.
7232 if (groupUuid == null) {
7233 return new String[]{subscriberId};
7234 }
7235
7236 // Get all subscriberIds from the group.
7237 final List<String> mergedSubscriberIds = new ArrayList<>();
7238 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007239 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007240 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007241 for (SubscriptionInfo subInfo : groupInfos) {
7242 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7243 if (subscriberId != null) {
7244 mergedSubscriberIds.add(subscriberId);
7245 }
7246 }
7247
7248 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7249 } finally {
7250 Binder.restoreCallingIdentity(identity);
7251
7252 }
7253 }
7254
7255 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007256 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007257 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007258 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007259
7260 final long identity = Binder.clearCallingIdentity();
7261 try {
7262 final Phone phone = getPhone(subId);
7263 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7264 } finally {
7265 Binder.restoreCallingIdentity(identity);
7266 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007267 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007268
7269 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007270 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007271 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7272 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007273 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7274 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007275
7276 final long identity = Binder.clearCallingIdentity();
7277 try {
7278 final Phone phone = getPhone(subId);
7279 if (phone == null) {
7280 return false;
7281 }
7282 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7283 cdmaNonRoamingList);
7284 } finally {
7285 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007286 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007287 }
7288
7289 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007290 @Deprecated
7291 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7292 enforceModifyPermission();
7293
7294 int returnValue = 0;
7295 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007296 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007297 if(result.exception == null) {
7298 if (result.result != null) {
7299 byte[] responseData = (byte[])(result.result);
7300 if(responseData.length > oemResp.length) {
7301 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7302 responseData.length + "bytes. Buffer Size is " +
7303 oemResp.length + "bytes.");
7304 }
7305 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7306 returnValue = responseData.length;
7307 }
7308 } else {
7309 CommandException ex = (CommandException) result.exception;
7310 returnValue = ex.getCommandError().ordinal();
7311 if(returnValue > 0) returnValue *= -1;
7312 }
7313 } catch (RuntimeException e) {
7314 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7315 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7316 if(returnValue > 0) returnValue *= -1;
7317 }
7318
7319 return returnValue;
7320 }
7321
7322 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007323 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007324 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007325 try {
7326 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007327 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007328 mApp, phone.getSubId(), "getRadioAccessFamily");
7329 } catch (SecurityException e) {
7330 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7331 throw e;
7332 }
chen xub97461a2018-10-26 14:17:57 -07007333 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007334 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007335 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007336 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007337 final long identity = Binder.clearCallingIdentity();
7338 try {
chen xub97461a2018-10-26 14:17:57 -07007339 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007340 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007341 mApp, phone.getSubId(), "getRadioAccessFamily");
7342 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007343 } finally {
7344 Binder.restoreCallingIdentity(identity);
7345 }
chen xub97461a2018-10-26 14:17:57 -07007346 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007347 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007348
7349 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007350 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007351 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007352 try {
7353 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7354 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007355 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007356 }
7357 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007358 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007359 }
7360 RoleManager rm = mApp.getSystemService(RoleManager.class);
7361 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7362 if (!dialerRoleHolders.contains(callingPackage)) {
7363 throw new SecurityException("App must be the dialer role holder to"
7364 + " upload a call composer pic");
7365 }
7366
7367 Executors.newSingleThreadExecutor().execute(() -> {
7368 ByteArrayOutputStream output = new ByteArrayOutputStream(
7369 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7370 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7371 boolean readUntilEnd = false;
7372 int totalBytesRead = 0;
7373 byte[] buffer = new byte[16 * 1024];
7374 while (true) {
7375 int numRead;
7376 try {
7377 numRead = input.read(buffer);
7378 } catch (IOException e) {
7379 try {
7380 fd.checkError();
7381 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7382 null);
7383 } catch (IOException e1) {
7384 // This means that the other side closed explicitly with an error. If this
7385 // happens, log and ignore.
7386 loge("Remote end of call composer picture pipe closed: " + e1);
7387 }
7388 break;
7389 }
7390 if (numRead == -1) {
7391 readUntilEnd = true;
7392 break;
7393 }
7394 totalBytesRead += numRead;
7395 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7396 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7397 try {
7398 input.close();
7399 } catch (IOException e) {
7400 // ignore
7401 }
7402 break;
7403 }
7404 output.write(buffer, 0, numRead);
7405 }
7406 // Generally, the remote end will close the file descriptors. The only case where we
7407 // close is above, where the picture size is too big.
7408
7409 try {
7410 fd.checkError();
7411 } catch (IOException e) {
7412 loge("Remote end for call composer closed with an error: " + e);
7413 return;
7414 }
7415
Hall Liuaa4211e2021-01-20 15:43:39 -08007416 if (!readUntilEnd) {
7417 loge("Did not finish reading entire image; aborting");
7418 return;
7419 }
Hall Liu82694d52020-12-11 18:22:04 -08007420
Hall Liuaa4211e2021-01-20 15:43:39 -08007421 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7422 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7423 new CallComposerPictureTransfer.Factory() {},
7424 imageData,
7425 (result) -> {
7426 if (result.first != null) {
7427 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7428 Bundle outputResult = new Bundle();
7429 outputResult.putParcelable(
7430 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7431 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7432 outputResult);
7433 } else {
7434 callback.send(result.second, null);
7435 }
7436 }
7437 );
Hall Liu82694d52020-12-11 18:22:04 -08007438 });
7439 }
7440
7441 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007442 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007443 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007444 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007445
7446 final long identity = Binder.clearCallingIdentity();
7447 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007448 ImsManager.getInstance(defaultPhone.getContext(),
7449 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007450 } finally {
7451 Binder.restoreCallingIdentity(identity);
7452 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007453 }
7454
7455 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007456 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007457 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007458 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7459 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007460 return false;
7461 }
Svet Ganovb320e182015-04-16 12:30:10 -07007462
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007463 final long identity = Binder.clearCallingIdentity();
7464 try {
7465 // Check the user preference and the system-level IMS setting. Even if the user has
7466 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7467 // In the long run, we may instead need to check if there exists a connection service
7468 // which can support video calling.
7469 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007470 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007471 return imsManager.isVtEnabledByPlatform()
7472 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7473 && imsManager.isVtEnabledByUser();
7474 } finally {
7475 Binder.restoreCallingIdentity(identity);
7476 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007477 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007478
Andrew Leea1239f22015-03-02 17:44:07 -08007479 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007480 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7481 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007482 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007483 mApp, subId, callingPackage, callingFeatureId,
7484 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007485 return false;
7486 }
7487
7488 final long identity = Binder.clearCallingIdentity();
7489 try {
7490 CarrierConfigManager configManager =
7491 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007492 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007493 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7494 } finally {
7495 Binder.restoreCallingIdentity(identity);
7496 }
Andrew Leea1239f22015-03-02 17:44:07 -08007497 }
7498
7499 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007500 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007501 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007502 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007503 return false;
7504 }
7505
7506 final long identity = Binder.clearCallingIdentity();
7507 try {
7508 CarrierConfigManager configManager =
7509 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007510 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007511 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7512 } finally {
7513 Binder.restoreCallingIdentity(identity);
7514 }
Andrew Leea1239f22015-03-02 17:44:07 -08007515 }
7516
Andrew Lee9431b832015-03-09 18:46:45 -07007517 @Override
7518 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007519 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007520 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007521 }
7522
7523 @Override
7524 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007525 final long identity = Binder.clearCallingIdentity();
7526 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007527 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007528 } finally {
7529 Binder.restoreCallingIdentity(identity);
7530 }
Andrew Lee9431b832015-03-09 18:46:45 -07007531 }
7532
Hall Liuf6668912018-10-31 17:05:23 -07007533 /**
7534 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7535 * support for the feature and device firmware support.
7536 *
7537 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7538 */
7539 @Override
7540 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007541 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007542 final Phone phone = getPhone(subscriptionId);
7543 if (phone == null) {
7544 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7545 return false;
7546 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007547 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007548 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007549 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7550 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007551 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007552 return isCarrierSupported && isDeviceSupported;
7553 } finally {
7554 Binder.restoreCallingIdentity(identity);
7555 }
Hall Liu98187582018-01-22 19:15:32 -08007556 }
7557
Hall Liuf6668912018-10-31 17:05:23 -07007558 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007559 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7560 * RTT setting, will return true if the device and carrier both support RTT.
7561 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007562 */
7563 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007564 final long identity = Binder.clearCallingIdentity();
7565 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007566 boolean isRttSupported = isRttSupported(subscriptionId);
7567 boolean isUserRttSettingOn = Settings.Secure.getInt(
7568 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7569 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7570 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7571 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007572 } finally {
7573 Binder.restoreCallingIdentity(identity);
7574 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007575 }
7576
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007577 @Deprecated
7578 @Override
7579 public String getDeviceId(String callingPackage) {
7580 return getDeviceIdWithFeature(callingPackage, null);
7581 }
7582
Sanket Padawe7310cc72015-01-14 09:53:20 -08007583 /**
7584 * Returns the unique device ID of phone, for example, the IMEI for
7585 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7586 *
7587 * <p>Requires Permission:
7588 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7589 */
7590 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007591 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007592 try {
7593 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7594 } catch (SecurityException se) {
7595 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7596 throw new SecurityException("Package " + callingPackage + " does not belong to "
7597 + Binder.getCallingUid());
7598 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007599 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007600 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007601 return null;
7602 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007603 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007604 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007605 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007606 return null;
7607 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007608
7609 final long identity = Binder.clearCallingIdentity();
7610 try {
7611 return phone.getDeviceId();
7612 } finally {
7613 Binder.restoreCallingIdentity(identity);
7614 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007615 }
7616
Ping Sunc67b7c22016-03-02 19:16:45 +08007617 /**
7618 * {@hide}
7619 * Returns the IMS Registration Status on a particular subid
7620 *
7621 * @param subId
7622 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007623 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007624 Phone phone = getPhone(subId);
7625 if (phone != null) {
7626 return phone.isImsRegistered();
7627 } else {
7628 return false;
7629 }
7630 }
7631
Santos Cordon7a1885b2015-02-03 11:15:19 -08007632 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007633 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007634 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007635 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007636 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007637 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7638 }
7639 final long identity = Binder.clearCallingIdentity();
7640 try {
7641 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7642 } finally {
7643 Binder.restoreCallingIdentity(identity);
7644 }
7645 }
7646
7647 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007648 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007649 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007650 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007651 mApp,
7652 subscriptionId,
7653 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007654 final long identity = Binder.clearCallingIdentity();
7655 try {
7656 Phone phone = getPhone(subscriptionId);
7657 if (phone == null) {
7658 return null;
7659 }
7660 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7661 } finally {
7662 Binder.restoreCallingIdentity(identity);
7663 }
7664 }
7665
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007666 /**
7667 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007668 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007669 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007670 final long identity = Binder.clearCallingIdentity();
7671 try {
7672 Phone phone = getPhone(subId);
7673 if (phone != null) {
7674 return phone.isWifiCallingEnabled();
7675 } else {
7676 return false;
7677 }
7678 } finally {
7679 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007680 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007681 }
7682
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007683 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007684 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007685 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007686 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007687 final long identity = Binder.clearCallingIdentity();
7688 try {
7689 Phone phone = getPhone(subId);
7690 if (phone != null) {
7691 return phone.isVideoEnabled();
7692 } else {
7693 return false;
7694 }
7695 } finally {
7696 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007697 }
7698 }
7699
7700 /**
7701 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7702 * defined in {@link ImsRegistrationImplBase}.
7703 */
7704 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007705 final long identity = Binder.clearCallingIdentity();
7706 try {
7707 Phone phone = getPhone(subId);
7708 if (phone != null) {
7709 return phone.getImsRegistrationTech();
7710 } else {
7711 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7712 }
7713 } finally {
7714 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007715 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007716 }
7717
Stuart Scott8eef64f2015-04-08 15:13:54 -07007718 @Override
7719 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007720 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007721 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7722 return;
7723 }
Kai Shif70f46f2021-03-03 13:59:46 -08007724 Phone defaultPhone = getDefaultPhone();
7725 if (defaultPhone != null) {
7726 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7727 mApp, getDefaultPhone().getSubId(), "factoryReset");
7728 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007729 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007730
Svet Ganovcc087f82015-05-12 20:35:54 -07007731 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007732 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7733 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007734 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007735 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007736 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007737 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007738 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007739 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007740 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007741 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007742 // There has been issues when Sms raw table somehow stores orphan
7743 // fragments. They lead to garbled message when new fragments come
7744 // in and combined with those stale ones. In case this happens again,
7745 // user can reset all network settings which will clean up this table.
7746 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007747 // Clean up IMS settings as well here.
7748 int slotId = getSlotIndex(subId);
7749 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7750 ImsManager.getInstance(mApp, slotId).factoryReset();
7751 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007752
Kai Shif70f46f2021-03-03 13:59:46 -08007753 if (defaultPhone == null) {
7754 return;
7755 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007756 // Erase modem config if erase modem on network setting is enabled.
7757 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7758 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7759 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007760 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007761 }
Kai Shif70f46f2021-03-03 13:59:46 -08007762
7763 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007764 } finally {
7765 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007766 }
7767 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007768
SongFerngWangfd89b102021-05-27 22:44:54 +08007769 @VisibleForTesting
7770 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7771 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7772 return;
7773 }
7774 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7775 RILConstants.PREFERRED_NETWORK_MODE);
7776 SubscriptionManager.setSubscriptionProperty(subId,
7777 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7778 "user=" + defaultNetworkType);
7779 phone.loadAllowedNetworksFromSubscriptionDatabase();
7780 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7781 defaultNetworkType, null);
7782 }
7783
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007784 private void cleanUpSmsRawTable(Context context) {
7785 ContentResolver resolver = context.getContentResolver();
7786 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7787 resolver.delete(uri, null, null);
7788 }
7789
Narayan Kamath1c496c22015-04-16 14:40:19 +01007790 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007791 public String getSimLocaleForSubscriber(int subId) {
7792 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7793 final Phone phone = getPhone(subId);
7794 if (phone == null) {
7795 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007796 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007797 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007798 final long identity = Binder.clearCallingIdentity();
7799 try {
chen xu5d3637b2019-01-21 23:31:38 -08007800 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007801 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007802 if (info == null) {
7803 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7804 return null;
7805 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007806 // Try and fetch the locale from the carrier properties or from the SIM language
7807 // preferences (EF-PL and EF-LI)...
7808 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007809 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007810 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7811 if (localeFromDefaultSim != null) {
7812 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7813 if (DBG) log("Using locale from subId: " + subId + " locale: "
7814 + localeFromDefaultSim);
7815 return localeFromDefaultSim.toLanguageTag();
7816 } else {
7817 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007818 }
7819 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007820
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007821 // The SIM language preferences only store a language (e.g. fr = French), not an
7822 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7823 // the SIM and carrier preferences does not include a country we add the country
7824 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007825 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007826 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007827 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007828 return mccLocale.toLanguageTag();
7829 }
7830
7831 if (DBG) log("No locale found - returning null");
7832 return null;
7833 } finally {
7834 Binder.restoreCallingIdentity(identity);
7835 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007836 }
7837
7838 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007839 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007840 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007841 }
7842
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007843 /**
7844 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7845 */
7846 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007847 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007848 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007849 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007850
Chenjie Yu1ba97252018-01-11 18:16:20 -08007851 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007852 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007853
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007854 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007855 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7856 * representing the state of the modem.
7857 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007858 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7859 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007860 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007861 */
7862 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007863 public void requestModemActivityInfo(ResultReceiver result) {
7864 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007865 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007866
7867 final long identity = Binder.clearCallingIdentity();
7868 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007869 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007870 } finally {
7871 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007872 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007873 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007874
Siddharth Rayb8114062018-06-17 15:02:38 -07007875 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7876 // less than total activity duration.
7877 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7878 if (info == null) {
7879 return false;
7880 }
7881 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007882 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7883 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7884
Siddharth Rayb8114062018-06-17 15:02:38 -07007885 return (info.isValid()
7886 && (info.getSleepTimeMillis() <= activityDurationMs)
7887 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007888 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007889 && (totalTxTimeMs <= activityDurationMs));
7890 }
7891
Jack Yu85bd38a2015-11-09 11:34:32 -08007892 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007893 * Returns the service state information on specified subscription.
7894 */
7895 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007896 public ServiceState getServiceStateForSubscriber(int subId,
7897 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7898 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007899 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007900 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007901 return null;
7902 }
7903
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007904 boolean hasFinePermission = false;
7905 boolean hasCoarsePermission = false;
7906 if (!renounceFineLocationAccess) {
7907 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7908 LocationAccessPolicy.checkLocationPermission(mApp,
7909 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7910 .setCallingPackage(callingPackage)
7911 .setCallingFeatureId(callingFeatureId)
7912 .setCallingPid(Binder.getCallingPid())
7913 .setCallingUid(Binder.getCallingUid())
7914 .setMethod("getServiceStateForSubscriber")
7915 .setLogAsInfo(true)
7916 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7917 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7918 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7919 .build());
7920 hasFinePermission =
7921 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7922 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007923
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007924 if (!renounceCoarseLocationAccess) {
7925 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7926 LocationAccessPolicy.checkLocationPermission(mApp,
7927 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7928 .setCallingPackage(callingPackage)
7929 .setCallingFeatureId(callingFeatureId)
7930 .setCallingPid(Binder.getCallingPid())
7931 .setCallingUid(Binder.getCallingUid())
7932 .setMethod("getServiceStateForSubscriber")
7933 .setLogAsInfo(true)
7934 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7935 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7936 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7937 .build());
7938 hasCoarsePermission =
7939 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7940 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007941
Jack Yu479f40e2020-10-27 21:29:25 -07007942 final Phone phone = getPhone(subId);
7943 if (phone == null) {
7944 return null;
7945 }
7946
Jordan Liu0f2bc442020-11-18 16:47:37 -08007947 final long identity = Binder.clearCallingIdentity();
7948
Jack Yu479f40e2020-10-27 21:29:25 -07007949 boolean isCallingPackageDataService = phone.getDataServicePackages()
7950 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007951 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007952 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7953 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7954 Rlog.d(LOG_TAG,
7955 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7956 return null;
7957 }
7958
Hall Liuf19c44f2018-11-27 14:38:17 -08007959 ServiceState ss = phone.getServiceState();
7960
7961 // Scrub out the location info in ServiceState depending on what level of access
7962 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007963 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007964 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7965 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007966 } finally {
7967 Binder.restoreCallingIdentity(identity);
7968 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007969 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007970
7971 /**
7972 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7973 *
7974 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7975 * voicemail ringtone.
7976 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7977 * PhoneAccount.
7978 */
7979 @Override
7980 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007981 final long identity = Binder.clearCallingIdentity();
7982 try {
7983 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7984 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007985 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007986 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007987
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007988 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7989 } finally {
7990 Binder.restoreCallingIdentity(identity);
7991 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007992 }
7993
7994 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007995 * Sets the per-account voicemail ringtone.
7996 *
7997 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7998 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7999 *
8000 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8001 * voicemail ringtone.
8002 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8003 * PhoneAccount.
8004 */
8005 @Override
8006 public void setVoicemailRingtoneUri(String callingPackage,
8007 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008008 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008009 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008010 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8011 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008012 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8013 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8014 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008015 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008016
8017 final long identity = Binder.clearCallingIdentity();
8018 try {
8019 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8020 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008021 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008022 }
8023 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8024 } finally {
8025 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008026 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008027 }
8028
8029 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008030 * Returns whether vibration is set for voicemail notification in Phone settings.
8031 *
8032 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8033 * voicemail vibration setting.
8034 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8035 */
8036 @Override
8037 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008038 final long identity = Binder.clearCallingIdentity();
8039 try {
8040 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8041 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008042 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008043 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008044
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008045 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8046 } finally {
8047 Binder.restoreCallingIdentity(identity);
8048 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008049 }
8050
Youhan Wange64578a2016-05-02 15:32:42 -07008051 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008052 * Sets the per-account voicemail vibration.
8053 *
8054 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8055 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8056 *
8057 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8058 * voicemail vibration setting.
8059 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8060 * specific PhoneAccount.
8061 */
8062 @Override
8063 public void setVoicemailVibrationEnabled(String callingPackage,
8064 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008065 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008066 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008067 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8068 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008069 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8070 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8071 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008072 }
8073
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008074 final long identity = Binder.clearCallingIdentity();
8075 try {
8076 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8077 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008078 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008079 }
8080 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8081 } finally {
8082 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008083 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008084 }
8085
8086 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008087 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8088 *
8089 * @throws SecurityException if the caller does not have the required permission
8090 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008091 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008092 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008093 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008094 }
8095
8096 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008097 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8098 * permission.
8099 *
8100 * @throws SecurityException if the caller does not have the required permission
8101 */
8102 private void enforceSendSmsPermission() {
8103 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8104 }
8105
8106 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008107 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008108 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008109 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008110 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008111 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008112 final long identity = Binder.clearCallingIdentity();
8113 try {
8114 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008115 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008116 if (componentName == null) {
8117 throw new SecurityException(
8118 "Caller not current active visual voicemail package[null]");
8119 }
8120 String vvmPackage = componentName.getPackageName();
8121 if (!callingPackage.equals(vvmPackage)) {
8122 throw new SecurityException("Caller not current active visual voicemail package["
8123 + vvmPackage + "]");
8124 }
8125 } finally {
8126 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008127 }
8128 }
8129
8130 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008131 * Return the application ID for the app type.
8132 *
8133 * @param subId the subscription ID that this request applies to.
8134 * @param appType the uicc app type.
8135 * @return Application ID for specificied app type, or null if no uicc.
8136 */
8137 @Override
8138 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008139 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008140 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008141
8142 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008143 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008144 if (phone == null) {
8145 return null;
8146 }
8147 String aid = null;
8148 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008149 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008150 .getApplicationByType(appType).getAid();
8151 } catch (Exception e) {
8152 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8153 }
8154 return aid;
8155 } finally {
8156 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008157 }
Youhan Wange64578a2016-05-02 15:32:42 -07008158 }
8159
Youhan Wang4001d252016-05-11 10:29:41 -07008160 /**
8161 * Return the Electronic Serial Number.
8162 *
8163 * @param subId the subscription ID that this request applies to.
8164 * @return ESN or null if error.
8165 */
8166 @Override
8167 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008168 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008169 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008170
8171 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008172 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008173 if (phone == null) {
8174 return null;
8175 }
8176 String esn = null;
8177 try {
8178 esn = phone.getEsn();
8179 } catch (Exception e) {
8180 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8181 }
8182 return esn;
8183 } finally {
8184 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008185 }
Youhan Wang4001d252016-05-11 10:29:41 -07008186 }
8187
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008188 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008189 * Return the Preferred Roaming List Version.
8190 *
8191 * @param subId the subscription ID that this request applies to.
8192 * @return PRLVersion or null if error.
8193 */
8194 @Override
8195 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008196 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008197 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008198
8199 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008200 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008201 if (phone == null) {
8202 return null;
8203 }
8204 String cdmaPrlVersion = null;
8205 try {
8206 cdmaPrlVersion = phone.getCdmaPrlVersion();
8207 } catch (Exception e) {
8208 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8209 }
8210 return cdmaPrlVersion;
8211 } finally {
8212 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008213 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008214 }
8215
8216 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008217 * Get snapshot of Telephony histograms
8218 * @return List of Telephony histograms
8219 * @hide
8220 */
8221 @Override
8222 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008223 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8224 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008225
8226 final long identity = Binder.clearCallingIdentity();
8227 try {
8228 return RIL.getTelephonyRILTimingHistograms();
8229 } finally {
8230 Binder.restoreCallingIdentity(identity);
8231 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008232 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008233
8234 /**
8235 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008236 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8237 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008238 * Require system privileges. In the future we may add this to carrier APIs.
8239 *
Michele Berionne482f8202018-11-27 18:57:59 -08008240 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008241 */
8242 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008243 @TelephonyManager.SetCarrierRestrictionResult
8244 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008245 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008246 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008247
Michele Berionne482f8202018-11-27 18:57:59 -08008248 if (carrierRestrictionRules == null) {
8249 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008250 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008251
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008252 final long identity = Binder.clearCallingIdentity();
8253 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008254 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008255 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008256 } finally {
8257 Binder.restoreCallingIdentity(identity);
8258 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008259 }
8260
8261 /**
8262 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008263 * Get the allowed carrier list and the excluded carrier list, including the priority between
8264 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008265 * Require system privileges. In the future we may add this to carrier APIs.
8266 *
Michele Berionne482f8202018-11-27 18:57:59 -08008267 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008268 */
8269 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008270 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008271 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008272 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008273
8274 final long identity = Binder.clearCallingIdentity();
8275 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008276 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8277 if (response instanceof CarrierRestrictionRules) {
8278 return (CarrierRestrictionRules) response;
8279 }
8280 // Response is an Exception of some kind,
8281 // which is signalled to the user as a NULL retval
8282 return null;
8283 } catch (Exception e) {
8284 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8285 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008286 } finally {
8287 Binder.restoreCallingIdentity(identity);
8288 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008289 }
8290
fionaxu59545b42016-05-25 15:53:37 -07008291 /**
fionaxu59545b42016-05-25 15:53:37 -07008292 * Action set from carrier signalling broadcast receivers to enable/disable radio
8293 * @param subId the subscription ID that this action applies to.
8294 * @param enabled control enable or disable radio.
8295 * {@hide}
8296 */
8297 @Override
8298 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8299 enforceModifyPermission();
8300 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008301
8302 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008303 if (phone == null) {
8304 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8305 return;
8306 }
8307 try {
8308 phone.carrierActionSetRadioEnabled(enabled);
8309 } catch (Exception e) {
8310 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008311 } finally {
8312 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008313 }
8314 }
8315
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008316 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008317 * Enable or disable Voice over NR (VoNR)
8318 * @param subId the subscription ID that this action applies to.
8319 * @param enabled enable or disable VoNR.
8320 * @return operation result.
8321 */
8322 @Override
8323 public int setVoNrEnabled(int subId, boolean enabled) {
8324 enforceModifyPermission();
8325 final Phone phone = getPhone(subId);
8326
8327 final long identity = Binder.clearCallingIdentity();
8328 if (phone == null) {
8329 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8330 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8331 }
8332
8333 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8334 try {
8335 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8336 workSource);
8337 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008338
8339 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8340 if (DBG) {
8341 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8342 }
8343 SubscriptionManager.setSubscriptionProperty(
8344 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8345 (enabled ? "1" : "0"));
8346 }
8347
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008348 return result;
8349 } finally {
8350 Binder.restoreCallingIdentity(identity);
8351 }
8352 }
8353
8354 /**
8355 * Is voice over NR enabled
8356 * @return true if VoNR is enabled else false
8357 */
8358 @Override
8359 public boolean isVoNrEnabled(int subId) {
8360 enforceReadPrivilegedPermission("isVoNrEnabled");
8361 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8362 final long identity = Binder.clearCallingIdentity();
8363 try {
8364 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8365 null, subId, workSource);
8366 if (DBG) log("isVoNrEnabled: " + isEnabled);
8367 return isEnabled;
8368 } finally {
8369 Binder.restoreCallingIdentity(identity);
8370 }
8371 }
8372
8373 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008374 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8375 * network status based on which carrier apps could apply actions accordingly,
8376 * enable/disable default url handler for example.
8377 *
8378 * @param subId the subscription ID that this action applies to.
8379 * @param report control start/stop reporting the default network status.
8380 * {@hide}
8381 */
8382 @Override
8383 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8384 enforceModifyPermission();
8385 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008386
8387 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008388 if (phone == null) {
8389 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8390 return;
8391 }
8392 try {
8393 phone.carrierActionReportDefaultNetworkStatus(report);
8394 } catch (Exception e) {
8395 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008396 } finally {
8397 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008398 }
8399 }
8400
8401 /**
fionaxud9622282017-07-17 17:51:30 -07008402 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8403 * @param subId the subscription ID that this action applies to.
8404 * {@hide}
8405 */
8406 @Override
8407 public void carrierActionResetAll(int subId) {
8408 enforceModifyPermission();
8409 final Phone phone = getPhone(subId);
8410 if (phone == null) {
8411 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8412 return;
8413 }
8414 try {
8415 phone.carrierActionResetAll();
8416 } catch (Exception e) {
8417 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8418 }
8419 }
8420
8421 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008422 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8423 * bug report is being generated.
8424 */
8425 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008426 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008427 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8428 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008429 writer.println("Permission Denial: can't dump Phone from pid="
8430 + Binder.getCallingPid()
8431 + ", uid=" + Binder.getCallingUid()
8432 + "without permission "
8433 + android.Manifest.permission.DUMP);
8434 return;
8435 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008436 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008437 }
Jack Yueb89b242016-06-22 13:27:47 -07008438
Brad Ebingerdac2f002018-04-03 15:17:52 -07008439 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008440 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8441 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8442 @NonNull String[] args) {
8443 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8444 this, in.getFileDescriptor(), out.getFileDescriptor(),
8445 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008446 }
8447
Jack Yueb89b242016-06-22 13:27:47 -07008448 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008449 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008450 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008451 * @param reason the reason the data enable change is taking place
8452 * @param enabled True if enabling the data, otherwise disabling.
8453 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008454 */
8455 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008456 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008457 boolean enabled) {
8458 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8459 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8460 try {
8461 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008462 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008463 } catch (SecurityException se) {
8464 enforceModifyPermission();
8465 }
8466 } else {
8467 enforceModifyPermission();
8468 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008469
8470 final long identity = Binder.clearCallingIdentity();
8471 try {
8472 Phone phone = getPhone(subId);
8473 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008474 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8475 phone.carrierActionSetMeteredApnsEnabled(enabled);
8476 } else {
Jack Yu99e87332021-12-17 23:14:15 -08008477 if (phone.isUsingNewDataStack()) {
8478 phone.getDataSettingsManager().setDataEnabled(reason, enabled);
8479 } else {
8480 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8481 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008482 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008483 }
8484 } finally {
8485 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008486 }
8487 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008488
8489 /**
8490 * Get Client request stats
8491 * @return List of Client Request Stats
8492 * @hide
8493 */
8494 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008495 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8496 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008497 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008498 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008499 return null;
8500 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008501 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008502
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008503 final long identity = Binder.clearCallingIdentity();
8504 try {
8505 if (phone != null) {
8506 return phone.getClientRequestStats();
8507 }
8508
8509 return null;
8510 } finally {
8511 Binder.restoreCallingIdentity(identity);
8512 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008513 }
8514
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008515 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008516 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008517 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008518 }
Jack Yueb4124c2017-02-16 15:32:43 -08008519
8520 /**
Grace Chen70990072017-03-24 17:21:30 -07008521 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008522 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008523 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008524 * @param state State of SIM (power down, power up, pass through)
8525 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8526 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8527 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008528 *
8529 **/
8530 @Override
Grace Chen70990072017-03-24 17:21:30 -07008531 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008532 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008533 Phone phone = PhoneFactory.getPhone(slotIndex);
8534
vagdeviaf9a5b92018-08-15 16:01:53 -07008535 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8536
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008537 final long identity = Binder.clearCallingIdentity();
8538 try {
8539 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008540 phone.setSimPowerState(state, null, workSource);
8541 }
8542 } finally {
8543 Binder.restoreCallingIdentity(identity);
8544 }
8545 }
8546
8547 /**
8548 * Set SIM card power state.
8549 *
8550 * @param slotIndex SIM slot id.
8551 * @param state State of SIM (power down, power up, pass through)
8552 * @param callback callback to trigger after success or failure
8553 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8554 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8555 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8556 *
8557 **/
8558 @Override
8559 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8560 IIntegerConsumer callback) {
8561 enforceModifyPermission();
8562 Phone phone = PhoneFactory.getPhone(slotIndex);
8563
8564 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8565
8566 final long identity = Binder.clearCallingIdentity();
8567 try {
8568 if (phone != null) {
8569 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8570 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008571 }
8572 } finally {
8573 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008574 }
8575 }
Shuo Qiandd210312017-04-12 22:11:33 +00008576
Tyler Gunn65d45c22017-06-05 11:22:26 -07008577 private boolean isUssdApiAllowed(int subId) {
8578 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008579 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008580 if (configManager == null) {
8581 return false;
8582 }
8583 PersistableBundle pb = configManager.getConfigForSubId(subId);
8584 if (pb == null) {
8585 return false;
8586 }
8587 return pb.getBoolean(
8588 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8589 }
8590
Shuo Qiandd210312017-04-12 22:11:33 +00008591 /**
8592 * Check if phone is in emergency callback mode
8593 * @return true if phone is in emergency callback mode
8594 * @param subId sub id
8595 */
goneil9c5f4872017-12-05 14:07:56 -08008596 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008597 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008598 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008599 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008600
8601 final long identity = Binder.clearCallingIdentity();
8602 try {
8603 if (phone != null) {
8604 return phone.isInEcm();
8605 } else {
8606 return false;
8607 }
8608 } finally {
8609 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008610 }
8611 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008612
8613 /**
8614 * Get the current signal strength information for the given subscription.
8615 * Because this information is not updated when the device is in a low power state
8616 * it should not be relied-upon to be current.
8617 * @param subId Subscription index
8618 * @return the most recent cached signal strength info from the modem
8619 */
8620 @Override
8621 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008622 final long identity = Binder.clearCallingIdentity();
8623 try {
8624 Phone p = getPhone(subId);
8625 if (p == null) {
8626 return null;
8627 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008628
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008629 return p.getSignalStrength();
8630 } finally {
8631 Binder.restoreCallingIdentity(identity);
8632 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008633 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008634
Pengquan Meng77b7f132018-08-22 14:49:57 -07008635 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008636 * Get the current modem radio state for the given slot.
8637 * @param slotIndex slot index.
8638 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008639 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008640 * @return the current radio power state from the modem
8641 */
8642 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008643 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008644 Phone phone = PhoneFactory.getPhone(slotIndex);
8645 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008646 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8647 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008648 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8649 }
8650
8651 final long identity = Binder.clearCallingIdentity();
8652 try {
8653 return phone.getRadioPowerState();
8654 } finally {
8655 Binder.restoreCallingIdentity(identity);
8656 }
8657 }
8658 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8659 }
8660
8661 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008662 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8663 *
8664 * <p>Requires one of the following permissions:
8665 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008666 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008667 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8668 * privileges.
8669 *
8670 * @param subId subscription id
8671 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8672 * {@code false}.
8673 */
8674 @Override
8675 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008676 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008677 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008678 try {
8679 mApp.enforceCallingOrSelfPermission(
8680 android.Manifest.permission.ACCESS_NETWORK_STATE,
8681 functionName);
8682 } catch (Exception e) {
8683 mApp.enforceCallingOrSelfPermission(
8684 permission.READ_BASIC_PHONE_STATE, functionName);
8685 }
Shuo Qian093013d2020-08-13 15:42:55 -07008686 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008687 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008688 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008689 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008690
Pengquan Menga1bb6272018-09-06 09:59:22 -07008691 boolean isEnabled = false;
8692 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008693 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008694 Phone phone = getPhone(subId);
8695 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008696 } finally {
8697 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008698 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008699 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008700 }
8701
8702
8703 /**
8704 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8705 *
8706 * <p> Requires permission:
8707 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8708 * privileges.
8709 *
8710 * @param subId subscription id
8711 * @param isEnabled {@code true} means enable, {@code false} means disable.
8712 */
8713 @Override
8714 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008715 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8716 mApp, subId, "setDataRoamingEnabled");
8717
Pengquan Menga1bb6272018-09-06 09:59:22 -07008718 final long identity = Binder.clearCallingIdentity();
8719 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008720 Phone phone = getPhone(subId);
8721 if (phone != null) {
8722 phone.setDataRoamingEnabled(isEnabled);
8723 }
8724 } finally {
8725 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008726 }
8727 }
8728
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008729 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008730 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008731 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008732 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008733 mApp, subId, "isManualNetworkSelectionAllowed");
8734
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008735 boolean isAllowed = true;
8736 final long identity = Binder.clearCallingIdentity();
8737 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008738 Phone phone = getPhone(subId);
8739 if (phone != null) {
8740 isAllowed = phone.isCspPlmnEnabled();
8741 }
8742 } finally {
8743 Binder.restoreCallingIdentity(identity);
8744 }
8745 return isAllowed;
8746 }
8747
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008748 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8749 UiccProfile profile = port.getUiccProfile();
8750 if (profile == null ||
8751 profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8752 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8753 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008754 }
8755 return true;
8756 }
8757
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008758 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008759 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008760 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008761 mApp.getSystemService(AppOpsManager.class)
8762 .checkPackage(Binder.getCallingUid(), callingPackage);
8763
Jordan Liu1e142fc2019-04-22 15:10:43 -07008764 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008765 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008766 try {
8767 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008768 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008769 } catch (SecurityException e) {
8770 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8771 // has carrier privileges on an active UICC
8772 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8773 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008774 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008775 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008776 }
sandeepjsb6c87872021-09-27 15:34:44 +00008777 // checking compatibility, if calling app's target SDK is T and beyond.
8778 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8779 Binder.getCallingUid())) {
8780 isIccIdAccessRestricted = true;
8781 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008782 final long identity = Binder.clearCallingIdentity();
8783 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008784 UiccController uiccController = UiccController.getInstance();
8785 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008786 if (hasReadPermission) {
8787 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008788 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008789
8790 // Remove private info if the caller doesn't have access
8791 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8792 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008793 //setting the value after compatibility check
8794 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008795 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8796 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008797 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008798 if (card == null) {
8799 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008800 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008801 continue;
8802 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008803 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8804 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008805 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008806 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008807 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008808 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8809 for (UiccPortInfo portInfo : portInfos) {
8810 UiccPort port = uiccController.getUiccPortForSlot(
8811 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8812 if (port == null) {
8813 // assume no access if port is null
8814 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8815 continue;
8816 }
8817 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8818 uiccPortInfos.add(portInfo);
8819 } else {
8820 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8821 }
8822 }
8823 filteredInfos.add(new UiccCardInfo(
8824 cardInfo.isEuicc(),
8825 cardInfo.getCardId(),
8826 null,
8827 cardInfo.getPhysicalSlotIndex(),
8828 cardInfo.isRemovable(),
8829 cardInfo.isMultipleEnabledProfilesSupported(),
8830 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008831 }
8832 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008833 } finally {
8834 Binder.restoreCallingIdentity(identity);
8835 }
8836 }
8837
sandeepjsb6c87872021-09-27 15:34:44 +00008838 /**
8839 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8840 * generally private and require carrier privileges to view.
8841 *
8842 * @hide
8843 */
8844 @NonNull
8845 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8846 List<UiccPortInfo> portinfo = new ArrayList<>();
8847 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8848 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8849 }
8850 return new UiccCardInfo(
8851 cardInfo.isEuicc(),
8852 cardInfo.getCardId(),
8853 null,
8854 cardInfo.getPhysicalSlotIndex(),
8855 cardInfo.isRemovable(),
8856 cardInfo.isMultipleEnabledProfilesSupported(),
8857 portinfo
8858 );
8859 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008860
sandeepjsb6c87872021-09-27 15:34:44 +00008861 /**
8862 * @hide
8863 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8864 * These values are generally private and require carrier privileges to view.
8865 */
8866 @NonNull
8867 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8868 return new UiccPortInfo(
8869 UiccPortInfo.ICCID_REDACTED,
8870 portInfo.getPortIndex(),
8871 portInfo.getLogicalSlotIndex(),
8872 portInfo.isActive()
8873 );
8874 }
8875 @Override
8876 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008877 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00008878 mApp.getSystemService(AppOpsManager.class)
8879 .checkPackage(Binder.getCallingUid(), callingPackage);
8880
8881 boolean hasReadPermission = false;
8882 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008883
8884 try {
8885 enforceReadPrivilegedPermission("getUiccSlotsInfo");
8886 hasReadPermission = true;
8887 } catch (SecurityException e) {
8888 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8889 // has carrier privileges on an active UICC
8890 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8891 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8892 hasReadPermission = true;
8893 }
8894 }
8895
8896 // checking compatibility, if calling app's target SDK is T and beyond.
8897 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8898 Binder.getCallingUid())) {
8899 isLogicalSlotAccessRestricted = true;
8900 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008901 final long identity = Binder.clearCallingIdentity();
8902 try {
8903 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8904 if (slots == null) {
8905 Rlog.i(LOG_TAG, "slots is null.");
8906 return null;
8907 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008908 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8909 for (int i = 0; i < slots.length; i++) {
8910 UiccSlot slot = slots[i];
8911 if (slot == null) {
8912 continue;
8913 }
8914
Jordan Liu7be7e652019-05-06 18:55:02 +00008915 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008916 UiccCard card = slot.getUiccCard();
8917 if (card != null) {
8918 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008919 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008920 cardId = slot.getEid();
8921 if (TextUtils.isEmpty(cardId)) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008922 // If cardId is null, use iccId of default port as cardId. Check if has
8923 // read permission otherwise set to null.(card is null which means no
8924 // carrier permission)
8925 cardId = hasReadPermission ? slot.getIccId(
8926 TelephonyManager.DEFAULT_PORT_INDEX) : null;
Jordan Liu01bd00d2019-09-12 16:19:43 -07008927 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008928 }
8929
Jordan Liu857451f2019-05-09 16:35:35 -07008930 if (cardId != null) {
8931 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8932 // if cardId is an EID, it's all digits so this is fine
8933 cardId = IccUtils.stripTrailingFs(cardId);
8934 }
8935
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008936 int cardState = 0;
8937 switch (slot.getCardState()) {
8938 case CARDSTATE_ABSENT:
8939 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8940 break;
8941 case CARDSTATE_PRESENT:
8942 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8943 break;
8944 case CARDSTATE_ERROR:
8945 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8946 break;
8947 case CARDSTATE_RESTRICTED:
8948 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8949 break;
8950 default:
8951 break;
8952
8953 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008954 List<UiccPortInfo> portInfos = new ArrayList<>();
8955 int[] portIndexes = slot.getPortList();
8956 for (int portIdx : portIndexes) {
8957 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
8958 callingPackage, hasReadPermission));
8959 if (slot.isPortActive(portIdx)) {
8960 UiccPort port = slot.getUiccCard().getUiccPort(portIdx);
8961 portInfos.add(new UiccPortInfo(iccId, port.getPortIdx(),
8962 port.getPhoneId(), true));
8963 } else {
8964 portInfos.add(new UiccPortInfo(iccId, portIdx, -1, false));
8965 }
8966 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008967 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008968 slot.isEuicc(),
8969 cardId,
8970 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08008971 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008972 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00008973 //setting the value after compatibility check
8974 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008975 }
8976 return infos;
8977 } finally {
8978 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008979 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008980 }
8981
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008982 /* Returns null if doesn't have read permission or carrier privilege access. */
8983 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
8984 boolean hasReadPermission) {
8985 String iccId = slot.getIccId(portIndex);
8986 if (hasReadPermission) { // if has read permission
8987 return iccId;
8988 } else {
8989 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
8990 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
8991 // if no read permission, checking carrier privilege access
8992 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8993 return iccId;
8994 }
8995 }
8996 }
8997 // No read permission or carrier privilege access.
8998 return UiccPortInfo.ICCID_REDACTED;
8999 }
9000
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009001 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009002 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009003 public boolean switchSlots(int[] physicalSlots) {
9004 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009005
9006 final long identity = Binder.clearCallingIdentity();
9007 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009008 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9009 for (int i = 0; i < physicalSlots.length; i++) {
9010 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9011 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9012 physicalSlots[i], i));
9013 }
9014 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009015 } finally {
9016 Binder.restoreCallingIdentity(identity);
9017 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009018 }
Jack Yu4c988042018-02-27 15:30:01 -08009019
9020 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009021 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9022 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9023 enforceModifyPermission();
9024
9025 final long identity = Binder.clearCallingIdentity();
9026 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009027 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009028 } finally {
9029 Binder.restoreCallingIdentity(identity);
9030 }
9031 }
9032
9033 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009034 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009035 final long identity = Binder.clearCallingIdentity();
9036 try {
9037 return UiccController.getInstance().getCardIdForDefaultEuicc();
9038 } finally {
9039 Binder.restoreCallingIdentity(identity);
9040 }
9041 }
9042
Pengquan Meng85728fb2018-03-12 16:31:21 -07009043 /**
goneil47ffb6e2018-04-06 15:40:58 -07009044 * A test API to reload the UICC profile.
9045 *
9046 * <p>Requires that the calling app has permission
9047 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9048 * @hide
9049 */
9050 @Override
9051 public void refreshUiccProfile(int subId) {
9052 enforceModifyPermission();
9053
9054 final long identity = Binder.clearCallingIdentity();
9055 try {
9056 Phone phone = getPhone(subId);
9057 if (phone == null) {
9058 return;
9059 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009060 UiccPort uiccPort = phone.getUiccPort();
9061 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009062 return;
9063 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009064 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009065 if (uiccProfile == null) {
9066 return;
9067 }
9068 uiccProfile.refresh();
9069 } finally {
9070 Binder.restoreCallingIdentity(identity);
9071 }
9072 }
9073
9074 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009075 * Returns false if the mobile data is disabled by default, otherwise return true.
9076 */
9077 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009078 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009079 }
9080
9081 /**
9082 * Returns true if the data roaming is enabled by default, i.e the system property
9083 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9084 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9085 */
9086 private boolean getDefaultDataRoamingEnabled(int subId) {
9087 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009088 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009089 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009090 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9091 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9092 return isDataRoamingEnabled;
9093 }
9094
9095 /**
9096 * Returns the default network type for the given {@code subId}, if the default network type is
9097 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9098 */
9099 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009100 List<Integer> list = TelephonyProperties.default_network();
9101 int phoneId = mSubscriptionController.getPhoneId(subId);
9102 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9103 return list.get(phoneId);
9104 }
9105 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009106 }
fionaxua13278b2018-03-21 00:08:13 -07009107
9108 @Override
9109 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009110 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009111 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009112
9113 final long identity = Binder.clearCallingIdentity();
9114 try {
9115 final Phone phone = getPhone(subId);
9116 if (phone == null) {
9117 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9118 return;
9119 }
chen xueaba88a2019-03-15 13:15:10 -07009120 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9121 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009122 if (carrierPrivilegeRules == null) {
9123 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9124 } else {
9125 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9126 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009127 } finally {
9128 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009129 }
fionaxua13278b2018-03-21 00:08:13 -07009130 }
9131
9132 @Override
9133 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009134 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009135
9136 final long identity = Binder.clearCallingIdentity();
9137 try {
9138 final Phone phone = getPhone(subId);
9139 if (phone == null) {
9140 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9141 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9142 }
9143 return phone.getCarrierIdListVersion();
9144 } finally {
9145 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009146 }
fionaxua13278b2018-03-21 00:08:13 -07009147 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009148
9149 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009150 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9151 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009152 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009153 mApp, subId, callingPackage, callingFeatureId,
9154 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009155 return -1;
9156 }
9157
9158 final long identity = Binder.clearCallingIdentity();
9159 try {
9160 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9161 } finally {
9162 Binder.restoreCallingIdentity(identity);
9163 }
9164 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009165
9166 @Override
9167 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009168 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009169 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009170 mApp, subId, "getCdmaRoamingMode");
9171
9172 final long identity = Binder.clearCallingIdentity();
9173 try {
9174 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9175 } finally {
9176 Binder.restoreCallingIdentity(identity);
9177 }
9178 }
9179
9180 @Override
9181 public boolean setCdmaRoamingMode(int subId, int mode) {
9182 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9183 mApp, subId, "setCdmaRoamingMode");
9184
9185 final long identity = Binder.clearCallingIdentity();
9186 try {
9187 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9188 } finally {
9189 Binder.restoreCallingIdentity(identity);
9190 }
9191 }
9192
9193 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009194 public int getCdmaSubscriptionMode(int subId) {
9195 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009196 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009197 mApp, subId, "getCdmaSubscriptionMode");
9198
9199 final long identity = Binder.clearCallingIdentity();
9200 try {
9201 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9202 } finally {
9203 Binder.restoreCallingIdentity(identity);
9204 }
9205 }
9206
9207 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009208 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9209 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9210 mApp, subId, "setCdmaSubscriptionMode");
9211
9212 final long identity = Binder.clearCallingIdentity();
9213 try {
9214 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9215 } finally {
9216 Binder.restoreCallingIdentity(identity);
9217 }
9218 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009219
sqianc5eccab2018-10-19 18:46:41 -07009220 @Override
sqian8c685422019-02-22 15:55:18 -08009221 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009222 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009223 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009224 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9225 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009226 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9227 }
9228 final long identity = Binder.clearCallingIdentity();
9229 try {
sqian854d44b2018-12-12 16:48:18 -08009230 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9231 for (Phone phone: PhoneFactory.getPhones()) {
9232 if (phone.getEmergencyNumberTracker() != null
9233 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9234 emergencyNumberListInternal.put(
9235 phone.getSubId(),
9236 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9237 }
sqian11b7a0e2018-12-05 18:48:28 -08009238 }
sqian854d44b2018-12-12 16:48:18 -08009239 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009240 } finally {
9241 Binder.restoreCallingIdentity(identity);
9242 }
sqianc5eccab2018-10-19 18:46:41 -07009243 }
9244
9245 @Override
sqian8c685422019-02-22 15:55:18 -08009246 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009247 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009248 if (!exactMatch) {
9249 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009250 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009251 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009252 }
9253 final long identity = Binder.clearCallingIdentity();
9254 try {
sqian854d44b2018-12-12 16:48:18 -08009255 for (Phone phone: PhoneFactory.getPhones()) {
9256 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009257 && phone.getEmergencyNumberTracker()
9258 .isEmergencyNumber(number, exactMatch)) {
9259 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009260 }
sqian11b7a0e2018-12-05 18:48:28 -08009261 }
9262 return false;
9263 } finally {
9264 Binder.restoreCallingIdentity(identity);
9265 }
9266 }
9267
sqianf4ca7ed2019-01-15 18:32:07 -08009268 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009269 * Start emergency callback mode for GsmCdmaPhone for testing.
9270 */
9271 @Override
9272 public void startEmergencyCallbackMode() {
9273 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9274 "startEmergencyCallbackMode");
9275 enforceModifyPermission();
9276 final long identity = Binder.clearCallingIdentity();
9277 try {
9278 for (Phone phone : PhoneFactory.getPhones()) {
9279 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9280 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9281 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9282 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9283 gsmCdmaPhone.obtainMessage(
9284 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9285 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9286 }
9287 }
9288 } finally {
9289 Binder.restoreCallingIdentity(identity);
9290 }
9291 }
9292
9293 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009294 * Update emergency number list for test mode.
9295 */
9296 @Override
9297 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9298 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9299 "updateEmergencyNumberListTestMode");
9300
9301 final long identity = Binder.clearCallingIdentity();
9302 try {
9303 for (Phone phone: PhoneFactory.getPhones()) {
9304 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9305 if (tracker != null) {
9306 tracker.executeEmergencyNumberTestModeCommand(action, num);
9307 }
9308 }
9309 } finally {
9310 Binder.restoreCallingIdentity(identity);
9311 }
9312 }
9313
9314 /**
9315 * Get the full emergency number list for test mode.
9316 */
9317 @Override
9318 public List<String> getEmergencyNumberListTestMode() {
9319 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9320 "getEmergencyNumberListTestMode");
9321
9322 final long identity = Binder.clearCallingIdentity();
9323 try {
9324 Set<String> emergencyNumbers = new HashSet<>();
9325 for (Phone phone: PhoneFactory.getPhones()) {
9326 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9327 if (tracker != null) {
9328 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9329 emergencyNumbers.add(num.getNumber());
9330 }
9331 }
9332 }
9333 return new ArrayList<>(emergencyNumbers);
9334 } finally {
9335 Binder.restoreCallingIdentity(identity);
9336 }
9337 }
9338
chen xud6b45bd2018-10-30 22:27:10 -07009339 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009340 public int getEmergencyNumberDbVersion(int subId) {
9341 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9342
9343 final long identity = Binder.clearCallingIdentity();
9344 try {
9345 final Phone phone = getPhone(subId);
9346 if (phone == null) {
9347 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9348 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9349 }
9350 return phone.getEmergencyNumberDbVersion();
9351 } finally {
9352 Binder.restoreCallingIdentity(identity);
9353 }
9354 }
9355
9356 @Override
9357 public void notifyOtaEmergencyNumberDbInstalled() {
9358 enforceModifyPermission();
9359
9360 final long identity = Binder.clearCallingIdentity();
9361 try {
9362 for (Phone phone: PhoneFactory.getPhones()) {
9363 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9364 if (tracker != null) {
9365 tracker.updateOtaEmergencyNumberDatabase();
9366 }
9367 }
9368 } finally {
9369 Binder.restoreCallingIdentity(identity);
9370 }
9371 }
9372
9373 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009374 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009375 enforceActiveEmergencySessionPermission();
9376
9377 final long identity = Binder.clearCallingIdentity();
9378 try {
9379 for (Phone phone: PhoneFactory.getPhones()) {
9380 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9381 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009382 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9383 }
9384 }
9385 } finally {
9386 Binder.restoreCallingIdentity(identity);
9387 }
9388 }
9389
9390 @Override
9391 public void resetOtaEmergencyNumberDbFilePath() {
9392 enforceActiveEmergencySessionPermission();
9393
9394 final long identity = Binder.clearCallingIdentity();
9395 try {
9396 for (Phone phone: PhoneFactory.getPhones()) {
9397 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9398 if (tracker != null) {
9399 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009400 }
9401 }
9402 } finally {
9403 Binder.restoreCallingIdentity(identity);
9404 }
9405 }
9406
9407 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009408 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9409 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9410 Phone phone = getPhone(subId);
9411 if (phone == null) {
9412 return null;
9413 }
9414 final long identity = Binder.clearCallingIdentity();
9415 try {
9416 UiccProfile profile = UiccController.getInstance()
9417 .getUiccProfileForPhone(phone.getPhoneId());
9418 if (profile != null) {
9419 return profile.getCertsFromCarrierPrivilegeAccessRules();
9420 }
9421 } finally {
9422 Binder.restoreCallingIdentity(identity);
9423 }
9424 return null;
9425 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009426
9427 /**
9428 * Enable or disable a modem stack.
9429 */
9430 @Override
9431 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9432 enforceModifyPermission();
9433
9434 final long identity = Binder.clearCallingIdentity();
9435 try {
9436 Phone phone = PhoneFactory.getPhone(slotIndex);
9437 if (phone == null) {
9438 return false;
9439 } else {
9440 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9441 }
9442 } finally {
9443 Binder.restoreCallingIdentity(identity);
9444 }
9445 }
Michelecea4cf22018-12-21 15:00:11 -08009446
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009447 /**
9448 * Whether a modem stack is enabled or not.
9449 */
9450 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009451 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9452 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009453 Phone phone = PhoneFactory.getPhone(slotIndex);
9454 if (phone == null) return false;
9455
9456 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009457 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9458 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009459 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9460 }
9461
9462 final long identity = Binder.clearCallingIdentity();
9463 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009464 try {
9465 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9466 } catch (NoSuchElementException ex) {
9467 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9468 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009469 } finally {
9470 Binder.restoreCallingIdentity(identity);
9471 }
9472 }
9473
Michelecea4cf22018-12-21 15:00:11 -08009474 @Override
Michele0ea7d782019-03-19 14:58:42 -07009475 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009476 enforceModifyPermission();
9477
9478 final long identity = Binder.clearCallingIdentity();
9479 try {
9480 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009481 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009482 .commit();
9483 } finally {
9484 Binder.restoreCallingIdentity(identity);
9485 }
9486 }
9487
9488 @Override
Michele0ea7d782019-03-19 14:58:42 -07009489 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009490 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009491 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009492 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9493 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009494 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009495 }
Michelecea4cf22018-12-21 15:00:11 -08009496
9497 final long identity = Binder.clearCallingIdentity();
9498 try {
Michele0ea7d782019-03-19 14:58:42 -07009499 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009500 } finally {
9501 Binder.restoreCallingIdentity(identity);
9502 }
9503 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009504
Michele0ea7d782019-03-19 14:58:42 -07009505 @TelephonyManager.IsMultiSimSupportedResult
9506 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009507 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9508 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9509 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009510 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9511 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009512 }
9513 // Check if the hardware supports multisim functionality. If usage of multisim is not
9514 // supported by the modem, indicate that it is restricted.
9515 PhoneCapability staticCapability =
9516 mPhoneConfigurationManager.getStaticPhoneCapability();
9517 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009518 loge("isMultiSimSupportedInternal: no static configuration available");
9519 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009520 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009521 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009522 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9523 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009524 }
9525 // Check if support of multiple SIMs is restricted by carrier
9526 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009527 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009528 }
9529
Michele0ea7d782019-03-19 14:58:42 -07009530 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009531 }
9532
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009533 /**
9534 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009535 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9536 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9537 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009538 * @param numOfSims number of active sims we want to switch to
9539 */
9540 @Override
9541 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009542 if (numOfSims == 1) {
9543 enforceModifyPermission();
9544 } else {
9545 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9546 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9547 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009548 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009549
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009550 try {
Michele30b57b22019-03-01 12:01:14 -08009551 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009552 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009553 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9554 return;
9555 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009556 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9557 } finally {
9558 Binder.restoreCallingIdentity(identity);
9559 }
9560 }
9561
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009562 @Override
9563 public boolean isApplicationOnUicc(int subId, int appType) {
9564 enforceReadPrivilegedPermission("isApplicationOnUicc");
9565 Phone phone = getPhone(subId);
9566 if (phone == null) {
9567 return false;
9568 }
9569 final long identity = Binder.clearCallingIdentity();
9570 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009571 UiccPort uiccPort = phone.getUiccPort();
9572 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009573 return false;
9574 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009575 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009576 if (uiccProfile == null) {
9577 return false;
9578 }
9579 if (TelephonyManager.APPTYPE_SIM <= appType
9580 && appType <= TelephonyManager.APPTYPE_ISIM) {
9581 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9582 }
9583 return false;
9584 } finally {
9585 Binder.restoreCallingIdentity(identity);
9586 }
9587 }
9588
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009589 /**
chen xub4baa772019-04-03 10:23:41 -07009590 * Get whether making changes to modem configurations will trigger reboot.
9591 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009592 */
9593 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009594 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9595 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009596 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009597 mApp, subId, callingPackage, callingFeatureId,
9598 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009599 return false;
9600 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009601 final long identity = Binder.clearCallingIdentity();
9602 try {
9603 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9604 } finally {
9605 Binder.restoreCallingIdentity(identity);
9606 }
9607 }
9608
Nathan Harold29f5f052019-02-15 13:41:57 -08009609 private void updateModemStateMetrics() {
9610 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9611 // TODO: check the state for each modem if the api is ready.
9612 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9613 }
9614
Pengquan Meng3889a572019-01-23 11:16:29 -08009615 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009616 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009617 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009618 // Verify that the callingPackage belongs to the calling UID
9619 mApp.getSystemService(AppOpsManager.class)
9620 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009621 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009622 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009623 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009624 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9625 if (slotInfos != null) {
9626 for (int i = 0; i < slotInfos.length; i++) {
9627 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9628 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9629 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9630 portInfo.getLogicalSlotIndex()));
9631 }
9632 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009633 }
9634 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009635 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009636 } finally {
9637 Binder.restoreCallingIdentity(identity);
9638 }
9639 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009640
9641 /**
9642 * Get the IRadio HAL Version
9643 */
9644 @Override
9645 public int getRadioHalVersion() {
9646 Phone phone = getDefaultPhone();
9647 if (phone == null) return -1;
9648 HalVersion hv = phone.getHalVersion();
9649 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9650 return hv.major * 100 + hv.minor;
9651 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009652
9653 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009654 * Get the current calling package name.
9655 * @return the current calling package name
9656 */
9657 @Override
9658 public String getCurrentPackageName() {
9659 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9660 }
9661
9662 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009663 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9664 * corresponding network requests on a subId.
9665 *
9666 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009667 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009668 * 2) APN is un-metered for this subscription, or
9669 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009670 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009671 *
9672 * @return whether data is allowed for a apn type.
9673 *
9674 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009675 */
9676 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009677 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009678 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9679 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009680
9681 // Now that all security checks passes, perform the operation as ourselves.
9682 final long identity = Binder.clearCallingIdentity();
9683 try {
9684 Phone phone = getPhone(subId);
9685 if (phone == null) return false;
9686
Jack Yu41407ee2019-05-13 16:54:09 -07009687 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Jack Yu99e87332021-12-17 23:14:15 -08009688 boolean isDataEnabled;
9689 if (phone.isUsingNewDataStack()) {
9690 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
9691 } else {
9692 isDataEnabled = phone.getDataEnabledSettings().isDataEnabled(apnType);
9693 }
9694 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009695 } finally {
9696 Binder.restoreCallingIdentity(identity);
9697 }
9698 }
9699
9700 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009701 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009702 enforceReadPrivilegedPermission("isApnMetered");
9703
9704 // Now that all security checks passes, perform the operation as ourselves.
9705 final long identity = Binder.clearCallingIdentity();
9706 try {
9707 Phone phone = getPhone(subId);
9708 if (phone == null) return true; // By default return true.
9709
Jack Yu41407ee2019-05-13 16:54:09 -07009710 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009711 } finally {
9712 Binder.restoreCallingIdentity(identity);
9713 }
9714 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009715
9716 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009717 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9718 int subscriptionId, IBooleanConsumer resultCallback) {
9719 enforceModifyPermission();
9720 long token = Binder.clearCallingIdentity();
9721 try {
9722 Phone phone = getPhone(subscriptionId);
9723 if (phone == null) {
9724 try {
9725 if (resultCallback != null) {
9726 resultCallback.accept(false);
9727 }
9728 } catch (RemoteException e) {
9729 // ignore
9730 }
9731 return;
9732 }
9733 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9734 Pair.create(specifiers, (x) -> {
9735 try {
9736 if (resultCallback != null) {
9737 resultCallback.accept(x);
9738 }
9739 } catch (RemoteException e) {
9740 // ignore
9741 }
9742 });
9743 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9744 } finally {
9745 Binder.restoreCallingIdentity(token);
9746 }
9747 }
9748
9749 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009750 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9751 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009752 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009753 mApp, subId, "getSystemSelectionChannels");
9754 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9755 final long identity = Binder.clearCallingIdentity();
9756 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009757 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9758 if (result instanceof IllegalStateException) {
9759 throw (IllegalStateException) result;
9760 }
9761 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009762 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9763 return specifiers;
9764 } finally {
9765 Binder.restoreCallingIdentity(identity);
9766 }
9767 }
9768
9769 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009770 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009771 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009772 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9773 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9774 if (iccRecords == null) {
9775 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9776 return false;
9777 }
9778 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9779 }
9780
9781 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009782 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9783 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009784 if (callingPackage == null) {
9785 callingPackage = getCurrentPackageName();
9786 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009787 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9788 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009789 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9790 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009791 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9792 }
9793 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9794 Intent intent = new Intent();
9795 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9796 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9797 // Bring up choose default SMS subscription dialog right now
9798 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9799 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9800 mApp.startActivity(intent);
9801 }
chen xud5ca2d52019-05-28 15:20:57 -07009802
9803 @Override
9804 public String getMmsUAProfUrl(int subId) {
9805 //TODO investigate if this API should require proper permission check in R b/133791609
9806 final long identity = Binder.clearCallingIdentity();
9807 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009808 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9809 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9810 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9811 return carrierUAProfUrl;
9812 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009813 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9814 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009815 } finally {
9816 Binder.restoreCallingIdentity(identity);
9817 }
9818 }
9819
9820 @Override
9821 public String getMmsUserAgent(int subId) {
9822 //TODO investigate if this API should require proper permission check in R b/133791609
9823 final long identity = Binder.clearCallingIdentity();
9824 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009825 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9826 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9827 if (!TextUtils.isEmpty(carrierUserAgent)) {
9828 return carrierUserAgent;
9829 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009830 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9831 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009832 } finally {
9833 Binder.restoreCallingIdentity(identity);
9834 }
9835 }
Jack Yub07d4972019-05-28 16:12:25 -07009836
9837 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009838 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9839 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009840
Jack Yub07d4972019-05-28 16:12:25 -07009841 final long identity = Binder.clearCallingIdentity();
9842 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009843 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009844 if (phone == null) return false;
9845
Hall Liua62f5da2020-09-25 10:42:19 -07009846 switch (policy) {
9847 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu99e87332021-12-17 23:14:15 -08009848 if (phone.isUsingNewDataStack()) {
9849 return phone.getDataSettingsManager().isDataAllowedInVoiceCall();
9850 } else {
9851 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9852 }
Hall Liua62f5da2020-09-25 10:42:19 -07009853 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu99e87332021-12-17 23:14:15 -08009854 if (phone.isUsingNewDataStack()) {
9855 return phone.getDataSettingsManager().isMmsAlwaysAllowed();
9856 } else {
9857 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9858 }
Hall Liua62f5da2020-09-25 10:42:19 -07009859 default:
9860 throw new IllegalArgumentException(policy + " is not a valid policy");
9861 }
Jack Yub07d4972019-05-28 16:12:25 -07009862 } finally {
9863 Binder.restoreCallingIdentity(identity);
9864 }
9865 }
9866
9867 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009868 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009869 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009870 enforceModifyPermission();
9871
changbettyd5c246e2019-12-24 15:40:37 +08009872 final long identity = Binder.clearCallingIdentity();
9873 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009874 Phone phone = getPhone(subscriptionId);
9875 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009876
Hall Liua62f5da2020-09-25 10:42:19 -07009877 switch (policy) {
9878 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu99e87332021-12-17 23:14:15 -08009879 if (phone.isUsingNewDataStack()) {
9880 phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled);
9881 } else {
9882 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9883 }
Hall Liua62f5da2020-09-25 10:42:19 -07009884 break;
9885 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu99e87332021-12-17 23:14:15 -08009886 if (phone.isUsingNewDataStack()) {
9887 phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled);
9888 } else {
9889 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9890 }
Hall Liua62f5da2020-09-25 10:42:19 -07009891 break;
9892 default:
9893 throw new IllegalArgumentException(policy + " is not a valid policy");
9894 }
changbettyd5c246e2019-12-24 15:40:37 +08009895 } finally {
9896 Binder.restoreCallingIdentity(identity);
9897 }
9898 }
9899
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009900 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009901 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009902 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9903 * otherwise.
9904 */
9905 @Override
9906 public void setCepEnabled(boolean isCepEnabled) {
9907 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9908
9909 final long identity = Binder.clearCallingIdentity();
9910 try {
9911 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9912 for (Phone phone : PhoneFactory.getPhones()) {
9913 Phone defaultPhone = phone.getImsPhone();
9914 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9915 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9916 ImsPhoneCallTracker imsPhoneCallTracker =
9917 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9918 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9919 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9920 + imsPhone.getMsisdn());
9921 }
9922 }
9923 } finally {
9924 Binder.restoreCallingIdentity(identity);
9925 }
9926 }
allenwtsu46dcc572020-01-08 18:24:03 +08009927
9928 /**
9929 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9930 *
9931 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9932 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9933 * before being read.
9934 */
9935 @Override
9936 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9937 isCompressed) {
9938 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9939 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009940 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9941 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9942 }
9943 if (!isImsAvailableOnDevice()) {
9944 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9945 "IMS not available on device.");
9946 }
9947
9948 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009949 try {
Hui Wang761a6682020-10-31 05:12:53 +00009950 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9951 } finally {
9952 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009953 }
9954 }
zoey chene02881a2019-12-30 16:11:23 +08009955
9956 @Override
9957 public boolean isIccLockEnabled(int subId) {
9958 enforceReadPrivilegedPermission("isIccLockEnabled");
9959
9960 // Now that all security checks passes, perform the operation as ourselves.
9961 final long identity = Binder.clearCallingIdentity();
9962 try {
9963 Phone phone = getPhone(subId);
9964 if (phone != null && phone.getIccCard() != null) {
9965 return phone.getIccCard().getIccLockEnabled();
9966 } else {
9967 return false;
9968 }
9969 } finally {
9970 Binder.restoreCallingIdentity(identity);
9971 }
9972 }
9973
9974 /**
9975 * Set the ICC pin lock enabled or disabled.
9976 *
9977 * @return an integer representing the status of IccLock enabled or disabled in the following
9978 * three cases:
9979 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9980 * successfully.
9981 * - Positive number and zero for remaining password attempts.
9982 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9983 *
9984 */
9985 @Override
9986 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9987 enforceModifyPermission();
9988
9989 Phone phone = getPhone(subId);
9990 if (phone == null) {
9991 return 0;
9992 }
9993 // Now that all security checks passes, perform the operation as ourselves.
9994 final long identity = Binder.clearCallingIdentity();
9995 try {
9996 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9997 new Pair<Boolean, String>(enabled, password), phone, null);
9998 return attemptsRemaining;
9999
10000 } catch (Exception e) {
10001 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10002 } finally {
10003 Binder.restoreCallingIdentity(identity);
10004 }
10005 return 0;
10006 }
10007
10008 /**
10009 * Change the ICC password used in ICC pin lock.
10010 *
10011 * @return an integer representing the status of IccLock changed in the following three cases:
10012 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10013 * - Positive number and zero for remaining password attempts.
10014 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10015 *
10016 */
10017 @Override
10018 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10019 enforceModifyPermission();
10020
10021 Phone phone = getPhone(subId);
10022 if (phone == null) {
10023 return 0;
10024 }
10025 // Now that all security checks passes, perform the operation as ourselves.
10026 final long identity = Binder.clearCallingIdentity();
10027 try {
10028 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10029 new Pair<String, String>(oldPassword, newPassword), phone, null);
10030 return attemptsRemaining;
10031
10032 } catch (Exception e) {
10033 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10034 } finally {
10035 Binder.restoreCallingIdentity(identity);
10036 }
10037 return 0;
10038 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010039
10040 /**
10041 * Request for receiving user activity notification
10042 */
10043 @Override
10044 public void requestUserActivityNotification() {
10045 if (!mNotifyUserActivity.get()
10046 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10047 mNotifyUserActivity.set(true);
10048 }
10049 }
10050
10051 /**
10052 * Called when userActivity is signalled in the power manager.
10053 * This is safe to call from any thread, with any window manager locks held or not.
10054 */
10055 @Override
10056 public void userActivity() {
10057 // ***************************************
10058 // * Inherited from PhoneWindowManager *
10059 // ***************************************
10060 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10061 // WITH ITS LOCKS HELD.
10062 //
10063 // This code must be VERY careful about the locks
10064 // it acquires.
10065 // In fact, the current code acquires way too many,
10066 // and probably has lurking deadlocks.
10067
10068 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10069 throw new SecurityException("Only the OS may call notifyUserActivity()");
10070 }
10071
10072 if (mNotifyUserActivity.getAndSet(false)) {
10073 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10074 USER_ACTIVITY_NOTIFICATION_DELAY);
10075 }
10076 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010077
10078 @Override
10079 public boolean canConnectTo5GInDsdsMode() {
10080 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10081 }
Jack Yud10cdd42020-09-28 20:28:01 -070010082
10083 @Override
10084 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10085 String callingFeatureId) {
10086 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10087 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10088 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10089 }
10090
10091 Phone phone = getPhone(subId);
10092 if (phone == null) {
10093 throw new RuntimeException("phone is not available");
10094 }
10095 // Now that all security checks passes, perform the operation as ourselves.
10096 final long identity = Binder.clearCallingIdentity();
10097 try {
10098 return phone.getEquivalentHomePlmns();
10099 } finally {
10100 Binder.restoreCallingIdentity(identity);
10101 }
10102 }
Daniel Bright59e67312020-11-13 11:49:37 -080010103
10104 @Override
10105 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010106 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10107 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010108 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010109 if (radioInterfaceCapabilities == null) {
10110 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010111 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010112 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010113 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010114
Hui Wang641e81c2020-10-12 12:14:23 -070010115 @Override
10116 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10117 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010118 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10119 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10120 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10121 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10122 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010123 if (DBG) {
10124 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10125 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10126 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10127 }
10128
10129 if (!SubscriptionManager.isValidSubscriptionId(subId)
10130 || appType < TelephonyManager.APPTYPE_UNKNOWN
10131 || appType > TelephonyManager.APPTYPE_ISIM
10132 || nafUrl == null || securityProtocol == null || callback == null) {
10133 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10134 if (callback != null) {
10135 try {
10136 callback.onAuthenticationFailure(
10137 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10138 } catch (RemoteException exception) {
10139 log("Fail to notify onAuthenticationFailure due to " + exception);
10140 }
10141 return;
10142 }
10143 }
10144
10145 final long token = Binder.clearCallingIdentity();
10146 try {
10147 getGbaManager(subId).bootstrapAuthenticationRequest(
10148 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10149 forceBootStrapping, callback));
10150 } finally {
10151 Binder.restoreCallingIdentity(token);
10152 }
10153 }
10154
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010155 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010156 * Attempts to set the radio power state for all phones for thermal reason.
10157 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010158 * requested radio power state will actually be set. See {@link
10159 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10160 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010161 * @param enable {@code true} if trying to turn radio on.
10162 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10163 * false}.
10164 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010165 private boolean setRadioPowerForThermal(boolean enable) {
10166 boolean isPhoneAvailable = false;
10167 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10168 Phone phone = PhoneFactory.getPhone(i);
10169 if (phone != null) {
10170 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10171 isPhoneAvailable = true;
10172 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010173 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010174
10175 // return true if successfully informed the phone object about the thermal radio power
10176 // request.
10177 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010178 }
10179
10180 private int handleDataThrottlingRequest(int subId,
10181 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010182 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10183 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10184 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10185 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10186 throw new IllegalArgumentException("modem does not support data throttling");
10187 }
10188
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010189 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10190 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010191 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010192 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10193 }
10194
10195 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10196
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010197 if (isDataThrottlingSupported) {
10198 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010199 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010200 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10201 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10202 } else if (thermalMitigationResult
10203 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010204 log("Modem likely does not support data throttling on secondary carrier. Data " +
10205 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10206 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010207 }
10208 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010209 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010210
10211 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010212 }
10213
Jack Nudelman644b91a2021-03-12 14:09:48 -080010214 private static List<String> getThermalMitigationAllowlist(Context context) {
10215 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10216 for (String pckg : context.getResources()
10217 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10218 sThermalMitigationAllowlistedPackages.add(pckg);
10219 }
10220 }
10221
10222 return sThermalMitigationAllowlistedPackages;
10223 }
10224
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010225 private boolean isAnyPhoneInEmergencyState() {
10226 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10227 if (tm.isInEmergencyCall()) {
10228 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10229 return true;
10230 }
10231 for (Phone phone : PhoneFactory.getPhones()) {
10232 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10233 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10234 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10235 + phone.isInEcm());
10236 return true;
10237 }
10238 }
10239
10240 return false;
10241 }
10242
Jack Nudelman644b91a2021-03-12 14:09:48 -080010243 /**
10244 * Used by shell commands to add an authorized package name for thermal mitigation.
10245 * @param packageName name of package to be allowlisted
10246 * @param context
10247 */
10248 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10249 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10250 sThermalMitigationAllowlistedPackages.add(packageName);
10251 }
10252
10253 /**
10254 * Used by shell commands to remove an authorized package name for thermal mitigation.
10255 * @param packageName name of package to remove from allowlist
10256 * @param context
10257 */
10258 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10259 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10260 sThermalMitigationAllowlistedPackages.remove(packageName);
10261 }
10262
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010263 /**
10264 * Thermal mitigation request to control functionalities at modem.
10265 *
10266 * @param subId the id of the subscription.
10267 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010268 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010269 *
10270 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10271 */
10272 @Override
10273 @ThermalMitigationResult
10274 public int sendThermalMitigationRequest(
10275 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010276 ThermalMitigationRequest thermalMitigationRequest,
10277 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010278 enforceModifyPermission();
10279
Jack Nudelman644b91a2021-03-12 14:09:48 -080010280 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10281 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10282 .contains(callingPackage)) {
10283 throw new SecurityException("Calling package must be configured in the device config. "
10284 + "calling package: " + callingPackage);
10285 }
10286
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010287 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10288 final long identity = Binder.clearCallingIdentity();
10289
10290 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10291 try {
10292 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10293 switch (thermalMitigationAction) {
10294 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10295 thermalMitigationResult =
10296 handleDataThrottlingRequest(subId,
10297 thermalMitigationRequest.getDataThrottlingRequest());
10298 break;
10299 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10300 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10301 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10302 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10303 }
10304
10305 // Ensure that radio is on. If not able to power on due to phone being
10306 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010307 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010308 thermalMitigationResult =
10309 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10310 break;
10311 }
10312
10313 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10314 false);
10315 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10316 break;
10317 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10318 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10319 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10320 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10321 }
10322
10323 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10324 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010325 Phone phone = getPhone(subId);
10326 if (phone == null) {
10327 thermalMitigationResult =
10328 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10329 break;
10330 }
10331
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010332 TelephonyConnectionService service =
10333 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010334 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010335 Log.e(LOG_TAG, "An emergency call is pending");
10336 thermalMitigationResult =
10337 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10338 break;
10339 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010340 thermalMitigationResult =
10341 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10342 break;
10343 }
10344 } else {
10345 thermalMitigationResult =
10346 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10347 break;
10348 }
10349
10350 // Turn radio off. If not able to power off due to phone being unavailable,
10351 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010352 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010353 thermalMitigationResult =
10354 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10355 break;
10356 }
10357 thermalMitigationResult =
10358 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10359 break;
10360 default:
10361 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10362 + "not exist. Requested action: " + thermalMitigationAction);
10363 }
10364 } catch (IllegalArgumentException e) {
10365 throw e;
10366 } catch (Exception e) {
10367 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10368 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10369 } finally {
10370 Binder.restoreCallingIdentity(identity);
10371 }
10372
10373 if (DBG) {
10374 log("thermalMitigationRequest returning with thermalMitigationResult: "
10375 + thermalMitigationResult);
10376 }
10377
10378 return thermalMitigationResult;
10379 }
Hui Wang641e81c2020-10-12 12:14:23 -070010380
10381 /**
10382 * Set the GbaService Package Name that Telephony will bind to.
10383 *
10384 * @param subId The sim that the GbaService is associated with.
10385 * @param packageName The name of the package to be replaced with.
10386 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10387 */
10388 @Override
10389 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10390 enforceModifyPermission();
10391
10392 final long identity = Binder.clearCallingIdentity();
10393 try {
10394 return getGbaManager(subId).overrideServicePackage(packageName);
10395 } finally {
10396 Binder.restoreCallingIdentity(identity);
10397 }
10398 }
10399
10400 /**
10401 * Return the package name of the currently bound GbaService.
10402 *
10403 * @param subId The sim that the GbaService is associated with.
10404 * @return the package name of the GbaService configuration, null if GBA is not supported.
10405 */
10406 @Override
10407 public String getBoundGbaService(int subId) {
10408 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10409
10410 final long identity = Binder.clearCallingIdentity();
10411 try {
10412 return getGbaManager(subId).getServicePackage();
10413 } finally {
10414 Binder.restoreCallingIdentity(identity);
10415 }
10416 }
10417
10418 /**
10419 * Set the release time for telephony to unbind GbaService.
10420 *
10421 * @param subId The sim that the GbaService is associated with.
10422 * @param interval The release time to unbind GbaService by millisecond.
10423 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10424 */
10425 @Override
10426 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10427 enforceModifyPermission();
10428
10429 final long identity = Binder.clearCallingIdentity();
10430 try {
10431 return getGbaManager(subId).overrideReleaseTime(interval);
10432 } finally {
10433 Binder.restoreCallingIdentity(identity);
10434 }
10435 }
10436
10437 /**
10438 * Return the release time for telephony to unbind GbaService.
10439 *
10440 * @param subId The sim that the GbaService is associated with.
10441 * @return The release time to unbind GbaService by millisecond.
10442 */
10443 @Override
10444 public int getGbaReleaseTime(int subId) {
10445 enforceReadPrivilegedPermission("getGbaReleaseTime");
10446
10447 final long identity = Binder.clearCallingIdentity();
10448 try {
10449 return getGbaManager(subId).getReleaseTime();
10450 } finally {
10451 Binder.restoreCallingIdentity(identity);
10452 }
10453 }
10454
10455 private GbaManager getGbaManager(int subId) {
10456 GbaManager instance = GbaManager.getInstance(subId);
10457 if (instance == null) {
10458 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10459 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10460 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10461 }
10462 return instance;
10463 }
Hui Wang761a6682020-10-31 05:12:53 +000010464
10465 /**
10466 * indicate whether the device and the carrier can support
10467 * RCS VoLTE single registration.
10468 */
10469 @Override
10470 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010471 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10472 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10473 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10474 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010475
10476 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10477 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10478 }
10479
10480 final long identity = Binder.clearCallingIdentity();
10481 try {
10482 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10483 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010484 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10485 if (isCapable != null) {
10486 return isCapable;
10487 }
Hui Wang761a6682020-10-31 05:12:53 +000010488 }
Hui Wang67af90e2021-06-04 16:57:15 -070010489 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10490 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010491 } finally {
10492 Binder.restoreCallingIdentity(identity);
10493 }
10494 }
10495
10496 /**
10497 * Register RCS provisioning callback.
10498 */
10499 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010500 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010501 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010502 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010503 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010504 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10505 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010506
10507 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10508 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10509 }
10510 if (!isImsAvailableOnDevice()) {
10511 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10512 "IMS not available on device.");
10513 }
10514
10515 final long identity = Binder.clearCallingIdentity();
10516 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010517 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010518 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010519 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10520 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010521 }
Hui Wang761a6682020-10-31 05:12:53 +000010522 } finally {
10523 Binder.restoreCallingIdentity(identity);
10524 }
10525 }
10526
10527 /**
10528 * Unregister RCS provisioning callback.
10529 */
10530 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010531 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010532 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010533 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010534 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010535 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10536 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010537
10538 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10539 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10540 }
10541 if (!isImsAvailableOnDevice()) {
10542 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10543 "IMS not available on device.");
10544 }
10545
10546 final long identity = Binder.clearCallingIdentity();
10547 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010548 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010549 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010550 } finally {
10551 Binder.restoreCallingIdentity(identity);
10552 }
10553 }
10554
10555 /**
10556 * trigger RCS reconfiguration.
10557 */
10558 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010559 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10560 "triggerRcsReconfiguration",
10561 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010562
10563 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10564 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10565 }
10566 if (!isImsAvailableOnDevice()) {
10567 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10568 "IMS not available on device.");
10569 }
10570
10571 final long identity = Binder.clearCallingIdentity();
10572 try {
10573 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10574 } finally {
10575 Binder.restoreCallingIdentity(identity);
10576 }
10577 }
10578
10579 /**
10580 * Provide the client configuration parameters of the RCS application.
10581 */
10582 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010583 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10584 "setRcsClientConfiguration",
10585 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010586
10587 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10588 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10589 }
10590 if (!isImsAvailableOnDevice()) {
10591 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10592 "IMS not available on device.");
10593 }
10594
10595 final long identity = Binder.clearCallingIdentity();
10596
10597 try {
10598 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10599 if (configBinder == null) {
10600 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010601 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10602 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010603 } else {
10604 configBinder.setRcsClientConfiguration(rcc);
10605 }
joonhunshin3e154242021-09-17 06:33:39 +000010606
10607 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10608 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010609 } catch (RemoteException e) {
10610 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010611 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10612 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010613 } finally {
10614 Binder.restoreCallingIdentity(identity);
10615 }
10616 }
10617
10618 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010619 * Enables or disables the test mode for RCS VoLTE single registration.
10620 */
10621 @Override
10622 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10623 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10624 "setRcsSingleRegistrationTestModeEnabled");
10625
10626 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10627 }
10628
10629 /**
10630 * Gets the test mode for RCS VoLTE single registration.
10631 */
10632 @Override
10633 public boolean getRcsSingleRegistrationTestModeEnabled() {
10634 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10635 "getRcsSingleRegistrationTestModeEnabled");
10636
10637 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10638 }
10639
10640 /**
Hui Wang761a6682020-10-31 05:12:53 +000010641 * Overrides the config of RCS VoLTE single registration enabled for the device.
10642 */
10643 @Override
10644 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10645 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10646 "setDeviceSingleRegistrationEnabledOverride");
10647 enforceModifyPermission();
10648
10649 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10650 : Boolean.parseBoolean(enabledStr);
10651 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010652 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010653 }
10654
10655 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010656 * Sends a device to device communication message. Only usable via shell.
10657 * @param message message to send.
10658 * @param value message value.
10659 */
10660 @Override
10661 public void sendDeviceToDeviceMessage(int message, int value) {
10662 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010663 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010664 enforceModifyPermission();
10665
10666 final long identity = Binder.clearCallingIdentity();
10667 try {
10668 TelephonyConnectionService service =
10669 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10670 if (service == null) {
10671 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10672 return;
10673 }
10674 service.sendTestDeviceToDeviceMessage(message, value);
10675 } finally {
10676 Binder.restoreCallingIdentity(identity);
10677 }
10678 }
10679
Tyler Gunnbabbda02021-02-10 11:05:02 -080010680 /**
10681 * Sets the specified device to device transport active.
10682 * @param transport The transport to set active.
10683 */
10684 @Override
10685 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10686 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10687 "setActiveDeviceToDeviceTransport");
10688 enforceModifyPermission();
10689
10690 final long identity = Binder.clearCallingIdentity();
10691 try {
10692 TelephonyConnectionService service =
10693 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10694 if (service == null) {
10695 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10696 return;
10697 }
10698 service.setActiveDeviceToDeviceTransport(transport);
10699 } finally {
10700 Binder.restoreCallingIdentity(identity);
10701 }
10702 }
Tyler Gunn92479152021-01-20 16:30:10 -080010703
Tyler Gunnd4339262021-05-03 14:46:49 -070010704 @Override
10705 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10706 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10707 "setDeviceToDeviceForceEnabled");
10708
10709 final long identity = Binder.clearCallingIdentity();
10710 try {
10711 Arrays.stream(PhoneFactory.getPhones()).forEach(
10712 p -> {
10713 Phone thePhone = p.getImsPhone();
10714 if (thePhone != null && thePhone instanceof ImsPhone) {
10715 ImsPhone imsPhone = (ImsPhone) thePhone;
10716 CallTracker tracker = imsPhone.getCallTracker();
10717 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10718 ImsPhoneCallTracker imsPhoneCallTracker =
10719 (ImsPhoneCallTracker) tracker;
10720 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10721 }
10722 }
10723 }
10724 );
10725 } finally {
10726 Binder.restoreCallingIdentity(identity);
10727 }
10728 }
10729
Tyler Gunn92479152021-01-20 16:30:10 -080010730 /**
Hui Wang761a6682020-10-31 05:12:53 +000010731 * Gets the config of RCS VoLTE single registration enabled for the device.
10732 */
10733 @Override
10734 public boolean getDeviceSingleRegistrationEnabled() {
10735 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10736 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10737 }
10738
10739 /**
10740 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10741 */
10742 @Override
10743 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10744 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10745 "setCarrierSingleRegistrationEnabledOverride");
10746 enforceModifyPermission();
10747
10748 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10749 : Boolean.parseBoolean(enabledStr);
10750 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10751 subId, enabled);
10752 }
10753
10754 /**
10755 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10756 */
10757 @Override
10758 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10759 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10760 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10761 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010762
10763 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010764 * Overrides the ims feature validation result
10765 */
10766 @Override
10767 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10768 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10769 "setImsFeatureValidationOverride");
10770
10771 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10772 : Boolean.parseBoolean(enabledStr);
10773 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10774 subId, enabled);
10775 }
10776
10777 /**
10778 * Gets the ims feature validation override value
10779 */
10780 @Override
10781 public boolean getImsFeatureValidationOverride(int subId) {
10782 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10783 "getImsFeatureValidationOverride");
10784 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10785 }
10786
10787 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010788 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10789 * their mobile plan.
10790 */
10791 @Override
10792 public String getMobileProvisioningUrl() {
10793 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10794 final long identity = Binder.clearCallingIdentity();
10795 try {
10796 return getDefaultPhone().getMobileProvisioningUrl();
10797 } finally {
10798 Binder.restoreCallingIdentity(identity);
10799 }
10800 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010801
James.cf Linbcdf8b32021-01-14 16:44:13 +080010802 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010803 * Get the EAB contact from the EAB database.
10804 */
10805 @Override
10806 public String getContactFromEab(String contact) {
10807 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10808 enforceModifyPermission();
10809 final long identity = Binder.clearCallingIdentity();
10810 try {
10811 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10812 } finally {
10813 Binder.restoreCallingIdentity(identity);
10814 }
10815 }
10816
10817 /**
Calvin Pana1434322021-07-01 19:27:01 +080010818 * Get the EAB capability from the EAB database.
10819 */
10820 @Override
10821 public String getCapabilityFromEab(String contact) {
10822 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10823 enforceModifyPermission();
10824 final long identity = Binder.clearCallingIdentity();
10825 try {
10826 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10827 } finally {
10828 Binder.restoreCallingIdentity(identity);
10829 }
10830 }
10831
10832 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010833 * Remove the EAB contacts from the EAB database.
10834 */
10835 @Override
10836 public int removeContactFromEab(int subId, String contacts) {
10837 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10838 enforceModifyPermission();
10839 final long identity = Binder.clearCallingIdentity();
10840 try {
10841 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10842 } finally {
10843 Binder.restoreCallingIdentity(identity);
10844 }
10845 }
10846
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010847 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010848 public boolean getDeviceUceEnabled() {
10849 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10850 final long identity = Binder.clearCallingIdentity();
10851 try {
10852 return mApp.getDeviceUceEnabled();
10853 } finally {
10854 Binder.restoreCallingIdentity(identity);
10855 }
10856 }
10857
10858 @Override
10859 public void setDeviceUceEnabled(boolean isEnabled) {
10860 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10861 final long identity = Binder.clearCallingIdentity();
10862 try {
10863 mApp.setDeviceUceEnabled(isEnabled);
10864 } finally {
10865 Binder.restoreCallingIdentity(identity);
10866 }
10867 }
10868
Brad Ebinger14d467f2021-02-12 06:18:28 +000010869 /**
10870 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10871 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10872 */
10873 // Used for SHELL command only right now.
10874 @Override
10875 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10876 List<String> featureTags) {
10877 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10878 "addUceRegistrationOverrideShell");
10879 final long identity = Binder.clearCallingIdentity();
10880 try {
10881 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10882 new ArraySet<>(featureTags));
10883 } catch (ImsException e) {
10884 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10885 } finally {
10886 Binder.restoreCallingIdentity(identity);
10887 }
10888 }
10889
10890 /**
10891 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10892 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10893 */
10894 // Used for SHELL command only right now.
10895 @Override
10896 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10897 List<String> featureTags) {
10898 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10899 "removeUceRegistrationOverrideShell");
10900 final long identity = Binder.clearCallingIdentity();
10901 try {
10902 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10903 new ArraySet<>(featureTags));
10904 } catch (ImsException e) {
10905 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10906 } finally {
10907 Binder.restoreCallingIdentity(identity);
10908 }
10909 }
10910
10911 /**
10912 * Clear all overrides in 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 clearUceRegistrationOverrideShell(int subId) {
10918 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10919 "clearUceRegistrationOverrideShell");
10920 final long identity = Binder.clearCallingIdentity();
10921 try {
10922 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10923 } catch (ImsException e) {
10924 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10925 } finally {
10926 Binder.restoreCallingIdentity(identity);
10927 }
10928 }
10929
10930 /**
10931 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10932 */
10933 // Used for SHELL command only right now.
10934 @Override
10935 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10936 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10937 "getLatestRcsContactUceCapabilityShell");
10938 final long identity = Binder.clearCallingIdentity();
10939 try {
10940 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10941 } catch (ImsException e) {
10942 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10943 } finally {
10944 Binder.restoreCallingIdentity(identity);
10945 }
10946 }
10947
10948 /**
10949 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10950 * device does not have an active PUBLISH.
10951 */
10952 // Used for SHELL command only right now.
10953 @Override
10954 public String getLastUcePidfXmlShell(int subId) {
10955 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10956 final long identity = Binder.clearCallingIdentity();
10957 try {
10958 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10959 } catch (ImsException e) {
10960 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10961 } finally {
10962 Binder.restoreCallingIdentity(identity);
10963 }
10964 }
10965
James.cf Line8713a42021-04-29 16:04:26 +080010966 /**
10967 * Remove UCE requests cannot be sent to the network status.
10968 */
10969 // Used for SHELL command only right now.
10970 @Override
10971 public boolean removeUceRequestDisallowedStatus(int subId) {
10972 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10973 final long identity = Binder.clearCallingIdentity();
10974 try {
10975 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10976 } catch (ImsException e) {
10977 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10978 } finally {
10979 Binder.restoreCallingIdentity(identity);
10980 }
10981 }
10982
James.cf Lin18bb9002021-05-25 01:37:38 +080010983 /**
10984 * Remove UCE requests cannot be sent to the network status.
10985 */
10986 // Used for SHELL command only.
10987 @Override
10988 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10989 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10990 final long identity = Binder.clearCallingIdentity();
10991 try {
10992 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10993 } catch (ImsException e) {
10994 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10995 } finally {
10996 Binder.restoreCallingIdentity(identity);
10997 }
10998 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010999
James.cf Lin4b784aa2021-01-31 03:25:15 +080011000 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011001 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11002 String callingPackage) {
11003 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11004 mApp, subId, "setSignalStrengthUpdateRequest");
11005
11006 final int callingUid = Binder.getCallingUid();
11007 // Verify that tha callingPackage belongs to the calling UID
11008 mApp.getSystemService(AppOpsManager.class)
11009 .checkPackage(callingUid, callingPackage);
11010
Rambo Wang3607f502021-02-01 21:51:40 -080011011 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011012
11013 final long identity = Binder.clearCallingIdentity();
11014 try {
11015 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11016 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11017
11018 if (result instanceof IllegalStateException) {
11019 throw (IllegalStateException) result;
11020 }
11021 } finally {
11022 Binder.restoreCallingIdentity(identity);
11023 }
11024 }
11025
11026 @Override
11027 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11028 String callingPackage) {
11029 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11030 mApp, subId, "clearSignalStrengthUpdateRequest");
11031
11032 final int callingUid = Binder.getCallingUid();
11033 // Verify that tha callingPackage belongs to the calling UID
11034 mApp.getSystemService(AppOpsManager.class)
11035 .checkPackage(callingUid, callingPackage);
11036
11037 final long identity = Binder.clearCallingIdentity();
11038 try {
11039 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11040 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11041
11042 if (result instanceof IllegalStateException) {
11043 throw (IllegalStateException) result;
11044 }
11045 } finally {
11046 Binder.restoreCallingIdentity(identity);
11047 }
11048 }
11049
Rambo Wang3607f502021-02-01 21:51:40 -080011050 private static void validateSignalStrengthUpdateRequest(Context context,
11051 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011052 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11053 // phone/system process do not have further restriction on request
11054 return;
11055 }
11056
11057 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011058 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011059 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011060 context.enforceCallingOrSelfPermission(
11061 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11062 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011063 }
11064
11065 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11066 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11067 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11068 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11069 || info.isEnabled()) {
11070 throw new IllegalArgumentException(
11071 "Only system can set hide fields in SignalThresholdInfo");
11072 }
11073
11074 // Thresholds length for each RAN need in range. This has been validated in
11075 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11076 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11077 final int[] thresholds = info.getThresholds();
11078 Objects.requireNonNull(thresholds);
11079 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11080 || thresholds.length
11081 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11082 throw new IllegalArgumentException(
11083 "thresholds length is out of range: " + thresholds.length);
11084 }
11085 }
11086 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011087
11088 /**
11089 * Gets the current phone capability.
11090 *
11091 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11092 * @return the PhoneCapability which describes the data connection capability of modem.
11093 * It's used to evaluate possible phone config change, for example from single
11094 * SIM device to multi-SIM device.
11095 */
11096 @Override
11097 public PhoneCapability getPhoneCapability() {
11098 enforceReadPrivilegedPermission("getPhoneCapability");
11099 final long identity = Binder.clearCallingIdentity();
11100 try {
11101 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11102 } finally {
11103 Binder.restoreCallingIdentity(identity);
11104 }
11105 }
Michele Berionne5e411512020-11-13 02:36:59 +000011106
11107 /**
11108 * Prepare TelephonyManager for an unattended reboot. The reboot is
11109 * required to be done shortly after the API is invoked.
11110 */
11111 @Override
11112 @TelephonyManager.PrepareUnattendedRebootResult
11113 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011114 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011115 enforceRebootPermission();
11116
11117 final long identity = Binder.clearCallingIdentity();
11118 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011119 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011120 } finally {
11121 Binder.restoreCallingIdentity(identity);
11122 }
11123 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011124
11125 /**
11126 * Request to get the current slicing configuration including URSP rules and
11127 * NSSAIs (configured, allowed and rejected).
11128 *
11129 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11130 */
11131 @Override
11132 public void getSlicingConfig(ResultReceiver callback) {
11133 enforceReadPrivilegedPermission("getSlicingConfig");
11134
11135 final long identity = Binder.clearCallingIdentity();
11136 try {
11137 Phone phone = getDefaultPhone();
11138 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11139 } finally {
11140 Binder.restoreCallingIdentity(identity);
11141 }
11142 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011143
11144 /**
11145 * Register an IMS connection state callback
11146 */
11147 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011148 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11149 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011150 if (feature == ImsFeature.FEATURE_MMTEL) {
11151 // ImsMmTelManager
11152 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11153 TelephonyPermissions
11154 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11155 mApp, subId, "registerImsStateCallback");
11156 } else if (feature == ImsFeature.FEATURE_RCS) {
11157 // ImsRcsManager or SipDelegateManager
11158 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11159 Binder.getCallingUid(), "registerImsStateCallback",
11160 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11161 Manifest.permission.READ_PRECISE_PHONE_STATE,
11162 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11163 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11164 }
11165
11166 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11167 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11168 "IMS not available on device.");
11169 }
11170
11171 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11172 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11173 }
11174
11175 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11176 if (controller == null) {
11177 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11178 "IMS not available on device.");
11179 }
11180
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011181 if (callingPackage == null) {
11182 callingPackage = getCurrentPackageName();
11183 }
11184
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011185 final long token = Binder.clearCallingIdentity();
11186 try {
11187 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011188 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011189 } catch (ImsException e) {
11190 throw new ServiceSpecificException(e.getCode());
11191 } finally {
11192 Binder.restoreCallingIdentity(token);
11193 }
11194 }
11195
11196 /**
11197 * Unregister an IMS connection state callback
11198 */
11199 @Override
11200 public void unregisterImsStateCallback(IImsStateCallback cb) {
11201 final long token = Binder.clearCallingIdentity();
11202 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11203 if (controller == null) {
11204 return;
11205 }
11206 try {
11207 controller.unregisterImsStateCallback(cb);
11208 } finally {
11209 Binder.restoreCallingIdentity(token);
11210 }
11211 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011212
11213 /**
11214 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11215 *
11216 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11217 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11218 * SecurityException.
11219 * If there is current registered network this value will be same as the registered cell
11220 * identity. If the device goes out of service the previous cell identity is cached and
11221 * will be returned. If the cache age of the Cell identity is more than 24 hours
11222 * it will be cleared and null will be returned.
11223 *
11224 */
11225 @Override
11226 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11227 String callingFeatureId) {
11228 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11229 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11230 LocationAccessPolicy.checkLocationPermission(mApp,
11231 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11232 .setCallingPackage(callingPackage)
11233 .setCallingFeatureId(callingFeatureId)
11234 .setCallingPid(Binder.getCallingPid())
11235 .setCallingUid(Binder.getCallingUid())
11236 .setMethod("getLastKnownCellIdentity")
11237 .setLogAsInfo(true)
11238 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11239 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11240 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11241 .build());
11242
11243 boolean hasFinePermission =
11244 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11245 if (!hasFinePermission
11246 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11247 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
11248 + "and BIND_CONNECTION_SERVICE permission.");
11249 }
11250
11251 final long identity = Binder.clearCallingIdentity();
11252 try {
11253 Phone phone = getPhone(subId);
11254 if (phone == null) return null;
11255 ServiceStateTracker sst = phone.getServiceStateTracker();
11256 if (sst == null) return null;
11257 return sst.getLastKnownCellIdentity();
11258 } finally {
11259 Binder.restoreCallingIdentity(identity);
11260 }
11261 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011262
11263 @Override
11264 public boolean isUsingNewDataStack() {
11265 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "isUsingNewDataStack");
11266 return getDefaultPhone().isUsingNewDataStack();
11267 }
jimsun3b9ccac2021-10-26 15:01:23 +080011268
11269 /**
11270 * Sets the modem service class Name that Telephony will bind to.
11271 *
11272 * @param serviceName The class name of the modem service.
11273 * @return true if the operation is succeed, otherwise false.
11274 */
11275 public boolean setModemService(String serviceName) {
11276 Log.d(LOG_TAG, "setModemService - " + serviceName);
11277 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11278 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11279 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11280 "setModemService");
11281 return mPhoneConfigurationManager.setModemService(serviceName);
11282 }
11283
11284 /**
11285 * Return the class name of the currently bounded modem service.
11286 *
11287 * @return the class name of the modem service.
11288 */
11289 public String getModemService() {
11290 String result;
11291 Log.d(LOG_TAG, "getModemService");
11292 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11293 TelephonyPermissions
11294 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11295 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11296 "getModemService");
11297 result = mPhoneConfigurationManager.getModemService();
11298 Log.d(LOG_TAG, "result = " + result);
11299 return result;
11300 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011301}