blob: bfc69a5a9af2d3daa1db7127e06b862f259acb43 [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;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800153import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800154import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700155import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700156import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800157import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700158import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700159import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800160import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800161import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800162import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700163import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000164import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700165import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800166import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700167import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800168import com.android.internal.telephony.IccCard;
Rambo Wanga1782702021-11-10 20:15:19 -0800169import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700170import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700171import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700172import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700173import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700174import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800175import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700176import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700177import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700178import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700179import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800180import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800181import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700182import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700183import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700184import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800185import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800186import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800187import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700188import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800189import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700190import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800191import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700192import com.android.internal.telephony.imsphone.ImsPhone;
193import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000194import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800195import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700196import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700197import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800198import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700199import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800200import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700201import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800202import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700203import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000204import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800205import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000206import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800207import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700208import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700209import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800210import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800211import com.android.phone.callcomposer.CallComposerPictureManager;
212import com.android.phone.callcomposer.CallComposerPictureTransfer;
213import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700214import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700215import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800216import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700217import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700218import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800219import com.android.services.telephony.TelecomAccountRegistry;
220import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800221import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800222
Hall Liu82694d52020-12-11 18:22:04 -0800223import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700224import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800225import java.io.IOException;
226import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700227import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700228import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800229import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000230import java.util.Collection;
sqian11b7a0e2018-12-05 18:48:28 -0800231import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800232import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800233import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100234import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800235import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700236import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800237import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800238import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800239import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800240import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800241import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700242
243/**
244 * Implementation of the ITelephony interface.
245 */
Santos Cordon117fee72014-05-16 17:56:12 -0700246public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700247 private static final String LOG_TAG = "PhoneInterfaceManager";
248 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
249 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800250 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700251
252 // Message codes used with mMainThreadHandler
253 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700254 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
255 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700256 private static final int CMD_OPEN_CHANNEL = 9;
257 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
258 private static final int CMD_CLOSE_CHANNEL = 11;
259 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800260 private static final int CMD_NV_READ_ITEM = 13;
261 private static final int EVENT_NV_READ_ITEM_DONE = 14;
262 private static final int CMD_NV_WRITE_ITEM = 15;
263 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
264 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
265 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700266 private static final int CMD_RESET_MODEM_CONFIG = 19;
267 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800268 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
269 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800270 private static final int CMD_SEND_ENVELOPE = 25;
271 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000272 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
273 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700274 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
275 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
276 private static final int CMD_EXCHANGE_SIM_IO = 31;
277 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800278 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
279 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700280 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
281 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700282 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
283 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700284 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
285 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
286 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
287 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700288 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
289 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
290 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
291 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700292 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800293 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
294 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000295 private static final int CMD_SWITCH_SLOTS = 50;
296 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700297 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
298 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
299 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
300 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
301 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
302 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
303 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
304 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700305 private static final int CMD_GET_ALL_CELL_INFO = 60;
306 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
307 private static final int CMD_GET_CELL_LOCATION = 62;
308 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700309 private static final int CMD_MODEM_REBOOT = 64;
310 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700311 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
312 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800313 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
314 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700315 private static final int CMD_GET_MODEM_STATUS = 70;
316 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700317 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
318 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700319 private static final int CMD_ERASE_MODEM_CONFIG = 74;
320 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800321 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
322 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
323 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
324 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800325 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
326 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800327 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800328 private static final int CMD_GET_CALL_FORWARDING = 83;
329 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
330 private static final int CMD_SET_CALL_FORWARDING = 85;
331 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
332 private static final int CMD_GET_CALL_WAITING = 87;
333 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
334 private static final int CMD_SET_CALL_WAITING = 89;
335 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700336 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
337 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
338 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
339 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700340 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
341 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800342 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
343 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800344 private static final int CMD_SET_DATA_THROTTLING = 99;
345 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800346 private static final int CMD_SET_SIM_POWER = 101;
347 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800348 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
349 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
350 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
351 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800352 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
353 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000354 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800355 private static final int CMD_GET_SLICING_CONFIG = 110;
356 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800357 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700358 private static final int CMD_ENABLE_VONR = 113;
359 private static final int EVENT_ENABLE_VONR_DONE = 114;
360 private static final int CMD_IS_VONR_ENABLED = 115;
361 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700362
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800363 // Parameters of select command.
364 private static final int SELECT_COMMAND = 0xA4;
365 private static final int SELECT_P1 = 0x04;
366 private static final int SELECT_P2 = 0;
367 private static final int SELECT_P3 = 0x10;
368
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700369 /** The singleton instance. */
370 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800371 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700372
Wink Saville3ab207e2014-11-20 13:07:20 -0800373 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800374 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800375 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700376 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800377 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700378 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800379 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800380 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800381 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700382 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800383 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700384
Peter Wangdafb9ac2020-01-15 14:13:38 -0800385 /** User Activity */
386 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800387 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
388
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700389 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
390
Derek Tan97ebb422014-09-05 16:55:38 -0700391 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
392 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800393 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800394 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700395
Michelecea4cf22018-12-21 15:00:11 -0800396 // String to store multi SIM allowed
397 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
398
Derek Tan740e1672017-06-27 14:56:27 -0700399 // The AID of ISD-R.
400 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
401
yinxub1bed742017-04-17 11:45:04 -0700402 private NetworkScanRequestTracker mNetworkScanRequestTracker;
403
David Kelly5e06a7f2018-03-12 14:10:59 +0000404 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
405 private static final int MANUFACTURER_CODE_LENGTH = 8;
406
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800407 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800408 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800409
Derek Tan89e89d42014-07-08 17:00:10 -0700410 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700411 * Experiment flag to enable erase modem config on reset network, default value is false
412 */
413 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
414 "reset_network_erase_modem_config_enabled";
415
Rambo Wang0f050d82021-02-12 11:43:36 -0800416 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800417
sandeepjsb6c87872021-09-27 15:34:44 +0000418 /**
419 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
420 * one ICCID active at the same time.
421 * Apps should use below API signatures if targeting SDK is T and beyond.
422 *
423 * @hide
424 */
425 @ChangeId
426 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
427 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800428
Naina Nallurid63128d2019-09-17 14:10:30 -0700429 /**
Chen Xu540470b2021-12-14 17:15:47 -0800430 * Apps targeting on Android T and beyond will get exception whenever icc close channel
431 * operation fails.
432 */
433 @ChangeId
434 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
435 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
436
437 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700438 * A request object to use for transmitting data to an ICC.
439 */
440 private static final class IccAPDUArgument {
441 public int channel, cla, command, p1, p2, p3;
442 public String data;
443
444 public IccAPDUArgument(int channel, int cla, int command,
445 int p1, int p2, int p3, String data) {
446 this.channel = channel;
447 this.cla = cla;
448 this.command = command;
449 this.p1 = p1;
450 this.p2 = p2;
451 this.p3 = p3;
452 this.data = data;
453 }
454 }
455
456 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700457 * A request object to use for transmitting data to an ICC.
458 */
459 private static final class ManualNetworkSelectionArgument {
460 public OperatorInfo operatorInfo;
461 public boolean persistSelection;
462
463 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
464 this.operatorInfo = operatorInfo;
465 this.persistSelection = persistSelection;
466 }
467 }
468
469 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700470 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
471 * request after sending. The main thread will notify the request when it is complete.
472 */
473 private static final class MainThreadRequest {
474 /** The argument to use for the request */
475 public Object argument;
476 /** The result of the request that is run on the main thread */
477 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800478 // The subscriber id that this request applies to. Defaults to
479 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
480 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700481
Nathan Harold92bed182018-10-12 18:16:49 -0700482 // In cases where subId is unavailable, the caller needs to specify the phone.
483 public Phone phone;
484
vagdeviaf9a5b92018-08-15 16:01:53 -0700485 public WorkSource workSource;
486
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700487 public MainThreadRequest(Object argument) {
488 this.argument = argument;
489 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800490
Nathan Harold92bed182018-10-12 18:16:49 -0700491 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
492 this.argument = argument;
493 if (phone != null) {
494 this.phone = phone;
495 }
496 this.workSource = workSource;
497 }
498
vagdeviaf9a5b92018-08-15 16:01:53 -0700499 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800500 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800501 if (subId != null) {
502 this.subId = subId;
503 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700504 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800505 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700506 }
507
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800508 private static final class IncomingThirdPartyCallArgs {
509 public final ComponentName component;
510 public final String callId;
511 public final String callerDisplayName;
512
513 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
514 String callerDisplayName) {
515 this.component = component;
516 this.callId = callId;
517 this.callerDisplayName = callerDisplayName;
518 }
519 }
520
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700521 /**
522 * A handler that processes messages on the main thread in the phone process. Since many
523 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
524 * inbound binder threads to the main thread in the phone process. The Binder thread
525 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
526 * on, which will be notified when the operation completes and will contain the result of the
527 * request.
528 *
529 * <p>If a MainThreadRequest object is provided in the msg.obj field,
530 * note that request.result must be set to something non-null for the calling thread to
531 * unblock.
532 */
533 private final class MainThreadHandler extends Handler {
534 @Override
535 public void handleMessage(Message msg) {
536 MainThreadRequest request;
537 Message onCompleted;
538 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000539 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700540 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800541 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700542
543 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700544 case CMD_HANDLE_USSD_REQUEST: {
545 request = (MainThreadRequest) msg.obj;
546 final Phone phone = getPhoneFromRequest(request);
547 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800548 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700549 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700550
Pengquan Menga1bb6272018-09-06 09:59:22 -0700551 if (!isUssdApiAllowed(request.subId)) {
552 // Carrier does not support use of this API, return failure.
553 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
554 UssdResponse response = new UssdResponse(ussdRequest, null);
555 Bundle returnData = new Bundle();
556 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
557 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700558
Pengquan Menga1bb6272018-09-06 09:59:22 -0700559 request.result = true;
560 notifyRequester(request);
561 return;
562 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700563
Pengquan Menga1bb6272018-09-06 09:59:22 -0700564 try {
565 request.result = phone != null
566 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
567 } catch (CallStateException cse) {
568 request.result = false;
569 }
570 // Wake up the requesting thread
571 notifyRequester(request);
572 break;
pkanwar32d516d2016-10-14 19:37:38 -0700573 }
574
Yorke Lee716f67e2015-06-17 15:39:16 -0700575 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700576 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700577 final Phone phone = getPhoneFromRequest(request);
578 request.result = phone != null ?
579 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
580 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700581 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700582 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700583 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700584 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700585
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700586 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700587 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700588 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000589 uiccPort = getUiccPortFromRequest(request);
590 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700591 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800592 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700593 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700594 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700595 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800596 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000597 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800598 iccArgument.channel, iccArgument.cla, iccArgument.command,
599 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
600 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700601 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700602 break;
603
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700604 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700605 ar = (AsyncResult) msg.obj;
606 request = (MainThreadRequest) ar.userObj;
607 if (ar.exception == null && ar.result != null) {
608 request.result = ar.result;
609 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800610 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700611 if (ar.result == null) {
612 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800613 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700614 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800615 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700616 } else {
617 loge("iccTransmitApduLogicalChannel: Unknown exception");
618 }
619 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700620 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700621 break;
622
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700623 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
624 request = (MainThreadRequest) msg.obj;
625 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000626 uiccPort = getUiccPortFromRequest(request);
627 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700628 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800629 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700630 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700631 } else {
632 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800633 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000634 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800635 iccArgument.cla, iccArgument.command, iccArgument.p1,
636 iccArgument.p2,
637 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700638 }
639 break;
640
641 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
642 ar = (AsyncResult) msg.obj;
643 request = (MainThreadRequest) ar.userObj;
644 if (ar.exception == null && ar.result != null) {
645 request.result = ar.result;
646 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800647 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700648 if (ar.result == null) {
649 loge("iccTransmitApduBasicChannel: Empty response");
650 } else if (ar.exception instanceof CommandException) {
651 loge("iccTransmitApduBasicChannel: CommandException: " +
652 ar.exception);
653 } else {
654 loge("iccTransmitApduBasicChannel: Unknown exception");
655 }
656 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700657 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700658 break;
659
660 case CMD_EXCHANGE_SIM_IO:
661 request = (MainThreadRequest) msg.obj;
662 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000663 uiccPort = getUiccPortFromRequest(request);
664 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700665 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800666 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700667 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700668 } else {
669 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
670 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000671 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700672 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
673 iccArgument.data, onCompleted);
674 }
675 break;
676
677 case EVENT_EXCHANGE_SIM_IO_DONE:
678 ar = (AsyncResult) msg.obj;
679 request = (MainThreadRequest) ar.userObj;
680 if (ar.exception == null && ar.result != null) {
681 request.result = ar.result;
682 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800683 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700684 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700685 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700686 break;
687
Derek Tan4d5e5c12014-02-04 11:54:58 -0800688 case CMD_SEND_ENVELOPE:
689 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000690 uiccPort = getUiccPortFromRequest(request);
691 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700692 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800693 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700694 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700695 } else {
696 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800697 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700698 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800699 break;
700
701 case EVENT_SEND_ENVELOPE_DONE:
702 ar = (AsyncResult) msg.obj;
703 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700704 if (ar.exception == null && ar.result != null) {
705 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800706 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800707 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700708 if (ar.result == null) {
709 loge("sendEnvelopeWithStatus: Empty response");
710 } else if (ar.exception instanceof CommandException) {
711 loge("sendEnvelopeWithStatus: CommandException: " +
712 ar.exception);
713 } else {
714 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
715 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800716 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700717 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800718 break;
719
Shishir Agrawal566b7612013-10-28 14:41:00 -0700720 case CMD_OPEN_CHANNEL:
721 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000722 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800723 IccLogicalChannelRequest openChannelRequest =
724 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000725 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700726 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800727 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800728 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700729 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700730 } else {
731 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800732 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
733 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700734 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700735 break;
736
737 case EVENT_OPEN_CHANNEL_DONE:
738 ar = (AsyncResult) msg.obj;
739 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700740 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700741 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700742 int[] result = (int[]) ar.result;
743 int channelId = result[0];
744 byte[] selectResponse = null;
745 if (result.length > 1) {
746 selectResponse = new byte[result.length - 1];
747 for (int i = 1; i < result.length; ++i) {
748 selectResponse[i - 1] = (byte) result[i];
749 }
750 }
751 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800752 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800753
754 uiccPort = getUiccPortFromRequest(request);
755 IccLogicalChannelRequest channelRequest =
756 (IccLogicalChannelRequest) request.argument;
757 channelRequest.channel = channelId;
758 uiccPort.onLogicalChannelOpened(channelRequest);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700759 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700760 if (ar.result == null) {
761 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700762 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700763 if (ar.exception != null) {
764 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
765 }
766
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700767 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700768 if (ar.exception instanceof CommandException) {
769 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800770 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700771 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700772 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700773 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700774 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700775 }
776 }
777 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800778 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700779 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700780 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700781 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700782 break;
783
784 case CMD_CLOSE_CHANNEL:
785 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000786 uiccPort = getUiccPortFromRequest(request);
787 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700788 loge("iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800789 // before this feature is enabled, this API should only return false if
790 // the operation fails instead of throwing runtime exception for
791 // backward-compatibility.
792 if (Compatibility.isChangeEnabled(ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE)) {
793 request.result = new IllegalArgumentException(
794 "iccCloseLogicalChannel: No UICC");
795 } else {
796 request.result = false;
797 }
798 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700799 } else {
800 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000801 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700802 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700803 break;
804
805 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800806 ar = (AsyncResult) msg.obj;
807 request = (MainThreadRequest) ar.userObj;
808 if (ar.exception == null) {
809 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800810 uiccPort = getUiccPortFromRequest(request);
811 final int channelId = (Integer) request.argument;
812 uiccPort.onLogicalChannelClosed(channelId);
Chen Xu540470b2021-12-14 17:15:47 -0800813 } else {
814 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800815 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800816 if (ar.exception instanceof CommandException) {
817 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
818 CommandException.Error error =
819 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800820 if (error == CommandException.Error.INVALID_ARGUMENTS) {
821 // should only throw exceptions from the binder threads.
822 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800823 "iccCloseLogicalChannel: invalid argument ");
824 }
825 } else {
826 loge("iccCloseLogicalChannel: Unknown exception");
827 }
Chen Xue9d737e2022-01-01 23:41:31 -0800828 // before this feature is enabled, this API should only return false if
829 // the operation fails instead of throwing runtime exception for
830 // backward-compatibility.
831 if (Compatibility.isChangeEnabled(ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE))
832 request.result = (exception != null) ? exception :
833 new IllegalStateException(
834 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800835 }
836 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800837 break;
838
839 case CMD_NV_READ_ITEM:
840 request = (MainThreadRequest) msg.obj;
841 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800842 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
843 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800844 break;
845
846 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700847 ar = (AsyncResult) msg.obj;
848 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800849 if (ar.exception == null && ar.result != null) {
850 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700851 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800852 request.result = "";
853 if (ar.result == null) {
854 loge("nvReadItem: Empty response");
855 } else if (ar.exception instanceof CommandException) {
856 loge("nvReadItem: CommandException: " +
857 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700858 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800859 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700860 }
861 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700862 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700863 break;
864
Jake Hambye994d462014-02-03 13:10:13 -0800865 case CMD_NV_WRITE_ITEM:
866 request = (MainThreadRequest) msg.obj;
867 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
868 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800869 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700870 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800871 break;
872
873 case EVENT_NV_WRITE_ITEM_DONE:
874 handleNullReturnEvent(msg, "nvWriteItem");
875 break;
876
877 case CMD_NV_WRITE_CDMA_PRL:
878 request = (MainThreadRequest) msg.obj;
879 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800880 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800881 break;
882
883 case EVENT_NV_WRITE_CDMA_PRL_DONE:
884 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
885 break;
886
chen xu6dac5ab2018-10-26 17:39:23 -0700887 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800888 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700889 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800890 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800891 break;
892
chen xu6dac5ab2018-10-26 17:39:23 -0700893 case EVENT_RESET_MODEM_CONFIG_DONE:
894 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800895 break;
896
Sooraj Sasindran37444802020-08-11 10:40:43 -0700897 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
898 request = (MainThreadRequest) msg.obj;
899 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
900 request);
901 Phone phone = getPhoneFromRequest(request);
902 if (phone != null) {
903 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
904 } else {
905 loge("isNRDualConnectivityEnabled: No phone object");
906 request.result = false;
907 notifyRequester(request);
908 }
909 break;
910 }
911
912 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
913 ar = (AsyncResult) msg.obj;
914 request = (MainThreadRequest) ar.userObj;
915 if (ar.exception == null && ar.result != null) {
916 request.result = ar.result;
917 } else {
918 // request.result must be set to something non-null
919 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700920 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700921 request.result = ar.result;
922 } else {
923 request.result = false;
924 }
925 if (ar.result == null) {
926 loge("isNRDualConnectivityEnabled: Empty response");
927 } else if (ar.exception instanceof CommandException) {
928 loge("isNRDualConnectivityEnabled: CommandException: "
929 + ar.exception);
930 } else {
931 loge("isNRDualConnectivityEnabled: Unknown exception");
932 }
933 }
934 notifyRequester(request);
935 break;
936
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700937 case CMD_IS_VONR_ENABLED: {
938 request = (MainThreadRequest) msg.obj;
939 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
940 request);
941 Phone phone = getPhoneFromRequest(request);
942 if (phone != null) {
943 phone.isVoNrEnabled(onCompleted, request.workSource);
944 } else {
945 loge("isVoNrEnabled: No phone object");
946 request.result = false;
947 notifyRequester(request);
948 }
949 break;
950 }
951
952 case EVENT_IS_VONR_ENABLED_DONE:
953 ar = (AsyncResult) msg.obj;
954 request = (MainThreadRequest) ar.userObj;
955 if (ar.exception == null && ar.result != null) {
956 request.result = ar.result;
957 } else {
958 // request.result must be set to something non-null
959 // for the calling thread to unblock
960 if (ar.result != null) {
961 request.result = ar.result;
962 } else {
963 request.result = false;
964 }
965 if (ar.result == null) {
966 loge("isVoNrEnabled: Empty response");
967 } else if (ar.exception instanceof CommandException) {
968 loge("isVoNrEnabled: CommandException: "
969 + ar.exception);
970 } else {
971 loge("isVoNrEnabled: Unknown exception");
972 }
973 }
974 notifyRequester(request);
975 break;
976
Sooraj Sasindran37444802020-08-11 10:40:43 -0700977 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
978 request = (MainThreadRequest) msg.obj;
979 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
980 Phone phone = getPhoneFromRequest(request);
981 if (phone != null) {
982 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
983 request.workSource);
984 } else {
985 loge("enableNrDualConnectivity: No phone object");
986 request.result =
987 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
988 notifyRequester(request);
989 }
990 break;
991 }
992
993 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
994 ar = (AsyncResult) msg.obj;
995 request = (MainThreadRequest) ar.userObj;
996 if (ar.exception == null) {
997 request.result =
998 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
999 } else {
1000 request.result =
1001 TelephonyManager
1002 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1003 if (ar.exception instanceof CommandException) {
1004 CommandException.Error error =
1005 ((CommandException) (ar.exception)).getCommandError();
1006 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1007 request.result =
1008 TelephonyManager
1009 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001010 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1011 request.result =
1012 TelephonyManager
1013 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001014 }
1015 loge("enableNrDualConnectivity" + ": CommandException: "
1016 + ar.exception);
1017 } else {
1018 loge("enableNrDualConnectivity" + ": Unknown exception");
1019 }
1020 }
1021 notifyRequester(request);
1022 break;
1023 }
1024
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001025 case CMD_ENABLE_VONR: {
1026 request = (MainThreadRequest) msg.obj;
1027 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1028 Phone phone = getPhoneFromRequest(request);
1029 if (phone != null) {
1030 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1031 request.workSource);
1032 } else {
1033 loge("setVoNrEnabled: No phone object");
1034 request.result =
1035 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1036 notifyRequester(request);
1037 }
1038 break;
1039 }
1040
1041 case EVENT_ENABLE_VONR_DONE: {
1042 ar = (AsyncResult) msg.obj;
1043 request = (MainThreadRequest) ar.userObj;
1044 if (ar.exception == null) {
1045 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1046 } else {
1047 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1048 if (ar.exception instanceof CommandException) {
1049 CommandException.Error error =
1050 ((CommandException) (ar.exception)).getCommandError();
1051 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1052 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1053 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1054 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1055 } else {
1056 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1057 }
1058 loge("setVoNrEnabled" + ": CommandException: "
1059 + ar.exception);
1060 } else {
1061 loge("setVoNrEnabled" + ": Unknown exception");
1062 }
1063 }
1064 notifyRequester(request);
1065 break;
1066 }
1067
SongFerngWang3ef3e072020-12-21 16:41:52 +08001068 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001069 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001070 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1071 request);
1072 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001073 break;
1074
SongFerngWang3ef3e072020-12-21 16:41:52 +08001075 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001076 ar = (AsyncResult) msg.obj;
1077 request = (MainThreadRequest) ar.userObj;
1078 if (ar.exception == null && ar.result != null) {
1079 request.result = ar.result; // Integer
1080 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301081 // request.result must be set to something non-null
1082 // for the calling thread to unblock
1083 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001084 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001085 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001086 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001087 loge("getAllowedNetworkTypesBitmask: CommandException: "
1088 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001089 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001090 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001091 }
1092 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001093 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001094 break;
1095
SongFerngWang3ef3e072020-12-21 16:41:52 +08001096 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001097 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001098 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1099 request);
1100 Pair<Integer, Long> reasonWithNetworkTypes =
1101 (Pair<Integer, Long>) request.argument;
1102 getPhoneFromRequest(request).setAllowedNetworkTypes(
1103 reasonWithNetworkTypes.first,
1104 reasonWithNetworkTypes.second,
1105 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001106 break;
1107
SongFerngWang3ef3e072020-12-21 16:41:52 +08001108 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1109 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001110 break;
1111
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001112 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1113 request = (MainThreadRequest)msg.obj;
1114 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001115 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001116 break;
1117
1118 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1119 ar = (AsyncResult)msg.obj;
1120 request = (MainThreadRequest)ar.userObj;
1121 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001122 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001123 break;
1124
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001125 case CMD_SET_VOICEMAIL_NUMBER:
1126 request = (MainThreadRequest) msg.obj;
1127 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1128 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001129 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1130 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001131 break;
1132
1133 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1134 handleNullReturnEvent(msg, "setVoicemailNumber");
1135 break;
1136
Stuart Scott54788802015-03-30 13:18:01 -07001137 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1138 request = (MainThreadRequest) msg.obj;
1139 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1140 request);
1141 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1142 break;
1143
1144 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1145 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1146 break;
1147
Shishir Agrawal302c8692015-06-19 13:49:39 -07001148 case CMD_PERFORM_NETWORK_SCAN:
1149 request = (MainThreadRequest) msg.obj;
1150 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1151 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1152 break;
1153
Hall Liu27d24262020-09-18 19:04:59 -07001154 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001155 request = (MainThreadRequest) msg.obj;
1156 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001157 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1158 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1159 request.argument;
1160 int callForwardingReason = args.first;
1161 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001162 break;
Hall Liu27d24262020-09-18 19:04:59 -07001163 }
1164 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001165 ar = (AsyncResult) msg.obj;
1166 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001167 TelephonyManager.CallForwardingInfoCallback callback =
1168 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1169 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001170 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001171 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001172 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1173 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1174 // Service Class is a bit mask per 3gpp 27.007. Search for
1175 // any service for voice call.
1176 if ((callForwardInfo.serviceClass
1177 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001178 callForwardingInfo = new CallForwardingInfo(
1179 callForwardInfo.status
1180 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001181 callForwardInfo.reason,
1182 callForwardInfo.number,
1183 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001184 break;
1185 }
1186 }
1187 // Didn't find a call forward info for voice call.
1188 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001189 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1190 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001191 }
Hall Liu27d24262020-09-18 19:04:59 -07001192 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001193 } else {
1194 if (ar.result == null) {
1195 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1196 }
1197 if (ar.exception != null) {
1198 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1199 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001200 int errorCode = TelephonyManager
1201 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001202 if (ar.exception instanceof CommandException) {
1203 CommandException.Error error =
1204 ((CommandException) (ar.exception)).getCommandError();
1205 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001206 errorCode = TelephonyManager
1207 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001208 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001209 errorCode = TelephonyManager
1210 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001211 }
1212 }
Hall Liu27d24262020-09-18 19:04:59 -07001213 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001214 }
Shuo Qian4a594052020-01-23 11:59:30 -08001215 break;
Hall Liu27d24262020-09-18 19:04:59 -07001216 }
Shuo Qian4a594052020-01-23 11:59:30 -08001217
Hall Liu27d24262020-09-18 19:04:59 -07001218 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001219 request = (MainThreadRequest) msg.obj;
1220 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001221 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001222 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001223 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1224 request.argument).first;
1225 request.phone.setCallForwardingOption(
1226 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001227 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001228 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001229 callForwardingInfoToSet.getReason(),
1230 callForwardingInfoToSet.getNumber(),
1231 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1232 break;
Hall Liu27d24262020-09-18 19:04:59 -07001233 }
Shuo Qian4a594052020-01-23 11:59:30 -08001234
Hall Liu27d24262020-09-18 19:04:59 -07001235 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001236 ar = (AsyncResult) msg.obj;
1237 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001238 Consumer<Integer> callback =
1239 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1240 request.argument).second;
1241 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001242 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001243 int errorCode = TelephonyManager.CallForwardingInfoCallback
1244 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001245 if (ar.exception instanceof CommandException) {
1246 CommandException.Error error =
1247 ((CommandException) (ar.exception)).getCommandError();
1248 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001249 errorCode = TelephonyManager.CallForwardingInfoCallback
1250 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001251 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001252 errorCode = TelephonyManager.CallForwardingInfoCallback
1253 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001254 }
1255 }
1256 callback.accept(errorCode);
1257 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001258 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001259 }
Shuo Qian4a594052020-01-23 11:59:30 -08001260 break;
Hall Liu27d24262020-09-18 19:04:59 -07001261 }
Shuo Qian4a594052020-01-23 11:59:30 -08001262
Hall Liu27d24262020-09-18 19:04:59 -07001263 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001264 request = (MainThreadRequest) msg.obj;
1265 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1266 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1267 break;
Hall Liu27d24262020-09-18 19:04:59 -07001268 }
Shuo Qian4a594052020-01-23 11:59:30 -08001269
Hall Liu27d24262020-09-18 19:04:59 -07001270 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001271 ar = (AsyncResult) msg.obj;
1272 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001273 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001274 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001275 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001276 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001277 // Service Class is a bit mask per 3gpp 27.007.
1278 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001279 if (callForwardResults.length > 1
1280 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001281 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001282 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001283 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1284 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001285 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001286 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001287 }
1288 } else {
1289 if (ar.result == null) {
1290 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1291 }
1292 if (ar.exception != null) {
1293 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1294 }
1295 if (ar.exception instanceof CommandException) {
1296 CommandException.Error error =
1297 ((CommandException) (ar.exception)).getCommandError();
1298 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001299 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001300 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001301 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1302 callWaitingStatus =
1303 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001304 }
1305 }
1306 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001307 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001308 break;
Hall Liu27d24262020-09-18 19:04:59 -07001309 }
Shuo Qian4a594052020-01-23 11:59:30 -08001310
Hall Liu27d24262020-09-18 19:04:59 -07001311 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001312 request = (MainThreadRequest) msg.obj;
1313 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001314 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1315 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001316 break;
Hall Liu27d24262020-09-18 19:04:59 -07001317 }
Shuo Qian4a594052020-01-23 11:59:30 -08001318
Hall Liu27d24262020-09-18 19:04:59 -07001319 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001320 ar = (AsyncResult) msg.obj;
1321 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001322 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1323 Consumer<Integer> callback =
1324 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1325 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001326 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001327 if (ar.exception instanceof CommandException) {
1328 CommandException.Error error =
1329 ((CommandException) (ar.exception)).getCommandError();
1330 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1331 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001332 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1333 callback.accept(
1334 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001335 } else {
1336 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1337 }
1338 } else {
1339 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1340 }
1341 } else {
1342 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1343 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001344 }
Shuo Qian4a594052020-01-23 11:59:30 -08001345 break;
Hall Liu27d24262020-09-18 19:04:59 -07001346 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001347 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1348 ar = (AsyncResult) msg.obj;
1349 request = (MainThreadRequest) ar.userObj;
1350 CellNetworkScanResult cellScanResult;
1351 if (ar.exception == null && ar.result != null) {
1352 cellScanResult = new CellNetworkScanResult(
1353 CellNetworkScanResult.STATUS_SUCCESS,
1354 (List<OperatorInfo>) ar.result);
1355 } else {
1356 if (ar.result == null) {
1357 loge("getCellNetworkScanResults: Empty response");
1358 }
1359 if (ar.exception != null) {
1360 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1361 }
1362 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1363 if (ar.exception instanceof CommandException) {
1364 CommandException.Error error =
1365 ((CommandException) (ar.exception)).getCommandError();
1366 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1367 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1368 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1369 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1370 }
1371 }
1372 cellScanResult = new CellNetworkScanResult(errorCode, null);
1373 }
1374 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001375 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001376 break;
1377
1378 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1379 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001380 ManualNetworkSelectionArgument selArg =
1381 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001382 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1383 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001384 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1385 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001386 break;
1387
1388 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001389 ar = (AsyncResult) msg.obj;
1390 request = (MainThreadRequest) ar.userObj;
1391 if (ar.exception == null) {
1392 request.result = true;
1393 } else {
1394 request.result = false;
1395 loge("setNetworkSelectionModeManual " + ar.exception);
1396 }
1397 notifyRequester(request);
1398 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001399 break;
1400
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001401 case CMD_GET_MODEM_ACTIVITY_INFO:
1402 request = (MainThreadRequest) msg.obj;
1403 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001404 if (defaultPhone != null) {
1405 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001406 } else {
1407 ResultReceiver result = (ResultReceiver) request.argument;
1408 Bundle bundle = new Bundle();
1409 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001410 new ModemActivityInfo(0, 0, 0,
1411 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001412 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001413 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001414 break;
1415
Hall Liud0f208c2020-10-14 16:54:44 -07001416 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001417 ar = (AsyncResult) msg.obj;
1418 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001419 ResultReceiver result = (ResultReceiver) request.argument;
1420
Hall Liud0f208c2020-10-14 16:54:44 -07001421 ModemActivityInfo ret = null;
1422 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001423 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001424 // Update the last modem activity info and the result of the request.
1425 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1426 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001427 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001428 int[] txTimeMs = info.getTransmitTimeMillis();
1429 int[] lastModemTxTimeMs = mLastModemActivityInfo
1430 .getTransmitTimeMillis();
1431 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1432 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1433 }
Hall Liu49656c02020-10-09 19:00:11 -07001434 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001435 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1436 + mLastModemActivityInfo.getSleepTimeMillis());
1437 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1438 + mLastModemActivityInfo.getIdleTimeMillis());
1439 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1440 mLastModemActivityInfo.setReceiveTimeMillis(
1441 info.getReceiveTimeMillis()
1442 + mLastModemActivityInfo.getReceiveTimeMillis());
1443 }
Hall Liu49656c02020-10-09 19:00:11 -07001444 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001445 mLastModemActivityInfo.getSleepTimeMillis(),
1446 mLastModemActivityInfo.getIdleTimeMillis(),
1447 mLastModemActivityInfo.getTransmitTimeMillis(),
1448 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001449 } else {
1450 if (ar.result == null) {
1451 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001452 error = TelephonyManager.ModemActivityInfoException
1453 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001454 } else if (ar.exception instanceof CommandException) {
1455 loge("queryModemActivityInfo: CommandException: " +
1456 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001457 error = TelephonyManager.ModemActivityInfoException
1458 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001459 } else {
1460 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001461 error = TelephonyManager.ModemActivityInfoException
1462 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001463 }
1464 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001465 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001466 if (ret != null) {
1467 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1468 } else {
1469 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1470 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001471 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001472 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001473 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001474 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001475
Meng Wang1a7c35a2016-05-05 20:56:15 -07001476 case CMD_SET_ALLOWED_CARRIERS:
1477 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001478 CarrierRestrictionRules argument =
1479 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001480 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001481 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001482 break;
1483
1484 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1485 ar = (AsyncResult) msg.obj;
1486 request = (MainThreadRequest) ar.userObj;
1487 if (ar.exception == null && ar.result != null) {
1488 request.result = ar.result;
1489 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001490 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1491 if (ar.exception instanceof CommandException) {
1492 loge("setAllowedCarriers: CommandException: " + ar.exception);
1493 CommandException.Error error =
1494 ((CommandException) (ar.exception)).getCommandError();
1495 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1496 request.result =
1497 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1498 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001499 } else {
1500 loge("setAllowedCarriers: Unknown exception");
1501 }
1502 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001503 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001504 break;
1505
1506 case CMD_GET_ALLOWED_CARRIERS:
1507 request = (MainThreadRequest) msg.obj;
1508 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001509 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001510 break;
1511
1512 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1513 ar = (AsyncResult) msg.obj;
1514 request = (MainThreadRequest) ar.userObj;
1515 if (ar.exception == null && ar.result != null) {
1516 request.result = ar.result;
1517 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001518 request.result = new IllegalStateException(
1519 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001520 if (ar.result == null) {
1521 loge("getAllowedCarriers: Empty response");
1522 } else if (ar.exception instanceof CommandException) {
1523 loge("getAllowedCarriers: CommandException: " +
1524 ar.exception);
1525 } else {
1526 loge("getAllowedCarriers: Unknown exception");
1527 }
1528 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001529 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001530 break;
1531
Nathan Haroldb3014052017-01-25 15:57:32 -08001532 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1533 ar = (AsyncResult) msg.obj;
1534 request = (MainThreadRequest) ar.userObj;
1535 if (ar.exception == null && ar.result != null) {
1536 request.result = ar.result;
1537 } else {
1538 request.result = new IllegalArgumentException(
1539 "Failed to retrieve Forbidden Plmns");
1540 if (ar.result == null) {
1541 loge("getForbiddenPlmns: Empty response");
1542 } else {
1543 loge("getForbiddenPlmns: Unknown exception");
1544 }
1545 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001546 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001547 break;
1548
1549 case CMD_GET_FORBIDDEN_PLMNS:
1550 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001551 uiccPort = getUiccPortFromRequest(request);
1552 if (uiccPort == null) {
1553 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001554 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001555 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001556 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001557 break;
1558 }
1559 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001560 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001561 if (uiccApp == null) {
1562 loge("getForbiddenPlmns() no app with specified type -- "
1563 + appType);
1564 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001565 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001566 break;
1567 } else {
1568 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1569 + " specified type -- " + appType);
1570 }
1571 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1572 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1573 onCompleted);
1574 break;
1575
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001576 case CMD_SWITCH_SLOTS:
1577 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001578 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001579 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001580 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001581 break;
1582
1583 case EVENT_SWITCH_SLOTS_DONE:
1584 ar = (AsyncResult) msg.obj;
1585 request = (MainThreadRequest) ar.userObj;
1586 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001587 notifyRequester(request);
1588 break;
1589 case CMD_GET_NETWORK_SELECTION_MODE:
1590 request = (MainThreadRequest) msg.obj;
1591 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1592 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1593 break;
1594
1595 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1596 ar = (AsyncResult) msg.obj;
1597 request = (MainThreadRequest) ar.userObj;
1598 if (ar.exception != null) {
1599 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1600 } else {
1601 int mode = ((int[]) ar.result)[0];
1602 if (mode == 0) {
1603 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1604 } else {
1605 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1606 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001607 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001608 notifyRequester(request);
1609 break;
1610 case CMD_GET_CDMA_ROAMING_MODE:
1611 request = (MainThreadRequest) msg.obj;
1612 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1613 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1614 break;
1615 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1616 ar = (AsyncResult) msg.obj;
1617 request = (MainThreadRequest) ar.userObj;
1618 if (ar.exception != null) {
1619 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1620 } else {
1621 request.result = ((int[]) ar.result)[0];
1622 }
1623 notifyRequester(request);
1624 break;
1625 case CMD_SET_CDMA_ROAMING_MODE:
1626 request = (MainThreadRequest) msg.obj;
1627 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1628 int mode = (int) request.argument;
1629 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1630 break;
1631 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1632 ar = (AsyncResult) msg.obj;
1633 request = (MainThreadRequest) ar.userObj;
1634 request.result = ar.exception == null;
1635 notifyRequester(request);
1636 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001637 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1638 request = (MainThreadRequest) msg.obj;
1639 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1640 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1641 break;
1642 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1643 ar = (AsyncResult) msg.obj;
1644 request = (MainThreadRequest) ar.userObj;
1645 if (ar.exception != null) {
1646 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1647 } else {
1648 request.result = ((int[]) ar.result)[0];
1649 }
1650 notifyRequester(request);
1651 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001652 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1653 request = (MainThreadRequest) msg.obj;
1654 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1655 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001656 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1657 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001658 break;
1659 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1660 ar = (AsyncResult) msg.obj;
1661 request = (MainThreadRequest) ar.userObj;
1662 request.result = ar.exception == null;
1663 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001664 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001665 case CMD_GET_ALL_CELL_INFO:
1666 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001667 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001668 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001669 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001670 case EVENT_GET_ALL_CELL_INFO_DONE:
1671 ar = (AsyncResult) msg.obj;
1672 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001673 // If a timeout occurs, the response will be null
1674 request.result = (ar.exception == null && ar.result != null)
1675 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001676 synchronized (request) {
1677 request.notifyAll();
1678 }
1679 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001680 case CMD_REQUEST_CELL_INFO_UPDATE:
1681 request = (MainThreadRequest) msg.obj;
1682 request.phone.requestCellInfoUpdate(request.workSource,
1683 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1684 break;
1685 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1686 ar = (AsyncResult) msg.obj;
1687 request = (MainThreadRequest) ar.userObj;
1688 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1689 try {
1690 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001691 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001692 cb.onError(
1693 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1694 ar.exception.getClass().getName(),
1695 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001696 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001697 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001698 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001699 } else {
1700 // use the result as returned
1701 cb.onCellInfo((List<CellInfo>) ar.result);
1702 }
1703 } catch (RemoteException re) {
1704 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1705 }
1706 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001707 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001708 request = (MainThreadRequest) msg.obj;
1709 WorkSource ws = (WorkSource) request.argument;
1710 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001711 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001712 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001713 }
1714 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001715 ar = (AsyncResult) msg.obj;
1716 request = (MainThreadRequest) ar.userObj;
1717 if (ar.exception == null) {
1718 request.result = ar.result;
1719 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001720 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001721 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001722 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001723 }
1724
1725 synchronized (request) {
1726 request.notifyAll();
1727 }
1728 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001729 }
chen xu6dac5ab2018-10-26 17:39:23 -07001730 case CMD_MODEM_REBOOT:
1731 request = (MainThreadRequest) msg.obj;
1732 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001733 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001734 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001735 case EVENT_CMD_MODEM_REBOOT_DONE:
1736 handleNullReturnEvent(msg, "rebootModem");
1737 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001738 case CMD_REQUEST_ENABLE_MODEM:
1739 request = (MainThreadRequest) msg.obj;
1740 boolean enable = (boolean) request.argument;
1741 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001742 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001743 PhoneConfigurationManager.getInstance()
1744 .enablePhone(request.phone, enable, onCompleted);
1745 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001746 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001747 ar = (AsyncResult) msg.obj;
1748 request = (MainThreadRequest) ar.userObj;
1749 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001750 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001751 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001752 if ((boolean) request.result) {
1753 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1754 updateModemStateMetrics();
1755 } else {
1756 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1757 + ar.exception);
1758 }
1759 notifyRequester(request);
1760 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001761 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001762 case CMD_GET_MODEM_STATUS:
1763 request = (MainThreadRequest) msg.obj;
1764 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1765 PhoneConfigurationManager.getInstance()
1766 .getPhoneStatusFromModem(request.phone, onCompleted);
1767 break;
1768 case EVENT_GET_MODEM_STATUS_DONE:
1769 ar = (AsyncResult) msg.obj;
1770 request = (MainThreadRequest) ar.userObj;
1771 int id = request.phone.getPhoneId();
1772 if (ar.exception == null && ar.result != null) {
1773 request.result = ar.result;
1774 //update the cache as modem status has changed
1775 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1776 (boolean) request.result);
1777 } else {
1778 // Return true if modem status cannot be retrieved. For most cases,
1779 // modem status is on. And for older version modems, GET_MODEM_STATUS
1780 // and disable modem are not supported. Modem is always on.
1781 // TODO: this should be fixed in R to support a third
1782 // status UNKNOWN b/131631629
1783 request.result = true;
1784 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1785 + ar.exception);
1786 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001787 notifyRequester(request);
1788 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001789 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1790 request = (MainThreadRequest) msg.obj;
1791 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1792 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1793 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1794 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1795 break;
1796 }
1797 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1798 ar = (AsyncResult) msg.obj;
1799 request = (MainThreadRequest) ar.userObj;
1800 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1801 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1802 args.second.accept(ar.exception == null);
1803 notifyRequester(request);
1804 break;
1805 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001806 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1807 request = (MainThreadRequest) msg.obj;
1808 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1809 Phone phone = getPhoneFromRequest(request);
1810 if (phone != null) {
1811 phone.getSystemSelectionChannels(onCompleted);
1812 } else {
1813 loge("getSystemSelectionChannels: No phone object");
1814 request.result = new ArrayList<RadioAccessSpecifier>();
1815 notifyRequester(request);
1816 }
1817 break;
1818 }
1819 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1820 ar = (AsyncResult) msg.obj;
1821 request = (MainThreadRequest) ar.userObj;
1822 if (ar.exception == null && ar.result != null) {
1823 request.result = ar.result;
1824 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001825 request.result = new IllegalStateException(
1826 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001827 if (ar.result == null) {
1828 loge("getSystemSelectionChannels: Empty response");
1829 } else {
1830 loge("getSystemSelectionChannels: Unknown exception");
1831 }
1832 }
1833 notifyRequester(request);
1834 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001835 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1836 ar = (AsyncResult) msg.obj;
1837 request = (MainThreadRequest) ar.userObj;
1838 if (ar.exception == null && ar.result != null) {
1839 request.result = ar.result;
1840 } else {
1841 request.result = -1;
1842 loge("Failed to set Forbidden Plmns");
1843 if (ar.result == null) {
1844 loge("setForbidenPlmns: Empty response");
1845 } else if (ar.exception != null) {
1846 loge("setForbiddenPlmns: Exception: " + ar.exception);
1847 request.result = -1;
1848 } else {
1849 loge("setForbiddenPlmns: Unknown exception");
1850 }
1851 }
1852 notifyRequester(request);
1853 break;
1854 case CMD_SET_FORBIDDEN_PLMNS:
1855 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001856 uiccPort = getUiccPortFromRequest(request);
1857 if (uiccPort == null) {
1858 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001859 request.result = -1;
1860 notifyRequester(request);
1861 break;
1862 }
1863 Pair<Integer, List<String>> setFplmnsArgs =
1864 (Pair<Integer, List<String>>) request.argument;
1865 appType = setFplmnsArgs.first;
1866 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001867 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001868 if (uiccApp == null) {
1869 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1870 request.result = -1;
1871 loge("Failed to get UICC App");
1872 notifyRequester(request);
1873 } else {
1874 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1875 ((SIMRecords) uiccApp.getIccRecords())
1876 .setForbiddenPlmns(onCompleted, fplmns);
1877 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001878 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001879 case CMD_ERASE_MODEM_CONFIG:
1880 request = (MainThreadRequest) msg.obj;
1881 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1882 defaultPhone.eraseModemConfig(onCompleted);
1883 break;
1884 case EVENT_ERASE_MODEM_CONFIG_DONE:
1885 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001886 break;
zoey chene02881a2019-12-30 16:11:23 +08001887
Kai Shif70f46f2021-03-03 13:59:46 -08001888 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1889 request = (MainThreadRequest) msg.obj;
1890 request.result = defaultPhone.eraseDataInSharedPreferences();
1891 notifyRequester(request);
1892 break;
1893
zoey chene02881a2019-12-30 16:11:23 +08001894 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1895 request = (MainThreadRequest) msg.obj;
1896 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1897 Pair<String, String> changed = (Pair<String, String>) request.argument;
1898 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1899 changed.first, changed.second, onCompleted);
1900 break;
1901 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1902 ar = (AsyncResult) msg.obj;
1903 request = (MainThreadRequest) ar.userObj;
1904 if (ar.exception == null) {
1905 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001906 // If the operation is successful, update the PIN storage
1907 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1908 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001909 UiccController.getInstance().getPinStorage()
1910 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001911 } else {
1912 request.result = msg.arg1;
1913 }
1914 notifyRequester(request);
1915 break;
1916
Michele Berionne5e411512020-11-13 02:36:59 +00001917 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001918 request = (MainThreadRequest) msg.obj;
1919 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1920 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1921 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1922 enabled.first, enabled.second, onCompleted);
1923 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001924 }
zoey chene02881a2019-12-30 16:11:23 +08001925 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1926 ar = (AsyncResult) msg.obj;
1927 request = (MainThreadRequest) ar.userObj;
1928 if (ar.exception == null) {
1929 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001930 // If the operation is successful, update the PIN storage
1931 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1932 int phoneId = getPhoneFromRequest(request).getPhoneId();
1933 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001934 UiccController.getInstance().getPinStorage()
1935 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001936 } else {
1937 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1938 }
zoey chene02881a2019-12-30 16:11:23 +08001939 } else {
1940 request.result = msg.arg1;
1941 }
Michele Berionne5e411512020-11-13 02:36:59 +00001942
1943
zoey chene02881a2019-12-30 16:11:23 +08001944 notifyRequester(request);
1945 break;
1946
Peter Wangdafb9ac2020-01-15 14:13:38 -08001947 case MSG_NOTIFY_USER_ACTIVITY:
1948 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001949 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001950 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1951 getDefaultPhone().getContext().sendBroadcastAsUser(
1952 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1953 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001954
1955 case CMD_SET_DATA_THROTTLING: {
1956 request = (MainThreadRequest) msg.obj;
1957 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1958 DataThrottlingRequest dataThrottlingRequest =
1959 (DataThrottlingRequest) request.argument;
1960 Phone phone = getPhoneFromRequest(request);
1961 if (phone != null) {
1962 phone.setDataThrottling(onCompleted,
1963 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1964 dataThrottlingRequest.getCompletionDurationMillis());
1965 } else {
1966 loge("setDataThrottling: No phone object");
1967 request.result =
1968 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1969 notifyRequester(request);
1970 }
1971
1972 break;
1973 }
1974 case EVENT_SET_DATA_THROTTLING_DONE:
1975 ar = (AsyncResult) msg.obj;
1976 request = (MainThreadRequest) ar.userObj;
1977
1978 if (ar.exception == null) {
1979 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1980 } else if (ar.exception instanceof CommandException) {
1981 loge("setDataThrottling: CommandException: " + ar.exception);
1982 CommandException.Error error =
1983 ((CommandException) (ar.exception)).getCommandError();
1984
1985 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1986 request.result = TelephonyManager
1987 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1988 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1989 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001990 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1991 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001992 } else {
1993 request.result =
1994 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1995 }
1996 } else {
1997 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1998 }
1999 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2000 notifyRequester(request);
2001 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002002
2003 case CMD_SET_SIM_POWER: {
2004 request = (MainThreadRequest) msg.obj;
2005 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2006 request = (MainThreadRequest) msg.obj;
2007 int stateToSet =
2008 ((Pair<Integer, IIntegerConsumer>)
2009 request.argument).first;
2010 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2011 break;
2012 }
2013 case EVENT_SET_SIM_POWER_DONE: {
2014 ar = (AsyncResult) msg.obj;
2015 request = (MainThreadRequest) ar.userObj;
2016 IIntegerConsumer callback =
2017 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2018 if (ar.exception != null) {
2019 loge("setSimPower exception: " + ar.exception);
2020 int errorCode = TelephonyManager.CallForwardingInfoCallback
2021 .RESULT_ERROR_UNKNOWN;
2022 if (ar.exception instanceof CommandException) {
2023 CommandException.Error error =
2024 ((CommandException) (ar.exception)).getCommandError();
2025 if (error == CommandException.Error.SIM_ERR) {
2026 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2027 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2028 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2029 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2030 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2031 } else {
2032 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2033 }
2034 }
2035 try {
2036 callback.accept(errorCode);
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 } else {
2042 try {
2043 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2044 } catch (RemoteException e) {
2045 // Ignore if the remote process is no longer available to call back.
2046 Log.w(LOG_TAG, "setSimPower: callback not available.");
2047 }
2048 }
2049 break;
2050 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002051 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2052 request = (MainThreadRequest) msg.obj;
2053
2054 final Phone phone = getPhoneFromRequest(request);
2055 if (phone == null || phone.getServiceStateTracker() == null) {
2056 request.result = new IllegalStateException("Phone or SST is null");
2057 notifyRequester(request);
2058 break;
2059 }
2060
2061 Pair<Integer, SignalStrengthUpdateRequest> pair =
2062 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2063 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2064 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002065 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002066 request.subId, pair.first /*callingUid*/,
2067 pair.second /*request*/, onCompleted);
2068 break;
2069 }
2070 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2071 ar = (AsyncResult) msg.obj;
2072 request = (MainThreadRequest) ar.userObj;
2073 // request.result will be the exception of ar if present, true otherwise.
2074 // Be cautious not to leave result null which will wait() forever
2075 request.result = ar.exception != null ? ar.exception : true;
2076 notifyRequester(request);
2077 break;
2078 }
2079 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2080 request = (MainThreadRequest) msg.obj;
2081
2082 Phone phone = getPhoneFromRequest(request);
2083 if (phone == null || phone.getServiceStateTracker() == null) {
2084 request.result = new IllegalStateException("Phone or SST is null");
2085 notifyRequester(request);
2086 break;
2087 }
2088
2089 Pair<Integer, SignalStrengthUpdateRequest> pair =
2090 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2091 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2092 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002093 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002094 request.subId, pair.first /*callingUid*/,
2095 pair.second /*request*/, onCompleted);
2096 break;
2097 }
2098 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2099 ar = (AsyncResult) msg.obj;
2100 request = (MainThreadRequest) ar.userObj;
2101 request.result = ar.exception != null ? ar.exception : true;
2102 notifyRequester(request);
2103 break;
2104 }
Jordan Liu109698e2020-11-24 14:50:34 -08002105
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002106 case CMD_GET_SLICING_CONFIG: {
2107 request = (MainThreadRequest) msg.obj;
2108 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2109 request.phone.getSlicingConfig(onCompleted);
2110 break;
2111 }
2112 case EVENT_GET_SLICING_CONFIG_DONE: {
2113 ar = (AsyncResult) msg.obj;
2114 request = (MainThreadRequest) ar.userObj;
2115 ResultReceiver result = (ResultReceiver) request.argument;
2116
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002117 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002118 Bundle bundle = new Bundle();
2119 int resultCode = 0;
2120 if (ar.exception != null) {
2121 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2122 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002123 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002124 } else if (ar.result == null) {
2125 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002126 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002127 } else {
2128 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002129 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2130 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002131 }
2132
2133 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002134 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002135 }
2136 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2137 result.send(resultCode, bundle);
2138 notifyRequester(request);
2139 break;
2140 }
2141
Michele Berionne5e411512020-11-13 02:36:59 +00002142 case CMD_PREPARE_UNATTENDED_REBOOT:
2143 request = (MainThreadRequest) msg.obj;
2144 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002145 UiccController.getInstance().getPinStorage()
2146 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002147 notifyRequester(request);
2148 break;
2149
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002150 default:
2151 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2152 break;
2153 }
2154 }
Jake Hambye994d462014-02-03 13:10:13 -08002155
Pengquan Menga1bb6272018-09-06 09:59:22 -07002156 private void notifyRequester(MainThreadRequest request) {
2157 synchronized (request) {
2158 request.notifyAll();
2159 }
2160 }
2161
Jake Hambye994d462014-02-03 13:10:13 -08002162 private void handleNullReturnEvent(Message msg, String command) {
2163 AsyncResult ar = (AsyncResult) msg.obj;
2164 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2165 if (ar.exception == null) {
2166 request.result = true;
2167 } else {
2168 request.result = false;
2169 if (ar.exception instanceof CommandException) {
2170 loge(command + ": CommandException: " + ar.exception);
2171 } else {
2172 loge(command + ": Unknown exception");
2173 }
2174 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002175 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002176 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002177 }
2178
2179 /**
2180 * Posts the specified command to be executed on the main thread,
2181 * waits for the request to complete, and returns the result.
2182 * @see #sendRequestAsync
2183 */
2184 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002185 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2186 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002187 }
2188
2189 /**
2190 * Posts the specified command to be executed on the main thread,
2191 * waits for the request to complete, and returns the result.
2192 * @see #sendRequestAsync
2193 */
2194 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2195 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002196 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002197 }
2198
2199 /**
2200 * Posts the specified command to be executed on the main thread,
2201 * waits for the request to complete, and returns the result.
2202 * @see #sendRequestAsync
2203 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002204 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002205 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2206 }
2207
2208 /**
2209 * Posts the specified command to be executed on the main thread,
2210 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2211 * if not timeout or null otherwise.
2212 * @see #sendRequestAsync
2213 */
2214 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2215 long timeoutInMs) {
2216 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002217 }
2218
2219 /**
2220 * Posts the specified command to be executed on the main thread,
2221 * waits for the request to complete, and returns the result.
2222 * @see #sendRequestAsync
2223 */
Nathan Harold92bed182018-10-12 18:16:49 -07002224 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002225 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002226 }
2227
2228 /**
2229 * Posts the specified command to be executed on the main thread,
2230 * waits for the request to complete, and returns the result.
2231 * @see #sendRequestAsync
2232 */
2233 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002234 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2235 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002236 }
2237
2238 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002239 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2240 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2241 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002242 * @see #sendRequestAsync
2243 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002244 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2245 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002246 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2247 throw new RuntimeException("This method will deadlock if called from the main thread.");
2248 }
2249
Nathan Harold92bed182018-10-12 18:16:49 -07002250 MainThreadRequest request = null;
2251 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2252 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2253 } else if (phone != null) {
2254 request = new MainThreadRequest(argument, phone, workSource);
2255 } else {
2256 request = new MainThreadRequest(argument, subId, workSource);
2257 }
2258
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002259 Message msg = mMainThreadHandler.obtainMessage(command, request);
2260 msg.sendToTarget();
2261
Rambo Wang0f050d82021-02-12 11:43:36 -08002262
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002263 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002264 if (timeoutInMs >= 0) {
2265 // Wait for at least timeoutInMs before returning null request result
2266 long now = SystemClock.elapsedRealtime();
2267 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002268 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002269 try {
2270 request.wait(deadline - now);
2271 } catch (InterruptedException e) {
2272 // Do nothing, go back and check if request is completed or timeout
2273 } finally {
2274 now = SystemClock.elapsedRealtime();
2275 }
2276 }
2277 } else {
2278 // Wait for the request to complete
2279 while (request.result == null) {
2280 try {
2281 request.wait();
2282 } catch (InterruptedException e) {
2283 // Do nothing, go back and wait until the request is complete
2284 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002285 }
2286 }
2287 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002288 if (request.result == null) {
2289 Log.wtf(LOG_TAG,
2290 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2291 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002292 return request.result;
2293 }
2294
2295 /**
2296 * Asynchronous ("fire and forget") version of sendRequest():
2297 * Posts the specified command to be executed on the main thread, and
2298 * returns immediately.
2299 * @see #sendRequest
2300 */
2301 private void sendRequestAsync(int command) {
2302 mMainThreadHandler.sendEmptyMessage(command);
2303 }
2304
2305 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002306 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002307 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002308 */
2309 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002310 sendRequestAsync(command, argument, null, null);
2311 }
2312
2313 /**
2314 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2315 * @see {@link #sendRequest(int,Object)}
2316 */
2317 private void sendRequestAsync(
2318 int command, Object argument, Phone phone, WorkSource workSource) {
2319 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002320 Message msg = mMainThreadHandler.obtainMessage(command, request);
2321 msg.sendToTarget();
2322 }
2323
2324 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002325 * Initialize the singleton PhoneInterfaceManager instance.
2326 * This is only done once, at startup, from PhoneApp.onCreate().
2327 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002328 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002329 synchronized (PhoneInterfaceManager.class) {
2330 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002331 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002332 } else {
2333 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2334 }
2335 return sInstance;
2336 }
2337 }
2338
2339 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002340 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002341 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002342 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002343 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002344 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002345 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002346 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002347 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002348 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002349 mTelephonySharedPreferences =
2350 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002351 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002352 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002353 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002354 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002355
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002356 publish();
2357 }
2358
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002359 private Phone getDefaultPhone() {
2360 Phone thePhone = getPhone(getDefaultSubscription());
2361 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2362 }
2363
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002364 private void publish() {
2365 if (DBG) log("publish: " + this);
2366
Peter Wangc035ce42020-01-08 21:00:22 -08002367 TelephonyFrameworkInitializer
2368 .getTelephonyServiceManager()
2369 .getTelephonyServiceRegisterer()
2370 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002371 }
2372
Stuart Scott584921c2015-01-15 17:10:34 -08002373 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002374 if (request.phone != null) {
2375 return request.phone;
2376 } else {
2377 return getPhoneFromSubId(request.subId);
2378 }
2379 }
2380
2381 private Phone getPhoneFromSubId(int subId) {
2382 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2383 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002384 }
2385
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002386 private UiccPort getUiccPortFromRequest(MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002387 Phone phone = getPhoneFromRequest(request);
2388 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002389 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002390 }
2391
Wink Saville36469e72014-06-11 15:17:00 -07002392 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002393 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002394 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002395 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002396
Kai Shif70f46f2021-03-03 13:59:46 -08002397 private void sendEraseModemConfig(@NonNull Phone phone) {
2398 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2399 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2400 }
2401
2402 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2403 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2404 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002405 }
2406
Peter Wang44b186e2020-01-13 23:33:09 -08002407 private boolean isImsAvailableOnDevice() {
2408 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2409 if (pm == null) {
2410 // For some reason package manger is not available.. This will fail internally anyway,
2411 // so do not throw error and allow.
2412 return true;
2413 }
2414 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2415 }
2416
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002417 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002418 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002419 }
2420
Wink Savilleb564aae2014-10-23 10:18:09 -07002421 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002422 if (DBG) log("dial: " + number);
2423 // No permission check needed here: This is just a wrapper around the
2424 // ACTION_DIAL intent, which is available to any app since it puts up
2425 // the UI before it does anything.
2426
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002427 final long identity = Binder.clearCallingIdentity();
2428 try {
2429 String url = createTelUrl(number);
2430 if (url == null) {
2431 return;
2432 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002433
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002434 // PENDING: should we just silently fail if phone is offhook or ringing?
2435 PhoneConstants.State state = mCM.getState(subId);
2436 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2437 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2438 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2439 mApp.startActivity(intent);
2440 }
2441 } finally {
2442 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002443 }
2444 }
2445
2446 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002447 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002448 }
2449
Wink Savilleb564aae2014-10-23 10:18:09 -07002450 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002451 if (DBG) log("call: " + number);
2452
2453 // This is just a wrapper around the ACTION_CALL intent, but we still
2454 // need to do a permission check since we're calling startActivity()
2455 // from the context of the phone app.
2456 enforceCallPermission();
2457
Jordan Liu1617b712019-07-10 15:06:26 -07002458 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002459 != AppOpsManager.MODE_ALLOWED) {
2460 return;
2461 }
2462
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002463 final long identity = Binder.clearCallingIdentity();
2464 try {
2465 String url = createTelUrl(number);
2466 if (url == null) {
2467 return;
2468 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002469
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002470 boolean isValid = false;
2471 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2472 if (slist != null) {
2473 for (SubscriptionInfo subInfoRecord : slist) {
2474 if (subInfoRecord.getSubscriptionId() == subId) {
2475 isValid = true;
2476 break;
2477 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002478 }
Wink Saville08874612014-08-31 19:19:58 -07002479 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002480 if (!isValid) {
2481 return;
2482 }
Wink Saville08874612014-08-31 19:19:58 -07002483
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002484 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2485 intent.putExtra(SUBSCRIPTION_KEY, subId);
2486 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2487 mApp.startActivity(intent);
2488 } finally {
2489 Binder.restoreCallingIdentity(identity);
2490 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002491 }
2492
Wink Savilleb564aae2014-10-23 10:18:09 -07002493 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002494 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002495 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2496 }
2497
Wink Savilleb564aae2014-10-23 10:18:09 -07002498 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002499 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002500 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2501 }
2502
Wink Savilleb564aae2014-10-23 10:18:09 -07002503 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002504 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002505
2506 final long identity = Binder.clearCallingIdentity();
2507 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002508 Phone phone = getPhone(subId);
2509 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002510 checkSimPin.start();
2511 return checkSimPin.unlockSim(null, pin);
2512 } finally {
2513 Binder.restoreCallingIdentity(identity);
2514 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002515 }
2516
Wink Savilleb564aae2014-10-23 10:18:09 -07002517 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002518 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002519
2520 final long identity = Binder.clearCallingIdentity();
2521 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002522 Phone phone = getPhone(subId);
2523 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002524 checkSimPuk.start();
2525 return checkSimPuk.unlockSim(puk, pin);
2526 } finally {
2527 Binder.restoreCallingIdentity(identity);
2528 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002529 }
2530
2531 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002532 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002533 * a synchronous one.
2534 */
2535 private static class UnlockSim extends Thread {
2536
2537 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002538 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002539
2540 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002541 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2542 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002543
2544 // For replies from SimCard interface
2545 private Handler mHandler;
2546
2547 // For async handler to identify request type
2548 private static final int SUPPLY_PIN_COMPLETE = 100;
2549
Michele Berionne5e411512020-11-13 02:36:59 +00002550 UnlockSim(int phoneId, IccCard simCard) {
2551 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002552 mSimCard = simCard;
2553 }
2554
2555 @Override
2556 public void run() {
2557 Looper.prepare();
2558 synchronized (UnlockSim.this) {
2559 mHandler = new Handler() {
2560 @Override
2561 public void handleMessage(Message msg) {
2562 AsyncResult ar = (AsyncResult) msg.obj;
2563 switch (msg.what) {
2564 case SUPPLY_PIN_COMPLETE:
2565 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2566 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002567 mRetryCount = msg.arg1;
2568 if (ar.exception != null) {
2569 if (ar.exception instanceof CommandException &&
2570 ((CommandException)(ar.exception)).getCommandError()
2571 == CommandException.Error.PASSWORD_INCORRECT) {
2572 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002573 } //When UiccCardApp dispose,handle message and return exception
2574 else if (ar.exception instanceof CommandException &&
2575 ((CommandException) (ar.exception)).getCommandError()
2576 == CommandException.Error.ABORTED) {
2577 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002578 } else {
2579 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2580 }
2581 } else {
2582 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2583 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002584 mDone = true;
2585 UnlockSim.this.notifyAll();
2586 }
2587 break;
2588 }
2589 }
2590 };
2591 UnlockSim.this.notifyAll();
2592 }
2593 Looper.loop();
2594 }
2595
2596 /*
2597 * Use PIN or PUK to unlock SIM card
2598 *
2599 * If PUK is null, unlock SIM card with PIN
2600 *
2601 * If PUK is not null, unlock SIM card with PUK and set PIN code
2602 */
Wink Saville9de0f752013-10-22 19:04:03 -07002603 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002604
2605 while (mHandler == null) {
2606 try {
2607 wait();
2608 } catch (InterruptedException e) {
2609 Thread.currentThread().interrupt();
2610 }
2611 }
2612 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2613
2614 if (puk == null) {
2615 mSimCard.supplyPin(pin, callback);
2616 } else {
2617 mSimCard.supplyPuk(puk, pin, callback);
2618 }
2619
2620 while (!mDone) {
2621 try {
2622 Log.d(LOG_TAG, "wait for done");
2623 wait();
2624 } catch (InterruptedException e) {
2625 // Restore the interrupted status
2626 Thread.currentThread().interrupt();
2627 }
2628 }
2629 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002630 int[] resultArray = new int[2];
2631 resultArray[0] = mResult;
2632 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002633
2634 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002635 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002636 }
2637
Wink Saville9de0f752013-10-22 19:04:03 -07002638 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002639 }
2640 }
2641
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002642 /**
2643 * This method has been removed due to privacy and stability concerns.
2644 */
2645 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002646 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002647 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2648 return;
Wink Saville36469e72014-06-11 15:17:00 -07002649 }
2650
Nathan Harold1f889d82020-06-04 17:05:26 -07002651 @Override
2652 public void updateServiceLocationWithPackageName(String callingPackage) {
2653 mApp.getSystemService(AppOpsManager.class)
2654 .checkPackage(Binder.getCallingUid(), callingPackage);
2655
Nathan Haroldf096d982020-11-18 17:18:06 -08002656 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002657 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2658 // Callers targeting S have no business invoking this method.
2659 return;
2660 }
2661
2662 LocationAccessPolicy.LocationPermissionResult locationResult =
2663 LocationAccessPolicy.checkLocationPermission(mApp,
2664 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2665 .setCallingPackage(callingPackage)
2666 .setCallingFeatureId(null)
2667 .setCallingPid(Binder.getCallingPid())
2668 .setCallingUid(Binder.getCallingUid())
2669 .setMethod("updateServiceLocation")
2670 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2671 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2672 .build());
2673 // Apps that lack location permission have no business calling this method;
2674 // however, because no permission was declared in the public API, denials must
2675 // all be "soft".
2676 switch (locationResult) {
2677 case DENIED_HARD: /* fall through */
2678 case DENIED_SOFT:
2679 return;
2680 }
2681
2682 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002683 final long identity = Binder.clearCallingIdentity();
2684 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002685 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002686 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002687 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002688 }
2689 } finally {
2690 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002691 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002692 }
2693
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002694 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002695 @Override
2696 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002697 return isRadioOnWithFeature(callingPackage, null);
2698 }
2699
2700
2701 @Override
2702 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2703 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2704 callingFeatureId);
2705 }
2706
2707 @Deprecated
2708 @Override
2709 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2710 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002711 }
2712
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002713 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002714 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2715 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002716 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002717 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002718 return false;
2719 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002720
2721 final long identity = Binder.clearCallingIdentity();
2722 try {
2723 return isRadioOnForSubscriber(subId);
2724 } finally {
2725 Binder.restoreCallingIdentity(identity);
2726 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002727 }
2728
2729 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002730 final long identity = Binder.clearCallingIdentity();
2731 try {
2732 final Phone phone = getPhone(subId);
2733 if (phone != null) {
2734 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2735 } else {
2736 return false;
2737 }
2738 } finally {
2739 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002740 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002741 }
2742
2743 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002744 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002745 }
Wink Saville36469e72014-06-11 15:17:00 -07002746
Wink Savilleb564aae2014-10-23 10:18:09 -07002747 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002748 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002749
2750 final long identity = Binder.clearCallingIdentity();
2751 try {
2752 final Phone phone = getPhone(subId);
2753 if (phone != null) {
2754 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2755 }
2756 } finally {
2757 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002758 }
Wink Saville36469e72014-06-11 15:17:00 -07002759 }
2760
2761 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002762 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002763 }
2764
Wink Savilleb564aae2014-10-23 10:18:09 -07002765 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002766 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002767
2768 final long identity = Binder.clearCallingIdentity();
2769 try {
2770 final Phone phone = getPhone(subId);
2771 if (phone == null) {
2772 return false;
2773 }
2774 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2775 toggleRadioOnOffForSubscriber(subId);
2776 }
2777 return true;
2778 } finally {
2779 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002780 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002781 }
Wink Saville36469e72014-06-11 15:17:00 -07002782
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002783 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002784 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002785 /*
2786 * If any of the Radios are available, it will need to be
2787 * shutdown. So return true if any Radio is available.
2788 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002789 final long identity = Binder.clearCallingIdentity();
2790 try {
2791 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2792 Phone phone = PhoneFactory.getPhone(i);
2793 if (phone != null && phone.isRadioAvailable()) return true;
2794 }
2795 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2796 return false;
2797 } finally {
2798 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002799 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002800 }
2801
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002802 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002803 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002804 enforceModifyPermission();
2805
2806 final long identity = Binder.clearCallingIdentity();
2807 try {
2808 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2809 logv("Shutting down Phone " + i);
2810 shutdownRadioUsingPhoneId(i);
2811 }
2812 } finally {
2813 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002814 }
2815 }
2816
2817 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002818 Phone phone = PhoneFactory.getPhone(phoneId);
2819 if (phone != null && phone.isRadioAvailable()) {
2820 phone.shutdownRadio();
2821 }
2822 }
2823
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002824 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002825 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002826
2827 final long identity = Binder.clearCallingIdentity();
2828 try {
2829 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2830 if (defaultPhone != null) {
2831 defaultPhone.setRadioPower(turnOn);
2832 return true;
2833 } else {
2834 loge("There's no default phone.");
2835 return false;
2836 }
2837 } finally {
2838 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002839 }
Wink Saville36469e72014-06-11 15:17:00 -07002840 }
2841
Wink Savilleb564aae2014-10-23 10:18:09 -07002842 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002843 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002844
2845 final long identity = Binder.clearCallingIdentity();
2846 try {
2847 final Phone phone = getPhone(subId);
2848 if (phone != null) {
2849 phone.setRadioPower(turnOn);
2850 return true;
2851 } else {
2852 return false;
2853 }
2854 } finally {
2855 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002856 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002857 }
2858
Wink Saville36469e72014-06-11 15:17:00 -07002859 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002860 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002861 public boolean enableDataConnectivity() {
2862 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002863
2864 final long identity = Binder.clearCallingIdentity();
2865 try {
2866 int subId = mSubscriptionController.getDefaultDataSubId();
2867 final Phone phone = getPhone(subId);
2868 if (phone != null) {
Jack Yu99e87332021-12-17 23:14:15 -08002869 if (phone.isUsingNewDataStack()) {
2870 phone.getDataSettingsManager().setDataEnabled(
2871 TelephonyManager.DATA_ENABLED_REASON_USER, true);
2872 } else {
2873 phone.getDataEnabledSettings().setDataEnabled(
2874 TelephonyManager.DATA_ENABLED_REASON_USER, true);
2875 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002876 return true;
2877 } else {
2878 return false;
2879 }
2880 } finally {
2881 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002882 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002883 }
2884
Wink Saville36469e72014-06-11 15:17:00 -07002885 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002886 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002887 public boolean disableDataConnectivity() {
2888 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002889
2890 final long identity = Binder.clearCallingIdentity();
2891 try {
2892 int subId = mSubscriptionController.getDefaultDataSubId();
2893 final Phone phone = getPhone(subId);
2894 if (phone != null) {
Jack Yu99e87332021-12-17 23:14:15 -08002895 if (phone.isUsingNewDataStack()) {
2896 phone.getDataSettingsManager().setDataEnabled(
2897 TelephonyManager.DATA_ENABLED_REASON_USER, false);
2898 } else {
2899 phone.getDataEnabledSettings().setDataEnabled(
2900 TelephonyManager.DATA_ENABLED_REASON_USER, false);
2901 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002902 return true;
2903 } else {
2904 return false;
2905 }
2906 } finally {
2907 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002908 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002909 }
2910
Sanket Padawe356d7632015-06-22 14:03:32 -07002911 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002912 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002913 final long identity = Binder.clearCallingIdentity();
2914 try {
2915 final Phone phone = getPhone(subId);
2916 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002917 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002918 } else {
2919 return false;
2920 }
2921 } finally {
2922 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002923 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002924 }
2925
2926 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002927 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002928 }
2929
pkanwarae03a6b2016-11-06 20:37:09 -08002930 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002931 enforceCallPermission();
2932
2933 final long identity = Binder.clearCallingIdentity();
2934 try {
2935 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2936 return;
2937 }
2938 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2939 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2940 } finally {
2941 Binder.restoreCallingIdentity(identity);
2942 }
pkanwar32d516d2016-10-14 19:37:38 -07002943 };
2944
Wink Savilleb564aae2014-10-23 10:18:09 -07002945 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002946 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002947
2948 final long identity = Binder.clearCallingIdentity();
2949 try {
2950 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2951 return false;
2952 }
2953 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2954 } finally {
2955 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002956 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002957 }
2958
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002959 /**
2960 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2961 * tag on getCallState Binder call.
2962 */
2963 @Deprecated
2964 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002965 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002966 if (CompatChanges.isChangeEnabled(
2967 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2968 Binder.getCallingUid())) {
2969 // Do not allow this API to be called on API version 31+, it should only be
2970 // called on old apps using this Binder call directly.
2971 throw new SecurityException("This method can only be used for applications "
2972 + "targeting API version 30 or less.");
2973 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002974 final long identity = Binder.clearCallingIdentity();
2975 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002976 Phone phone = getPhone(getDefaultSubscription());
2977 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2978 PhoneConstantConversions.convertCallState(phone.getState());
2979 } finally {
2980 Binder.restoreCallingIdentity(identity);
2981 }
2982 }
2983
2984 @Override
2985 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2986 if (CompatChanges.isChangeEnabled(
2987 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2988 Binder.getCallingUid())) {
2989 // Check READ_PHONE_STATE for API version 31+
2990 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2991 featureId, "getCallStateForSubscription")) {
2992 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2993 + "targeting API level 31+.");
2994 }
2995 }
2996 final long identity = Binder.clearCallingIdentity();
2997 try {
2998 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002999 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3000 PhoneConstantConversions.convertCallState(phone.getState());
3001 } finally {
3002 Binder.restoreCallingIdentity(identity);
3003 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003004 }
3005
Sanket Padawe356d7632015-06-22 14:03:32 -07003006 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003007 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003008 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
3009 }
3010
3011 @Override
3012 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003013 final long identity = Binder.clearCallingIdentity();
3014 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003015 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003016 if (phone != null) {
Jack Yu2c450952021-11-29 11:36:17 -08003017 if (phone.isUsingNewDataStack()) {
3018 return phone.getDataNetworkController().getInternetDataNetworkState();
3019 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003020 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
3021 } else {
3022 return PhoneConstantConversions.convertDataState(
3023 PhoneConstants.DataState.DISCONNECTED);
3024 }
3025 } finally {
3026 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003027 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003028 }
3029
Sanket Padawe356d7632015-06-22 14:03:32 -07003030 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003031 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003032 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
3033 }
3034
3035 @Override
3036 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003037 final long identity = Binder.clearCallingIdentity();
3038 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003039 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003040 if (phone != null) {
3041 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
3042 } else {
3043 return TelephonyManager.DATA_ACTIVITY_NONE;
3044 }
3045 } finally {
3046 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003047 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003048 }
3049
3050 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003051 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003052 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003053 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003054
3055 LocationAccessPolicy.LocationPermissionResult locationResult =
3056 LocationAccessPolicy.checkLocationPermission(mApp,
3057 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3058 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003059 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003060 .setCallingPid(Binder.getCallingPid())
3061 .setCallingUid(Binder.getCallingUid())
3062 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003063 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003064 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3065 .build());
3066 switch (locationResult) {
3067 case DENIED_HARD:
3068 throw new SecurityException("Not allowed to access cell location");
3069 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003070 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3071 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003072 }
3073
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003074 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003075 final long identity = Binder.clearCallingIdentity();
3076 try {
3077 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003078 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003079 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003080 } finally {
3081 Binder.restoreCallingIdentity(identity);
3082 }
Svetoslav64fad262015-04-14 14:35:21 -07003083 }
3084
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003085 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003086 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003087 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3088 // registered cell info, so return a NULL country instead.
3089 final long identity = Binder.clearCallingIdentity();
3090 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003091 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3092 // Get default phone in this case.
3093 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3094 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003095 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003096 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003097 if (phone == null) return "";
3098 ServiceStateTracker sst = phone.getServiceStateTracker();
3099 if (sst == null) return "";
3100 LocaleTracker lt = sst.getLocaleTracker();
3101 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003102 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003103 } finally {
3104 Binder.restoreCallingIdentity(identity);
3105 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003106 }
3107
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003108 /**
3109 * This method was removed due to potential issues caused by performing partial
3110 * updates of service state, and lack of a credible use case.
3111 *
3112 * This has the ability to break the telephony implementation by disabling notification of
3113 * changes in device connectivity. DO NOT USE THIS!
3114 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003115 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003116 public void enableLocationUpdates() {
3117 mApp.enforceCallingOrSelfPermission(
3118 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003119 }
3120
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003121 /**
3122 * This method was removed due to potential issues caused by performing partial
3123 * updates of service state, and lack of a credible use case.
3124 *
3125 * This has the ability to break the telephony implementation by disabling notification of
3126 * changes in device connectivity. DO NOT USE THIS!
3127 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003128 @Override
3129 public void disableLocationUpdates() {
3130 mApp.enforceCallingOrSelfPermission(
3131 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003132 }
3133
3134 @Override
3135 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003136 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3137 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003138 try {
3139 mApp.getSystemService(AppOpsManager.class)
3140 .checkPackage(Binder.getCallingUid(), callingPackage);
3141 } catch (SecurityException e) {
3142 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3143 throw e;
3144 }
3145
Nathan Haroldf096d982020-11-18 17:18:06 -08003146 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003147 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3148 throw new SecurityException(
3149 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3150 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003151
Jordan Liu1617b712019-07-10 15:06:26 -07003152 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003153 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3154 return null;
3155 }
Svetoslav64fad262015-04-14 14:35:21 -07003156
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003157 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003158
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003159 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003160 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003161
Nathan Haroldf180aac2018-06-01 18:43:55 -07003162 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3163 for (CellInfo ci : info) {
3164 if (ci instanceof CellInfoGsm) {
3165 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3166 } else if (ci instanceof CellInfoWcdma) {
3167 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3168 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003169 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003170 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003171 }
3172
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003173 private List<CellInfo> getCachedCellInfo() {
3174 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3175 for (Phone phone : PhoneFactory.getPhones()) {
3176 List<CellInfo> info = phone.getAllCellInfo();
3177 if (info != null) cellInfos.addAll(info);
3178 }
3179 return cellInfos;
3180 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003181
3182 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003183 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003184 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003185 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003186
3187 LocationAccessPolicy.LocationPermissionResult locationResult =
3188 LocationAccessPolicy.checkLocationPermission(mApp,
3189 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3190 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003191 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003192 .setCallingPid(Binder.getCallingPid())
3193 .setCallingUid(Binder.getCallingUid())
3194 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003195 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003196 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3197 .build());
3198 switch (locationResult) {
3199 case DENIED_HARD:
3200 throw new SecurityException("Not allowed to access cell info");
3201 case DENIED_SOFT:
3202 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003203 }
3204
Nathan Haroldf096d982020-11-18 17:18:06 -08003205 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003206 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3207 return getCachedCellInfo();
3208 }
3209
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003210 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003211 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003212 final long identity = Binder.clearCallingIdentity();
3213 try {
3214 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3215 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003216 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003217 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003218 if (info != null) cellInfos.addAll(info);
3219 }
3220 return cellInfos;
3221 } finally {
3222 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003223 }
3224 }
3225
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003226 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003227 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3228 String callingFeatureId) {
3229 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3230 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003231 }
3232
3233 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003234 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3235 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003236 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003237 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003238 }
3239
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003240 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3241 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003242 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003243 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003244
3245 LocationAccessPolicy.LocationPermissionResult locationResult =
3246 LocationAccessPolicy.checkLocationPermission(mApp,
3247 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3248 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003249 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003250 .setCallingPid(Binder.getCallingPid())
3251 .setCallingUid(Binder.getCallingUid())
3252 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003253 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3254 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003255 .build());
3256 switch (locationResult) {
3257 case DENIED_HARD:
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 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003263 throw new SecurityException("Not allowed to access cell info");
3264 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003265 if (TelephonyPermissions
3266 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003267 // Safetynet logging for b/154934934
3268 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3269 }
Nathan Harold5320c422019-05-09 10:26:08 -07003270 try {
3271 cb.onCellInfo(new ArrayList<CellInfo>());
3272 } catch (RemoteException re) {
3273 // Drop without consequences
3274 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003275 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003276 }
3277
Nathan Harolda939a962019-05-09 10:13:47 -07003278
3279 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003280 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3281
3282 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3283 }
3284
3285 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003286 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003287 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003288 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003289
3290 final long identity = Binder.clearCallingIdentity();
3291 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003292 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003293 } finally {
3294 Binder.restoreCallingIdentity(identity);
3295 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003296 }
3297
Shishir Agrawala9f32182016-04-12 12:00:16 -07003298 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003299 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003300 Phone phone = PhoneFactory.getPhone(slotIndex);
3301 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003302 return null;
3303 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003304 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003305 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003306 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003307 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003308 return null;
3309 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003310
3311 final long identity = Binder.clearCallingIdentity();
3312 try {
3313 return phone.getImei();
3314 } finally {
3315 Binder.restoreCallingIdentity(identity);
3316 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003317 }
3318
3319 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003320 public String getTypeAllocationCodeForSlot(int slotIndex) {
3321 Phone phone = PhoneFactory.getPhone(slotIndex);
3322 String tac = null;
3323 if (phone != null) {
3324 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003325 try {
3326 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3327 } catch (IndexOutOfBoundsException e) {
3328 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3329 return null;
3330 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003331 }
3332 return tac;
3333 }
3334
3335 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003336 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003337 try {
3338 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3339 } catch (SecurityException se) {
3340 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3341 throw new SecurityException("Package " + callingPackage + " does not belong to "
3342 + Binder.getCallingUid());
3343 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003344 Phone phone = PhoneFactory.getPhone(slotIndex);
3345 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003346 return null;
3347 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003348
Jeff Davidson913390f2018-02-23 17:11:49 -08003349 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003350 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003351 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003352 return null;
3353 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003354
3355 final long identity = Binder.clearCallingIdentity();
3356 try {
3357 return phone.getMeid();
3358 } finally {
3359 Binder.restoreCallingIdentity(identity);
3360 }
Jack Yu2af8d712017-03-15 17:14:14 -07003361 }
3362
3363 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003364 public String getManufacturerCodeForSlot(int slotIndex) {
3365 Phone phone = PhoneFactory.getPhone(slotIndex);
3366 String manufacturerCode = null;
3367 if (phone != null) {
3368 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003369 try {
3370 manufacturerCode =
3371 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3372 } catch (IndexOutOfBoundsException e) {
3373 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3374 return null;
3375 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003376 }
3377 return manufacturerCode;
3378 }
3379
3380 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003381 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3382 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003383 Phone phone = PhoneFactory.getPhone(slotIndex);
3384 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003385 return null;
3386 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003387 int subId = phone.getSubId();
3388 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003389 mApp, subId, callingPackage, callingFeatureId,
3390 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003391 return null;
3392 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003393
3394 final long identity = Binder.clearCallingIdentity();
3395 try {
3396 return phone.getDeviceSvn();
3397 } finally {
3398 Binder.restoreCallingIdentity(identity);
3399 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003400 }
3401
fionaxu43304da2017-11-27 22:51:16 -08003402 @Override
3403 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003404 final long identity = Binder.clearCallingIdentity();
3405 try {
3406 final Phone phone = getPhone(subId);
3407 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3408 } finally {
3409 Binder.restoreCallingIdentity(identity);
3410 }
fionaxu43304da2017-11-27 22:51:16 -08003411 }
3412
3413 @Override
3414 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003415 final long identity = Binder.clearCallingIdentity();
3416 try {
3417 final Phone phone = getPhone(subId);
3418 return phone == null ? null : phone.getCarrierName();
3419 } finally {
3420 Binder.restoreCallingIdentity(identity);
3421 }
fionaxu43304da2017-11-27 22:51:16 -08003422 }
3423
calvinpanffe225e2018-11-01 19:43:06 +08003424 @Override
chen xu0026ca62019-03-06 15:28:50 -08003425 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003426 final long identity = Binder.clearCallingIdentity();
3427 try {
3428 final Phone phone = getPhone(subId);
3429 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003430 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003431 } finally {
3432 Binder.restoreCallingIdentity(identity);
3433 }
3434 }
3435
3436 @Override
chen xu0026ca62019-03-06 15:28:50 -08003437 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003438 final long identity = Binder.clearCallingIdentity();
3439 try {
3440 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003441 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003442 } finally {
3443 Binder.restoreCallingIdentity(identity);
3444 }
3445 }
3446
chen xu651eec72018-11-11 19:03:44 -08003447 @Override
chen xu864e11c2018-12-06 22:10:03 -08003448 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3449 if (!isSubscriptionMccMnc) {
3450 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3451 }
chen xu651eec72018-11-11 19:03:44 -08003452 final Phone phone = PhoneFactory.getPhone(slotIndex);
3453 if (phone == null) {
3454 return TelephonyManager.UNKNOWN_CARRIER_ID;
3455 }
3456 final long identity = Binder.clearCallingIdentity();
3457 try {
3458 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3459 } finally {
3460 Binder.restoreCallingIdentity(identity);
3461 }
3462 }
3463
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003464 //
3465 // Internal helper methods.
3466 //
3467
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003468 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003469 * Make sure the caller is the calling package itself
3470 *
3471 * @throws SecurityException if the caller is not the calling package
3472 */
3473 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3474 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003475 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3476 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003477 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003478 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003479 } catch (PackageManager.NameNotFoundException e) {
3480 // packageUid is -1
3481 }
3482 if (packageUid != callingUid) {
3483 throw new SecurityException(message + ": Package " + callingPackage
3484 + " does not belong to " + callingUid);
3485 }
3486 }
3487
3488 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003489 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3490 *
3491 * @throws SecurityException if the caller does not have the required permission
3492 */
3493 private void enforceModifyPermission() {
3494 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3495 }
3496
Shuo Qian3b6ee772019-11-13 17:43:31 -08003497 private void enforceActiveEmergencySessionPermission() {
3498 mApp.enforceCallingOrSelfPermission(
3499 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3500 }
3501
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003502 /**
3503 * Make sure the caller has the CALL_PHONE permission.
3504 *
3505 * @throws SecurityException if the caller does not have the required permission
3506 */
3507 private void enforceCallPermission() {
3508 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3509 }
3510
paulhu5a773602019-08-23 19:17:33 +08003511 private void enforceSettingsPermission() {
3512 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003513 }
3514
Michele Berionne5e411512020-11-13 02:36:59 +00003515 private void enforceRebootPermission() {
3516 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3517 }
3518
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003519 private String createTelUrl(String number) {
3520 if (TextUtils.isEmpty(number)) {
3521 return null;
3522 }
3523
Jake Hambye994d462014-02-03 13:10:13 -08003524 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003525 }
3526
Ihab Awadf9e92732013-12-05 18:02:52 -08003527 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003528 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3529 }
3530
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003531 private static void logv(String msg) {
3532 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3533 }
3534
Ihab Awadf9e92732013-12-05 18:02:52 -08003535 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003536 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3537 }
3538
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003539 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003540 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003541 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003542 }
3543
Sanket Padawe356d7632015-06-22 14:03:32 -07003544 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003545 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003546 final long identity = Binder.clearCallingIdentity();
3547 try {
3548 final Phone phone = PhoneFactory.getPhone(slotIndex);
3549 if (phone == null) {
3550 return PhoneConstants.PHONE_TYPE_NONE;
3551 } else {
3552 return phone.getPhoneType();
3553 }
3554 } finally {
3555 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003556 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003557 }
3558
3559 /**
3560 * Returns the CDMA ERI icon index to display
3561 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003562 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003563 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3564 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3565 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003566 }
3567
Sanket Padawe356d7632015-06-22 14:03:32 -07003568 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003569 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3570 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003571 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003572 mApp, subId, callingPackage, callingFeatureId,
3573 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003574 return -1;
3575 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003576
3577 final long identity = Binder.clearCallingIdentity();
3578 try {
3579 final Phone phone = getPhone(subId);
3580 if (phone != null) {
3581 return phone.getCdmaEriIconIndex();
3582 } else {
3583 return -1;
3584 }
3585 } finally {
3586 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003587 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003588 }
3589
3590 /**
3591 * Returns the CDMA ERI icon mode,
3592 * 0 - ON
3593 * 1 - FLASHING
3594 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003595 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003596 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3597 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3598 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003599 }
3600
Sanket Padawe356d7632015-06-22 14:03:32 -07003601 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003602 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3603 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003604 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003605 mApp, subId, callingPackage, callingFeatureId,
3606 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003607 return -1;
3608 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003609
3610 final long identity = Binder.clearCallingIdentity();
3611 try {
3612 final Phone phone = getPhone(subId);
3613 if (phone != null) {
3614 return phone.getCdmaEriIconMode();
3615 } else {
3616 return -1;
3617 }
3618 } finally {
3619 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003620 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003621 }
3622
3623 /**
3624 * Returns the CDMA ERI text,
3625 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003626 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003627 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3628 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3629 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003630 }
3631
Sanket Padawe356d7632015-06-22 14:03:32 -07003632 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003633 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3634 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003635 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003636 mApp, subId, callingPackage, callingFeatureId,
3637 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003638 return null;
3639 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003640
3641 final long identity = Binder.clearCallingIdentity();
3642 try {
3643 final Phone phone = getPhone(subId);
3644 if (phone != null) {
3645 return phone.getCdmaEriText();
3646 } else {
3647 return null;
3648 }
3649 } finally {
3650 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003651 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003652 }
3653
3654 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003655 * Returns the CDMA MDN.
3656 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003657 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003658 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003659 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3660 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003661
3662 final long identity = Binder.clearCallingIdentity();
3663 try {
3664 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003665 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003666 return phone.getLine1Number();
3667 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003668 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003669 return null;
3670 }
3671 } finally {
3672 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003673 }
3674 }
3675
3676 /**
3677 * Returns the CDMA MIN.
3678 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003679 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003680 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003681 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3682 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003683
3684 final long identity = Binder.clearCallingIdentity();
3685 try {
3686 final Phone phone = getPhone(subId);
3687 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3688 return phone.getCdmaMin();
3689 } else {
3690 return null;
3691 }
3692 } finally {
3693 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003694 }
3695 }
3696
Hall Liud892bec2018-11-30 14:51:45 -08003697 @Override
3698 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3699 INumberVerificationCallback callback, String callingPackage) {
3700 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3701 != PERMISSION_GRANTED) {
3702 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3703 }
3704 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3705
3706 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3707 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003708 throw new SecurityException("Calling package must be configured in the device config: "
3709 + "calling package: " + callingPackage
3710 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003711 }
3712
3713 if (range == null) {
3714 throw new NullPointerException("Range must be non-null");
3715 }
3716
3717 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003718 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003719
3720 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3721 }
3722
Junda Liuca05d5d2014-08-14 22:36:34 -07003723 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003724 * Returns true if CDMA provisioning needs to run.
3725 */
3726 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003727 final long identity = Binder.clearCallingIdentity();
3728 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003729 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003730 } finally {
3731 Binder.restoreCallingIdentity(identity);
3732 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003733 }
3734
3735 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003736 * Sets the voice mail number of a given subId.
3737 */
3738 @Override
3739 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003740 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3741 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003742
3743 final long identity = Binder.clearCallingIdentity();
3744 try {
3745 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3746 new Pair<String, String>(alphaTag, number), new Integer(subId));
3747 return success;
3748 } finally {
3749 Binder.restoreCallingIdentity(identity);
3750 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003751 }
3752
Ta-wei Yen87c49842016-05-13 21:19:52 -07003753 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003754 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3755 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003756 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3757 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003758 if (!TextUtils.equals(callingPackage, systemDialer)) {
3759 throw new SecurityException("caller must be system dialer");
3760 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003761
3762 final long identity = Binder.clearCallingIdentity();
3763 try {
3764 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3765 if (phoneAccountHandle == null) {
3766 return null;
3767 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003768 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003769 } finally {
3770 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003771 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003772 }
3773
3774 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003775 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3776 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003777 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003778 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003779 mApp, subId, callingPackage, callingFeatureId,
3780 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003781 return null;
3782 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003783
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003784 final long identity = Binder.clearCallingIdentity();
3785 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003786 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003787 } finally {
3788 Binder.restoreCallingIdentity(identity);
3789 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003790 }
3791
3792 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003793 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3794 VisualVoicemailSmsFilterSettings settings) {
3795 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003796
3797 final long identity = Binder.clearCallingIdentity();
3798 try {
3799 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003800 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003801 } finally {
3802 Binder.restoreCallingIdentity(identity);
3803 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003804 }
3805
3806 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003807 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3808 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003809
3810 final long identity = Binder.clearCallingIdentity();
3811 try {
3812 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003813 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003814 } finally {
3815 Binder.restoreCallingIdentity(identity);
3816 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003817 }
3818
3819 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003820 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3821 String callingPackage, int subId) {
3822 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003823
3824 final long identity = Binder.clearCallingIdentity();
3825 try {
3826 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003827 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003828 } finally {
3829 Binder.restoreCallingIdentity(identity);
3830 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003831 }
3832
3833 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003834 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003835 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003836
3837 final long identity = Binder.clearCallingIdentity();
3838 try {
3839 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003840 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003841 } finally {
3842 Binder.restoreCallingIdentity(identity);
3843 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003844 }
3845
3846 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003847 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3848 String callingAttributionTag, int subId, String number, int port, String text,
3849 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003850 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003851 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003852 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003853 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003854 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3855 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003856 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003857
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003858 /**
fionaxu0152e512016-11-14 13:36:14 -08003859 * Sets the voice activation state of a given subId.
3860 */
3861 @Override
3862 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003863 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3864 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003865
3866 final long identity = Binder.clearCallingIdentity();
3867 try {
3868 final Phone phone = getPhone(subId);
3869 if (phone != null) {
3870 phone.setVoiceActivationState(activationState);
3871 } else {
3872 loge("setVoiceActivationState fails with invalid subId: " + subId);
3873 }
3874 } finally {
3875 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003876 }
3877 }
3878
3879 /**
3880 * Sets the data activation state of a given subId.
3881 */
3882 @Override
3883 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003884 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3885 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003886
3887 final long identity = Binder.clearCallingIdentity();
3888 try {
3889 final Phone phone = getPhone(subId);
3890 if (phone != null) {
3891 phone.setDataActivationState(activationState);
3892 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003893 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003894 }
3895 } finally {
3896 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003897 }
3898 }
3899
3900 /**
3901 * Returns the voice activation state of a given subId.
3902 */
3903 @Override
3904 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003905 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003906
fionaxu0152e512016-11-14 13:36:14 -08003907 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003908 final long identity = Binder.clearCallingIdentity();
3909 try {
3910 if (phone != null) {
3911 return phone.getVoiceActivationState();
3912 } else {
3913 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3914 }
3915 } finally {
3916 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003917 }
3918 }
3919
3920 /**
3921 * Returns the data activation state of a given subId.
3922 */
3923 @Override
3924 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003925 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003926
fionaxu0152e512016-11-14 13:36:14 -08003927 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003928 final long identity = Binder.clearCallingIdentity();
3929 try {
3930 if (phone != null) {
3931 return phone.getDataActivationState();
3932 } else {
3933 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3934 }
3935 } finally {
3936 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003937 }
3938 }
3939
3940 /**
Wink Saville36469e72014-06-11 15:17:00 -07003941 * Returns the unread count of voicemails for a subId
3942 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003943 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003944 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3945 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003946 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003947 mApp, subId, callingPackage, callingFeatureId,
3948 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003949 return 0;
3950 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003951 final long identity = Binder.clearCallingIdentity();
3952 try {
3953 final Phone phone = getPhone(subId);
3954 if (phone != null) {
3955 return phone.getVoiceMessageCount();
3956 } else {
3957 return 0;
3958 }
3959 } finally {
3960 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003961 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003962 }
3963
3964 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003965 * returns true, if the device is in a state where both voice and data
3966 * are supported simultaneously. This can change based on location or network condition.
3967 */
3968 @Override
3969 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003970 final long identity = Binder.clearCallingIdentity();
3971 try {
3972 final Phone phone = getPhone(subId);
3973 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3974 } finally {
3975 Binder.restoreCallingIdentity(identity);
3976 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003977 }
3978
3979 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003980 * Send the dialer code if called from the current default dialer or the caller has
3981 * carrier privilege.
3982 * @param inputCode The dialer code to send
3983 */
3984 @Override
3985 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003986 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003987 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003988 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3989 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003990 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003991 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003992 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003993 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003994
3995 final long identity = Binder.clearCallingIdentity();
3996 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003997 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003998 } finally {
3999 Binder.restoreCallingIdentity(identity);
4000 }
fionaxu235cc5e2017-03-06 22:25:57 -08004001 }
4002
Pengquan Menga1bb6272018-09-06 09:59:22 -07004003 @Override
4004 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004005 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07004006 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08004007 mApp, subId, "getNetworkSelectionMode");
4008 final long identity = Binder.clearCallingIdentity();
4009 try {
4010 if (!isActiveSubscription(subId)) {
4011 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4012 }
4013 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4014 } finally {
4015 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004016 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004017 }
4018
Brad Ebinger35c841c2018-10-01 10:40:55 -07004019 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004020 public boolean isInEmergencySmsMode() {
4021 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4022 final long identity = Binder.clearCallingIdentity();
4023 try {
4024 for (Phone phone : PhoneFactory.getPhones()) {
4025 if (phone.isInEmergencySmsMode()) {
4026 return true;
4027 }
4028 }
4029 } finally {
4030 Binder.restoreCallingIdentity(identity);
4031 }
4032 return false;
4033 }
4034
shilu366312e2019-12-17 09:28:10 -08004035 /**
4036 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4037 * @param subId The subscription to use to check the configuration.
4038 * @param c The callback that will be used to send the result.
4039 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004040 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004041 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4042 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004043 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004044 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08004045
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004046 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4047 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4048 "IMS not available on device.");
4049 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004050 final long token = Binder.clearCallingIdentity();
4051 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004052 int slotId = getSlotIndexOrException(subId);
4053 verifyImsMmTelConfiguredOrThrow(slotId);
4054 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004055 } catch (ImsException e) {
4056 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004057 } finally {
4058 Binder.restoreCallingIdentity(token);
4059 }
4060 }
4061
shilu366312e2019-12-17 09:28:10 -08004062 /**
4063 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4064 * @param subId The subscription to use to check the configuration.
4065 * @param c The callback that will be used to send the result.
4066 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004067 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004068 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004069 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004070 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004071 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4072 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4073 }
Meng Wangafbc5852019-09-19 17:37:13 -07004074 final long token = Binder.clearCallingIdentity();
4075 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004076 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4077 .removeRegistrationCallbackForSubscription(c, subId);
4078 } catch (ImsException e) {
4079 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4080 + "is inactive, ignoring unregister.");
4081 // If the subscription is no longer active, just return, since the callback
4082 // will already have been removed internally.
4083 } finally {
4084 Binder.restoreCallingIdentity(token);
4085 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004086 }
4087
Brad Ebingera34a6c22019-10-22 17:36:18 -07004088 /**
4089 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4090 */
4091 @Override
4092 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4093 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4094 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4095 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4096 "IMS not available on device.");
4097 }
4098 final long token = Binder.clearCallingIdentity();
4099 try {
4100 Phone phone = getPhone(subId);
4101 if (phone == null) {
4102 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4103 + subId + "'");
4104 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4105 }
4106 phone.getImsRegistrationState(regState -> {
4107 try {
4108 consumer.accept((regState == null)
4109 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4110 } catch (RemoteException e) {
4111 // Ignore if the remote process is no longer available to call back.
4112 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4113 }
4114 });
4115 } finally {
4116 Binder.restoreCallingIdentity(token);
4117 }
4118 }
4119
4120 /**
4121 * Get the transport type for the IMS service registration state.
4122 */
4123 @Override
4124 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004125 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004126 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004127 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4128 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4129 "IMS not available on device.");
4130 }
4131 final long token = Binder.clearCallingIdentity();
4132 try {
4133 Phone phone = getPhone(subId);
4134 if (phone == null) {
4135 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4136 + subId + "'");
4137 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4138 }
4139 phone.getImsRegistrationTech(regTech -> {
4140 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4141 int regTechConverted = (regTech == null)
4142 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4143 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4144 regTechConverted);
4145 try {
4146 consumer.accept(regTechConverted);
4147 } catch (RemoteException e) {
4148 // Ignore if the remote process is no longer available to call back.
4149 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4150 }
4151 });
4152 } finally {
4153 Binder.restoreCallingIdentity(token);
4154 }
4155 }
4156
shilu366312e2019-12-17 09:28:10 -08004157 /**
4158 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4159 * @param subId The subscription to use to check the configuration.
4160 * @param c The callback that will be used to send the result.
4161 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004162 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004163 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4164 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004165 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004166 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004167 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4168 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4169 "IMS not available on device.");
4170 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004171 final long token = Binder.clearCallingIdentity();
4172 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004173 int slotId = getSlotIndexOrException(subId);
4174 verifyImsMmTelConfiguredOrThrow(slotId);
4175 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004176 } catch (ImsException e) {
4177 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004178 } finally {
4179 Binder.restoreCallingIdentity(token);
4180 }
4181 }
4182
shilu366312e2019-12-17 09:28:10 -08004183 /**
4184 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4185 * @param subId The subscription to use to check the configuration.
4186 * @param c The callback that will be used to send the result.
4187 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004188 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004189 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004190 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004191 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004192 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4193 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4194 }
Meng Wangafbc5852019-09-19 17:37:13 -07004195
4196 final long token = Binder.clearCallingIdentity();
4197 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004198 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004199 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004200 } catch (ImsException e) {
4201 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4202 + "is inactive, ignoring unregister.");
4203 // If the subscription is no longer active, just return, since the callback
4204 // will already have been removed internally.
4205 } finally {
4206 Binder.restoreCallingIdentity(token);
4207 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004208 }
4209
4210 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004211 public boolean isCapable(int subId, int capability, int regTech) {
4212 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004213 final long token = Binder.clearCallingIdentity();
4214 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004215 int slotId = getSlotIndexOrException(subId);
4216 verifyImsMmTelConfiguredOrThrow(slotId);
4217 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004218 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004219 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4220 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004221 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004222 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4223 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004224 } finally {
4225 Binder.restoreCallingIdentity(token);
4226 }
4227 }
4228
4229 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004230 public boolean isAvailable(int subId, int capability, int regTech) {
4231 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004232 final long token = Binder.clearCallingIdentity();
4233 try {
4234 Phone phone = getPhone(subId);
4235 if (phone == null) return false;
4236 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004237 } catch (com.android.ims.ImsException e) {
4238 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4239 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004240 } finally {
4241 Binder.restoreCallingIdentity(token);
4242 }
4243 }
4244
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004245 /**
4246 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4247 * subscription.
4248 * @param subId The subscription to use to check the configuration.
4249 * @param callback The callback that will be used to send the result.
4250 * @param capability The MmTelFeature capability that will be used to send the result.
4251 * @param transportType The transport type of the MmTelFeature capability.
4252 */
4253 @Override
4254 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4255 int transportType) {
4256 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4257 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4258 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4259 "IMS not available on device.");
4260 }
4261 final long token = Binder.clearCallingIdentity();
4262 try {
4263 int slotId = getSlotIndex(subId);
4264 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4265 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4266 + subId + "'");
4267 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4268 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004269 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004270 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4271 transportType, aBoolean -> {
4272 try {
4273 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4274 } catch (RemoteException e) {
4275 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4276 + "running. Ignore");
4277 }
4278 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004279 } catch (ImsException e) {
4280 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004281 } finally {
4282 Binder.restoreCallingIdentity(token);
4283 }
4284 }
4285
shilu366312e2019-12-17 09:28:10 -08004286 /**
4287 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4288 * @param subId The subscription to use to check the configuration.
4289 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004290 @Override
4291 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004292 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004293 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004294
Brad Ebinger35c841c2018-10-01 10:40:55 -07004295 final long token = Binder.clearCallingIdentity();
4296 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004297 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004298 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004299 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004300 } catch (ImsException e) {
4301 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004302 } finally {
4303 Binder.restoreCallingIdentity(token);
4304 }
4305 }
4306
4307 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004308 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004309 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004310 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004311 final long identity = Binder.clearCallingIdentity();
4312 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004313 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004314 // This setting doesn't require an active ImsService connection, so do not verify. The
4315 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004316 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004317 } catch (ImsException e) {
4318 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004319 } finally {
4320 Binder.restoreCallingIdentity(identity);
4321 }
4322 }
4323
shilu366312e2019-12-17 09:28:10 -08004324 /**
4325 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4326 * @param subId The subscription to use to check the configuration.
4327 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004328 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004329 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004330 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004331 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004332 final long identity = Binder.clearCallingIdentity();
4333 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004334 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004335 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004336 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004337 } catch (ImsException e) {
4338 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004339 } finally {
4340 Binder.restoreCallingIdentity(identity);
4341 }
4342 }
4343
4344 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004345 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004346 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004347 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004348 final long identity = Binder.clearCallingIdentity();
4349 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004350 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004351 // This setting doesn't require an active ImsService connection, so do not verify. The
4352 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004353 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004354 } catch (ImsException e) {
4355 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004356 } finally {
4357 Binder.restoreCallingIdentity(identity);
4358 }
4359 }
4360
shilu366312e2019-12-17 09:28:10 -08004361 /**
4362 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4363 * @param subId The subscription to use to check the configuration.
4364 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004365 @Override
4366 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004367 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004368 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004369 final long identity = Binder.clearCallingIdentity();
4370 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004371 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004372 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004373 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004374 } catch (ImsException e) {
4375 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004376 } finally {
4377 Binder.restoreCallingIdentity(identity);
4378 }
4379 }
4380
4381 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004382 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004383 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004384 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004385 final long identity = Binder.clearCallingIdentity();
4386 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004387 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004388 // This setting doesn't require an active ImsService connection, so do not verify. The
4389 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004390 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004391 } catch (ImsException e) {
4392 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004393 } finally {
4394 Binder.restoreCallingIdentity(identity);
4395 }
4396 }
4397
shilu366312e2019-12-17 09:28:10 -08004398 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004399 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4400 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4401 * @param subId The subscription to use to check the configuration.
4402 */
4403 @Override
4404 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004405 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004406 mApp, subId, "isCrossSimCallingEnabledByUser");
4407 final long identity = Binder.clearCallingIdentity();
4408 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004409 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004410 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004411 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004412 } catch (ImsException e) {
4413 throw new ServiceSpecificException(e.getCode());
4414 } finally {
4415 Binder.restoreCallingIdentity(identity);
4416 }
4417 }
4418
4419 /**
4420 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4421 * Requires MODIFY_PHONE_STATE permission.
4422 * @param subId The subscription to use to check the configuration.
4423 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4424 * false otherwise
4425 */
4426 @Override
4427 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4428 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4429 "setCrossSimCallingEnabled");
4430 final long identity = Binder.clearCallingIdentity();
4431 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004432 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004433 // This setting doesn't require an active ImsService connection, so do not verify. The
4434 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004435 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004436 } catch (ImsException e) {
4437 throw new ServiceSpecificException(e.getCode());
4438 } finally {
4439 Binder.restoreCallingIdentity(identity);
4440 }
4441 }
4442
4443 /**
shilu366312e2019-12-17 09:28:10 -08004444 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4445 * @param subId The subscription to use to check the configuration.
4446 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004447 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004448
Brad Ebinger35c841c2018-10-01 10:40:55 -07004449 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004450 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004451 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004452 final long identity = Binder.clearCallingIdentity();
4453 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004454 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004455 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004456 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004457 } catch (ImsException e) {
4458 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004459 } finally {
4460 Binder.restoreCallingIdentity(identity);
4461 }
4462 }
4463
4464 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004465 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004466 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004467 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004468 final long identity = Binder.clearCallingIdentity();
4469 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004470 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004471 // This setting doesn't require an active ImsService connection, so do not verify. The
4472 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004473 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004474 } catch (ImsException e) {
4475 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004476 } finally {
4477 Binder.restoreCallingIdentity(identity);
4478 }
4479 }
4480
4481 @Override
4482 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4483 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4484 "setVoWiFiNonPersistent");
4485 final long identity = Binder.clearCallingIdentity();
4486 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004487 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004488 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004489 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004490 } catch (ImsException e) {
4491 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004492 } finally {
4493 Binder.restoreCallingIdentity(identity);
4494 }
4495 }
4496
shilu366312e2019-12-17 09:28:10 -08004497 /**
4498 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4499 * @param subId The subscription to use to check the configuration.
4500 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004501 @Override
4502 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004503 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004504 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004505 final long identity = Binder.clearCallingIdentity();
4506 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004507 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004508 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004509 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004510 } catch (ImsException e) {
4511 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004512 } finally {
4513 Binder.restoreCallingIdentity(identity);
4514 }
4515 }
4516
4517 @Override
4518 public void setVoWiFiModeSetting(int subId, int mode) {
4519 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4520 "setVoWiFiModeSetting");
4521 final long identity = Binder.clearCallingIdentity();
4522 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004523 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004524 // This setting doesn't require an active ImsService connection, so do not verify. The
4525 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004526 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004527 } catch (ImsException e) {
4528 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004529 } finally {
4530 Binder.restoreCallingIdentity(identity);
4531 }
4532 }
4533
4534 @Override
4535 public int getVoWiFiRoamingModeSetting(int subId) {
4536 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4537 final long identity = Binder.clearCallingIdentity();
4538 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004539 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004540 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004541 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004542 } catch (ImsException e) {
4543 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004544 } finally {
4545 Binder.restoreCallingIdentity(identity);
4546 }
4547 }
4548
4549 @Override
4550 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4551 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4552 "setVoWiFiRoamingModeSetting");
4553 final long identity = Binder.clearCallingIdentity();
4554 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004555 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004556 // This setting doesn't require an active ImsService connection, so do not verify. The
4557 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004558 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004559 } catch (ImsException e) {
4560 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004561 } finally {
4562 Binder.restoreCallingIdentity(identity);
4563 }
4564 }
4565
4566 @Override
4567 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4568 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4569 "setRttCapabilityEnabled");
4570 final long identity = Binder.clearCallingIdentity();
4571 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004572 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004573 // This setting doesn't require an active ImsService connection, so do not verify. The
4574 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004575 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004576 } catch (ImsException e) {
4577 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004578 } finally {
4579 Binder.restoreCallingIdentity(identity);
4580 }
4581 }
4582
shilu366312e2019-12-17 09:28:10 -08004583 /**
4584 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4585 * @param subId The subscription to use to check the configuration.
4586 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004587 @Override
4588 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004589 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004590 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004591 final long identity = Binder.clearCallingIdentity();
4592 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004593 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004594 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004595 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004596 } catch (ImsException e) {
4597 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004598 } finally {
4599 Binder.restoreCallingIdentity(identity);
4600 }
4601 }
4602
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004603 @Override
4604 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4605 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004606
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004607 final long identity = Binder.clearCallingIdentity();
4608 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004609 if (!isImsAvailableOnDevice()) {
4610 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4611 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004612 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004613 int slotId = getSlotIndexOrException(subId);
4614 verifyImsMmTelConfiguredOrThrow(slotId);
4615 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004616 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004617 } catch (ImsException e) {
4618 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004619 } finally {
4620 Binder.restoreCallingIdentity(identity);
4621 }
4622 }
4623
4624 @Override
4625 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4626 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004627
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004628 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004629 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4630 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4631 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004632 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004633 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004634 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004635 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004636 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4637 + "is inactive, ignoring unregister.");
4638 // If the subscription is no longer active, just return, since the callback will already
4639 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004640 } finally {
4641 Binder.restoreCallingIdentity(identity);
4642 }
4643 }
4644
joonhunshincffb7fc2021-11-28 07:32:01 +00004645 @Override
4646 public void registerFeatureProvisioningChangedCallback(int subId,
4647 IFeatureProvisioningCallback callback) {
4648 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4649 mApp, subId, "registerFeatureProvisioningChangedCallback");
4650
4651 final long identity = Binder.clearCallingIdentity();
4652 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4653 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4654 }
4655
4656 ImsProvisioningController.getInstance()
4657 .addFeatureProvisioningChangedCallback(subId, callback);
4658
4659 Binder.restoreCallingIdentity(identity);
4660 }
4661
4662 @Override
4663 public void unregisterFeatureProvisioningChangedCallback(int subId,
4664 IFeatureProvisioningCallback callback) {
4665 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4666 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4667
4668 final long identity = Binder.clearCallingIdentity();
4669 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4670 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4671 }
4672
4673 ImsProvisioningController.getInstance()
4674 .removeFeatureProvisioningChangedCallback(subId, callback);
4675
4676 Binder.restoreCallingIdentity(identity);
4677 }
allenwtsu99c623b2020-01-03 18:24:23 +08004678
4679 private void checkModifyPhoneStatePermission(int subId, String message) {
4680 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4681 message);
4682 }
4683
4684 private boolean isImsProvisioningRequired(int subId, int capability,
4685 boolean isMmtelCapability) {
4686 Phone phone = getPhone(subId);
4687 if (phone == null) {
4688 loge("phone instance null for subid " + subId);
4689 return false;
4690 }
4691 if (isMmtelCapability) {
4692 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4693 return false;
4694 }
4695 } else {
4696 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4697 return false;
4698 }
4699 }
4700 return true;
4701 }
4702
4703 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004704 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004705 boolean isProvisioned) {
4706 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4707
4708 final long identity = Binder.clearCallingIdentity();
4709 try {
joonhunshincffb7fc2021-11-28 07:32:01 +00004710 ImsProvisioningController.getInstance()
4711 .setRcsProvisioningStatusForCapability(subId, capability, tech, isProvisioned);
4712 return;
allenwtsu99c623b2020-01-03 18:24:23 +08004713 } finally {
4714 Binder.restoreCallingIdentity(identity);
4715 }
allenwtsu99c623b2020-01-03 18:24:23 +08004716 }
4717
4718
4719 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004720 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4721 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4722 mApp, subId, "getRcsProvisioningStatusForCapability");
4723
allenwtsu99c623b2020-01-03 18:24:23 +08004724 final long identity = Binder.clearCallingIdentity();
4725 try {
joonhunshincffb7fc2021-11-28 07:32:01 +00004726 return ImsProvisioningController.getInstance()
4727 .getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004728 } finally {
4729 Binder.restoreCallingIdentity(identity);
4730 }
4731 }
4732
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004733 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004734 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4735 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004736 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004737
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004738 final long identity = Binder.clearCallingIdentity();
4739 try {
joonhunshincffb7fc2021-11-28 07:32:01 +00004740 ImsProvisioningController.getInstance()
4741 .setImsProvisioningStatusForCapability(subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004742 } finally {
4743 Binder.restoreCallingIdentity(identity);
4744 }
4745 }
4746
4747 @Override
4748 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00004749 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4750 mApp, subId, "getProvisioningStatusForCapability");
4751
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004752 final long identity = Binder.clearCallingIdentity();
4753 try {
joonhunshincffb7fc2021-11-28 07:32:01 +00004754 return ImsProvisioningController.getInstance()
4755 .getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004756
4757 } finally {
4758 Binder.restoreCallingIdentity(identity);
4759 }
4760 }
4761
4762 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004763 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4764 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4765 mApp, subId, "isProvisioningRequiredForCapability");
4766
4767 final long identity = Binder.clearCallingIdentity();
4768 try {
4769 return ImsProvisioningController.getInstance()
4770 .isImsProvisioningRequiredForCapability(subId, capability, tech);
4771 } finally {
4772 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004773 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004774 }
4775
4776 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004777 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4778 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4779 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004780
joonhunshincffb7fc2021-11-28 07:32:01 +00004781 final long identity = Binder.clearCallingIdentity();
4782 try {
4783 return ImsProvisioningController.getInstance()
4784 .isRcsProvisioningRequiredForCapability(subId, capability, tech);
4785 } finally {
4786 Binder.restoreCallingIdentity(identity);
4787 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004788 }
4789
4790 private static String getMmTelProvisioningKey(int subId, int tech) {
4791 // resulting key is provision_ims_mmtel_{subId}_{tech}
4792 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4793 }
4794
4795 /**
4796 * Query CarrierConfig to see if the specified capability requires provisioning for the
4797 * carrier associated with the subscription id.
4798 */
4799 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4800 int capability) {
4801 CarrierConfigManager configManager = new CarrierConfigManager(context);
4802 PersistableBundle c = configManager.getConfigForSubId(subId);
4803 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004804 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004805 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4806 false);
4807 boolean requireVoiceVtProvisioning = c.getBoolean(
4808 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4809
4810 // First check to make sure that the capability requires provisioning.
4811 switch (capability) {
4812 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4813 // intentional fallthrough
4814 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4815 if (requireVoiceVtProvisioning) {
4816 // Voice and Video requires provisioning
4817 return true;
4818 }
4819 break;
4820 }
4821 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4822 if (requireUtProvisioning) {
4823 // UT requires provisioning
4824 return true;
4825 }
4826 break;
4827 }
4828 }
4829 return false;
4830 }
4831
allenwtsu99c623b2020-01-03 18:24:23 +08004832 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4833 int capability) {
4834 CarrierConfigManager configManager = new CarrierConfigManager(context);
4835 PersistableBundle c = configManager.getConfigForSubId(subId);
4836
4837 boolean requireRcsProvisioning = c.getBoolean(
4838 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4839
4840 // First check to make sure that the capability requires provisioning.
4841 switch (capability) {
4842 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4843 // intentional fallthrough
4844 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4845 if (requireRcsProvisioning) {
4846 // OPTION or PRESENCE requires provisioning
4847 return true;
4848 }
4849 break;
4850 }
4851 }
4852 return false;
4853 }
4854
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004855 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004856 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004857 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4858 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4859 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004860 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4861 mApp, subId, "getImsProvisioningInt");
4862
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004863 final long identity = Binder.clearCallingIdentity();
4864 try {
4865 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004866 int slotId = getSlotIndex(subId);
4867 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4868 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4869 + subId + "' for key:" + key);
4870 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4871 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004872
4873 int retVal = ImsProvisioningController.getInstance().getProvisioningValue(subId, key);
4874 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4875 return retVal;
4876 }
4877
calvinpanb5a34062021-02-08 19:59:36 +08004878 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004879 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004880 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4881 + subId + "' for key:" + key);
4882 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004883 } finally {
4884 Binder.restoreCallingIdentity(identity);
4885 }
4886 }
4887
4888 @Override
4889 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004890 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4891 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4892 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004893 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4894 mApp, subId, "getImsProvisioningString");
4895
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004896 final long identity = Binder.clearCallingIdentity();
4897 try {
4898 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004899 int slotId = getSlotIndex(subId);
4900 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4901 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4902 + subId + "' for key:" + key);
4903 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4904 }
calvinpanb5a34062021-02-08 19:59:36 +08004905 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004906 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004907 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4908 + subId + "' for key:" + key);
4909 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004910 } finally {
4911 Binder.restoreCallingIdentity(identity);
4912 }
4913 }
4914
4915 @Override
4916 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004917 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4918 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4919 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004920 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4921 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00004922
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004923 final long identity = Binder.clearCallingIdentity();
4924 try {
4925 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004926 int slotId = getSlotIndex(subId);
4927 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4928 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4929 + subId + "' for key:" + key);
4930 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4931 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004932
4933 int retVal = ImsProvisioningController.getInstance()
4934 .setProvisioningValue(subId, key, value);
4935 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4936 return retVal;
4937 }
4938
calvinpanb5a34062021-02-08 19:59:36 +08004939 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4940 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004941 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004942 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004943 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004944 } finally {
4945 Binder.restoreCallingIdentity(identity);
4946 }
4947 }
4948
4949 @Override
4950 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004951 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4952 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4953 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004954 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4955 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004956 final long identity = Binder.clearCallingIdentity();
4957 try {
4958 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004959 int slotId = getSlotIndex(subId);
4960 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4961 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4962 + subId + "' for key:" + key);
4963 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4964 }
calvinpanb5a34062021-02-08 19:59:36 +08004965 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4966 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004967 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004968 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004969 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004970 } finally {
4971 Binder.restoreCallingIdentity(identity);
4972 }
4973 }
4974
Brad Ebinger919631e2021-06-02 17:46:35 -07004975 /**
4976 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4977 * for the given slot ID or no ImsResolver instance has been created.
4978 * @param slotId The slot ID that the IMS service is created for.
4979 * @throws ImsException If there is no ImsService configured for this slot.
4980 */
4981 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4982 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4983 ImsFeature.FEATURE_MMTEL)) {
4984 throw new ImsException("This subscription does not support MMTEL over IMS",
4985 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4986 }
4987 }
4988
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004989 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004990 int slotId = SubscriptionManager.getSlotIndex(subId);
4991 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004992 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4993 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004994 }
4995 return slotId;
4996 }
4997
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004998 private int getSlotIndex(int subId) {
4999 int slotId = SubscriptionManager.getSlotIndex(subId);
5000 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5001 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5002 }
5003 return slotId;
5004 }
5005
Wink Saville36469e72014-06-11 15:17:00 -07005006 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005007 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005008 */
5009 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005010 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5011 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005012 try {
5013 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5014 } catch (SecurityException se) {
5015 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5016 throw new SecurityException("Package " + callingPackage + " does not belong to "
5017 + Binder.getCallingUid());
5018 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005019 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005020 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005021 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005022 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005023 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005024 mApp, subId, callingPackage, callingFeatureId,
5025 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005026 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5027 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005028
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005029 final long identity = Binder.clearCallingIdentity();
5030 try {
5031 final Phone phone = getPhone(subId);
5032 if (phone != null) {
5033 return phone.getServiceState().getDataNetworkType();
5034 } else {
5035 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5036 }
5037 } finally {
5038 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005039 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005040 }
5041
5042 /**
5043 * Returns the data network type
5044 */
5045 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005046 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005047 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5048 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005049 }
5050
5051 /**
5052 * Returns the data network type for a subId
5053 */
5054 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005055 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5056 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005057 String functionName = "getDataNetworkTypeForSubscriber";
5058 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5059 mApp, functionName)) {
5060 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5061 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5062 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5063 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005064 }
5065
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005066 final long identity = Binder.clearCallingIdentity();
5067 try {
5068 final Phone phone = getPhone(subId);
5069 if (phone != null) {
5070 return phone.getServiceState().getDataNetworkType();
5071 } else {
5072 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5073 }
5074 } finally {
5075 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005076 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005077 }
5078
5079 /**
Wink Saville36469e72014-06-11 15:17:00 -07005080 * Returns the Voice network type for a subId
5081 */
5082 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005083 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5084 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005085 String functionName = "getVoiceNetworkTypeForSubscriber";
5086 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5087 mApp, functionName)) {
5088 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5089 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5090 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5091 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005092 }
5093
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005094 final long identity = Binder.clearCallingIdentity();
5095 try {
5096 final Phone phone = getPhone(subId);
5097 if (phone != null) {
5098 return phone.getServiceState().getVoiceNetworkType();
5099 } else {
5100 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5101 }
5102 } finally {
5103 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005104 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005105 }
5106
5107 /**
5108 * @return true if a ICC card is present
5109 */
5110 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005111 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005112 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5113 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005114 }
5115
5116 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005117 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005118 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005119 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005120 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005121 final long identity = Binder.clearCallingIdentity();
5122 try {
5123 final Phone phone = PhoneFactory.getPhone(slotIndex);
5124 if (phone != null) {
5125 return phone.getIccCard().hasIccCard();
5126 } else {
5127 return false;
5128 }
5129 } finally {
5130 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005131 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005132 }
5133
5134 /**
5135 * Return if the current radio is LTE on CDMA. This
5136 * is a tri-state return value as for a period of time
5137 * the mode may be unknown.
5138 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005139 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005140 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005141 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005142 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005143 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005144 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5145 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5146 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005147 }
5148
Sanket Padawe356d7632015-06-22 14:03:32 -07005149 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005150 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5151 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005152 try {
5153 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5154 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005155 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5156 }
5157
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005158 final long identity = Binder.clearCallingIdentity();
5159 try {
5160 final Phone phone = getPhone(subId);
5161 if (phone == null) {
5162 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5163 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005164 return TelephonyProperties.lte_on_cdma_device()
5165 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005166 }
5167 } finally {
5168 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005169 }
Wink Saville36469e72014-06-11 15:17:00 -07005170 }
5171
Wink Saville36469e72014-06-11 15:17:00 -07005172 /**
5173 * {@hide}
5174 * Returns Default subId, 0 in the case of single standby.
5175 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005176 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005177 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005178 }
5179
Shishir Agrawala9f32182016-04-12 12:00:16 -07005180 private int getSlotForDefaultSubscription() {
5181 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5182 }
5183
Wink Savilleb564aae2014-10-23 10:18:09 -07005184 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005185 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005186 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005187
Pengquan Menge92a50d2018-09-21 15:54:48 -07005188 private boolean isActiveSubscription(int subId) {
5189 return mSubscriptionController.isActiveSubId(subId);
5190 }
5191
Ihab Awadf2177b72013-11-25 13:33:23 -08005192 /**
5193 * @see android.telephony.TelephonyManager.WifiCallingChoices
5194 */
5195 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005196 final long identity = Binder.clearCallingIdentity();
5197 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005198 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005199 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5200 getWhenToMakeWifiCallsDefaultPreference());
5201 } finally {
5202 Binder.restoreCallingIdentity(identity);
5203 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005204 }
5205
5206 /**
5207 * @see android.telephony.TelephonyManager.WifiCallingChoices
5208 */
5209 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005210 final long identity = Binder.clearCallingIdentity();
5211 try {
5212 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005213 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005214 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5215 } finally {
5216 Binder.restoreCallingIdentity(identity);
5217 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005218 }
5219
Sailesh Nepald1e68152013-12-12 19:08:02 -08005220 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005221 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005222 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005223 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005224
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005225 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5226 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5227 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005228 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005229 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5230 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005231 }
5232 return PhoneFactory.getPhone(phoneId);
5233 }
5234
Shishir Agrawal566b7612013-10-28 14:41:00 -07005235 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005236 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005237 @NonNull IccLogicalChannelRequest request) {
5238 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5239 /*message=*/ "iccOpenLogicalChannel");
5240
5241 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5242 // Verify that the callingPackage in the request belongs to the calling UID
5243 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5244
5245 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005246 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005247
Rambo Wanga1782702021-11-10 20:15:19 -08005248 private Phone getPhoneFromValidIccLogicalChannelRequest(
5249 @NonNull IccLogicalChannelRequest request, String message) {
5250 Phone phone;
5251 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5252 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5253 mApp, request.subId, message);
5254 phone = getPhoneFromSubId(request.subId);
5255 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5256 enforceModifyPermission();
5257 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5258 } else {
5259 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005260 }
Rambo Wanga1782702021-11-10 20:15:19 -08005261 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005262 }
5263
5264 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005265 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005266 final long identity = Binder.clearCallingIdentity();
5267 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005268 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005269 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005270 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5271 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005272 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5273 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005274 loge("The calling package is not allowed to access ISD-R.");
5275 throw new SecurityException(
5276 "The calling package is not allowed to access ISD-R.");
5277 }
Derek Tan740e1672017-06-27 14:56:27 -07005278 }
Derek Tan740e1672017-06-27 14:56:27 -07005279
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005280 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005281 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5282 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005283 return response;
5284 } finally {
5285 Binder.restoreCallingIdentity(identity);
5286 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005287 }
5288
5289 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005290 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5291 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5292 /*message=*/"iccCloseLogicalChannel");
5293
5294 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5295
5296 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005297 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005298
Rambo Wanga1782702021-11-10 20:15:19 -08005299 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5300 IccLogicalChannelRequest request) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005301 final long identity = Binder.clearCallingIdentity();
5302 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005303 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005304 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005305 }
Chen Xue9d737e2022-01-01 23:41:31 -08005306 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005307 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005308 Boolean success = false;
5309 if (result instanceof RuntimeException) {
5310 // if there is an exception returned, throw from the binder thread here.
5311 throw (RuntimeException) result;
5312 } else if (result instanceof Boolean) {
5313 success = (Boolean) result;
5314 } else {
5315 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5316 }
Rambo Wanga1782702021-11-10 20:15:19 -08005317 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005318 return success;
5319 } finally {
5320 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005321 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005322 }
5323
5324 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005325 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005326 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005327 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5328 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005329 if (DBG) {
5330 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5331 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5332 + p3 + " data=" + data);
5333 }
5334 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5335 command, p1, p2, p3, data);
5336 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005337
Jordan Liu4c733742019-02-28 12:03:40 -08005338 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005339 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5340 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005341 enforceModifyPermission();
5342 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005343 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5344 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5345 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005346 }
5347 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005348 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5349 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005350 }
5351
5352 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5353 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005354 final long identity = Binder.clearCallingIdentity();
5355 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005356 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005357 return "";
5358 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005359
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005360 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005361 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5362 null /* workSource */);
5363 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005364
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005365 // Append the returned status code to the end of the response payload.
5366 String s = Integer.toHexString(
5367 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5368 if (response.payload != null) {
5369 s = IccUtils.bytesToHexString(response.payload) + s;
5370 }
5371 return s;
5372 } finally {
5373 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005374 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005375 }
Jake Hambye994d462014-02-03 13:10:13 -08005376
Evan Charltonc66da362014-05-16 14:06:40 -07005377 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005378 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5379 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005380 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5381 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005382 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005383 if (DBG) {
5384 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5385 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5386 }
5387 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5388 cla, command, p1, p2, p3, data);
5389 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005390
Jordan Liu4c733742019-02-28 12:03:40 -08005391 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005392 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5393 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005394 enforceModifyPermission();
5395 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5396 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005397 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5398 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5399 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005400 }
5401
5402 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005403 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5404 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005405 }
5406
5407 // open APDU basic channel assuming the caller has sufficient permissions
5408 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5409 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005410 final long identity = Binder.clearCallingIdentity();
5411 try {
5412 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5413 && TextUtils.equals(ISDR_AID, data)) {
5414 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005415 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5416 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005417 if (bestComponent == null
5418 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5419 loge("The calling package is not allowed to select ISD-R.");
5420 throw new SecurityException(
5421 "The calling package is not allowed to select ISD-R.");
5422 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005423 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005424
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005425 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005426 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5427 null /* workSource */);
5428 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005429
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005430 // Append the returned status code to the end of the response payload.
5431 String s = Integer.toHexString(
5432 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5433 if (response.payload != null) {
5434 s = IccUtils.bytesToHexString(response.payload) + s;
5435 }
5436 return s;
5437 } finally {
5438 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005439 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005440 }
5441
5442 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005443 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005444 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005445 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5446 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005447
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005448 final long identity = Binder.clearCallingIdentity();
5449 try {
5450 if (DBG) {
5451 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5452 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5453 }
5454
5455 IccIoResult response =
5456 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5457 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5458 subId);
5459
5460 if (DBG) {
5461 log("Exchange SIM_IO [R]" + response);
5462 }
5463
5464 byte[] result = null;
5465 int length = 2;
5466 if (response.payload != null) {
5467 length = 2 + response.payload.length;
5468 result = new byte[length];
5469 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5470 } else {
5471 result = new byte[length];
5472 }
5473
5474 result[length - 1] = (byte) response.sw2;
5475 result[length - 2] = (byte) response.sw1;
5476 return result;
5477 } finally {
5478 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005479 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005480 }
5481
Nathan Haroldb3014052017-01-25 15:57:32 -08005482 /**
5483 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5484 * on a particular subscription
5485 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005486 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5487 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005488 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005489 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005490 return null;
5491 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005492
5493 final long identity = Binder.clearCallingIdentity();
5494 try {
5495 if (appType != TelephonyManager.APPTYPE_USIM
5496 && appType != TelephonyManager.APPTYPE_SIM) {
5497 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5498 return null;
5499 }
5500 Object response = sendRequest(
5501 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5502 if (response instanceof String[]) {
5503 return (String[]) response;
5504 }
yincheng zhao2737e882019-09-06 17:06:54 -07005505 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005506 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005507 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005508 } finally {
5509 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005510 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005511 }
5512
yincheng zhao2737e882019-09-06 17:06:54 -07005513 /**
5514 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5515 * subscription.
5516 *
5517 * @param subId the id of the subscription.
5518 * @param appType the uicc app type, must be USIM or SIM.
5519 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5520 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005521 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005522 * @return number of fplmns that is successfully written to the SIM.
5523 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005524 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5525 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005526 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5527 mApp, subId, "setForbiddenPlmns");
5528
yincheng zhao2737e882019-09-06 17:06:54 -07005529 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5530 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5531 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5532 }
5533 if (fplmns == null) {
5534 throw new IllegalArgumentException("Fplmn List provided is null");
5535 }
5536 for (String fplmn : fplmns) {
5537 if (!CellIdentity.isValidPlmn(fplmn)) {
5538 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5539 }
5540 }
5541 final long identity = Binder.clearCallingIdentity();
5542 try {
5543 Object response = sendRequest(
5544 CMD_SET_FORBIDDEN_PLMNS,
5545 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5546 subId);
5547 return (int) response;
5548 } finally {
5549 Binder.restoreCallingIdentity(identity);
5550 }
5551 }
5552
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005553 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005554 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005555 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5556 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005557
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005558 final long identity = Binder.clearCallingIdentity();
5559 try {
5560 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5561 if (response.payload == null) {
5562 return "";
5563 }
Evan Charltonc66da362014-05-16 14:06:40 -07005564
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005565 // Append the returned status code to the end of the response payload.
5566 String s = Integer.toHexString(
5567 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5568 s = IccUtils.bytesToHexString(response.payload) + s;
5569 return s;
5570 } finally {
5571 Binder.restoreCallingIdentity(identity);
5572 }
Evan Charltonc66da362014-05-16 14:06:40 -07005573 }
5574
Jake Hambye994d462014-02-03 13:10:13 -08005575 /**
5576 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5577 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5578 *
5579 * @param itemID the ID of the item to read
5580 * @return the NV item as a String, or null on error.
5581 */
5582 @Override
5583 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005584 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005585 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5586 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005587
5588 final long identity = Binder.clearCallingIdentity();
5589 try {
5590 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005591 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005592 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5593 return value;
5594 } finally {
5595 Binder.restoreCallingIdentity(identity);
5596 }
Jake Hambye994d462014-02-03 13:10:13 -08005597 }
5598
5599 /**
5600 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5601 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5602 *
5603 * @param itemID the ID of the item to read
5604 * @param itemValue the value to write, as a String
5605 * @return true on success; false on any failure
5606 */
5607 @Override
5608 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005609 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005610 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5611 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005612
5613 final long identity = Binder.clearCallingIdentity();
5614 try {
5615 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5616 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005617 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005618 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5619 return success;
5620 } finally {
5621 Binder.restoreCallingIdentity(identity);
5622 }
Jake Hambye994d462014-02-03 13:10:13 -08005623 }
5624
5625 /**
5626 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5627 * Used for device configuration by some CDMA operators.
5628 *
5629 * @param preferredRoamingList byte array containing the new PRL
5630 * @return true on success; false on any failure
5631 */
5632 @Override
5633 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005634 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5635 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005636
5637 final long identity = Binder.clearCallingIdentity();
5638 try {
5639 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5640 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5641 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5642 return success;
5643 } finally {
5644 Binder.restoreCallingIdentity(identity);
5645 }
Jake Hambye994d462014-02-03 13:10:13 -08005646 }
5647
5648 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005649 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005650 * Used for device configuration by some CDMA operators.
5651 *
chen xu6dac5ab2018-10-26 17:39:23 -07005652 * @param slotIndex - device slot.
5653 *
Jake Hambye994d462014-02-03 13:10:13 -08005654 * @return true on success; false on any failure
5655 */
5656 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005657 public boolean resetModemConfig(int slotIndex) {
5658 Phone phone = PhoneFactory.getPhone(slotIndex);
5659 if (phone != null) {
5660 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5661 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005662
chen xu6dac5ab2018-10-26 17:39:23 -07005663 final long identity = Binder.clearCallingIdentity();
5664 try {
5665 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5666 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5667 return success;
5668 } finally {
5669 Binder.restoreCallingIdentity(identity);
5670 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005671 }
chen xu6dac5ab2018-10-26 17:39:23 -07005672 return false;
5673 }
5674
5675 /**
5676 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5677 *
5678 * @param slotIndex - device slot.
5679 *
5680 * @return true on success; false on any failure
5681 */
5682 @Override
5683 public boolean rebootModem(int slotIndex) {
5684 Phone phone = PhoneFactory.getPhone(slotIndex);
5685 if (phone != null) {
5686 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5687 mApp, phone.getSubId(), "rebootModem");
5688
5689 final long identity = Binder.clearCallingIdentity();
5690 try {
5691 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5692 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5693 return success;
5694 } finally {
5695 Binder.restoreCallingIdentity(identity);
5696 }
5697 }
5698 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005699 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005700
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005701 public String[] getPcscfAddress(String apnType, String callingPackage,
5702 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005703 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005704 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5705 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005706 return new String[0];
5707 }
5708
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005709 final long identity = Binder.clearCallingIdentity();
5710 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005711 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005712 } finally {
5713 Binder.restoreCallingIdentity(identity);
5714 }
Wink Saville36469e72014-06-11 15:17:00 -07005715 }
5716
Brad Ebinger51f743a2017-01-23 13:50:20 -08005717 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005718 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5719 * {@link #disableIms(int)}.
5720 * @param slotIndex device slot.
5721 */
5722 public void resetIms(int slotIndex) {
5723 enforceModifyPermission();
5724
5725 final long identity = Binder.clearCallingIdentity();
5726 try {
5727 if (mImsResolver == null) {
5728 // may happen if the does not support IMS.
5729 return;
5730 }
5731 mImsResolver.disableIms(slotIndex);
5732 mImsResolver.enableIms(slotIndex);
5733 } finally {
5734 Binder.restoreCallingIdentity(identity);
5735 }
5736 }
5737
5738 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005739 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5740 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005741 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005742 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005743 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005744
5745 final long identity = Binder.clearCallingIdentity();
5746 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005747 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005748 // may happen if the device does not support IMS.
5749 return;
5750 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005751 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005752 } finally {
5753 Binder.restoreCallingIdentity(identity);
5754 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005755 }
5756
5757 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005758 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5759 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005760 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005761 public void disableIms(int slotId) {
5762 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005763
5764 final long identity = Binder.clearCallingIdentity();
5765 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005766 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005767 // may happen if the device does not support IMS.
5768 return;
5769 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005770 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005771 } finally {
5772 Binder.restoreCallingIdentity(identity);
5773 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005774 }
5775
5776 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005777 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5778 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005779 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005780 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005781 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005782 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005783
5784 final long identity = Binder.clearCallingIdentity();
5785 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005786 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005787 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5788 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005789 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005790 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005791 } finally {
5792 Binder.restoreCallingIdentity(identity);
5793 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005794 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005795 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005796 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5797 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005798 @Override
5799 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005800 enforceModifyPermission();
5801
5802 final long identity = Binder.clearCallingIdentity();
5803 try {
5804 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005805 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005806 } finally {
5807 Binder.restoreCallingIdentity(identity);
5808 }
5809 }
5810
5811 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005812 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005813 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005814 */
5815 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5816 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005817
5818 final long identity = Binder.clearCallingIdentity();
5819 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005820 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005821 // may happen if the device does not support IMS.
5822 return null;
5823 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005824 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005825 } finally {
5826 Binder.restoreCallingIdentity(identity);
5827 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005828 }
5829
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005830 /**
5831 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005832 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005833 */
5834 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5835 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005836
5837 final long identity = Binder.clearCallingIdentity();
5838 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005839 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005840 // may happen if the device does not support IMS.
5841 return null;
5842 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005843 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005844 } finally {
5845 Binder.restoreCallingIdentity(identity);
5846 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005847 }
5848
Brad Ebinger884c07b2018-02-15 16:17:40 -08005849 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005850 * Sets the ImsService Package Name that Telephony will bind to.
5851 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005852 * @param slotIndex the slot ID that the ImsService should bind for.
5853 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005854 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005855 * @param featureTypes An integer array of feature types associated with a packageName.
5856 * @param packageName The name of the package that the current configuration will be replaced
5857 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005858 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005859 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005860 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5861 int[] featureTypes, String packageName) {
5862 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5863 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005864 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5865 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005866 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005867
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005868 final long identity = Binder.clearCallingIdentity();
5869 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005870 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005871 // may happen if the device does not support IMS.
5872 return false;
5873 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005874 Map<Integer, String> featureConfig = new HashMap<>();
5875 for (int featureType : featureTypes) {
5876 featureConfig.put(featureType, packageName);
5877 }
5878 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5879 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005880 } finally {
5881 Binder.restoreCallingIdentity(identity);
5882 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005883 }
5884
5885 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005886 * Clears any carrier ImsService overrides for the slot index specified that were previously
5887 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5888 *
5889 * This should only be used for testing.
5890 *
5891 * @param slotIndex the slot ID that the ImsService should bind for.
5892 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5893 */
5894 @Override
5895 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5896 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5897 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5898 "clearCarrierImsServiceOverride");
5899 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5900 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5901 "clearCarrierImsServiceOverride");
5902
5903 final long identity = Binder.clearCallingIdentity();
5904 try {
5905 if (mImsResolver == null) {
5906 // may happen if the device does not support IMS.
5907 return false;
5908 }
5909 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5910 } finally {
5911 Binder.restoreCallingIdentity(identity);
5912 }
5913 }
5914
5915 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005916 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005917 *
5918 * @param slotId The slot that the ImsService is associated with.
5919 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5920 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005921 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005922 * @return the package name of the ImsService configuration.
5923 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005924 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5925 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005926 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005927 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005928 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005929 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5930 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005931
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005932 final long identity = Binder.clearCallingIdentity();
5933 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005934 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005935 // may happen if the device does not support IMS.
5936 return "";
5937 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005938 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005939 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5940 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005941 } finally {
5942 Binder.restoreCallingIdentity(identity);
5943 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005944 }
5945
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005946 /**
5947 * Get the MmTelFeature state associated with the requested subscription id.
5948 * @param subId The subscription that the MmTelFeature is associated with.
5949 * @param callback A callback with an integer containing the
5950 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5951 */
5952 @Override
5953 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5954 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5955 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5956 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5957 "IMS not available on device.");
5958 }
5959 final long token = Binder.clearCallingIdentity();
5960 try {
5961 int slotId = getSlotIndex(subId);
5962 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5963 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5964 + subId + "'");
5965 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5966 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005967 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005968 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5969 try {
5970 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5971 } catch (RemoteException e) {
5972 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5973 + "Ignore");
5974 }
5975 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005976 } catch (ImsException e) {
5977 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005978 } finally {
5979 Binder.restoreCallingIdentity(token);
5980 }
5981 }
5982
Daniel Brightbb5840b2021-01-12 15:48:18 -08005983 /**
5984 * Sets the ims registration state on all valid {@link Phone}s.
5985 */
5986 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005987 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005988
5989 final long identity = Binder.clearCallingIdentity();
5990 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005991 // NOTE: Before S, this method only set the default phone.
5992 for (final Phone phone : PhoneFactory.getPhones()) {
5993 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5994 phone.setImsRegistrationState(registered);
5995 }
5996 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005997 } finally {
5998 Binder.restoreCallingIdentity(identity);
5999 }
Wink Saville36469e72014-06-11 15:17:00 -07006000 }
6001
6002 /**
Stuart Scott54788802015-03-30 13:18:01 -07006003 * Set the network selection mode to automatic.
6004 *
6005 */
6006 @Override
6007 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006008 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6009 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006010
6011 final long identity = Binder.clearCallingIdentity();
6012 try {
shilufc958392020-01-20 11:36:01 -08006013 if (!isActiveSubscription(subId)) {
6014 return;
6015 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006016 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006017 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6018 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006019 } finally {
6020 Binder.restoreCallingIdentity(identity);
6021 }
Stuart Scott54788802015-03-30 13:18:01 -07006022 }
6023
Jack Yud10cdd42020-09-28 20:28:01 -07006024 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006025 * Ask the radio to connect to the input network and change selection mode to manual.
6026 *
6027 * @param subId the id of the subscription.
6028 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6029 * the operator to attach to.
6030 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6031 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6032 * normal network selection next time.
6033 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006034 */
6035 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006036 public boolean setNetworkSelectionModeManual(
6037 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006038 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6039 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006040
6041 if (!isActiveSubscription(subId)) {
6042 return false;
6043 }
6044
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006045 final long identity = Binder.clearCallingIdentity();
6046 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006047 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006048 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006049 if (DBG) {
6050 log("setNetworkSelectionModeManual: subId: " + subId
6051 + " operator: " + operatorInfo);
6052 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006053 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6054 } finally {
6055 Binder.restoreCallingIdentity(identity);
6056 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006057 }
shilu84f6e8b2019-12-19 13:58:01 -08006058 /**
6059 * Get the manual network selection
6060 *
6061 * @param subId the id of the subscription.
6062 *
6063 * @return the previously saved user selected PLMN
6064 */
6065 @Override
6066 public String getManualNetworkSelectionPlmn(int subId) {
6067 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006068 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006069 mApp, subId, "getManualNetworkSelectionPlmn");
6070
6071 final long identity = Binder.clearCallingIdentity();
6072 try {
6073 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006074 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006075 }
6076
6077 final Phone phone = getPhone(subId);
6078 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006079 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006080 }
6081 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6082 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6083 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6084 } finally {
6085 Binder.restoreCallingIdentity(identity);
6086 }
6087 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006088
6089 /**
6090 * Scans for available networks.
6091 */
6092 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006093 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6094 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006095 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6096 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006097 LocationAccessPolicy.LocationPermissionResult locationResult =
6098 LocationAccessPolicy.checkLocationPermission(mApp,
6099 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6100 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006101 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006102 .setCallingPid(Binder.getCallingPid())
6103 .setCallingUid(Binder.getCallingUid())
6104 .setMethod("getCellNetworkScanResults")
6105 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006106 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6107 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006108 .build());
6109 switch (locationResult) {
6110 case DENIED_HARD:
6111 throw new SecurityException("Not allowed to access scan results -- location");
6112 case DENIED_SOFT:
6113 return null;
6114 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006115
Pengquan Menga1bb6272018-09-06 09:59:22 -07006116 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006117 try {
6118 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006119 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006120 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006121 } finally {
6122 Binder.restoreCallingIdentity(identity);
6123 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006124 }
6125
6126 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006127 * Get the call forwarding info, given the call forwarding reason.
6128 */
6129 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006130 public void getCallForwarding(int subId, int callForwardingReason,
6131 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006132 enforceReadPrivilegedPermission("getCallForwarding");
6133 long identity = Binder.clearCallingIdentity();
6134 try {
6135 if (DBG) {
6136 log("getCallForwarding: subId " + subId
6137 + " callForwardingReason" + callForwardingReason);
6138 }
Hall Liu27d24262020-09-18 19:04:59 -07006139
6140 Phone phone = getPhone(subId);
6141 if (phone == null) {
6142 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006143 callback.onError(
6144 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006145 } catch (RemoteException e) {
6146 // ignore
6147 }
6148 return;
6149 }
6150
6151 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6152 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6153 @Override
6154 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6155 try {
6156 callback.onCallForwardingInfoAvailable(info);
6157 } catch (RemoteException e) {
6158 // ignore
6159 }
6160 }
6161
6162 @Override
6163 public void onError(int error) {
6164 try {
6165 callback.onError(error);
6166 } catch (RemoteException e) {
6167 // ignore
6168 }
6169 }
6170 });
6171 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006172 } finally {
6173 Binder.restoreCallingIdentity(identity);
6174 }
6175 }
6176
6177 /**
6178 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6179 * reason, the number to forward, and the timeout before the forwarding is attempted.
6180 */
6181 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006182 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6183 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006184 enforceModifyPermission();
6185 long identity = Binder.clearCallingIdentity();
6186 try {
6187 if (DBG) {
6188 log("setCallForwarding: subId " + subId
6189 + " callForwardingInfo" + callForwardingInfo);
6190 }
Hall Liu27d24262020-09-18 19:04:59 -07006191
6192 Phone phone = getPhone(subId);
6193 if (phone == null) {
6194 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006195 callback.accept(
6196 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006197 } catch (RemoteException e) {
6198 // ignore
6199 }
6200 return;
6201 }
6202
6203 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6204 FunctionalUtils.ignoreRemoteException(callback::accept));
6205
6206 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006207 } finally {
6208 Binder.restoreCallingIdentity(identity);
6209 }
6210 }
6211
6212 /**
Hall Liu27d24262020-09-18 19:04:59 -07006213 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006214 */
6215 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006216 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006217 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006218 long identity = Binder.clearCallingIdentity();
6219 try {
Hall Liu27d24262020-09-18 19:04:59 -07006220 Phone phone = getPhone(subId);
6221 if (phone == null) {
6222 try {
6223 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6224 } catch (RemoteException e) {
6225 // ignore
6226 }
6227 return;
6228 }
SongFerngWang0e767992021-03-31 22:08:45 +08006229 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6230 PersistableBundle c = configManager.getConfigForSubId(subId);
6231 boolean requireUssd = c.getBoolean(
6232 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006233
Shuo Qian4a594052020-01-23 11:59:30 -08006234 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006235 if (requireUssd) {
6236 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6237 getSubscriptionCarrierId(subId));
6238 String newUssdCommand = "";
6239 try {
6240 newUssdCommand = carrierXmlParser.getFeature(
6241 CarrierXmlParser.FEATURE_CALL_WAITING)
6242 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6243 } catch (NullPointerException e) {
6244 loge("Failed to generate USSD number" + e);
6245 }
6246 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6247 mMainThreadHandler, callback, carrierXmlParser,
6248 CarrierXmlParser.SsEntry.SSAction.QUERY);
6249 final String ussdCommand = newUssdCommand;
6250 Executors.newSingleThreadExecutor().execute(() -> {
6251 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6252 });
6253 } else {
6254 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6255 callback::accept);
6256 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6257 }
Shuo Qian4a594052020-01-23 11:59:30 -08006258 } finally {
6259 Binder.restoreCallingIdentity(identity);
6260 }
6261 }
6262
6263 /**
Hall Liu27d24262020-09-18 19:04:59 -07006264 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006265 */
6266 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006267 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006268 enforceModifyPermission();
6269 long identity = Binder.clearCallingIdentity();
6270 try {
Hall Liu27d24262020-09-18 19:04:59 -07006271 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6272
6273 Phone phone = getPhone(subId);
6274 if (phone == null) {
6275 try {
6276 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6277 } catch (RemoteException e) {
6278 // ignore
6279 }
6280 return;
6281 }
6282
SongFerngWang0e767992021-03-31 22:08:45 +08006283 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6284 PersistableBundle c = configManager.getConfigForSubId(subId);
6285 boolean requireUssd = c.getBoolean(
6286 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006287
SongFerngWang0e767992021-03-31 22:08:45 +08006288 if (DBG) log("getCallWaitingStatus: subId " + subId);
6289 if (requireUssd) {
6290 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6291 getSubscriptionCarrierId(subId));
6292 CarrierXmlParser.SsEntry.SSAction ssAction =
6293 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6294 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6295 String newUssdCommand = "";
6296 try {
6297 newUssdCommand = carrierXmlParser.getFeature(
6298 CarrierXmlParser.FEATURE_CALL_WAITING)
6299 .makeCommand(ssAction, null);
6300 } catch (NullPointerException e) {
6301 loge("Failed to generate USSD number" + e);
6302 }
6303 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6304 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6305 final String ussdCommand = newUssdCommand;
6306 Executors.newSingleThreadExecutor().execute(() -> {
6307 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6308 });
6309 } else {
6310 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6311 FunctionalUtils.ignoreRemoteException(callback::accept));
6312
6313 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6314 }
Shuo Qian4a594052020-01-23 11:59:30 -08006315 } finally {
6316 Binder.restoreCallingIdentity(identity);
6317 }
6318 }
6319
6320 /**
yinxub1bed742017-04-17 11:45:04 -07006321 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006322 *
yinxub1bed742017-04-17 11:45:04 -07006323 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006324 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6325 * location related information which will be sent if the caller already possess
6326 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006327 * @param request contains the radio access networks with bands/channels to scan
6328 * @param messenger callback messenger for scan results or errors
6329 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006330 * @return the id of the requested scan which can be used to stop the scan.
6331 */
6332 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006333 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6334 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006335 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006336 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6337 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006338 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006339 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6340 if (!renounceFineLocationAccess) {
6341 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6342 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6343 .setCallingPackage(callingPackage)
6344 .setCallingFeatureId(callingFeatureId)
6345 .setCallingPid(Binder.getCallingPid())
6346 .setCallingUid(Binder.getCallingUid())
6347 .setMethod("requestNetworkScan")
6348 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6349 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6350 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6351 .build());
6352 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006353 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006354 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6355 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006356 if (e != null) {
6357 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6358 throw e;
6359 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006360 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006361 return TelephonyScanManager.INVALID_SCAN_ID;
6362 }
6363 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006364 }
Hall Liu912dfd32019-04-25 14:02:26 -07006365 int callingUid = Binder.getCallingUid();
6366 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006367 final long identity = Binder.clearCallingIdentity();
6368 try {
6369 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006370 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006371 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006372 } finally {
6373 Binder.restoreCallingIdentity(identity);
6374 }
yinxu504e1392017-04-12 16:03:22 -07006375 }
6376
Hall Liub2ac8ef2019-02-28 15:56:23 -08006377 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006378 NetworkScanRequest request, int subId, String callingPackage) {
6379 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006380 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6381 boolean hasNetworkScanPermission =
6382 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6383 == PERMISSION_GRANTED;
6384
6385 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6386 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6387 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006388 }
6389
6390 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6391 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006392 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6393 return new SecurityException("Specific channels must not be"
6394 + " scanned without location access.");
6395 }
6396 }
6397 }
6398
Hall Liub2ac8ef2019-02-28 15:56:23 -08006399 return null;
6400 }
6401
yinxu504e1392017-04-12 16:03:22 -07006402 /**
6403 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006404 *
6405 * @param subId id of the subscription
6406 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006407 */
6408 @Override
6409 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006410 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6411 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006412
Hall Liu912dfd32019-04-25 14:02:26 -07006413 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006414 final long identity = Binder.clearCallingIdentity();
6415 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006416 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006417 } finally {
6418 Binder.restoreCallingIdentity(identity);
6419 }
yinxu504e1392017-04-12 16:03:22 -07006420 }
6421
6422 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006423 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006424 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006425 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006426 */
6427 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006428 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006429 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006430 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006431 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006432
6433 final long identity = Binder.clearCallingIdentity();
6434 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006435 if (DBG) log("getAllowedNetworkTypesBitmask");
6436 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6437 int networkTypesBitmask = (result != null ? result[0] : -1);
6438 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6439 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006440 } finally {
6441 Binder.restoreCallingIdentity(identity);
6442 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006443 }
6444
6445 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006446 * Get the allowed network types for certain reason.
6447 *
6448 * @param subId the id of the subscription.
6449 * @param reason the reason the allowed network type change is taking place
6450 * @return the allowed network types.
6451 */
6452 @Override
6453 public long getAllowedNetworkTypesForReason(int subId,
6454 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006455 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006456 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006457 final long identity = Binder.clearCallingIdentity();
6458 try {
6459 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6460 } finally {
6461 Binder.restoreCallingIdentity(identity);
6462 }
6463 }
6464
6465 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006466 * Enable/Disable E-UTRA-NR Dual Connectivity
6467 * @param subId subscription id of the sim card
6468 * @param nrDualConnectivityState expected NR dual connectivity state
6469 * This can be passed following states
6470 * <ol>
6471 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6472 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6473 * <li>Disable NR dual connectivity and force secondary cell to be released
6474 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6475 * </ol>
6476 * @return operation result.
6477 */
6478 @Override
6479 public int setNrDualConnectivityState(int subId,
6480 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6481 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6482 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006483 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006484 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6485 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6486 }
6487
Sooraj Sasindran37444802020-08-11 10:40:43 -07006488 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6489 final long identity = Binder.clearCallingIdentity();
6490 try {
6491 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6492 nrDualConnectivityState, subId,
6493 workSource);
6494 if (DBG) log("enableNRDualConnectivity result: " + result);
6495 return result;
6496 } finally {
6497 Binder.restoreCallingIdentity(identity);
6498 }
6499 }
6500
6501 /**
6502 * Is E-UTRA-NR Dual Connectivity enabled
6503 * @return true if dual connectivity is enabled else false
6504 */
6505 @Override
6506 public boolean isNrDualConnectivityEnabled(int subId) {
6507 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006508 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006509 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006510 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006511 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6512 return false;
6513 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006514 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6515 final long identity = Binder.clearCallingIdentity();
6516 try {
6517 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6518 null, subId, workSource);
6519 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6520 return isEnabled;
6521 } finally {
6522 Binder.restoreCallingIdentity(identity);
6523 }
6524 }
6525
6526 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006527 * Set the allowed network types of the device and
6528 * provide the reason triggering the allowed network change.
6529 *
6530 * @param subId the id of the subscription.
6531 * @param reason the reason the allowed network type change is taking place
6532 * @param allowedNetworkTypes the allowed network types.
6533 * @return true on success; false on any failure.
6534 */
6535 @Override
6536 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006537 @TelephonyManager.AllowedNetworkTypesReason int reason,
6538 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006539 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6540 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006541 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006542 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6543 return false;
6544 }
6545 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6546 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006547 return false;
6548 }
6549
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006550 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6551 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6552
6553
6554 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6555 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6556 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006557 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006558
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006559 final long identity = Binder.clearCallingIdentity();
6560 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006561 Boolean success = (Boolean) sendRequest(
6562 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6563 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6564
6565 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6566 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006567 } finally {
6568 Binder.restoreCallingIdentity(identity);
6569 }
6570 }
6571
6572 /**
Miaoa84611c2019-03-15 09:21:10 +08006573 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006574 *
Miaoa84611c2019-03-15 09:21:10 +08006575 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006576 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006577 * @hide
6578 */
6579 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006580 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006581 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006582 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006583 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006584 try {
Miaoa84611c2019-03-15 09:21:10 +08006585 if (phone != null) {
6586 return phone.hasMatchedTetherApnSetting();
6587 } else {
6588 return false;
6589 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006590 } finally {
6591 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006592 }
Junda Liu475951f2014-11-07 16:45:03 -08006593 }
6594
6595 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006596 * Get the user enabled state of Mobile Data.
6597 *
6598 * TODO: remove and use isUserDataEnabled.
6599 * This can't be removed now because some vendor codes
6600 * calls through ITelephony directly while they should
6601 * use TelephonyManager.
6602 *
6603 * @return true on enabled
6604 */
6605 @Override
6606 public boolean getDataEnabled(int subId) {
6607 return isUserDataEnabled(subId);
6608 }
6609
6610 /**
6611 * Get whether mobile data is enabled per user setting.
6612 *
6613 * There are other factors deciding whether mobile data is actually enabled, but they are
6614 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006615 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006616 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6617 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006618 *
6619 * @return {@code true} if data is enabled else {@code false}
6620 */
6621 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006622 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006623 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006624 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006625 try {
6626 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6627 functionName);
6628 } catch (Exception e) {
6629 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6630 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006631 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006632 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006633 mApp, subId, functionName);
6634
Robert Greenwalt646120a2014-05-23 11:54:03 -07006635 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006636
6637 final long identity = Binder.clearCallingIdentity();
6638 try {
6639 int phoneId = mSubscriptionController.getPhoneId(subId);
6640 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6641 Phone phone = PhoneFactory.getPhone(phoneId);
6642 if (phone != null) {
6643 boolean retVal = phone.isUserDataEnabled();
6644 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6645 return retVal;
6646 } else {
6647 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6648 return false;
6649 }
6650 } finally {
6651 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006652 }
6653 }
6654
6655 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006656 * Checks if the device is capable of mobile data by considering whether whether the
6657 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6658 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006659 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006660 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006661 */
6662 @Override
6663 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006664 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006665 try {
6666 try {
6667 mApp.enforceCallingOrSelfPermission(
6668 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006669 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006670 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006671 try {
6672 mApp.enforceCallingOrSelfPermission(
6673 android.Manifest.permission.READ_PHONE_STATE,
6674 functionName);
6675 } catch (Exception e2) {
6676 mApp.enforceCallingOrSelfPermission(
6677 permission.READ_BASIC_PHONE_STATE, functionName);
6678 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006679 }
6680 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006681 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006682 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006683
6684 final long identity = Binder.clearCallingIdentity();
6685 try {
6686 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006687 Phone phone = PhoneFactory.getPhone(phoneId);
6688 if (phone != null) {
Jack Yu4ad64e52021-12-03 14:23:53 -08006689 boolean retVal;
6690 if (phone.isUsingNewDataStack()) {
6691 retVal = phone.getDataNetworkController().getDataSettingsManager()
6692 .isDataEnabled();
6693 } else {
6694 retVal = phone.getDataEnabledSettings().isDataEnabled();
6695 }
6696 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006697 return retVal;
6698 } else {
6699 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6700 return false;
6701 }
6702 } finally {
6703 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006704 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006705 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006706
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006707 /**
6708 * Check if data is enabled for a specific reason
6709 * @param subId Subscription index
6710 * @param reason the reason the data enable change is taking place
6711 * @return {@code true} if the overall data is enabled; {@code false} if not.
6712 */
6713 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006714 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006715 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006716 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006717 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006718 try {
6719 mApp.enforceCallingOrSelfPermission(
6720 android.Manifest.permission.ACCESS_NETWORK_STATE,
6721 functionName);
6722 } catch (Exception e) {
6723 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6724 functionName);
6725 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006726 } catch (Exception e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006727 try {
6728 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006729 functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006730 } catch (Exception e2) {
6731 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006732 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006733 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006734 }
6735
6736
6737 final long identity = Binder.clearCallingIdentity();
6738 try {
6739 int phoneId = mSubscriptionController.getPhoneId(subId);
6740 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006741 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006742 + " reason=" + reason);
6743 }
6744 Phone phone = PhoneFactory.getPhone(phoneId);
6745 if (phone != null) {
6746 boolean retVal;
Jack Yu99e87332021-12-17 23:14:15 -08006747 if (phone.isUsingNewDataStack()) {
6748 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006749 } else {
Jack Yu99e87332021-12-17 23:14:15 -08006750 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6751 retVal = phone.isUserDataEnabled();
6752 } else {
6753 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
6754 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006755 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006756 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006757 return retVal;
6758 } else {
6759 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006760 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006761 + subId + " retVal=false");
6762 }
6763 return false;
6764 }
6765 } finally {
6766 Binder.restoreCallingIdentity(identity);
6767 }
6768 }
6769
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006770 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006771 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006772 if (uid == Process.PHONE_UID) {
6773 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6774 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006775 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6776 }
6777
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006778 //load access rules from carrier configs, and check those as well: b/139133814
6779 SubscriptionController subController = SubscriptionController.getInstance();
6780 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6781 || subController == null) return privilegeFromSim;
6782
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006783 PackageManager pkgMgr = phone.getContext().getPackageManager();
6784 String[] packages = pkgMgr.getPackagesForUid(uid);
6785
6786 final long identity = Binder.clearCallingIdentity();
6787 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006788 int subId = phone.getSubId();
6789 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6790 // A test override is in place for the privileges for this subId, so don't try to
6791 // read the subscription privileges.
6792 return privilegeFromSim;
6793 }
6794 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006795 SubscriptionManager subManager = (SubscriptionManager)
6796 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6797 for (String pkg : packages) {
6798 if (subManager.canManageSubscription(subInfo, pkg)) {
6799 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6800 }
6801 }
6802 return privilegeFromSim;
6803 } finally {
6804 Binder.restoreCallingIdentity(identity);
6805 }
6806 }
6807
6808 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6809 String pkgName) {
6810 //load access rules from carrier configs, and check those as well: b/139133814
6811 SubscriptionController subController = SubscriptionController.getInstance();
6812 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6813 || subController == null) return privilegeFromSim;
6814
6815 final long identity = Binder.clearCallingIdentity();
6816 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006817 int subId = phone.getSubId();
6818 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6819 // A test override is in place for the privileges for this subId, so don't try to
6820 // read the subscription privileges.
6821 return privilegeFromSim;
6822 }
6823 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006824 SubscriptionManager subManager = (SubscriptionManager)
6825 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6826 return subManager.canManageSubscription(subInfo, pkgName)
6827 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6828 } finally {
6829 Binder.restoreCallingIdentity(identity);
6830 }
6831 }
6832
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006833 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006834 public int getCarrierPrivilegeStatus(int subId) {
6835 final Phone phone = getPhone(subId);
6836 if (phone == null) {
6837 loge("getCarrierPrivilegeStatus: Invalid subId");
6838 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6839 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006840 UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId());
6841 if (port == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006842 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006843 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6844 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006845
6846 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006847 port.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006848 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006849 }
Junda Liu29340342014-07-10 15:23:27 -07006850
6851 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006852 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006853 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006854 final Phone phone = getPhone(subId);
6855 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006856 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006857 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6858 }
6859 UiccProfile profile =
6860 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6861 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006862 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006863 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6864 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006865 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006866 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006867 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006868 }
6869
6870 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006871 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006872 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006873 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006874 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006875 }
6876
6877 int phoneId = SubscriptionManager.getPhoneId(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006878 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6879 if (port == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006880 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006881 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6882 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006883 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006884 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006885 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006886 }
6887
6888 @Override
6889 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006890 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006891 if (TextUtils.isEmpty(pkgName))
6892 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006893 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6894 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006895 UiccPort port = UiccController.getInstance().getUiccPort(i);
6896 if (port == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006897 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006898 continue;
6899 }
6900
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006901 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006902 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006903 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006904 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6905 break;
6906 }
6907 }
6908
6909 return result;
Junda Liu29340342014-07-10 15:23:27 -07006910 }
Derek Tan89e89d42014-07-08 17:00:10 -07006911
6912 @Override
Junda Liue64de782015-04-16 17:19:16 -07006913 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006914 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006915 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6916 loge("phoneId " + phoneId + " is not valid.");
6917 return null;
6918 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006919 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6920 if (port == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006921 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006922 return null ;
6923 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006924 return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006925 }
6926
Amith Yamasani6e118872016-02-19 12:53:51 -08006927 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006928 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006929 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006930 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006931 List<String> privilegedPackages = new ArrayList<>();
6932 List<PackageInfo> packages = null;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006933 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
chen xuf7e9fe82019-05-09 19:31:02 -07006934 // has UICC in that slot.
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006935 if (port != null) {
6936 if (port.hasCarrierPrivilegeRules()) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006937 if (packages == null) {
6938 // Only check packages in user 0 for now
6939 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006940 PackageManager.MATCH_DISABLED_COMPONENTS
6941 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006942 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006943 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006944 }
6945 for (int p = packages.size() - 1; p >= 0; p--) {
6946 PackageInfo pkgInfo = packages.get(p);
6947 if (pkgInfo != null && pkgInfo.packageName != null
Sooraj Sasindran97bce6f2021-09-28 21:37:29 +00006948 && getCarrierPrivilegeStatusFromCarrierConfigRules(
6949 port.getCarrierPrivilegeStatus(pkgInfo),
6950 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07006951 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006952 privilegedPackages.add(pkgInfo.packageName);
6953 }
6954 }
6955 }
6956 }
6957 return privilegedPackages;
6958 }
6959
chen xuf7e9fe82019-05-09 19:31:02 -07006960 @Override
6961 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006962 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6963
6964 final long identity = Binder.clearCallingIdentity();
6965
chen xuf7e9fe82019-05-09 19:31:02 -07006966 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006967 try {
6968 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6969 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6970 }
6971 } finally {
6972 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006973 }
6974 return privilegedPackages;
6975 }
6976
Wink Savilleb564aae2014-10-23 10:18:09 -07006977 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006978 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006979 UiccPort port = phone == null ? null : phone.getUiccPort();
6980 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006981 return null;
6982 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006983 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006984 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006985 return null;
6986 }
6987 return iccId;
6988 }
6989
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006990 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006991 public void setCallComposerStatus(int subId, int status) {
6992 enforceModifyPermission();
6993
6994 final long identity = Binder.clearCallingIdentity();
6995 try {
6996 Phone phone = getPhone(subId);
6997 if (phone != null) {
6998 Phone defaultPhone = phone.getImsPhone();
6999 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7000 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7001 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007002 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7003 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007004 }
7005 }
Shuo Qian284ae752020-12-22 19:10:14 -08007006 } catch (ImsException e) {
7007 throw new ServiceSpecificException(e.getCode());
7008 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007009 Binder.restoreCallingIdentity(identity);
7010 }
7011 }
7012
7013 @Override
7014 public int getCallComposerStatus(int subId) {
7015 enforceReadPrivilegedPermission("getCallComposerStatus");
7016
7017 final long identity = Binder.clearCallingIdentity();
7018 try {
7019 Phone phone = getPhone(subId);
7020 if (phone != null) {
7021 Phone defaultPhone = phone.getImsPhone();
7022 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7023 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7024 return imsPhone.getCallComposerStatus();
7025 }
7026 }
7027 } finally {
7028 Binder.restoreCallingIdentity(identity);
7029 }
7030 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7031 }
7032
7033 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007034 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7035 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007036 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007037 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007038
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007039 final long identity = Binder.clearCallingIdentity();
7040 try {
7041 final String iccId = getIccId(subId);
7042 final Phone phone = getPhone(subId);
7043 if (phone == null) {
7044 return false;
7045 }
7046 final String subscriberId = phone.getSubscriberId();
7047
7048 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007049 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007050 + subscriberId + " to " + number);
7051 }
7052
7053 if (TextUtils.isEmpty(iccId)) {
7054 return false;
7055 }
7056
7057 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7058
7059 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7060 if (alphaTag == null) {
7061 editor.remove(alphaTagPrefKey);
7062 } else {
7063 editor.putString(alphaTagPrefKey, alphaTag);
7064 }
7065
7066 // Record both the line number and IMSI for this ICCID, since we need to
7067 // track all merged IMSIs based on line number
7068 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7069 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7070 if (number == null) {
7071 editor.remove(numberPrefKey);
7072 editor.remove(subscriberPrefKey);
7073 } else {
7074 editor.putString(numberPrefKey, number);
7075 editor.putString(subscriberPrefKey, subscriberId);
7076 }
7077
7078 editor.commit();
7079 return true;
7080 } finally {
7081 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007082 }
Derek Tan7226c842014-07-02 17:42:23 -07007083 }
7084
7085 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007086 public String getLine1NumberForDisplay(int subId, String callingPackage,
7087 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007088 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007089 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007090 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007091 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007092 return null;
7093 }
Derek Tan97ebb422014-09-05 16:55:38 -07007094
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007095 final long identity = Binder.clearCallingIdentity();
7096 try {
7097 String iccId = getIccId(subId);
7098 if (iccId != null) {
7099 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7100 if (DBG_MERGE) {
7101 log("getLine1NumberForDisplay returning "
7102 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7103 }
7104 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007105 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007106 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7107 return null;
7108 } finally {
7109 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007110 }
Derek Tan7226c842014-07-02 17:42:23 -07007111 }
7112
7113 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007114 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7115 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007116 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007117 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007118 return null;
7119 }
Derek Tan97ebb422014-09-05 16:55:38 -07007120
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007121 final long identity = Binder.clearCallingIdentity();
7122 try {
7123 String iccId = getIccId(subId);
7124 if (iccId != null) {
7125 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7126 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7127 }
7128 return null;
7129 } finally {
7130 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007131 }
Derek Tan7226c842014-07-02 17:42:23 -07007132 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007133
7134 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007135 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7136 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007137 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7138 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007139 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007140 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007141 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007142 return null;
7143 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007144
Jordan Liub49b04b2019-05-06 14:45:15 -07007145 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7146 // the process, where TelephonyManager was instantiated.
7147 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007148 final long identity = Binder.clearCallingIdentity();
7149 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007150 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007151 final TelephonyManager tele = TelephonyManager.from(context);
7152 final SubscriptionManager sub = SubscriptionManager.from(context);
7153
7154 // Figure out what subscribers are currently active
7155 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007156
Jordan Liub49b04b2019-05-06 14:45:15 -07007157 // Only consider subs which match the current subId
7158 // This logic can be simplified. See b/131189269 for progress.
7159 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007160 activeSubscriberIds.add(tele.getSubscriberId(subId));
7161 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007162
7163 // First pass, find a number override for an active subscriber
7164 String mergeNumber = null;
7165 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7166 for (String key : prefs.keySet()) {
7167 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7168 final String subscriberId = (String) prefs.get(key);
7169 if (activeSubscriberIds.contains(subscriberId)) {
7170 final String iccId = key.substring(
7171 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7172 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7173 mergeNumber = (String) prefs.get(numberKey);
7174 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007175 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007176 + " for active subscriber " + subscriberId);
7177 }
7178 if (!TextUtils.isEmpty(mergeNumber)) {
7179 break;
7180 }
7181 }
7182 }
7183 }
7184
7185 // Shortcut when no active merged subscribers
7186 if (TextUtils.isEmpty(mergeNumber)) {
7187 return null;
7188 }
7189
7190 // Second pass, find all subscribers under that line override
7191 final ArraySet<String> result = new ArraySet<>();
7192 for (String key : prefs.keySet()) {
7193 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7194 final String number = (String) prefs.get(key);
7195 if (mergeNumber.equals(number)) {
7196 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7197 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7198 final String subscriberId = (String) prefs.get(subscriberKey);
7199 if (!TextUtils.isEmpty(subscriberId)) {
7200 result.add(subscriberId);
7201 }
7202 }
7203 }
7204 }
7205
7206 final String[] resultArray = result.toArray(new String[result.size()]);
7207 Arrays.sort(resultArray);
7208 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007209 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007210 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7211 }
7212 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007213 } finally {
7214 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007215 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007216 }
7217
7218 @Override
zoey chen38003472019-12-13 17:16:31 +08007219 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7220 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007221
7222 final long identity = Binder.clearCallingIdentity();
7223 try {
7224 final TelephonyManager telephonyManager = mApp.getSystemService(
7225 TelephonyManager.class);
7226 String subscriberId = telephonyManager.getSubscriberId(subId);
7227 if (subscriberId == null) {
7228 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007229 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007230 + subId);
7231 }
7232 return null;
7233 }
7234
7235 final SubscriptionInfo info = SubscriptionController.getInstance()
7236 .getSubscriptionInfo(subId);
7237 final ParcelUuid groupUuid = info.getGroupUuid();
7238 // If it doesn't belong to any group, return just subscriberId of itself.
7239 if (groupUuid == null) {
7240 return new String[]{subscriberId};
7241 }
7242
7243 // Get all subscriberIds from the group.
7244 final List<String> mergedSubscriberIds = new ArrayList<>();
7245 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007246 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007247 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007248 for (SubscriptionInfo subInfo : groupInfos) {
7249 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7250 if (subscriberId != null) {
7251 mergedSubscriberIds.add(subscriberId);
7252 }
7253 }
7254
7255 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7256 } finally {
7257 Binder.restoreCallingIdentity(identity);
7258
7259 }
7260 }
7261
7262 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007263 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007264 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007265 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007266
7267 final long identity = Binder.clearCallingIdentity();
7268 try {
7269 final Phone phone = getPhone(subId);
7270 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7271 } finally {
7272 Binder.restoreCallingIdentity(identity);
7273 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007274 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007275
7276 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007277 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007278 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7279 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007280 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7281 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007282
7283 final long identity = Binder.clearCallingIdentity();
7284 try {
7285 final Phone phone = getPhone(subId);
7286 if (phone == null) {
7287 return false;
7288 }
7289 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7290 cdmaNonRoamingList);
7291 } finally {
7292 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007293 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007294 }
7295
7296 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007297 @Deprecated
7298 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7299 enforceModifyPermission();
7300
7301 int returnValue = 0;
7302 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007303 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007304 if(result.exception == null) {
7305 if (result.result != null) {
7306 byte[] responseData = (byte[])(result.result);
7307 if(responseData.length > oemResp.length) {
7308 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7309 responseData.length + "bytes. Buffer Size is " +
7310 oemResp.length + "bytes.");
7311 }
7312 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7313 returnValue = responseData.length;
7314 }
7315 } else {
7316 CommandException ex = (CommandException) result.exception;
7317 returnValue = ex.getCommandError().ordinal();
7318 if(returnValue > 0) returnValue *= -1;
7319 }
7320 } catch (RuntimeException e) {
7321 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7322 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7323 if(returnValue > 0) returnValue *= -1;
7324 }
7325
7326 return returnValue;
7327 }
7328
7329 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007330 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007331 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007332 try {
7333 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007334 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007335 mApp, phone.getSubId(), "getRadioAccessFamily");
7336 } catch (SecurityException e) {
7337 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7338 throw e;
7339 }
chen xub97461a2018-10-26 14:17:57 -07007340 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007341 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007342 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007343 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007344 final long identity = Binder.clearCallingIdentity();
7345 try {
chen xub97461a2018-10-26 14:17:57 -07007346 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007347 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007348 mApp, phone.getSubId(), "getRadioAccessFamily");
7349 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007350 } finally {
7351 Binder.restoreCallingIdentity(identity);
7352 }
chen xub97461a2018-10-26 14:17:57 -07007353 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007354 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007355
7356 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007357 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007358 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007359 try {
7360 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7361 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007362 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007363 }
7364 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007365 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007366 }
7367 RoleManager rm = mApp.getSystemService(RoleManager.class);
7368 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7369 if (!dialerRoleHolders.contains(callingPackage)) {
7370 throw new SecurityException("App must be the dialer role holder to"
7371 + " upload a call composer pic");
7372 }
7373
7374 Executors.newSingleThreadExecutor().execute(() -> {
7375 ByteArrayOutputStream output = new ByteArrayOutputStream(
7376 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7377 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7378 boolean readUntilEnd = false;
7379 int totalBytesRead = 0;
7380 byte[] buffer = new byte[16 * 1024];
7381 while (true) {
7382 int numRead;
7383 try {
7384 numRead = input.read(buffer);
7385 } catch (IOException e) {
7386 try {
7387 fd.checkError();
7388 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7389 null);
7390 } catch (IOException e1) {
7391 // This means that the other side closed explicitly with an error. If this
7392 // happens, log and ignore.
7393 loge("Remote end of call composer picture pipe closed: " + e1);
7394 }
7395 break;
7396 }
7397 if (numRead == -1) {
7398 readUntilEnd = true;
7399 break;
7400 }
7401 totalBytesRead += numRead;
7402 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7403 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7404 try {
7405 input.close();
7406 } catch (IOException e) {
7407 // ignore
7408 }
7409 break;
7410 }
7411 output.write(buffer, 0, numRead);
7412 }
7413 // Generally, the remote end will close the file descriptors. The only case where we
7414 // close is above, where the picture size is too big.
7415
7416 try {
7417 fd.checkError();
7418 } catch (IOException e) {
7419 loge("Remote end for call composer closed with an error: " + e);
7420 return;
7421 }
7422
Hall Liuaa4211e2021-01-20 15:43:39 -08007423 if (!readUntilEnd) {
7424 loge("Did not finish reading entire image; aborting");
7425 return;
7426 }
Hall Liu82694d52020-12-11 18:22:04 -08007427
Hall Liuaa4211e2021-01-20 15:43:39 -08007428 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7429 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7430 new CallComposerPictureTransfer.Factory() {},
7431 imageData,
7432 (result) -> {
7433 if (result.first != null) {
7434 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7435 Bundle outputResult = new Bundle();
7436 outputResult.putParcelable(
7437 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7438 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7439 outputResult);
7440 } else {
7441 callback.send(result.second, null);
7442 }
7443 }
7444 );
Hall Liu82694d52020-12-11 18:22:04 -08007445 });
7446 }
7447
7448 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007449 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007450 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007451 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007452
7453 final long identity = Binder.clearCallingIdentity();
7454 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007455 ImsManager.getInstance(defaultPhone.getContext(),
7456 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007457 } finally {
7458 Binder.restoreCallingIdentity(identity);
7459 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007460 }
7461
7462 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007463 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007464 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007465 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7466 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007467 return false;
7468 }
Svet Ganovb320e182015-04-16 12:30:10 -07007469
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007470 final long identity = Binder.clearCallingIdentity();
7471 try {
7472 // Check the user preference and the system-level IMS setting. Even if the user has
7473 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7474 // In the long run, we may instead need to check if there exists a connection service
7475 // which can support video calling.
7476 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007477 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007478 return imsManager.isVtEnabledByPlatform()
7479 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7480 && imsManager.isVtEnabledByUser();
7481 } finally {
7482 Binder.restoreCallingIdentity(identity);
7483 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007484 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007485
Andrew Leea1239f22015-03-02 17:44:07 -08007486 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007487 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7488 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007489 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007490 mApp, subId, callingPackage, callingFeatureId,
7491 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007492 return false;
7493 }
7494
7495 final long identity = Binder.clearCallingIdentity();
7496 try {
7497 CarrierConfigManager configManager =
7498 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007499 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007500 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7501 } finally {
7502 Binder.restoreCallingIdentity(identity);
7503 }
Andrew Leea1239f22015-03-02 17:44:07 -08007504 }
7505
7506 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007507 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007508 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007509 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007510 return false;
7511 }
7512
7513 final long identity = Binder.clearCallingIdentity();
7514 try {
7515 CarrierConfigManager configManager =
7516 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007517 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007518 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7519 } finally {
7520 Binder.restoreCallingIdentity(identity);
7521 }
Andrew Leea1239f22015-03-02 17:44:07 -08007522 }
7523
Andrew Lee9431b832015-03-09 18:46:45 -07007524 @Override
7525 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007526 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007527 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007528 }
7529
7530 @Override
7531 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007532 final long identity = Binder.clearCallingIdentity();
7533 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007534 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007535 } finally {
7536 Binder.restoreCallingIdentity(identity);
7537 }
Andrew Lee9431b832015-03-09 18:46:45 -07007538 }
7539
Hall Liuf6668912018-10-31 17:05:23 -07007540 /**
7541 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7542 * support for the feature and device firmware support.
7543 *
7544 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7545 */
7546 @Override
7547 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007548 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007549 final Phone phone = getPhone(subscriptionId);
7550 if (phone == null) {
7551 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7552 return false;
7553 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007554 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007555 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007556 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7557 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007558 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007559 return isCarrierSupported && isDeviceSupported;
7560 } finally {
7561 Binder.restoreCallingIdentity(identity);
7562 }
Hall Liu98187582018-01-22 19:15:32 -08007563 }
7564
Hall Liuf6668912018-10-31 17:05:23 -07007565 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007566 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7567 * RTT setting, will return true if the device and carrier both support RTT.
7568 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007569 */
7570 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007571 final long identity = Binder.clearCallingIdentity();
7572 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007573 boolean isRttSupported = isRttSupported(subscriptionId);
7574 boolean isUserRttSettingOn = Settings.Secure.getInt(
7575 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7576 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7577 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7578 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007579 } finally {
7580 Binder.restoreCallingIdentity(identity);
7581 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007582 }
7583
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007584 @Deprecated
7585 @Override
7586 public String getDeviceId(String callingPackage) {
7587 return getDeviceIdWithFeature(callingPackage, null);
7588 }
7589
Sanket Padawe7310cc72015-01-14 09:53:20 -08007590 /**
7591 * Returns the unique device ID of phone, for example, the IMEI for
7592 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7593 *
7594 * <p>Requires Permission:
7595 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7596 */
7597 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007598 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007599 try {
7600 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7601 } catch (SecurityException se) {
7602 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7603 throw new SecurityException("Package " + callingPackage + " does not belong to "
7604 + Binder.getCallingUid());
7605 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007606 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007607 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007608 return null;
7609 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007610 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007611 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007612 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007613 return null;
7614 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007615
7616 final long identity = Binder.clearCallingIdentity();
7617 try {
7618 return phone.getDeviceId();
7619 } finally {
7620 Binder.restoreCallingIdentity(identity);
7621 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007622 }
7623
Ping Sunc67b7c22016-03-02 19:16:45 +08007624 /**
7625 * {@hide}
7626 * Returns the IMS Registration Status on a particular subid
7627 *
7628 * @param subId
7629 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007630 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007631 Phone phone = getPhone(subId);
7632 if (phone != null) {
7633 return phone.isImsRegistered();
7634 } else {
7635 return false;
7636 }
7637 }
7638
Santos Cordon7a1885b2015-02-03 11:15:19 -08007639 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007640 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007641 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007642 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007643 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007644 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7645 }
7646 final long identity = Binder.clearCallingIdentity();
7647 try {
7648 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7649 } finally {
7650 Binder.restoreCallingIdentity(identity);
7651 }
7652 }
7653
7654 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007655 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007656 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007657 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007658 mApp,
7659 subscriptionId,
7660 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007661 final long identity = Binder.clearCallingIdentity();
7662 try {
7663 Phone phone = getPhone(subscriptionId);
7664 if (phone == null) {
7665 return null;
7666 }
7667 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7668 } finally {
7669 Binder.restoreCallingIdentity(identity);
7670 }
7671 }
7672
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007673 /**
7674 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007675 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007676 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007677 final long identity = Binder.clearCallingIdentity();
7678 try {
7679 Phone phone = getPhone(subId);
7680 if (phone != null) {
7681 return phone.isWifiCallingEnabled();
7682 } else {
7683 return false;
7684 }
7685 } finally {
7686 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007687 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007688 }
7689
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007690 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007691 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007692 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007693 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007694 final long identity = Binder.clearCallingIdentity();
7695 try {
7696 Phone phone = getPhone(subId);
7697 if (phone != null) {
7698 return phone.isVideoEnabled();
7699 } else {
7700 return false;
7701 }
7702 } finally {
7703 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007704 }
7705 }
7706
7707 /**
7708 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7709 * defined in {@link ImsRegistrationImplBase}.
7710 */
7711 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007712 final long identity = Binder.clearCallingIdentity();
7713 try {
7714 Phone phone = getPhone(subId);
7715 if (phone != null) {
7716 return phone.getImsRegistrationTech();
7717 } else {
7718 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7719 }
7720 } finally {
7721 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007722 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007723 }
7724
Stuart Scott8eef64f2015-04-08 15:13:54 -07007725 @Override
7726 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007727 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007728 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7729 return;
7730 }
Kai Shif70f46f2021-03-03 13:59:46 -08007731 Phone defaultPhone = getDefaultPhone();
7732 if (defaultPhone != null) {
7733 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7734 mApp, getDefaultPhone().getSubId(), "factoryReset");
7735 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007736 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007737
Svet Ganovcc087f82015-05-12 20:35:54 -07007738 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007739 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7740 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007741 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007742 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007743 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007744 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007745 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007746 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007747 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007748 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007749 // There has been issues when Sms raw table somehow stores orphan
7750 // fragments. They lead to garbled message when new fragments come
7751 // in and combined with those stale ones. In case this happens again,
7752 // user can reset all network settings which will clean up this table.
7753 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007754 // Clean up IMS settings as well here.
7755 int slotId = getSlotIndex(subId);
7756 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7757 ImsManager.getInstance(mApp, slotId).factoryReset();
7758 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007759
Kai Shif70f46f2021-03-03 13:59:46 -08007760 if (defaultPhone == null) {
7761 return;
7762 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007763 // Erase modem config if erase modem on network setting is enabled.
7764 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7765 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7766 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007767 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007768 }
Kai Shif70f46f2021-03-03 13:59:46 -08007769
7770 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007771 } finally {
7772 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007773 }
7774 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007775
SongFerngWangfd89b102021-05-27 22:44:54 +08007776 @VisibleForTesting
7777 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7778 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7779 return;
7780 }
7781 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7782 RILConstants.PREFERRED_NETWORK_MODE);
7783 SubscriptionManager.setSubscriptionProperty(subId,
7784 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7785 "user=" + defaultNetworkType);
7786 phone.loadAllowedNetworksFromSubscriptionDatabase();
7787 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7788 defaultNetworkType, null);
7789 }
7790
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007791 private void cleanUpSmsRawTable(Context context) {
7792 ContentResolver resolver = context.getContentResolver();
7793 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7794 resolver.delete(uri, null, null);
7795 }
7796
Narayan Kamath1c496c22015-04-16 14:40:19 +01007797 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007798 public String getSimLocaleForSubscriber(int subId) {
7799 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7800 final Phone phone = getPhone(subId);
7801 if (phone == null) {
7802 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007803 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007804 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007805 final long identity = Binder.clearCallingIdentity();
7806 try {
chen xu5d3637b2019-01-21 23:31:38 -08007807 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007808 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007809 if (info == null) {
7810 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7811 return null;
7812 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007813 // Try and fetch the locale from the carrier properties or from the SIM language
7814 // preferences (EF-PL and EF-LI)...
7815 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007816 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007817 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7818 if (localeFromDefaultSim != null) {
7819 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7820 if (DBG) log("Using locale from subId: " + subId + " locale: "
7821 + localeFromDefaultSim);
7822 return localeFromDefaultSim.toLanguageTag();
7823 } else {
7824 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007825 }
7826 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007827
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007828 // The SIM language preferences only store a language (e.g. fr = French), not an
7829 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7830 // the SIM and carrier preferences does not include a country we add the country
7831 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007832 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007833 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007834 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007835 return mccLocale.toLanguageTag();
7836 }
7837
7838 if (DBG) log("No locale found - returning null");
7839 return null;
7840 } finally {
7841 Binder.restoreCallingIdentity(identity);
7842 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007843 }
7844
7845 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007846 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007847 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007848 }
7849
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007850 /**
7851 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7852 */
7853 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007854 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007855 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007856 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007857
Chenjie Yu1ba97252018-01-11 18:16:20 -08007858 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007859 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007860
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007861 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007862 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7863 * representing the state of the modem.
7864 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007865 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7866 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007867 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007868 */
7869 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007870 public void requestModemActivityInfo(ResultReceiver result) {
7871 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007872 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007873
7874 final long identity = Binder.clearCallingIdentity();
7875 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007876 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007877 } finally {
7878 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007879 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007880 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007881
Siddharth Rayb8114062018-06-17 15:02:38 -07007882 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7883 // less than total activity duration.
7884 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7885 if (info == null) {
7886 return false;
7887 }
7888 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007889 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7890 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7891
Siddharth Rayb8114062018-06-17 15:02:38 -07007892 return (info.isValid()
7893 && (info.getSleepTimeMillis() <= activityDurationMs)
7894 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007895 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007896 && (totalTxTimeMs <= activityDurationMs));
7897 }
7898
Jack Yu85bd38a2015-11-09 11:34:32 -08007899 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007900 * Returns the service state information on specified subscription.
7901 */
7902 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007903 public ServiceState getServiceStateForSubscriber(int subId,
7904 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7905 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007906 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007907 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007908 return null;
7909 }
7910
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007911 boolean hasFinePermission = false;
7912 boolean hasCoarsePermission = false;
7913 if (!renounceFineLocationAccess) {
7914 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7915 LocationAccessPolicy.checkLocationPermission(mApp,
7916 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7917 .setCallingPackage(callingPackage)
7918 .setCallingFeatureId(callingFeatureId)
7919 .setCallingPid(Binder.getCallingPid())
7920 .setCallingUid(Binder.getCallingUid())
7921 .setMethod("getServiceStateForSubscriber")
7922 .setLogAsInfo(true)
7923 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7924 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7925 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7926 .build());
7927 hasFinePermission =
7928 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7929 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007930
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007931 if (!renounceCoarseLocationAccess) {
7932 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7933 LocationAccessPolicy.checkLocationPermission(mApp,
7934 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7935 .setCallingPackage(callingPackage)
7936 .setCallingFeatureId(callingFeatureId)
7937 .setCallingPid(Binder.getCallingPid())
7938 .setCallingUid(Binder.getCallingUid())
7939 .setMethod("getServiceStateForSubscriber")
7940 .setLogAsInfo(true)
7941 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7942 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7943 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7944 .build());
7945 hasCoarsePermission =
7946 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7947 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007948
Jack Yu479f40e2020-10-27 21:29:25 -07007949 final Phone phone = getPhone(subId);
7950 if (phone == null) {
7951 return null;
7952 }
7953
Jordan Liu0f2bc442020-11-18 16:47:37 -08007954 final long identity = Binder.clearCallingIdentity();
7955
Jack Yu479f40e2020-10-27 21:29:25 -07007956 boolean isCallingPackageDataService = phone.getDataServicePackages()
7957 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007958 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007959 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7960 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7961 Rlog.d(LOG_TAG,
7962 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7963 return null;
7964 }
7965
Hall Liuf19c44f2018-11-27 14:38:17 -08007966 ServiceState ss = phone.getServiceState();
7967
7968 // Scrub out the location info in ServiceState depending on what level of access
7969 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007970 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007971 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7972 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007973 } finally {
7974 Binder.restoreCallingIdentity(identity);
7975 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007976 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007977
7978 /**
7979 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7980 *
7981 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7982 * voicemail ringtone.
7983 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7984 * PhoneAccount.
7985 */
7986 @Override
7987 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007988 final long identity = Binder.clearCallingIdentity();
7989 try {
7990 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7991 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007992 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007993 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007994
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007995 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7996 } finally {
7997 Binder.restoreCallingIdentity(identity);
7998 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007999 }
8000
8001 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008002 * Sets the per-account voicemail ringtone.
8003 *
8004 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8005 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8006 *
8007 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8008 * voicemail ringtone.
8009 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8010 * PhoneAccount.
8011 */
8012 @Override
8013 public void setVoicemailRingtoneUri(String callingPackage,
8014 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008015 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008016 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008017 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8018 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008019 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8020 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8021 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008022 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008023
8024 final long identity = Binder.clearCallingIdentity();
8025 try {
8026 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8027 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008028 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008029 }
8030 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8031 } finally {
8032 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008033 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008034 }
8035
8036 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008037 * Returns whether vibration is set for voicemail notification in Phone settings.
8038 *
8039 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8040 * voicemail vibration setting.
8041 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8042 */
8043 @Override
8044 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008045 final long identity = Binder.clearCallingIdentity();
8046 try {
8047 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8048 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008049 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008050 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008051
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008052 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8053 } finally {
8054 Binder.restoreCallingIdentity(identity);
8055 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008056 }
8057
Youhan Wange64578a2016-05-02 15:32:42 -07008058 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008059 * Sets the per-account voicemail vibration.
8060 *
8061 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8062 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8063 *
8064 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8065 * voicemail vibration setting.
8066 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8067 * specific PhoneAccount.
8068 */
8069 @Override
8070 public void setVoicemailVibrationEnabled(String callingPackage,
8071 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008072 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008073 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008074 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8075 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008076 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8077 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8078 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008079 }
8080
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008081 final long identity = Binder.clearCallingIdentity();
8082 try {
8083 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8084 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008085 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008086 }
8087 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8088 } finally {
8089 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008090 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008091 }
8092
8093 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008094 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8095 *
8096 * @throws SecurityException if the caller does not have the required permission
8097 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008098 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008099 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008100 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008101 }
8102
8103 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008104 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8105 * permission.
8106 *
8107 * @throws SecurityException if the caller does not have the required permission
8108 */
8109 private void enforceSendSmsPermission() {
8110 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8111 }
8112
8113 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008114 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008115 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008116 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008117 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008118 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008119 final long identity = Binder.clearCallingIdentity();
8120 try {
8121 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008122 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008123 if (componentName == null) {
8124 throw new SecurityException(
8125 "Caller not current active visual voicemail package[null]");
8126 }
8127 String vvmPackage = componentName.getPackageName();
8128 if (!callingPackage.equals(vvmPackage)) {
8129 throw new SecurityException("Caller not current active visual voicemail package["
8130 + vvmPackage + "]");
8131 }
8132 } finally {
8133 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008134 }
8135 }
8136
8137 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008138 * Return the application ID for the app type.
8139 *
8140 * @param subId the subscription ID that this request applies to.
8141 * @param appType the uicc app type.
8142 * @return Application ID for specificied app type, or null if no uicc.
8143 */
8144 @Override
8145 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008146 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008147 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008148
8149 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008150 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008151 if (phone == null) {
8152 return null;
8153 }
8154 String aid = null;
8155 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008156 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008157 .getApplicationByType(appType).getAid();
8158 } catch (Exception e) {
8159 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8160 }
8161 return aid;
8162 } finally {
8163 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008164 }
Youhan Wange64578a2016-05-02 15:32:42 -07008165 }
8166
Youhan Wang4001d252016-05-11 10:29:41 -07008167 /**
8168 * Return the Electronic Serial Number.
8169 *
8170 * @param subId the subscription ID that this request applies to.
8171 * @return ESN or null if error.
8172 */
8173 @Override
8174 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008175 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008176 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008177
8178 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008179 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008180 if (phone == null) {
8181 return null;
8182 }
8183 String esn = null;
8184 try {
8185 esn = phone.getEsn();
8186 } catch (Exception e) {
8187 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8188 }
8189 return esn;
8190 } finally {
8191 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008192 }
Youhan Wang4001d252016-05-11 10:29:41 -07008193 }
8194
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008195 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008196 * Return the Preferred Roaming List Version.
8197 *
8198 * @param subId the subscription ID that this request applies to.
8199 * @return PRLVersion or null if error.
8200 */
8201 @Override
8202 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008203 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008204 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008205
8206 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008207 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008208 if (phone == null) {
8209 return null;
8210 }
8211 String cdmaPrlVersion = null;
8212 try {
8213 cdmaPrlVersion = phone.getCdmaPrlVersion();
8214 } catch (Exception e) {
8215 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8216 }
8217 return cdmaPrlVersion;
8218 } finally {
8219 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008220 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008221 }
8222
8223 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008224 * Get snapshot of Telephony histograms
8225 * @return List of Telephony histograms
8226 * @hide
8227 */
8228 @Override
8229 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008230 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8231 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008232
8233 final long identity = Binder.clearCallingIdentity();
8234 try {
8235 return RIL.getTelephonyRILTimingHistograms();
8236 } finally {
8237 Binder.restoreCallingIdentity(identity);
8238 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008239 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008240
8241 /**
8242 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008243 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8244 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008245 * Require system privileges. In the future we may add this to carrier APIs.
8246 *
Michele Berionne482f8202018-11-27 18:57:59 -08008247 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008248 */
8249 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008250 @TelephonyManager.SetCarrierRestrictionResult
8251 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008252 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008253 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008254
Michele Berionne482f8202018-11-27 18:57:59 -08008255 if (carrierRestrictionRules == null) {
8256 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008257 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008258
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008259 final long identity = Binder.clearCallingIdentity();
8260 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008261 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008262 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008263 } finally {
8264 Binder.restoreCallingIdentity(identity);
8265 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008266 }
8267
8268 /**
8269 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008270 * Get the allowed carrier list and the excluded carrier list, including the priority between
8271 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008272 * Require system privileges. In the future we may add this to carrier APIs.
8273 *
Michele Berionne482f8202018-11-27 18:57:59 -08008274 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008275 */
8276 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008277 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008278 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008279 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008280
8281 final long identity = Binder.clearCallingIdentity();
8282 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008283 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8284 if (response instanceof CarrierRestrictionRules) {
8285 return (CarrierRestrictionRules) response;
8286 }
8287 // Response is an Exception of some kind,
8288 // which is signalled to the user as a NULL retval
8289 return null;
8290 } catch (Exception e) {
8291 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8292 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008293 } finally {
8294 Binder.restoreCallingIdentity(identity);
8295 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008296 }
8297
fionaxu59545b42016-05-25 15:53:37 -07008298 /**
fionaxu59545b42016-05-25 15:53:37 -07008299 * Action set from carrier signalling broadcast receivers to enable/disable radio
8300 * @param subId the subscription ID that this action applies to.
8301 * @param enabled control enable or disable radio.
8302 * {@hide}
8303 */
8304 @Override
8305 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8306 enforceModifyPermission();
8307 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008308
8309 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008310 if (phone == null) {
8311 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8312 return;
8313 }
8314 try {
8315 phone.carrierActionSetRadioEnabled(enabled);
8316 } catch (Exception e) {
8317 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008318 } finally {
8319 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008320 }
8321 }
8322
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008323 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008324 * Enable or disable Voice over NR (VoNR)
8325 * @param subId the subscription ID that this action applies to.
8326 * @param enabled enable or disable VoNR.
8327 * @return operation result.
8328 */
8329 @Override
8330 public int setVoNrEnabled(int subId, boolean enabled) {
8331 enforceModifyPermission();
8332 final Phone phone = getPhone(subId);
8333
8334 final long identity = Binder.clearCallingIdentity();
8335 if (phone == null) {
8336 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8337 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8338 }
8339
8340 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8341 try {
8342 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8343 workSource);
8344 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008345
8346 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8347 if (DBG) {
8348 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8349 }
8350 SubscriptionManager.setSubscriptionProperty(
8351 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8352 (enabled ? "1" : "0"));
8353 }
8354
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008355 return result;
8356 } finally {
8357 Binder.restoreCallingIdentity(identity);
8358 }
8359 }
8360
8361 /**
8362 * Is voice over NR enabled
8363 * @return true if VoNR is enabled else false
8364 */
8365 @Override
8366 public boolean isVoNrEnabled(int subId) {
8367 enforceReadPrivilegedPermission("isVoNrEnabled");
8368 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8369 final long identity = Binder.clearCallingIdentity();
8370 try {
8371 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8372 null, subId, workSource);
8373 if (DBG) log("isVoNrEnabled: " + isEnabled);
8374 return isEnabled;
8375 } finally {
8376 Binder.restoreCallingIdentity(identity);
8377 }
8378 }
8379
8380 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008381 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8382 * network status based on which carrier apps could apply actions accordingly,
8383 * enable/disable default url handler for example.
8384 *
8385 * @param subId the subscription ID that this action applies to.
8386 * @param report control start/stop reporting the default network status.
8387 * {@hide}
8388 */
8389 @Override
8390 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8391 enforceModifyPermission();
8392 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008393
8394 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008395 if (phone == null) {
8396 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8397 return;
8398 }
8399 try {
8400 phone.carrierActionReportDefaultNetworkStatus(report);
8401 } catch (Exception e) {
8402 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008403 } finally {
8404 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008405 }
8406 }
8407
8408 /**
fionaxud9622282017-07-17 17:51:30 -07008409 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8410 * @param subId the subscription ID that this action applies to.
8411 * {@hide}
8412 */
8413 @Override
8414 public void carrierActionResetAll(int subId) {
8415 enforceModifyPermission();
8416 final Phone phone = getPhone(subId);
8417 if (phone == null) {
8418 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8419 return;
8420 }
8421 try {
8422 phone.carrierActionResetAll();
8423 } catch (Exception e) {
8424 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8425 }
8426 }
8427
8428 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008429 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8430 * bug report is being generated.
8431 */
8432 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008433 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008434 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8435 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008436 writer.println("Permission Denial: can't dump Phone from pid="
8437 + Binder.getCallingPid()
8438 + ", uid=" + Binder.getCallingUid()
8439 + "without permission "
8440 + android.Manifest.permission.DUMP);
8441 return;
8442 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008443 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008444 }
Jack Yueb89b242016-06-22 13:27:47 -07008445
Brad Ebingerdac2f002018-04-03 15:17:52 -07008446 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008447 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8448 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8449 @NonNull String[] args) {
8450 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8451 this, in.getFileDescriptor(), out.getFileDescriptor(),
8452 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008453 }
8454
Jack Yueb89b242016-06-22 13:27:47 -07008455 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008456 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008457 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008458 * @param reason the reason the data enable change is taking place
8459 * @param enabled True if enabling the data, otherwise disabling.
8460 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008461 */
8462 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008463 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008464 boolean enabled) {
8465 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8466 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8467 try {
8468 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008469 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008470 } catch (SecurityException se) {
8471 enforceModifyPermission();
8472 }
8473 } else {
8474 enforceModifyPermission();
8475 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008476
8477 final long identity = Binder.clearCallingIdentity();
8478 try {
8479 Phone phone = getPhone(subId);
8480 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008481 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8482 phone.carrierActionSetMeteredApnsEnabled(enabled);
8483 } else {
Jack Yu99e87332021-12-17 23:14:15 -08008484 if (phone.isUsingNewDataStack()) {
8485 phone.getDataSettingsManager().setDataEnabled(reason, enabled);
8486 } else {
8487 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8488 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008489 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008490 }
8491 } finally {
8492 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008493 }
8494 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008495
8496 /**
8497 * Get Client request stats
8498 * @return List of Client Request Stats
8499 * @hide
8500 */
8501 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008502 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8503 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008504 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008505 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008506 return null;
8507 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008508 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008509
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008510 final long identity = Binder.clearCallingIdentity();
8511 try {
8512 if (phone != null) {
8513 return phone.getClientRequestStats();
8514 }
8515
8516 return null;
8517 } finally {
8518 Binder.restoreCallingIdentity(identity);
8519 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008520 }
8521
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008522 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008523 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008524 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008525 }
Jack Yueb4124c2017-02-16 15:32:43 -08008526
8527 /**
Grace Chen70990072017-03-24 17:21:30 -07008528 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008529 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008530 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008531 * @param state State of SIM (power down, power up, pass through)
8532 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8533 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8534 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008535 *
8536 **/
8537 @Override
Grace Chen70990072017-03-24 17:21:30 -07008538 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008539 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008540 Phone phone = PhoneFactory.getPhone(slotIndex);
8541
vagdeviaf9a5b92018-08-15 16:01:53 -07008542 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8543
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008544 final long identity = Binder.clearCallingIdentity();
8545 try {
8546 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008547 phone.setSimPowerState(state, null, workSource);
8548 }
8549 } finally {
8550 Binder.restoreCallingIdentity(identity);
8551 }
8552 }
8553
8554 /**
8555 * Set SIM card power state.
8556 *
8557 * @param slotIndex SIM slot id.
8558 * @param state State of SIM (power down, power up, pass through)
8559 * @param callback callback to trigger after success or failure
8560 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8561 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8562 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8563 *
8564 **/
8565 @Override
8566 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8567 IIntegerConsumer callback) {
8568 enforceModifyPermission();
8569 Phone phone = PhoneFactory.getPhone(slotIndex);
8570
8571 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8572
8573 final long identity = Binder.clearCallingIdentity();
8574 try {
8575 if (phone != null) {
8576 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8577 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008578 }
8579 } finally {
8580 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008581 }
8582 }
Shuo Qiandd210312017-04-12 22:11:33 +00008583
Tyler Gunn65d45c22017-06-05 11:22:26 -07008584 private boolean isUssdApiAllowed(int subId) {
8585 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008586 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008587 if (configManager == null) {
8588 return false;
8589 }
8590 PersistableBundle pb = configManager.getConfigForSubId(subId);
8591 if (pb == null) {
8592 return false;
8593 }
8594 return pb.getBoolean(
8595 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8596 }
8597
Shuo Qiandd210312017-04-12 22:11:33 +00008598 /**
8599 * Check if phone is in emergency callback mode
8600 * @return true if phone is in emergency callback mode
8601 * @param subId sub id
8602 */
goneil9c5f4872017-12-05 14:07:56 -08008603 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008604 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008605 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008606 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008607
8608 final long identity = Binder.clearCallingIdentity();
8609 try {
8610 if (phone != null) {
8611 return phone.isInEcm();
8612 } else {
8613 return false;
8614 }
8615 } finally {
8616 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008617 }
8618 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008619
8620 /**
8621 * Get the current signal strength information for the given subscription.
8622 * Because this information is not updated when the device is in a low power state
8623 * it should not be relied-upon to be current.
8624 * @param subId Subscription index
8625 * @return the most recent cached signal strength info from the modem
8626 */
8627 @Override
8628 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008629 final long identity = Binder.clearCallingIdentity();
8630 try {
8631 Phone p = getPhone(subId);
8632 if (p == null) {
8633 return null;
8634 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008635
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008636 return p.getSignalStrength();
8637 } finally {
8638 Binder.restoreCallingIdentity(identity);
8639 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008640 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008641
Pengquan Meng77b7f132018-08-22 14:49:57 -07008642 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008643 * Get the current modem radio state for the given slot.
8644 * @param slotIndex slot index.
8645 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008646 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008647 * @return the current radio power state from the modem
8648 */
8649 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008650 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008651 Phone phone = PhoneFactory.getPhone(slotIndex);
8652 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008653 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8654 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008655 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8656 }
8657
8658 final long identity = Binder.clearCallingIdentity();
8659 try {
8660 return phone.getRadioPowerState();
8661 } finally {
8662 Binder.restoreCallingIdentity(identity);
8663 }
8664 }
8665 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8666 }
8667
8668 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008669 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8670 *
8671 * <p>Requires one of the following permissions:
8672 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008673 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008674 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8675 * privileges.
8676 *
8677 * @param subId subscription id
8678 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8679 * {@code false}.
8680 */
8681 @Override
8682 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008683 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008684 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008685 try {
8686 mApp.enforceCallingOrSelfPermission(
8687 android.Manifest.permission.ACCESS_NETWORK_STATE,
8688 functionName);
8689 } catch (Exception e) {
8690 mApp.enforceCallingOrSelfPermission(
8691 permission.READ_BASIC_PHONE_STATE, functionName);
8692 }
Shuo Qian093013d2020-08-13 15:42:55 -07008693 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008694 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008695 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008696 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008697
Pengquan Menga1bb6272018-09-06 09:59:22 -07008698 boolean isEnabled = false;
8699 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008700 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008701 Phone phone = getPhone(subId);
8702 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008703 } finally {
8704 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008705 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008706 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008707 }
8708
8709
8710 /**
8711 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8712 *
8713 * <p> Requires permission:
8714 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8715 * privileges.
8716 *
8717 * @param subId subscription id
8718 * @param isEnabled {@code true} means enable, {@code false} means disable.
8719 */
8720 @Override
8721 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008722 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8723 mApp, subId, "setDataRoamingEnabled");
8724
Pengquan Menga1bb6272018-09-06 09:59:22 -07008725 final long identity = Binder.clearCallingIdentity();
8726 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008727 Phone phone = getPhone(subId);
8728 if (phone != null) {
8729 phone.setDataRoamingEnabled(isEnabled);
8730 }
8731 } finally {
8732 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008733 }
8734 }
8735
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008736 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008737 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008738 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008739 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008740 mApp, subId, "isManualNetworkSelectionAllowed");
8741
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008742 boolean isAllowed = true;
8743 final long identity = Binder.clearCallingIdentity();
8744 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008745 Phone phone = getPhone(subId);
8746 if (phone != null) {
8747 isAllowed = phone.isCspPlmnEnabled();
8748 }
8749 } finally {
8750 Binder.restoreCallingIdentity(identity);
8751 }
8752 return isAllowed;
8753 }
8754
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008755 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8756 UiccProfile profile = port.getUiccProfile();
8757 if (profile == null ||
8758 profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8759 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8760 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008761 }
8762 return true;
8763 }
8764
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008765 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008766 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008767 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008768 mApp.getSystemService(AppOpsManager.class)
8769 .checkPackage(Binder.getCallingUid(), callingPackage);
8770
Jordan Liu1e142fc2019-04-22 15:10:43 -07008771 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008772 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008773 try {
8774 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008775 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008776 } catch (SecurityException e) {
8777 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8778 // has carrier privileges on an active UICC
8779 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8780 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008781 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008782 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008783 }
sandeepjsb6c87872021-09-27 15:34:44 +00008784 // checking compatibility, if calling app's target SDK is T and beyond.
8785 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8786 Binder.getCallingUid())) {
8787 isIccIdAccessRestricted = true;
8788 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008789 final long identity = Binder.clearCallingIdentity();
8790 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008791 UiccController uiccController = UiccController.getInstance();
8792 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008793 if (hasReadPermission) {
8794 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008795 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008796
8797 // Remove private info if the caller doesn't have access
8798 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8799 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008800 //setting the value after compatibility check
8801 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008802 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8803 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008804 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008805 if (card == null) {
8806 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008807 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008808 continue;
8809 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008810 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8811 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008812 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008813 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008814 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008815 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8816 for (UiccPortInfo portInfo : portInfos) {
8817 UiccPort port = uiccController.getUiccPortForSlot(
8818 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8819 if (port == null) {
8820 // assume no access if port is null
8821 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8822 continue;
8823 }
8824 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8825 uiccPortInfos.add(portInfo);
8826 } else {
8827 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8828 }
8829 }
8830 filteredInfos.add(new UiccCardInfo(
8831 cardInfo.isEuicc(),
8832 cardInfo.getCardId(),
8833 null,
8834 cardInfo.getPhysicalSlotIndex(),
8835 cardInfo.isRemovable(),
8836 cardInfo.isMultipleEnabledProfilesSupported(),
8837 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008838 }
8839 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008840 } finally {
8841 Binder.restoreCallingIdentity(identity);
8842 }
8843 }
8844
sandeepjsb6c87872021-09-27 15:34:44 +00008845 /**
8846 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8847 * generally private and require carrier privileges to view.
8848 *
8849 * @hide
8850 */
8851 @NonNull
8852 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8853 List<UiccPortInfo> portinfo = new ArrayList<>();
8854 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8855 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8856 }
8857 return new UiccCardInfo(
8858 cardInfo.isEuicc(),
8859 cardInfo.getCardId(),
8860 null,
8861 cardInfo.getPhysicalSlotIndex(),
8862 cardInfo.isRemovable(),
8863 cardInfo.isMultipleEnabledProfilesSupported(),
8864 portinfo
8865 );
8866 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008867
sandeepjsb6c87872021-09-27 15:34:44 +00008868 /**
8869 * @hide
8870 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8871 * These values are generally private and require carrier privileges to view.
8872 */
8873 @NonNull
8874 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8875 return new UiccPortInfo(
8876 UiccPortInfo.ICCID_REDACTED,
8877 portInfo.getPortIndex(),
8878 portInfo.getLogicalSlotIndex(),
8879 portInfo.isActive()
8880 );
8881 }
8882 @Override
8883 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008884 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00008885 mApp.getSystemService(AppOpsManager.class)
8886 .checkPackage(Binder.getCallingUid(), callingPackage);
8887
8888 boolean hasReadPermission = false;
8889 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008890
8891 try {
8892 enforceReadPrivilegedPermission("getUiccSlotsInfo");
8893 hasReadPermission = true;
8894 } catch (SecurityException e) {
8895 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8896 // has carrier privileges on an active UICC
8897 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8898 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8899 hasReadPermission = true;
8900 }
8901 }
8902
8903 // checking compatibility, if calling app's target SDK is T and beyond.
8904 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8905 Binder.getCallingUid())) {
8906 isLogicalSlotAccessRestricted = true;
8907 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008908 final long identity = Binder.clearCallingIdentity();
8909 try {
8910 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00008911 if (slots == null || slots.length == 0) {
8912 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008913 return null;
8914 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008915 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8916 for (int i = 0; i < slots.length; i++) {
8917 UiccSlot slot = slots[i];
8918 if (slot == null) {
8919 continue;
8920 }
8921
Jordan Liu7be7e652019-05-06 18:55:02 +00008922 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008923 UiccCard card = slot.getUiccCard();
8924 if (card != null) {
8925 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008926 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008927 cardId = slot.getEid();
8928 if (TextUtils.isEmpty(cardId)) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008929 // If cardId is null, use iccId of default port as cardId. Check if has
8930 // read permission otherwise set to null.(card is null which means no
8931 // carrier permission)
8932 cardId = hasReadPermission ? slot.getIccId(
8933 TelephonyManager.DEFAULT_PORT_INDEX) : null;
Jordan Liu01bd00d2019-09-12 16:19:43 -07008934 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008935 }
8936
Jordan Liu857451f2019-05-09 16:35:35 -07008937 if (cardId != null) {
8938 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8939 // if cardId is an EID, it's all digits so this is fine
8940 cardId = IccUtils.stripTrailingFs(cardId);
8941 }
8942
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008943 int cardState = 0;
8944 switch (slot.getCardState()) {
8945 case CARDSTATE_ABSENT:
8946 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8947 break;
8948 case CARDSTATE_PRESENT:
8949 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8950 break;
8951 case CARDSTATE_ERROR:
8952 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8953 break;
8954 case CARDSTATE_RESTRICTED:
8955 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8956 break;
8957 default:
8958 break;
8959
8960 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008961 List<UiccPortInfo> portInfos = new ArrayList<>();
8962 int[] portIndexes = slot.getPortList();
8963 for (int portIdx : portIndexes) {
8964 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
8965 callingPackage, hasReadPermission));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00008966 portInfos.add(new UiccPortInfo(iccId, portIdx,
8967 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008968 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008969 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008970 slot.isEuicc(),
8971 cardId,
8972 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08008973 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008974 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00008975 //setting the value after compatibility check
8976 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008977 }
8978 return infos;
8979 } finally {
8980 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008981 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008982 }
8983
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008984 /* Returns null if doesn't have read permission or carrier privilege access. */
8985 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
8986 boolean hasReadPermission) {
8987 String iccId = slot.getIccId(portIndex);
8988 if (hasReadPermission) { // if has read permission
8989 return iccId;
8990 } else {
8991 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
8992 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
8993 // if no read permission, checking carrier privilege access
8994 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8995 return iccId;
8996 }
8997 }
8998 }
8999 // No read permission or carrier privilege access.
9000 return UiccPortInfo.ICCID_REDACTED;
9001 }
9002
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009003 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009004 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009005 public boolean switchSlots(int[] physicalSlots) {
9006 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009007
9008 final long identity = Binder.clearCallingIdentity();
9009 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009010 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9011 for (int i = 0; i < physicalSlots.length; i++) {
9012 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9013 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9014 physicalSlots[i], i));
9015 }
9016 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009017 } finally {
9018 Binder.restoreCallingIdentity(identity);
9019 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009020 }
Jack Yu4c988042018-02-27 15:30:01 -08009021
9022 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009023 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9024 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9025 enforceModifyPermission();
9026
9027 final long identity = Binder.clearCallingIdentity();
9028 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009029 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009030 } finally {
9031 Binder.restoreCallingIdentity(identity);
9032 }
9033 }
9034
9035 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009036 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009037 final long identity = Binder.clearCallingIdentity();
9038 try {
9039 return UiccController.getInstance().getCardIdForDefaultEuicc();
9040 } finally {
9041 Binder.restoreCallingIdentity(identity);
9042 }
9043 }
9044
Pengquan Meng85728fb2018-03-12 16:31:21 -07009045 /**
goneil47ffb6e2018-04-06 15:40:58 -07009046 * A test API to reload the UICC profile.
9047 *
9048 * <p>Requires that the calling app has permission
9049 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9050 * @hide
9051 */
9052 @Override
9053 public void refreshUiccProfile(int subId) {
9054 enforceModifyPermission();
9055
9056 final long identity = Binder.clearCallingIdentity();
9057 try {
9058 Phone phone = getPhone(subId);
9059 if (phone == null) {
9060 return;
9061 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009062 UiccPort uiccPort = phone.getUiccPort();
9063 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009064 return;
9065 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009066 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009067 if (uiccProfile == null) {
9068 return;
9069 }
9070 uiccProfile.refresh();
9071 } finally {
9072 Binder.restoreCallingIdentity(identity);
9073 }
9074 }
9075
9076 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009077 * Returns false if the mobile data is disabled by default, otherwise return true.
9078 */
9079 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009080 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009081 }
9082
9083 /**
9084 * Returns true if the data roaming is enabled by default, i.e the system property
9085 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9086 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9087 */
9088 private boolean getDefaultDataRoamingEnabled(int subId) {
9089 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009090 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009091 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009092 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9093 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9094 return isDataRoamingEnabled;
9095 }
9096
9097 /**
9098 * Returns the default network type for the given {@code subId}, if the default network type is
9099 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9100 */
9101 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009102 List<Integer> list = TelephonyProperties.default_network();
9103 int phoneId = mSubscriptionController.getPhoneId(subId);
9104 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9105 return list.get(phoneId);
9106 }
9107 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009108 }
fionaxua13278b2018-03-21 00:08:13 -07009109
9110 @Override
9111 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009112 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009113 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009114
9115 final long identity = Binder.clearCallingIdentity();
9116 try {
9117 final Phone phone = getPhone(subId);
9118 if (phone == null) {
9119 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9120 return;
9121 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009122 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9123 if (cpt != null) {
9124 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9125 }
9126 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009127 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9128 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009129 if (carrierPrivilegeRules == null) {
9130 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9131 } else {
9132 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9133 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009134 } finally {
9135 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009136 }
fionaxua13278b2018-03-21 00:08:13 -07009137 }
9138
9139 @Override
9140 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009141 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009142
9143 final long identity = Binder.clearCallingIdentity();
9144 try {
9145 final Phone phone = getPhone(subId);
9146 if (phone == null) {
9147 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9148 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9149 }
9150 return phone.getCarrierIdListVersion();
9151 } finally {
9152 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009153 }
fionaxua13278b2018-03-21 00:08:13 -07009154 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009155
9156 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009157 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9158 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009159 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009160 mApp, subId, callingPackage, callingFeatureId,
9161 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009162 return -1;
9163 }
9164
9165 final long identity = Binder.clearCallingIdentity();
9166 try {
9167 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9168 } finally {
9169 Binder.restoreCallingIdentity(identity);
9170 }
9171 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009172
9173 @Override
9174 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009175 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009176 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009177 mApp, subId, "getCdmaRoamingMode");
9178
9179 final long identity = Binder.clearCallingIdentity();
9180 try {
9181 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9182 } finally {
9183 Binder.restoreCallingIdentity(identity);
9184 }
9185 }
9186
9187 @Override
9188 public boolean setCdmaRoamingMode(int subId, int mode) {
9189 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9190 mApp, subId, "setCdmaRoamingMode");
9191
9192 final long identity = Binder.clearCallingIdentity();
9193 try {
9194 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9195 } finally {
9196 Binder.restoreCallingIdentity(identity);
9197 }
9198 }
9199
9200 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009201 public int getCdmaSubscriptionMode(int subId) {
9202 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009203 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009204 mApp, subId, "getCdmaSubscriptionMode");
9205
9206 final long identity = Binder.clearCallingIdentity();
9207 try {
9208 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9209 } finally {
9210 Binder.restoreCallingIdentity(identity);
9211 }
9212 }
9213
9214 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009215 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9216 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9217 mApp, subId, "setCdmaSubscriptionMode");
9218
9219 final long identity = Binder.clearCallingIdentity();
9220 try {
9221 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9222 } finally {
9223 Binder.restoreCallingIdentity(identity);
9224 }
9225 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009226
sqianc5eccab2018-10-19 18:46:41 -07009227 @Override
sqian8c685422019-02-22 15:55:18 -08009228 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009229 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009230 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009231 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9232 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009233 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9234 }
9235 final long identity = Binder.clearCallingIdentity();
9236 try {
sqian854d44b2018-12-12 16:48:18 -08009237 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9238 for (Phone phone: PhoneFactory.getPhones()) {
9239 if (phone.getEmergencyNumberTracker() != null
9240 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9241 emergencyNumberListInternal.put(
9242 phone.getSubId(),
9243 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9244 }
sqian11b7a0e2018-12-05 18:48:28 -08009245 }
sqian854d44b2018-12-12 16:48:18 -08009246 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009247 } finally {
9248 Binder.restoreCallingIdentity(identity);
9249 }
sqianc5eccab2018-10-19 18:46:41 -07009250 }
9251
9252 @Override
sqian8c685422019-02-22 15:55:18 -08009253 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009254 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009255 if (!exactMatch) {
9256 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009257 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009258 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009259 }
9260 final long identity = Binder.clearCallingIdentity();
9261 try {
sqian854d44b2018-12-12 16:48:18 -08009262 for (Phone phone: PhoneFactory.getPhones()) {
9263 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009264 && phone.getEmergencyNumberTracker()
9265 .isEmergencyNumber(number, exactMatch)) {
9266 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009267 }
sqian11b7a0e2018-12-05 18:48:28 -08009268 }
9269 return false;
9270 } finally {
9271 Binder.restoreCallingIdentity(identity);
9272 }
9273 }
9274
sqianf4ca7ed2019-01-15 18:32:07 -08009275 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009276 * Start emergency callback mode for GsmCdmaPhone for testing.
9277 */
9278 @Override
9279 public void startEmergencyCallbackMode() {
9280 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9281 "startEmergencyCallbackMode");
9282 enforceModifyPermission();
9283 final long identity = Binder.clearCallingIdentity();
9284 try {
9285 for (Phone phone : PhoneFactory.getPhones()) {
9286 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9287 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9288 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9289 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9290 gsmCdmaPhone.obtainMessage(
9291 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9292 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9293 }
9294 }
9295 } finally {
9296 Binder.restoreCallingIdentity(identity);
9297 }
9298 }
9299
9300 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009301 * Update emergency number list for test mode.
9302 */
9303 @Override
9304 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9305 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9306 "updateEmergencyNumberListTestMode");
9307
9308 final long identity = Binder.clearCallingIdentity();
9309 try {
9310 for (Phone phone: PhoneFactory.getPhones()) {
9311 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9312 if (tracker != null) {
9313 tracker.executeEmergencyNumberTestModeCommand(action, num);
9314 }
9315 }
9316 } finally {
9317 Binder.restoreCallingIdentity(identity);
9318 }
9319 }
9320
9321 /**
9322 * Get the full emergency number list for test mode.
9323 */
9324 @Override
9325 public List<String> getEmergencyNumberListTestMode() {
9326 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9327 "getEmergencyNumberListTestMode");
9328
9329 final long identity = Binder.clearCallingIdentity();
9330 try {
9331 Set<String> emergencyNumbers = new HashSet<>();
9332 for (Phone phone: PhoneFactory.getPhones()) {
9333 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9334 if (tracker != null) {
9335 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9336 emergencyNumbers.add(num.getNumber());
9337 }
9338 }
9339 }
9340 return new ArrayList<>(emergencyNumbers);
9341 } finally {
9342 Binder.restoreCallingIdentity(identity);
9343 }
9344 }
9345
chen xud6b45bd2018-10-30 22:27:10 -07009346 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009347 public int getEmergencyNumberDbVersion(int subId) {
9348 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9349
9350 final long identity = Binder.clearCallingIdentity();
9351 try {
9352 final Phone phone = getPhone(subId);
9353 if (phone == null) {
9354 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9355 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9356 }
9357 return phone.getEmergencyNumberDbVersion();
9358 } finally {
9359 Binder.restoreCallingIdentity(identity);
9360 }
9361 }
9362
9363 @Override
9364 public void notifyOtaEmergencyNumberDbInstalled() {
9365 enforceModifyPermission();
9366
9367 final long identity = Binder.clearCallingIdentity();
9368 try {
9369 for (Phone phone: PhoneFactory.getPhones()) {
9370 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9371 if (tracker != null) {
9372 tracker.updateOtaEmergencyNumberDatabase();
9373 }
9374 }
9375 } finally {
9376 Binder.restoreCallingIdentity(identity);
9377 }
9378 }
9379
9380 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009381 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009382 enforceActiveEmergencySessionPermission();
9383
9384 final long identity = Binder.clearCallingIdentity();
9385 try {
9386 for (Phone phone: PhoneFactory.getPhones()) {
9387 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9388 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009389 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9390 }
9391 }
9392 } finally {
9393 Binder.restoreCallingIdentity(identity);
9394 }
9395 }
9396
9397 @Override
9398 public void resetOtaEmergencyNumberDbFilePath() {
9399 enforceActiveEmergencySessionPermission();
9400
9401 final long identity = Binder.clearCallingIdentity();
9402 try {
9403 for (Phone phone: PhoneFactory.getPhones()) {
9404 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9405 if (tracker != null) {
9406 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009407 }
9408 }
9409 } finally {
9410 Binder.restoreCallingIdentity(identity);
9411 }
9412 }
9413
9414 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009415 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9416 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9417 Phone phone = getPhone(subId);
9418 if (phone == null) {
9419 return null;
9420 }
9421 final long identity = Binder.clearCallingIdentity();
9422 try {
9423 UiccProfile profile = UiccController.getInstance()
9424 .getUiccProfileForPhone(phone.getPhoneId());
9425 if (profile != null) {
9426 return profile.getCertsFromCarrierPrivilegeAccessRules();
9427 }
9428 } finally {
9429 Binder.restoreCallingIdentity(identity);
9430 }
9431 return null;
9432 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009433
9434 /**
9435 * Enable or disable a modem stack.
9436 */
9437 @Override
9438 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9439 enforceModifyPermission();
9440
9441 final long identity = Binder.clearCallingIdentity();
9442 try {
9443 Phone phone = PhoneFactory.getPhone(slotIndex);
9444 if (phone == null) {
9445 return false;
9446 } else {
9447 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9448 }
9449 } finally {
9450 Binder.restoreCallingIdentity(identity);
9451 }
9452 }
Michelecea4cf22018-12-21 15:00:11 -08009453
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009454 /**
9455 * Whether a modem stack is enabled or not.
9456 */
9457 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009458 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9459 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009460 Phone phone = PhoneFactory.getPhone(slotIndex);
9461 if (phone == null) return false;
9462
9463 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009464 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9465 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009466 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9467 }
9468
9469 final long identity = Binder.clearCallingIdentity();
9470 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009471 try {
9472 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9473 } catch (NoSuchElementException ex) {
9474 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9475 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009476 } finally {
9477 Binder.restoreCallingIdentity(identity);
9478 }
9479 }
9480
Michelecea4cf22018-12-21 15:00:11 -08009481 @Override
Michele0ea7d782019-03-19 14:58:42 -07009482 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009483 enforceModifyPermission();
9484
9485 final long identity = Binder.clearCallingIdentity();
9486 try {
9487 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009488 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009489 .commit();
9490 } finally {
9491 Binder.restoreCallingIdentity(identity);
9492 }
9493 }
9494
9495 @Override
Michele0ea7d782019-03-19 14:58:42 -07009496 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009497 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009498 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009499 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9500 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009501 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009502 }
Michelecea4cf22018-12-21 15:00:11 -08009503
9504 final long identity = Binder.clearCallingIdentity();
9505 try {
Michele0ea7d782019-03-19 14:58:42 -07009506 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009507 } finally {
9508 Binder.restoreCallingIdentity(identity);
9509 }
9510 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009511
Michele0ea7d782019-03-19 14:58:42 -07009512 @TelephonyManager.IsMultiSimSupportedResult
9513 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009514 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9515 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9516 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009517 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9518 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009519 }
9520 // Check if the hardware supports multisim functionality. If usage of multisim is not
9521 // supported by the modem, indicate that it is restricted.
9522 PhoneCapability staticCapability =
9523 mPhoneConfigurationManager.getStaticPhoneCapability();
9524 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009525 loge("isMultiSimSupportedInternal: no static configuration available");
9526 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009527 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009528 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009529 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9530 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009531 }
9532 // Check if support of multiple SIMs is restricted by carrier
9533 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009534 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009535 }
9536
Michele0ea7d782019-03-19 14:58:42 -07009537 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009538 }
9539
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009540 /**
9541 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009542 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9543 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9544 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009545 * @param numOfSims number of active sims we want to switch to
9546 */
9547 @Override
9548 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009549 if (numOfSims == 1) {
9550 enforceModifyPermission();
9551 } else {
9552 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9553 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9554 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009555 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009556
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009557 try {
Michele30b57b22019-03-01 12:01:14 -08009558 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009559 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009560 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9561 return;
9562 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009563 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9564 } finally {
9565 Binder.restoreCallingIdentity(identity);
9566 }
9567 }
9568
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009569 @Override
9570 public boolean isApplicationOnUicc(int subId, int appType) {
9571 enforceReadPrivilegedPermission("isApplicationOnUicc");
9572 Phone phone = getPhone(subId);
9573 if (phone == null) {
9574 return false;
9575 }
9576 final long identity = Binder.clearCallingIdentity();
9577 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009578 UiccPort uiccPort = phone.getUiccPort();
9579 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009580 return false;
9581 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009582 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009583 if (uiccProfile == null) {
9584 return false;
9585 }
9586 if (TelephonyManager.APPTYPE_SIM <= appType
9587 && appType <= TelephonyManager.APPTYPE_ISIM) {
9588 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9589 }
9590 return false;
9591 } finally {
9592 Binder.restoreCallingIdentity(identity);
9593 }
9594 }
9595
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009596 /**
chen xub4baa772019-04-03 10:23:41 -07009597 * Get whether making changes to modem configurations will trigger reboot.
9598 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009599 */
9600 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009601 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9602 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009603 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009604 mApp, subId, callingPackage, callingFeatureId,
9605 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009606 return false;
9607 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009608 final long identity = Binder.clearCallingIdentity();
9609 try {
9610 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9611 } finally {
9612 Binder.restoreCallingIdentity(identity);
9613 }
9614 }
9615
Nathan Harold29f5f052019-02-15 13:41:57 -08009616 private void updateModemStateMetrics() {
9617 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9618 // TODO: check the state for each modem if the api is ready.
9619 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9620 }
9621
Pengquan Meng3889a572019-01-23 11:16:29 -08009622 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009623 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009624 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009625 // Verify that the callingPackage belongs to the calling UID
9626 mApp.getSystemService(AppOpsManager.class)
9627 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009628 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009629 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009630 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009631 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9632 if (slotInfos != null) {
9633 for (int i = 0; i < slotInfos.length; i++) {
9634 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9635 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9636 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9637 portInfo.getLogicalSlotIndex()));
9638 }
9639 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009640 }
9641 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009642 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009643 } finally {
9644 Binder.restoreCallingIdentity(identity);
9645 }
9646 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009647
9648 /**
9649 * Get the IRadio HAL Version
9650 */
9651 @Override
9652 public int getRadioHalVersion() {
9653 Phone phone = getDefaultPhone();
9654 if (phone == null) return -1;
9655 HalVersion hv = phone.getHalVersion();
9656 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9657 return hv.major * 100 + hv.minor;
9658 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009659
9660 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009661 * Get the current calling package name.
9662 * @return the current calling package name
9663 */
9664 @Override
9665 public String getCurrentPackageName() {
9666 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9667 }
9668
9669 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009670 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9671 * corresponding network requests on a subId.
9672 *
9673 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009674 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009675 * 2) APN is un-metered for this subscription, or
9676 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009677 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009678 *
9679 * @return whether data is allowed for a apn type.
9680 *
9681 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009682 */
9683 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009684 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009685 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9686 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009687
9688 // Now that all security checks passes, perform the operation as ourselves.
9689 final long identity = Binder.clearCallingIdentity();
9690 try {
9691 Phone phone = getPhone(subId);
9692 if (phone == null) return false;
9693
Jack Yu41407ee2019-05-13 16:54:09 -07009694 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Jack Yu99e87332021-12-17 23:14:15 -08009695 boolean isDataEnabled;
9696 if (phone.isUsingNewDataStack()) {
9697 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
9698 } else {
9699 isDataEnabled = phone.getDataEnabledSettings().isDataEnabled(apnType);
9700 }
9701 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009702 } finally {
9703 Binder.restoreCallingIdentity(identity);
9704 }
9705 }
9706
9707 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009708 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009709 enforceReadPrivilegedPermission("isApnMetered");
9710
9711 // Now that all security checks passes, perform the operation as ourselves.
9712 final long identity = Binder.clearCallingIdentity();
9713 try {
9714 Phone phone = getPhone(subId);
9715 if (phone == null) return true; // By default return true.
9716
Jack Yu41407ee2019-05-13 16:54:09 -07009717 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009718 } finally {
9719 Binder.restoreCallingIdentity(identity);
9720 }
9721 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009722
9723 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009724 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9725 int subscriptionId, IBooleanConsumer resultCallback) {
9726 enforceModifyPermission();
9727 long token = Binder.clearCallingIdentity();
9728 try {
9729 Phone phone = getPhone(subscriptionId);
9730 if (phone == null) {
9731 try {
9732 if (resultCallback != null) {
9733 resultCallback.accept(false);
9734 }
9735 } catch (RemoteException e) {
9736 // ignore
9737 }
9738 return;
9739 }
9740 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9741 Pair.create(specifiers, (x) -> {
9742 try {
9743 if (resultCallback != null) {
9744 resultCallback.accept(x);
9745 }
9746 } catch (RemoteException e) {
9747 // ignore
9748 }
9749 });
9750 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9751 } finally {
9752 Binder.restoreCallingIdentity(token);
9753 }
9754 }
9755
9756 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009757 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9758 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009759 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009760 mApp, subId, "getSystemSelectionChannels");
9761 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9762 final long identity = Binder.clearCallingIdentity();
9763 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009764 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9765 if (result instanceof IllegalStateException) {
9766 throw (IllegalStateException) result;
9767 }
9768 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009769 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9770 return specifiers;
9771 } finally {
9772 Binder.restoreCallingIdentity(identity);
9773 }
9774 }
9775
9776 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009777 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009778 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009779 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9780 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9781 if (iccRecords == null) {
9782 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9783 return false;
9784 }
9785 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9786 }
9787
9788 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009789 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9790 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009791 if (callingPackage == null) {
9792 callingPackage = getCurrentPackageName();
9793 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009794 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9795 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009796 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9797 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009798 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9799 }
9800 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9801 Intent intent = new Intent();
9802 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9803 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9804 // Bring up choose default SMS subscription dialog right now
9805 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9806 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9807 mApp.startActivity(intent);
9808 }
chen xud5ca2d52019-05-28 15:20:57 -07009809
9810 @Override
9811 public String getMmsUAProfUrl(int subId) {
9812 //TODO investigate if this API should require proper permission check in R b/133791609
9813 final long identity = Binder.clearCallingIdentity();
9814 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009815 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9816 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9817 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9818 return carrierUAProfUrl;
9819 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009820 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9821 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009822 } finally {
9823 Binder.restoreCallingIdentity(identity);
9824 }
9825 }
9826
9827 @Override
9828 public String getMmsUserAgent(int subId) {
9829 //TODO investigate if this API should require proper permission check in R b/133791609
9830 final long identity = Binder.clearCallingIdentity();
9831 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009832 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9833 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9834 if (!TextUtils.isEmpty(carrierUserAgent)) {
9835 return carrierUserAgent;
9836 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009837 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9838 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009839 } finally {
9840 Binder.restoreCallingIdentity(identity);
9841 }
9842 }
Jack Yub07d4972019-05-28 16:12:25 -07009843
9844 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009845 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9846 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009847
Jack Yub07d4972019-05-28 16:12:25 -07009848 final long identity = Binder.clearCallingIdentity();
9849 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009850 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009851 if (phone == null) return false;
9852
Hall Liua62f5da2020-09-25 10:42:19 -07009853 switch (policy) {
9854 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu99e87332021-12-17 23:14:15 -08009855 if (phone.isUsingNewDataStack()) {
9856 return phone.getDataSettingsManager().isDataAllowedInVoiceCall();
9857 } else {
9858 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9859 }
Hall Liua62f5da2020-09-25 10:42:19 -07009860 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu99e87332021-12-17 23:14:15 -08009861 if (phone.isUsingNewDataStack()) {
9862 return phone.getDataSettingsManager().isMmsAlwaysAllowed();
9863 } else {
9864 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9865 }
Hall Liua62f5da2020-09-25 10:42:19 -07009866 default:
9867 throw new IllegalArgumentException(policy + " is not a valid policy");
9868 }
Jack Yub07d4972019-05-28 16:12:25 -07009869 } finally {
9870 Binder.restoreCallingIdentity(identity);
9871 }
9872 }
9873
9874 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009875 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009876 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009877 enforceModifyPermission();
9878
changbettyd5c246e2019-12-24 15:40:37 +08009879 final long identity = Binder.clearCallingIdentity();
9880 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009881 Phone phone = getPhone(subscriptionId);
9882 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009883
Hall Liua62f5da2020-09-25 10:42:19 -07009884 switch (policy) {
9885 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu99e87332021-12-17 23:14:15 -08009886 if (phone.isUsingNewDataStack()) {
9887 phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled);
9888 } else {
9889 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9890 }
Hall Liua62f5da2020-09-25 10:42:19 -07009891 break;
9892 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu99e87332021-12-17 23:14:15 -08009893 if (phone.isUsingNewDataStack()) {
9894 phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled);
9895 } else {
9896 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9897 }
Hall Liua62f5da2020-09-25 10:42:19 -07009898 break;
9899 default:
9900 throw new IllegalArgumentException(policy + " is not a valid policy");
9901 }
changbettyd5c246e2019-12-24 15:40:37 +08009902 } finally {
9903 Binder.restoreCallingIdentity(identity);
9904 }
9905 }
9906
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009907 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009908 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009909 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9910 * otherwise.
9911 */
9912 @Override
9913 public void setCepEnabled(boolean isCepEnabled) {
9914 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9915
9916 final long identity = Binder.clearCallingIdentity();
9917 try {
9918 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9919 for (Phone phone : PhoneFactory.getPhones()) {
9920 Phone defaultPhone = phone.getImsPhone();
9921 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9922 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9923 ImsPhoneCallTracker imsPhoneCallTracker =
9924 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9925 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9926 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9927 + imsPhone.getMsisdn());
9928 }
9929 }
9930 } finally {
9931 Binder.restoreCallingIdentity(identity);
9932 }
9933 }
allenwtsu46dcc572020-01-08 18:24:03 +08009934
9935 /**
9936 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9937 *
9938 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9939 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9940 * before being read.
9941 */
9942 @Override
9943 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9944 isCompressed) {
9945 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9946 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009947 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9948 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9949 }
9950 if (!isImsAvailableOnDevice()) {
9951 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9952 "IMS not available on device.");
9953 }
9954
9955 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009956 try {
Hui Wang761a6682020-10-31 05:12:53 +00009957 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9958 } finally {
9959 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009960 }
9961 }
zoey chene02881a2019-12-30 16:11:23 +08009962
9963 @Override
9964 public boolean isIccLockEnabled(int subId) {
9965 enforceReadPrivilegedPermission("isIccLockEnabled");
9966
9967 // Now that all security checks passes, perform the operation as ourselves.
9968 final long identity = Binder.clearCallingIdentity();
9969 try {
9970 Phone phone = getPhone(subId);
9971 if (phone != null && phone.getIccCard() != null) {
9972 return phone.getIccCard().getIccLockEnabled();
9973 } else {
9974 return false;
9975 }
9976 } finally {
9977 Binder.restoreCallingIdentity(identity);
9978 }
9979 }
9980
9981 /**
9982 * Set the ICC pin lock enabled or disabled.
9983 *
9984 * @return an integer representing the status of IccLock enabled or disabled in the following
9985 * three cases:
9986 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9987 * successfully.
9988 * - Positive number and zero for remaining password attempts.
9989 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9990 *
9991 */
9992 @Override
9993 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9994 enforceModifyPermission();
9995
9996 Phone phone = getPhone(subId);
9997 if (phone == null) {
9998 return 0;
9999 }
10000 // Now that all security checks passes, perform the operation as ourselves.
10001 final long identity = Binder.clearCallingIdentity();
10002 try {
10003 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10004 new Pair<Boolean, String>(enabled, password), phone, null);
10005 return attemptsRemaining;
10006
10007 } catch (Exception e) {
10008 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10009 } finally {
10010 Binder.restoreCallingIdentity(identity);
10011 }
10012 return 0;
10013 }
10014
10015 /**
10016 * Change the ICC password used in ICC pin lock.
10017 *
10018 * @return an integer representing the status of IccLock changed in the following three cases:
10019 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10020 * - Positive number and zero for remaining password attempts.
10021 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10022 *
10023 */
10024 @Override
10025 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10026 enforceModifyPermission();
10027
10028 Phone phone = getPhone(subId);
10029 if (phone == null) {
10030 return 0;
10031 }
10032 // Now that all security checks passes, perform the operation as ourselves.
10033 final long identity = Binder.clearCallingIdentity();
10034 try {
10035 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10036 new Pair<String, String>(oldPassword, newPassword), phone, null);
10037 return attemptsRemaining;
10038
10039 } catch (Exception e) {
10040 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10041 } finally {
10042 Binder.restoreCallingIdentity(identity);
10043 }
10044 return 0;
10045 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010046
10047 /**
10048 * Request for receiving user activity notification
10049 */
10050 @Override
10051 public void requestUserActivityNotification() {
10052 if (!mNotifyUserActivity.get()
10053 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10054 mNotifyUserActivity.set(true);
10055 }
10056 }
10057
10058 /**
10059 * Called when userActivity is signalled in the power manager.
10060 * This is safe to call from any thread, with any window manager locks held or not.
10061 */
10062 @Override
10063 public void userActivity() {
10064 // ***************************************
10065 // * Inherited from PhoneWindowManager *
10066 // ***************************************
10067 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10068 // WITH ITS LOCKS HELD.
10069 //
10070 // This code must be VERY careful about the locks
10071 // it acquires.
10072 // In fact, the current code acquires way too many,
10073 // and probably has lurking deadlocks.
10074
10075 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10076 throw new SecurityException("Only the OS may call notifyUserActivity()");
10077 }
10078
10079 if (mNotifyUserActivity.getAndSet(false)) {
10080 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10081 USER_ACTIVITY_NOTIFICATION_DELAY);
10082 }
10083 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010084
10085 @Override
10086 public boolean canConnectTo5GInDsdsMode() {
10087 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10088 }
Jack Yud10cdd42020-09-28 20:28:01 -070010089
10090 @Override
10091 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10092 String callingFeatureId) {
10093 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10094 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10095 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10096 }
10097
10098 Phone phone = getPhone(subId);
10099 if (phone == null) {
10100 throw new RuntimeException("phone is not available");
10101 }
10102 // Now that all security checks passes, perform the operation as ourselves.
10103 final long identity = Binder.clearCallingIdentity();
10104 try {
10105 return phone.getEquivalentHomePlmns();
10106 } finally {
10107 Binder.restoreCallingIdentity(identity);
10108 }
10109 }
Daniel Bright59e67312020-11-13 11:49:37 -080010110
10111 @Override
10112 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010113 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10114 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010115 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010116 if (radioInterfaceCapabilities == null) {
10117 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010118 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010119 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010120 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010121
Hui Wang641e81c2020-10-12 12:14:23 -070010122 @Override
10123 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10124 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010125 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10126 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10127 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10128 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10129 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010130 if (DBG) {
10131 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10132 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10133 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10134 }
10135
10136 if (!SubscriptionManager.isValidSubscriptionId(subId)
10137 || appType < TelephonyManager.APPTYPE_UNKNOWN
10138 || appType > TelephonyManager.APPTYPE_ISIM
10139 || nafUrl == null || securityProtocol == null || callback == null) {
10140 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10141 if (callback != null) {
10142 try {
10143 callback.onAuthenticationFailure(
10144 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10145 } catch (RemoteException exception) {
10146 log("Fail to notify onAuthenticationFailure due to " + exception);
10147 }
10148 return;
10149 }
10150 }
10151
10152 final long token = Binder.clearCallingIdentity();
10153 try {
10154 getGbaManager(subId).bootstrapAuthenticationRequest(
10155 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10156 forceBootStrapping, callback));
10157 } finally {
10158 Binder.restoreCallingIdentity(token);
10159 }
10160 }
10161
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010162 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010163 * Attempts to set the radio power state for all phones for thermal reason.
10164 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010165 * requested radio power state will actually be set. See {@link
10166 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10167 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010168 * @param enable {@code true} if trying to turn radio on.
10169 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10170 * false}.
10171 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010172 private boolean setRadioPowerForThermal(boolean enable) {
10173 boolean isPhoneAvailable = false;
10174 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10175 Phone phone = PhoneFactory.getPhone(i);
10176 if (phone != null) {
10177 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10178 isPhoneAvailable = true;
10179 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010180 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010181
10182 // return true if successfully informed the phone object about the thermal radio power
10183 // request.
10184 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010185 }
10186
10187 private int handleDataThrottlingRequest(int subId,
10188 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010189 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10190 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10191 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10192 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10193 throw new IllegalArgumentException("modem does not support data throttling");
10194 }
10195
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010196 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10197 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010198 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010199 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10200 }
10201
10202 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10203
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010204 if (isDataThrottlingSupported) {
10205 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010206 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010207 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10208 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10209 } else if (thermalMitigationResult
10210 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010211 log("Modem likely does not support data throttling on secondary carrier. Data " +
10212 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10213 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010214 }
10215 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010216 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010217
10218 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010219 }
10220
Jack Nudelman644b91a2021-03-12 14:09:48 -080010221 private static List<String> getThermalMitigationAllowlist(Context context) {
10222 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10223 for (String pckg : context.getResources()
10224 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10225 sThermalMitigationAllowlistedPackages.add(pckg);
10226 }
10227 }
10228
10229 return sThermalMitigationAllowlistedPackages;
10230 }
10231
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010232 private boolean isAnyPhoneInEmergencyState() {
10233 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10234 if (tm.isInEmergencyCall()) {
10235 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10236 return true;
10237 }
10238 for (Phone phone : PhoneFactory.getPhones()) {
10239 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10240 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10241 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10242 + phone.isInEcm());
10243 return true;
10244 }
10245 }
10246
10247 return false;
10248 }
10249
Jack Nudelman644b91a2021-03-12 14:09:48 -080010250 /**
10251 * Used by shell commands to add an authorized package name for thermal mitigation.
10252 * @param packageName name of package to be allowlisted
10253 * @param context
10254 */
10255 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10256 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10257 sThermalMitigationAllowlistedPackages.add(packageName);
10258 }
10259
10260 /**
10261 * Used by shell commands to remove an authorized package name for thermal mitigation.
10262 * @param packageName name of package to remove from allowlist
10263 * @param context
10264 */
10265 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10266 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10267 sThermalMitigationAllowlistedPackages.remove(packageName);
10268 }
10269
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010270 /**
10271 * Thermal mitigation request to control functionalities at modem.
10272 *
10273 * @param subId the id of the subscription.
10274 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010275 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010276 *
10277 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10278 */
10279 @Override
10280 @ThermalMitigationResult
10281 public int sendThermalMitigationRequest(
10282 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010283 ThermalMitigationRequest thermalMitigationRequest,
10284 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010285 enforceModifyPermission();
10286
Jack Nudelman644b91a2021-03-12 14:09:48 -080010287 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10288 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10289 .contains(callingPackage)) {
10290 throw new SecurityException("Calling package must be configured in the device config. "
10291 + "calling package: " + callingPackage);
10292 }
10293
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010294 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10295 final long identity = Binder.clearCallingIdentity();
10296
10297 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10298 try {
10299 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10300 switch (thermalMitigationAction) {
10301 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10302 thermalMitigationResult =
10303 handleDataThrottlingRequest(subId,
10304 thermalMitigationRequest.getDataThrottlingRequest());
10305 break;
10306 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10307 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10308 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10309 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10310 }
10311
10312 // Ensure that radio is on. If not able to power on due to phone being
10313 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010314 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010315 thermalMitigationResult =
10316 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10317 break;
10318 }
10319
10320 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10321 false);
10322 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10323 break;
10324 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10325 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10326 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10327 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10328 }
10329
10330 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10331 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010332 Phone phone = getPhone(subId);
10333 if (phone == null) {
10334 thermalMitigationResult =
10335 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10336 break;
10337 }
10338
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010339 TelephonyConnectionService service =
10340 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010341 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010342 Log.e(LOG_TAG, "An emergency call is pending");
10343 thermalMitigationResult =
10344 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10345 break;
10346 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010347 thermalMitigationResult =
10348 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10349 break;
10350 }
10351 } else {
10352 thermalMitigationResult =
10353 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10354 break;
10355 }
10356
10357 // Turn radio off. If not able to power off due to phone being unavailable,
10358 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010359 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010360 thermalMitigationResult =
10361 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10362 break;
10363 }
10364 thermalMitigationResult =
10365 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10366 break;
10367 default:
10368 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10369 + "not exist. Requested action: " + thermalMitigationAction);
10370 }
10371 } catch (IllegalArgumentException e) {
10372 throw e;
10373 } catch (Exception e) {
10374 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10375 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10376 } finally {
10377 Binder.restoreCallingIdentity(identity);
10378 }
10379
10380 if (DBG) {
10381 log("thermalMitigationRequest returning with thermalMitigationResult: "
10382 + thermalMitigationResult);
10383 }
10384
10385 return thermalMitigationResult;
10386 }
Hui Wang641e81c2020-10-12 12:14:23 -070010387
10388 /**
10389 * Set the GbaService Package Name that Telephony will bind to.
10390 *
10391 * @param subId The sim that the GbaService is associated with.
10392 * @param packageName The name of the package to be replaced with.
10393 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10394 */
10395 @Override
10396 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10397 enforceModifyPermission();
10398
10399 final long identity = Binder.clearCallingIdentity();
10400 try {
10401 return getGbaManager(subId).overrideServicePackage(packageName);
10402 } finally {
10403 Binder.restoreCallingIdentity(identity);
10404 }
10405 }
10406
10407 /**
10408 * Return the package name of the currently bound GbaService.
10409 *
10410 * @param subId The sim that the GbaService is associated with.
10411 * @return the package name of the GbaService configuration, null if GBA is not supported.
10412 */
10413 @Override
10414 public String getBoundGbaService(int subId) {
10415 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10416
10417 final long identity = Binder.clearCallingIdentity();
10418 try {
10419 return getGbaManager(subId).getServicePackage();
10420 } finally {
10421 Binder.restoreCallingIdentity(identity);
10422 }
10423 }
10424
10425 /**
10426 * Set the release time for telephony to unbind GbaService.
10427 *
10428 * @param subId The sim that the GbaService is associated with.
10429 * @param interval The release time to unbind GbaService by millisecond.
10430 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10431 */
10432 @Override
10433 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10434 enforceModifyPermission();
10435
10436 final long identity = Binder.clearCallingIdentity();
10437 try {
10438 return getGbaManager(subId).overrideReleaseTime(interval);
10439 } finally {
10440 Binder.restoreCallingIdentity(identity);
10441 }
10442 }
10443
10444 /**
10445 * Return the release time for telephony to unbind GbaService.
10446 *
10447 * @param subId The sim that the GbaService is associated with.
10448 * @return The release time to unbind GbaService by millisecond.
10449 */
10450 @Override
10451 public int getGbaReleaseTime(int subId) {
10452 enforceReadPrivilegedPermission("getGbaReleaseTime");
10453
10454 final long identity = Binder.clearCallingIdentity();
10455 try {
10456 return getGbaManager(subId).getReleaseTime();
10457 } finally {
10458 Binder.restoreCallingIdentity(identity);
10459 }
10460 }
10461
10462 private GbaManager getGbaManager(int subId) {
10463 GbaManager instance = GbaManager.getInstance(subId);
10464 if (instance == null) {
10465 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10466 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10467 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10468 }
10469 return instance;
10470 }
Hui Wang761a6682020-10-31 05:12:53 +000010471
10472 /**
10473 * indicate whether the device and the carrier can support
10474 * RCS VoLTE single registration.
10475 */
10476 @Override
10477 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010478 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10479 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10480 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10481 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010482
10483 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10484 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10485 }
10486
10487 final long identity = Binder.clearCallingIdentity();
10488 try {
10489 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10490 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010491 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10492 if (isCapable != null) {
10493 return isCapable;
10494 }
Hui Wang761a6682020-10-31 05:12:53 +000010495 }
Hui Wang67af90e2021-06-04 16:57:15 -070010496 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10497 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010498 } finally {
10499 Binder.restoreCallingIdentity(identity);
10500 }
10501 }
10502
10503 /**
10504 * Register RCS provisioning callback.
10505 */
10506 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010507 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010508 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010509 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010510 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010511 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10512 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010513
10514 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10515 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10516 }
10517 if (!isImsAvailableOnDevice()) {
10518 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10519 "IMS not available on device.");
10520 }
10521
10522 final long identity = Binder.clearCallingIdentity();
10523 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010524 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010525 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010526 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10527 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010528 }
Hui Wang761a6682020-10-31 05:12:53 +000010529 } finally {
10530 Binder.restoreCallingIdentity(identity);
10531 }
10532 }
10533
10534 /**
10535 * Unregister RCS provisioning callback.
10536 */
10537 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010538 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010539 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010540 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010541 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010542 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10543 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010544
10545 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10546 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10547 }
10548 if (!isImsAvailableOnDevice()) {
10549 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10550 "IMS not available on device.");
10551 }
10552
10553 final long identity = Binder.clearCallingIdentity();
10554 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010555 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010556 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010557 } finally {
10558 Binder.restoreCallingIdentity(identity);
10559 }
10560 }
10561
10562 /**
10563 * trigger RCS reconfiguration.
10564 */
10565 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010566 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10567 "triggerRcsReconfiguration",
10568 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010569
10570 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10571 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10572 }
10573 if (!isImsAvailableOnDevice()) {
10574 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10575 "IMS not available on device.");
10576 }
10577
10578 final long identity = Binder.clearCallingIdentity();
10579 try {
10580 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10581 } finally {
10582 Binder.restoreCallingIdentity(identity);
10583 }
10584 }
10585
10586 /**
10587 * Provide the client configuration parameters of the RCS application.
10588 */
10589 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010590 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10591 "setRcsClientConfiguration",
10592 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010593
10594 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10595 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10596 }
10597 if (!isImsAvailableOnDevice()) {
10598 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10599 "IMS not available on device.");
10600 }
10601
10602 final long identity = Binder.clearCallingIdentity();
10603
10604 try {
10605 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10606 if (configBinder == null) {
10607 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010608 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10609 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010610 } else {
10611 configBinder.setRcsClientConfiguration(rcc);
10612 }
joonhunshin3e154242021-09-17 06:33:39 +000010613
10614 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10615 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010616 } catch (RemoteException e) {
10617 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010618 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10619 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010620 } finally {
10621 Binder.restoreCallingIdentity(identity);
10622 }
10623 }
10624
10625 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010626 * Enables or disables the test mode for RCS VoLTE single registration.
10627 */
10628 @Override
10629 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10630 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10631 "setRcsSingleRegistrationTestModeEnabled");
10632
10633 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10634 }
10635
10636 /**
10637 * Gets the test mode for RCS VoLTE single registration.
10638 */
10639 @Override
10640 public boolean getRcsSingleRegistrationTestModeEnabled() {
10641 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10642 "getRcsSingleRegistrationTestModeEnabled");
10643
10644 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10645 }
10646
10647 /**
Hui Wang761a6682020-10-31 05:12:53 +000010648 * Overrides the config of RCS VoLTE single registration enabled for the device.
10649 */
10650 @Override
10651 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10652 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10653 "setDeviceSingleRegistrationEnabledOverride");
10654 enforceModifyPermission();
10655
10656 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10657 : Boolean.parseBoolean(enabledStr);
10658 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010659 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010660 }
10661
10662 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010663 * Sends a device to device communication message. Only usable via shell.
10664 * @param message message to send.
10665 * @param value message value.
10666 */
10667 @Override
10668 public void sendDeviceToDeviceMessage(int message, int value) {
10669 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010670 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010671 enforceModifyPermission();
10672
10673 final long identity = Binder.clearCallingIdentity();
10674 try {
10675 TelephonyConnectionService service =
10676 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10677 if (service == null) {
10678 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10679 return;
10680 }
10681 service.sendTestDeviceToDeviceMessage(message, value);
10682 } finally {
10683 Binder.restoreCallingIdentity(identity);
10684 }
10685 }
10686
Tyler Gunnbabbda02021-02-10 11:05:02 -080010687 /**
10688 * Sets the specified device to device transport active.
10689 * @param transport The transport to set active.
10690 */
10691 @Override
10692 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10693 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10694 "setActiveDeviceToDeviceTransport");
10695 enforceModifyPermission();
10696
10697 final long identity = Binder.clearCallingIdentity();
10698 try {
10699 TelephonyConnectionService service =
10700 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10701 if (service == null) {
10702 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10703 return;
10704 }
10705 service.setActiveDeviceToDeviceTransport(transport);
10706 } finally {
10707 Binder.restoreCallingIdentity(identity);
10708 }
10709 }
Tyler Gunn92479152021-01-20 16:30:10 -080010710
Tyler Gunnd4339262021-05-03 14:46:49 -070010711 @Override
10712 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10713 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10714 "setDeviceToDeviceForceEnabled");
10715
10716 final long identity = Binder.clearCallingIdentity();
10717 try {
10718 Arrays.stream(PhoneFactory.getPhones()).forEach(
10719 p -> {
10720 Phone thePhone = p.getImsPhone();
10721 if (thePhone != null && thePhone instanceof ImsPhone) {
10722 ImsPhone imsPhone = (ImsPhone) thePhone;
10723 CallTracker tracker = imsPhone.getCallTracker();
10724 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10725 ImsPhoneCallTracker imsPhoneCallTracker =
10726 (ImsPhoneCallTracker) tracker;
10727 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10728 }
10729 }
10730 }
10731 );
10732 } finally {
10733 Binder.restoreCallingIdentity(identity);
10734 }
10735 }
10736
Tyler Gunn92479152021-01-20 16:30:10 -080010737 /**
Hui Wang761a6682020-10-31 05:12:53 +000010738 * Gets the config of RCS VoLTE single registration enabled for the device.
10739 */
10740 @Override
10741 public boolean getDeviceSingleRegistrationEnabled() {
10742 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10743 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10744 }
10745
10746 /**
10747 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10748 */
10749 @Override
10750 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10751 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10752 "setCarrierSingleRegistrationEnabledOverride");
10753 enforceModifyPermission();
10754
10755 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10756 : Boolean.parseBoolean(enabledStr);
10757 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10758 subId, enabled);
10759 }
10760
10761 /**
10762 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10763 */
10764 @Override
10765 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10766 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10767 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10768 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010769
10770 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010771 * Overrides the ims feature validation result
10772 */
10773 @Override
10774 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10775 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10776 "setImsFeatureValidationOverride");
10777
10778 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10779 : Boolean.parseBoolean(enabledStr);
10780 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10781 subId, enabled);
10782 }
10783
10784 /**
10785 * Gets the ims feature validation override value
10786 */
10787 @Override
10788 public boolean getImsFeatureValidationOverride(int subId) {
10789 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10790 "getImsFeatureValidationOverride");
10791 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10792 }
10793
10794 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010795 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10796 * their mobile plan.
10797 */
10798 @Override
10799 public String getMobileProvisioningUrl() {
10800 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10801 final long identity = Binder.clearCallingIdentity();
10802 try {
10803 return getDefaultPhone().getMobileProvisioningUrl();
10804 } finally {
10805 Binder.restoreCallingIdentity(identity);
10806 }
10807 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010808
James.cf Linbcdf8b32021-01-14 16:44:13 +080010809 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010810 * Get the EAB contact from the EAB database.
10811 */
10812 @Override
10813 public String getContactFromEab(String contact) {
10814 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10815 enforceModifyPermission();
10816 final long identity = Binder.clearCallingIdentity();
10817 try {
10818 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10819 } finally {
10820 Binder.restoreCallingIdentity(identity);
10821 }
10822 }
10823
10824 /**
Calvin Pana1434322021-07-01 19:27:01 +080010825 * Get the EAB capability from the EAB database.
10826 */
10827 @Override
10828 public String getCapabilityFromEab(String contact) {
10829 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10830 enforceModifyPermission();
10831 final long identity = Binder.clearCallingIdentity();
10832 try {
10833 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10834 } finally {
10835 Binder.restoreCallingIdentity(identity);
10836 }
10837 }
10838
10839 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010840 * Remove the EAB contacts from the EAB database.
10841 */
10842 @Override
10843 public int removeContactFromEab(int subId, String contacts) {
10844 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10845 enforceModifyPermission();
10846 final long identity = Binder.clearCallingIdentity();
10847 try {
10848 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10849 } finally {
10850 Binder.restoreCallingIdentity(identity);
10851 }
10852 }
10853
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010854 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010855 public boolean getDeviceUceEnabled() {
10856 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10857 final long identity = Binder.clearCallingIdentity();
10858 try {
10859 return mApp.getDeviceUceEnabled();
10860 } finally {
10861 Binder.restoreCallingIdentity(identity);
10862 }
10863 }
10864
10865 @Override
10866 public void setDeviceUceEnabled(boolean isEnabled) {
10867 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10868 final long identity = Binder.clearCallingIdentity();
10869 try {
10870 mApp.setDeviceUceEnabled(isEnabled);
10871 } finally {
10872 Binder.restoreCallingIdentity(identity);
10873 }
10874 }
10875
Brad Ebinger14d467f2021-02-12 06:18:28 +000010876 /**
10877 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10878 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10879 */
10880 // Used for SHELL command only right now.
10881 @Override
10882 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10883 List<String> featureTags) {
10884 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10885 "addUceRegistrationOverrideShell");
10886 final long identity = Binder.clearCallingIdentity();
10887 try {
10888 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10889 new ArraySet<>(featureTags));
10890 } catch (ImsException e) {
10891 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10892 } finally {
10893 Binder.restoreCallingIdentity(identity);
10894 }
10895 }
10896
10897 /**
10898 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10899 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10900 */
10901 // Used for SHELL command only right now.
10902 @Override
10903 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10904 List<String> featureTags) {
10905 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10906 "removeUceRegistrationOverrideShell");
10907 final long identity = Binder.clearCallingIdentity();
10908 try {
10909 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10910 new ArraySet<>(featureTags));
10911 } catch (ImsException e) {
10912 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10913 } finally {
10914 Binder.restoreCallingIdentity(identity);
10915 }
10916 }
10917
10918 /**
10919 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10920 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10921 */
10922 // Used for SHELL command only right now.
10923 @Override
10924 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10925 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10926 "clearUceRegistrationOverrideShell");
10927 final long identity = Binder.clearCallingIdentity();
10928 try {
10929 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10930 } catch (ImsException e) {
10931 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10932 } finally {
10933 Binder.restoreCallingIdentity(identity);
10934 }
10935 }
10936
10937 /**
10938 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10939 */
10940 // Used for SHELL command only right now.
10941 @Override
10942 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10943 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10944 "getLatestRcsContactUceCapabilityShell");
10945 final long identity = Binder.clearCallingIdentity();
10946 try {
10947 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10948 } catch (ImsException e) {
10949 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10950 } finally {
10951 Binder.restoreCallingIdentity(identity);
10952 }
10953 }
10954
10955 /**
10956 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10957 * device does not have an active PUBLISH.
10958 */
10959 // Used for SHELL command only right now.
10960 @Override
10961 public String getLastUcePidfXmlShell(int subId) {
10962 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10963 final long identity = Binder.clearCallingIdentity();
10964 try {
10965 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10966 } catch (ImsException e) {
10967 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10968 } finally {
10969 Binder.restoreCallingIdentity(identity);
10970 }
10971 }
10972
James.cf Line8713a42021-04-29 16:04:26 +080010973 /**
10974 * Remove UCE requests cannot be sent to the network status.
10975 */
10976 // Used for SHELL command only right now.
10977 @Override
10978 public boolean removeUceRequestDisallowedStatus(int subId) {
10979 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10980 final long identity = Binder.clearCallingIdentity();
10981 try {
10982 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10983 } catch (ImsException e) {
10984 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10985 } finally {
10986 Binder.restoreCallingIdentity(identity);
10987 }
10988 }
10989
James.cf Lin18bb9002021-05-25 01:37:38 +080010990 /**
10991 * Remove UCE requests cannot be sent to the network status.
10992 */
10993 // Used for SHELL command only.
10994 @Override
10995 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10996 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10997 final long identity = Binder.clearCallingIdentity();
10998 try {
10999 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11000 } catch (ImsException e) {
11001 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11002 } finally {
11003 Binder.restoreCallingIdentity(identity);
11004 }
11005 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011006
James.cf Lin4b784aa2021-01-31 03:25:15 +080011007 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011008 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11009 String callingPackage) {
11010 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11011 mApp, subId, "setSignalStrengthUpdateRequest");
11012
11013 final int callingUid = Binder.getCallingUid();
11014 // Verify that tha callingPackage belongs to the calling UID
11015 mApp.getSystemService(AppOpsManager.class)
11016 .checkPackage(callingUid, callingPackage);
11017
Rambo Wang3607f502021-02-01 21:51:40 -080011018 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011019
11020 final long identity = Binder.clearCallingIdentity();
11021 try {
11022 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11023 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11024
11025 if (result instanceof IllegalStateException) {
11026 throw (IllegalStateException) result;
11027 }
11028 } finally {
11029 Binder.restoreCallingIdentity(identity);
11030 }
11031 }
11032
11033 @Override
11034 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11035 String callingPackage) {
11036 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11037 mApp, subId, "clearSignalStrengthUpdateRequest");
11038
11039 final int callingUid = Binder.getCallingUid();
11040 // Verify that tha callingPackage belongs to the calling UID
11041 mApp.getSystemService(AppOpsManager.class)
11042 .checkPackage(callingUid, callingPackage);
11043
11044 final long identity = Binder.clearCallingIdentity();
11045 try {
11046 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11047 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11048
11049 if (result instanceof IllegalStateException) {
11050 throw (IllegalStateException) result;
11051 }
11052 } finally {
11053 Binder.restoreCallingIdentity(identity);
11054 }
11055 }
11056
Rambo Wang3607f502021-02-01 21:51:40 -080011057 private static void validateSignalStrengthUpdateRequest(Context context,
11058 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011059 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11060 // phone/system process do not have further restriction on request
11061 return;
11062 }
11063
11064 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011065 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011066 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011067 context.enforceCallingOrSelfPermission(
11068 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11069 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011070 }
11071
11072 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11073 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11074 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11075 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11076 || info.isEnabled()) {
11077 throw new IllegalArgumentException(
11078 "Only system can set hide fields in SignalThresholdInfo");
11079 }
11080
11081 // Thresholds length for each RAN need in range. This has been validated in
11082 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11083 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11084 final int[] thresholds = info.getThresholds();
11085 Objects.requireNonNull(thresholds);
11086 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11087 || thresholds.length
11088 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11089 throw new IllegalArgumentException(
11090 "thresholds length is out of range: " + thresholds.length);
11091 }
11092 }
11093 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011094
11095 /**
11096 * Gets the current phone capability.
11097 *
11098 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11099 * @return the PhoneCapability which describes the data connection capability of modem.
11100 * It's used to evaluate possible phone config change, for example from single
11101 * SIM device to multi-SIM device.
11102 */
11103 @Override
11104 public PhoneCapability getPhoneCapability() {
11105 enforceReadPrivilegedPermission("getPhoneCapability");
11106 final long identity = Binder.clearCallingIdentity();
11107 try {
11108 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11109 } finally {
11110 Binder.restoreCallingIdentity(identity);
11111 }
11112 }
Michele Berionne5e411512020-11-13 02:36:59 +000011113
11114 /**
11115 * Prepare TelephonyManager for an unattended reboot. The reboot is
11116 * required to be done shortly after the API is invoked.
11117 */
11118 @Override
11119 @TelephonyManager.PrepareUnattendedRebootResult
11120 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011121 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011122 enforceRebootPermission();
11123
11124 final long identity = Binder.clearCallingIdentity();
11125 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011126 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011127 } finally {
11128 Binder.restoreCallingIdentity(identity);
11129 }
11130 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011131
11132 /**
11133 * Request to get the current slicing configuration including URSP rules and
11134 * NSSAIs (configured, allowed and rejected).
11135 *
11136 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11137 */
11138 @Override
11139 public void getSlicingConfig(ResultReceiver callback) {
11140 enforceReadPrivilegedPermission("getSlicingConfig");
11141
11142 final long identity = Binder.clearCallingIdentity();
11143 try {
11144 Phone phone = getDefaultPhone();
11145 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11146 } finally {
11147 Binder.restoreCallingIdentity(identity);
11148 }
11149 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011150
11151 /**
11152 * Register an IMS connection state callback
11153 */
11154 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011155 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11156 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011157 if (feature == ImsFeature.FEATURE_MMTEL) {
11158 // ImsMmTelManager
11159 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11160 TelephonyPermissions
11161 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11162 mApp, subId, "registerImsStateCallback");
11163 } else if (feature == ImsFeature.FEATURE_RCS) {
11164 // ImsRcsManager or SipDelegateManager
11165 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11166 Binder.getCallingUid(), "registerImsStateCallback",
11167 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11168 Manifest.permission.READ_PRECISE_PHONE_STATE,
11169 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11170 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11171 }
11172
11173 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11174 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11175 "IMS not available on device.");
11176 }
11177
11178 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11179 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11180 }
11181
11182 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11183 if (controller == null) {
11184 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11185 "IMS not available on device.");
11186 }
11187
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011188 if (callingPackage == null) {
11189 callingPackage = getCurrentPackageName();
11190 }
11191
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011192 final long token = Binder.clearCallingIdentity();
11193 try {
11194 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011195 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011196 } catch (ImsException e) {
11197 throw new ServiceSpecificException(e.getCode());
11198 } finally {
11199 Binder.restoreCallingIdentity(token);
11200 }
11201 }
11202
11203 /**
11204 * Unregister an IMS connection state callback
11205 */
11206 @Override
11207 public void unregisterImsStateCallback(IImsStateCallback cb) {
11208 final long token = Binder.clearCallingIdentity();
11209 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11210 if (controller == null) {
11211 return;
11212 }
11213 try {
11214 controller.unregisterImsStateCallback(cb);
11215 } finally {
11216 Binder.restoreCallingIdentity(token);
11217 }
11218 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011219
11220 /**
11221 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11222 *
11223 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11224 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11225 * SecurityException.
11226 * If there is current registered network this value will be same as the registered cell
11227 * identity. If the device goes out of service the previous cell identity is cached and
11228 * will be returned. If the cache age of the Cell identity is more than 24 hours
11229 * it will be cleared and null will be returned.
11230 *
11231 */
11232 @Override
11233 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11234 String callingFeatureId) {
11235 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11236 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11237 LocationAccessPolicy.checkLocationPermission(mApp,
11238 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11239 .setCallingPackage(callingPackage)
11240 .setCallingFeatureId(callingFeatureId)
11241 .setCallingPid(Binder.getCallingPid())
11242 .setCallingUid(Binder.getCallingUid())
11243 .setMethod("getLastKnownCellIdentity")
11244 .setLogAsInfo(true)
11245 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11246 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11247 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11248 .build());
11249
11250 boolean hasFinePermission =
11251 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11252 if (!hasFinePermission
11253 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11254 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
11255 + "and BIND_CONNECTION_SERVICE permission.");
11256 }
11257
11258 final long identity = Binder.clearCallingIdentity();
11259 try {
11260 Phone phone = getPhone(subId);
11261 if (phone == null) return null;
11262 ServiceStateTracker sst = phone.getServiceStateTracker();
11263 if (sst == null) return null;
11264 return sst.getLastKnownCellIdentity();
11265 } finally {
11266 Binder.restoreCallingIdentity(identity);
11267 }
11268 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011269
11270 @Override
11271 public boolean isUsingNewDataStack() {
11272 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "isUsingNewDataStack");
11273 return getDefaultPhone().isUsingNewDataStack();
11274 }
jimsun3b9ccac2021-10-26 15:01:23 +080011275
11276 /**
11277 * Sets the modem service class Name that Telephony will bind to.
11278 *
11279 * @param serviceName The class name of the modem service.
11280 * @return true if the operation is succeed, otherwise false.
11281 */
11282 public boolean setModemService(String serviceName) {
11283 Log.d(LOG_TAG, "setModemService - " + serviceName);
11284 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11285 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11286 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11287 "setModemService");
11288 return mPhoneConfigurationManager.setModemService(serviceName);
11289 }
11290
11291 /**
11292 * Return the class name of the currently bounded modem service.
11293 *
11294 * @return the class name of the modem service.
11295 */
11296 public String getModemService() {
11297 String result;
11298 Log.d(LOG_TAG, "getModemService");
11299 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11300 TelephonyPermissions
11301 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11302 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11303 "getModemService");
11304 result = mPhoneConfigurationManager.getModemService();
11305 Log.d(LOG_TAG, "result = " + result);
11306 return result;
11307 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011308
11309 @Override
11310 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11311 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11312 mApp.enforceCallingOrSelfPermission(
11313 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11314 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11315
11316 final long identity = Binder.clearCallingIdentity();
11317 try {
11318 Phone phone = getPhone(subId);
11319 if (phone == null) return;
11320 phone.setVoiceServiceStateOverride(hasService);
11321 } finally {
11322 Binder.restoreCallingIdentity(identity);
11323 }
11324 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011325}