blob: f0f7731eb18a30ae37d6fa974ffdadf4c1bad5b9 [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;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070045import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.net.Uri;
47import android.os.AsyncResult;
48import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080049import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.Bundle;
51import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070052import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.os.Looper;
54import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070055import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080056import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070057import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070058import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080059import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080060import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070061import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070062import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080063import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070065import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070066import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070067import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070068import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080069import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070070import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090071import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080072import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080073import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070074import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070075import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080076import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080077import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070078import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080079import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070080import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080081import android.telephony.CellIdentityCdma;
82import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070083import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070084import android.telephony.CellInfoGsm;
85import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070086import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080087import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070088import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070089import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070090import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080091import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070092import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080093import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070094import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080095import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080096import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070097import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080098import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070099import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800100import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800101import android.telephony.SignalStrengthUpdateRequest;
102import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800103import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800104import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800105import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700106import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700107import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800108import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800109import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800110import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000111import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000112import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000113import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700114import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700115import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800116import android.telephony.data.ApnSetting;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800117import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800118import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700119import android.telephony.gba.GbaAuthRequest;
120import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700121import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800122import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000123import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000124import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700125import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000126import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700127import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800128import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700129import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800130import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700131import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000132import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700133import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800134import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800135import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800136import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800137import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800139import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700140import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700141import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800142import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800143
Andrew Lee312e8172014-10-23 17:01:36 -0700144import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800145import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800146import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800147import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800148import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700149import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700150import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700151import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800152import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800153import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700154import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700155import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800156import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700157import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700158import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800159import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800160import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800161import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700162import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000163import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700164import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800165import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700166import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800167import com.android.internal.telephony.IccCard;
Rambo Wanga1782702021-11-10 20:15:19 -0800168import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700169import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700170import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700171import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700172import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700173import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800174import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700175import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700176import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700177import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700178import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800179import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800180import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700181import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700182import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700183import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800184import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800185import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800186import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700187import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800188import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700189import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800190import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700191import com.android.internal.telephony.imsphone.ImsPhone;
192import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000193import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800194import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700195import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700196import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800197import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700198import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800199import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700200import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800201import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700202import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000203import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800204import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000205import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800206import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700207import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700208import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800209import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800210import com.android.phone.callcomposer.CallComposerPictureManager;
211import com.android.phone.callcomposer.CallComposerPictureTransfer;
212import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700213import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700214import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800215import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700216import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700217import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800218import com.android.services.telephony.TelecomAccountRegistry;
219import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800220import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800221
Hall Liu82694d52020-12-11 18:22:04 -0800222import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700223import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800224import java.io.IOException;
225import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700226import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700227import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800228import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000229import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800230import java.util.Collections;
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) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006835 // No permission needed; this only lets the caller inspect their own status.
6836 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006837 }
Junda Liu29340342014-07-10 15:23:27 -07006838
6839 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006840 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006841 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006842 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6843 }
6844
6845 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6846 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006847 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006848 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006849 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6850 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006851 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6852 if (cpt == null) {
6853 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006854 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6855 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006856 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006857 }
6858
6859 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006860 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006861 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006862 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006863 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006864 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006865 Phone phone = getPhone(subId);
6866 if (phone == null) {
6867 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6868 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6869 }
6870 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6871 if (cpt == null) {
6872 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006873 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6874 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006875 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006876 }
6877
6878 @Override
6879 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006880 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
6881 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006882 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006883 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006884 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006885 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6886 Phone phone = PhoneFactory.getPhone(phoneId);
6887 if (phone == null) {
6888 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006889 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006890 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6891 if (cpt == null) {
6892 continue;
6893 }
6894 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006895 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6896 break;
6897 }
6898 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006899 return result;
Junda Liu29340342014-07-10 15:23:27 -07006900 }
Derek Tan89e89d42014-07-08 17:00:10 -07006901
6902 @Override
Junda Liue64de782015-04-16 17:19:16 -07006903 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006904 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00006905 Phone phone = PhoneFactory.getPhone(phoneId);
6906 if (phone == null) {
6907 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006908 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006909 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6910 if (cpt == null) {
6911 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006912 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006913 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006914 }
6915
Amith Yamasani6e118872016-02-19 12:53:51 -08006916 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006917 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006918 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006919 Phone phone = PhoneFactory.getPhone(phoneId);
6920 if (phone == null) {
6921 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006922 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006923 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6924 if (cpt == null) {
6925 return Collections.emptyList();
6926 }
6927 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006928 }
6929
chen xuf7e9fe82019-05-09 19:31:02 -07006930 @Override
6931 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006932 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006933 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006934 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00006935 try {
6936 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6937 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6938 }
6939 } finally {
6940 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006941 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006942 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07006943 }
6944
Wink Savilleb564aae2014-10-23 10:18:09 -07006945 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006946 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006947 UiccPort port = phone == null ? null : phone.getUiccPort();
6948 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006949 return null;
6950 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006951 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006952 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006953 return null;
6954 }
6955 return iccId;
6956 }
6957
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006958 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006959 public void setCallComposerStatus(int subId, int status) {
6960 enforceModifyPermission();
6961
6962 final long identity = Binder.clearCallingIdentity();
6963 try {
6964 Phone phone = getPhone(subId);
6965 if (phone != null) {
6966 Phone defaultPhone = phone.getImsPhone();
6967 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6968 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6969 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006970 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6971 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006972 }
6973 }
Shuo Qian284ae752020-12-22 19:10:14 -08006974 } catch (ImsException e) {
6975 throw new ServiceSpecificException(e.getCode());
6976 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006977 Binder.restoreCallingIdentity(identity);
6978 }
6979 }
6980
6981 @Override
6982 public int getCallComposerStatus(int subId) {
6983 enforceReadPrivilegedPermission("getCallComposerStatus");
6984
6985 final long identity = Binder.clearCallingIdentity();
6986 try {
6987 Phone phone = getPhone(subId);
6988 if (phone != null) {
6989 Phone defaultPhone = phone.getImsPhone();
6990 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6991 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6992 return imsPhone.getCallComposerStatus();
6993 }
6994 }
6995 } finally {
6996 Binder.restoreCallingIdentity(identity);
6997 }
6998 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6999 }
7000
7001 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007002 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7003 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007004 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007005 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007006
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007007 final long identity = Binder.clearCallingIdentity();
7008 try {
7009 final String iccId = getIccId(subId);
7010 final Phone phone = getPhone(subId);
7011 if (phone == null) {
7012 return false;
7013 }
7014 final String subscriberId = phone.getSubscriberId();
7015
7016 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007017 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007018 + subscriberId + " to " + number);
7019 }
7020
7021 if (TextUtils.isEmpty(iccId)) {
7022 return false;
7023 }
7024
7025 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7026
7027 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7028 if (alphaTag == null) {
7029 editor.remove(alphaTagPrefKey);
7030 } else {
7031 editor.putString(alphaTagPrefKey, alphaTag);
7032 }
7033
7034 // Record both the line number and IMSI for this ICCID, since we need to
7035 // track all merged IMSIs based on line number
7036 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7037 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7038 if (number == null) {
7039 editor.remove(numberPrefKey);
7040 editor.remove(subscriberPrefKey);
7041 } else {
7042 editor.putString(numberPrefKey, number);
7043 editor.putString(subscriberPrefKey, subscriberId);
7044 }
7045
7046 editor.commit();
7047 return true;
7048 } finally {
7049 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007050 }
Derek Tan7226c842014-07-02 17:42:23 -07007051 }
7052
7053 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007054 public String getLine1NumberForDisplay(int subId, String callingPackage,
7055 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007056 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007057 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007058 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007059 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007060 return null;
7061 }
Derek Tan97ebb422014-09-05 16:55:38 -07007062
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007063 final long identity = Binder.clearCallingIdentity();
7064 try {
7065 String iccId = getIccId(subId);
7066 if (iccId != null) {
7067 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7068 if (DBG_MERGE) {
7069 log("getLine1NumberForDisplay returning "
7070 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7071 }
7072 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007073 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007074 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7075 return null;
7076 } finally {
7077 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007078 }
Derek Tan7226c842014-07-02 17:42:23 -07007079 }
7080
7081 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007082 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7083 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007084 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007085 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007086 return null;
7087 }
Derek Tan97ebb422014-09-05 16:55:38 -07007088
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007089 final long identity = Binder.clearCallingIdentity();
7090 try {
7091 String iccId = getIccId(subId);
7092 if (iccId != null) {
7093 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7094 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7095 }
7096 return null;
7097 } finally {
7098 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007099 }
Derek Tan7226c842014-07-02 17:42:23 -07007100 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007101
7102 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007103 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7104 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007105 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7106 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007107 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007108 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007109 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007110 return null;
7111 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007112
Jordan Liub49b04b2019-05-06 14:45:15 -07007113 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7114 // the process, where TelephonyManager was instantiated.
7115 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007116 final long identity = Binder.clearCallingIdentity();
7117 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007118 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007119 final TelephonyManager tele = TelephonyManager.from(context);
7120 final SubscriptionManager sub = SubscriptionManager.from(context);
7121
7122 // Figure out what subscribers are currently active
7123 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007124
Jordan Liub49b04b2019-05-06 14:45:15 -07007125 // Only consider subs which match the current subId
7126 // This logic can be simplified. See b/131189269 for progress.
7127 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007128 activeSubscriberIds.add(tele.getSubscriberId(subId));
7129 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007130
7131 // First pass, find a number override for an active subscriber
7132 String mergeNumber = null;
7133 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7134 for (String key : prefs.keySet()) {
7135 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7136 final String subscriberId = (String) prefs.get(key);
7137 if (activeSubscriberIds.contains(subscriberId)) {
7138 final String iccId = key.substring(
7139 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7140 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7141 mergeNumber = (String) prefs.get(numberKey);
7142 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007143 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007144 + " for active subscriber " + subscriberId);
7145 }
7146 if (!TextUtils.isEmpty(mergeNumber)) {
7147 break;
7148 }
7149 }
7150 }
7151 }
7152
7153 // Shortcut when no active merged subscribers
7154 if (TextUtils.isEmpty(mergeNumber)) {
7155 return null;
7156 }
7157
7158 // Second pass, find all subscribers under that line override
7159 final ArraySet<String> result = new ArraySet<>();
7160 for (String key : prefs.keySet()) {
7161 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7162 final String number = (String) prefs.get(key);
7163 if (mergeNumber.equals(number)) {
7164 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7165 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7166 final String subscriberId = (String) prefs.get(subscriberKey);
7167 if (!TextUtils.isEmpty(subscriberId)) {
7168 result.add(subscriberId);
7169 }
7170 }
7171 }
7172 }
7173
7174 final String[] resultArray = result.toArray(new String[result.size()]);
7175 Arrays.sort(resultArray);
7176 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007177 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007178 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7179 }
7180 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007181 } finally {
7182 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007183 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007184 }
7185
7186 @Override
zoey chen38003472019-12-13 17:16:31 +08007187 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7188 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007189
7190 final long identity = Binder.clearCallingIdentity();
7191 try {
7192 final TelephonyManager telephonyManager = mApp.getSystemService(
7193 TelephonyManager.class);
7194 String subscriberId = telephonyManager.getSubscriberId(subId);
7195 if (subscriberId == null) {
7196 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007197 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007198 + subId);
7199 }
7200 return null;
7201 }
7202
7203 final SubscriptionInfo info = SubscriptionController.getInstance()
7204 .getSubscriptionInfo(subId);
7205 final ParcelUuid groupUuid = info.getGroupUuid();
7206 // If it doesn't belong to any group, return just subscriberId of itself.
7207 if (groupUuid == null) {
7208 return new String[]{subscriberId};
7209 }
7210
7211 // Get all subscriberIds from the group.
7212 final List<String> mergedSubscriberIds = new ArrayList<>();
7213 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007214 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007215 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007216 for (SubscriptionInfo subInfo : groupInfos) {
7217 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7218 if (subscriberId != null) {
7219 mergedSubscriberIds.add(subscriberId);
7220 }
7221 }
7222
7223 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7224 } finally {
7225 Binder.restoreCallingIdentity(identity);
7226
7227 }
7228 }
7229
7230 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007231 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007232 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007233 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007234
7235 final long identity = Binder.clearCallingIdentity();
7236 try {
7237 final Phone phone = getPhone(subId);
7238 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7239 } finally {
7240 Binder.restoreCallingIdentity(identity);
7241 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007242 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007243
7244 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007245 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007246 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7247 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007248 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7249 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007250
7251 final long identity = Binder.clearCallingIdentity();
7252 try {
7253 final Phone phone = getPhone(subId);
7254 if (phone == null) {
7255 return false;
7256 }
7257 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7258 cdmaNonRoamingList);
7259 } finally {
7260 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007261 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007262 }
7263
7264 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007265 @Deprecated
7266 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7267 enforceModifyPermission();
7268
7269 int returnValue = 0;
7270 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007271 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007272 if(result.exception == null) {
7273 if (result.result != null) {
7274 byte[] responseData = (byte[])(result.result);
7275 if(responseData.length > oemResp.length) {
7276 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7277 responseData.length + "bytes. Buffer Size is " +
7278 oemResp.length + "bytes.");
7279 }
7280 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7281 returnValue = responseData.length;
7282 }
7283 } else {
7284 CommandException ex = (CommandException) result.exception;
7285 returnValue = ex.getCommandError().ordinal();
7286 if(returnValue > 0) returnValue *= -1;
7287 }
7288 } catch (RuntimeException e) {
7289 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7290 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7291 if(returnValue > 0) returnValue *= -1;
7292 }
7293
7294 return returnValue;
7295 }
7296
7297 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007298 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007299 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007300 try {
7301 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007302 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007303 mApp, phone.getSubId(), "getRadioAccessFamily");
7304 } catch (SecurityException e) {
7305 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7306 throw e;
7307 }
chen xub97461a2018-10-26 14:17:57 -07007308 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007309 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007310 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007311 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007312 final long identity = Binder.clearCallingIdentity();
7313 try {
chen xub97461a2018-10-26 14:17:57 -07007314 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007315 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007316 mApp, phone.getSubId(), "getRadioAccessFamily");
7317 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007318 } finally {
7319 Binder.restoreCallingIdentity(identity);
7320 }
chen xub97461a2018-10-26 14:17:57 -07007321 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007322 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007323
7324 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007325 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007326 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007327 try {
7328 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7329 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007330 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007331 }
7332 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007333 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007334 }
7335 RoleManager rm = mApp.getSystemService(RoleManager.class);
7336 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7337 if (!dialerRoleHolders.contains(callingPackage)) {
7338 throw new SecurityException("App must be the dialer role holder to"
7339 + " upload a call composer pic");
7340 }
7341
7342 Executors.newSingleThreadExecutor().execute(() -> {
7343 ByteArrayOutputStream output = new ByteArrayOutputStream(
7344 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7345 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7346 boolean readUntilEnd = false;
7347 int totalBytesRead = 0;
7348 byte[] buffer = new byte[16 * 1024];
7349 while (true) {
7350 int numRead;
7351 try {
7352 numRead = input.read(buffer);
7353 } catch (IOException e) {
7354 try {
7355 fd.checkError();
7356 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7357 null);
7358 } catch (IOException e1) {
7359 // This means that the other side closed explicitly with an error. If this
7360 // happens, log and ignore.
7361 loge("Remote end of call composer picture pipe closed: " + e1);
7362 }
7363 break;
7364 }
7365 if (numRead == -1) {
7366 readUntilEnd = true;
7367 break;
7368 }
7369 totalBytesRead += numRead;
7370 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7371 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7372 try {
7373 input.close();
7374 } catch (IOException e) {
7375 // ignore
7376 }
7377 break;
7378 }
7379 output.write(buffer, 0, numRead);
7380 }
7381 // Generally, the remote end will close the file descriptors. The only case where we
7382 // close is above, where the picture size is too big.
7383
7384 try {
7385 fd.checkError();
7386 } catch (IOException e) {
7387 loge("Remote end for call composer closed with an error: " + e);
7388 return;
7389 }
7390
Hall Liuaa4211e2021-01-20 15:43:39 -08007391 if (!readUntilEnd) {
7392 loge("Did not finish reading entire image; aborting");
7393 return;
7394 }
Hall Liu82694d52020-12-11 18:22:04 -08007395
Hall Liuaa4211e2021-01-20 15:43:39 -08007396 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7397 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7398 new CallComposerPictureTransfer.Factory() {},
7399 imageData,
7400 (result) -> {
7401 if (result.first != null) {
7402 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7403 Bundle outputResult = new Bundle();
7404 outputResult.putParcelable(
7405 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7406 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7407 outputResult);
7408 } else {
7409 callback.send(result.second, null);
7410 }
7411 }
7412 );
Hall Liu82694d52020-12-11 18:22:04 -08007413 });
7414 }
7415
7416 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007417 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007418 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007419 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007420
7421 final long identity = Binder.clearCallingIdentity();
7422 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007423 ImsManager.getInstance(defaultPhone.getContext(),
7424 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007425 } finally {
7426 Binder.restoreCallingIdentity(identity);
7427 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007428 }
7429
7430 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007431 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007432 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007433 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7434 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007435 return false;
7436 }
Svet Ganovb320e182015-04-16 12:30:10 -07007437
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007438 final long identity = Binder.clearCallingIdentity();
7439 try {
7440 // Check the user preference and the system-level IMS setting. Even if the user has
7441 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7442 // In the long run, we may instead need to check if there exists a connection service
7443 // which can support video calling.
7444 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007445 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007446 return imsManager.isVtEnabledByPlatform()
7447 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7448 && imsManager.isVtEnabledByUser();
7449 } finally {
7450 Binder.restoreCallingIdentity(identity);
7451 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007452 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007453
Andrew Leea1239f22015-03-02 17:44:07 -08007454 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007455 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7456 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007457 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007458 mApp, subId, callingPackage, callingFeatureId,
7459 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007460 return false;
7461 }
7462
7463 final long identity = Binder.clearCallingIdentity();
7464 try {
7465 CarrierConfigManager configManager =
7466 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007467 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007468 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7469 } finally {
7470 Binder.restoreCallingIdentity(identity);
7471 }
Andrew Leea1239f22015-03-02 17:44:07 -08007472 }
7473
7474 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007475 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007476 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007477 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007478 return false;
7479 }
7480
7481 final long identity = Binder.clearCallingIdentity();
7482 try {
7483 CarrierConfigManager configManager =
7484 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007485 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007486 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7487 } finally {
7488 Binder.restoreCallingIdentity(identity);
7489 }
Andrew Leea1239f22015-03-02 17:44:07 -08007490 }
7491
Andrew Lee9431b832015-03-09 18:46:45 -07007492 @Override
7493 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007494 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007495 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007496 }
7497
7498 @Override
7499 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007500 final long identity = Binder.clearCallingIdentity();
7501 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007502 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007503 } finally {
7504 Binder.restoreCallingIdentity(identity);
7505 }
Andrew Lee9431b832015-03-09 18:46:45 -07007506 }
7507
Hall Liuf6668912018-10-31 17:05:23 -07007508 /**
7509 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7510 * support for the feature and device firmware support.
7511 *
7512 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7513 */
7514 @Override
7515 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007516 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007517 final Phone phone = getPhone(subscriptionId);
7518 if (phone == null) {
7519 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7520 return false;
7521 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007522 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007523 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007524 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7525 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007526 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007527 return isCarrierSupported && isDeviceSupported;
7528 } finally {
7529 Binder.restoreCallingIdentity(identity);
7530 }
Hall Liu98187582018-01-22 19:15:32 -08007531 }
7532
Hall Liuf6668912018-10-31 17:05:23 -07007533 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007534 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7535 * RTT setting, will return true if the device and carrier both support RTT.
7536 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007537 */
7538 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007539 final long identity = Binder.clearCallingIdentity();
7540 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007541 boolean isRttSupported = isRttSupported(subscriptionId);
7542 boolean isUserRttSettingOn = Settings.Secure.getInt(
7543 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7544 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7545 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7546 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007547 } finally {
7548 Binder.restoreCallingIdentity(identity);
7549 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007550 }
7551
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007552 @Deprecated
7553 @Override
7554 public String getDeviceId(String callingPackage) {
7555 return getDeviceIdWithFeature(callingPackage, null);
7556 }
7557
Sanket Padawe7310cc72015-01-14 09:53:20 -08007558 /**
7559 * Returns the unique device ID of phone, for example, the IMEI for
7560 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7561 *
7562 * <p>Requires Permission:
7563 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7564 */
7565 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007566 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007567 try {
7568 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7569 } catch (SecurityException se) {
7570 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7571 throw new SecurityException("Package " + callingPackage + " does not belong to "
7572 + Binder.getCallingUid());
7573 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007574 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007575 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007576 return null;
7577 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007578 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007579 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007580 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007581 return null;
7582 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007583
7584 final long identity = Binder.clearCallingIdentity();
7585 try {
7586 return phone.getDeviceId();
7587 } finally {
7588 Binder.restoreCallingIdentity(identity);
7589 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007590 }
7591
Ping Sunc67b7c22016-03-02 19:16:45 +08007592 /**
7593 * {@hide}
7594 * Returns the IMS Registration Status on a particular subid
7595 *
7596 * @param subId
7597 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007598 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007599 Phone phone = getPhone(subId);
7600 if (phone != null) {
7601 return phone.isImsRegistered();
7602 } else {
7603 return false;
7604 }
7605 }
7606
Santos Cordon7a1885b2015-02-03 11:15:19 -08007607 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007608 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007609 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007610 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007611 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007612 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7613 }
7614 final long identity = Binder.clearCallingIdentity();
7615 try {
7616 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7617 } finally {
7618 Binder.restoreCallingIdentity(identity);
7619 }
7620 }
7621
7622 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007623 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007624 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007625 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007626 mApp,
7627 subscriptionId,
7628 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007629 final long identity = Binder.clearCallingIdentity();
7630 try {
7631 Phone phone = getPhone(subscriptionId);
7632 if (phone == null) {
7633 return null;
7634 }
7635 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7636 } finally {
7637 Binder.restoreCallingIdentity(identity);
7638 }
7639 }
7640
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007641 /**
7642 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007643 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007644 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007645 final long identity = Binder.clearCallingIdentity();
7646 try {
7647 Phone phone = getPhone(subId);
7648 if (phone != null) {
7649 return phone.isWifiCallingEnabled();
7650 } else {
7651 return false;
7652 }
7653 } finally {
7654 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007655 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007656 }
7657
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007658 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007659 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007660 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007661 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007662 final long identity = Binder.clearCallingIdentity();
7663 try {
7664 Phone phone = getPhone(subId);
7665 if (phone != null) {
7666 return phone.isVideoEnabled();
7667 } else {
7668 return false;
7669 }
7670 } finally {
7671 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007672 }
7673 }
7674
7675 /**
7676 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7677 * defined in {@link ImsRegistrationImplBase}.
7678 */
7679 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007680 final long identity = Binder.clearCallingIdentity();
7681 try {
7682 Phone phone = getPhone(subId);
7683 if (phone != null) {
7684 return phone.getImsRegistrationTech();
7685 } else {
7686 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7687 }
7688 } finally {
7689 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007690 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007691 }
7692
Stuart Scott8eef64f2015-04-08 15:13:54 -07007693 @Override
7694 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007695 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007696 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7697 return;
7698 }
Kai Shif70f46f2021-03-03 13:59:46 -08007699 Phone defaultPhone = getDefaultPhone();
7700 if (defaultPhone != null) {
7701 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7702 mApp, getDefaultPhone().getSubId(), "factoryReset");
7703 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007704 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007705
Svet Ganovcc087f82015-05-12 20:35:54 -07007706 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007707 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7708 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007709 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007710 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007711 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007712 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007713 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007714 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007715 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007716 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007717 // There has been issues when Sms raw table somehow stores orphan
7718 // fragments. They lead to garbled message when new fragments come
7719 // in and combined with those stale ones. In case this happens again,
7720 // user can reset all network settings which will clean up this table.
7721 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007722 // Clean up IMS settings as well here.
7723 int slotId = getSlotIndex(subId);
7724 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7725 ImsManager.getInstance(mApp, slotId).factoryReset();
7726 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007727
Kai Shif70f46f2021-03-03 13:59:46 -08007728 if (defaultPhone == null) {
7729 return;
7730 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007731 // Erase modem config if erase modem on network setting is enabled.
7732 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7733 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7734 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007735 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007736 }
Kai Shif70f46f2021-03-03 13:59:46 -08007737
7738 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007739 } finally {
7740 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007741 }
7742 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007743
SongFerngWangfd89b102021-05-27 22:44:54 +08007744 @VisibleForTesting
7745 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7746 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7747 return;
7748 }
7749 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7750 RILConstants.PREFERRED_NETWORK_MODE);
7751 SubscriptionManager.setSubscriptionProperty(subId,
7752 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7753 "user=" + defaultNetworkType);
7754 phone.loadAllowedNetworksFromSubscriptionDatabase();
7755 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7756 defaultNetworkType, null);
7757 }
7758
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007759 private void cleanUpSmsRawTable(Context context) {
7760 ContentResolver resolver = context.getContentResolver();
7761 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7762 resolver.delete(uri, null, null);
7763 }
7764
Narayan Kamath1c496c22015-04-16 14:40:19 +01007765 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007766 public String getSimLocaleForSubscriber(int subId) {
7767 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7768 final Phone phone = getPhone(subId);
7769 if (phone == null) {
7770 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007771 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007772 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007773 final long identity = Binder.clearCallingIdentity();
7774 try {
chen xu5d3637b2019-01-21 23:31:38 -08007775 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007776 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007777 if (info == null) {
7778 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7779 return null;
7780 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007781 // Try and fetch the locale from the carrier properties or from the SIM language
7782 // preferences (EF-PL and EF-LI)...
7783 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007784 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007785 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7786 if (localeFromDefaultSim != null) {
7787 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7788 if (DBG) log("Using locale from subId: " + subId + " locale: "
7789 + localeFromDefaultSim);
7790 return localeFromDefaultSim.toLanguageTag();
7791 } else {
7792 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007793 }
7794 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007795
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007796 // The SIM language preferences only store a language (e.g. fr = French), not an
7797 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7798 // the SIM and carrier preferences does not include a country we add the country
7799 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007800 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007801 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007802 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007803 return mccLocale.toLanguageTag();
7804 }
7805
7806 if (DBG) log("No locale found - returning null");
7807 return null;
7808 } finally {
7809 Binder.restoreCallingIdentity(identity);
7810 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007811 }
7812
7813 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007814 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007815 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007816 }
7817
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007818 /**
7819 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7820 */
7821 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007822 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007823 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007824 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007825
Chenjie Yu1ba97252018-01-11 18:16:20 -08007826 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007827 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007828
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007829 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007830 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7831 * representing the state of the modem.
7832 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007833 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7834 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007835 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007836 */
7837 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007838 public void requestModemActivityInfo(ResultReceiver result) {
7839 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007840 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007841
7842 final long identity = Binder.clearCallingIdentity();
7843 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007844 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007845 } finally {
7846 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007847 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007848 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007849
Siddharth Rayb8114062018-06-17 15:02:38 -07007850 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7851 // less than total activity duration.
7852 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7853 if (info == null) {
7854 return false;
7855 }
7856 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007857 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7858 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7859
Siddharth Rayb8114062018-06-17 15:02:38 -07007860 return (info.isValid()
7861 && (info.getSleepTimeMillis() <= activityDurationMs)
7862 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007863 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007864 && (totalTxTimeMs <= activityDurationMs));
7865 }
7866
Jack Yu85bd38a2015-11-09 11:34:32 -08007867 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007868 * Returns the service state information on specified subscription.
7869 */
7870 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007871 public ServiceState getServiceStateForSubscriber(int subId,
7872 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7873 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007874 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007875 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007876 return null;
7877 }
7878
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007879 boolean hasFinePermission = false;
7880 boolean hasCoarsePermission = false;
7881 if (!renounceFineLocationAccess) {
7882 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7883 LocationAccessPolicy.checkLocationPermission(mApp,
7884 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7885 .setCallingPackage(callingPackage)
7886 .setCallingFeatureId(callingFeatureId)
7887 .setCallingPid(Binder.getCallingPid())
7888 .setCallingUid(Binder.getCallingUid())
7889 .setMethod("getServiceStateForSubscriber")
7890 .setLogAsInfo(true)
7891 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7892 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7893 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7894 .build());
7895 hasFinePermission =
7896 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7897 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007898
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007899 if (!renounceCoarseLocationAccess) {
7900 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7901 LocationAccessPolicy.checkLocationPermission(mApp,
7902 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7903 .setCallingPackage(callingPackage)
7904 .setCallingFeatureId(callingFeatureId)
7905 .setCallingPid(Binder.getCallingPid())
7906 .setCallingUid(Binder.getCallingUid())
7907 .setMethod("getServiceStateForSubscriber")
7908 .setLogAsInfo(true)
7909 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7910 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7911 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7912 .build());
7913 hasCoarsePermission =
7914 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7915 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007916
Jack Yu479f40e2020-10-27 21:29:25 -07007917 final Phone phone = getPhone(subId);
7918 if (phone == null) {
7919 return null;
7920 }
7921
Jordan Liu0f2bc442020-11-18 16:47:37 -08007922 final long identity = Binder.clearCallingIdentity();
7923
Jack Yu479f40e2020-10-27 21:29:25 -07007924 boolean isCallingPackageDataService = phone.getDataServicePackages()
7925 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007926 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007927 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7928 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7929 Rlog.d(LOG_TAG,
7930 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7931 return null;
7932 }
7933
Hall Liuf19c44f2018-11-27 14:38:17 -08007934 ServiceState ss = phone.getServiceState();
7935
7936 // Scrub out the location info in ServiceState depending on what level of access
7937 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007938 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007939 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7940 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007941 } finally {
7942 Binder.restoreCallingIdentity(identity);
7943 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007944 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007945
7946 /**
7947 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7948 *
7949 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7950 * voicemail ringtone.
7951 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7952 * PhoneAccount.
7953 */
7954 @Override
7955 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007956 final long identity = Binder.clearCallingIdentity();
7957 try {
7958 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7959 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007960 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007961 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007962
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007963 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7964 } finally {
7965 Binder.restoreCallingIdentity(identity);
7966 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007967 }
7968
7969 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007970 * Sets the per-account voicemail ringtone.
7971 *
7972 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7973 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7974 *
7975 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7976 * voicemail ringtone.
7977 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7978 * PhoneAccount.
7979 */
7980 @Override
7981 public void setVoicemailRingtoneUri(String callingPackage,
7982 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007983 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007984 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007985 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7986 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007987 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7988 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7989 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007990 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007991
7992 final long identity = Binder.clearCallingIdentity();
7993 try {
7994 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7995 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007996 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007997 }
7998 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7999 } finally {
8000 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008001 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008002 }
8003
8004 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008005 * Returns whether vibration is set for voicemail notification in Phone settings.
8006 *
8007 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8008 * voicemail vibration setting.
8009 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8010 */
8011 @Override
8012 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008013 final long identity = Binder.clearCallingIdentity();
8014 try {
8015 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8016 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008017 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008018 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008019
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008020 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8021 } finally {
8022 Binder.restoreCallingIdentity(identity);
8023 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008024 }
8025
Youhan Wange64578a2016-05-02 15:32:42 -07008026 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008027 * Sets the per-account voicemail vibration.
8028 *
8029 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8030 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8031 *
8032 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8033 * voicemail vibration setting.
8034 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8035 * specific PhoneAccount.
8036 */
8037 @Override
8038 public void setVoicemailVibrationEnabled(String callingPackage,
8039 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008040 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008041 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008042 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8043 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008044 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8045 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8046 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008047 }
8048
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008049 final long identity = Binder.clearCallingIdentity();
8050 try {
8051 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8052 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008053 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008054 }
8055 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8056 } finally {
8057 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008058 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008059 }
8060
8061 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008062 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8063 *
8064 * @throws SecurityException if the caller does not have the required permission
8065 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008066 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008067 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008068 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008069 }
8070
8071 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008072 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8073 * permission.
8074 *
8075 * @throws SecurityException if the caller does not have the required permission
8076 */
8077 private void enforceSendSmsPermission() {
8078 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8079 }
8080
8081 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008082 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008083 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008084 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008085 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008086 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008087 final long identity = Binder.clearCallingIdentity();
8088 try {
8089 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008090 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008091 if (componentName == null) {
8092 throw new SecurityException(
8093 "Caller not current active visual voicemail package[null]");
8094 }
8095 String vvmPackage = componentName.getPackageName();
8096 if (!callingPackage.equals(vvmPackage)) {
8097 throw new SecurityException("Caller not current active visual voicemail package["
8098 + vvmPackage + "]");
8099 }
8100 } finally {
8101 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008102 }
8103 }
8104
8105 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008106 * Return the application ID for the app type.
8107 *
8108 * @param subId the subscription ID that this request applies to.
8109 * @param appType the uicc app type.
8110 * @return Application ID for specificied app type, or null if no uicc.
8111 */
8112 @Override
8113 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008114 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008115 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008116
8117 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008118 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008119 if (phone == null) {
8120 return null;
8121 }
8122 String aid = null;
8123 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008124 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008125 .getApplicationByType(appType).getAid();
8126 } catch (Exception e) {
8127 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8128 }
8129 return aid;
8130 } finally {
8131 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008132 }
Youhan Wange64578a2016-05-02 15:32:42 -07008133 }
8134
Youhan Wang4001d252016-05-11 10:29:41 -07008135 /**
8136 * Return the Electronic Serial Number.
8137 *
8138 * @param subId the subscription ID that this request applies to.
8139 * @return ESN or null if error.
8140 */
8141 @Override
8142 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008143 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008144 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008145
8146 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008147 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008148 if (phone == null) {
8149 return null;
8150 }
8151 String esn = null;
8152 try {
8153 esn = phone.getEsn();
8154 } catch (Exception e) {
8155 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8156 }
8157 return esn;
8158 } finally {
8159 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008160 }
Youhan Wang4001d252016-05-11 10:29:41 -07008161 }
8162
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008163 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008164 * Return the Preferred Roaming List Version.
8165 *
8166 * @param subId the subscription ID that this request applies to.
8167 * @return PRLVersion or null if error.
8168 */
8169 @Override
8170 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008171 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008172 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008173
8174 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008175 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008176 if (phone == null) {
8177 return null;
8178 }
8179 String cdmaPrlVersion = null;
8180 try {
8181 cdmaPrlVersion = phone.getCdmaPrlVersion();
8182 } catch (Exception e) {
8183 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8184 }
8185 return cdmaPrlVersion;
8186 } finally {
8187 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008188 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008189 }
8190
8191 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008192 * Get snapshot of Telephony histograms
8193 * @return List of Telephony histograms
8194 * @hide
8195 */
8196 @Override
8197 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008198 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8199 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008200
8201 final long identity = Binder.clearCallingIdentity();
8202 try {
8203 return RIL.getTelephonyRILTimingHistograms();
8204 } finally {
8205 Binder.restoreCallingIdentity(identity);
8206 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008207 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008208
8209 /**
8210 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008211 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8212 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008213 * Require system privileges. In the future we may add this to carrier APIs.
8214 *
Michele Berionne482f8202018-11-27 18:57:59 -08008215 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008216 */
8217 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008218 @TelephonyManager.SetCarrierRestrictionResult
8219 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008220 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008221 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008222
Michele Berionne482f8202018-11-27 18:57:59 -08008223 if (carrierRestrictionRules == null) {
8224 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008225 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008226
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008227 final long identity = Binder.clearCallingIdentity();
8228 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008229 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008230 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008231 } finally {
8232 Binder.restoreCallingIdentity(identity);
8233 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008234 }
8235
8236 /**
8237 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008238 * Get the allowed carrier list and the excluded carrier list, including the priority between
8239 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008240 * Require system privileges. In the future we may add this to carrier APIs.
8241 *
Michele Berionne482f8202018-11-27 18:57:59 -08008242 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008243 */
8244 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008245 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008246 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008247 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008248
8249 final long identity = Binder.clearCallingIdentity();
8250 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008251 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8252 if (response instanceof CarrierRestrictionRules) {
8253 return (CarrierRestrictionRules) response;
8254 }
8255 // Response is an Exception of some kind,
8256 // which is signalled to the user as a NULL retval
8257 return null;
8258 } catch (Exception e) {
8259 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8260 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008261 } finally {
8262 Binder.restoreCallingIdentity(identity);
8263 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008264 }
8265
fionaxu59545b42016-05-25 15:53:37 -07008266 /**
fionaxu59545b42016-05-25 15:53:37 -07008267 * Action set from carrier signalling broadcast receivers to enable/disable radio
8268 * @param subId the subscription ID that this action applies to.
8269 * @param enabled control enable or disable radio.
8270 * {@hide}
8271 */
8272 @Override
8273 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8274 enforceModifyPermission();
8275 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008276
8277 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008278 if (phone == null) {
8279 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8280 return;
8281 }
8282 try {
8283 phone.carrierActionSetRadioEnabled(enabled);
8284 } catch (Exception e) {
8285 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008286 } finally {
8287 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008288 }
8289 }
8290
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008291 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008292 * Enable or disable Voice over NR (VoNR)
8293 * @param subId the subscription ID that this action applies to.
8294 * @param enabled enable or disable VoNR.
8295 * @return operation result.
8296 */
8297 @Override
8298 public int setVoNrEnabled(int subId, boolean enabled) {
8299 enforceModifyPermission();
8300 final Phone phone = getPhone(subId);
8301
8302 final long identity = Binder.clearCallingIdentity();
8303 if (phone == null) {
8304 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8305 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8306 }
8307
8308 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8309 try {
8310 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8311 workSource);
8312 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008313
8314 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8315 if (DBG) {
8316 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8317 }
8318 SubscriptionManager.setSubscriptionProperty(
8319 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8320 (enabled ? "1" : "0"));
8321 }
8322
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008323 return result;
8324 } finally {
8325 Binder.restoreCallingIdentity(identity);
8326 }
8327 }
8328
8329 /**
8330 * Is voice over NR enabled
8331 * @return true if VoNR is enabled else false
8332 */
8333 @Override
8334 public boolean isVoNrEnabled(int subId) {
8335 enforceReadPrivilegedPermission("isVoNrEnabled");
8336 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8337 final long identity = Binder.clearCallingIdentity();
8338 try {
8339 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8340 null, subId, workSource);
8341 if (DBG) log("isVoNrEnabled: " + isEnabled);
8342 return isEnabled;
8343 } finally {
8344 Binder.restoreCallingIdentity(identity);
8345 }
8346 }
8347
8348 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008349 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8350 * network status based on which carrier apps could apply actions accordingly,
8351 * enable/disable default url handler for example.
8352 *
8353 * @param subId the subscription ID that this action applies to.
8354 * @param report control start/stop reporting the default network status.
8355 * {@hide}
8356 */
8357 @Override
8358 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8359 enforceModifyPermission();
8360 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008361
8362 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008363 if (phone == null) {
8364 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8365 return;
8366 }
8367 try {
8368 phone.carrierActionReportDefaultNetworkStatus(report);
8369 } catch (Exception e) {
8370 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008371 } finally {
8372 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008373 }
8374 }
8375
8376 /**
fionaxud9622282017-07-17 17:51:30 -07008377 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8378 * @param subId the subscription ID that this action applies to.
8379 * {@hide}
8380 */
8381 @Override
8382 public void carrierActionResetAll(int subId) {
8383 enforceModifyPermission();
8384 final Phone phone = getPhone(subId);
8385 if (phone == null) {
8386 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8387 return;
8388 }
8389 try {
8390 phone.carrierActionResetAll();
8391 } catch (Exception e) {
8392 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8393 }
8394 }
8395
8396 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008397 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8398 * bug report is being generated.
8399 */
8400 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008401 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008402 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8403 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008404 writer.println("Permission Denial: can't dump Phone from pid="
8405 + Binder.getCallingPid()
8406 + ", uid=" + Binder.getCallingUid()
8407 + "without permission "
8408 + android.Manifest.permission.DUMP);
8409 return;
8410 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008411 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008412 }
Jack Yueb89b242016-06-22 13:27:47 -07008413
Brad Ebingerdac2f002018-04-03 15:17:52 -07008414 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008415 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8416 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8417 @NonNull String[] args) {
8418 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8419 this, in.getFileDescriptor(), out.getFileDescriptor(),
8420 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008421 }
8422
Jack Yueb89b242016-06-22 13:27:47 -07008423 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008424 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008425 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008426 * @param reason the reason the data enable change is taking place
8427 * @param enabled True if enabling the data, otherwise disabling.
8428 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008429 */
8430 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008431 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008432 boolean enabled) {
8433 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8434 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8435 try {
8436 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008437 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008438 } catch (SecurityException se) {
8439 enforceModifyPermission();
8440 }
8441 } else {
8442 enforceModifyPermission();
8443 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008444
8445 final long identity = Binder.clearCallingIdentity();
8446 try {
8447 Phone phone = getPhone(subId);
8448 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008449 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8450 phone.carrierActionSetMeteredApnsEnabled(enabled);
8451 } else {
Jack Yu99e87332021-12-17 23:14:15 -08008452 if (phone.isUsingNewDataStack()) {
8453 phone.getDataSettingsManager().setDataEnabled(reason, enabled);
8454 } else {
8455 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8456 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008457 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008458 }
8459 } finally {
8460 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008461 }
8462 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008463
8464 /**
8465 * Get Client request stats
8466 * @return List of Client Request Stats
8467 * @hide
8468 */
8469 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008470 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8471 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008472 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008473 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008474 return null;
8475 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008476 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008477
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008478 final long identity = Binder.clearCallingIdentity();
8479 try {
8480 if (phone != null) {
8481 return phone.getClientRequestStats();
8482 }
8483
8484 return null;
8485 } finally {
8486 Binder.restoreCallingIdentity(identity);
8487 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008488 }
8489
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008490 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008491 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008492 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008493 }
Jack Yueb4124c2017-02-16 15:32:43 -08008494
8495 /**
Grace Chen70990072017-03-24 17:21:30 -07008496 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008497 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008498 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008499 * @param state State of SIM (power down, power up, pass through)
8500 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8501 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8502 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008503 *
8504 **/
8505 @Override
Grace Chen70990072017-03-24 17:21:30 -07008506 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008507 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008508 Phone phone = PhoneFactory.getPhone(slotIndex);
8509
vagdeviaf9a5b92018-08-15 16:01:53 -07008510 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8511
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008512 final long identity = Binder.clearCallingIdentity();
8513 try {
8514 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008515 phone.setSimPowerState(state, null, workSource);
8516 }
8517 } finally {
8518 Binder.restoreCallingIdentity(identity);
8519 }
8520 }
8521
8522 /**
8523 * Set SIM card power state.
8524 *
8525 * @param slotIndex SIM slot id.
8526 * @param state State of SIM (power down, power up, pass through)
8527 * @param callback callback to trigger after success or failure
8528 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8529 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8530 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8531 *
8532 **/
8533 @Override
8534 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8535 IIntegerConsumer callback) {
8536 enforceModifyPermission();
8537 Phone phone = PhoneFactory.getPhone(slotIndex);
8538
8539 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8540
8541 final long identity = Binder.clearCallingIdentity();
8542 try {
8543 if (phone != null) {
8544 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8545 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008546 }
8547 } finally {
8548 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008549 }
8550 }
Shuo Qiandd210312017-04-12 22:11:33 +00008551
Tyler Gunn65d45c22017-06-05 11:22:26 -07008552 private boolean isUssdApiAllowed(int subId) {
8553 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008554 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008555 if (configManager == null) {
8556 return false;
8557 }
8558 PersistableBundle pb = configManager.getConfigForSubId(subId);
8559 if (pb == null) {
8560 return false;
8561 }
8562 return pb.getBoolean(
8563 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8564 }
8565
Shuo Qiandd210312017-04-12 22:11:33 +00008566 /**
8567 * Check if phone is in emergency callback mode
8568 * @return true if phone is in emergency callback mode
8569 * @param subId sub id
8570 */
goneil9c5f4872017-12-05 14:07:56 -08008571 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008572 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008573 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008574 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008575
8576 final long identity = Binder.clearCallingIdentity();
8577 try {
8578 if (phone != null) {
8579 return phone.isInEcm();
8580 } else {
8581 return false;
8582 }
8583 } finally {
8584 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008585 }
8586 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008587
8588 /**
8589 * Get the current signal strength information for the given subscription.
8590 * Because this information is not updated when the device is in a low power state
8591 * it should not be relied-upon to be current.
8592 * @param subId Subscription index
8593 * @return the most recent cached signal strength info from the modem
8594 */
8595 @Override
8596 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008597 final long identity = Binder.clearCallingIdentity();
8598 try {
8599 Phone p = getPhone(subId);
8600 if (p == null) {
8601 return null;
8602 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008603
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008604 return p.getSignalStrength();
8605 } finally {
8606 Binder.restoreCallingIdentity(identity);
8607 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008608 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008609
Pengquan Meng77b7f132018-08-22 14:49:57 -07008610 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008611 * Get the current modem radio state for the given slot.
8612 * @param slotIndex slot index.
8613 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008614 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008615 * @return the current radio power state from the modem
8616 */
8617 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008618 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008619 Phone phone = PhoneFactory.getPhone(slotIndex);
8620 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008621 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8622 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008623 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8624 }
8625
8626 final long identity = Binder.clearCallingIdentity();
8627 try {
8628 return phone.getRadioPowerState();
8629 } finally {
8630 Binder.restoreCallingIdentity(identity);
8631 }
8632 }
8633 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8634 }
8635
8636 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008637 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8638 *
8639 * <p>Requires one of the following permissions:
8640 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008641 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008642 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8643 * privileges.
8644 *
8645 * @param subId subscription id
8646 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8647 * {@code false}.
8648 */
8649 @Override
8650 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008651 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008652 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008653 try {
8654 mApp.enforceCallingOrSelfPermission(
8655 android.Manifest.permission.ACCESS_NETWORK_STATE,
8656 functionName);
8657 } catch (Exception e) {
8658 mApp.enforceCallingOrSelfPermission(
8659 permission.READ_BASIC_PHONE_STATE, functionName);
8660 }
Shuo Qian093013d2020-08-13 15:42:55 -07008661 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008662 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008663 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008664 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008665
Pengquan Menga1bb6272018-09-06 09:59:22 -07008666 boolean isEnabled = false;
8667 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008668 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008669 Phone phone = getPhone(subId);
8670 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008671 } finally {
8672 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008673 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008674 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008675 }
8676
8677
8678 /**
8679 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8680 *
8681 * <p> Requires permission:
8682 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8683 * privileges.
8684 *
8685 * @param subId subscription id
8686 * @param isEnabled {@code true} means enable, {@code false} means disable.
8687 */
8688 @Override
8689 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008690 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8691 mApp, subId, "setDataRoamingEnabled");
8692
Pengquan Menga1bb6272018-09-06 09:59:22 -07008693 final long identity = Binder.clearCallingIdentity();
8694 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008695 Phone phone = getPhone(subId);
8696 if (phone != null) {
8697 phone.setDataRoamingEnabled(isEnabled);
8698 }
8699 } finally {
8700 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008701 }
8702 }
8703
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008704 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008705 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008706 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008707 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008708 mApp, subId, "isManualNetworkSelectionAllowed");
8709
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008710 boolean isAllowed = true;
8711 final long identity = Binder.clearCallingIdentity();
8712 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008713 Phone phone = getPhone(subId);
8714 if (phone != null) {
8715 isAllowed = phone.isCspPlmnEnabled();
8716 }
8717 } finally {
8718 Binder.restoreCallingIdentity(identity);
8719 }
8720 return isAllowed;
8721 }
8722
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008723 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8724 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008725 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008726 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008727 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008728 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8729 if (phone == null) {
8730 return false;
8731 }
8732 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8733 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8734 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008735 }
8736
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008737 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008738 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008739 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008740 mApp.getSystemService(AppOpsManager.class)
8741 .checkPackage(Binder.getCallingUid(), callingPackage);
8742
Jordan Liu1e142fc2019-04-22 15:10:43 -07008743 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008744 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008745 try {
8746 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008747 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008748 } catch (SecurityException e) {
8749 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8750 // has carrier privileges on an active UICC
8751 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8752 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008753 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008754 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008755 }
sandeepjsb6c87872021-09-27 15:34:44 +00008756 // checking compatibility, if calling app's target SDK is T and beyond.
8757 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8758 Binder.getCallingUid())) {
8759 isIccIdAccessRestricted = true;
8760 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008761 final long identity = Binder.clearCallingIdentity();
8762 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008763 UiccController uiccController = UiccController.getInstance();
8764 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008765 if (hasReadPermission) {
8766 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008767 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008768
8769 // Remove private info if the caller doesn't have access
8770 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8771 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008772 //setting the value after compatibility check
8773 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008774 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8775 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008776 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008777 if (card == null) {
8778 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008779 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008780 continue;
8781 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008782 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8783 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008784 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008785 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008786 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008787 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8788 for (UiccPortInfo portInfo : portInfos) {
8789 UiccPort port = uiccController.getUiccPortForSlot(
8790 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8791 if (port == null) {
8792 // assume no access if port is null
8793 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8794 continue;
8795 }
8796 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8797 uiccPortInfos.add(portInfo);
8798 } else {
8799 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8800 }
8801 }
8802 filteredInfos.add(new UiccCardInfo(
8803 cardInfo.isEuicc(),
8804 cardInfo.getCardId(),
8805 null,
8806 cardInfo.getPhysicalSlotIndex(),
8807 cardInfo.isRemovable(),
8808 cardInfo.isMultipleEnabledProfilesSupported(),
8809 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008810 }
8811 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008812 } finally {
8813 Binder.restoreCallingIdentity(identity);
8814 }
8815 }
8816
sandeepjsb6c87872021-09-27 15:34:44 +00008817 /**
8818 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8819 * generally private and require carrier privileges to view.
8820 *
8821 * @hide
8822 */
8823 @NonNull
8824 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8825 List<UiccPortInfo> portinfo = new ArrayList<>();
8826 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8827 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8828 }
8829 return new UiccCardInfo(
8830 cardInfo.isEuicc(),
8831 cardInfo.getCardId(),
8832 null,
8833 cardInfo.getPhysicalSlotIndex(),
8834 cardInfo.isRemovable(),
8835 cardInfo.isMultipleEnabledProfilesSupported(),
8836 portinfo
8837 );
8838 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008839
sandeepjsb6c87872021-09-27 15:34:44 +00008840 /**
8841 * @hide
8842 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8843 * These values are generally private and require carrier privileges to view.
8844 */
8845 @NonNull
8846 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8847 return new UiccPortInfo(
8848 UiccPortInfo.ICCID_REDACTED,
8849 portInfo.getPortIndex(),
8850 portInfo.getLogicalSlotIndex(),
8851 portInfo.isActive()
8852 );
8853 }
8854 @Override
8855 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008856 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00008857 mApp.getSystemService(AppOpsManager.class)
8858 .checkPackage(Binder.getCallingUid(), callingPackage);
8859
8860 boolean hasReadPermission = false;
8861 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008862
8863 try {
8864 enforceReadPrivilegedPermission("getUiccSlotsInfo");
8865 hasReadPermission = true;
8866 } catch (SecurityException e) {
8867 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8868 // has carrier privileges on an active UICC
8869 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8870 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8871 hasReadPermission = true;
8872 }
8873 }
8874
8875 // checking compatibility, if calling app's target SDK is T and beyond.
8876 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8877 Binder.getCallingUid())) {
8878 isLogicalSlotAccessRestricted = true;
8879 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008880 final long identity = Binder.clearCallingIdentity();
8881 try {
8882 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00008883 if (slots == null || slots.length == 0) {
8884 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008885 return null;
8886 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008887 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8888 for (int i = 0; i < slots.length; i++) {
8889 UiccSlot slot = slots[i];
8890 if (slot == null) {
8891 continue;
8892 }
8893
Jordan Liu7be7e652019-05-06 18:55:02 +00008894 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008895 UiccCard card = slot.getUiccCard();
8896 if (card != null) {
8897 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008898 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008899 cardId = slot.getEid();
8900 if (TextUtils.isEmpty(cardId)) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008901 // If cardId is null, use iccId of default port as cardId. Check if has
8902 // read permission otherwise set to null.(card is null which means no
8903 // carrier permission)
8904 cardId = hasReadPermission ? slot.getIccId(
8905 TelephonyManager.DEFAULT_PORT_INDEX) : null;
Jordan Liu01bd00d2019-09-12 16:19:43 -07008906 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008907 }
8908
Jordan Liu857451f2019-05-09 16:35:35 -07008909 if (cardId != null) {
8910 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8911 // if cardId is an EID, it's all digits so this is fine
8912 cardId = IccUtils.stripTrailingFs(cardId);
8913 }
8914
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008915 int cardState = 0;
8916 switch (slot.getCardState()) {
8917 case CARDSTATE_ABSENT:
8918 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8919 break;
8920 case CARDSTATE_PRESENT:
8921 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8922 break;
8923 case CARDSTATE_ERROR:
8924 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8925 break;
8926 case CARDSTATE_RESTRICTED:
8927 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8928 break;
8929 default:
8930 break;
8931
8932 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008933 List<UiccPortInfo> portInfos = new ArrayList<>();
8934 int[] portIndexes = slot.getPortList();
8935 for (int portIdx : portIndexes) {
8936 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
8937 callingPackage, hasReadPermission));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00008938 portInfos.add(new UiccPortInfo(iccId, portIdx,
8939 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008940 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008941 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008942 slot.isEuicc(),
8943 cardId,
8944 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08008945 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008946 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00008947 //setting the value after compatibility check
8948 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008949 }
8950 return infos;
8951 } finally {
8952 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008953 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008954 }
8955
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008956 /* Returns null if doesn't have read permission or carrier privilege access. */
8957 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
8958 boolean hasReadPermission) {
8959 String iccId = slot.getIccId(portIndex);
8960 if (hasReadPermission) { // if has read permission
8961 return iccId;
8962 } else {
8963 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
8964 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
8965 // if no read permission, checking carrier privilege access
8966 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8967 return iccId;
8968 }
8969 }
8970 }
8971 // No read permission or carrier privilege access.
8972 return UiccPortInfo.ICCID_REDACTED;
8973 }
8974
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008975 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00008976 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008977 public boolean switchSlots(int[] physicalSlots) {
8978 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008979
8980 final long identity = Binder.clearCallingIdentity();
8981 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008982 List<UiccSlotMapping> slotMappings = new ArrayList<>();
8983 for (int i = 0; i < physicalSlots.length; i++) {
8984 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
8985 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
8986 physicalSlots[i], i));
8987 }
8988 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008989 } finally {
8990 Binder.restoreCallingIdentity(identity);
8991 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008992 }
Jack Yu4c988042018-02-27 15:30:01 -08008993
8994 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00008995 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
8996 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
8997 enforceModifyPermission();
8998
8999 final long identity = Binder.clearCallingIdentity();
9000 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009001 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009002 } finally {
9003 Binder.restoreCallingIdentity(identity);
9004 }
9005 }
9006
9007 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009008 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009009 final long identity = Binder.clearCallingIdentity();
9010 try {
9011 return UiccController.getInstance().getCardIdForDefaultEuicc();
9012 } finally {
9013 Binder.restoreCallingIdentity(identity);
9014 }
9015 }
9016
Pengquan Meng85728fb2018-03-12 16:31:21 -07009017 /**
goneil47ffb6e2018-04-06 15:40:58 -07009018 * A test API to reload the UICC profile.
9019 *
9020 * <p>Requires that the calling app has permission
9021 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9022 * @hide
9023 */
9024 @Override
9025 public void refreshUiccProfile(int subId) {
9026 enforceModifyPermission();
9027
9028 final long identity = Binder.clearCallingIdentity();
9029 try {
9030 Phone phone = getPhone(subId);
9031 if (phone == null) {
9032 return;
9033 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009034 UiccPort uiccPort = phone.getUiccPort();
9035 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009036 return;
9037 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009038 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009039 if (uiccProfile == null) {
9040 return;
9041 }
9042 uiccProfile.refresh();
9043 } finally {
9044 Binder.restoreCallingIdentity(identity);
9045 }
9046 }
9047
9048 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009049 * Returns false if the mobile data is disabled by default, otherwise return true.
9050 */
9051 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009052 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009053 }
9054
9055 /**
9056 * Returns true if the data roaming is enabled by default, i.e the system property
9057 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9058 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9059 */
9060 private boolean getDefaultDataRoamingEnabled(int subId) {
9061 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009062 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009063 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009064 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9065 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9066 return isDataRoamingEnabled;
9067 }
9068
9069 /**
9070 * Returns the default network type for the given {@code subId}, if the default network type is
9071 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9072 */
9073 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009074 List<Integer> list = TelephonyProperties.default_network();
9075 int phoneId = mSubscriptionController.getPhoneId(subId);
9076 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9077 return list.get(phoneId);
9078 }
9079 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009080 }
fionaxua13278b2018-03-21 00:08:13 -07009081
9082 @Override
9083 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009084 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009085 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009086
9087 final long identity = Binder.clearCallingIdentity();
9088 try {
9089 final Phone phone = getPhone(subId);
9090 if (phone == null) {
9091 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9092 return;
9093 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009094 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9095 if (cpt != null) {
9096 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9097 }
9098 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009099 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9100 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009101 if (carrierPrivilegeRules == null) {
9102 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9103 } else {
9104 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9105 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009106 } finally {
9107 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009108 }
fionaxua13278b2018-03-21 00:08:13 -07009109 }
9110
9111 @Override
9112 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009113 enforceReadPrivilegedPermission("getCarrierIdListVersion");
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("getCarrierIdListVersion fails with invalid subId: " + subId);
9120 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9121 }
9122 return phone.getCarrierIdListVersion();
9123 } finally {
9124 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009125 }
fionaxua13278b2018-03-21 00:08:13 -07009126 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009127
9128 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009129 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9130 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009131 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009132 mApp, subId, callingPackage, callingFeatureId,
9133 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009134 return -1;
9135 }
9136
9137 final long identity = Binder.clearCallingIdentity();
9138 try {
9139 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9140 } finally {
9141 Binder.restoreCallingIdentity(identity);
9142 }
9143 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009144
9145 @Override
9146 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009147 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009148 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009149 mApp, subId, "getCdmaRoamingMode");
9150
9151 final long identity = Binder.clearCallingIdentity();
9152 try {
9153 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9154 } finally {
9155 Binder.restoreCallingIdentity(identity);
9156 }
9157 }
9158
9159 @Override
9160 public boolean setCdmaRoamingMode(int subId, int mode) {
9161 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9162 mApp, subId, "setCdmaRoamingMode");
9163
9164 final long identity = Binder.clearCallingIdentity();
9165 try {
9166 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9167 } finally {
9168 Binder.restoreCallingIdentity(identity);
9169 }
9170 }
9171
9172 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009173 public int getCdmaSubscriptionMode(int subId) {
9174 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009175 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009176 mApp, subId, "getCdmaSubscriptionMode");
9177
9178 final long identity = Binder.clearCallingIdentity();
9179 try {
9180 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9181 } finally {
9182 Binder.restoreCallingIdentity(identity);
9183 }
9184 }
9185
9186 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009187 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9188 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9189 mApp, subId, "setCdmaSubscriptionMode");
9190
9191 final long identity = Binder.clearCallingIdentity();
9192 try {
9193 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9194 } finally {
9195 Binder.restoreCallingIdentity(identity);
9196 }
9197 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009198
sqianc5eccab2018-10-19 18:46:41 -07009199 @Override
sqian8c685422019-02-22 15:55:18 -08009200 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009201 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009202 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009203 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9204 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009205 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9206 }
9207 final long identity = Binder.clearCallingIdentity();
9208 try {
sqian854d44b2018-12-12 16:48:18 -08009209 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9210 for (Phone phone: PhoneFactory.getPhones()) {
9211 if (phone.getEmergencyNumberTracker() != null
9212 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9213 emergencyNumberListInternal.put(
9214 phone.getSubId(),
9215 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9216 }
sqian11b7a0e2018-12-05 18:48:28 -08009217 }
sqian854d44b2018-12-12 16:48:18 -08009218 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009219 } finally {
9220 Binder.restoreCallingIdentity(identity);
9221 }
sqianc5eccab2018-10-19 18:46:41 -07009222 }
9223
9224 @Override
sqian8c685422019-02-22 15:55:18 -08009225 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009226 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009227 if (!exactMatch) {
9228 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009229 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009230 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009231 }
9232 final long identity = Binder.clearCallingIdentity();
9233 try {
sqian854d44b2018-12-12 16:48:18 -08009234 for (Phone phone: PhoneFactory.getPhones()) {
9235 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009236 && phone.getEmergencyNumberTracker()
9237 .isEmergencyNumber(number, exactMatch)) {
9238 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009239 }
sqian11b7a0e2018-12-05 18:48:28 -08009240 }
9241 return false;
9242 } finally {
9243 Binder.restoreCallingIdentity(identity);
9244 }
9245 }
9246
sqianf4ca7ed2019-01-15 18:32:07 -08009247 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009248 * Start emergency callback mode for GsmCdmaPhone for testing.
9249 */
9250 @Override
9251 public void startEmergencyCallbackMode() {
9252 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9253 "startEmergencyCallbackMode");
9254 enforceModifyPermission();
9255 final long identity = Binder.clearCallingIdentity();
9256 try {
9257 for (Phone phone : PhoneFactory.getPhones()) {
9258 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9259 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9260 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9261 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9262 gsmCdmaPhone.obtainMessage(
9263 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9264 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9265 }
9266 }
9267 } finally {
9268 Binder.restoreCallingIdentity(identity);
9269 }
9270 }
9271
9272 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009273 * Update emergency number list for test mode.
9274 */
9275 @Override
9276 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9277 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9278 "updateEmergencyNumberListTestMode");
9279
9280 final long identity = Binder.clearCallingIdentity();
9281 try {
9282 for (Phone phone: PhoneFactory.getPhones()) {
9283 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9284 if (tracker != null) {
9285 tracker.executeEmergencyNumberTestModeCommand(action, num);
9286 }
9287 }
9288 } finally {
9289 Binder.restoreCallingIdentity(identity);
9290 }
9291 }
9292
9293 /**
9294 * Get the full emergency number list for test mode.
9295 */
9296 @Override
9297 public List<String> getEmergencyNumberListTestMode() {
9298 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9299 "getEmergencyNumberListTestMode");
9300
9301 final long identity = Binder.clearCallingIdentity();
9302 try {
9303 Set<String> emergencyNumbers = new HashSet<>();
9304 for (Phone phone: PhoneFactory.getPhones()) {
9305 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9306 if (tracker != null) {
9307 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9308 emergencyNumbers.add(num.getNumber());
9309 }
9310 }
9311 }
9312 return new ArrayList<>(emergencyNumbers);
9313 } finally {
9314 Binder.restoreCallingIdentity(identity);
9315 }
9316 }
9317
chen xud6b45bd2018-10-30 22:27:10 -07009318 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009319 public int getEmergencyNumberDbVersion(int subId) {
9320 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9321
9322 final long identity = Binder.clearCallingIdentity();
9323 try {
9324 final Phone phone = getPhone(subId);
9325 if (phone == null) {
9326 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9327 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9328 }
9329 return phone.getEmergencyNumberDbVersion();
9330 } finally {
9331 Binder.restoreCallingIdentity(identity);
9332 }
9333 }
9334
9335 @Override
9336 public void notifyOtaEmergencyNumberDbInstalled() {
9337 enforceModifyPermission();
9338
9339 final long identity = Binder.clearCallingIdentity();
9340 try {
9341 for (Phone phone: PhoneFactory.getPhones()) {
9342 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9343 if (tracker != null) {
9344 tracker.updateOtaEmergencyNumberDatabase();
9345 }
9346 }
9347 } finally {
9348 Binder.restoreCallingIdentity(identity);
9349 }
9350 }
9351
9352 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009353 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009354 enforceActiveEmergencySessionPermission();
9355
9356 final long identity = Binder.clearCallingIdentity();
9357 try {
9358 for (Phone phone: PhoneFactory.getPhones()) {
9359 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9360 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009361 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9362 }
9363 }
9364 } finally {
9365 Binder.restoreCallingIdentity(identity);
9366 }
9367 }
9368
9369 @Override
9370 public void resetOtaEmergencyNumberDbFilePath() {
9371 enforceActiveEmergencySessionPermission();
9372
9373 final long identity = Binder.clearCallingIdentity();
9374 try {
9375 for (Phone phone: PhoneFactory.getPhones()) {
9376 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9377 if (tracker != null) {
9378 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009379 }
9380 }
9381 } finally {
9382 Binder.restoreCallingIdentity(identity);
9383 }
9384 }
9385
9386 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009387 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9388 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9389 Phone phone = getPhone(subId);
9390 if (phone == null) {
9391 return null;
9392 }
9393 final long identity = Binder.clearCallingIdentity();
9394 try {
9395 UiccProfile profile = UiccController.getInstance()
9396 .getUiccProfileForPhone(phone.getPhoneId());
9397 if (profile != null) {
9398 return profile.getCertsFromCarrierPrivilegeAccessRules();
9399 }
9400 } finally {
9401 Binder.restoreCallingIdentity(identity);
9402 }
9403 return null;
9404 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009405
9406 /**
9407 * Enable or disable a modem stack.
9408 */
9409 @Override
9410 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9411 enforceModifyPermission();
9412
9413 final long identity = Binder.clearCallingIdentity();
9414 try {
9415 Phone phone = PhoneFactory.getPhone(slotIndex);
9416 if (phone == null) {
9417 return false;
9418 } else {
9419 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9420 }
9421 } finally {
9422 Binder.restoreCallingIdentity(identity);
9423 }
9424 }
Michelecea4cf22018-12-21 15:00:11 -08009425
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009426 /**
9427 * Whether a modem stack is enabled or not.
9428 */
9429 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009430 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9431 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009432 Phone phone = PhoneFactory.getPhone(slotIndex);
9433 if (phone == null) return false;
9434
9435 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009436 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9437 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009438 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9439 }
9440
9441 final long identity = Binder.clearCallingIdentity();
9442 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009443 try {
9444 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9445 } catch (NoSuchElementException ex) {
9446 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9447 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009448 } finally {
9449 Binder.restoreCallingIdentity(identity);
9450 }
9451 }
9452
Michelecea4cf22018-12-21 15:00:11 -08009453 @Override
Michele0ea7d782019-03-19 14:58:42 -07009454 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009455 enforceModifyPermission();
9456
9457 final long identity = Binder.clearCallingIdentity();
9458 try {
9459 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009460 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009461 .commit();
9462 } finally {
9463 Binder.restoreCallingIdentity(identity);
9464 }
9465 }
9466
9467 @Override
Michele0ea7d782019-03-19 14:58:42 -07009468 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009469 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009470 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009471 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9472 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009473 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009474 }
Michelecea4cf22018-12-21 15:00:11 -08009475
9476 final long identity = Binder.clearCallingIdentity();
9477 try {
Michele0ea7d782019-03-19 14:58:42 -07009478 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009479 } finally {
9480 Binder.restoreCallingIdentity(identity);
9481 }
9482 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009483
Michele0ea7d782019-03-19 14:58:42 -07009484 @TelephonyManager.IsMultiSimSupportedResult
9485 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009486 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9487 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9488 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009489 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9490 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009491 }
9492 // Check if the hardware supports multisim functionality. If usage of multisim is not
9493 // supported by the modem, indicate that it is restricted.
9494 PhoneCapability staticCapability =
9495 mPhoneConfigurationManager.getStaticPhoneCapability();
9496 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009497 loge("isMultiSimSupportedInternal: no static configuration available");
9498 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009499 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009500 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009501 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9502 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009503 }
9504 // Check if support of multiple SIMs is restricted by carrier
9505 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009506 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009507 }
9508
Michele0ea7d782019-03-19 14:58:42 -07009509 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009510 }
9511
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009512 /**
9513 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009514 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9515 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9516 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009517 * @param numOfSims number of active sims we want to switch to
9518 */
9519 @Override
9520 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009521 if (numOfSims == 1) {
9522 enforceModifyPermission();
9523 } else {
9524 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9525 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9526 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009527 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009528
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009529 try {
Michele30b57b22019-03-01 12:01:14 -08009530 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009531 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009532 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9533 return;
9534 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009535 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9536 } finally {
9537 Binder.restoreCallingIdentity(identity);
9538 }
9539 }
9540
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009541 @Override
9542 public boolean isApplicationOnUicc(int subId, int appType) {
9543 enforceReadPrivilegedPermission("isApplicationOnUicc");
9544 Phone phone = getPhone(subId);
9545 if (phone == null) {
9546 return false;
9547 }
9548 final long identity = Binder.clearCallingIdentity();
9549 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009550 UiccPort uiccPort = phone.getUiccPort();
9551 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009552 return false;
9553 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009554 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009555 if (uiccProfile == null) {
9556 return false;
9557 }
9558 if (TelephonyManager.APPTYPE_SIM <= appType
9559 && appType <= TelephonyManager.APPTYPE_ISIM) {
9560 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9561 }
9562 return false;
9563 } finally {
9564 Binder.restoreCallingIdentity(identity);
9565 }
9566 }
9567
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009568 /**
chen xub4baa772019-04-03 10:23:41 -07009569 * Get whether making changes to modem configurations will trigger reboot.
9570 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009571 */
9572 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009573 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9574 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009575 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009576 mApp, subId, callingPackage, callingFeatureId,
9577 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009578 return false;
9579 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009580 final long identity = Binder.clearCallingIdentity();
9581 try {
9582 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9583 } finally {
9584 Binder.restoreCallingIdentity(identity);
9585 }
9586 }
9587
Nathan Harold29f5f052019-02-15 13:41:57 -08009588 private void updateModemStateMetrics() {
9589 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9590 // TODO: check the state for each modem if the api is ready.
9591 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9592 }
9593
Pengquan Meng3889a572019-01-23 11:16:29 -08009594 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009595 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009596 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009597 // Verify that the callingPackage belongs to the calling UID
9598 mApp.getSystemService(AppOpsManager.class)
9599 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009600 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009601 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009602 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009603 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9604 if (slotInfos != null) {
9605 for (int i = 0; i < slotInfos.length; i++) {
9606 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9607 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9608 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9609 portInfo.getLogicalSlotIndex()));
9610 }
9611 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009612 }
9613 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009614 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009615 } finally {
9616 Binder.restoreCallingIdentity(identity);
9617 }
9618 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009619
9620 /**
9621 * Get the IRadio HAL Version
9622 */
9623 @Override
9624 public int getRadioHalVersion() {
9625 Phone phone = getDefaultPhone();
9626 if (phone == null) return -1;
9627 HalVersion hv = phone.getHalVersion();
9628 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9629 return hv.major * 100 + hv.minor;
9630 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009631
9632 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009633 * Get the current calling package name.
9634 * @return the current calling package name
9635 */
9636 @Override
9637 public String getCurrentPackageName() {
9638 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9639 }
9640
9641 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009642 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9643 * corresponding network requests on a subId.
9644 *
9645 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009646 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009647 * 2) APN is un-metered for this subscription, or
9648 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009649 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009650 *
9651 * @return whether data is allowed for a apn type.
9652 *
9653 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009654 */
9655 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009656 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009657 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9658 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009659
9660 // Now that all security checks passes, perform the operation as ourselves.
9661 final long identity = Binder.clearCallingIdentity();
9662 try {
9663 Phone phone = getPhone(subId);
9664 if (phone == null) return false;
9665
Jack Yu41407ee2019-05-13 16:54:09 -07009666 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Jack Yu99e87332021-12-17 23:14:15 -08009667 boolean isDataEnabled;
9668 if (phone.isUsingNewDataStack()) {
9669 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
9670 } else {
9671 isDataEnabled = phone.getDataEnabledSettings().isDataEnabled(apnType);
9672 }
9673 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009674 } finally {
9675 Binder.restoreCallingIdentity(identity);
9676 }
9677 }
9678
9679 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009680 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009681 enforceReadPrivilegedPermission("isApnMetered");
9682
9683 // Now that all security checks passes, perform the operation as ourselves.
9684 final long identity = Binder.clearCallingIdentity();
9685 try {
9686 Phone phone = getPhone(subId);
9687 if (phone == null) return true; // By default return true.
9688
Jack Yu41407ee2019-05-13 16:54:09 -07009689 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009690 } finally {
9691 Binder.restoreCallingIdentity(identity);
9692 }
9693 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009694
9695 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009696 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9697 int subscriptionId, IBooleanConsumer resultCallback) {
9698 enforceModifyPermission();
9699 long token = Binder.clearCallingIdentity();
9700 try {
9701 Phone phone = getPhone(subscriptionId);
9702 if (phone == null) {
9703 try {
9704 if (resultCallback != null) {
9705 resultCallback.accept(false);
9706 }
9707 } catch (RemoteException e) {
9708 // ignore
9709 }
9710 return;
9711 }
9712 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9713 Pair.create(specifiers, (x) -> {
9714 try {
9715 if (resultCallback != null) {
9716 resultCallback.accept(x);
9717 }
9718 } catch (RemoteException e) {
9719 // ignore
9720 }
9721 });
9722 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9723 } finally {
9724 Binder.restoreCallingIdentity(token);
9725 }
9726 }
9727
9728 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009729 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9730 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009731 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009732 mApp, subId, "getSystemSelectionChannels");
9733 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9734 final long identity = Binder.clearCallingIdentity();
9735 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009736 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9737 if (result instanceof IllegalStateException) {
9738 throw (IllegalStateException) result;
9739 }
9740 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009741 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9742 return specifiers;
9743 } finally {
9744 Binder.restoreCallingIdentity(identity);
9745 }
9746 }
9747
9748 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009749 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009750 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009751 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9752 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9753 if (iccRecords == null) {
9754 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9755 return false;
9756 }
9757 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9758 }
9759
9760 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009761 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9762 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009763 if (callingPackage == null) {
9764 callingPackage = getCurrentPackageName();
9765 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009766 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9767 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009768 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9769 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009770 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9771 }
9772 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9773 Intent intent = new Intent();
9774 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9775 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9776 // Bring up choose default SMS subscription dialog right now
9777 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9778 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9779 mApp.startActivity(intent);
9780 }
chen xud5ca2d52019-05-28 15:20:57 -07009781
9782 @Override
9783 public String getMmsUAProfUrl(int subId) {
9784 //TODO investigate if this API should require proper permission check in R b/133791609
9785 final long identity = Binder.clearCallingIdentity();
9786 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009787 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9788 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9789 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9790 return carrierUAProfUrl;
9791 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009792 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9793 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009794 } finally {
9795 Binder.restoreCallingIdentity(identity);
9796 }
9797 }
9798
9799 @Override
9800 public String getMmsUserAgent(int subId) {
9801 //TODO investigate if this API should require proper permission check in R b/133791609
9802 final long identity = Binder.clearCallingIdentity();
9803 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009804 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9805 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9806 if (!TextUtils.isEmpty(carrierUserAgent)) {
9807 return carrierUserAgent;
9808 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009809 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9810 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009811 } finally {
9812 Binder.restoreCallingIdentity(identity);
9813 }
9814 }
Jack Yub07d4972019-05-28 16:12:25 -07009815
9816 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009817 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9818 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009819
Jack Yub07d4972019-05-28 16:12:25 -07009820 final long identity = Binder.clearCallingIdentity();
9821 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009822 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009823 if (phone == null) return false;
9824
Hall Liua62f5da2020-09-25 10:42:19 -07009825 switch (policy) {
9826 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu99e87332021-12-17 23:14:15 -08009827 if (phone.isUsingNewDataStack()) {
9828 return phone.getDataSettingsManager().isDataAllowedInVoiceCall();
9829 } else {
9830 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9831 }
Hall Liua62f5da2020-09-25 10:42:19 -07009832 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu99e87332021-12-17 23:14:15 -08009833 if (phone.isUsingNewDataStack()) {
9834 return phone.getDataSettingsManager().isMmsAlwaysAllowed();
9835 } else {
9836 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9837 }
Hall Liua62f5da2020-09-25 10:42:19 -07009838 default:
9839 throw new IllegalArgumentException(policy + " is not a valid policy");
9840 }
Jack Yub07d4972019-05-28 16:12:25 -07009841 } finally {
9842 Binder.restoreCallingIdentity(identity);
9843 }
9844 }
9845
9846 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009847 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009848 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009849 enforceModifyPermission();
9850
changbettyd5c246e2019-12-24 15:40:37 +08009851 final long identity = Binder.clearCallingIdentity();
9852 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009853 Phone phone = getPhone(subscriptionId);
9854 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009855
Hall Liua62f5da2020-09-25 10:42:19 -07009856 switch (policy) {
9857 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu99e87332021-12-17 23:14:15 -08009858 if (phone.isUsingNewDataStack()) {
9859 phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled);
9860 } else {
9861 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9862 }
Hall Liua62f5da2020-09-25 10:42:19 -07009863 break;
9864 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu99e87332021-12-17 23:14:15 -08009865 if (phone.isUsingNewDataStack()) {
9866 phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled);
9867 } else {
9868 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9869 }
Hall Liua62f5da2020-09-25 10:42:19 -07009870 break;
9871 default:
9872 throw new IllegalArgumentException(policy + " is not a valid policy");
9873 }
changbettyd5c246e2019-12-24 15:40:37 +08009874 } finally {
9875 Binder.restoreCallingIdentity(identity);
9876 }
9877 }
9878
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009879 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009880 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009881 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9882 * otherwise.
9883 */
9884 @Override
9885 public void setCepEnabled(boolean isCepEnabled) {
9886 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9887
9888 final long identity = Binder.clearCallingIdentity();
9889 try {
9890 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9891 for (Phone phone : PhoneFactory.getPhones()) {
9892 Phone defaultPhone = phone.getImsPhone();
9893 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9894 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9895 ImsPhoneCallTracker imsPhoneCallTracker =
9896 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9897 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9898 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9899 + imsPhone.getMsisdn());
9900 }
9901 }
9902 } finally {
9903 Binder.restoreCallingIdentity(identity);
9904 }
9905 }
allenwtsu46dcc572020-01-08 18:24:03 +08009906
9907 /**
9908 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9909 *
9910 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9911 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9912 * before being read.
9913 */
9914 @Override
9915 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9916 isCompressed) {
9917 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9918 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009919 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9920 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9921 }
9922 if (!isImsAvailableOnDevice()) {
9923 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9924 "IMS not available on device.");
9925 }
9926
9927 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009928 try {
Hui Wang761a6682020-10-31 05:12:53 +00009929 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9930 } finally {
9931 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009932 }
9933 }
zoey chene02881a2019-12-30 16:11:23 +08009934
9935 @Override
9936 public boolean isIccLockEnabled(int subId) {
9937 enforceReadPrivilegedPermission("isIccLockEnabled");
9938
9939 // Now that all security checks passes, perform the operation as ourselves.
9940 final long identity = Binder.clearCallingIdentity();
9941 try {
9942 Phone phone = getPhone(subId);
9943 if (phone != null && phone.getIccCard() != null) {
9944 return phone.getIccCard().getIccLockEnabled();
9945 } else {
9946 return false;
9947 }
9948 } finally {
9949 Binder.restoreCallingIdentity(identity);
9950 }
9951 }
9952
9953 /**
9954 * Set the ICC pin lock enabled or disabled.
9955 *
9956 * @return an integer representing the status of IccLock enabled or disabled in the following
9957 * three cases:
9958 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9959 * successfully.
9960 * - Positive number and zero for remaining password attempts.
9961 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9962 *
9963 */
9964 @Override
9965 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9966 enforceModifyPermission();
9967
9968 Phone phone = getPhone(subId);
9969 if (phone == null) {
9970 return 0;
9971 }
9972 // Now that all security checks passes, perform the operation as ourselves.
9973 final long identity = Binder.clearCallingIdentity();
9974 try {
9975 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9976 new Pair<Boolean, String>(enabled, password), phone, null);
9977 return attemptsRemaining;
9978
9979 } catch (Exception e) {
9980 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9981 } finally {
9982 Binder.restoreCallingIdentity(identity);
9983 }
9984 return 0;
9985 }
9986
9987 /**
9988 * Change the ICC password used in ICC pin lock.
9989 *
9990 * @return an integer representing the status of IccLock changed in the following three cases:
9991 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9992 * - Positive number and zero for remaining password attempts.
9993 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9994 *
9995 */
9996 @Override
9997 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9998 enforceModifyPermission();
9999
10000 Phone phone = getPhone(subId);
10001 if (phone == null) {
10002 return 0;
10003 }
10004 // Now that all security checks passes, perform the operation as ourselves.
10005 final long identity = Binder.clearCallingIdentity();
10006 try {
10007 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10008 new Pair<String, String>(oldPassword, newPassword), phone, null);
10009 return attemptsRemaining;
10010
10011 } catch (Exception e) {
10012 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10013 } finally {
10014 Binder.restoreCallingIdentity(identity);
10015 }
10016 return 0;
10017 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010018
10019 /**
10020 * Request for receiving user activity notification
10021 */
10022 @Override
10023 public void requestUserActivityNotification() {
10024 if (!mNotifyUserActivity.get()
10025 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10026 mNotifyUserActivity.set(true);
10027 }
10028 }
10029
10030 /**
10031 * Called when userActivity is signalled in the power manager.
10032 * This is safe to call from any thread, with any window manager locks held or not.
10033 */
10034 @Override
10035 public void userActivity() {
10036 // ***************************************
10037 // * Inherited from PhoneWindowManager *
10038 // ***************************************
10039 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10040 // WITH ITS LOCKS HELD.
10041 //
10042 // This code must be VERY careful about the locks
10043 // it acquires.
10044 // In fact, the current code acquires way too many,
10045 // and probably has lurking deadlocks.
10046
10047 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10048 throw new SecurityException("Only the OS may call notifyUserActivity()");
10049 }
10050
10051 if (mNotifyUserActivity.getAndSet(false)) {
10052 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10053 USER_ACTIVITY_NOTIFICATION_DELAY);
10054 }
10055 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010056
10057 @Override
10058 public boolean canConnectTo5GInDsdsMode() {
10059 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10060 }
Jack Yud10cdd42020-09-28 20:28:01 -070010061
10062 @Override
10063 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10064 String callingFeatureId) {
10065 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10066 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10067 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10068 }
10069
10070 Phone phone = getPhone(subId);
10071 if (phone == null) {
10072 throw new RuntimeException("phone is not available");
10073 }
10074 // Now that all security checks passes, perform the operation as ourselves.
10075 final long identity = Binder.clearCallingIdentity();
10076 try {
10077 return phone.getEquivalentHomePlmns();
10078 } finally {
10079 Binder.restoreCallingIdentity(identity);
10080 }
10081 }
Daniel Bright59e67312020-11-13 11:49:37 -080010082
10083 @Override
10084 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010085 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10086 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010087 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010088 if (radioInterfaceCapabilities == null) {
10089 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010090 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010091 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010092 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010093
Hui Wang641e81c2020-10-12 12:14:23 -070010094 @Override
10095 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10096 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010097 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10098 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10099 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10100 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10101 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010102 if (DBG) {
10103 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10104 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10105 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10106 }
10107
10108 if (!SubscriptionManager.isValidSubscriptionId(subId)
10109 || appType < TelephonyManager.APPTYPE_UNKNOWN
10110 || appType > TelephonyManager.APPTYPE_ISIM
10111 || nafUrl == null || securityProtocol == null || callback == null) {
10112 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10113 if (callback != null) {
10114 try {
10115 callback.onAuthenticationFailure(
10116 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10117 } catch (RemoteException exception) {
10118 log("Fail to notify onAuthenticationFailure due to " + exception);
10119 }
10120 return;
10121 }
10122 }
10123
10124 final long token = Binder.clearCallingIdentity();
10125 try {
10126 getGbaManager(subId).bootstrapAuthenticationRequest(
10127 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10128 forceBootStrapping, callback));
10129 } finally {
10130 Binder.restoreCallingIdentity(token);
10131 }
10132 }
10133
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010134 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010135 * Attempts to set the radio power state for all phones for thermal reason.
10136 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010137 * requested radio power state will actually be set. See {@link
10138 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10139 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010140 * @param enable {@code true} if trying to turn radio on.
10141 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10142 * false}.
10143 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010144 private boolean setRadioPowerForThermal(boolean enable) {
10145 boolean isPhoneAvailable = false;
10146 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10147 Phone phone = PhoneFactory.getPhone(i);
10148 if (phone != null) {
10149 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10150 isPhoneAvailable = true;
10151 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010152 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010153
10154 // return true if successfully informed the phone object about the thermal radio power
10155 // request.
10156 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010157 }
10158
10159 private int handleDataThrottlingRequest(int subId,
10160 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010161 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10162 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10163 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10164 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10165 throw new IllegalArgumentException("modem does not support data throttling");
10166 }
10167
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010168 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10169 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010170 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010171 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10172 }
10173
10174 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10175
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010176 if (isDataThrottlingSupported) {
10177 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010178 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010179 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10180 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10181 } else if (thermalMitigationResult
10182 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010183 log("Modem likely does not support data throttling on secondary carrier. Data " +
10184 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10185 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010186 }
10187 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010188 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010189
10190 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010191 }
10192
Jack Nudelman644b91a2021-03-12 14:09:48 -080010193 private static List<String> getThermalMitigationAllowlist(Context context) {
10194 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10195 for (String pckg : context.getResources()
10196 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10197 sThermalMitigationAllowlistedPackages.add(pckg);
10198 }
10199 }
10200
10201 return sThermalMitigationAllowlistedPackages;
10202 }
10203
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010204 private boolean isAnyPhoneInEmergencyState() {
10205 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10206 if (tm.isInEmergencyCall()) {
10207 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10208 return true;
10209 }
10210 for (Phone phone : PhoneFactory.getPhones()) {
10211 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10212 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10213 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10214 + phone.isInEcm());
10215 return true;
10216 }
10217 }
10218
10219 return false;
10220 }
10221
Jack Nudelman644b91a2021-03-12 14:09:48 -080010222 /**
10223 * Used by shell commands to add an authorized package name for thermal mitigation.
10224 * @param packageName name of package to be allowlisted
10225 * @param context
10226 */
10227 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10228 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10229 sThermalMitigationAllowlistedPackages.add(packageName);
10230 }
10231
10232 /**
10233 * Used by shell commands to remove an authorized package name for thermal mitigation.
10234 * @param packageName name of package to remove from allowlist
10235 * @param context
10236 */
10237 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10238 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10239 sThermalMitigationAllowlistedPackages.remove(packageName);
10240 }
10241
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010242 /**
10243 * Thermal mitigation request to control functionalities at modem.
10244 *
10245 * @param subId the id of the subscription.
10246 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010247 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010248 *
10249 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10250 */
10251 @Override
10252 @ThermalMitigationResult
10253 public int sendThermalMitigationRequest(
10254 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010255 ThermalMitigationRequest thermalMitigationRequest,
10256 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010257 enforceModifyPermission();
10258
Jack Nudelman644b91a2021-03-12 14:09:48 -080010259 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10260 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10261 .contains(callingPackage)) {
10262 throw new SecurityException("Calling package must be configured in the device config. "
10263 + "calling package: " + callingPackage);
10264 }
10265
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010266 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10267 final long identity = Binder.clearCallingIdentity();
10268
10269 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10270 try {
10271 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10272 switch (thermalMitigationAction) {
10273 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10274 thermalMitigationResult =
10275 handleDataThrottlingRequest(subId,
10276 thermalMitigationRequest.getDataThrottlingRequest());
10277 break;
10278 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10279 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10280 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10281 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10282 }
10283
10284 // Ensure that radio is on. If not able to power on due to phone being
10285 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010286 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010287 thermalMitigationResult =
10288 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10289 break;
10290 }
10291
10292 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10293 false);
10294 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10295 break;
10296 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10297 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10298 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10299 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10300 }
10301
10302 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10303 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010304 Phone phone = getPhone(subId);
10305 if (phone == null) {
10306 thermalMitigationResult =
10307 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10308 break;
10309 }
10310
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010311 TelephonyConnectionService service =
10312 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010313 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010314 Log.e(LOG_TAG, "An emergency call is pending");
10315 thermalMitigationResult =
10316 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10317 break;
10318 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010319 thermalMitigationResult =
10320 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10321 break;
10322 }
10323 } else {
10324 thermalMitigationResult =
10325 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10326 break;
10327 }
10328
10329 // Turn radio off. If not able to power off due to phone being unavailable,
10330 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010331 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010332 thermalMitigationResult =
10333 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10334 break;
10335 }
10336 thermalMitigationResult =
10337 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10338 break;
10339 default:
10340 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10341 + "not exist. Requested action: " + thermalMitigationAction);
10342 }
10343 } catch (IllegalArgumentException e) {
10344 throw e;
10345 } catch (Exception e) {
10346 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10347 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10348 } finally {
10349 Binder.restoreCallingIdentity(identity);
10350 }
10351
10352 if (DBG) {
10353 log("thermalMitigationRequest returning with thermalMitigationResult: "
10354 + thermalMitigationResult);
10355 }
10356
10357 return thermalMitigationResult;
10358 }
Hui Wang641e81c2020-10-12 12:14:23 -070010359
10360 /**
10361 * Set the GbaService Package Name that Telephony will bind to.
10362 *
10363 * @param subId The sim that the GbaService is associated with.
10364 * @param packageName The name of the package to be replaced with.
10365 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10366 */
10367 @Override
10368 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10369 enforceModifyPermission();
10370
10371 final long identity = Binder.clearCallingIdentity();
10372 try {
10373 return getGbaManager(subId).overrideServicePackage(packageName);
10374 } finally {
10375 Binder.restoreCallingIdentity(identity);
10376 }
10377 }
10378
10379 /**
10380 * Return the package name of the currently bound GbaService.
10381 *
10382 * @param subId The sim that the GbaService is associated with.
10383 * @return the package name of the GbaService configuration, null if GBA is not supported.
10384 */
10385 @Override
10386 public String getBoundGbaService(int subId) {
10387 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10388
10389 final long identity = Binder.clearCallingIdentity();
10390 try {
10391 return getGbaManager(subId).getServicePackage();
10392 } finally {
10393 Binder.restoreCallingIdentity(identity);
10394 }
10395 }
10396
10397 /**
10398 * Set the release time for telephony to unbind GbaService.
10399 *
10400 * @param subId The sim that the GbaService is associated with.
10401 * @param interval The release time to unbind GbaService by millisecond.
10402 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10403 */
10404 @Override
10405 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10406 enforceModifyPermission();
10407
10408 final long identity = Binder.clearCallingIdentity();
10409 try {
10410 return getGbaManager(subId).overrideReleaseTime(interval);
10411 } finally {
10412 Binder.restoreCallingIdentity(identity);
10413 }
10414 }
10415
10416 /**
10417 * Return the release time for telephony to unbind GbaService.
10418 *
10419 * @param subId The sim that the GbaService is associated with.
10420 * @return The release time to unbind GbaService by millisecond.
10421 */
10422 @Override
10423 public int getGbaReleaseTime(int subId) {
10424 enforceReadPrivilegedPermission("getGbaReleaseTime");
10425
10426 final long identity = Binder.clearCallingIdentity();
10427 try {
10428 return getGbaManager(subId).getReleaseTime();
10429 } finally {
10430 Binder.restoreCallingIdentity(identity);
10431 }
10432 }
10433
10434 private GbaManager getGbaManager(int subId) {
10435 GbaManager instance = GbaManager.getInstance(subId);
10436 if (instance == null) {
10437 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10438 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10439 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10440 }
10441 return instance;
10442 }
Hui Wang761a6682020-10-31 05:12:53 +000010443
10444 /**
10445 * indicate whether the device and the carrier can support
10446 * RCS VoLTE single registration.
10447 */
10448 @Override
10449 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010450 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10451 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10452 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10453 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010454
10455 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10456 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10457 }
10458
10459 final long identity = Binder.clearCallingIdentity();
10460 try {
10461 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10462 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010463 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10464 if (isCapable != null) {
10465 return isCapable;
10466 }
Hui Wang761a6682020-10-31 05:12:53 +000010467 }
Hui Wang67af90e2021-06-04 16:57:15 -070010468 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10469 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010470 } finally {
10471 Binder.restoreCallingIdentity(identity);
10472 }
10473 }
10474
10475 /**
10476 * Register RCS provisioning callback.
10477 */
10478 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010479 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010480 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010481 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010482 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010483 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10484 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010485
10486 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10487 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10488 }
10489 if (!isImsAvailableOnDevice()) {
10490 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10491 "IMS not available on device.");
10492 }
10493
10494 final long identity = Binder.clearCallingIdentity();
10495 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010496 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010497 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010498 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10499 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010500 }
Hui Wang761a6682020-10-31 05:12:53 +000010501 } finally {
10502 Binder.restoreCallingIdentity(identity);
10503 }
10504 }
10505
10506 /**
10507 * Unregister RCS provisioning callback.
10508 */
10509 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010510 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010511 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010512 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010513 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010514 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10515 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010516
10517 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10518 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10519 }
10520 if (!isImsAvailableOnDevice()) {
10521 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10522 "IMS not available on device.");
10523 }
10524
10525 final long identity = Binder.clearCallingIdentity();
10526 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010527 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010528 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010529 } finally {
10530 Binder.restoreCallingIdentity(identity);
10531 }
10532 }
10533
10534 /**
10535 * trigger RCS reconfiguration.
10536 */
10537 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010538 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10539 "triggerRcsReconfiguration",
10540 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010541
10542 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10543 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10544 }
10545 if (!isImsAvailableOnDevice()) {
10546 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10547 "IMS not available on device.");
10548 }
10549
10550 final long identity = Binder.clearCallingIdentity();
10551 try {
10552 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10553 } finally {
10554 Binder.restoreCallingIdentity(identity);
10555 }
10556 }
10557
10558 /**
10559 * Provide the client configuration parameters of the RCS application.
10560 */
10561 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010562 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10563 "setRcsClientConfiguration",
10564 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010565
10566 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10567 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10568 }
10569 if (!isImsAvailableOnDevice()) {
10570 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10571 "IMS not available on device.");
10572 }
10573
10574 final long identity = Binder.clearCallingIdentity();
10575
10576 try {
10577 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10578 if (configBinder == null) {
10579 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010580 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10581 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010582 } else {
10583 configBinder.setRcsClientConfiguration(rcc);
10584 }
joonhunshin3e154242021-09-17 06:33:39 +000010585
10586 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10587 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010588 } catch (RemoteException e) {
10589 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010590 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10591 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010592 } finally {
10593 Binder.restoreCallingIdentity(identity);
10594 }
10595 }
10596
10597 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010598 * Enables or disables the test mode for RCS VoLTE single registration.
10599 */
10600 @Override
10601 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10602 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10603 "setRcsSingleRegistrationTestModeEnabled");
10604
10605 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10606 }
10607
10608 /**
10609 * Gets the test mode for RCS VoLTE single registration.
10610 */
10611 @Override
10612 public boolean getRcsSingleRegistrationTestModeEnabled() {
10613 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10614 "getRcsSingleRegistrationTestModeEnabled");
10615
10616 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10617 }
10618
10619 /**
Hui Wang761a6682020-10-31 05:12:53 +000010620 * Overrides the config of RCS VoLTE single registration enabled for the device.
10621 */
10622 @Override
10623 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10624 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10625 "setDeviceSingleRegistrationEnabledOverride");
10626 enforceModifyPermission();
10627
10628 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10629 : Boolean.parseBoolean(enabledStr);
10630 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010631 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010632 }
10633
10634 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010635 * Sends a device to device communication message. Only usable via shell.
10636 * @param message message to send.
10637 * @param value message value.
10638 */
10639 @Override
10640 public void sendDeviceToDeviceMessage(int message, int value) {
10641 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010642 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010643 enforceModifyPermission();
10644
10645 final long identity = Binder.clearCallingIdentity();
10646 try {
10647 TelephonyConnectionService service =
10648 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10649 if (service == null) {
10650 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10651 return;
10652 }
10653 service.sendTestDeviceToDeviceMessage(message, value);
10654 } finally {
10655 Binder.restoreCallingIdentity(identity);
10656 }
10657 }
10658
Tyler Gunnbabbda02021-02-10 11:05:02 -080010659 /**
10660 * Sets the specified device to device transport active.
10661 * @param transport The transport to set active.
10662 */
10663 @Override
10664 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10665 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10666 "setActiveDeviceToDeviceTransport");
10667 enforceModifyPermission();
10668
10669 final long identity = Binder.clearCallingIdentity();
10670 try {
10671 TelephonyConnectionService service =
10672 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10673 if (service == null) {
10674 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10675 return;
10676 }
10677 service.setActiveDeviceToDeviceTransport(transport);
10678 } finally {
10679 Binder.restoreCallingIdentity(identity);
10680 }
10681 }
Tyler Gunn92479152021-01-20 16:30:10 -080010682
Tyler Gunnd4339262021-05-03 14:46:49 -070010683 @Override
10684 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10685 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10686 "setDeviceToDeviceForceEnabled");
10687
10688 final long identity = Binder.clearCallingIdentity();
10689 try {
10690 Arrays.stream(PhoneFactory.getPhones()).forEach(
10691 p -> {
10692 Phone thePhone = p.getImsPhone();
10693 if (thePhone != null && thePhone instanceof ImsPhone) {
10694 ImsPhone imsPhone = (ImsPhone) thePhone;
10695 CallTracker tracker = imsPhone.getCallTracker();
10696 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10697 ImsPhoneCallTracker imsPhoneCallTracker =
10698 (ImsPhoneCallTracker) tracker;
10699 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10700 }
10701 }
10702 }
10703 );
10704 } finally {
10705 Binder.restoreCallingIdentity(identity);
10706 }
10707 }
10708
Tyler Gunn92479152021-01-20 16:30:10 -080010709 /**
Hui Wang761a6682020-10-31 05:12:53 +000010710 * Gets the config of RCS VoLTE single registration enabled for the device.
10711 */
10712 @Override
10713 public boolean getDeviceSingleRegistrationEnabled() {
10714 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10715 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10716 }
10717
10718 /**
10719 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10720 */
10721 @Override
10722 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10723 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10724 "setCarrierSingleRegistrationEnabledOverride");
10725 enforceModifyPermission();
10726
10727 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10728 : Boolean.parseBoolean(enabledStr);
10729 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10730 subId, enabled);
10731 }
10732
10733 /**
10734 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10735 */
10736 @Override
10737 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10738 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10739 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10740 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010741
10742 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010743 * Overrides the ims feature validation result
10744 */
10745 @Override
10746 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10747 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10748 "setImsFeatureValidationOverride");
10749
10750 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10751 : Boolean.parseBoolean(enabledStr);
10752 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10753 subId, enabled);
10754 }
10755
10756 /**
10757 * Gets the ims feature validation override value
10758 */
10759 @Override
10760 public boolean getImsFeatureValidationOverride(int subId) {
10761 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10762 "getImsFeatureValidationOverride");
10763 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10764 }
10765
10766 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010767 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10768 * their mobile plan.
10769 */
10770 @Override
10771 public String getMobileProvisioningUrl() {
10772 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10773 final long identity = Binder.clearCallingIdentity();
10774 try {
10775 return getDefaultPhone().getMobileProvisioningUrl();
10776 } finally {
10777 Binder.restoreCallingIdentity(identity);
10778 }
10779 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010780
James.cf Linbcdf8b32021-01-14 16:44:13 +080010781 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010782 * Get the EAB contact from the EAB database.
10783 */
10784 @Override
10785 public String getContactFromEab(String contact) {
10786 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10787 enforceModifyPermission();
10788 final long identity = Binder.clearCallingIdentity();
10789 try {
10790 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10791 } finally {
10792 Binder.restoreCallingIdentity(identity);
10793 }
10794 }
10795
10796 /**
Calvin Pana1434322021-07-01 19:27:01 +080010797 * Get the EAB capability from the EAB database.
10798 */
10799 @Override
10800 public String getCapabilityFromEab(String contact) {
10801 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10802 enforceModifyPermission();
10803 final long identity = Binder.clearCallingIdentity();
10804 try {
10805 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10806 } finally {
10807 Binder.restoreCallingIdentity(identity);
10808 }
10809 }
10810
10811 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010812 * Remove the EAB contacts from the EAB database.
10813 */
10814 @Override
10815 public int removeContactFromEab(int subId, String contacts) {
10816 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10817 enforceModifyPermission();
10818 final long identity = Binder.clearCallingIdentity();
10819 try {
10820 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10821 } finally {
10822 Binder.restoreCallingIdentity(identity);
10823 }
10824 }
10825
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010826 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010827 public boolean getDeviceUceEnabled() {
10828 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10829 final long identity = Binder.clearCallingIdentity();
10830 try {
10831 return mApp.getDeviceUceEnabled();
10832 } finally {
10833 Binder.restoreCallingIdentity(identity);
10834 }
10835 }
10836
10837 @Override
10838 public void setDeviceUceEnabled(boolean isEnabled) {
10839 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10840 final long identity = Binder.clearCallingIdentity();
10841 try {
10842 mApp.setDeviceUceEnabled(isEnabled);
10843 } finally {
10844 Binder.restoreCallingIdentity(identity);
10845 }
10846 }
10847
Brad Ebinger14d467f2021-02-12 06:18:28 +000010848 /**
10849 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10850 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10851 */
10852 // Used for SHELL command only right now.
10853 @Override
10854 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10855 List<String> featureTags) {
10856 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10857 "addUceRegistrationOverrideShell");
10858 final long identity = Binder.clearCallingIdentity();
10859 try {
10860 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10861 new ArraySet<>(featureTags));
10862 } catch (ImsException e) {
10863 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10864 } finally {
10865 Binder.restoreCallingIdentity(identity);
10866 }
10867 }
10868
10869 /**
10870 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10871 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10872 */
10873 // Used for SHELL command only right now.
10874 @Override
10875 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10876 List<String> featureTags) {
10877 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10878 "removeUceRegistrationOverrideShell");
10879 final long identity = Binder.clearCallingIdentity();
10880 try {
10881 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10882 new ArraySet<>(featureTags));
10883 } catch (ImsException e) {
10884 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10885 } finally {
10886 Binder.restoreCallingIdentity(identity);
10887 }
10888 }
10889
10890 /**
10891 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10892 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10893 */
10894 // Used for SHELL command only right now.
10895 @Override
10896 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10897 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10898 "clearUceRegistrationOverrideShell");
10899 final long identity = Binder.clearCallingIdentity();
10900 try {
10901 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10902 } catch (ImsException e) {
10903 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10904 } finally {
10905 Binder.restoreCallingIdentity(identity);
10906 }
10907 }
10908
10909 /**
10910 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10911 */
10912 // Used for SHELL command only right now.
10913 @Override
10914 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10915 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10916 "getLatestRcsContactUceCapabilityShell");
10917 final long identity = Binder.clearCallingIdentity();
10918 try {
10919 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10920 } catch (ImsException e) {
10921 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10922 } finally {
10923 Binder.restoreCallingIdentity(identity);
10924 }
10925 }
10926
10927 /**
10928 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10929 * device does not have an active PUBLISH.
10930 */
10931 // Used for SHELL command only right now.
10932 @Override
10933 public String getLastUcePidfXmlShell(int subId) {
10934 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10935 final long identity = Binder.clearCallingIdentity();
10936 try {
10937 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10938 } catch (ImsException e) {
10939 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10940 } finally {
10941 Binder.restoreCallingIdentity(identity);
10942 }
10943 }
10944
James.cf Line8713a42021-04-29 16:04:26 +080010945 /**
10946 * Remove UCE requests cannot be sent to the network status.
10947 */
10948 // Used for SHELL command only right now.
10949 @Override
10950 public boolean removeUceRequestDisallowedStatus(int subId) {
10951 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10952 final long identity = Binder.clearCallingIdentity();
10953 try {
10954 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10955 } catch (ImsException e) {
10956 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10957 } finally {
10958 Binder.restoreCallingIdentity(identity);
10959 }
10960 }
10961
James.cf Lin18bb9002021-05-25 01:37:38 +080010962 /**
10963 * Remove UCE requests cannot be sent to the network status.
10964 */
10965 // Used for SHELL command only.
10966 @Override
10967 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10968 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10969 final long identity = Binder.clearCallingIdentity();
10970 try {
10971 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10972 } catch (ImsException e) {
10973 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10974 } finally {
10975 Binder.restoreCallingIdentity(identity);
10976 }
10977 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010978
James.cf Lin4b784aa2021-01-31 03:25:15 +080010979 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010980 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10981 String callingPackage) {
10982 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10983 mApp, subId, "setSignalStrengthUpdateRequest");
10984
10985 final int callingUid = Binder.getCallingUid();
10986 // Verify that tha callingPackage belongs to the calling UID
10987 mApp.getSystemService(AppOpsManager.class)
10988 .checkPackage(callingUid, callingPackage);
10989
Rambo Wang3607f502021-02-01 21:51:40 -080010990 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010991
10992 final long identity = Binder.clearCallingIdentity();
10993 try {
10994 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10995 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10996
10997 if (result instanceof IllegalStateException) {
10998 throw (IllegalStateException) result;
10999 }
11000 } finally {
11001 Binder.restoreCallingIdentity(identity);
11002 }
11003 }
11004
11005 @Override
11006 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11007 String callingPackage) {
11008 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11009 mApp, subId, "clearSignalStrengthUpdateRequest");
11010
11011 final int callingUid = Binder.getCallingUid();
11012 // Verify that tha callingPackage belongs to the calling UID
11013 mApp.getSystemService(AppOpsManager.class)
11014 .checkPackage(callingUid, callingPackage);
11015
11016 final long identity = Binder.clearCallingIdentity();
11017 try {
11018 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11019 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11020
11021 if (result instanceof IllegalStateException) {
11022 throw (IllegalStateException) result;
11023 }
11024 } finally {
11025 Binder.restoreCallingIdentity(identity);
11026 }
11027 }
11028
Rambo Wang3607f502021-02-01 21:51:40 -080011029 private static void validateSignalStrengthUpdateRequest(Context context,
11030 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011031 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11032 // phone/system process do not have further restriction on request
11033 return;
11034 }
11035
11036 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011037 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011038 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011039 context.enforceCallingOrSelfPermission(
11040 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11041 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011042 }
11043
11044 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11045 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11046 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11047 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11048 || info.isEnabled()) {
11049 throw new IllegalArgumentException(
11050 "Only system can set hide fields in SignalThresholdInfo");
11051 }
11052
11053 // Thresholds length for each RAN need in range. This has been validated in
11054 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11055 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11056 final int[] thresholds = info.getThresholds();
11057 Objects.requireNonNull(thresholds);
11058 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11059 || thresholds.length
11060 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11061 throw new IllegalArgumentException(
11062 "thresholds length is out of range: " + thresholds.length);
11063 }
11064 }
11065 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011066
11067 /**
11068 * Gets the current phone capability.
11069 *
11070 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11071 * @return the PhoneCapability which describes the data connection capability of modem.
11072 * It's used to evaluate possible phone config change, for example from single
11073 * SIM device to multi-SIM device.
11074 */
11075 @Override
11076 public PhoneCapability getPhoneCapability() {
11077 enforceReadPrivilegedPermission("getPhoneCapability");
11078 final long identity = Binder.clearCallingIdentity();
11079 try {
11080 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11081 } finally {
11082 Binder.restoreCallingIdentity(identity);
11083 }
11084 }
Michele Berionne5e411512020-11-13 02:36:59 +000011085
11086 /**
11087 * Prepare TelephonyManager for an unattended reboot. The reboot is
11088 * required to be done shortly after the API is invoked.
11089 */
11090 @Override
11091 @TelephonyManager.PrepareUnattendedRebootResult
11092 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011093 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011094 enforceRebootPermission();
11095
11096 final long identity = Binder.clearCallingIdentity();
11097 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011098 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011099 } finally {
11100 Binder.restoreCallingIdentity(identity);
11101 }
11102 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011103
11104 /**
11105 * Request to get the current slicing configuration including URSP rules and
11106 * NSSAIs (configured, allowed and rejected).
11107 *
11108 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11109 */
11110 @Override
11111 public void getSlicingConfig(ResultReceiver callback) {
11112 enforceReadPrivilegedPermission("getSlicingConfig");
11113
11114 final long identity = Binder.clearCallingIdentity();
11115 try {
11116 Phone phone = getDefaultPhone();
11117 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11118 } finally {
11119 Binder.restoreCallingIdentity(identity);
11120 }
11121 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011122
11123 /**
11124 * Register an IMS connection state callback
11125 */
11126 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011127 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11128 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011129 if (feature == ImsFeature.FEATURE_MMTEL) {
11130 // ImsMmTelManager
11131 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11132 TelephonyPermissions
11133 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11134 mApp, subId, "registerImsStateCallback");
11135 } else if (feature == ImsFeature.FEATURE_RCS) {
11136 // ImsRcsManager or SipDelegateManager
11137 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11138 Binder.getCallingUid(), "registerImsStateCallback",
11139 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11140 Manifest.permission.READ_PRECISE_PHONE_STATE,
11141 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11142 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11143 }
11144
11145 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11146 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11147 "IMS not available on device.");
11148 }
11149
11150 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11151 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11152 }
11153
11154 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11155 if (controller == null) {
11156 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11157 "IMS not available on device.");
11158 }
11159
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011160 if (callingPackage == null) {
11161 callingPackage = getCurrentPackageName();
11162 }
11163
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011164 final long token = Binder.clearCallingIdentity();
11165 try {
11166 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011167 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011168 } catch (ImsException e) {
11169 throw new ServiceSpecificException(e.getCode());
11170 } finally {
11171 Binder.restoreCallingIdentity(token);
11172 }
11173 }
11174
11175 /**
11176 * Unregister an IMS connection state callback
11177 */
11178 @Override
11179 public void unregisterImsStateCallback(IImsStateCallback cb) {
11180 final long token = Binder.clearCallingIdentity();
11181 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11182 if (controller == null) {
11183 return;
11184 }
11185 try {
11186 controller.unregisterImsStateCallback(cb);
11187 } finally {
11188 Binder.restoreCallingIdentity(token);
11189 }
11190 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011191
11192 /**
11193 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11194 *
11195 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11196 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11197 * SecurityException.
11198 * If there is current registered network this value will be same as the registered cell
11199 * identity. If the device goes out of service the previous cell identity is cached and
11200 * will be returned. If the cache age of the Cell identity is more than 24 hours
11201 * it will be cleared and null will be returned.
11202 *
11203 */
11204 @Override
11205 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11206 String callingFeatureId) {
11207 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11208 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11209 LocationAccessPolicy.checkLocationPermission(mApp,
11210 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11211 .setCallingPackage(callingPackage)
11212 .setCallingFeatureId(callingFeatureId)
11213 .setCallingPid(Binder.getCallingPid())
11214 .setCallingUid(Binder.getCallingUid())
11215 .setMethod("getLastKnownCellIdentity")
11216 .setLogAsInfo(true)
11217 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11218 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11219 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11220 .build());
11221
11222 boolean hasFinePermission =
11223 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11224 if (!hasFinePermission
11225 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11226 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
11227 + "and BIND_CONNECTION_SERVICE permission.");
11228 }
11229
11230 final long identity = Binder.clearCallingIdentity();
11231 try {
11232 Phone phone = getPhone(subId);
11233 if (phone == null) return null;
11234 ServiceStateTracker sst = phone.getServiceStateTracker();
11235 if (sst == null) return null;
11236 return sst.getLastKnownCellIdentity();
11237 } finally {
11238 Binder.restoreCallingIdentity(identity);
11239 }
11240 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011241
11242 @Override
11243 public boolean isUsingNewDataStack() {
11244 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "isUsingNewDataStack");
11245 return getDefaultPhone().isUsingNewDataStack();
11246 }
jimsun3b9ccac2021-10-26 15:01:23 +080011247
11248 /**
11249 * Sets the modem service class Name that Telephony will bind to.
11250 *
11251 * @param serviceName The class name of the modem service.
11252 * @return true if the operation is succeed, otherwise false.
11253 */
11254 public boolean setModemService(String serviceName) {
11255 Log.d(LOG_TAG, "setModemService - " + serviceName);
11256 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11257 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11258 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11259 "setModemService");
11260 return mPhoneConfigurationManager.setModemService(serviceName);
11261 }
11262
11263 /**
11264 * Return the class name of the currently bounded modem service.
11265 *
11266 * @return the class name of the modem service.
11267 */
11268 public String getModemService() {
11269 String result;
11270 Log.d(LOG_TAG, "getModemService");
11271 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11272 TelephonyPermissions
11273 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11274 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11275 "getModemService");
11276 result = mPhoneConfigurationManager.getModemService();
11277 Log.d(LOG_TAG, "result = " + result);
11278 return result;
11279 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011280
11281 @Override
11282 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11283 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11284 mApp.enforceCallingOrSelfPermission(
11285 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11286 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11287
11288 final long identity = Binder.clearCallingIdentity();
11289 try {
11290 Phone phone = getPhone(subId);
11291 if (phone == null) return;
11292 phone.setVoiceServiceStateOverride(hasService);
11293 } finally {
11294 Binder.restoreCallingIdentity(identity);
11295 }
11296 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011297}