blob: 003b639faec0553b2572cbed27a2bd3d63702490 [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;
joonhunshinfa314642021-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;
sandeepjs0a502c42021-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 Xu9040b472021-12-14 17:15:47 -080036import android.compat.Compatibility;
sandeepjs0a502c42021-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;
sandeepjs0a502c42021-09-27 15:34:44 +0000111import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000112import android.telephony.UiccSlotInfo;
sandeepjs0a502c42021-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;
joonhunshin2c3e4232021-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 Gunnd4575212021-05-03 14:46:49 -0700151import com.android.internal.telephony.CallTracker;
Rambo Wanga7436882022-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 Choic7ebc0f2021-11-15 23:46:41 +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 Wange162e302021-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;
joonhunshinfa314642021-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 Reddy864fe982021-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 Reddy70bf65a2021-11-19 03:07:54 +0000229import java.util.Collection;
Hunter Knepshield25ee6fc2021-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 Sasindranbf5c79c2021-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 Xu9040b472021-12-14 17:15:47 -0800417
sandeepjs0a502c42021-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 Xu9040b472021-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 Reddy864fe982021-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;
548 String ussdRequest = ussdObject.first;
549 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 Reddy864fe982021-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");
592 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,
596 request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000597 uiccPort.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700598 iccArgument.channel, iccArgument.cla, iccArgument.command,
599 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700600 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 {
610 request.result = new IccIoResult(0x6F, 0, (byte[])null);
611 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 Reddy864fe982021-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");
629 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,
633 request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000634 uiccPort.iccTransmitApduBasicChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700635 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
636 iccArgument.p3, iccArgument.data, onCompleted);
637 }
638 break;
639
640 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
641 ar = (AsyncResult) msg.obj;
642 request = (MainThreadRequest) ar.userObj;
643 if (ar.exception == null && ar.result != null) {
644 request.result = ar.result;
645 } else {
646 request.result = new IccIoResult(0x6F, 0, (byte[])null);
647 if (ar.result == null) {
648 loge("iccTransmitApduBasicChannel: Empty response");
649 } else if (ar.exception instanceof CommandException) {
650 loge("iccTransmitApduBasicChannel: CommandException: " +
651 ar.exception);
652 } else {
653 loge("iccTransmitApduBasicChannel: Unknown exception");
654 }
655 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700656 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700657 break;
658
659 case CMD_EXCHANGE_SIM_IO:
660 request = (MainThreadRequest) msg.obj;
661 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000662 uiccPort = getUiccPortFromRequest(request);
663 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700664 loge("iccExchangeSimIO: No UICC");
665 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700666 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700667 } else {
668 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
669 request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000670 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700671 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
672 iccArgument.data, onCompleted);
673 }
674 break;
675
676 case EVENT_EXCHANGE_SIM_IO_DONE:
677 ar = (AsyncResult) msg.obj;
678 request = (MainThreadRequest) ar.userObj;
679 if (ar.exception == null && ar.result != null) {
680 request.result = ar.result;
681 } else {
682 request.result = new IccIoResult(0x6f, 0, (byte[])null);
683 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700684 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700685 break;
686
Derek Tan4d5e5c12014-02-04 11:54:58 -0800687 case CMD_SEND_ENVELOPE:
688 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000689 uiccPort = getUiccPortFromRequest(request);
690 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700691 loge("sendEnvelopeWithStatus: No UICC");
692 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700693 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700694 } else {
695 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000696 uiccPort.sendEnvelopeWithStatus((String)request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700697 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800698 break;
699
700 case EVENT_SEND_ENVELOPE_DONE:
701 ar = (AsyncResult) msg.obj;
702 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700703 if (ar.exception == null && ar.result != null) {
704 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800705 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700706 request.result = new IccIoResult(0x6F, 0, (byte[])null);
707 if (ar.result == null) {
708 loge("sendEnvelopeWithStatus: Empty response");
709 } else if (ar.exception instanceof CommandException) {
710 loge("sendEnvelopeWithStatus: CommandException: " +
711 ar.exception);
712 } else {
713 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
714 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800715 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700716 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800717 break;
718
Shishir Agrawal566b7612013-10-28 14:41:00 -0700719 case CMD_OPEN_CHANNEL:
720 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000721 uiccPort = getUiccPortFromRequest(request);
Rambo Wange162e302021-11-10 20:15:19 -0800722 IccLogicalChannelRequest openChannelRequest =
723 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000724 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700725 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800726 request.result = new IccOpenLogicalChannelResponse(-1,
727 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700728 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700729 } else {
730 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wange162e302021-11-10 20:15:19 -0800731 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
732 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700733 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700734 break;
735
736 case EVENT_OPEN_CHANNEL_DONE:
737 ar = (AsyncResult) msg.obj;
738 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700739 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700740 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700741 int[] result = (int[]) ar.result;
742 int channelId = result[0];
743 byte[] selectResponse = null;
744 if (result.length > 1) {
745 selectResponse = new byte[result.length - 1];
746 for (int i = 1; i < result.length; ++i) {
747 selectResponse[i - 1] = (byte) result[i];
748 }
749 }
750 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700751 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang805c7172021-11-10 20:15:19 -0800752
753 uiccPort = getUiccPortFromRequest(request);
754 IccLogicalChannelRequest channelRequest =
755 (IccLogicalChannelRequest) request.argument;
756 channelRequest.channel = channelId;
757 uiccPort.onLogicalChannelOpened(channelRequest);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700758 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700759 if (ar.result == null) {
760 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700761 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700762 if (ar.exception != null) {
763 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
764 }
765
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700766 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700767 if (ar.exception instanceof CommandException) {
768 CommandException.Error error =
769 ((CommandException) (ar.exception)).getCommandError();
770 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700771 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700772 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700773 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700774 }
775 }
776 openChannelResp = new IccOpenLogicalChannelResponse(
777 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700778 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700779 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700780 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700781 break;
782
783 case CMD_CLOSE_CHANNEL:
784 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000785 uiccPort = getUiccPortFromRequest(request);
786 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700787 loge("iccCloseLogicalChannel: No UICC");
Chen Xu9040b472021-12-14 17:15:47 -0800788 throw new IllegalArgumentException("iccCloseLogicalChannel: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700789 } else {
790 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000791 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700792 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700793 break;
794
795 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu9040b472021-12-14 17:15:47 -0800796 ar = (AsyncResult) msg.obj;
797 request = (MainThreadRequest) ar.userObj;
798 if (ar.exception == null) {
799 request.result = true;
Rambo Wang805c7172021-11-10 20:15:19 -0800800 uiccPort = getUiccPortFromRequest(request);
801 final int channelId = (Integer) request.argument;
802 uiccPort.onLogicalChannelClosed(channelId);
Chen Xu9040b472021-12-14 17:15:47 -0800803 } else {
804 request.result = false;
805 if (ar.exception instanceof CommandException) {
806 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
807 CommandException.Error error =
808 ((CommandException) (ar.exception)).getCommandError();
809 // before this feature is enabled, this API should only return false if
810 // the operation fails instead of throwing runtime exception for
811 // backward-compatibility.
812 if (Compatibility.isChangeEnabled(
813 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE)
814 && error == CommandException.Error.INVALID_ARGUMENTS) {
815 throw new IllegalArgumentException(
816 "iccCloseLogicalChannel: invalid argument ");
817 }
818 } else {
819 loge("iccCloseLogicalChannel: Unknown exception");
820 }
821 if (Compatibility.isChangeEnabled(ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE)) {
822 throw new IllegalStateException(
823 "exception from modem to close iccLogical Channel");
824 }
825 }
826 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800827 break;
828
829 case CMD_NV_READ_ITEM:
830 request = (MainThreadRequest) msg.obj;
831 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800832 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
833 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800834 break;
835
836 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700837 ar = (AsyncResult) msg.obj;
838 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800839 if (ar.exception == null && ar.result != null) {
840 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700841 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800842 request.result = "";
843 if (ar.result == null) {
844 loge("nvReadItem: Empty response");
845 } else if (ar.exception instanceof CommandException) {
846 loge("nvReadItem: CommandException: " +
847 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700848 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800849 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700850 }
851 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700852 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700853 break;
854
Jake Hambye994d462014-02-03 13:10:13 -0800855 case CMD_NV_WRITE_ITEM:
856 request = (MainThreadRequest) msg.obj;
857 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
858 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800859 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700860 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800861 break;
862
863 case EVENT_NV_WRITE_ITEM_DONE:
864 handleNullReturnEvent(msg, "nvWriteItem");
865 break;
866
867 case CMD_NV_WRITE_CDMA_PRL:
868 request = (MainThreadRequest) msg.obj;
869 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800870 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800871 break;
872
873 case EVENT_NV_WRITE_CDMA_PRL_DONE:
874 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
875 break;
876
chen xu6dac5ab2018-10-26 17:39:23 -0700877 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800878 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700879 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800880 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800881 break;
882
chen xu6dac5ab2018-10-26 17:39:23 -0700883 case EVENT_RESET_MODEM_CONFIG_DONE:
884 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800885 break;
886
Sooraj Sasindran37444802020-08-11 10:40:43 -0700887 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
888 request = (MainThreadRequest) msg.obj;
889 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
890 request);
891 Phone phone = getPhoneFromRequest(request);
892 if (phone != null) {
893 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
894 } else {
895 loge("isNRDualConnectivityEnabled: No phone object");
896 request.result = false;
897 notifyRequester(request);
898 }
899 break;
900 }
901
902 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
903 ar = (AsyncResult) msg.obj;
904 request = (MainThreadRequest) ar.userObj;
905 if (ar.exception == null && ar.result != null) {
906 request.result = ar.result;
907 } else {
908 // request.result must be set to something non-null
909 // for the calling thread to unblock
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700910 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700911 request.result = ar.result;
912 } else {
913 request.result = false;
914 }
915 if (ar.result == null) {
916 loge("isNRDualConnectivityEnabled: Empty response");
917 } else if (ar.exception instanceof CommandException) {
918 loge("isNRDualConnectivityEnabled: CommandException: "
919 + ar.exception);
920 } else {
921 loge("isNRDualConnectivityEnabled: Unknown exception");
922 }
923 }
924 notifyRequester(request);
925 break;
926
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700927 case CMD_IS_VONR_ENABLED: {
928 request = (MainThreadRequest) msg.obj;
929 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
930 request);
931 Phone phone = getPhoneFromRequest(request);
932 if (phone != null) {
933 phone.isVoNrEnabled(onCompleted, request.workSource);
934 } else {
935 loge("isVoNrEnabled: No phone object");
936 request.result = false;
937 notifyRequester(request);
938 }
939 break;
940 }
941
942 case EVENT_IS_VONR_ENABLED_DONE:
943 ar = (AsyncResult) msg.obj;
944 request = (MainThreadRequest) ar.userObj;
945 if (ar.exception == null && ar.result != null) {
946 request.result = ar.result;
947 } else {
948 // request.result must be set to something non-null
949 // for the calling thread to unblock
950 if (ar.result != null) {
951 request.result = ar.result;
952 } else {
953 request.result = false;
954 }
955 if (ar.result == null) {
956 loge("isVoNrEnabled: Empty response");
957 } else if (ar.exception instanceof CommandException) {
958 loge("isVoNrEnabled: CommandException: "
959 + ar.exception);
960 } else {
961 loge("isVoNrEnabled: Unknown exception");
962 }
963 }
964 notifyRequester(request);
965 break;
966
Sooraj Sasindran37444802020-08-11 10:40:43 -0700967 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
968 request = (MainThreadRequest) msg.obj;
969 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
970 Phone phone = getPhoneFromRequest(request);
971 if (phone != null) {
972 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
973 request.workSource);
974 } else {
975 loge("enableNrDualConnectivity: No phone object");
976 request.result =
977 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
978 notifyRequester(request);
979 }
980 break;
981 }
982
983 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
984 ar = (AsyncResult) msg.obj;
985 request = (MainThreadRequest) ar.userObj;
986 if (ar.exception == null) {
987 request.result =
988 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
989 } else {
990 request.result =
991 TelephonyManager
992 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
993 if (ar.exception instanceof CommandException) {
994 CommandException.Error error =
995 ((CommandException) (ar.exception)).getCommandError();
996 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
997 request.result =
998 TelephonyManager
999 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001000 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1001 request.result =
1002 TelephonyManager
1003 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001004 }
1005 loge("enableNrDualConnectivity" + ": CommandException: "
1006 + ar.exception);
1007 } else {
1008 loge("enableNrDualConnectivity" + ": Unknown exception");
1009 }
1010 }
1011 notifyRequester(request);
1012 break;
1013 }
1014
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -07001015 case CMD_ENABLE_VONR: {
1016 request = (MainThreadRequest) msg.obj;
1017 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1018 Phone phone = getPhoneFromRequest(request);
1019 if (phone != null) {
1020 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1021 request.workSource);
1022 } else {
1023 loge("setVoNrEnabled: No phone object");
1024 request.result =
1025 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1026 notifyRequester(request);
1027 }
1028 break;
1029 }
1030
1031 case EVENT_ENABLE_VONR_DONE: {
1032 ar = (AsyncResult) msg.obj;
1033 request = (MainThreadRequest) ar.userObj;
1034 if (ar.exception == null) {
1035 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1036 } else {
1037 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1038 if (ar.exception instanceof CommandException) {
1039 CommandException.Error error =
1040 ((CommandException) (ar.exception)).getCommandError();
1041 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1042 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1043 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1044 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1045 } else {
1046 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1047 }
1048 loge("setVoNrEnabled" + ": CommandException: "
1049 + ar.exception);
1050 } else {
1051 loge("setVoNrEnabled" + ": Unknown exception");
1052 }
1053 }
1054 notifyRequester(request);
1055 break;
1056 }
1057
SongFerngWang3ef3e072020-12-21 16:41:52 +08001058 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001059 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001060 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1061 request);
1062 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001063 break;
1064
SongFerngWang3ef3e072020-12-21 16:41:52 +08001065 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001066 ar = (AsyncResult) msg.obj;
1067 request = (MainThreadRequest) ar.userObj;
1068 if (ar.exception == null && ar.result != null) {
1069 request.result = ar.result; // Integer
1070 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301071 // request.result must be set to something non-null
1072 // for the calling thread to unblock
1073 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001074 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001075 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001076 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001077 loge("getAllowedNetworkTypesBitmask: CommandException: "
1078 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001079 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001080 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001081 }
1082 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001083 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001084 break;
1085
SongFerngWang3ef3e072020-12-21 16:41:52 +08001086 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001087 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001088 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1089 request);
1090 Pair<Integer, Long> reasonWithNetworkTypes =
1091 (Pair<Integer, Long>) request.argument;
1092 getPhoneFromRequest(request).setAllowedNetworkTypes(
1093 reasonWithNetworkTypes.first,
1094 reasonWithNetworkTypes.second,
1095 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001096 break;
1097
SongFerngWang3ef3e072020-12-21 16:41:52 +08001098 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1099 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001100 break;
1101
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001102 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1103 request = (MainThreadRequest)msg.obj;
1104 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001105 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001106 break;
1107
1108 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1109 ar = (AsyncResult)msg.obj;
1110 request = (MainThreadRequest)ar.userObj;
1111 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001112 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001113 break;
1114
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001115 case CMD_SET_VOICEMAIL_NUMBER:
1116 request = (MainThreadRequest) msg.obj;
1117 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1118 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001119 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1120 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001121 break;
1122
1123 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1124 handleNullReturnEvent(msg, "setVoicemailNumber");
1125 break;
1126
Stuart Scott54788802015-03-30 13:18:01 -07001127 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1128 request = (MainThreadRequest) msg.obj;
1129 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1130 request);
1131 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1132 break;
1133
1134 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1135 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1136 break;
1137
Shishir Agrawal302c8692015-06-19 13:49:39 -07001138 case CMD_PERFORM_NETWORK_SCAN:
1139 request = (MainThreadRequest) msg.obj;
1140 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1141 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1142 break;
1143
Hall Liu27d24262020-09-18 19:04:59 -07001144 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001145 request = (MainThreadRequest) msg.obj;
1146 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001147 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1148 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1149 request.argument;
1150 int callForwardingReason = args.first;
1151 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001152 break;
Hall Liu27d24262020-09-18 19:04:59 -07001153 }
1154 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001155 ar = (AsyncResult) msg.obj;
1156 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001157 TelephonyManager.CallForwardingInfoCallback callback =
1158 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1159 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001160 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001161 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001162 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1163 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1164 // Service Class is a bit mask per 3gpp 27.007. Search for
1165 // any service for voice call.
1166 if ((callForwardInfo.serviceClass
1167 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001168 callForwardingInfo = new CallForwardingInfo(
1169 callForwardInfo.status
1170 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001171 callForwardInfo.reason,
1172 callForwardInfo.number,
1173 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001174 break;
1175 }
1176 }
1177 // Didn't find a call forward info for voice call.
1178 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001179 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1180 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001181 }
Hall Liu27d24262020-09-18 19:04:59 -07001182 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001183 } else {
1184 if (ar.result == null) {
1185 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1186 }
1187 if (ar.exception != null) {
1188 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1189 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001190 int errorCode = TelephonyManager
1191 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001192 if (ar.exception instanceof CommandException) {
1193 CommandException.Error error =
1194 ((CommandException) (ar.exception)).getCommandError();
1195 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001196 errorCode = TelephonyManager
1197 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001198 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001199 errorCode = TelephonyManager
1200 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001201 }
1202 }
Hall Liu27d24262020-09-18 19:04:59 -07001203 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001204 }
Shuo Qian4a594052020-01-23 11:59:30 -08001205 break;
Hall Liu27d24262020-09-18 19:04:59 -07001206 }
Shuo Qian4a594052020-01-23 11:59:30 -08001207
Hall Liu27d24262020-09-18 19:04:59 -07001208 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001209 request = (MainThreadRequest) msg.obj;
1210 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001211 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001212 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001213 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1214 request.argument).first;
1215 request.phone.setCallForwardingOption(
1216 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001217 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001218 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001219 callForwardingInfoToSet.getReason(),
1220 callForwardingInfoToSet.getNumber(),
1221 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1222 break;
Hall Liu27d24262020-09-18 19:04:59 -07001223 }
Shuo Qian4a594052020-01-23 11:59:30 -08001224
Hall Liu27d24262020-09-18 19:04:59 -07001225 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001226 ar = (AsyncResult) msg.obj;
1227 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001228 Consumer<Integer> callback =
1229 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1230 request.argument).second;
1231 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001232 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001233 int errorCode = TelephonyManager.CallForwardingInfoCallback
1234 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001235 if (ar.exception instanceof CommandException) {
1236 CommandException.Error error =
1237 ((CommandException) (ar.exception)).getCommandError();
1238 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001239 errorCode = TelephonyManager.CallForwardingInfoCallback
1240 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001241 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001242 errorCode = TelephonyManager.CallForwardingInfoCallback
1243 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001244 }
1245 }
1246 callback.accept(errorCode);
1247 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001248 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001249 }
Shuo Qian4a594052020-01-23 11:59:30 -08001250 break;
Hall Liu27d24262020-09-18 19:04:59 -07001251 }
Shuo Qian4a594052020-01-23 11:59:30 -08001252
Hall Liu27d24262020-09-18 19:04:59 -07001253 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001254 request = (MainThreadRequest) msg.obj;
1255 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1256 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1257 break;
Hall Liu27d24262020-09-18 19:04:59 -07001258 }
Shuo Qian4a594052020-01-23 11:59:30 -08001259
Hall Liu27d24262020-09-18 19:04:59 -07001260 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001261 ar = (AsyncResult) msg.obj;
1262 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001263 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001264 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1265 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001266 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001267 // Service Class is a bit mask per 3gpp 27.007.
1268 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001269 if (callForwardResults.length > 1
1270 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001271 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001272 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001273 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1274 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001275 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001276 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001277 }
1278 } else {
1279 if (ar.result == null) {
1280 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1281 }
1282 if (ar.exception != null) {
1283 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1284 }
1285 if (ar.exception instanceof CommandException) {
1286 CommandException.Error error =
1287 ((CommandException) (ar.exception)).getCommandError();
1288 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1289 callForwardingStatus =
1290 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1291 }
1292 }
1293 }
Hall Liu27d24262020-09-18 19:04:59 -07001294 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001295 break;
Hall Liu27d24262020-09-18 19:04:59 -07001296 }
Shuo Qian4a594052020-01-23 11:59:30 -08001297
Hall Liu27d24262020-09-18 19:04:59 -07001298 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001299 request = (MainThreadRequest) msg.obj;
1300 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001301 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1302 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001303 break;
Hall Liu27d24262020-09-18 19:04:59 -07001304 }
Shuo Qian4a594052020-01-23 11:59:30 -08001305
Hall Liu27d24262020-09-18 19:04:59 -07001306 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001307 ar = (AsyncResult) msg.obj;
1308 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001309 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1310 Consumer<Integer> callback =
1311 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1312 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001313 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001314 if (ar.exception instanceof CommandException) {
1315 CommandException.Error error =
1316 ((CommandException) (ar.exception)).getCommandError();
1317 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1318 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1319 } else {
1320 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1321 }
1322 } else {
1323 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1324 }
1325 } else {
1326 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1327 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001328 }
Shuo Qian4a594052020-01-23 11:59:30 -08001329 break;
Hall Liu27d24262020-09-18 19:04:59 -07001330 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001331 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1332 ar = (AsyncResult) msg.obj;
1333 request = (MainThreadRequest) ar.userObj;
1334 CellNetworkScanResult cellScanResult;
1335 if (ar.exception == null && ar.result != null) {
1336 cellScanResult = new CellNetworkScanResult(
1337 CellNetworkScanResult.STATUS_SUCCESS,
1338 (List<OperatorInfo>) ar.result);
1339 } else {
1340 if (ar.result == null) {
1341 loge("getCellNetworkScanResults: Empty response");
1342 }
1343 if (ar.exception != null) {
1344 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1345 }
1346 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1347 if (ar.exception instanceof CommandException) {
1348 CommandException.Error error =
1349 ((CommandException) (ar.exception)).getCommandError();
1350 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1351 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1352 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1353 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1354 }
1355 }
1356 cellScanResult = new CellNetworkScanResult(errorCode, null);
1357 }
1358 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001359 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001360 break;
1361
1362 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1363 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001364 ManualNetworkSelectionArgument selArg =
1365 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001366 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1367 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001368 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1369 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001370 break;
1371
1372 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001373 ar = (AsyncResult) msg.obj;
1374 request = (MainThreadRequest) ar.userObj;
1375 if (ar.exception == null) {
1376 request.result = true;
1377 } else {
1378 request.result = false;
1379 loge("setNetworkSelectionModeManual " + ar.exception);
1380 }
1381 notifyRequester(request);
1382 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001383 break;
1384
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001385 case CMD_GET_MODEM_ACTIVITY_INFO:
1386 request = (MainThreadRequest) msg.obj;
1387 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001388 if (defaultPhone != null) {
1389 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001390 } else {
1391 ResultReceiver result = (ResultReceiver) request.argument;
1392 Bundle bundle = new Bundle();
1393 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001394 new ModemActivityInfo(0, 0, 0,
1395 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001396 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001397 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001398 break;
1399
Hall Liud0f208c2020-10-14 16:54:44 -07001400 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001401 ar = (AsyncResult) msg.obj;
1402 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001403 ResultReceiver result = (ResultReceiver) request.argument;
1404
Hall Liud0f208c2020-10-14 16:54:44 -07001405 ModemActivityInfo ret = null;
1406 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001407 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001408 // Update the last modem activity info and the result of the request.
1409 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1410 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001411 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001412 int[] txTimeMs = info.getTransmitTimeMillis();
1413 int[] lastModemTxTimeMs = mLastModemActivityInfo
1414 .getTransmitTimeMillis();
1415 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1416 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1417 }
Hall Liu49656c02020-10-09 19:00:11 -07001418 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001419 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1420 + mLastModemActivityInfo.getSleepTimeMillis());
1421 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1422 + mLastModemActivityInfo.getIdleTimeMillis());
1423 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1424 mLastModemActivityInfo.setReceiveTimeMillis(
1425 info.getReceiveTimeMillis()
1426 + mLastModemActivityInfo.getReceiveTimeMillis());
1427 }
Hall Liu49656c02020-10-09 19:00:11 -07001428 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001429 mLastModemActivityInfo.getSleepTimeMillis(),
1430 mLastModemActivityInfo.getIdleTimeMillis(),
1431 mLastModemActivityInfo.getTransmitTimeMillis(),
1432 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001433 } else {
1434 if (ar.result == null) {
1435 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001436 error = TelephonyManager.ModemActivityInfoException
1437 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001438 } else if (ar.exception instanceof CommandException) {
1439 loge("queryModemActivityInfo: CommandException: " +
1440 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001441 error = TelephonyManager.ModemActivityInfoException
1442 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001443 } else {
1444 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001445 error = TelephonyManager.ModemActivityInfoException
1446 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001447 }
1448 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001449 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001450 if (ret != null) {
1451 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1452 } else {
1453 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1454 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001455 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001456 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001457 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001458 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001459
Meng Wang1a7c35a2016-05-05 20:56:15 -07001460 case CMD_SET_ALLOWED_CARRIERS:
1461 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001462 CarrierRestrictionRules argument =
1463 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001464 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001465 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001466 break;
1467
1468 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1469 ar = (AsyncResult) msg.obj;
1470 request = (MainThreadRequest) ar.userObj;
1471 if (ar.exception == null && ar.result != null) {
1472 request.result = ar.result;
1473 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001474 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1475 if (ar.exception instanceof CommandException) {
1476 loge("setAllowedCarriers: CommandException: " + ar.exception);
1477 CommandException.Error error =
1478 ((CommandException) (ar.exception)).getCommandError();
1479 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1480 request.result =
1481 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1482 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001483 } else {
1484 loge("setAllowedCarriers: Unknown exception");
1485 }
1486 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001487 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001488 break;
1489
1490 case CMD_GET_ALLOWED_CARRIERS:
1491 request = (MainThreadRequest) msg.obj;
1492 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001493 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001494 break;
1495
1496 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1497 ar = (AsyncResult) msg.obj;
1498 request = (MainThreadRequest) ar.userObj;
1499 if (ar.exception == null && ar.result != null) {
1500 request.result = ar.result;
1501 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001502 request.result = new IllegalStateException(
1503 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001504 if (ar.result == null) {
1505 loge("getAllowedCarriers: Empty response");
1506 } else if (ar.exception instanceof CommandException) {
1507 loge("getAllowedCarriers: CommandException: " +
1508 ar.exception);
1509 } else {
1510 loge("getAllowedCarriers: Unknown exception");
1511 }
1512 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001513 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001514 break;
1515
Nathan Haroldb3014052017-01-25 15:57:32 -08001516 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1517 ar = (AsyncResult) msg.obj;
1518 request = (MainThreadRequest) ar.userObj;
1519 if (ar.exception == null && ar.result != null) {
1520 request.result = ar.result;
1521 } else {
1522 request.result = new IllegalArgumentException(
1523 "Failed to retrieve Forbidden Plmns");
1524 if (ar.result == null) {
1525 loge("getForbiddenPlmns: Empty response");
1526 } else {
1527 loge("getForbiddenPlmns: Unknown exception");
1528 }
1529 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001530 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001531 break;
1532
1533 case CMD_GET_FORBIDDEN_PLMNS:
1534 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001535 uiccPort = getUiccPortFromRequest(request);
1536 if (uiccPort == null) {
1537 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001538 request.result = new IllegalArgumentException(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001539 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001540 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001541 break;
1542 }
1543 Integer appType = (Integer) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001544 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001545 if (uiccApp == null) {
1546 loge("getForbiddenPlmns() no app with specified type -- "
1547 + appType);
1548 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001549 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001550 break;
1551 } else {
1552 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1553 + " specified type -- " + appType);
1554 }
1555 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1556 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1557 onCompleted);
1558 break;
1559
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001560 case CMD_SWITCH_SLOTS:
1561 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00001562 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001563 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00001564 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001565 break;
1566
1567 case EVENT_SWITCH_SLOTS_DONE:
1568 ar = (AsyncResult) msg.obj;
1569 request = (MainThreadRequest) ar.userObj;
1570 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001571 notifyRequester(request);
1572 break;
1573 case CMD_GET_NETWORK_SELECTION_MODE:
1574 request = (MainThreadRequest) msg.obj;
1575 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1576 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1577 break;
1578
1579 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1580 ar = (AsyncResult) msg.obj;
1581 request = (MainThreadRequest) ar.userObj;
1582 if (ar.exception != null) {
1583 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1584 } else {
1585 int mode = ((int[]) ar.result)[0];
1586 if (mode == 0) {
1587 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1588 } else {
1589 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1590 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001591 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001592 notifyRequester(request);
1593 break;
1594 case CMD_GET_CDMA_ROAMING_MODE:
1595 request = (MainThreadRequest) msg.obj;
1596 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1597 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1598 break;
1599 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1600 ar = (AsyncResult) msg.obj;
1601 request = (MainThreadRequest) ar.userObj;
1602 if (ar.exception != null) {
1603 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1604 } else {
1605 request.result = ((int[]) ar.result)[0];
1606 }
1607 notifyRequester(request);
1608 break;
1609 case CMD_SET_CDMA_ROAMING_MODE:
1610 request = (MainThreadRequest) msg.obj;
1611 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1612 int mode = (int) request.argument;
1613 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1614 break;
1615 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1616 ar = (AsyncResult) msg.obj;
1617 request = (MainThreadRequest) ar.userObj;
1618 request.result = ar.exception == null;
1619 notifyRequester(request);
1620 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001621 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1622 request = (MainThreadRequest) msg.obj;
1623 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1624 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1625 break;
1626 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1627 ar = (AsyncResult) msg.obj;
1628 request = (MainThreadRequest) ar.userObj;
1629 if (ar.exception != null) {
1630 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1631 } else {
1632 request.result = ((int[]) ar.result)[0];
1633 }
1634 notifyRequester(request);
1635 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001636 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1637 request = (MainThreadRequest) msg.obj;
1638 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1639 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001640 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1641 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001642 break;
1643 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1644 ar = (AsyncResult) msg.obj;
1645 request = (MainThreadRequest) ar.userObj;
1646 request.result = ar.exception == null;
1647 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001648 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001649 case CMD_GET_ALL_CELL_INFO:
1650 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001651 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001652 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001653 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001654 case EVENT_GET_ALL_CELL_INFO_DONE:
1655 ar = (AsyncResult) msg.obj;
1656 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001657 // If a timeout occurs, the response will be null
1658 request.result = (ar.exception == null && ar.result != null)
1659 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001660 synchronized (request) {
1661 request.notifyAll();
1662 }
1663 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001664 case CMD_REQUEST_CELL_INFO_UPDATE:
1665 request = (MainThreadRequest) msg.obj;
1666 request.phone.requestCellInfoUpdate(request.workSource,
1667 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1668 break;
1669 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1670 ar = (AsyncResult) msg.obj;
1671 request = (MainThreadRequest) ar.userObj;
1672 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1673 try {
1674 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001675 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001676 cb.onError(
1677 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1678 ar.exception.getClass().getName(),
1679 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001680 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001681 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001682 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001683 } else {
1684 // use the result as returned
1685 cb.onCellInfo((List<CellInfo>) ar.result);
1686 }
1687 } catch (RemoteException re) {
1688 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1689 }
1690 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001691 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001692 request = (MainThreadRequest) msg.obj;
1693 WorkSource ws = (WorkSource) request.argument;
1694 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001695 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001696 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001697 }
1698 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001699 ar = (AsyncResult) msg.obj;
1700 request = (MainThreadRequest) ar.userObj;
1701 if (ar.exception == null) {
1702 request.result = ar.result;
1703 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001704 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001705 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001706 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001707 }
1708
1709 synchronized (request) {
1710 request.notifyAll();
1711 }
1712 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001713 }
chen xu6dac5ab2018-10-26 17:39:23 -07001714 case CMD_MODEM_REBOOT:
1715 request = (MainThreadRequest) msg.obj;
1716 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001717 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001718 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001719 case EVENT_CMD_MODEM_REBOOT_DONE:
1720 handleNullReturnEvent(msg, "rebootModem");
1721 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001722 case CMD_REQUEST_ENABLE_MODEM:
1723 request = (MainThreadRequest) msg.obj;
1724 boolean enable = (boolean) request.argument;
1725 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001726 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001727 PhoneConfigurationManager.getInstance()
1728 .enablePhone(request.phone, enable, onCompleted);
1729 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001730 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001731 ar = (AsyncResult) msg.obj;
1732 request = (MainThreadRequest) ar.userObj;
1733 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001734 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001735 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001736 if ((boolean) request.result) {
1737 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1738 updateModemStateMetrics();
1739 } else {
1740 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1741 + ar.exception);
1742 }
1743 notifyRequester(request);
1744 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001745 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001746 case CMD_GET_MODEM_STATUS:
1747 request = (MainThreadRequest) msg.obj;
1748 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1749 PhoneConfigurationManager.getInstance()
1750 .getPhoneStatusFromModem(request.phone, onCompleted);
1751 break;
1752 case EVENT_GET_MODEM_STATUS_DONE:
1753 ar = (AsyncResult) msg.obj;
1754 request = (MainThreadRequest) ar.userObj;
1755 int id = request.phone.getPhoneId();
1756 if (ar.exception == null && ar.result != null) {
1757 request.result = ar.result;
1758 //update the cache as modem status has changed
1759 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1760 (boolean) request.result);
1761 } else {
1762 // Return true if modem status cannot be retrieved. For most cases,
1763 // modem status is on. And for older version modems, GET_MODEM_STATUS
1764 // and disable modem are not supported. Modem is always on.
1765 // TODO: this should be fixed in R to support a third
1766 // status UNKNOWN b/131631629
1767 request.result = true;
1768 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1769 + ar.exception);
1770 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001771 notifyRequester(request);
1772 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001773 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1774 request = (MainThreadRequest) msg.obj;
1775 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1776 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1777 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1778 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1779 break;
1780 }
1781 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1782 ar = (AsyncResult) msg.obj;
1783 request = (MainThreadRequest) ar.userObj;
1784 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1785 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1786 args.second.accept(ar.exception == null);
1787 notifyRequester(request);
1788 break;
1789 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001790 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1791 request = (MainThreadRequest) msg.obj;
1792 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1793 Phone phone = getPhoneFromRequest(request);
1794 if (phone != null) {
1795 phone.getSystemSelectionChannels(onCompleted);
1796 } else {
1797 loge("getSystemSelectionChannels: No phone object");
1798 request.result = new ArrayList<RadioAccessSpecifier>();
1799 notifyRequester(request);
1800 }
1801 break;
1802 }
1803 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1804 ar = (AsyncResult) msg.obj;
1805 request = (MainThreadRequest) ar.userObj;
1806 if (ar.exception == null && ar.result != null) {
1807 request.result = ar.result;
1808 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001809 request.result = new IllegalStateException(
1810 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001811 if (ar.result == null) {
1812 loge("getSystemSelectionChannels: Empty response");
1813 } else {
1814 loge("getSystemSelectionChannels: Unknown exception");
1815 }
1816 }
1817 notifyRequester(request);
1818 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001819 case EVENT_SET_FORBIDDEN_PLMNS_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 {
1825 request.result = -1;
1826 loge("Failed to set Forbidden Plmns");
1827 if (ar.result == null) {
1828 loge("setForbidenPlmns: Empty response");
1829 } else if (ar.exception != null) {
1830 loge("setForbiddenPlmns: Exception: " + ar.exception);
1831 request.result = -1;
1832 } else {
1833 loge("setForbiddenPlmns: Unknown exception");
1834 }
1835 }
1836 notifyRequester(request);
1837 break;
1838 case CMD_SET_FORBIDDEN_PLMNS:
1839 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001840 uiccPort = getUiccPortFromRequest(request);
1841 if (uiccPort == null) {
1842 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001843 request.result = -1;
1844 notifyRequester(request);
1845 break;
1846 }
1847 Pair<Integer, List<String>> setFplmnsArgs =
1848 (Pair<Integer, List<String>>) request.argument;
1849 appType = setFplmnsArgs.first;
1850 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001851 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001852 if (uiccApp == null) {
1853 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1854 request.result = -1;
1855 loge("Failed to get UICC App");
1856 notifyRequester(request);
1857 } else {
1858 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1859 ((SIMRecords) uiccApp.getIccRecords())
1860 .setForbiddenPlmns(onCompleted, fplmns);
1861 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001862 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001863 case CMD_ERASE_MODEM_CONFIG:
1864 request = (MainThreadRequest) msg.obj;
1865 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1866 defaultPhone.eraseModemConfig(onCompleted);
1867 break;
1868 case EVENT_ERASE_MODEM_CONFIG_DONE:
1869 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001870 break;
zoey chene02881a2019-12-30 16:11:23 +08001871
Kai Shif70f46f2021-03-03 13:59:46 -08001872 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1873 request = (MainThreadRequest) msg.obj;
1874 request.result = defaultPhone.eraseDataInSharedPreferences();
1875 notifyRequester(request);
1876 break;
1877
zoey chene02881a2019-12-30 16:11:23 +08001878 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1879 request = (MainThreadRequest) msg.obj;
1880 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1881 Pair<String, String> changed = (Pair<String, String>) request.argument;
1882 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1883 changed.first, changed.second, onCompleted);
1884 break;
1885 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1886 ar = (AsyncResult) msg.obj;
1887 request = (MainThreadRequest) ar.userObj;
1888 if (ar.exception == null) {
1889 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001890 // If the operation is successful, update the PIN storage
1891 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1892 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivackbb777522021-10-06 20:53:09 +00001893 UiccController.getInstance().getPinStorage()
1894 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001895 } else {
1896 request.result = msg.arg1;
1897 }
1898 notifyRequester(request);
1899 break;
1900
Michele Berionne5e411512020-11-13 02:36:59 +00001901 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001902 request = (MainThreadRequest) msg.obj;
1903 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1904 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1905 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1906 enabled.first, enabled.second, onCompleted);
1907 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001908 }
zoey chene02881a2019-12-30 16:11:23 +08001909 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1910 ar = (AsyncResult) msg.obj;
1911 request = (MainThreadRequest) ar.userObj;
1912 if (ar.exception == null) {
1913 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001914 // If the operation is successful, update the PIN storage
1915 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1916 int phoneId = getPhoneFromRequest(request).getPhoneId();
1917 if (enabled.first) {
Jon Spivackbb777522021-10-06 20:53:09 +00001918 UiccController.getInstance().getPinStorage()
1919 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001920 } else {
1921 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1922 }
zoey chene02881a2019-12-30 16:11:23 +08001923 } else {
1924 request.result = msg.arg1;
1925 }
Michele Berionne5e411512020-11-13 02:36:59 +00001926
1927
zoey chene02881a2019-12-30 16:11:23 +08001928 notifyRequester(request);
1929 break;
1930
Peter Wangdafb9ac2020-01-15 14:13:38 -08001931 case MSG_NOTIFY_USER_ACTIVITY:
1932 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001933 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001934 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1935 getDefaultPhone().getContext().sendBroadcastAsUser(
1936 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1937 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001938
1939 case CMD_SET_DATA_THROTTLING: {
1940 request = (MainThreadRequest) msg.obj;
1941 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1942 DataThrottlingRequest dataThrottlingRequest =
1943 (DataThrottlingRequest) request.argument;
1944 Phone phone = getPhoneFromRequest(request);
1945 if (phone != null) {
1946 phone.setDataThrottling(onCompleted,
1947 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1948 dataThrottlingRequest.getCompletionDurationMillis());
1949 } else {
1950 loge("setDataThrottling: No phone object");
1951 request.result =
1952 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1953 notifyRequester(request);
1954 }
1955
1956 break;
1957 }
1958 case EVENT_SET_DATA_THROTTLING_DONE:
1959 ar = (AsyncResult) msg.obj;
1960 request = (MainThreadRequest) ar.userObj;
1961
1962 if (ar.exception == null) {
1963 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1964 } else if (ar.exception instanceof CommandException) {
1965 loge("setDataThrottling: CommandException: " + ar.exception);
1966 CommandException.Error error =
1967 ((CommandException) (ar.exception)).getCommandError();
1968
1969 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1970 request.result = TelephonyManager
1971 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1972 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1973 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001974 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1975 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001976 } else {
1977 request.result =
1978 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1979 }
1980 } else {
1981 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1982 }
1983 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1984 notifyRequester(request);
1985 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001986
1987 case CMD_SET_SIM_POWER: {
1988 request = (MainThreadRequest) msg.obj;
1989 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1990 request = (MainThreadRequest) msg.obj;
1991 int stateToSet =
1992 ((Pair<Integer, IIntegerConsumer>)
1993 request.argument).first;
1994 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1995 break;
1996 }
1997 case EVENT_SET_SIM_POWER_DONE: {
1998 ar = (AsyncResult) msg.obj;
1999 request = (MainThreadRequest) ar.userObj;
2000 IIntegerConsumer callback =
2001 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2002 if (ar.exception != null) {
2003 loge("setSimPower exception: " + ar.exception);
2004 int errorCode = TelephonyManager.CallForwardingInfoCallback
2005 .RESULT_ERROR_UNKNOWN;
2006 if (ar.exception instanceof CommandException) {
2007 CommandException.Error error =
2008 ((CommandException) (ar.exception)).getCommandError();
2009 if (error == CommandException.Error.SIM_ERR) {
2010 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2011 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2012 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2013 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2014 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2015 } else {
2016 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2017 }
2018 }
2019 try {
2020 callback.accept(errorCode);
2021 } catch (RemoteException e) {
2022 // Ignore if the remote process is no longer available to call back.
2023 Log.w(LOG_TAG, "setSimPower: callback not available.");
2024 }
2025 } else {
2026 try {
2027 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2028 } catch (RemoteException e) {
2029 // Ignore if the remote process is no longer available to call back.
2030 Log.w(LOG_TAG, "setSimPower: callback not available.");
2031 }
2032 }
2033 break;
2034 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002035 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2036 request = (MainThreadRequest) msg.obj;
2037
2038 final Phone phone = getPhoneFromRequest(request);
2039 if (phone == null || phone.getServiceStateTracker() == null) {
2040 request.result = new IllegalStateException("Phone or SST is null");
2041 notifyRequester(request);
2042 break;
2043 }
2044
2045 Pair<Integer, SignalStrengthUpdateRequest> pair =
2046 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2047 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2048 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002049 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002050 request.subId, pair.first /*callingUid*/,
2051 pair.second /*request*/, onCompleted);
2052 break;
2053 }
2054 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2055 ar = (AsyncResult) msg.obj;
2056 request = (MainThreadRequest) ar.userObj;
2057 // request.result will be the exception of ar if present, true otherwise.
2058 // Be cautious not to leave result null which will wait() forever
2059 request.result = ar.exception != null ? ar.exception : true;
2060 notifyRequester(request);
2061 break;
2062 }
2063 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2064 request = (MainThreadRequest) msg.obj;
2065
2066 Phone phone = getPhoneFromRequest(request);
2067 if (phone == null || phone.getServiceStateTracker() == null) {
2068 request.result = new IllegalStateException("Phone or SST is null");
2069 notifyRequester(request);
2070 break;
2071 }
2072
2073 Pair<Integer, SignalStrengthUpdateRequest> pair =
2074 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2075 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2076 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002077 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002078 request.subId, pair.first /*callingUid*/,
2079 pair.second /*request*/, onCompleted);
2080 break;
2081 }
2082 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2083 ar = (AsyncResult) msg.obj;
2084 request = (MainThreadRequest) ar.userObj;
2085 request.result = ar.exception != null ? ar.exception : true;
2086 notifyRequester(request);
2087 break;
2088 }
Jordan Liu109698e2020-11-24 14:50:34 -08002089
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002090 case CMD_GET_SLICING_CONFIG: {
2091 request = (MainThreadRequest) msg.obj;
2092 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2093 request.phone.getSlicingConfig(onCompleted);
2094 break;
2095 }
2096 case EVENT_GET_SLICING_CONFIG_DONE: {
2097 ar = (AsyncResult) msg.obj;
2098 request = (MainThreadRequest) ar.userObj;
2099 ResultReceiver result = (ResultReceiver) request.argument;
2100
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002101 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002102 Bundle bundle = new Bundle();
2103 int resultCode = 0;
2104 if (ar.exception != null) {
2105 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2106 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002107 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002108 } else if (ar.result == null) {
2109 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002110 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002111 } else {
2112 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002113 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2114 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002115 }
2116
2117 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002118 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002119 }
2120 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2121 result.send(resultCode, bundle);
2122 notifyRequester(request);
2123 break;
2124 }
2125
Michele Berionne5e411512020-11-13 02:36:59 +00002126 case CMD_PREPARE_UNATTENDED_REBOOT:
2127 request = (MainThreadRequest) msg.obj;
2128 request.result =
2129 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
2130 notifyRequester(request);
2131 break;
2132
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002133 default:
2134 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2135 break;
2136 }
2137 }
Jake Hambye994d462014-02-03 13:10:13 -08002138
Pengquan Menga1bb6272018-09-06 09:59:22 -07002139 private void notifyRequester(MainThreadRequest request) {
2140 synchronized (request) {
2141 request.notifyAll();
2142 }
2143 }
2144
Jake Hambye994d462014-02-03 13:10:13 -08002145 private void handleNullReturnEvent(Message msg, String command) {
2146 AsyncResult ar = (AsyncResult) msg.obj;
2147 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2148 if (ar.exception == null) {
2149 request.result = true;
2150 } else {
2151 request.result = false;
2152 if (ar.exception instanceof CommandException) {
2153 loge(command + ": CommandException: " + ar.exception);
2154 } else {
2155 loge(command + ": Unknown exception");
2156 }
2157 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002158 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002159 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002160 }
2161
2162 /**
2163 * Posts the specified command to be executed on the main thread,
2164 * waits for the request to complete, and returns the result.
2165 * @see #sendRequestAsync
2166 */
2167 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002168 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2169 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002170 }
2171
2172 /**
2173 * Posts the specified command to be executed on the main thread,
2174 * waits for the request to complete, and returns the result.
2175 * @see #sendRequestAsync
2176 */
2177 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2178 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002179 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002180 }
2181
2182 /**
2183 * Posts the specified command to be executed on the main thread,
2184 * waits for the request to complete, and returns the result.
2185 * @see #sendRequestAsync
2186 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002187 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002188 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2189 }
2190
2191 /**
2192 * Posts the specified command to be executed on the main thread,
2193 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2194 * if not timeout or null otherwise.
2195 * @see #sendRequestAsync
2196 */
2197 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2198 long timeoutInMs) {
2199 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002200 }
2201
2202 /**
2203 * Posts the specified command to be executed on the main thread,
2204 * waits for the request to complete, and returns the result.
2205 * @see #sendRequestAsync
2206 */
Nathan Harold92bed182018-10-12 18:16:49 -07002207 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002208 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002209 }
2210
2211 /**
2212 * Posts the specified command to be executed on the main thread,
2213 * waits for the request to complete, and returns the result.
2214 * @see #sendRequestAsync
2215 */
2216 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002217 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2218 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002219 }
2220
2221 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002222 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2223 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2224 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002225 * @see #sendRequestAsync
2226 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002227 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2228 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002229 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2230 throw new RuntimeException("This method will deadlock if called from the main thread.");
2231 }
2232
Nathan Harold92bed182018-10-12 18:16:49 -07002233 MainThreadRequest request = null;
2234 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2235 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2236 } else if (phone != null) {
2237 request = new MainThreadRequest(argument, phone, workSource);
2238 } else {
2239 request = new MainThreadRequest(argument, subId, workSource);
2240 }
2241
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002242 Message msg = mMainThreadHandler.obtainMessage(command, request);
2243 msg.sendToTarget();
2244
Rambo Wang0f050d82021-02-12 11:43:36 -08002245
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002246 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002247 if (timeoutInMs >= 0) {
2248 // Wait for at least timeoutInMs before returning null request result
2249 long now = SystemClock.elapsedRealtime();
2250 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002251 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002252 try {
2253 request.wait(deadline - now);
2254 } catch (InterruptedException e) {
2255 // Do nothing, go back and check if request is completed or timeout
2256 } finally {
2257 now = SystemClock.elapsedRealtime();
2258 }
2259 }
2260 } else {
2261 // Wait for the request to complete
2262 while (request.result == null) {
2263 try {
2264 request.wait();
2265 } catch (InterruptedException e) {
2266 // Do nothing, go back and wait until the request is complete
2267 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002268 }
2269 }
2270 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002271 if (request.result == null) {
2272 Log.wtf(LOG_TAG,
2273 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2274 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002275 return request.result;
2276 }
2277
2278 /**
2279 * Asynchronous ("fire and forget") version of sendRequest():
2280 * Posts the specified command to be executed on the main thread, and
2281 * returns immediately.
2282 * @see #sendRequest
2283 */
2284 private void sendRequestAsync(int command) {
2285 mMainThreadHandler.sendEmptyMessage(command);
2286 }
2287
2288 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002289 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002290 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002291 */
2292 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002293 sendRequestAsync(command, argument, null, null);
2294 }
2295
2296 /**
2297 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2298 * @see {@link #sendRequest(int,Object)}
2299 */
2300 private void sendRequestAsync(
2301 int command, Object argument, Phone phone, WorkSource workSource) {
2302 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002303 Message msg = mMainThreadHandler.obtainMessage(command, request);
2304 msg.sendToTarget();
2305 }
2306
2307 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002308 * Initialize the singleton PhoneInterfaceManager instance.
2309 * This is only done once, at startup, from PhoneApp.onCreate().
2310 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002311 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002312 synchronized (PhoneInterfaceManager.class) {
2313 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002314 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002315 } else {
2316 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2317 }
2318 return sInstance;
2319 }
2320 }
2321
2322 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002323 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002324 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002325 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002326 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002327 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002328 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002329 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002330 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002331 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002332 mTelephonySharedPreferences =
2333 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002334 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002335 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002336 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002337 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002338
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002339 publish();
2340 }
2341
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002342 private Phone getDefaultPhone() {
2343 Phone thePhone = getPhone(getDefaultSubscription());
2344 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2345 }
2346
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002347 private void publish() {
2348 if (DBG) log("publish: " + this);
2349
Peter Wangc035ce42020-01-08 21:00:22 -08002350 TelephonyFrameworkInitializer
2351 .getTelephonyServiceManager()
2352 .getTelephonyServiceRegisterer()
2353 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002354 }
2355
Stuart Scott584921c2015-01-15 17:10:34 -08002356 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002357 if (request.phone != null) {
2358 return request.phone;
2359 } else {
2360 return getPhoneFromSubId(request.subId);
2361 }
2362 }
2363
2364 private Phone getPhoneFromSubId(int subId) {
2365 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2366 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002367 }
2368
Muralidhar Reddy864fe982021-09-29 19:38:40 +00002369 private UiccPort getUiccPortFromRequest(MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002370 Phone phone = getPhoneFromRequest(request);
2371 return phone == null ? null :
Muralidhar Reddy864fe982021-09-29 19:38:40 +00002372 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002373 }
2374
Wink Saville36469e72014-06-11 15:17:00 -07002375 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002376 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002377 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002378 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002379
Kai Shif70f46f2021-03-03 13:59:46 -08002380 private void sendEraseModemConfig(@NonNull Phone phone) {
2381 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2382 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2383 }
2384
2385 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2386 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2387 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002388 }
2389
Peter Wang44b186e2020-01-13 23:33:09 -08002390 private boolean isImsAvailableOnDevice() {
2391 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2392 if (pm == null) {
2393 // For some reason package manger is not available.. This will fail internally anyway,
2394 // so do not throw error and allow.
2395 return true;
2396 }
2397 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2398 }
2399
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002400 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002401 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002402 }
2403
Wink Savilleb564aae2014-10-23 10:18:09 -07002404 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002405 if (DBG) log("dial: " + number);
2406 // No permission check needed here: This is just a wrapper around the
2407 // ACTION_DIAL intent, which is available to any app since it puts up
2408 // the UI before it does anything.
2409
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002410 final long identity = Binder.clearCallingIdentity();
2411 try {
2412 String url = createTelUrl(number);
2413 if (url == null) {
2414 return;
2415 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002416
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002417 // PENDING: should we just silently fail if phone is offhook or ringing?
2418 PhoneConstants.State state = mCM.getState(subId);
2419 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2420 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2421 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2422 mApp.startActivity(intent);
2423 }
2424 } finally {
2425 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002426 }
2427 }
2428
2429 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002430 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002431 }
2432
Wink Savilleb564aae2014-10-23 10:18:09 -07002433 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002434 if (DBG) log("call: " + number);
2435
2436 // This is just a wrapper around the ACTION_CALL intent, but we still
2437 // need to do a permission check since we're calling startActivity()
2438 // from the context of the phone app.
2439 enforceCallPermission();
2440
Jordan Liu1617b712019-07-10 15:06:26 -07002441 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002442 != AppOpsManager.MODE_ALLOWED) {
2443 return;
2444 }
2445
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002446 final long identity = Binder.clearCallingIdentity();
2447 try {
2448 String url = createTelUrl(number);
2449 if (url == null) {
2450 return;
2451 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002452
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002453 boolean isValid = false;
2454 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2455 if (slist != null) {
2456 for (SubscriptionInfo subInfoRecord : slist) {
2457 if (subInfoRecord.getSubscriptionId() == subId) {
2458 isValid = true;
2459 break;
2460 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002461 }
Wink Saville08874612014-08-31 19:19:58 -07002462 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002463 if (!isValid) {
2464 return;
2465 }
Wink Saville08874612014-08-31 19:19:58 -07002466
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002467 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2468 intent.putExtra(SUBSCRIPTION_KEY, subId);
2469 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2470 mApp.startActivity(intent);
2471 } finally {
2472 Binder.restoreCallingIdentity(identity);
2473 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002474 }
2475
Wink Savilleb564aae2014-10-23 10:18:09 -07002476 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002477 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002478 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2479 }
2480
Wink Savilleb564aae2014-10-23 10:18:09 -07002481 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002482 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002483 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2484 }
2485
Wink Savilleb564aae2014-10-23 10:18:09 -07002486 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002487 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002488
2489 final long identity = Binder.clearCallingIdentity();
2490 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002491 Phone phone = getPhone(subId);
2492 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002493 checkSimPin.start();
2494 return checkSimPin.unlockSim(null, pin);
2495 } finally {
2496 Binder.restoreCallingIdentity(identity);
2497 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002498 }
2499
Wink Savilleb564aae2014-10-23 10:18:09 -07002500 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002501 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002502
2503 final long identity = Binder.clearCallingIdentity();
2504 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002505 Phone phone = getPhone(subId);
2506 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002507 checkSimPuk.start();
2508 return checkSimPuk.unlockSim(puk, pin);
2509 } finally {
2510 Binder.restoreCallingIdentity(identity);
2511 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002512 }
2513
2514 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002515 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002516 * a synchronous one.
2517 */
2518 private static class UnlockSim extends Thread {
2519
2520 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002521 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002522
2523 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002524 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2525 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002526
2527 // For replies from SimCard interface
2528 private Handler mHandler;
2529
2530 // For async handler to identify request type
2531 private static final int SUPPLY_PIN_COMPLETE = 100;
2532
Michele Berionne5e411512020-11-13 02:36:59 +00002533 UnlockSim(int phoneId, IccCard simCard) {
2534 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002535 mSimCard = simCard;
2536 }
2537
2538 @Override
2539 public void run() {
2540 Looper.prepare();
2541 synchronized (UnlockSim.this) {
2542 mHandler = new Handler() {
2543 @Override
2544 public void handleMessage(Message msg) {
2545 AsyncResult ar = (AsyncResult) msg.obj;
2546 switch (msg.what) {
2547 case SUPPLY_PIN_COMPLETE:
2548 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2549 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002550 mRetryCount = msg.arg1;
2551 if (ar.exception != null) {
2552 if (ar.exception instanceof CommandException &&
2553 ((CommandException)(ar.exception)).getCommandError()
2554 == CommandException.Error.PASSWORD_INCORRECT) {
2555 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002556 } //When UiccCardApp dispose,handle message and return exception
2557 else if (ar.exception instanceof CommandException &&
2558 ((CommandException) (ar.exception)).getCommandError()
2559 == CommandException.Error.ABORTED) {
2560 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002561 } else {
2562 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2563 }
2564 } else {
2565 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2566 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002567 mDone = true;
2568 UnlockSim.this.notifyAll();
2569 }
2570 break;
2571 }
2572 }
2573 };
2574 UnlockSim.this.notifyAll();
2575 }
2576 Looper.loop();
2577 }
2578
2579 /*
2580 * Use PIN or PUK to unlock SIM card
2581 *
2582 * If PUK is null, unlock SIM card with PIN
2583 *
2584 * If PUK is not null, unlock SIM card with PUK and set PIN code
2585 */
Wink Saville9de0f752013-10-22 19:04:03 -07002586 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002587
2588 while (mHandler == null) {
2589 try {
2590 wait();
2591 } catch (InterruptedException e) {
2592 Thread.currentThread().interrupt();
2593 }
2594 }
2595 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2596
2597 if (puk == null) {
2598 mSimCard.supplyPin(pin, callback);
2599 } else {
2600 mSimCard.supplyPuk(puk, pin, callback);
2601 }
2602
2603 while (!mDone) {
2604 try {
2605 Log.d(LOG_TAG, "wait for done");
2606 wait();
2607 } catch (InterruptedException e) {
2608 // Restore the interrupted status
2609 Thread.currentThread().interrupt();
2610 }
2611 }
2612 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002613 int[] resultArray = new int[2];
2614 resultArray[0] = mResult;
2615 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002616
2617 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivackbb777522021-10-06 20:53:09 +00002618 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002619 }
2620
Wink Saville9de0f752013-10-22 19:04:03 -07002621 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002622 }
2623 }
2624
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002625 /**
2626 * This method has been removed due to privacy and stability concerns.
2627 */
2628 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002629 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002630 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2631 return;
Wink Saville36469e72014-06-11 15:17:00 -07002632 }
2633
Nathan Harold1f889d82020-06-04 17:05:26 -07002634 @Override
2635 public void updateServiceLocationWithPackageName(String callingPackage) {
2636 mApp.getSystemService(AppOpsManager.class)
2637 .checkPackage(Binder.getCallingUid(), callingPackage);
2638
Nathan Haroldf096d982020-11-18 17:18:06 -08002639 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002640 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2641 // Callers targeting S have no business invoking this method.
2642 return;
2643 }
2644
2645 LocationAccessPolicy.LocationPermissionResult locationResult =
2646 LocationAccessPolicy.checkLocationPermission(mApp,
2647 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2648 .setCallingPackage(callingPackage)
2649 .setCallingFeatureId(null)
2650 .setCallingPid(Binder.getCallingPid())
2651 .setCallingUid(Binder.getCallingUid())
2652 .setMethod("updateServiceLocation")
2653 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2654 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2655 .build());
2656 // Apps that lack location permission have no business calling this method;
2657 // however, because no permission was declared in the public API, denials must
2658 // all be "soft".
2659 switch (locationResult) {
2660 case DENIED_HARD: /* fall through */
2661 case DENIED_SOFT:
2662 return;
2663 }
2664
2665 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002666 final long identity = Binder.clearCallingIdentity();
2667 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002668 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002669 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002670 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002671 }
2672 } finally {
2673 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002674 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002675 }
2676
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002677 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002678 @Override
2679 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002680 return isRadioOnWithFeature(callingPackage, null);
2681 }
2682
2683
2684 @Override
2685 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2686 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2687 callingFeatureId);
2688 }
2689
2690 @Deprecated
2691 @Override
2692 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2693 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002694 }
2695
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002696 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002697 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2698 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002699 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002700 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002701 return false;
2702 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002703
2704 final long identity = Binder.clearCallingIdentity();
2705 try {
2706 return isRadioOnForSubscriber(subId);
2707 } finally {
2708 Binder.restoreCallingIdentity(identity);
2709 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002710 }
2711
2712 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002713 final long identity = Binder.clearCallingIdentity();
2714 try {
2715 final Phone phone = getPhone(subId);
2716 if (phone != null) {
2717 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2718 } else {
2719 return false;
2720 }
2721 } finally {
2722 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002723 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002724 }
2725
2726 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002727 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002728 }
Wink Saville36469e72014-06-11 15:17:00 -07002729
Wink Savilleb564aae2014-10-23 10:18:09 -07002730 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002731 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002732
2733 final long identity = Binder.clearCallingIdentity();
2734 try {
2735 final Phone phone = getPhone(subId);
2736 if (phone != null) {
2737 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2738 }
2739 } finally {
2740 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002741 }
Wink Saville36469e72014-06-11 15:17:00 -07002742 }
2743
2744 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002745 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002746 }
2747
Wink Savilleb564aae2014-10-23 10:18:09 -07002748 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002749 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002750
2751 final long identity = Binder.clearCallingIdentity();
2752 try {
2753 final Phone phone = getPhone(subId);
2754 if (phone == null) {
2755 return false;
2756 }
2757 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2758 toggleRadioOnOffForSubscriber(subId);
2759 }
2760 return true;
2761 } finally {
2762 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002763 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002764 }
Wink Saville36469e72014-06-11 15:17:00 -07002765
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002766 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002767 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002768 /*
2769 * If any of the Radios are available, it will need to be
2770 * shutdown. So return true if any Radio is available.
2771 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002772 final long identity = Binder.clearCallingIdentity();
2773 try {
2774 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2775 Phone phone = PhoneFactory.getPhone(i);
2776 if (phone != null && phone.isRadioAvailable()) return true;
2777 }
2778 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2779 return false;
2780 } finally {
2781 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002782 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002783 }
2784
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002785 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002786 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002787 enforceModifyPermission();
2788
2789 final long identity = Binder.clearCallingIdentity();
2790 try {
2791 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2792 logv("Shutting down Phone " + i);
2793 shutdownRadioUsingPhoneId(i);
2794 }
2795 } finally {
2796 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002797 }
2798 }
2799
2800 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002801 Phone phone = PhoneFactory.getPhone(phoneId);
2802 if (phone != null && phone.isRadioAvailable()) {
2803 phone.shutdownRadio();
2804 }
2805 }
2806
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002807 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002808 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002809
2810 final long identity = Binder.clearCallingIdentity();
2811 try {
2812 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2813 if (defaultPhone != null) {
2814 defaultPhone.setRadioPower(turnOn);
2815 return true;
2816 } else {
2817 loge("There's no default phone.");
2818 return false;
2819 }
2820 } finally {
2821 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002822 }
Wink Saville36469e72014-06-11 15:17:00 -07002823 }
2824
Wink Savilleb564aae2014-10-23 10:18:09 -07002825 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002826 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002827
2828 final long identity = Binder.clearCallingIdentity();
2829 try {
2830 final Phone phone = getPhone(subId);
2831 if (phone != null) {
2832 phone.setRadioPower(turnOn);
2833 return true;
2834 } else {
2835 return false;
2836 }
2837 } finally {
2838 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002839 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002840 }
2841
Wink Saville36469e72014-06-11 15:17:00 -07002842 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002843 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002844 public boolean enableDataConnectivity() {
2845 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002846
2847 final long identity = Binder.clearCallingIdentity();
2848 try {
2849 int subId = mSubscriptionController.getDefaultDataSubId();
2850 final Phone phone = getPhone(subId);
2851 if (phone != null) {
Jack Yu6bc9c8b2021-12-17 23:14:15 -08002852 if (phone.isUsingNewDataStack()) {
2853 phone.getDataSettingsManager().setDataEnabled(
2854 TelephonyManager.DATA_ENABLED_REASON_USER, true);
2855 } else {
2856 phone.getDataEnabledSettings().setDataEnabled(
2857 TelephonyManager.DATA_ENABLED_REASON_USER, true);
2858 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002859 return true;
2860 } else {
2861 return false;
2862 }
2863 } finally {
2864 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002865 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002866 }
2867
Wink Saville36469e72014-06-11 15:17:00 -07002868 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002869 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002870 public boolean disableDataConnectivity() {
2871 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002872
2873 final long identity = Binder.clearCallingIdentity();
2874 try {
2875 int subId = mSubscriptionController.getDefaultDataSubId();
2876 final Phone phone = getPhone(subId);
2877 if (phone != null) {
Jack Yu6bc9c8b2021-12-17 23:14:15 -08002878 if (phone.isUsingNewDataStack()) {
2879 phone.getDataSettingsManager().setDataEnabled(
2880 TelephonyManager.DATA_ENABLED_REASON_USER, false);
2881 } else {
2882 phone.getDataEnabledSettings().setDataEnabled(
2883 TelephonyManager.DATA_ENABLED_REASON_USER, false);
2884 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002885 return true;
2886 } else {
2887 return false;
2888 }
2889 } finally {
2890 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002891 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002892 }
2893
Sanket Padawe356d7632015-06-22 14:03:32 -07002894 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002895 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002896 final long identity = Binder.clearCallingIdentity();
2897 try {
2898 final Phone phone = getPhone(subId);
2899 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002900 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002901 } else {
2902 return false;
2903 }
2904 } finally {
2905 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002906 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002907 }
2908
2909 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002910 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002911 }
2912
pkanwarae03a6b2016-11-06 20:37:09 -08002913 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002914 enforceCallPermission();
2915
2916 final long identity = Binder.clearCallingIdentity();
2917 try {
2918 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2919 return;
2920 }
2921 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2922 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2923 } finally {
2924 Binder.restoreCallingIdentity(identity);
2925 }
pkanwar32d516d2016-10-14 19:37:38 -07002926 };
2927
Wink Savilleb564aae2014-10-23 10:18:09 -07002928 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002929 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002930
2931 final long identity = Binder.clearCallingIdentity();
2932 try {
2933 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2934 return false;
2935 }
2936 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2937 } finally {
2938 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002939 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002940 }
2941
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002942 /**
2943 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2944 * tag on getCallState Binder call.
2945 */
2946 @Deprecated
2947 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002948 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002949 if (CompatChanges.isChangeEnabled(
2950 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2951 Binder.getCallingUid())) {
2952 // Do not allow this API to be called on API version 31+, it should only be
2953 // called on old apps using this Binder call directly.
2954 throw new SecurityException("This method can only be used for applications "
2955 + "targeting API version 30 or less.");
2956 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002957 final long identity = Binder.clearCallingIdentity();
2958 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002959 Phone phone = getPhone(getDefaultSubscription());
2960 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2961 PhoneConstantConversions.convertCallState(phone.getState());
2962 } finally {
2963 Binder.restoreCallingIdentity(identity);
2964 }
2965 }
2966
2967 @Override
2968 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2969 if (CompatChanges.isChangeEnabled(
2970 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2971 Binder.getCallingUid())) {
2972 // Check READ_PHONE_STATE for API version 31+
2973 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2974 featureId, "getCallStateForSubscription")) {
2975 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2976 + "targeting API level 31+.");
2977 }
2978 }
2979 final long identity = Binder.clearCallingIdentity();
2980 try {
2981 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002982 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2983 PhoneConstantConversions.convertCallState(phone.getState());
2984 } finally {
2985 Binder.restoreCallingIdentity(identity);
2986 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002987 }
2988
Sanket Padawe356d7632015-06-22 14:03:32 -07002989 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002990 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002991 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2992 }
2993
2994 @Override
2995 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002996 final long identity = Binder.clearCallingIdentity();
2997 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002998 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002999 if (phone != null) {
Jack Yu4accbd92021-11-29 11:36:17 -08003000 if (phone.isUsingNewDataStack()) {
3001 return phone.getDataNetworkController().getInternetDataNetworkState();
3002 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003003 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
3004 } else {
3005 return PhoneConstantConversions.convertDataState(
3006 PhoneConstants.DataState.DISCONNECTED);
3007 }
3008 } finally {
3009 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003010 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003011 }
3012
Sanket Padawe356d7632015-06-22 14:03:32 -07003013 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003014 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003015 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
3016 }
3017
3018 @Override
3019 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003020 final long identity = Binder.clearCallingIdentity();
3021 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003022 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003023 if (phone != null) {
3024 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
3025 } else {
3026 return TelephonyManager.DATA_ACTIVITY_NONE;
3027 }
3028 } finally {
3029 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003030 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003031 }
3032
3033 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003034 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003035 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003036 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003037
3038 LocationAccessPolicy.LocationPermissionResult locationResult =
3039 LocationAccessPolicy.checkLocationPermission(mApp,
3040 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3041 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003042 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003043 .setCallingPid(Binder.getCallingPid())
3044 .setCallingUid(Binder.getCallingUid())
3045 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003046 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003047 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3048 .build());
3049 switch (locationResult) {
3050 case DENIED_HARD:
3051 throw new SecurityException("Not allowed to access cell location");
3052 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003053 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3054 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003055 }
3056
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003057 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003058 final long identity = Binder.clearCallingIdentity();
3059 try {
3060 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003061 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003062 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003063 } finally {
3064 Binder.restoreCallingIdentity(identity);
3065 }
Svetoslav64fad262015-04-14 14:35:21 -07003066 }
3067
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003068 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003069 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003070 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3071 // registered cell info, so return a NULL country instead.
3072 final long identity = Binder.clearCallingIdentity();
3073 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003074 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3075 // Get default phone in this case.
3076 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3077 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003078 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003079 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003080 if (phone == null) return "";
3081 ServiceStateTracker sst = phone.getServiceStateTracker();
3082 if (sst == null) return "";
3083 LocaleTracker lt = sst.getLocaleTracker();
3084 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003085 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003086 } finally {
3087 Binder.restoreCallingIdentity(identity);
3088 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003089 }
3090
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003091 /**
3092 * This method was removed due to potential issues caused by performing partial
3093 * updates of service state, and lack of a credible use case.
3094 *
3095 * This has the ability to break the telephony implementation by disabling notification of
3096 * changes in device connectivity. DO NOT USE THIS!
3097 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003098 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003099 public void enableLocationUpdates() {
3100 mApp.enforceCallingOrSelfPermission(
3101 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003102 }
3103
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003104 /**
3105 * This method was removed due to potential issues caused by performing partial
3106 * updates of service state, and lack of a credible use case.
3107 *
3108 * This has the ability to break the telephony implementation by disabling notification of
3109 * changes in device connectivity. DO NOT USE THIS!
3110 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003111 @Override
3112 public void disableLocationUpdates() {
3113 mApp.enforceCallingOrSelfPermission(
3114 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003115 }
3116
3117 @Override
3118 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003119 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3120 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003121 try {
3122 mApp.getSystemService(AppOpsManager.class)
3123 .checkPackage(Binder.getCallingUid(), callingPackage);
3124 } catch (SecurityException e) {
3125 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3126 throw e;
3127 }
3128
Nathan Haroldf096d982020-11-18 17:18:06 -08003129 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003130 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3131 throw new SecurityException(
3132 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3133 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003134
Jordan Liu1617b712019-07-10 15:06:26 -07003135 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003136 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3137 return null;
3138 }
Svetoslav64fad262015-04-14 14:35:21 -07003139
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003140 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003141
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003142 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003143 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003144
Nathan Haroldf180aac2018-06-01 18:43:55 -07003145 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3146 for (CellInfo ci : info) {
3147 if (ci instanceof CellInfoGsm) {
3148 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3149 } else if (ci instanceof CellInfoWcdma) {
3150 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3151 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003152 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003153 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003154 }
3155
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003156 private List<CellInfo> getCachedCellInfo() {
3157 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3158 for (Phone phone : PhoneFactory.getPhones()) {
3159 List<CellInfo> info = phone.getAllCellInfo();
3160 if (info != null) cellInfos.addAll(info);
3161 }
3162 return cellInfos;
3163 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003164
3165 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003166 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003167 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003168 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003169
3170 LocationAccessPolicy.LocationPermissionResult locationResult =
3171 LocationAccessPolicy.checkLocationPermission(mApp,
3172 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3173 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003174 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003175 .setCallingPid(Binder.getCallingPid())
3176 .setCallingUid(Binder.getCallingUid())
3177 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003178 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003179 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3180 .build());
3181 switch (locationResult) {
3182 case DENIED_HARD:
3183 throw new SecurityException("Not allowed to access cell info");
3184 case DENIED_SOFT:
3185 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003186 }
3187
Nathan Haroldf096d982020-11-18 17:18:06 -08003188 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003189 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3190 return getCachedCellInfo();
3191 }
3192
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003193 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003194 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003195 final long identity = Binder.clearCallingIdentity();
3196 try {
3197 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3198 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003199 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003200 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003201 if (info != null) cellInfos.addAll(info);
3202 }
3203 return cellInfos;
3204 } finally {
3205 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003206 }
3207 }
3208
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003209 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003210 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3211 String callingFeatureId) {
3212 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3213 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003214 }
3215
3216 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003217 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3218 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003219 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003220 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003221 }
3222
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003223 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3224 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003225 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003226 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003227
3228 LocationAccessPolicy.LocationPermissionResult locationResult =
3229 LocationAccessPolicy.checkLocationPermission(mApp,
3230 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3231 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003232 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003233 .setCallingPid(Binder.getCallingPid())
3234 .setCallingUid(Binder.getCallingUid())
3235 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003236 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3237 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003238 .build());
3239 switch (locationResult) {
3240 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003241 if (TelephonyPermissions
3242 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003243 // Safetynet logging for b/154934934
3244 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3245 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003246 throw new SecurityException("Not allowed to access cell info");
3247 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003248 if (TelephonyPermissions
3249 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003250 // Safetynet logging for b/154934934
3251 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3252 }
Nathan Harold5320c422019-05-09 10:26:08 -07003253 try {
3254 cb.onCellInfo(new ArrayList<CellInfo>());
3255 } catch (RemoteException re) {
3256 // Drop without consequences
3257 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003258 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003259 }
3260
Nathan Harolda939a962019-05-09 10:13:47 -07003261
3262 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003263 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3264
3265 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3266 }
3267
3268 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003269 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003270 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003271 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003272
3273 final long identity = Binder.clearCallingIdentity();
3274 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003275 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003276 } finally {
3277 Binder.restoreCallingIdentity(identity);
3278 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003279 }
3280
Shishir Agrawala9f32182016-04-12 12:00:16 -07003281 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003282 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003283 Phone phone = PhoneFactory.getPhone(slotIndex);
3284 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003285 return null;
3286 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003287 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003288 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003289 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003290 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003291 return null;
3292 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003293
3294 final long identity = Binder.clearCallingIdentity();
3295 try {
3296 return phone.getImei();
3297 } finally {
3298 Binder.restoreCallingIdentity(identity);
3299 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003300 }
3301
3302 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003303 public String getTypeAllocationCodeForSlot(int slotIndex) {
3304 Phone phone = PhoneFactory.getPhone(slotIndex);
3305 String tac = null;
3306 if (phone != null) {
3307 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003308 try {
3309 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3310 } catch (IndexOutOfBoundsException e) {
3311 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3312 return null;
3313 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003314 }
3315 return tac;
3316 }
3317
3318 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003319 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003320 try {
3321 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3322 } catch (SecurityException se) {
3323 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3324 throw new SecurityException("Package " + callingPackage + " does not belong to "
3325 + Binder.getCallingUid());
3326 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003327 Phone phone = PhoneFactory.getPhone(slotIndex);
3328 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003329 return null;
3330 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003331
Jeff Davidson913390f2018-02-23 17:11:49 -08003332 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003333 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003334 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003335 return null;
3336 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003337
3338 final long identity = Binder.clearCallingIdentity();
3339 try {
3340 return phone.getMeid();
3341 } finally {
3342 Binder.restoreCallingIdentity(identity);
3343 }
Jack Yu2af8d712017-03-15 17:14:14 -07003344 }
3345
3346 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003347 public String getManufacturerCodeForSlot(int slotIndex) {
3348 Phone phone = PhoneFactory.getPhone(slotIndex);
3349 String manufacturerCode = null;
3350 if (phone != null) {
3351 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003352 try {
3353 manufacturerCode =
3354 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3355 } catch (IndexOutOfBoundsException e) {
3356 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3357 return null;
3358 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003359 }
3360 return manufacturerCode;
3361 }
3362
3363 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003364 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3365 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003366 Phone phone = PhoneFactory.getPhone(slotIndex);
3367 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003368 return null;
3369 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003370 int subId = phone.getSubId();
3371 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003372 mApp, subId, callingPackage, callingFeatureId,
3373 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003374 return null;
3375 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003376
3377 final long identity = Binder.clearCallingIdentity();
3378 try {
3379 return phone.getDeviceSvn();
3380 } finally {
3381 Binder.restoreCallingIdentity(identity);
3382 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003383 }
3384
fionaxu43304da2017-11-27 22:51:16 -08003385 @Override
3386 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003387 final long identity = Binder.clearCallingIdentity();
3388 try {
3389 final Phone phone = getPhone(subId);
3390 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3391 } finally {
3392 Binder.restoreCallingIdentity(identity);
3393 }
fionaxu43304da2017-11-27 22:51:16 -08003394 }
3395
3396 @Override
3397 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003398 final long identity = Binder.clearCallingIdentity();
3399 try {
3400 final Phone phone = getPhone(subId);
3401 return phone == null ? null : phone.getCarrierName();
3402 } finally {
3403 Binder.restoreCallingIdentity(identity);
3404 }
fionaxu43304da2017-11-27 22:51:16 -08003405 }
3406
calvinpanffe225e2018-11-01 19:43:06 +08003407 @Override
chen xu0026ca62019-03-06 15:28:50 -08003408 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003409 final long identity = Binder.clearCallingIdentity();
3410 try {
3411 final Phone phone = getPhone(subId);
3412 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003413 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003414 } finally {
3415 Binder.restoreCallingIdentity(identity);
3416 }
3417 }
3418
3419 @Override
chen xu0026ca62019-03-06 15:28:50 -08003420 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003421 final long identity = Binder.clearCallingIdentity();
3422 try {
3423 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003424 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003425 } finally {
3426 Binder.restoreCallingIdentity(identity);
3427 }
3428 }
3429
chen xu651eec72018-11-11 19:03:44 -08003430 @Override
chen xu864e11c2018-12-06 22:10:03 -08003431 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3432 if (!isSubscriptionMccMnc) {
3433 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3434 }
chen xu651eec72018-11-11 19:03:44 -08003435 final Phone phone = PhoneFactory.getPhone(slotIndex);
3436 if (phone == null) {
3437 return TelephonyManager.UNKNOWN_CARRIER_ID;
3438 }
3439 final long identity = Binder.clearCallingIdentity();
3440 try {
3441 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3442 } finally {
3443 Binder.restoreCallingIdentity(identity);
3444 }
3445 }
3446
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003447 //
3448 // Internal helper methods.
3449 //
3450
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003451 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003452 * Make sure the caller is the calling package itself
3453 *
3454 * @throws SecurityException if the caller is not the calling package
3455 */
3456 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3457 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003458 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3459 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003460 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003461 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003462 } catch (PackageManager.NameNotFoundException e) {
3463 // packageUid is -1
3464 }
3465 if (packageUid != callingUid) {
3466 throw new SecurityException(message + ": Package " + callingPackage
3467 + " does not belong to " + callingUid);
3468 }
3469 }
3470
3471 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003472 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3473 *
3474 * @throws SecurityException if the caller does not have the required permission
3475 */
3476 private void enforceModifyPermission() {
3477 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3478 }
3479
Shuo Qian3b6ee772019-11-13 17:43:31 -08003480 private void enforceActiveEmergencySessionPermission() {
3481 mApp.enforceCallingOrSelfPermission(
3482 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3483 }
3484
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003485 /**
3486 * Make sure the caller has the CALL_PHONE permission.
3487 *
3488 * @throws SecurityException if the caller does not have the required permission
3489 */
3490 private void enforceCallPermission() {
3491 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3492 }
3493
paulhu5a773602019-08-23 19:17:33 +08003494 private void enforceSettingsPermission() {
3495 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003496 }
3497
Michele Berionne5e411512020-11-13 02:36:59 +00003498 private void enforceRebootPermission() {
3499 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3500 }
3501
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003502 private String createTelUrl(String number) {
3503 if (TextUtils.isEmpty(number)) {
3504 return null;
3505 }
3506
Jake Hambye994d462014-02-03 13:10:13 -08003507 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003508 }
3509
Ihab Awadf9e92732013-12-05 18:02:52 -08003510 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003511 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3512 }
3513
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003514 private static void logv(String msg) {
3515 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3516 }
3517
Ihab Awadf9e92732013-12-05 18:02:52 -08003518 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003519 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3520 }
3521
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003522 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003523 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003524 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003525 }
3526
Sanket Padawe356d7632015-06-22 14:03:32 -07003527 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003528 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003529 final long identity = Binder.clearCallingIdentity();
3530 try {
3531 final Phone phone = PhoneFactory.getPhone(slotIndex);
3532 if (phone == null) {
3533 return PhoneConstants.PHONE_TYPE_NONE;
3534 } else {
3535 return phone.getPhoneType();
3536 }
3537 } finally {
3538 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003539 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003540 }
3541
3542 /**
3543 * Returns the CDMA ERI icon index to display
3544 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003545 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003546 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3547 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3548 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003549 }
3550
Sanket Padawe356d7632015-06-22 14:03:32 -07003551 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003552 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3553 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003554 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003555 mApp, subId, callingPackage, callingFeatureId,
3556 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003557 return -1;
3558 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003559
3560 final long identity = Binder.clearCallingIdentity();
3561 try {
3562 final Phone phone = getPhone(subId);
3563 if (phone != null) {
3564 return phone.getCdmaEriIconIndex();
3565 } else {
3566 return -1;
3567 }
3568 } finally {
3569 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003570 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003571 }
3572
3573 /**
3574 * Returns the CDMA ERI icon mode,
3575 * 0 - ON
3576 * 1 - FLASHING
3577 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003578 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003579 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3580 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3581 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003582 }
3583
Sanket Padawe356d7632015-06-22 14:03:32 -07003584 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003585 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3586 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003587 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003588 mApp, subId, callingPackage, callingFeatureId,
3589 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003590 return -1;
3591 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003592
3593 final long identity = Binder.clearCallingIdentity();
3594 try {
3595 final Phone phone = getPhone(subId);
3596 if (phone != null) {
3597 return phone.getCdmaEriIconMode();
3598 } else {
3599 return -1;
3600 }
3601 } finally {
3602 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003603 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003604 }
3605
3606 /**
3607 * Returns the CDMA ERI text,
3608 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003609 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003610 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3611 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3612 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003613 }
3614
Sanket Padawe356d7632015-06-22 14:03:32 -07003615 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003616 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3617 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003618 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003619 mApp, subId, callingPackage, callingFeatureId,
3620 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003621 return null;
3622 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003623
3624 final long identity = Binder.clearCallingIdentity();
3625 try {
3626 final Phone phone = getPhone(subId);
3627 if (phone != null) {
3628 return phone.getCdmaEriText();
3629 } else {
3630 return null;
3631 }
3632 } finally {
3633 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003634 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003635 }
3636
3637 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003638 * Returns the CDMA MDN.
3639 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003640 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003641 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003642 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3643 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003644
3645 final long identity = Binder.clearCallingIdentity();
3646 try {
3647 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003648 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003649 return phone.getLine1Number();
3650 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003651 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003652 return null;
3653 }
3654 } finally {
3655 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003656 }
3657 }
3658
3659 /**
3660 * Returns the CDMA MIN.
3661 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003662 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003663 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003664 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3665 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003666
3667 final long identity = Binder.clearCallingIdentity();
3668 try {
3669 final Phone phone = getPhone(subId);
3670 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3671 return phone.getCdmaMin();
3672 } else {
3673 return null;
3674 }
3675 } finally {
3676 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003677 }
3678 }
3679
Hall Liud892bec2018-11-30 14:51:45 -08003680 @Override
3681 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3682 INumberVerificationCallback callback, String callingPackage) {
3683 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3684 != PERMISSION_GRANTED) {
3685 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3686 }
3687 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3688
3689 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3690 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003691 throw new SecurityException("Calling package must be configured in the device config: "
3692 + "calling package: " + callingPackage
3693 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003694 }
3695
3696 if (range == null) {
3697 throw new NullPointerException("Range must be non-null");
3698 }
3699
3700 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003701 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003702
3703 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3704 }
3705
Junda Liuca05d5d2014-08-14 22:36:34 -07003706 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003707 * Returns true if CDMA provisioning needs to run.
3708 */
3709 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003710 final long identity = Binder.clearCallingIdentity();
3711 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003712 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003713 } finally {
3714 Binder.restoreCallingIdentity(identity);
3715 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003716 }
3717
3718 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003719 * Sets the voice mail number of a given subId.
3720 */
3721 @Override
3722 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003723 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3724 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003725
3726 final long identity = Binder.clearCallingIdentity();
3727 try {
3728 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3729 new Pair<String, String>(alphaTag, number), new Integer(subId));
3730 return success;
3731 } finally {
3732 Binder.restoreCallingIdentity(identity);
3733 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003734 }
3735
Ta-wei Yen87c49842016-05-13 21:19:52 -07003736 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003737 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3738 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003739 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3740 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003741 if (!TextUtils.equals(callingPackage, systemDialer)) {
3742 throw new SecurityException("caller must be system dialer");
3743 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003744
3745 final long identity = Binder.clearCallingIdentity();
3746 try {
3747 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3748 if (phoneAccountHandle == null) {
3749 return null;
3750 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003751 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003752 } finally {
3753 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003754 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003755 }
3756
3757 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003758 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3759 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003760 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003761 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003762 mApp, subId, callingPackage, callingFeatureId,
3763 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003764 return null;
3765 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003766
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003767 final long identity = Binder.clearCallingIdentity();
3768 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003769 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003770 } finally {
3771 Binder.restoreCallingIdentity(identity);
3772 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003773 }
3774
3775 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003776 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3777 VisualVoicemailSmsFilterSettings settings) {
3778 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003779
3780 final long identity = Binder.clearCallingIdentity();
3781 try {
3782 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003783 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003784 } finally {
3785 Binder.restoreCallingIdentity(identity);
3786 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003787 }
3788
3789 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003790 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3791 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003792
3793 final long identity = Binder.clearCallingIdentity();
3794 try {
3795 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003796 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003797 } finally {
3798 Binder.restoreCallingIdentity(identity);
3799 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003800 }
3801
3802 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003803 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3804 String callingPackage, int subId) {
3805 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003806
3807 final long identity = Binder.clearCallingIdentity();
3808 try {
3809 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003810 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003811 } finally {
3812 Binder.restoreCallingIdentity(identity);
3813 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003814 }
3815
3816 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003817 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003818 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003819
3820 final long identity = Binder.clearCallingIdentity();
3821 try {
3822 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003823 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003824 } finally {
3825 Binder.restoreCallingIdentity(identity);
3826 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003827 }
3828
3829 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003830 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3831 String callingAttributionTag, int subId, String number, int port, String text,
3832 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003833 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003834 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003835 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003836 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003837 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3838 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003839 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003840
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003841 /**
fionaxu0152e512016-11-14 13:36:14 -08003842 * Sets the voice activation state of a given subId.
3843 */
3844 @Override
3845 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003846 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3847 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003848
3849 final long identity = Binder.clearCallingIdentity();
3850 try {
3851 final Phone phone = getPhone(subId);
3852 if (phone != null) {
3853 phone.setVoiceActivationState(activationState);
3854 } else {
3855 loge("setVoiceActivationState fails with invalid subId: " + subId);
3856 }
3857 } finally {
3858 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003859 }
3860 }
3861
3862 /**
3863 * Sets the data activation state of a given subId.
3864 */
3865 @Override
3866 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003867 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3868 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003869
3870 final long identity = Binder.clearCallingIdentity();
3871 try {
3872 final Phone phone = getPhone(subId);
3873 if (phone != null) {
3874 phone.setDataActivationState(activationState);
3875 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003876 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003877 }
3878 } finally {
3879 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003880 }
3881 }
3882
3883 /**
3884 * Returns the voice activation state of a given subId.
3885 */
3886 @Override
3887 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003888 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003889
fionaxu0152e512016-11-14 13:36:14 -08003890 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003891 final long identity = Binder.clearCallingIdentity();
3892 try {
3893 if (phone != null) {
3894 return phone.getVoiceActivationState();
3895 } else {
3896 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3897 }
3898 } finally {
3899 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003900 }
3901 }
3902
3903 /**
3904 * Returns the data activation state of a given subId.
3905 */
3906 @Override
3907 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003908 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003909
fionaxu0152e512016-11-14 13:36:14 -08003910 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003911 final long identity = Binder.clearCallingIdentity();
3912 try {
3913 if (phone != null) {
3914 return phone.getDataActivationState();
3915 } else {
3916 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3917 }
3918 } finally {
3919 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003920 }
3921 }
3922
3923 /**
Wink Saville36469e72014-06-11 15:17:00 -07003924 * Returns the unread count of voicemails for a subId
3925 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003926 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003927 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3928 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003929 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003930 mApp, subId, callingPackage, callingFeatureId,
3931 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003932 return 0;
3933 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003934 final long identity = Binder.clearCallingIdentity();
3935 try {
3936 final Phone phone = getPhone(subId);
3937 if (phone != null) {
3938 return phone.getVoiceMessageCount();
3939 } else {
3940 return 0;
3941 }
3942 } finally {
3943 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003944 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003945 }
3946
3947 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003948 * returns true, if the device is in a state where both voice and data
3949 * are supported simultaneously. This can change based on location or network condition.
3950 */
3951 @Override
3952 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003953 final long identity = Binder.clearCallingIdentity();
3954 try {
3955 final Phone phone = getPhone(subId);
3956 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3957 } finally {
3958 Binder.restoreCallingIdentity(identity);
3959 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003960 }
3961
3962 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003963 * Send the dialer code if called from the current default dialer or the caller has
3964 * carrier privilege.
3965 * @param inputCode The dialer code to send
3966 */
3967 @Override
3968 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003969 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003970 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003971 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3972 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003973 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003974 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003975 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003976 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003977
3978 final long identity = Binder.clearCallingIdentity();
3979 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003980 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003981 } finally {
3982 Binder.restoreCallingIdentity(identity);
3983 }
fionaxu235cc5e2017-03-06 22:25:57 -08003984 }
3985
Pengquan Menga1bb6272018-09-06 09:59:22 -07003986 @Override
3987 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003988 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003989 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003990 mApp, subId, "getNetworkSelectionMode");
3991 final long identity = Binder.clearCallingIdentity();
3992 try {
3993 if (!isActiveSubscription(subId)) {
3994 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3995 }
3996 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3997 } finally {
3998 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003999 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004000 }
4001
Brad Ebinger35c841c2018-10-01 10:40:55 -07004002 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004003 public boolean isInEmergencySmsMode() {
4004 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4005 final long identity = Binder.clearCallingIdentity();
4006 try {
4007 for (Phone phone : PhoneFactory.getPhones()) {
4008 if (phone.isInEmergencySmsMode()) {
4009 return true;
4010 }
4011 }
4012 } finally {
4013 Binder.restoreCallingIdentity(identity);
4014 }
4015 return false;
4016 }
4017
shilu366312e2019-12-17 09:28:10 -08004018 /**
4019 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4020 * @param subId The subscription to use to check the configuration.
4021 * @param c The callback that will be used to send the result.
4022 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004023 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004024 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4025 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004026 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004027 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08004028
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004029 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4030 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4031 "IMS not available on device.");
4032 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004033 final long token = Binder.clearCallingIdentity();
4034 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004035 int slotId = getSlotIndexOrException(subId);
4036 verifyImsMmTelConfiguredOrThrow(slotId);
4037 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004038 } catch (ImsException e) {
4039 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004040 } finally {
4041 Binder.restoreCallingIdentity(token);
4042 }
4043 }
4044
shilu366312e2019-12-17 09:28:10 -08004045 /**
4046 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4047 * @param subId The subscription to use to check the configuration.
4048 * @param c The callback that will be used to send the result.
4049 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004050 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004051 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004052 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004053 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004054 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4055 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4056 }
Meng Wangafbc5852019-09-19 17:37:13 -07004057 final long token = Binder.clearCallingIdentity();
4058 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004059 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4060 .removeRegistrationCallbackForSubscription(c, subId);
4061 } catch (ImsException e) {
4062 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4063 + "is inactive, ignoring unregister.");
4064 // If the subscription is no longer active, just return, since the callback
4065 // will already have been removed internally.
4066 } finally {
4067 Binder.restoreCallingIdentity(token);
4068 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004069 }
4070
Brad Ebingera34a6c22019-10-22 17:36:18 -07004071 /**
4072 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4073 */
4074 @Override
4075 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4076 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4077 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4078 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4079 "IMS not available on device.");
4080 }
4081 final long token = Binder.clearCallingIdentity();
4082 try {
4083 Phone phone = getPhone(subId);
4084 if (phone == null) {
4085 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4086 + subId + "'");
4087 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4088 }
4089 phone.getImsRegistrationState(regState -> {
4090 try {
4091 consumer.accept((regState == null)
4092 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4093 } catch (RemoteException e) {
4094 // Ignore if the remote process is no longer available to call back.
4095 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4096 }
4097 });
4098 } finally {
4099 Binder.restoreCallingIdentity(token);
4100 }
4101 }
4102
4103 /**
4104 * Get the transport type for the IMS service registration state.
4105 */
4106 @Override
4107 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004108 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004109 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004110 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4111 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4112 "IMS not available on device.");
4113 }
4114 final long token = Binder.clearCallingIdentity();
4115 try {
4116 Phone phone = getPhone(subId);
4117 if (phone == null) {
4118 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4119 + subId + "'");
4120 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4121 }
4122 phone.getImsRegistrationTech(regTech -> {
4123 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4124 int regTechConverted = (regTech == null)
4125 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4126 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4127 regTechConverted);
4128 try {
4129 consumer.accept(regTechConverted);
4130 } catch (RemoteException e) {
4131 // Ignore if the remote process is no longer available to call back.
4132 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4133 }
4134 });
4135 } finally {
4136 Binder.restoreCallingIdentity(token);
4137 }
4138 }
4139
shilu366312e2019-12-17 09:28:10 -08004140 /**
4141 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4142 * @param subId The subscription to use to check the configuration.
4143 * @param c The callback that will be used to send the result.
4144 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004145 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004146 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4147 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004148 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004149 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004150 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4151 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4152 "IMS not available on device.");
4153 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004154 final long token = Binder.clearCallingIdentity();
4155 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004156 int slotId = getSlotIndexOrException(subId);
4157 verifyImsMmTelConfiguredOrThrow(slotId);
4158 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004159 } catch (ImsException e) {
4160 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004161 } finally {
4162 Binder.restoreCallingIdentity(token);
4163 }
4164 }
4165
shilu366312e2019-12-17 09:28:10 -08004166 /**
4167 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4168 * @param subId The subscription to use to check the configuration.
4169 * @param c The callback that will be used to send the result.
4170 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004171 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004172 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004173 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004174 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004175 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4176 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4177 }
Meng Wangafbc5852019-09-19 17:37:13 -07004178
4179 final long token = Binder.clearCallingIdentity();
4180 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004181 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004182 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004183 } catch (ImsException e) {
4184 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4185 + "is inactive, ignoring unregister.");
4186 // If the subscription is no longer active, just return, since the callback
4187 // will already have been removed internally.
4188 } finally {
4189 Binder.restoreCallingIdentity(token);
4190 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004191 }
4192
4193 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004194 public boolean isCapable(int subId, int capability, int regTech) {
4195 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004196 final long token = Binder.clearCallingIdentity();
4197 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004198 int slotId = getSlotIndexOrException(subId);
4199 verifyImsMmTelConfiguredOrThrow(slotId);
4200 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004201 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004202 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4203 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004204 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004205 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4206 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004207 } finally {
4208 Binder.restoreCallingIdentity(token);
4209 }
4210 }
4211
4212 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004213 public boolean isAvailable(int subId, int capability, int regTech) {
4214 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004215 final long token = Binder.clearCallingIdentity();
4216 try {
4217 Phone phone = getPhone(subId);
4218 if (phone == null) return false;
4219 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004220 } catch (com.android.ims.ImsException e) {
4221 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4222 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004223 } finally {
4224 Binder.restoreCallingIdentity(token);
4225 }
4226 }
4227
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004228 /**
4229 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4230 * subscription.
4231 * @param subId The subscription to use to check the configuration.
4232 * @param callback The callback that will be used to send the result.
4233 * @param capability The MmTelFeature capability that will be used to send the result.
4234 * @param transportType The transport type of the MmTelFeature capability.
4235 */
4236 @Override
4237 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4238 int transportType) {
4239 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4240 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4241 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4242 "IMS not available on device.");
4243 }
4244 final long token = Binder.clearCallingIdentity();
4245 try {
4246 int slotId = getSlotIndex(subId);
4247 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4248 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4249 + subId + "'");
4250 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4251 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004252 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004253 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4254 transportType, aBoolean -> {
4255 try {
4256 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4257 } catch (RemoteException e) {
4258 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4259 + "running. Ignore");
4260 }
4261 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004262 } catch (ImsException e) {
4263 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004264 } finally {
4265 Binder.restoreCallingIdentity(token);
4266 }
4267 }
4268
shilu366312e2019-12-17 09:28:10 -08004269 /**
4270 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4271 * @param subId The subscription to use to check the configuration.
4272 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004273 @Override
4274 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004275 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004276 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004277
Brad Ebinger35c841c2018-10-01 10:40:55 -07004278 final long token = Binder.clearCallingIdentity();
4279 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004280 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004281 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004282 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004283 } catch (ImsException e) {
4284 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004285 } finally {
4286 Binder.restoreCallingIdentity(token);
4287 }
4288 }
4289
4290 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004291 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004292 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004293 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004294 final long identity = Binder.clearCallingIdentity();
4295 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004296 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004297 // This setting doesn't require an active ImsService connection, so do not verify. The
4298 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004299 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
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(identity);
4304 }
4305 }
4306
shilu366312e2019-12-17 09:28:10 -08004307 /**
4308 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4309 * @param subId The subscription to use to check the configuration.
4310 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004311 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004312 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004313 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004314 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004315 final long identity = Binder.clearCallingIdentity();
4316 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004317 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004318 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004319 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004320 } catch (ImsException e) {
4321 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004322 } finally {
4323 Binder.restoreCallingIdentity(identity);
4324 }
4325 }
4326
4327 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004328 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004329 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004330 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004331 final long identity = Binder.clearCallingIdentity();
4332 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004333 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004334 // This setting doesn't require an active ImsService connection, so do not verify. The
4335 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004336 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
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
shilu366312e2019-12-17 09:28:10 -08004344 /**
4345 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4346 * @param subId The subscription to use to check the configuration.
4347 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004348 @Override
4349 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004350 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004351 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004352 final long identity = Binder.clearCallingIdentity();
4353 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004354 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004355 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004356 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004357 } catch (ImsException e) {
4358 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004359 } finally {
4360 Binder.restoreCallingIdentity(identity);
4361 }
4362 }
4363
4364 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004365 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004366 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004367 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004368 final long identity = Binder.clearCallingIdentity();
4369 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004370 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004371 // This setting doesn't require an active ImsService connection, so do not verify. The
4372 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004373 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
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
shilu366312e2019-12-17 09:28:10 -08004381 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004382 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4383 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4384 * @param subId The subscription to use to check the configuration.
4385 */
4386 @Override
4387 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004388 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004389 mApp, subId, "isCrossSimCallingEnabledByUser");
4390 final long identity = Binder.clearCallingIdentity();
4391 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004392 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004393 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004394 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004395 } catch (ImsException e) {
4396 throw new ServiceSpecificException(e.getCode());
4397 } finally {
4398 Binder.restoreCallingIdentity(identity);
4399 }
4400 }
4401
4402 /**
4403 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4404 * Requires MODIFY_PHONE_STATE permission.
4405 * @param subId The subscription to use to check the configuration.
4406 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4407 * false otherwise
4408 */
4409 @Override
4410 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4411 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4412 "setCrossSimCallingEnabled");
4413 final long identity = Binder.clearCallingIdentity();
4414 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004415 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004416 // This setting doesn't require an active ImsService connection, so do not verify. The
4417 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004418 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004419 } catch (ImsException e) {
4420 throw new ServiceSpecificException(e.getCode());
4421 } finally {
4422 Binder.restoreCallingIdentity(identity);
4423 }
4424 }
4425
4426 /**
shilu366312e2019-12-17 09:28:10 -08004427 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4428 * @param subId The subscription to use to check the configuration.
4429 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004430 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004431
Brad Ebinger35c841c2018-10-01 10:40:55 -07004432 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004433 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004434 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004435 final long identity = Binder.clearCallingIdentity();
4436 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004437 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004438 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004439 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004440 } catch (ImsException e) {
4441 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004442 } finally {
4443 Binder.restoreCallingIdentity(identity);
4444 }
4445 }
4446
4447 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004448 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004449 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004450 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004451 final long identity = Binder.clearCallingIdentity();
4452 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004453 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004454 // This setting doesn't require an active ImsService connection, so do not verify. The
4455 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004456 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
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
4465 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4466 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4467 "setVoWiFiNonPersistent");
4468 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 will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004472 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004473 } catch (ImsException e) {
4474 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004475 } finally {
4476 Binder.restoreCallingIdentity(identity);
4477 }
4478 }
4479
shilu366312e2019-12-17 09:28:10 -08004480 /**
4481 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4482 * @param subId The subscription to use to check the configuration.
4483 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004484 @Override
4485 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004486 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004487 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004488 final long identity = Binder.clearCallingIdentity();
4489 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004490 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004491 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004492 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004493 } catch (ImsException e) {
4494 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004495 } finally {
4496 Binder.restoreCallingIdentity(identity);
4497 }
4498 }
4499
4500 @Override
4501 public void setVoWiFiModeSetting(int subId, int mode) {
4502 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4503 "setVoWiFiModeSetting");
4504 final long identity = Binder.clearCallingIdentity();
4505 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004506 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004507 // This setting doesn't require an active ImsService connection, so do not verify. The
4508 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004509 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, 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 int getVoWiFiRoamingModeSetting(int subId) {
4519 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4520 final long identity = Binder.clearCallingIdentity();
4521 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004522 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004523 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004524 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004525 } catch (ImsException e) {
4526 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004527 } finally {
4528 Binder.restoreCallingIdentity(identity);
4529 }
4530 }
4531
4532 @Override
4533 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4534 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4535 "setVoWiFiRoamingModeSetting");
4536 final long identity = Binder.clearCallingIdentity();
4537 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004538 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004539 // This setting doesn't require an active ImsService connection, so do not verify. The
4540 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004541 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, 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 setRttCapabilitySetting(int subId, boolean isEnabled) {
4551 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4552 "setRttCapabilityEnabled");
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).setRttEnabled(isEnabled);
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
shilu366312e2019-12-17 09:28:10 -08004566 /**
4567 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4568 * @param subId The subscription to use to check the configuration.
4569 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004570 @Override
4571 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004572 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004573 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004574 final long identity = Binder.clearCallingIdentity();
4575 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004576 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004577 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004578 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004579 } catch (ImsException e) {
4580 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004581 } finally {
4582 Binder.restoreCallingIdentity(identity);
4583 }
4584 }
4585
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004586 @Override
4587 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4588 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshin2c3e4232021-11-28 07:32:01 +00004589
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004590 final long identity = Binder.clearCallingIdentity();
4591 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004592 if (!isImsAvailableOnDevice()) {
4593 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4594 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004595 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004596 int slotId = getSlotIndexOrException(subId);
4597 verifyImsMmTelConfiguredOrThrow(slotId);
4598 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004599 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004600 } catch (ImsException e) {
4601 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004602 } finally {
4603 Binder.restoreCallingIdentity(identity);
4604 }
4605 }
4606
4607 @Override
4608 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4609 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshin2c3e4232021-11-28 07:32:01 +00004610
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004611 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004612 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4613 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4614 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004615 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004616 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004617 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004618 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004619 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4620 + "is inactive, ignoring unregister.");
4621 // If the subscription is no longer active, just return, since the callback will already
4622 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004623 } finally {
4624 Binder.restoreCallingIdentity(identity);
4625 }
4626 }
4627
joonhunshin2c3e4232021-11-28 07:32:01 +00004628 @Override
4629 public void registerFeatureProvisioningChangedCallback(int subId,
4630 IFeatureProvisioningCallback callback) {
4631 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4632 mApp, subId, "registerFeatureProvisioningChangedCallback");
4633
4634 final long identity = Binder.clearCallingIdentity();
4635 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4636 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4637 }
4638
4639 ImsProvisioningController.getInstance()
4640 .addFeatureProvisioningChangedCallback(subId, callback);
4641
4642 Binder.restoreCallingIdentity(identity);
4643 }
4644
4645 @Override
4646 public void unregisterFeatureProvisioningChangedCallback(int subId,
4647 IFeatureProvisioningCallback callback) {
4648 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4649 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
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 .removeFeatureProvisioningChangedCallback(subId, callback);
4658
4659 Binder.restoreCallingIdentity(identity);
4660 }
allenwtsu99c623b2020-01-03 18:24:23 +08004661
4662 private void checkModifyPhoneStatePermission(int subId, String message) {
4663 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4664 message);
4665 }
4666
4667 private boolean isImsProvisioningRequired(int subId, int capability,
4668 boolean isMmtelCapability) {
4669 Phone phone = getPhone(subId);
4670 if (phone == null) {
4671 loge("phone instance null for subid " + subId);
4672 return false;
4673 }
4674 if (isMmtelCapability) {
4675 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4676 return false;
4677 }
4678 } else {
4679 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4680 return false;
4681 }
4682 }
4683 return true;
4684 }
4685
4686 @Override
joonhunshin2c3e4232021-11-28 07:32:01 +00004687 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004688 boolean isProvisioned) {
4689 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4690
4691 final long identity = Binder.clearCallingIdentity();
4692 try {
joonhunshin2c3e4232021-11-28 07:32:01 +00004693 ImsProvisioningController.getInstance()
4694 .setRcsProvisioningStatusForCapability(subId, capability, tech, isProvisioned);
4695 return;
allenwtsu99c623b2020-01-03 18:24:23 +08004696 } finally {
4697 Binder.restoreCallingIdentity(identity);
4698 }
allenwtsu99c623b2020-01-03 18:24:23 +08004699 }
4700
4701
4702 @Override
joonhunshin2c3e4232021-11-28 07:32:01 +00004703 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4704 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4705 mApp, subId, "getRcsProvisioningStatusForCapability");
4706
allenwtsu99c623b2020-01-03 18:24:23 +08004707 final long identity = Binder.clearCallingIdentity();
4708 try {
joonhunshin2c3e4232021-11-28 07:32:01 +00004709 return ImsProvisioningController.getInstance()
4710 .getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004711 } finally {
4712 Binder.restoreCallingIdentity(identity);
4713 }
4714 }
4715
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004716 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004717 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4718 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004719 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshin2c3e4232021-11-28 07:32:01 +00004720
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004721 final long identity = Binder.clearCallingIdentity();
4722 try {
joonhunshin2c3e4232021-11-28 07:32:01 +00004723 ImsProvisioningController.getInstance()
4724 .setImsProvisioningStatusForCapability(subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004725 } finally {
4726 Binder.restoreCallingIdentity(identity);
4727 }
4728 }
4729
4730 @Override
4731 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshin2c3e4232021-11-28 07:32:01 +00004732 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4733 mApp, subId, "getProvisioningStatusForCapability");
4734
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004735 final long identity = Binder.clearCallingIdentity();
4736 try {
joonhunshin2c3e4232021-11-28 07:32:01 +00004737 return ImsProvisioningController.getInstance()
4738 .getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004739
4740 } finally {
4741 Binder.restoreCallingIdentity(identity);
4742 }
4743 }
4744
4745 @Override
joonhunshin2c3e4232021-11-28 07:32:01 +00004746 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4747 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4748 mApp, subId, "isProvisioningRequiredForCapability");
4749
4750 final long identity = Binder.clearCallingIdentity();
4751 try {
4752 return ImsProvisioningController.getInstance()
4753 .isImsProvisioningRequiredForCapability(subId, capability, tech);
4754 } finally {
4755 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004756 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004757 }
4758
4759 @Override
joonhunshin2c3e4232021-11-28 07:32:01 +00004760 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4761 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4762 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004763
joonhunshin2c3e4232021-11-28 07:32:01 +00004764 final long identity = Binder.clearCallingIdentity();
4765 try {
4766 return ImsProvisioningController.getInstance()
4767 .isRcsProvisioningRequiredForCapability(subId, capability, tech);
4768 } finally {
4769 Binder.restoreCallingIdentity(identity);
4770 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004771 }
4772
4773 private static String getMmTelProvisioningKey(int subId, int tech) {
4774 // resulting key is provision_ims_mmtel_{subId}_{tech}
4775 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4776 }
4777
4778 /**
4779 * Query CarrierConfig to see if the specified capability requires provisioning for the
4780 * carrier associated with the subscription id.
4781 */
4782 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4783 int capability) {
4784 CarrierConfigManager configManager = new CarrierConfigManager(context);
4785 PersistableBundle c = configManager.getConfigForSubId(subId);
4786 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004787 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004788 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4789 false);
4790 boolean requireVoiceVtProvisioning = c.getBoolean(
4791 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4792
4793 // First check to make sure that the capability requires provisioning.
4794 switch (capability) {
4795 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4796 // intentional fallthrough
4797 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4798 if (requireVoiceVtProvisioning) {
4799 // Voice and Video requires provisioning
4800 return true;
4801 }
4802 break;
4803 }
4804 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4805 if (requireUtProvisioning) {
4806 // UT requires provisioning
4807 return true;
4808 }
4809 break;
4810 }
4811 }
4812 return false;
4813 }
4814
allenwtsu99c623b2020-01-03 18:24:23 +08004815 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4816 int capability) {
4817 CarrierConfigManager configManager = new CarrierConfigManager(context);
4818 PersistableBundle c = configManager.getConfigForSubId(subId);
4819
4820 boolean requireRcsProvisioning = c.getBoolean(
4821 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4822
4823 // First check to make sure that the capability requires provisioning.
4824 switch (capability) {
4825 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4826 // intentional fallthrough
4827 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4828 if (requireRcsProvisioning) {
4829 // OPTION or PRESENCE requires provisioning
4830 return true;
4831 }
4832 break;
4833 }
4834 }
4835 return false;
4836 }
4837
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004838 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004839 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004840 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4841 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4842 }
joonhunshin2c3e4232021-11-28 07:32:01 +00004843 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4844 mApp, subId, "getImsProvisioningInt");
4845
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004846 final long identity = Binder.clearCallingIdentity();
4847 try {
4848 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004849 int slotId = getSlotIndex(subId);
4850 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4851 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4852 + subId + "' for key:" + key);
4853 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4854 }
joonhunshin2c3e4232021-11-28 07:32:01 +00004855
4856 int retVal = ImsProvisioningController.getInstance().getProvisioningValue(subId, key);
4857 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4858 return retVal;
4859 }
4860
calvinpanb5a34062021-02-08 19:59:36 +08004861 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004862 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004863 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4864 + subId + "' for key:" + key);
4865 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004866 } finally {
4867 Binder.restoreCallingIdentity(identity);
4868 }
4869 }
4870
4871 @Override
4872 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004873 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4874 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4875 }
joonhunshin2c3e4232021-11-28 07:32:01 +00004876 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4877 mApp, subId, "getImsProvisioningString");
4878
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004879 final long identity = Binder.clearCallingIdentity();
4880 try {
4881 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004882 int slotId = getSlotIndex(subId);
4883 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4884 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4885 + subId + "' for key:" + key);
4886 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4887 }
calvinpanb5a34062021-02-08 19:59:36 +08004888 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004889 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004890 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4891 + subId + "' for key:" + key);
4892 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004893 } finally {
4894 Binder.restoreCallingIdentity(identity);
4895 }
4896 }
4897
4898 @Override
4899 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004900 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4901 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4902 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004903 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4904 "setImsProvisioningInt");
joonhunshin2c3e4232021-11-28 07:32:01 +00004905
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004906 final long identity = Binder.clearCallingIdentity();
4907 try {
4908 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004909 int slotId = getSlotIndex(subId);
4910 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4911 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4912 + subId + "' for key:" + key);
4913 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4914 }
joonhunshin2c3e4232021-11-28 07:32:01 +00004915
4916 int retVal = ImsProvisioningController.getInstance()
4917 .setProvisioningValue(subId, key, value);
4918 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4919 return retVal;
4920 }
4921
calvinpanb5a34062021-02-08 19:59:36 +08004922 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4923 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004924 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004925 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004926 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004927 } finally {
4928 Binder.restoreCallingIdentity(identity);
4929 }
4930 }
4931
4932 @Override
4933 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004934 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4935 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4936 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004937 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4938 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004939 final long identity = Binder.clearCallingIdentity();
4940 try {
4941 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004942 int slotId = getSlotIndex(subId);
4943 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4944 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4945 + subId + "' for key:" + key);
4946 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4947 }
calvinpanb5a34062021-02-08 19:59:36 +08004948 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4949 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004950 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004951 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004952 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004953 } finally {
4954 Binder.restoreCallingIdentity(identity);
4955 }
4956 }
4957
Brad Ebinger919631e2021-06-02 17:46:35 -07004958 /**
4959 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4960 * for the given slot ID or no ImsResolver instance has been created.
4961 * @param slotId The slot ID that the IMS service is created for.
4962 * @throws ImsException If there is no ImsService configured for this slot.
4963 */
4964 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4965 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4966 ImsFeature.FEATURE_MMTEL)) {
4967 throw new ImsException("This subscription does not support MMTEL over IMS",
4968 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4969 }
4970 }
4971
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004972 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004973 int slotId = SubscriptionManager.getSlotIndex(subId);
4974 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004975 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4976 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004977 }
4978 return slotId;
4979 }
4980
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004981 private int getSlotIndex(int subId) {
4982 int slotId = SubscriptionManager.getSlotIndex(subId);
4983 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4984 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4985 }
4986 return slotId;
4987 }
4988
Wink Saville36469e72014-06-11 15:17:00 -07004989 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004990 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004991 */
4992 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004993 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4994 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07004995 try {
4996 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4997 } catch (SecurityException se) {
4998 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
4999 throw new SecurityException("Package " + callingPackage + " does not belong to "
5000 + Binder.getCallingUid());
5001 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005002 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005003 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005004 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005005 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005006 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005007 mApp, subId, callingPackage, callingFeatureId,
5008 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005009 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5010 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005011
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005012 final long identity = Binder.clearCallingIdentity();
5013 try {
5014 final Phone phone = getPhone(subId);
5015 if (phone != null) {
5016 return phone.getServiceState().getDataNetworkType();
5017 } else {
5018 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5019 }
5020 } finally {
5021 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005022 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005023 }
5024
5025 /**
5026 * Returns the data network type
5027 */
5028 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005029 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005030 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5031 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005032 }
5033
5034 /**
5035 * Returns the data network type for a subId
5036 */
5037 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005038 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5039 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005040 String functionName = "getDataNetworkTypeForSubscriber";
5041 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5042 mApp, functionName)) {
5043 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5044 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5045 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5046 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005047 }
5048
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005049 final long identity = Binder.clearCallingIdentity();
5050 try {
5051 final Phone phone = getPhone(subId);
5052 if (phone != null) {
5053 return phone.getServiceState().getDataNetworkType();
5054 } else {
5055 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5056 }
5057 } finally {
5058 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005059 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005060 }
5061
5062 /**
Wink Saville36469e72014-06-11 15:17:00 -07005063 * Returns the Voice network type for a subId
5064 */
5065 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005066 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5067 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005068 String functionName = "getVoiceNetworkTypeForSubscriber";
5069 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5070 mApp, functionName)) {
5071 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5072 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5073 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5074 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005075 }
5076
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005077 final long identity = Binder.clearCallingIdentity();
5078 try {
5079 final Phone phone = getPhone(subId);
5080 if (phone != null) {
5081 return phone.getServiceState().getVoiceNetworkType();
5082 } else {
5083 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5084 }
5085 } finally {
5086 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005087 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005088 }
5089
5090 /**
5091 * @return true if a ICC card is present
5092 */
5093 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005094 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005095 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5096 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005097 }
5098
5099 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005100 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005101 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005102 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005103 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005104 final long identity = Binder.clearCallingIdentity();
5105 try {
5106 final Phone phone = PhoneFactory.getPhone(slotIndex);
5107 if (phone != null) {
5108 return phone.getIccCard().hasIccCard();
5109 } else {
5110 return false;
5111 }
5112 } finally {
5113 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005114 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005115 }
5116
5117 /**
5118 * Return if the current radio is LTE on CDMA. This
5119 * is a tri-state return value as for a period of time
5120 * the mode may be unknown.
5121 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005122 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005123 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005124 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005125 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005126 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005127 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5128 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5129 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005130 }
5131
Sanket Padawe356d7632015-06-22 14:03:32 -07005132 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005133 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5134 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005135 try {
5136 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5137 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005138 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5139 }
5140
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005141 final long identity = Binder.clearCallingIdentity();
5142 try {
5143 final Phone phone = getPhone(subId);
5144 if (phone == null) {
5145 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5146 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005147 return TelephonyProperties.lte_on_cdma_device()
5148 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005149 }
5150 } finally {
5151 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005152 }
Wink Saville36469e72014-06-11 15:17:00 -07005153 }
5154
Wink Saville36469e72014-06-11 15:17:00 -07005155 /**
5156 * {@hide}
5157 * Returns Default subId, 0 in the case of single standby.
5158 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005159 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005160 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005161 }
5162
Shishir Agrawala9f32182016-04-12 12:00:16 -07005163 private int getSlotForDefaultSubscription() {
5164 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5165 }
5166
Wink Savilleb564aae2014-10-23 10:18:09 -07005167 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005168 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005169 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005170
Pengquan Menge92a50d2018-09-21 15:54:48 -07005171 private boolean isActiveSubscription(int subId) {
5172 return mSubscriptionController.isActiveSubId(subId);
5173 }
5174
Ihab Awadf2177b72013-11-25 13:33:23 -08005175 /**
5176 * @see android.telephony.TelephonyManager.WifiCallingChoices
5177 */
5178 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005179 final long identity = Binder.clearCallingIdentity();
5180 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005181 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005182 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5183 getWhenToMakeWifiCallsDefaultPreference());
5184 } finally {
5185 Binder.restoreCallingIdentity(identity);
5186 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005187 }
5188
5189 /**
5190 * @see android.telephony.TelephonyManager.WifiCallingChoices
5191 */
5192 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005193 final long identity = Binder.clearCallingIdentity();
5194 try {
5195 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005196 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005197 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5198 } finally {
5199 Binder.restoreCallingIdentity(identity);
5200 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005201 }
5202
Sailesh Nepald1e68152013-12-12 19:08:02 -08005203 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005204 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005205 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005206 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005207
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005208 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5209 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5210 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005211 if (phoneId == -1) {
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005212 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5213 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005214 }
5215 return PhoneFactory.getPhone(phoneId);
5216 }
5217
Shishir Agrawal566b7612013-10-28 14:41:00 -07005218 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005219 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wange162e302021-11-10 20:15:19 -08005220 @NonNull IccLogicalChannelRequest request) {
5221 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5222 /*message=*/ "iccOpenLogicalChannel");
5223
5224 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5225 // Verify that the callingPackage in the request belongs to the calling UID
5226 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5227
5228 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005229 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005230
Rambo Wange162e302021-11-10 20:15:19 -08005231 private Phone getPhoneFromValidIccLogicalChannelRequest(
5232 @NonNull IccLogicalChannelRequest request, String message) {
5233 Phone phone;
5234 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5235 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5236 mApp, request.subId, message);
5237 phone = getPhoneFromSubId(request.subId);
5238 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5239 enforceModifyPermission();
5240 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5241 } else {
5242 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005243 }
Rambo Wange162e302021-11-10 20:15:19 -08005244 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005245 }
5246
5247 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wange162e302021-11-10 20:15:19 -08005248 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005249 final long identity = Binder.clearCallingIdentity();
5250 try {
Rambo Wange162e302021-11-10 20:15:19 -08005251 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005252 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005253 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5254 .getContext().getPackageManager());
Rambo Wange162e302021-11-10 20:15:19 -08005255 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5256 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005257 loge("The calling package is not allowed to access ISD-R.");
5258 throw new SecurityException(
5259 "The calling package is not allowed to access ISD-R.");
5260 }
Derek Tan740e1672017-06-27 14:56:27 -07005261 }
Derek Tan740e1672017-06-27 14:56:27 -07005262
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005263 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wange162e302021-11-10 20:15:19 -08005264 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5265 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005266 return response;
5267 } finally {
5268 Binder.restoreCallingIdentity(identity);
5269 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005270 }
5271
5272 @Override
Rambo Wange162e302021-11-10 20:15:19 -08005273 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5274 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5275 /*message=*/"iccCloseLogicalChannel");
5276
5277 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5278
5279 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005280 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005281
Rambo Wange162e302021-11-10 20:15:19 -08005282 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5283 IccLogicalChannelRequest request) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005284 final long identity = Binder.clearCallingIdentity();
5285 try {
Rambo Wange162e302021-11-10 20:15:19 -08005286 if (request.channel < 0) {
Chen Xu9040b472021-12-14 17:15:47 -08005287 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005288 }
Rambo Wange162e302021-11-10 20:15:19 -08005289 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005290 null /* workSource */);
Rambo Wange162e302021-11-10 20:15:19 -08005291 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005292 return success;
5293 } finally {
5294 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005295 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005296 }
5297
5298 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005299 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005300 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005301 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5302 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005303 if (DBG) {
5304 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5305 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5306 + p3 + " data=" + data);
5307 }
5308 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5309 command, p1, p2, p3, data);
5310 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005311
Jordan Liu4c733742019-02-28 12:03:40 -08005312 @Override
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005313 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5314 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005315 enforceModifyPermission();
5316 if (DBG) {
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005317 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5318 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5319 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005320 }
5321 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005322 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5323 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005324 }
5325
5326 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5327 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005328 final long identity = Binder.clearCallingIdentity();
5329 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005330 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005331 return "";
5332 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005333
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005334 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005335 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5336 null /* workSource */);
5337 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005338
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005339 // Append the returned status code to the end of the response payload.
5340 String s = Integer.toHexString(
5341 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5342 if (response.payload != null) {
5343 s = IccUtils.bytesToHexString(response.payload) + s;
5344 }
5345 return s;
5346 } finally {
5347 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005348 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005349 }
Jake Hambye994d462014-02-03 13:10:13 -08005350
Evan Charltonc66da362014-05-16 14:06:40 -07005351 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005352 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5353 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005354 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5355 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005356 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005357 if (DBG) {
5358 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5359 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5360 }
5361 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5362 cla, command, p1, p2, p3, data);
5363 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005364
Jordan Liu4c733742019-02-28 12:03:40 -08005365 @Override
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005366 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5367 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005368 enforceModifyPermission();
5369 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5370 if (DBG) {
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005371 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5372 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5373 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005374 }
5375
5376 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005377 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5378 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005379 }
5380
5381 // open APDU basic channel assuming the caller has sufficient permissions
5382 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5383 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005384 final long identity = Binder.clearCallingIdentity();
5385 try {
5386 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5387 && TextUtils.equals(ISDR_AID, data)) {
5388 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005389 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5390 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005391 if (bestComponent == null
5392 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5393 loge("The calling package is not allowed to select ISD-R.");
5394 throw new SecurityException(
5395 "The calling package is not allowed to select ISD-R.");
5396 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005397 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005398
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005399 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005400 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5401 null /* workSource */);
5402 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005403
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005404 // Append the returned status code to the end of the response payload.
5405 String s = Integer.toHexString(
5406 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5407 if (response.payload != null) {
5408 s = IccUtils.bytesToHexString(response.payload) + s;
5409 }
5410 return s;
5411 } finally {
5412 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005413 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005414 }
5415
5416 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005417 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005418 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005419 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5420 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005421
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005422 final long identity = Binder.clearCallingIdentity();
5423 try {
5424 if (DBG) {
5425 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5426 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5427 }
5428
5429 IccIoResult response =
5430 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5431 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5432 subId);
5433
5434 if (DBG) {
5435 log("Exchange SIM_IO [R]" + response);
5436 }
5437
5438 byte[] result = null;
5439 int length = 2;
5440 if (response.payload != null) {
5441 length = 2 + response.payload.length;
5442 result = new byte[length];
5443 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5444 } else {
5445 result = new byte[length];
5446 }
5447
5448 result[length - 1] = (byte) response.sw2;
5449 result[length - 2] = (byte) response.sw1;
5450 return result;
5451 } finally {
5452 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005453 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005454 }
5455
Nathan Haroldb3014052017-01-25 15:57:32 -08005456 /**
5457 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5458 * on a particular subscription
5459 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005460 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5461 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005462 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005463 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005464 return null;
5465 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005466
5467 final long identity = Binder.clearCallingIdentity();
5468 try {
5469 if (appType != TelephonyManager.APPTYPE_USIM
5470 && appType != TelephonyManager.APPTYPE_SIM) {
5471 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5472 return null;
5473 }
5474 Object response = sendRequest(
5475 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5476 if (response instanceof String[]) {
5477 return (String[]) response;
5478 }
yincheng zhao2737e882019-09-06 17:06:54 -07005479 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005480 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005481 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005482 } finally {
5483 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005484 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005485 }
5486
yincheng zhao2737e882019-09-06 17:06:54 -07005487 /**
5488 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5489 * subscription.
5490 *
5491 * @param subId the id of the subscription.
5492 * @param appType the uicc app type, must be USIM or SIM.
5493 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5494 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005495 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005496 * @return number of fplmns that is successfully written to the SIM.
5497 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005498 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5499 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005500 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5501 mApp, subId, "setForbiddenPlmns");
5502
yincheng zhao2737e882019-09-06 17:06:54 -07005503 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5504 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5505 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5506 }
5507 if (fplmns == null) {
5508 throw new IllegalArgumentException("Fplmn List provided is null");
5509 }
5510 for (String fplmn : fplmns) {
5511 if (!CellIdentity.isValidPlmn(fplmn)) {
5512 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5513 }
5514 }
5515 final long identity = Binder.clearCallingIdentity();
5516 try {
5517 Object response = sendRequest(
5518 CMD_SET_FORBIDDEN_PLMNS,
5519 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5520 subId);
5521 return (int) response;
5522 } finally {
5523 Binder.restoreCallingIdentity(identity);
5524 }
5525 }
5526
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005527 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005528 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005529 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5530 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005531
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005532 final long identity = Binder.clearCallingIdentity();
5533 try {
5534 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5535 if (response.payload == null) {
5536 return "";
5537 }
Evan Charltonc66da362014-05-16 14:06:40 -07005538
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005539 // Append the returned status code to the end of the response payload.
5540 String s = Integer.toHexString(
5541 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5542 s = IccUtils.bytesToHexString(response.payload) + s;
5543 return s;
5544 } finally {
5545 Binder.restoreCallingIdentity(identity);
5546 }
Evan Charltonc66da362014-05-16 14:06:40 -07005547 }
5548
Jake Hambye994d462014-02-03 13:10:13 -08005549 /**
5550 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5551 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5552 *
5553 * @param itemID the ID of the item to read
5554 * @return the NV item as a String, or null on error.
5555 */
5556 @Override
5557 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005558 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005559 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5560 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005561
5562 final long identity = Binder.clearCallingIdentity();
5563 try {
5564 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005565 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005566 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5567 return value;
5568 } finally {
5569 Binder.restoreCallingIdentity(identity);
5570 }
Jake Hambye994d462014-02-03 13:10:13 -08005571 }
5572
5573 /**
5574 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5575 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5576 *
5577 * @param itemID the ID of the item to read
5578 * @param itemValue the value to write, as a String
5579 * @return true on success; false on any failure
5580 */
5581 @Override
5582 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005583 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005584 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5585 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005586
5587 final long identity = Binder.clearCallingIdentity();
5588 try {
5589 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5590 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005591 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005592 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5593 return success;
5594 } finally {
5595 Binder.restoreCallingIdentity(identity);
5596 }
Jake Hambye994d462014-02-03 13:10:13 -08005597 }
5598
5599 /**
5600 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5601 * Used for device configuration by some CDMA operators.
5602 *
5603 * @param preferredRoamingList byte array containing the new PRL
5604 * @return true on success; false on any failure
5605 */
5606 @Override
5607 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005608 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5609 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005610
5611 final long identity = Binder.clearCallingIdentity();
5612 try {
5613 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5614 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5615 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5616 return success;
5617 } finally {
5618 Binder.restoreCallingIdentity(identity);
5619 }
Jake Hambye994d462014-02-03 13:10:13 -08005620 }
5621
5622 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005623 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005624 * Used for device configuration by some CDMA operators.
5625 *
chen xu6dac5ab2018-10-26 17:39:23 -07005626 * @param slotIndex - device slot.
5627 *
Jake Hambye994d462014-02-03 13:10:13 -08005628 * @return true on success; false on any failure
5629 */
5630 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005631 public boolean resetModemConfig(int slotIndex) {
5632 Phone phone = PhoneFactory.getPhone(slotIndex);
5633 if (phone != null) {
5634 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5635 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005636
chen xu6dac5ab2018-10-26 17:39:23 -07005637 final long identity = Binder.clearCallingIdentity();
5638 try {
5639 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5640 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5641 return success;
5642 } finally {
5643 Binder.restoreCallingIdentity(identity);
5644 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005645 }
chen xu6dac5ab2018-10-26 17:39:23 -07005646 return false;
5647 }
5648
5649 /**
5650 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5651 *
5652 * @param slotIndex - device slot.
5653 *
5654 * @return true on success; false on any failure
5655 */
5656 @Override
5657 public boolean rebootModem(int slotIndex) {
5658 Phone phone = PhoneFactory.getPhone(slotIndex);
5659 if (phone != null) {
5660 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5661 mApp, phone.getSubId(), "rebootModem");
5662
5663 final long identity = Binder.clearCallingIdentity();
5664 try {
5665 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5666 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5667 return success;
5668 } finally {
5669 Binder.restoreCallingIdentity(identity);
5670 }
5671 }
5672 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005673 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005674
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005675 public String[] getPcscfAddress(String apnType, String callingPackage,
5676 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005677 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005678 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5679 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005680 return new String[0];
5681 }
5682
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005683 final long identity = Binder.clearCallingIdentity();
5684 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005685 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005686 } finally {
5687 Binder.restoreCallingIdentity(identity);
5688 }
Wink Saville36469e72014-06-11 15:17:00 -07005689 }
5690
Brad Ebinger51f743a2017-01-23 13:50:20 -08005691 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005692 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5693 * {@link #disableIms(int)}.
5694 * @param slotIndex device slot.
5695 */
5696 public void resetIms(int slotIndex) {
5697 enforceModifyPermission();
5698
5699 final long identity = Binder.clearCallingIdentity();
5700 try {
5701 if (mImsResolver == null) {
5702 // may happen if the does not support IMS.
5703 return;
5704 }
5705 mImsResolver.disableIms(slotIndex);
5706 mImsResolver.enableIms(slotIndex);
5707 } finally {
5708 Binder.restoreCallingIdentity(identity);
5709 }
5710 }
5711
5712 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005713 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5714 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005715 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005716 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005717 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005718
5719 final long identity = Binder.clearCallingIdentity();
5720 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005721 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005722 // may happen if the device does not support IMS.
5723 return;
5724 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005725 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005726 } finally {
5727 Binder.restoreCallingIdentity(identity);
5728 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005729 }
5730
5731 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005732 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5733 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005734 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005735 public void disableIms(int slotId) {
5736 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005737
5738 final long identity = Binder.clearCallingIdentity();
5739 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005740 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005741 // may happen if the device does not support IMS.
5742 return;
5743 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005744 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005745 } finally {
5746 Binder.restoreCallingIdentity(identity);
5747 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005748 }
5749
5750 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005751 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5752 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005753 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005754 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005755 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005756 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005757
5758 final long identity = Binder.clearCallingIdentity();
5759 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005760 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005761 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5762 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005763 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005764 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005765 } finally {
5766 Binder.restoreCallingIdentity(identity);
5767 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005768 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005769 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005770 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5771 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005772 @Override
5773 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005774 enforceModifyPermission();
5775
5776 final long identity = Binder.clearCallingIdentity();
5777 try {
5778 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005779 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005780 } finally {
5781 Binder.restoreCallingIdentity(identity);
5782 }
5783 }
5784
5785 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005786 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005787 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005788 */
5789 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5790 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005791
5792 final long identity = Binder.clearCallingIdentity();
5793 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005794 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005795 // may happen if the device does not support IMS.
5796 return null;
5797 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005798 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005799 } finally {
5800 Binder.restoreCallingIdentity(identity);
5801 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005802 }
5803
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005804 /**
5805 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005806 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005807 */
5808 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5809 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005810
5811 final long identity = Binder.clearCallingIdentity();
5812 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005813 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005814 // may happen if the device does not support IMS.
5815 return null;
5816 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005817 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005818 } finally {
5819 Binder.restoreCallingIdentity(identity);
5820 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005821 }
5822
Brad Ebinger884c07b2018-02-15 16:17:40 -08005823 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005824 * Sets the ImsService Package Name that Telephony will bind to.
5825 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005826 * @param slotIndex the slot ID that the ImsService should bind for.
5827 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005828 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005829 * @param featureTypes An integer array of feature types associated with a packageName.
5830 * @param packageName The name of the package that the current configuration will be replaced
5831 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005832 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005833 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005834 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5835 int[] featureTypes, String packageName) {
5836 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5837 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005838 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5839 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005840 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005841
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005842 final long identity = Binder.clearCallingIdentity();
5843 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005844 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005845 // may happen if the device does not support IMS.
5846 return false;
5847 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005848 Map<Integer, String> featureConfig = new HashMap<>();
5849 for (int featureType : featureTypes) {
5850 featureConfig.put(featureType, packageName);
5851 }
5852 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5853 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005854 } finally {
5855 Binder.restoreCallingIdentity(identity);
5856 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005857 }
5858
5859 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005860 * Clears any carrier ImsService overrides for the slot index specified that were previously
5861 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5862 *
5863 * This should only be used for testing.
5864 *
5865 * @param slotIndex the slot ID that the ImsService should bind for.
5866 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5867 */
5868 @Override
5869 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5870 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5871 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5872 "clearCarrierImsServiceOverride");
5873 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5874 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5875 "clearCarrierImsServiceOverride");
5876
5877 final long identity = Binder.clearCallingIdentity();
5878 try {
5879 if (mImsResolver == null) {
5880 // may happen if the device does not support IMS.
5881 return false;
5882 }
5883 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5884 } finally {
5885 Binder.restoreCallingIdentity(identity);
5886 }
5887 }
5888
5889 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005890 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005891 *
5892 * @param slotId The slot that the ImsService is associated with.
5893 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5894 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005895 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005896 * @return the package name of the ImsService configuration.
5897 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005898 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5899 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005900 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005901 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005902 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005903 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5904 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005905
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005906 final long identity = Binder.clearCallingIdentity();
5907 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005908 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005909 // may happen if the device does not support IMS.
5910 return "";
5911 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005912 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005913 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5914 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005915 } finally {
5916 Binder.restoreCallingIdentity(identity);
5917 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005918 }
5919
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005920 /**
5921 * Get the MmTelFeature state associated with the requested subscription id.
5922 * @param subId The subscription that the MmTelFeature is associated with.
5923 * @param callback A callback with an integer containing the
5924 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5925 */
5926 @Override
5927 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5928 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5929 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5930 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5931 "IMS not available on device.");
5932 }
5933 final long token = Binder.clearCallingIdentity();
5934 try {
5935 int slotId = getSlotIndex(subId);
5936 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5937 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5938 + subId + "'");
5939 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5940 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005941 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005942 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5943 try {
5944 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5945 } catch (RemoteException e) {
5946 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5947 + "Ignore");
5948 }
5949 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005950 } catch (ImsException e) {
5951 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005952 } finally {
5953 Binder.restoreCallingIdentity(token);
5954 }
5955 }
5956
Daniel Brightbb5840b2021-01-12 15:48:18 -08005957 /**
5958 * Sets the ims registration state on all valid {@link Phone}s.
5959 */
5960 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005961 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005962
5963 final long identity = Binder.clearCallingIdentity();
5964 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005965 // NOTE: Before S, this method only set the default phone.
5966 for (final Phone phone : PhoneFactory.getPhones()) {
5967 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5968 phone.setImsRegistrationState(registered);
5969 }
5970 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005971 } finally {
5972 Binder.restoreCallingIdentity(identity);
5973 }
Wink Saville36469e72014-06-11 15:17:00 -07005974 }
5975
5976 /**
Stuart Scott54788802015-03-30 13:18:01 -07005977 * Set the network selection mode to automatic.
5978 *
5979 */
5980 @Override
5981 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005982 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5983 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005984
5985 final long identity = Binder.clearCallingIdentity();
5986 try {
shilufc958392020-01-20 11:36:01 -08005987 if (!isActiveSubscription(subId)) {
5988 return;
5989 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005990 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005991 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5992 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005993 } finally {
5994 Binder.restoreCallingIdentity(identity);
5995 }
Stuart Scott54788802015-03-30 13:18:01 -07005996 }
5997
Jack Yud10cdd42020-09-28 20:28:01 -07005998 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005999 * Ask the radio to connect to the input network and change selection mode to manual.
6000 *
6001 * @param subId the id of the subscription.
6002 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6003 * the operator to attach to.
6004 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6005 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6006 * normal network selection next time.
6007 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006008 */
6009 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006010 public boolean setNetworkSelectionModeManual(
6011 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006012 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6013 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006014
6015 if (!isActiveSubscription(subId)) {
6016 return false;
6017 }
6018
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006019 final long identity = Binder.clearCallingIdentity();
6020 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006021 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006022 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006023 if (DBG) {
6024 log("setNetworkSelectionModeManual: subId: " + subId
6025 + " operator: " + operatorInfo);
6026 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006027 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6028 } finally {
6029 Binder.restoreCallingIdentity(identity);
6030 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006031 }
shilu84f6e8b2019-12-19 13:58:01 -08006032 /**
6033 * Get the manual network selection
6034 *
6035 * @param subId the id of the subscription.
6036 *
6037 * @return the previously saved user selected PLMN
6038 */
6039 @Override
6040 public String getManualNetworkSelectionPlmn(int subId) {
6041 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006042 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006043 mApp, subId, "getManualNetworkSelectionPlmn");
6044
6045 final long identity = Binder.clearCallingIdentity();
6046 try {
6047 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006048 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006049 }
6050
6051 final Phone phone = getPhone(subId);
6052 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006053 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006054 }
6055 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6056 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6057 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6058 } finally {
6059 Binder.restoreCallingIdentity(identity);
6060 }
6061 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006062
6063 /**
6064 * Scans for available networks.
6065 */
6066 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006067 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6068 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006069 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6070 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006071 LocationAccessPolicy.LocationPermissionResult locationResult =
6072 LocationAccessPolicy.checkLocationPermission(mApp,
6073 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6074 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006075 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006076 .setCallingPid(Binder.getCallingPid())
6077 .setCallingUid(Binder.getCallingUid())
6078 .setMethod("getCellNetworkScanResults")
6079 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006080 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6081 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006082 .build());
6083 switch (locationResult) {
6084 case DENIED_HARD:
6085 throw new SecurityException("Not allowed to access scan results -- location");
6086 case DENIED_SOFT:
6087 return null;
6088 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006089
Pengquan Menga1bb6272018-09-06 09:59:22 -07006090 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006091 try {
6092 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006093 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006094 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006095 } finally {
6096 Binder.restoreCallingIdentity(identity);
6097 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006098 }
6099
6100 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006101 * Get the call forwarding info, given the call forwarding reason.
6102 */
6103 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006104 public void getCallForwarding(int subId, int callForwardingReason,
6105 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006106 enforceReadPrivilegedPermission("getCallForwarding");
6107 long identity = Binder.clearCallingIdentity();
6108 try {
6109 if (DBG) {
6110 log("getCallForwarding: subId " + subId
6111 + " callForwardingReason" + callForwardingReason);
6112 }
Hall Liu27d24262020-09-18 19:04:59 -07006113
6114 Phone phone = getPhone(subId);
6115 if (phone == null) {
6116 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006117 callback.onError(
6118 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006119 } catch (RemoteException e) {
6120 // ignore
6121 }
6122 return;
6123 }
6124
6125 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6126 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6127 @Override
6128 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6129 try {
6130 callback.onCallForwardingInfoAvailable(info);
6131 } catch (RemoteException e) {
6132 // ignore
6133 }
6134 }
6135
6136 @Override
6137 public void onError(int error) {
6138 try {
6139 callback.onError(error);
6140 } catch (RemoteException e) {
6141 // ignore
6142 }
6143 }
6144 });
6145 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006146 } finally {
6147 Binder.restoreCallingIdentity(identity);
6148 }
6149 }
6150
6151 /**
6152 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6153 * reason, the number to forward, and the timeout before the forwarding is attempted.
6154 */
6155 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006156 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6157 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006158 enforceModifyPermission();
6159 long identity = Binder.clearCallingIdentity();
6160 try {
6161 if (DBG) {
6162 log("setCallForwarding: subId " + subId
6163 + " callForwardingInfo" + callForwardingInfo);
6164 }
Hall Liu27d24262020-09-18 19:04:59 -07006165
6166 Phone phone = getPhone(subId);
6167 if (phone == null) {
6168 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006169 callback.accept(
6170 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006171 } catch (RemoteException e) {
6172 // ignore
6173 }
6174 return;
6175 }
6176
6177 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6178 FunctionalUtils.ignoreRemoteException(callback::accept));
6179
6180 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006181 } finally {
6182 Binder.restoreCallingIdentity(identity);
6183 }
6184 }
6185
6186 /**
Hall Liu27d24262020-09-18 19:04:59 -07006187 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006188 */
6189 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006190 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006191 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006192 long identity = Binder.clearCallingIdentity();
6193 try {
Hall Liu27d24262020-09-18 19:04:59 -07006194 Phone phone = getPhone(subId);
6195 if (phone == null) {
6196 try {
6197 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6198 } catch (RemoteException e) {
6199 // ignore
6200 }
6201 return;
6202 }
SongFerngWang0e767992021-03-31 22:08:45 +08006203 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6204 PersistableBundle c = configManager.getConfigForSubId(subId);
6205 boolean requireUssd = c.getBoolean(
6206 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006207
Shuo Qian4a594052020-01-23 11:59:30 -08006208 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006209 if (requireUssd) {
6210 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6211 getSubscriptionCarrierId(subId));
6212 String newUssdCommand = "";
6213 try {
6214 newUssdCommand = carrierXmlParser.getFeature(
6215 CarrierXmlParser.FEATURE_CALL_WAITING)
6216 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6217 } catch (NullPointerException e) {
6218 loge("Failed to generate USSD number" + e);
6219 }
6220 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6221 mMainThreadHandler, callback, carrierXmlParser,
6222 CarrierXmlParser.SsEntry.SSAction.QUERY);
6223 final String ussdCommand = newUssdCommand;
6224 Executors.newSingleThreadExecutor().execute(() -> {
6225 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6226 });
6227 } else {
6228 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6229 callback::accept);
6230 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6231 }
Shuo Qian4a594052020-01-23 11:59:30 -08006232 } finally {
6233 Binder.restoreCallingIdentity(identity);
6234 }
6235 }
6236
6237 /**
Hall Liu27d24262020-09-18 19:04:59 -07006238 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006239 */
6240 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006241 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006242 enforceModifyPermission();
6243 long identity = Binder.clearCallingIdentity();
6244 try {
Hall Liu27d24262020-09-18 19:04:59 -07006245 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6246
6247 Phone phone = getPhone(subId);
6248 if (phone == null) {
6249 try {
6250 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6251 } catch (RemoteException e) {
6252 // ignore
6253 }
6254 return;
6255 }
6256
SongFerngWang0e767992021-03-31 22:08:45 +08006257 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6258 PersistableBundle c = configManager.getConfigForSubId(subId);
6259 boolean requireUssd = c.getBoolean(
6260 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006261
SongFerngWang0e767992021-03-31 22:08:45 +08006262 if (DBG) log("getCallWaitingStatus: subId " + subId);
6263 if (requireUssd) {
6264 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6265 getSubscriptionCarrierId(subId));
6266 CarrierXmlParser.SsEntry.SSAction ssAction =
6267 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6268 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6269 String newUssdCommand = "";
6270 try {
6271 newUssdCommand = carrierXmlParser.getFeature(
6272 CarrierXmlParser.FEATURE_CALL_WAITING)
6273 .makeCommand(ssAction, null);
6274 } catch (NullPointerException e) {
6275 loge("Failed to generate USSD number" + e);
6276 }
6277 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6278 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6279 final String ussdCommand = newUssdCommand;
6280 Executors.newSingleThreadExecutor().execute(() -> {
6281 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6282 });
6283 } else {
6284 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6285 FunctionalUtils.ignoreRemoteException(callback::accept));
6286
6287 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6288 }
Shuo Qian4a594052020-01-23 11:59:30 -08006289 } finally {
6290 Binder.restoreCallingIdentity(identity);
6291 }
6292 }
6293
6294 /**
yinxub1bed742017-04-17 11:45:04 -07006295 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006296 *
yinxub1bed742017-04-17 11:45:04 -07006297 * @param subId id of the subscription
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006298 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6299 * location related information which will be sent if the caller already possess
6300 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006301 * @param request contains the radio access networks with bands/channels to scan
6302 * @param messenger callback messenger for scan results or errors
6303 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006304 * @return the id of the requested scan which can be used to stop the scan.
6305 */
6306 @Override
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006307 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6308 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006309 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006310 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6311 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006312 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006313 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6314 if (!renounceFineLocationAccess) {
6315 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6316 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6317 .setCallingPackage(callingPackage)
6318 .setCallingFeatureId(callingFeatureId)
6319 .setCallingPid(Binder.getCallingPid())
6320 .setCallingUid(Binder.getCallingUid())
6321 .setMethod("requestNetworkScan")
6322 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6323 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6324 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6325 .build());
6326 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006327 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006328 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6329 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006330 if (e != null) {
6331 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6332 throw e;
6333 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006334 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006335 return TelephonyScanManager.INVALID_SCAN_ID;
6336 }
6337 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006338 }
Hall Liu912dfd32019-04-25 14:02:26 -07006339 int callingUid = Binder.getCallingUid();
6340 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006341 final long identity = Binder.clearCallingIdentity();
6342 try {
6343 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006344 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006345 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006346 } finally {
6347 Binder.restoreCallingIdentity(identity);
6348 }
yinxu504e1392017-04-12 16:03:22 -07006349 }
6350
Hall Liub2ac8ef2019-02-28 15:56:23 -08006351 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006352 NetworkScanRequest request, int subId, String callingPackage) {
6353 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006354 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6355 boolean hasNetworkScanPermission =
6356 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6357 == PERMISSION_GRANTED;
6358
6359 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6360 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6361 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006362 }
6363
6364 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6365 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006366 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6367 return new SecurityException("Specific channels must not be"
6368 + " scanned without location access.");
6369 }
6370 }
6371 }
6372
Hall Liub2ac8ef2019-02-28 15:56:23 -08006373 return null;
6374 }
6375
yinxu504e1392017-04-12 16:03:22 -07006376 /**
6377 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006378 *
6379 * @param subId id of the subscription
6380 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006381 */
6382 @Override
6383 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006384 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6385 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006386
Hall Liu912dfd32019-04-25 14:02:26 -07006387 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006388 final long identity = Binder.clearCallingIdentity();
6389 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006390 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006391 } finally {
6392 Binder.restoreCallingIdentity(identity);
6393 }
yinxu504e1392017-04-12 16:03:22 -07006394 }
6395
6396 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006397 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006398 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006399 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006400 */
6401 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006402 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006403 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006404 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006405 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006406
6407 final long identity = Binder.clearCallingIdentity();
6408 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006409 if (DBG) log("getAllowedNetworkTypesBitmask");
6410 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6411 int networkTypesBitmask = (result != null ? result[0] : -1);
6412 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6413 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006414 } finally {
6415 Binder.restoreCallingIdentity(identity);
6416 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006417 }
6418
6419 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006420 * Get the allowed network types for certain reason.
6421 *
6422 * @param subId the id of the subscription.
6423 * @param reason the reason the allowed network type change is taking place
6424 * @return the allowed network types.
6425 */
6426 @Override
6427 public long getAllowedNetworkTypesForReason(int subId,
6428 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006429 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006430 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006431 final long identity = Binder.clearCallingIdentity();
6432 try {
6433 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6434 } finally {
6435 Binder.restoreCallingIdentity(identity);
6436 }
6437 }
6438
6439 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006440 * Enable/Disable E-UTRA-NR Dual Connectivity
6441 * @param subId subscription id of the sim card
6442 * @param nrDualConnectivityState expected NR dual connectivity state
6443 * This can be passed following states
6444 * <ol>
6445 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6446 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6447 * <li>Disable NR dual connectivity and force secondary cell to be released
6448 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6449 * </ol>
6450 * @return operation result.
6451 */
6452 @Override
6453 public int setNrDualConnectivityState(int subId,
6454 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6455 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6456 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006457 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006458 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6459 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6460 }
6461
Sooraj Sasindran37444802020-08-11 10:40:43 -07006462 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6463 final long identity = Binder.clearCallingIdentity();
6464 try {
6465 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6466 nrDualConnectivityState, subId,
6467 workSource);
6468 if (DBG) log("enableNRDualConnectivity result: " + result);
6469 return result;
6470 } finally {
6471 Binder.restoreCallingIdentity(identity);
6472 }
6473 }
6474
6475 /**
6476 * Is E-UTRA-NR Dual Connectivity enabled
6477 * @return true if dual connectivity is enabled else false
6478 */
6479 @Override
6480 public boolean isNrDualConnectivityEnabled(int subId) {
6481 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006482 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006483 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006484 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006485 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6486 return false;
6487 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006488 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6489 final long identity = Binder.clearCallingIdentity();
6490 try {
6491 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6492 null, subId, workSource);
6493 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6494 return isEnabled;
6495 } finally {
6496 Binder.restoreCallingIdentity(identity);
6497 }
6498 }
6499
6500 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006501 * Set the allowed network types of the device and
6502 * provide the reason triggering the allowed network change.
6503 *
6504 * @param subId the id of the subscription.
6505 * @param reason the reason the allowed network type change is taking place
6506 * @param allowedNetworkTypes the allowed network types.
6507 * @return true on success; false on any failure.
6508 */
6509 @Override
6510 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006511 @TelephonyManager.AllowedNetworkTypesReason int reason,
6512 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006513 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6514 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006515 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006516 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6517 return false;
6518 }
6519 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6520 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006521 return false;
6522 }
6523
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006524 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6525 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6526
6527
6528 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6529 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6530 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006531 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006532
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006533 final long identity = Binder.clearCallingIdentity();
6534 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006535 Boolean success = (Boolean) sendRequest(
6536 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6537 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6538
6539 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6540 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006541 } finally {
6542 Binder.restoreCallingIdentity(identity);
6543 }
6544 }
6545
6546 /**
Miaoa84611c2019-03-15 09:21:10 +08006547 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006548 *
Miaoa84611c2019-03-15 09:21:10 +08006549 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006550 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006551 * @hide
6552 */
6553 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006554 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006555 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006556 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006557 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006558 try {
Miaoa84611c2019-03-15 09:21:10 +08006559 if (phone != null) {
6560 return phone.hasMatchedTetherApnSetting();
6561 } else {
6562 return false;
6563 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006564 } finally {
6565 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006566 }
Junda Liu475951f2014-11-07 16:45:03 -08006567 }
6568
6569 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006570 * Get the user enabled state of Mobile Data.
6571 *
6572 * TODO: remove and use isUserDataEnabled.
6573 * This can't be removed now because some vendor codes
6574 * calls through ITelephony directly while they should
6575 * use TelephonyManager.
6576 *
6577 * @return true on enabled
6578 */
6579 @Override
6580 public boolean getDataEnabled(int subId) {
6581 return isUserDataEnabled(subId);
6582 }
6583
6584 /**
6585 * Get whether mobile data is enabled per user setting.
6586 *
6587 * There are other factors deciding whether mobile data is actually enabled, but they are
6588 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006589 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006590 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6591 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006592 *
6593 * @return {@code true} if data is enabled else {@code false}
6594 */
6595 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006596 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006597 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006598 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006599 try {
6600 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6601 functionName);
6602 } catch (Exception e) {
6603 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6604 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006605 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006606 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006607 mApp, subId, functionName);
6608
Robert Greenwalt646120a2014-05-23 11:54:03 -07006609 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006610
6611 final long identity = Binder.clearCallingIdentity();
6612 try {
6613 int phoneId = mSubscriptionController.getPhoneId(subId);
6614 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6615 Phone phone = PhoneFactory.getPhone(phoneId);
6616 if (phone != null) {
6617 boolean retVal = phone.isUserDataEnabled();
6618 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6619 return retVal;
6620 } else {
6621 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6622 return false;
6623 }
6624 } finally {
6625 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006626 }
6627 }
6628
6629 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006630 * Checks if the device is capable of mobile data by considering whether whether the
6631 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6632 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006633 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006634 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006635 */
6636 @Override
6637 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006638 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006639 try {
6640 try {
6641 mApp.enforceCallingOrSelfPermission(
6642 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006643 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006644 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006645 try {
6646 mApp.enforceCallingOrSelfPermission(
6647 android.Manifest.permission.READ_PHONE_STATE,
6648 functionName);
6649 } catch (Exception e2) {
6650 mApp.enforceCallingOrSelfPermission(
6651 permission.READ_BASIC_PHONE_STATE, functionName);
6652 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006653 }
6654 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006655 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006656 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006657
6658 final long identity = Binder.clearCallingIdentity();
6659 try {
6660 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006661 Phone phone = PhoneFactory.getPhone(phoneId);
6662 if (phone != null) {
Jack Yu3fb3a6b2021-12-03 14:23:53 -08006663 boolean retVal;
6664 if (phone.isUsingNewDataStack()) {
Sarah Chin8619e162022-03-09 13:57:52 -08006665 retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu3fb3a6b2021-12-03 14:23:53 -08006666 } else {
6667 retVal = phone.getDataEnabledSettings().isDataEnabled();
6668 }
6669 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006670 return retVal;
6671 } else {
6672 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6673 return false;
6674 }
6675 } finally {
6676 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006677 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006678 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006679
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006680 /**
6681 * Check if data is enabled for a specific reason
6682 * @param subId Subscription index
6683 * @param reason the reason the data enable change is taking place
6684 * @return {@code true} if the overall data is enabled; {@code false} if not.
6685 */
6686 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006687 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006688 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006689 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006690 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006691 try {
6692 mApp.enforceCallingOrSelfPermission(
6693 android.Manifest.permission.ACCESS_NETWORK_STATE,
6694 functionName);
6695 } catch (Exception e) {
6696 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6697 functionName);
6698 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006699 } catch (Exception e) {
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006700 try {
6701 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006702 functionName);
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006703 } catch (Exception e2) {
6704 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006705 mApp, subId, functionName);
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006706 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006707 }
6708
6709
6710 final long identity = Binder.clearCallingIdentity();
6711 try {
6712 int phoneId = mSubscriptionController.getPhoneId(subId);
6713 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006714 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006715 + " reason=" + reason);
6716 }
6717 Phone phone = PhoneFactory.getPhone(phoneId);
6718 if (phone != null) {
6719 boolean retVal;
Jack Yu6bc9c8b2021-12-17 23:14:15 -08006720 if (phone.isUsingNewDataStack()) {
6721 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006722 } else {
Jack Yu6bc9c8b2021-12-17 23:14:15 -08006723 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6724 retVal = phone.isUserDataEnabled();
6725 } else {
6726 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
6727 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006728 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006729 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006730 return retVal;
6731 } else {
6732 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006733 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006734 + subId + " retVal=false");
6735 }
6736 return false;
6737 }
6738 } finally {
6739 Binder.restoreCallingIdentity(identity);
6740 }
6741 }
6742
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006743 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006744 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006745 // No permission needed; this only lets the caller inspect their own status.
6746 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006747 }
Junda Liu29340342014-07-10 15:23:27 -07006748
6749 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006750 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006751 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006752 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6753 }
6754
6755 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6756 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006757 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006758 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006759 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6760 }
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006761 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6762 if (cpt == null) {
6763 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006764 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6765 }
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006766 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006767 }
6768
6769 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006770 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006771 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006772 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006773 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006774 }
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006775 Phone phone = getPhone(subId);
6776 if (phone == null) {
6777 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6778 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6779 }
6780 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6781 if (cpt == null) {
6782 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006783 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6784 }
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006785 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006786 }
6787
6788 @Override
6789 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006790 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
6791 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006792 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006793 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006794 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006795 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6796 Phone phone = PhoneFactory.getPhone(phoneId);
6797 if (phone == null) {
6798 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006799 }
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006800 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6801 if (cpt == null) {
6802 continue;
6803 }
6804 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006805 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6806 break;
6807 }
6808 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006809 return result;
Junda Liu29340342014-07-10 15:23:27 -07006810 }
Derek Tan89e89d42014-07-08 17:00:10 -07006811
6812 @Override
Junda Liue64de782015-04-16 17:19:16 -07006813 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006814 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Hunter Knepshieldb0eb4792021-12-14 18:49:15 -08006815 Phone phone = PhoneFactory.getPhone(phoneId);
6816 if (phone == null) {
6817 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006818 }
Hunter Knepshieldb0eb4792021-12-14 18:49:15 -08006819 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6820 if (cpt == null) {
6821 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006822 }
Hunter Knepshieldb0eb4792021-12-14 18:49:15 -08006823 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006824 }
6825
Amith Yamasani6e118872016-02-19 12:53:51 -08006826 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006827 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006828 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006829 Phone phone = PhoneFactory.getPhone(phoneId);
6830 if (phone == null) {
6831 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006832 }
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006833 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6834 if (cpt == null) {
6835 return Collections.emptyList();
6836 }
6837 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006838 }
6839
chen xuf7e9fe82019-05-09 19:31:02 -07006840 @Override
6841 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006842 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006843 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006844 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00006845 try {
6846 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6847 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6848 }
6849 } finally {
6850 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006851 }
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006852 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07006853 }
6854
Rambo Wang9b91ffd2022-03-15 16:54:17 -07006855 @Override
6856 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
6857 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
6858
6859 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
6860 if (phone == null) {
6861 return null;
6862 }
6863 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6864 if (cpt == null) {
6865 return null;
6866 }
6867 return cpt.getCarrierServicePackageName();
6868 }
6869
Wink Savilleb564aae2014-10-23 10:18:09 -07006870 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006871 final Phone phone = getPhone(subId);
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006872 UiccPort port = phone == null ? null : phone.getUiccPort();
6873 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006874 return null;
6875 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006876 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006877 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006878 return null;
6879 }
6880 return iccId;
6881 }
6882
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006883 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006884 public void setCallComposerStatus(int subId, int status) {
6885 enforceModifyPermission();
6886
6887 final long identity = Binder.clearCallingIdentity();
6888 try {
6889 Phone phone = getPhone(subId);
6890 if (phone != null) {
6891 Phone defaultPhone = phone.getImsPhone();
6892 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6893 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6894 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006895 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6896 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006897 }
6898 }
Shuo Qian284ae752020-12-22 19:10:14 -08006899 } catch (ImsException e) {
6900 throw new ServiceSpecificException(e.getCode());
6901 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006902 Binder.restoreCallingIdentity(identity);
6903 }
6904 }
6905
6906 @Override
6907 public int getCallComposerStatus(int subId) {
6908 enforceReadPrivilegedPermission("getCallComposerStatus");
6909
6910 final long identity = Binder.clearCallingIdentity();
6911 try {
6912 Phone phone = getPhone(subId);
6913 if (phone != null) {
6914 Phone defaultPhone = phone.getImsPhone();
6915 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6916 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6917 return imsPhone.getCallComposerStatus();
6918 }
6919 }
6920 } finally {
6921 Binder.restoreCallingIdentity(identity);
6922 }
6923 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6924 }
6925
6926 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006927 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6928 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006929 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006930 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006931
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006932 final long identity = Binder.clearCallingIdentity();
6933 try {
6934 final String iccId = getIccId(subId);
6935 final Phone phone = getPhone(subId);
6936 if (phone == null) {
6937 return false;
6938 }
6939 final String subscriberId = phone.getSubscriberId();
6940
6941 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006942 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006943 + subscriberId + " to " + number);
6944 }
6945
6946 if (TextUtils.isEmpty(iccId)) {
6947 return false;
6948 }
6949
6950 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6951
6952 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6953 if (alphaTag == null) {
6954 editor.remove(alphaTagPrefKey);
6955 } else {
6956 editor.putString(alphaTagPrefKey, alphaTag);
6957 }
6958
6959 // Record both the line number and IMSI for this ICCID, since we need to
6960 // track all merged IMSIs based on line number
6961 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6962 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6963 if (number == null) {
6964 editor.remove(numberPrefKey);
6965 editor.remove(subscriberPrefKey);
6966 } else {
6967 editor.putString(numberPrefKey, number);
6968 editor.putString(subscriberPrefKey, subscriberId);
6969 }
6970
6971 editor.commit();
6972 return true;
6973 } finally {
6974 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006975 }
Derek Tan7226c842014-07-02 17:42:23 -07006976 }
6977
6978 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006979 public String getLine1NumberForDisplay(int subId, String callingPackage,
6980 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006981 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006982 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006983 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006984 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006985 return null;
6986 }
Derek Tan97ebb422014-09-05 16:55:38 -07006987
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006988 final long identity = Binder.clearCallingIdentity();
6989 try {
6990 String iccId = getIccId(subId);
6991 if (iccId != null) {
6992 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6993 if (DBG_MERGE) {
6994 log("getLine1NumberForDisplay returning "
6995 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6996 }
6997 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006998 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006999 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7000 return null;
7001 } finally {
7002 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007003 }
Derek Tan7226c842014-07-02 17:42:23 -07007004 }
7005
7006 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007007 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7008 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007009 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007010 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007011 return null;
7012 }
Derek Tan97ebb422014-09-05 16:55:38 -07007013
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007014 final long identity = Binder.clearCallingIdentity();
7015 try {
7016 String iccId = getIccId(subId);
7017 if (iccId != null) {
7018 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7019 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7020 }
7021 return null;
7022 } finally {
7023 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007024 }
Derek Tan7226c842014-07-02 17:42:23 -07007025 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007026
7027 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007028 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7029 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007030 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7031 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007032 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007033 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007034 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007035 return null;
7036 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007037
Jordan Liub49b04b2019-05-06 14:45:15 -07007038 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7039 // the process, where TelephonyManager was instantiated.
7040 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007041 final long identity = Binder.clearCallingIdentity();
7042 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007043 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007044 final TelephonyManager tele = TelephonyManager.from(context);
7045 final SubscriptionManager sub = SubscriptionManager.from(context);
7046
7047 // Figure out what subscribers are currently active
7048 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007049
Jordan Liub49b04b2019-05-06 14:45:15 -07007050 // Only consider subs which match the current subId
7051 // This logic can be simplified. See b/131189269 for progress.
7052 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007053 activeSubscriberIds.add(tele.getSubscriberId(subId));
7054 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007055
7056 // First pass, find a number override for an active subscriber
7057 String mergeNumber = null;
7058 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7059 for (String key : prefs.keySet()) {
7060 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7061 final String subscriberId = (String) prefs.get(key);
7062 if (activeSubscriberIds.contains(subscriberId)) {
7063 final String iccId = key.substring(
7064 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7065 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7066 mergeNumber = (String) prefs.get(numberKey);
7067 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007068 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007069 + " for active subscriber " + subscriberId);
7070 }
7071 if (!TextUtils.isEmpty(mergeNumber)) {
7072 break;
7073 }
7074 }
7075 }
7076 }
7077
7078 // Shortcut when no active merged subscribers
7079 if (TextUtils.isEmpty(mergeNumber)) {
7080 return null;
7081 }
7082
7083 // Second pass, find all subscribers under that line override
7084 final ArraySet<String> result = new ArraySet<>();
7085 for (String key : prefs.keySet()) {
7086 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7087 final String number = (String) prefs.get(key);
7088 if (mergeNumber.equals(number)) {
7089 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7090 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7091 final String subscriberId = (String) prefs.get(subscriberKey);
7092 if (!TextUtils.isEmpty(subscriberId)) {
7093 result.add(subscriberId);
7094 }
7095 }
7096 }
7097 }
7098
7099 final String[] resultArray = result.toArray(new String[result.size()]);
7100 Arrays.sort(resultArray);
7101 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007102 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007103 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7104 }
7105 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007106 } finally {
7107 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007108 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007109 }
7110
7111 @Override
zoey chen38003472019-12-13 17:16:31 +08007112 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7113 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007114
7115 final long identity = Binder.clearCallingIdentity();
7116 try {
7117 final TelephonyManager telephonyManager = mApp.getSystemService(
7118 TelephonyManager.class);
7119 String subscriberId = telephonyManager.getSubscriberId(subId);
7120 if (subscriberId == null) {
7121 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007122 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007123 + subId);
7124 }
7125 return null;
7126 }
7127
7128 final SubscriptionInfo info = SubscriptionController.getInstance()
7129 .getSubscriptionInfo(subId);
7130 final ParcelUuid groupUuid = info.getGroupUuid();
7131 // If it doesn't belong to any group, return just subscriberId of itself.
7132 if (groupUuid == null) {
7133 return new String[]{subscriberId};
7134 }
7135
7136 // Get all subscriberIds from the group.
7137 final List<String> mergedSubscriberIds = new ArrayList<>();
7138 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007139 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007140 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007141 for (SubscriptionInfo subInfo : groupInfos) {
7142 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7143 if (subscriberId != null) {
7144 mergedSubscriberIds.add(subscriberId);
7145 }
7146 }
7147
7148 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7149 } finally {
7150 Binder.restoreCallingIdentity(identity);
7151
7152 }
7153 }
7154
7155 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007156 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007157 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007158 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007159
7160 final long identity = Binder.clearCallingIdentity();
7161 try {
7162 final Phone phone = getPhone(subId);
7163 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7164 } finally {
7165 Binder.restoreCallingIdentity(identity);
7166 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007167 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007168
7169 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007170 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007171 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7172 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007173 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7174 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007175
7176 final long identity = Binder.clearCallingIdentity();
7177 try {
7178 final Phone phone = getPhone(subId);
7179 if (phone == null) {
7180 return false;
7181 }
7182 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7183 cdmaNonRoamingList);
7184 } finally {
7185 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007186 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007187 }
7188
7189 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007190 @Deprecated
7191 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7192 enforceModifyPermission();
7193
7194 int returnValue = 0;
7195 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007196 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007197 if(result.exception == null) {
7198 if (result.result != null) {
7199 byte[] responseData = (byte[])(result.result);
7200 if(responseData.length > oemResp.length) {
7201 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7202 responseData.length + "bytes. Buffer Size is " +
7203 oemResp.length + "bytes.");
7204 }
7205 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7206 returnValue = responseData.length;
7207 }
7208 } else {
7209 CommandException ex = (CommandException) result.exception;
7210 returnValue = ex.getCommandError().ordinal();
7211 if(returnValue > 0) returnValue *= -1;
7212 }
7213 } catch (RuntimeException e) {
7214 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7215 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7216 if(returnValue > 0) returnValue *= -1;
7217 }
7218
7219 return returnValue;
7220 }
7221
7222 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007223 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007224 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007225 try {
7226 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007227 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007228 mApp, phone.getSubId(), "getRadioAccessFamily");
7229 } catch (SecurityException e) {
7230 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7231 throw e;
7232 }
chen xub97461a2018-10-26 14:17:57 -07007233 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007234 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007235 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007236 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007237 final long identity = Binder.clearCallingIdentity();
7238 try {
chen xub97461a2018-10-26 14:17:57 -07007239 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007240 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007241 mApp, phone.getSubId(), "getRadioAccessFamily");
7242 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007243 } finally {
7244 Binder.restoreCallingIdentity(identity);
7245 }
chen xub97461a2018-10-26 14:17:57 -07007246 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007247 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007248
7249 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007250 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007251 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007252 try {
7253 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7254 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007255 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007256 }
7257 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007258 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007259 }
7260 RoleManager rm = mApp.getSystemService(RoleManager.class);
7261 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7262 if (!dialerRoleHolders.contains(callingPackage)) {
7263 throw new SecurityException("App must be the dialer role holder to"
7264 + " upload a call composer pic");
7265 }
7266
7267 Executors.newSingleThreadExecutor().execute(() -> {
7268 ByteArrayOutputStream output = new ByteArrayOutputStream(
7269 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7270 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7271 boolean readUntilEnd = false;
7272 int totalBytesRead = 0;
7273 byte[] buffer = new byte[16 * 1024];
7274 while (true) {
7275 int numRead;
7276 try {
7277 numRead = input.read(buffer);
7278 } catch (IOException e) {
7279 try {
7280 fd.checkError();
7281 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7282 null);
7283 } catch (IOException e1) {
7284 // This means that the other side closed explicitly with an error. If this
7285 // happens, log and ignore.
7286 loge("Remote end of call composer picture pipe closed: " + e1);
7287 }
7288 break;
7289 }
7290 if (numRead == -1) {
7291 readUntilEnd = true;
7292 break;
7293 }
7294 totalBytesRead += numRead;
7295 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7296 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7297 try {
7298 input.close();
7299 } catch (IOException e) {
7300 // ignore
7301 }
7302 break;
7303 }
7304 output.write(buffer, 0, numRead);
7305 }
7306 // Generally, the remote end will close the file descriptors. The only case where we
7307 // close is above, where the picture size is too big.
7308
7309 try {
7310 fd.checkError();
7311 } catch (IOException e) {
7312 loge("Remote end for call composer closed with an error: " + e);
7313 return;
7314 }
7315
Hall Liuaa4211e2021-01-20 15:43:39 -08007316 if (!readUntilEnd) {
7317 loge("Did not finish reading entire image; aborting");
7318 return;
7319 }
Hall Liu82694d52020-12-11 18:22:04 -08007320
Hall Liuaa4211e2021-01-20 15:43:39 -08007321 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7322 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7323 new CallComposerPictureTransfer.Factory() {},
7324 imageData,
7325 (result) -> {
7326 if (result.first != null) {
7327 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7328 Bundle outputResult = new Bundle();
7329 outputResult.putParcelable(
7330 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7331 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7332 outputResult);
7333 } else {
7334 callback.send(result.second, null);
7335 }
7336 }
7337 );
Hall Liu82694d52020-12-11 18:22:04 -08007338 });
7339 }
7340
7341 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007342 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007343 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007344 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007345
7346 final long identity = Binder.clearCallingIdentity();
7347 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007348 ImsManager.getInstance(defaultPhone.getContext(),
7349 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007350 } finally {
7351 Binder.restoreCallingIdentity(identity);
7352 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007353 }
7354
7355 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007356 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007357 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007358 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7359 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007360 return false;
7361 }
Svet Ganovb320e182015-04-16 12:30:10 -07007362
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007363 final long identity = Binder.clearCallingIdentity();
7364 try {
7365 // Check the user preference and the system-level IMS setting. Even if the user has
7366 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7367 // In the long run, we may instead need to check if there exists a connection service
7368 // which can support video calling.
7369 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007370 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007371 return imsManager.isVtEnabledByPlatform()
7372 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7373 && imsManager.isVtEnabledByUser();
7374 } finally {
7375 Binder.restoreCallingIdentity(identity);
7376 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007377 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007378
Andrew Leea1239f22015-03-02 17:44:07 -08007379 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007380 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7381 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007382 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007383 mApp, subId, callingPackage, callingFeatureId,
7384 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007385 return false;
7386 }
7387
7388 final long identity = Binder.clearCallingIdentity();
7389 try {
7390 CarrierConfigManager configManager =
7391 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007392 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007393 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7394 } finally {
7395 Binder.restoreCallingIdentity(identity);
7396 }
Andrew Leea1239f22015-03-02 17:44:07 -08007397 }
7398
7399 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007400 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007401 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007402 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007403 return false;
7404 }
7405
7406 final long identity = Binder.clearCallingIdentity();
7407 try {
7408 CarrierConfigManager configManager =
7409 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007410 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007411 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7412 } finally {
7413 Binder.restoreCallingIdentity(identity);
7414 }
Andrew Leea1239f22015-03-02 17:44:07 -08007415 }
7416
Andrew Lee9431b832015-03-09 18:46:45 -07007417 @Override
7418 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007419 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007420 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007421 }
7422
7423 @Override
7424 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007425 final long identity = Binder.clearCallingIdentity();
7426 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007427 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007428 } finally {
7429 Binder.restoreCallingIdentity(identity);
7430 }
Andrew Lee9431b832015-03-09 18:46:45 -07007431 }
7432
Hall Liuf6668912018-10-31 17:05:23 -07007433 /**
7434 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7435 * support for the feature and device firmware support.
7436 *
7437 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7438 */
7439 @Override
7440 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007441 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007442 final Phone phone = getPhone(subscriptionId);
7443 if (phone == null) {
7444 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7445 return false;
7446 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007447 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007448 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007449 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7450 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007451 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007452 return isCarrierSupported && isDeviceSupported;
7453 } finally {
7454 Binder.restoreCallingIdentity(identity);
7455 }
Hall Liu98187582018-01-22 19:15:32 -08007456 }
7457
Hall Liuf6668912018-10-31 17:05:23 -07007458 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007459 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7460 * RTT setting, will return true if the device and carrier both support RTT.
7461 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007462 */
7463 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007464 final long identity = Binder.clearCallingIdentity();
7465 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007466 boolean isRttSupported = isRttSupported(subscriptionId);
7467 boolean isUserRttSettingOn = Settings.Secure.getInt(
7468 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7469 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7470 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7471 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007472 } finally {
7473 Binder.restoreCallingIdentity(identity);
7474 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007475 }
7476
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007477 @Deprecated
7478 @Override
7479 public String getDeviceId(String callingPackage) {
7480 return getDeviceIdWithFeature(callingPackage, null);
7481 }
7482
Sanket Padawe7310cc72015-01-14 09:53:20 -08007483 /**
7484 * Returns the unique device ID of phone, for example, the IMEI for
7485 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7486 *
7487 * <p>Requires Permission:
7488 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7489 */
7490 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007491 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007492 try {
7493 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7494 } catch (SecurityException se) {
7495 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7496 throw new SecurityException("Package " + callingPackage + " does not belong to "
7497 + Binder.getCallingUid());
7498 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007499 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007500 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007501 return null;
7502 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007503 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007504 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007505 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007506 return null;
7507 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007508
7509 final long identity = Binder.clearCallingIdentity();
7510 try {
7511 return phone.getDeviceId();
7512 } finally {
7513 Binder.restoreCallingIdentity(identity);
7514 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007515 }
7516
Ping Sunc67b7c22016-03-02 19:16:45 +08007517 /**
7518 * {@hide}
7519 * Returns the IMS Registration Status on a particular subid
7520 *
7521 * @param subId
7522 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007523 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007524 Phone phone = getPhone(subId);
7525 if (phone != null) {
7526 return phone.isImsRegistered();
7527 } else {
7528 return false;
7529 }
7530 }
7531
Santos Cordon7a1885b2015-02-03 11:15:19 -08007532 @Override
7533 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007534 final long identity = Binder.clearCallingIdentity();
7535 try {
7536 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7537 } finally {
7538 Binder.restoreCallingIdentity(identity);
7539 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007540 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007541
Tyler Gunnf70ed162019-04-03 15:28:53 -07007542 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007543 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007544 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007545 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007546 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007547 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7548 }
7549 final long identity = Binder.clearCallingIdentity();
7550 try {
7551 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7552 } finally {
7553 Binder.restoreCallingIdentity(identity);
7554 }
7555 }
7556
7557 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007558 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007559 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007560 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007561 mApp,
7562 subscriptionId,
7563 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007564 final long identity = Binder.clearCallingIdentity();
7565 try {
7566 Phone phone = getPhone(subscriptionId);
7567 if (phone == null) {
7568 return null;
7569 }
7570 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7571 } finally {
7572 Binder.restoreCallingIdentity(identity);
7573 }
7574 }
7575
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007576 /**
7577 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007578 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007579 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007580 final long identity = Binder.clearCallingIdentity();
7581 try {
7582 Phone phone = getPhone(subId);
7583 if (phone != null) {
7584 return phone.isWifiCallingEnabled();
7585 } else {
7586 return false;
7587 }
7588 } finally {
7589 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007590 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007591 }
7592
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007593 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007594 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007595 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007596 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007597 final long identity = Binder.clearCallingIdentity();
7598 try {
7599 Phone phone = getPhone(subId);
7600 if (phone != null) {
7601 return phone.isVideoEnabled();
7602 } else {
7603 return false;
7604 }
7605 } finally {
7606 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007607 }
7608 }
7609
7610 /**
7611 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7612 * defined in {@link ImsRegistrationImplBase}.
7613 */
7614 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007615 final long identity = Binder.clearCallingIdentity();
7616 try {
7617 Phone phone = getPhone(subId);
7618 if (phone != null) {
7619 return phone.getImsRegistrationTech();
7620 } else {
7621 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7622 }
7623 } finally {
7624 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007625 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007626 }
7627
Stuart Scott8eef64f2015-04-08 15:13:54 -07007628 @Override
7629 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007630 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007631 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7632 return;
7633 }
Kai Shif70f46f2021-03-03 13:59:46 -08007634 Phone defaultPhone = getDefaultPhone();
7635 if (defaultPhone != null) {
7636 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7637 mApp, getDefaultPhone().getSubId(), "factoryReset");
7638 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007639 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007640
Svet Ganovcc087f82015-05-12 20:35:54 -07007641 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007642 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7643 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007644 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007645 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007646 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007647 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007648 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007649 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007650 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007651 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007652 // There has been issues when Sms raw table somehow stores orphan
7653 // fragments. They lead to garbled message when new fragments come
7654 // in and combined with those stale ones. In case this happens again,
7655 // user can reset all network settings which will clean up this table.
7656 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007657 // Clean up IMS settings as well here.
7658 int slotId = getSlotIndex(subId);
7659 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7660 ImsManager.getInstance(mApp, slotId).factoryReset();
7661 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007662
Kai Shif70f46f2021-03-03 13:59:46 -08007663 if (defaultPhone == null) {
7664 return;
7665 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007666 // Erase modem config if erase modem on network setting is enabled.
7667 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7668 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7669 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007670 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007671 }
Kai Shif70f46f2021-03-03 13:59:46 -08007672
7673 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007674 } finally {
7675 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007676 }
7677 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007678
SongFerngWangfd89b102021-05-27 22:44:54 +08007679 @VisibleForTesting
7680 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7681 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7682 return;
7683 }
7684 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7685 RILConstants.PREFERRED_NETWORK_MODE);
7686 SubscriptionManager.setSubscriptionProperty(subId,
7687 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7688 "user=" + defaultNetworkType);
7689 phone.loadAllowedNetworksFromSubscriptionDatabase();
7690 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7691 defaultNetworkType, null);
7692 }
7693
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007694 private void cleanUpSmsRawTable(Context context) {
7695 ContentResolver resolver = context.getContentResolver();
7696 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7697 resolver.delete(uri, null, null);
7698 }
7699
Narayan Kamath1c496c22015-04-16 14:40:19 +01007700 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007701 public String getSimLocaleForSubscriber(int subId) {
7702 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7703 final Phone phone = getPhone(subId);
7704 if (phone == null) {
7705 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007706 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007707 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007708 final long identity = Binder.clearCallingIdentity();
7709 try {
chen xu5d3637b2019-01-21 23:31:38 -08007710 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007711 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007712 if (info == null) {
7713 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7714 return null;
7715 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007716 // Try and fetch the locale from the carrier properties or from the SIM language
7717 // preferences (EF-PL and EF-LI)...
7718 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007719 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007720 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7721 if (localeFromDefaultSim != null) {
7722 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7723 if (DBG) log("Using locale from subId: " + subId + " locale: "
7724 + localeFromDefaultSim);
7725 return localeFromDefaultSim.toLanguageTag();
7726 } else {
7727 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007728 }
7729 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007730
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007731 // The SIM language preferences only store a language (e.g. fr = French), not an
7732 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7733 // the SIM and carrier preferences does not include a country we add the country
7734 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007735 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007736 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007737 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007738 return mccLocale.toLanguageTag();
7739 }
7740
7741 if (DBG) log("No locale found - returning null");
7742 return null;
7743 } finally {
7744 Binder.restoreCallingIdentity(identity);
7745 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007746 }
7747
7748 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007749 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007750 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007751 }
7752
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007753 /**
7754 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7755 */
7756 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007757 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007758 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007759 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007760
Chenjie Yu1ba97252018-01-11 18:16:20 -08007761 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007762 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007763
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007764 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007765 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7766 * representing the state of the modem.
7767 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007768 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7769 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007770 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007771 */
7772 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007773 public void requestModemActivityInfo(ResultReceiver result) {
7774 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007775 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007776
7777 final long identity = Binder.clearCallingIdentity();
7778 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007779 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007780 } finally {
7781 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007782 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007783 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007784
Siddharth Rayb8114062018-06-17 15:02:38 -07007785 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7786 // less than total activity duration.
7787 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7788 if (info == null) {
7789 return false;
7790 }
7791 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007792 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7793 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7794
Siddharth Rayb8114062018-06-17 15:02:38 -07007795 return (info.isValid()
7796 && (info.getSleepTimeMillis() <= activityDurationMs)
7797 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007798 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007799 && (totalTxTimeMs <= activityDurationMs));
7800 }
7801
Jack Yu85bd38a2015-11-09 11:34:32 -08007802 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007803 * Returns the service state information on specified subscription.
7804 */
7805 @Override
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007806 public ServiceState getServiceStateForSubscriber(int subId,
7807 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7808 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007809 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007810 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007811 return null;
7812 }
7813
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007814 boolean hasFinePermission = false;
7815 boolean hasCoarsePermission = false;
7816 if (!renounceFineLocationAccess) {
7817 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7818 LocationAccessPolicy.checkLocationPermission(mApp,
7819 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7820 .setCallingPackage(callingPackage)
7821 .setCallingFeatureId(callingFeatureId)
7822 .setCallingPid(Binder.getCallingPid())
7823 .setCallingUid(Binder.getCallingUid())
7824 .setMethod("getServiceStateForSubscriber")
7825 .setLogAsInfo(true)
7826 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7827 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7828 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7829 .build());
7830 hasFinePermission =
7831 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7832 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007833
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007834 if (!renounceCoarseLocationAccess) {
7835 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7836 LocationAccessPolicy.checkLocationPermission(mApp,
7837 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7838 .setCallingPackage(callingPackage)
7839 .setCallingFeatureId(callingFeatureId)
7840 .setCallingPid(Binder.getCallingPid())
7841 .setCallingUid(Binder.getCallingUid())
7842 .setMethod("getServiceStateForSubscriber")
7843 .setLogAsInfo(true)
7844 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7845 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7846 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7847 .build());
7848 hasCoarsePermission =
7849 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7850 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007851
Jack Yu479f40e2020-10-27 21:29:25 -07007852 final Phone phone = getPhone(subId);
7853 if (phone == null) {
7854 return null;
7855 }
7856
Jordan Liu0f2bc442020-11-18 16:47:37 -08007857 final long identity = Binder.clearCallingIdentity();
7858
Jack Yu479f40e2020-10-27 21:29:25 -07007859 boolean isCallingPackageDataService = phone.getDataServicePackages()
7860 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007861 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007862 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7863 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7864 Rlog.d(LOG_TAG,
7865 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7866 return null;
7867 }
7868
Hall Liuf19c44f2018-11-27 14:38:17 -08007869 ServiceState ss = phone.getServiceState();
7870
7871 // Scrub out the location info in ServiceState depending on what level of access
7872 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007873 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007874 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7875 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007876 } finally {
7877 Binder.restoreCallingIdentity(identity);
7878 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007879 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007880
7881 /**
7882 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7883 *
7884 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7885 * voicemail ringtone.
7886 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7887 * PhoneAccount.
7888 */
7889 @Override
7890 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007891 final long identity = Binder.clearCallingIdentity();
7892 try {
7893 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7894 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007895 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007896 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007897
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007898 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7899 } finally {
7900 Binder.restoreCallingIdentity(identity);
7901 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007902 }
7903
7904 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007905 * Sets the per-account voicemail ringtone.
7906 *
7907 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7908 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7909 *
7910 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7911 * voicemail ringtone.
7912 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7913 * PhoneAccount.
7914 */
7915 @Override
7916 public void setVoicemailRingtoneUri(String callingPackage,
7917 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007918 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007919 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007920 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7921 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007922 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7923 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7924 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007925 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007926
7927 final long identity = Binder.clearCallingIdentity();
7928 try {
7929 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7930 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007931 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007932 }
7933 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7934 } finally {
7935 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007936 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007937 }
7938
7939 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007940 * Returns whether vibration is set for voicemail notification in Phone settings.
7941 *
7942 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7943 * voicemail vibration setting.
7944 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7945 */
7946 @Override
7947 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007948 final long identity = Binder.clearCallingIdentity();
7949 try {
7950 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7951 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007952 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007953 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007954
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007955 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7956 } finally {
7957 Binder.restoreCallingIdentity(identity);
7958 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007959 }
7960
Youhan Wange64578a2016-05-02 15:32:42 -07007961 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007962 * Sets the per-account voicemail vibration.
7963 *
7964 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7965 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7966 *
7967 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7968 * voicemail vibration setting.
7969 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7970 * specific PhoneAccount.
7971 */
7972 @Override
7973 public void setVoicemailVibrationEnabled(String callingPackage,
7974 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007975 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007976 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007977 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7978 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007979 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7980 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7981 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007982 }
7983
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007984 final long identity = Binder.clearCallingIdentity();
7985 try {
7986 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7987 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007988 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007989 }
7990 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7991 } finally {
7992 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007993 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007994 }
7995
7996 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007997 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7998 *
7999 * @throws SecurityException if the caller does not have the required permission
8000 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008001 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008002 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008003 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008004 }
8005
8006 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008007 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8008 * permission.
8009 *
8010 * @throws SecurityException if the caller does not have the required permission
8011 */
8012 private void enforceSendSmsPermission() {
8013 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8014 }
8015
8016 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008017 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008018 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008019 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008020 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008021 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008022 final long identity = Binder.clearCallingIdentity();
8023 try {
8024 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008025 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008026 if (componentName == null) {
8027 throw new SecurityException(
8028 "Caller not current active visual voicemail package[null]");
8029 }
8030 String vvmPackage = componentName.getPackageName();
8031 if (!callingPackage.equals(vvmPackage)) {
8032 throw new SecurityException("Caller not current active visual voicemail package["
8033 + vvmPackage + "]");
8034 }
8035 } finally {
8036 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008037 }
8038 }
8039
8040 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008041 * Return the application ID for the app type.
8042 *
8043 * @param subId the subscription ID that this request applies to.
8044 * @param appType the uicc app type.
8045 * @return Application ID for specificied app type, or null if no uicc.
8046 */
8047 @Override
8048 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008049 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008050 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008051
8052 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008053 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008054 if (phone == null) {
8055 return null;
8056 }
8057 String aid = null;
8058 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008059 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008060 .getApplicationByType(appType).getAid();
8061 } catch (Exception e) {
8062 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8063 }
8064 return aid;
8065 } finally {
8066 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008067 }
Youhan Wange64578a2016-05-02 15:32:42 -07008068 }
8069
Youhan Wang4001d252016-05-11 10:29:41 -07008070 /**
8071 * Return the Electronic Serial Number.
8072 *
8073 * @param subId the subscription ID that this request applies to.
8074 * @return ESN or null if error.
8075 */
8076 @Override
8077 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008078 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008079 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008080
8081 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008082 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008083 if (phone == null) {
8084 return null;
8085 }
8086 String esn = null;
8087 try {
8088 esn = phone.getEsn();
8089 } catch (Exception e) {
8090 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8091 }
8092 return esn;
8093 } finally {
8094 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008095 }
Youhan Wang4001d252016-05-11 10:29:41 -07008096 }
8097
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008098 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008099 * Return the Preferred Roaming List Version.
8100 *
8101 * @param subId the subscription ID that this request applies to.
8102 * @return PRLVersion or null if error.
8103 */
8104 @Override
8105 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008106 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008107 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008108
8109 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008110 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008111 if (phone == null) {
8112 return null;
8113 }
8114 String cdmaPrlVersion = null;
8115 try {
8116 cdmaPrlVersion = phone.getCdmaPrlVersion();
8117 } catch (Exception e) {
8118 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8119 }
8120 return cdmaPrlVersion;
8121 } finally {
8122 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008123 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008124 }
8125
8126 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008127 * Get snapshot of Telephony histograms
8128 * @return List of Telephony histograms
8129 * @hide
8130 */
8131 @Override
8132 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008133 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8134 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008135
8136 final long identity = Binder.clearCallingIdentity();
8137 try {
8138 return RIL.getTelephonyRILTimingHistograms();
8139 } finally {
8140 Binder.restoreCallingIdentity(identity);
8141 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008142 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008143
8144 /**
8145 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008146 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8147 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008148 * Require system privileges. In the future we may add this to carrier APIs.
8149 *
Michele Berionne482f8202018-11-27 18:57:59 -08008150 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008151 */
8152 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008153 @TelephonyManager.SetCarrierRestrictionResult
8154 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008155 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008156 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008157
Michele Berionne482f8202018-11-27 18:57:59 -08008158 if (carrierRestrictionRules == null) {
8159 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008160 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008161
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008162 final long identity = Binder.clearCallingIdentity();
8163 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008164 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008165 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008166 } finally {
8167 Binder.restoreCallingIdentity(identity);
8168 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008169 }
8170
8171 /**
8172 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008173 * Get the allowed carrier list and the excluded carrier list, including the priority between
8174 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008175 * Require system privileges. In the future we may add this to carrier APIs.
8176 *
Michele Berionne482f8202018-11-27 18:57:59 -08008177 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008178 */
8179 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008180 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008181 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008182 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008183
8184 final long identity = Binder.clearCallingIdentity();
8185 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008186 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8187 if (response instanceof CarrierRestrictionRules) {
8188 return (CarrierRestrictionRules) response;
8189 }
8190 // Response is an Exception of some kind,
8191 // which is signalled to the user as a NULL retval
8192 return null;
8193 } catch (Exception e) {
8194 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8195 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008196 } finally {
8197 Binder.restoreCallingIdentity(identity);
8198 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008199 }
8200
fionaxu59545b42016-05-25 15:53:37 -07008201 /**
fionaxu59545b42016-05-25 15:53:37 -07008202 * Action set from carrier signalling broadcast receivers to enable/disable radio
8203 * @param subId the subscription ID that this action applies to.
8204 * @param enabled control enable or disable radio.
8205 * {@hide}
8206 */
8207 @Override
8208 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8209 enforceModifyPermission();
8210 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008211
8212 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008213 if (phone == null) {
8214 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8215 return;
8216 }
8217 try {
8218 phone.carrierActionSetRadioEnabled(enabled);
8219 } catch (Exception e) {
8220 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008221 } finally {
8222 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008223 }
8224 }
8225
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008226 /**
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -07008227 * Enable or disable Voice over NR (VoNR)
8228 * @param subId the subscription ID that this action applies to.
8229 * @param enabled enable or disable VoNR.
8230 * @return operation result.
8231 */
8232 @Override
8233 public int setVoNrEnabled(int subId, boolean enabled) {
8234 enforceModifyPermission();
8235 final Phone phone = getPhone(subId);
8236
8237 final long identity = Binder.clearCallingIdentity();
8238 if (phone == null) {
8239 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8240 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8241 }
8242
8243 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8244 try {
8245 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8246 workSource);
8247 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008248
8249 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8250 if (DBG) {
8251 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8252 }
8253 SubscriptionManager.setSubscriptionProperty(
8254 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8255 (enabled ? "1" : "0"));
8256 }
8257
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -07008258 return result;
8259 } finally {
8260 Binder.restoreCallingIdentity(identity);
8261 }
8262 }
8263
8264 /**
8265 * Is voice over NR enabled
8266 * @return true if VoNR is enabled else false
8267 */
8268 @Override
8269 public boolean isVoNrEnabled(int subId) {
8270 enforceReadPrivilegedPermission("isVoNrEnabled");
8271 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8272 final long identity = Binder.clearCallingIdentity();
8273 try {
8274 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8275 null, subId, workSource);
8276 if (DBG) log("isVoNrEnabled: " + isEnabled);
8277 return isEnabled;
8278 } finally {
8279 Binder.restoreCallingIdentity(identity);
8280 }
8281 }
8282
8283 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008284 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8285 * network status based on which carrier apps could apply actions accordingly,
8286 * enable/disable default url handler for example.
8287 *
8288 * @param subId the subscription ID that this action applies to.
8289 * @param report control start/stop reporting the default network status.
8290 * {@hide}
8291 */
8292 @Override
8293 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8294 enforceModifyPermission();
8295 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008296
8297 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008298 if (phone == null) {
8299 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8300 return;
8301 }
8302 try {
8303 phone.carrierActionReportDefaultNetworkStatus(report);
8304 } catch (Exception e) {
8305 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008306 } finally {
8307 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008308 }
8309 }
8310
8311 /**
fionaxud9622282017-07-17 17:51:30 -07008312 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8313 * @param subId the subscription ID that this action applies to.
8314 * {@hide}
8315 */
8316 @Override
8317 public void carrierActionResetAll(int subId) {
8318 enforceModifyPermission();
8319 final Phone phone = getPhone(subId);
8320 if (phone == null) {
8321 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8322 return;
8323 }
8324 try {
8325 phone.carrierActionResetAll();
8326 } catch (Exception e) {
8327 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8328 }
8329 }
8330
8331 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008332 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8333 * bug report is being generated.
8334 */
8335 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008336 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008337 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8338 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008339 writer.println("Permission Denial: can't dump Phone from pid="
8340 + Binder.getCallingPid()
8341 + ", uid=" + Binder.getCallingUid()
8342 + "without permission "
8343 + android.Manifest.permission.DUMP);
8344 return;
8345 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008346 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008347 }
Jack Yueb89b242016-06-22 13:27:47 -07008348
Brad Ebingerdac2f002018-04-03 15:17:52 -07008349 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008350 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8351 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8352 @NonNull String[] args) {
8353 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8354 this, in.getFileDescriptor(), out.getFileDescriptor(),
8355 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008356 }
8357
Jack Yueb89b242016-06-22 13:27:47 -07008358 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008359 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008360 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008361 * @param reason the reason the data enable change is taking place
8362 * @param enabled True if enabling the data, otherwise disabling.
8363 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008364 */
8365 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008366 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008367 boolean enabled) {
8368 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8369 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8370 try {
8371 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008372 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008373 } catch (SecurityException se) {
8374 enforceModifyPermission();
8375 }
8376 } else {
8377 enforceModifyPermission();
8378 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008379
8380 final long identity = Binder.clearCallingIdentity();
8381 try {
8382 Phone phone = getPhone(subId);
8383 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008384 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8385 phone.carrierActionSetMeteredApnsEnabled(enabled);
8386 } else {
Jack Yu6bc9c8b2021-12-17 23:14:15 -08008387 if (phone.isUsingNewDataStack()) {
8388 phone.getDataSettingsManager().setDataEnabled(reason, enabled);
8389 } else {
8390 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8391 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008392 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008393 }
8394 } finally {
8395 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008396 }
8397 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008398
8399 /**
8400 * Get Client request stats
8401 * @return List of Client Request Stats
8402 * @hide
8403 */
8404 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008405 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8406 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008407 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008408 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008409 return null;
8410 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008411 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008412
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008413 final long identity = Binder.clearCallingIdentity();
8414 try {
8415 if (phone != null) {
8416 return phone.getClientRequestStats();
8417 }
8418
8419 return null;
8420 } finally {
8421 Binder.restoreCallingIdentity(identity);
8422 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008423 }
8424
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008425 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008426 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008427 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008428 }
Jack Yueb4124c2017-02-16 15:32:43 -08008429
8430 /**
Grace Chen70990072017-03-24 17:21:30 -07008431 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008432 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008433 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008434 * @param state State of SIM (power down, power up, pass through)
8435 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8436 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8437 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008438 *
8439 **/
8440 @Override
Grace Chen70990072017-03-24 17:21:30 -07008441 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008442 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008443 Phone phone = PhoneFactory.getPhone(slotIndex);
8444
vagdeviaf9a5b92018-08-15 16:01:53 -07008445 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8446
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008447 final long identity = Binder.clearCallingIdentity();
8448 try {
8449 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008450 phone.setSimPowerState(state, null, workSource);
8451 }
8452 } finally {
8453 Binder.restoreCallingIdentity(identity);
8454 }
8455 }
8456
8457 /**
8458 * Set SIM card power state.
8459 *
8460 * @param slotIndex SIM slot id.
8461 * @param state State of SIM (power down, power up, pass through)
8462 * @param callback callback to trigger after success or failure
8463 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8464 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8465 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8466 *
8467 **/
8468 @Override
8469 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8470 IIntegerConsumer callback) {
8471 enforceModifyPermission();
8472 Phone phone = PhoneFactory.getPhone(slotIndex);
8473
8474 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8475
8476 final long identity = Binder.clearCallingIdentity();
8477 try {
8478 if (phone != null) {
8479 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8480 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008481 }
8482 } finally {
8483 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008484 }
8485 }
Shuo Qiandd210312017-04-12 22:11:33 +00008486
Tyler Gunn65d45c22017-06-05 11:22:26 -07008487 private boolean isUssdApiAllowed(int subId) {
8488 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008489 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008490 if (configManager == null) {
8491 return false;
8492 }
8493 PersistableBundle pb = configManager.getConfigForSubId(subId);
8494 if (pb == null) {
8495 return false;
8496 }
8497 return pb.getBoolean(
8498 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8499 }
8500
Shuo Qiandd210312017-04-12 22:11:33 +00008501 /**
8502 * Check if phone is in emergency callback mode
8503 * @return true if phone is in emergency callback mode
8504 * @param subId sub id
8505 */
goneil9c5f4872017-12-05 14:07:56 -08008506 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008507 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008508 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008509 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008510
8511 final long identity = Binder.clearCallingIdentity();
8512 try {
8513 if (phone != null) {
8514 return phone.isInEcm();
8515 } else {
8516 return false;
8517 }
8518 } finally {
8519 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008520 }
8521 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008522
8523 /**
8524 * Get the current signal strength information for the given subscription.
8525 * Because this information is not updated when the device is in a low power state
8526 * it should not be relied-upon to be current.
8527 * @param subId Subscription index
8528 * @return the most recent cached signal strength info from the modem
8529 */
8530 @Override
8531 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008532 final long identity = Binder.clearCallingIdentity();
8533 try {
8534 Phone p = getPhone(subId);
8535 if (p == null) {
8536 return null;
8537 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008538
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008539 return p.getSignalStrength();
8540 } finally {
8541 Binder.restoreCallingIdentity(identity);
8542 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008543 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008544
Pengquan Meng77b7f132018-08-22 14:49:57 -07008545 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008546 * Get the current modem radio state for the given slot.
8547 * @param slotIndex slot index.
8548 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008549 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008550 * @return the current radio power state from the modem
8551 */
8552 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008553 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008554 Phone phone = PhoneFactory.getPhone(slotIndex);
8555 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008556 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8557 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008558 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8559 }
8560
8561 final long identity = Binder.clearCallingIdentity();
8562 try {
8563 return phone.getRadioPowerState();
8564 } finally {
8565 Binder.restoreCallingIdentity(identity);
8566 }
8567 }
8568 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8569 }
8570
8571 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008572 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8573 *
8574 * <p>Requires one of the following permissions:
8575 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008576 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008577 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8578 * privileges.
8579 *
8580 * @param subId subscription id
8581 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8582 * {@code false}.
8583 */
8584 @Override
8585 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008586 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008587 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008588 try {
8589 mApp.enforceCallingOrSelfPermission(
8590 android.Manifest.permission.ACCESS_NETWORK_STATE,
8591 functionName);
8592 } catch (Exception e) {
8593 mApp.enforceCallingOrSelfPermission(
8594 permission.READ_BASIC_PHONE_STATE, functionName);
8595 }
Shuo Qian093013d2020-08-13 15:42:55 -07008596 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008597 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008598 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008599 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008600
Pengquan Menga1bb6272018-09-06 09:59:22 -07008601 boolean isEnabled = false;
8602 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008603 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008604 Phone phone = getPhone(subId);
8605 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008606 } finally {
8607 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008608 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008609 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008610 }
8611
8612
8613 /**
8614 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8615 *
8616 * <p> Requires permission:
8617 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8618 * privileges.
8619 *
8620 * @param subId subscription id
8621 * @param isEnabled {@code true} means enable, {@code false} means disable.
8622 */
8623 @Override
8624 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008625 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8626 mApp, subId, "setDataRoamingEnabled");
8627
Pengquan Menga1bb6272018-09-06 09:59:22 -07008628 final long identity = Binder.clearCallingIdentity();
8629 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008630 Phone phone = getPhone(subId);
8631 if (phone != null) {
8632 phone.setDataRoamingEnabled(isEnabled);
8633 }
8634 } finally {
8635 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008636 }
8637 }
8638
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008639 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008640 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008641 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008642 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008643 mApp, subId, "isManualNetworkSelectionAllowed");
8644
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008645 boolean isAllowed = true;
8646 final long identity = Binder.clearCallingIdentity();
8647 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008648 Phone phone = getPhone(subId);
8649 if (phone != null) {
8650 isAllowed = phone.isCspPlmnEnabled();
8651 }
8652 } finally {
8653 Binder.restoreCallingIdentity(identity);
8654 }
8655 return isAllowed;
8656 }
8657
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008658 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8659 UiccProfile profile = port.getUiccProfile();
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08008660 if (profile == null) {
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008661 return false;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008662 }
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08008663 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8664 if (phone == null) {
8665 return false;
8666 }
8667 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8668 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8669 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008670 }
8671
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008672 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008673 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjs29b7e8e2021-11-17 04:05:58 +00008674 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008675 mApp.getSystemService(AppOpsManager.class)
8676 .checkPackage(Binder.getCallingUid(), callingPackage);
8677
Jordan Liu1e142fc2019-04-22 15:10:43 -07008678 boolean hasReadPermission = false;
sandeepjs0a502c42021-09-27 15:34:44 +00008679 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008680 try {
8681 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008682 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008683 } catch (SecurityException e) {
8684 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8685 // has carrier privileges on an active UICC
8686 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8687 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008688 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008689 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008690 }
sandeepjs0a502c42021-09-27 15:34:44 +00008691 // checking compatibility, if calling app's target SDK is T and beyond.
8692 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8693 Binder.getCallingUid())) {
8694 isIccIdAccessRestricted = true;
8695 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008696 final long identity = Binder.clearCallingIdentity();
8697 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008698 UiccController uiccController = UiccController.getInstance();
8699 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008700 if (hasReadPermission) {
8701 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008702 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008703
8704 // Remove private info if the caller doesn't have access
8705 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8706 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjs0a502c42021-09-27 15:34:44 +00008707 //setting the value after compatibility check
8708 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008709 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8710 // is available
sandeepjs0a502c42021-09-27 15:34:44 +00008711 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008712 if (card == null) {
8713 // assume no access if the card is unavailable
sandeepjs0a502c42021-09-27 15:34:44 +00008714 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008715 continue;
8716 }
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008717 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8718 if (portInfos.isEmpty()) {
sandeepjs0a502c42021-09-27 15:34:44 +00008719 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008720 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008721 }
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008722 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8723 for (UiccPortInfo portInfo : portInfos) {
8724 UiccPort port = uiccController.getUiccPortForSlot(
8725 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8726 if (port == null) {
8727 // assume no access if port is null
8728 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8729 continue;
8730 }
8731 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8732 uiccPortInfos.add(portInfo);
8733 } else {
8734 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8735 }
8736 }
8737 filteredInfos.add(new UiccCardInfo(
8738 cardInfo.isEuicc(),
8739 cardInfo.getCardId(),
8740 null,
8741 cardInfo.getPhysicalSlotIndex(),
8742 cardInfo.isRemovable(),
8743 cardInfo.isMultipleEnabledProfilesSupported(),
8744 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008745 }
8746 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008747 } finally {
8748 Binder.restoreCallingIdentity(identity);
8749 }
8750 }
8751
sandeepjs0a502c42021-09-27 15:34:44 +00008752 /**
8753 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8754 * generally private and require carrier privileges to view.
8755 *
8756 * @hide
8757 */
8758 @NonNull
8759 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8760 List<UiccPortInfo> portinfo = new ArrayList<>();
8761 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8762 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8763 }
8764 return new UiccCardInfo(
8765 cardInfo.isEuicc(),
8766 cardInfo.getCardId(),
8767 null,
8768 cardInfo.getPhysicalSlotIndex(),
8769 cardInfo.isRemovable(),
8770 cardInfo.isMultipleEnabledProfilesSupported(),
8771 portinfo
8772 );
8773 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008774
sandeepjs0a502c42021-09-27 15:34:44 +00008775 /**
8776 * @hide
8777 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8778 * These values are generally private and require carrier privileges to view.
8779 */
8780 @NonNull
8781 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8782 return new UiccPortInfo(
8783 UiccPortInfo.ICCID_REDACTED,
8784 portInfo.getPortIndex(),
8785 portInfo.getLogicalSlotIndex(),
8786 portInfo.isActive()
8787 );
8788 }
8789 @Override
8790 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjs29b7e8e2021-11-17 04:05:58 +00008791 // Verify that the callingPackage belongs to the calling UID
sandeepjs0a502c42021-09-27 15:34:44 +00008792 mApp.getSystemService(AppOpsManager.class)
8793 .checkPackage(Binder.getCallingUid(), callingPackage);
8794
8795 boolean hasReadPermission = false;
8796 boolean isLogicalSlotAccessRestricted = false;
sandeepjs0a502c42021-09-27 15:34:44 +00008797
8798 try {
8799 enforceReadPrivilegedPermission("getUiccSlotsInfo");
8800 hasReadPermission = true;
8801 } catch (SecurityException e) {
8802 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8803 // has carrier privileges on an active UICC
8804 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8805 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8806 hasReadPermission = true;
8807 }
8808 }
8809
8810 // checking compatibility, if calling app's target SDK is T and beyond.
8811 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8812 Binder.getCallingUid())) {
8813 isLogicalSlotAccessRestricted = true;
8814 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008815 final long identity = Binder.clearCallingIdentity();
8816 try {
8817 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8818 if (slots == null) {
8819 Rlog.i(LOG_TAG, "slots is null.");
8820 return null;
8821 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008822 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8823 for (int i = 0; i < slots.length; i++) {
8824 UiccSlot slot = slots[i];
8825 if (slot == null) {
8826 continue;
8827 }
8828
Jordan Liu7be7e652019-05-06 18:55:02 +00008829 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008830 UiccCard card = slot.getUiccCard();
8831 if (card != null) {
8832 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008833 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008834 cardId = slot.getEid();
8835 if (TextUtils.isEmpty(cardId)) {
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008836 // If cardId is null, use iccId of default port as cardId. Check if has
8837 // read permission otherwise set to null.(card is null which means no
8838 // carrier permission)
8839 cardId = hasReadPermission ? slot.getIccId(
8840 TelephonyManager.DEFAULT_PORT_INDEX) : null;
Jordan Liu01bd00d2019-09-12 16:19:43 -07008841 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008842 }
8843
Jordan Liu857451f2019-05-09 16:35:35 -07008844 if (cardId != null) {
8845 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8846 // if cardId is an EID, it's all digits so this is fine
8847 cardId = IccUtils.stripTrailingFs(cardId);
8848 }
8849
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008850 int cardState = 0;
8851 switch (slot.getCardState()) {
8852 case CARDSTATE_ABSENT:
8853 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8854 break;
8855 case CARDSTATE_PRESENT:
8856 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8857 break;
8858 case CARDSTATE_ERROR:
8859 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8860 break;
8861 case CARDSTATE_RESTRICTED:
8862 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8863 break;
8864 default:
8865 break;
8866
8867 }
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008868 List<UiccPortInfo> portInfos = new ArrayList<>();
8869 int[] portIndexes = slot.getPortList();
8870 for (int portIdx : portIndexes) {
8871 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
8872 callingPackage, hasReadPermission));
8873 if (slot.isPortActive(portIdx)) {
8874 UiccPort port = slot.getUiccCard().getUiccPort(portIdx);
8875 portInfos.add(new UiccPortInfo(iccId, port.getPortIdx(),
8876 port.getPhoneId(), true));
8877 } else {
8878 portInfos.add(new UiccPortInfo(iccId, portIdx, -1, false));
8879 }
8880 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008881 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008882 slot.isEuicc(),
8883 cardId,
8884 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08008885 slot.isExtendedApduSupported(),
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008886 slot.isRemovable(), portInfos);
sandeepjs0a502c42021-09-27 15:34:44 +00008887 //setting the value after compatibility check
8888 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008889 }
8890 return infos;
8891 } finally {
8892 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008893 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008894 }
8895
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008896 /* Returns null if doesn't have read permission or carrier privilege access. */
8897 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
8898 boolean hasReadPermission) {
8899 String iccId = slot.getIccId(portIndex);
8900 if (hasReadPermission) { // if has read permission
8901 return iccId;
8902 } else {
8903 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
8904 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
8905 // if no read permission, checking carrier privilege access
8906 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8907 return iccId;
8908 }
8909 }
8910 }
8911 // No read permission or carrier privilege access.
8912 return UiccPortInfo.ICCID_REDACTED;
8913 }
8914
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008915 @Override
sandeepjs0a502c42021-09-27 15:34:44 +00008916 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008917 public boolean switchSlots(int[] physicalSlots) {
8918 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008919
8920 final long identity = Binder.clearCallingIdentity();
8921 try {
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008922 List<UiccSlotMapping> slotMappings = new ArrayList<>();
8923 for (int i = 0; i < physicalSlots.length; i++) {
8924 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
8925 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
8926 physicalSlots[i], i));
8927 }
8928 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008929 } finally {
8930 Binder.restoreCallingIdentity(identity);
8931 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008932 }
Jack Yu4c988042018-02-27 15:30:01 -08008933
8934 @Override
sandeepjs0a502c42021-09-27 15:34:44 +00008935 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
8936 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
8937 enforceModifyPermission();
8938
8939 final long identity = Binder.clearCallingIdentity();
8940 try {
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008941 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjs0a502c42021-09-27 15:34:44 +00008942 } finally {
8943 Binder.restoreCallingIdentity(identity);
8944 }
8945 }
8946
8947 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008948 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008949 final long identity = Binder.clearCallingIdentity();
8950 try {
8951 return UiccController.getInstance().getCardIdForDefaultEuicc();
8952 } finally {
8953 Binder.restoreCallingIdentity(identity);
8954 }
8955 }
8956
Pengquan Meng85728fb2018-03-12 16:31:21 -07008957 /**
goneil47ffb6e2018-04-06 15:40:58 -07008958 * A test API to reload the UICC profile.
8959 *
8960 * <p>Requires that the calling app has permission
8961 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8962 * @hide
8963 */
8964 @Override
8965 public void refreshUiccProfile(int subId) {
8966 enforceModifyPermission();
8967
8968 final long identity = Binder.clearCallingIdentity();
8969 try {
8970 Phone phone = getPhone(subId);
8971 if (phone == null) {
8972 return;
8973 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008974 UiccPort uiccPort = phone.getUiccPort();
8975 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07008976 return;
8977 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008978 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07008979 if (uiccProfile == null) {
8980 return;
8981 }
8982 uiccProfile.refresh();
8983 } finally {
8984 Binder.restoreCallingIdentity(identity);
8985 }
8986 }
8987
8988 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008989 * Returns false if the mobile data is disabled by default, otherwise return true.
8990 */
8991 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008992 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008993 }
8994
8995 /**
8996 * Returns true if the data roaming is enabled by default, i.e the system property
8997 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8998 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8999 */
9000 private boolean getDefaultDataRoamingEnabled(int subId) {
9001 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009002 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009003 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009004 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9005 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9006 return isDataRoamingEnabled;
9007 }
9008
9009 /**
9010 * Returns the default network type for the given {@code subId}, if the default network type is
9011 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9012 */
9013 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009014 List<Integer> list = TelephonyProperties.default_network();
9015 int phoneId = mSubscriptionController.getPhoneId(subId);
9016 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9017 return list.get(phoneId);
9018 }
9019 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009020 }
fionaxua13278b2018-03-21 00:08:13 -07009021
9022 @Override
9023 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009024 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009025 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009026
9027 final long identity = Binder.clearCallingIdentity();
9028 try {
9029 final Phone phone = getPhone(subId);
9030 if (phone == null) {
9031 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9032 return;
9033 }
Rambo Wanga7436882022-01-13 21:51:44 -08009034 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9035 if (cpt != null) {
9036 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9037 }
9038 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009039 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9040 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009041 if (carrierPrivilegeRules == null) {
9042 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9043 } else {
9044 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9045 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009046 } finally {
9047 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009048 }
fionaxua13278b2018-03-21 00:08:13 -07009049 }
9050
9051 @Override
9052 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009053 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009054
9055 final long identity = Binder.clearCallingIdentity();
9056 try {
9057 final Phone phone = getPhone(subId);
9058 if (phone == null) {
9059 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9060 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9061 }
9062 return phone.getCarrierIdListVersion();
9063 } finally {
9064 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009065 }
fionaxua13278b2018-03-21 00:08:13 -07009066 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009067
9068 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009069 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9070 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009071 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009072 mApp, subId, callingPackage, callingFeatureId,
9073 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009074 return -1;
9075 }
9076
9077 final long identity = Binder.clearCallingIdentity();
9078 try {
9079 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9080 } finally {
9081 Binder.restoreCallingIdentity(identity);
9082 }
9083 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009084
9085 @Override
9086 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009087 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009088 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009089 mApp, subId, "getCdmaRoamingMode");
9090
9091 final long identity = Binder.clearCallingIdentity();
9092 try {
9093 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9094 } finally {
9095 Binder.restoreCallingIdentity(identity);
9096 }
9097 }
9098
9099 @Override
9100 public boolean setCdmaRoamingMode(int subId, int mode) {
9101 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9102 mApp, subId, "setCdmaRoamingMode");
9103
9104 final long identity = Binder.clearCallingIdentity();
9105 try {
9106 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9107 } finally {
9108 Binder.restoreCallingIdentity(identity);
9109 }
9110 }
9111
9112 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009113 public int getCdmaSubscriptionMode(int subId) {
9114 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009115 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009116 mApp, subId, "getCdmaSubscriptionMode");
9117
9118 final long identity = Binder.clearCallingIdentity();
9119 try {
9120 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9121 } finally {
9122 Binder.restoreCallingIdentity(identity);
9123 }
9124 }
9125
9126 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009127 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9128 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9129 mApp, subId, "setCdmaSubscriptionMode");
9130
9131 final long identity = Binder.clearCallingIdentity();
9132 try {
9133 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9134 } finally {
9135 Binder.restoreCallingIdentity(identity);
9136 }
9137 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009138
sqianc5eccab2018-10-19 18:46:41 -07009139 @Override
sqian8c685422019-02-22 15:55:18 -08009140 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009141 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009142 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009143 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9144 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009145 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9146 }
9147 final long identity = Binder.clearCallingIdentity();
9148 try {
sqian854d44b2018-12-12 16:48:18 -08009149 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9150 for (Phone phone: PhoneFactory.getPhones()) {
9151 if (phone.getEmergencyNumberTracker() != null
9152 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9153 emergencyNumberListInternal.put(
9154 phone.getSubId(),
9155 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9156 }
sqian11b7a0e2018-12-05 18:48:28 -08009157 }
sqian854d44b2018-12-12 16:48:18 -08009158 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009159 } finally {
9160 Binder.restoreCallingIdentity(identity);
9161 }
sqianc5eccab2018-10-19 18:46:41 -07009162 }
9163
9164 @Override
sqian8c685422019-02-22 15:55:18 -08009165 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009166 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009167 if (!exactMatch) {
9168 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009169 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009170 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009171 }
9172 final long identity = Binder.clearCallingIdentity();
9173 try {
sqian854d44b2018-12-12 16:48:18 -08009174 for (Phone phone: PhoneFactory.getPhones()) {
9175 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009176 && phone.getEmergencyNumberTracker()
9177 .isEmergencyNumber(number, exactMatch)) {
9178 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009179 }
sqian11b7a0e2018-12-05 18:48:28 -08009180 }
9181 return false;
9182 } finally {
9183 Binder.restoreCallingIdentity(identity);
9184 }
9185 }
9186
sqianf4ca7ed2019-01-15 18:32:07 -08009187 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009188 * Start emergency callback mode for GsmCdmaPhone for testing.
9189 */
9190 @Override
9191 public void startEmergencyCallbackMode() {
9192 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9193 "startEmergencyCallbackMode");
9194 enforceModifyPermission();
9195 final long identity = Binder.clearCallingIdentity();
9196 try {
9197 for (Phone phone : PhoneFactory.getPhones()) {
9198 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9199 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9200 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9201 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9202 gsmCdmaPhone.obtainMessage(
9203 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9204 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9205 }
9206 }
9207 } finally {
9208 Binder.restoreCallingIdentity(identity);
9209 }
9210 }
9211
9212 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009213 * Update emergency number list for test mode.
9214 */
9215 @Override
9216 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9217 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9218 "updateEmergencyNumberListTestMode");
9219
9220 final long identity = Binder.clearCallingIdentity();
9221 try {
9222 for (Phone phone: PhoneFactory.getPhones()) {
9223 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9224 if (tracker != null) {
9225 tracker.executeEmergencyNumberTestModeCommand(action, num);
9226 }
9227 }
9228 } finally {
9229 Binder.restoreCallingIdentity(identity);
9230 }
9231 }
9232
9233 /**
9234 * Get the full emergency number list for test mode.
9235 */
9236 @Override
9237 public List<String> getEmergencyNumberListTestMode() {
9238 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9239 "getEmergencyNumberListTestMode");
9240
9241 final long identity = Binder.clearCallingIdentity();
9242 try {
9243 Set<String> emergencyNumbers = new HashSet<>();
9244 for (Phone phone: PhoneFactory.getPhones()) {
9245 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9246 if (tracker != null) {
9247 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9248 emergencyNumbers.add(num.getNumber());
9249 }
9250 }
9251 }
9252 return new ArrayList<>(emergencyNumbers);
9253 } finally {
9254 Binder.restoreCallingIdentity(identity);
9255 }
9256 }
9257
chen xud6b45bd2018-10-30 22:27:10 -07009258 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009259 public int getEmergencyNumberDbVersion(int subId) {
9260 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9261
9262 final long identity = Binder.clearCallingIdentity();
9263 try {
9264 final Phone phone = getPhone(subId);
9265 if (phone == null) {
9266 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9267 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9268 }
9269 return phone.getEmergencyNumberDbVersion();
9270 } finally {
9271 Binder.restoreCallingIdentity(identity);
9272 }
9273 }
9274
9275 @Override
9276 public void notifyOtaEmergencyNumberDbInstalled() {
9277 enforceModifyPermission();
9278
9279 final long identity = Binder.clearCallingIdentity();
9280 try {
9281 for (Phone phone: PhoneFactory.getPhones()) {
9282 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9283 if (tracker != null) {
9284 tracker.updateOtaEmergencyNumberDatabase();
9285 }
9286 }
9287 } finally {
9288 Binder.restoreCallingIdentity(identity);
9289 }
9290 }
9291
9292 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009293 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009294 enforceActiveEmergencySessionPermission();
9295
9296 final long identity = Binder.clearCallingIdentity();
9297 try {
9298 for (Phone phone: PhoneFactory.getPhones()) {
9299 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9300 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009301 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9302 }
9303 }
9304 } finally {
9305 Binder.restoreCallingIdentity(identity);
9306 }
9307 }
9308
9309 @Override
9310 public void resetOtaEmergencyNumberDbFilePath() {
9311 enforceActiveEmergencySessionPermission();
9312
9313 final long identity = Binder.clearCallingIdentity();
9314 try {
9315 for (Phone phone: PhoneFactory.getPhones()) {
9316 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9317 if (tracker != null) {
9318 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009319 }
9320 }
9321 } finally {
9322 Binder.restoreCallingIdentity(identity);
9323 }
9324 }
9325
9326 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009327 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9328 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9329 Phone phone = getPhone(subId);
9330 if (phone == null) {
9331 return null;
9332 }
9333 final long identity = Binder.clearCallingIdentity();
9334 try {
9335 UiccProfile profile = UiccController.getInstance()
9336 .getUiccProfileForPhone(phone.getPhoneId());
9337 if (profile != null) {
9338 return profile.getCertsFromCarrierPrivilegeAccessRules();
9339 }
9340 } finally {
9341 Binder.restoreCallingIdentity(identity);
9342 }
9343 return null;
9344 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009345
9346 /**
9347 * Enable or disable a modem stack.
9348 */
9349 @Override
9350 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9351 enforceModifyPermission();
9352
9353 final long identity = Binder.clearCallingIdentity();
9354 try {
9355 Phone phone = PhoneFactory.getPhone(slotIndex);
9356 if (phone == null) {
9357 return false;
9358 } else {
9359 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9360 }
9361 } finally {
9362 Binder.restoreCallingIdentity(identity);
9363 }
9364 }
Michelecea4cf22018-12-21 15:00:11 -08009365
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009366 /**
9367 * Whether a modem stack is enabled or not.
9368 */
9369 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009370 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9371 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009372 Phone phone = PhoneFactory.getPhone(slotIndex);
9373 if (phone == null) return false;
9374
9375 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009376 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9377 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009378 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9379 }
9380
9381 final long identity = Binder.clearCallingIdentity();
9382 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009383 try {
9384 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9385 } catch (NoSuchElementException ex) {
9386 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9387 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009388 } finally {
9389 Binder.restoreCallingIdentity(identity);
9390 }
9391 }
9392
Michelecea4cf22018-12-21 15:00:11 -08009393 @Override
Michele0ea7d782019-03-19 14:58:42 -07009394 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009395 enforceModifyPermission();
9396
9397 final long identity = Binder.clearCallingIdentity();
9398 try {
9399 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009400 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009401 .commit();
9402 } finally {
9403 Binder.restoreCallingIdentity(identity);
9404 }
9405 }
9406
9407 @Override
Michele0ea7d782019-03-19 14:58:42 -07009408 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009409 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009410 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009411 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9412 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009413 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009414 }
Michelecea4cf22018-12-21 15:00:11 -08009415
9416 final long identity = Binder.clearCallingIdentity();
9417 try {
Michele0ea7d782019-03-19 14:58:42 -07009418 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009419 } finally {
9420 Binder.restoreCallingIdentity(identity);
9421 }
9422 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009423
Michele0ea7d782019-03-19 14:58:42 -07009424 @TelephonyManager.IsMultiSimSupportedResult
9425 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009426 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9427 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9428 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009429 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9430 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009431 }
9432 // Check if the hardware supports multisim functionality. If usage of multisim is not
9433 // supported by the modem, indicate that it is restricted.
9434 PhoneCapability staticCapability =
9435 mPhoneConfigurationManager.getStaticPhoneCapability();
9436 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009437 loge("isMultiSimSupportedInternal: no static configuration available");
9438 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009439 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009440 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009441 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9442 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009443 }
9444 // Check if support of multiple SIMs is restricted by carrier
9445 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009446 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009447 }
9448
Michele0ea7d782019-03-19 14:58:42 -07009449 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009450 }
9451
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009452 /**
9453 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009454 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9455 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9456 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009457 * @param numOfSims number of active sims we want to switch to
9458 */
9459 @Override
9460 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009461 if (numOfSims == 1) {
9462 enforceModifyPermission();
9463 } else {
9464 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9465 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9466 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009467 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009468
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009469 try {
Michele30b57b22019-03-01 12:01:14 -08009470 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009471 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009472 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9473 return;
9474 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009475 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9476 } finally {
9477 Binder.restoreCallingIdentity(identity);
9478 }
9479 }
9480
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009481 @Override
9482 public boolean isApplicationOnUicc(int subId, int appType) {
9483 enforceReadPrivilegedPermission("isApplicationOnUicc");
9484 Phone phone = getPhone(subId);
9485 if (phone == null) {
9486 return false;
9487 }
9488 final long identity = Binder.clearCallingIdentity();
9489 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009490 UiccPort uiccPort = phone.getUiccPort();
9491 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009492 return false;
9493 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009494 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009495 if (uiccProfile == null) {
9496 return false;
9497 }
9498 if (TelephonyManager.APPTYPE_SIM <= appType
9499 && appType <= TelephonyManager.APPTYPE_ISIM) {
9500 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9501 }
9502 return false;
9503 } finally {
9504 Binder.restoreCallingIdentity(identity);
9505 }
9506 }
9507
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009508 /**
chen xub4baa772019-04-03 10:23:41 -07009509 * Get whether making changes to modem configurations will trigger reboot.
9510 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009511 */
9512 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009513 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9514 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009515 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009516 mApp, subId, callingPackage, callingFeatureId,
9517 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009518 return false;
9519 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009520 final long identity = Binder.clearCallingIdentity();
9521 try {
9522 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9523 } finally {
9524 Binder.restoreCallingIdentity(identity);
9525 }
9526 }
9527
Nathan Harold29f5f052019-02-15 13:41:57 -08009528 private void updateModemStateMetrics() {
9529 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9530 // TODO: check the state for each modem if the api is ready.
9531 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9532 }
9533
Pengquan Meng3889a572019-01-23 11:16:29 -08009534 @Override
sandeepjs29b7e8e2021-11-17 04:05:58 +00009535 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009536 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjs29b7e8e2021-11-17 04:05:58 +00009537 // Verify that the callingPackage belongs to the calling UID
9538 mApp.getSystemService(AppOpsManager.class)
9539 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009540 final long identity = Binder.clearCallingIdentity();
sandeepjs29b7e8e2021-11-17 04:05:58 +00009541 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009542 try {
sandeepjs29b7e8e2021-11-17 04:05:58 +00009543 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9544 if (slotInfos != null) {
9545 for (int i = 0; i < slotInfos.length; i++) {
9546 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9547 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9548 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9549 portInfo.getLogicalSlotIndex()));
9550 }
9551 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009552 }
9553 }
sandeepjs29b7e8e2021-11-17 04:05:58 +00009554 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009555 } finally {
9556 Binder.restoreCallingIdentity(identity);
9557 }
9558 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009559
9560 /**
9561 * Get the IRadio HAL Version
9562 */
9563 @Override
9564 public int getRadioHalVersion() {
9565 Phone phone = getDefaultPhone();
9566 if (phone == null) return -1;
9567 HalVersion hv = phone.getHalVersion();
9568 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9569 return hv.major * 100 + hv.minor;
9570 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009571
9572 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009573 * Get the current calling package name.
9574 * @return the current calling package name
9575 */
9576 @Override
9577 public String getCurrentPackageName() {
9578 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9579 }
9580
9581 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009582 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9583 * corresponding network requests on a subId.
9584 *
9585 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009586 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009587 * 2) APN is un-metered for this subscription, or
9588 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009589 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009590 *
9591 * @return whether data is allowed for a apn type.
9592 *
9593 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009594 */
9595 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009596 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009597 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9598 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009599
9600 // Now that all security checks passes, perform the operation as ourselves.
9601 final long identity = Binder.clearCallingIdentity();
9602 try {
9603 Phone phone = getPhone(subId);
9604 if (phone == null) return false;
9605
Jack Yu41407ee2019-05-13 16:54:09 -07009606 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009607 boolean isDataEnabled;
9608 if (phone.isUsingNewDataStack()) {
9609 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
9610 } else {
9611 isDataEnabled = phone.getDataEnabledSettings().isDataEnabled(apnType);
9612 }
9613 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009614 } finally {
9615 Binder.restoreCallingIdentity(identity);
9616 }
9617 }
9618
9619 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009620 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009621 enforceReadPrivilegedPermission("isApnMetered");
9622
9623 // Now that all security checks passes, perform the operation as ourselves.
9624 final long identity = Binder.clearCallingIdentity();
9625 try {
9626 Phone phone = getPhone(subId);
9627 if (phone == null) return true; // By default return true.
9628
Jack Yu41407ee2019-05-13 16:54:09 -07009629 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009630 } finally {
9631 Binder.restoreCallingIdentity(identity);
9632 }
9633 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009634
9635 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009636 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9637 int subscriptionId, IBooleanConsumer resultCallback) {
9638 enforceModifyPermission();
9639 long token = Binder.clearCallingIdentity();
9640 try {
9641 Phone phone = getPhone(subscriptionId);
9642 if (phone == null) {
9643 try {
9644 if (resultCallback != null) {
9645 resultCallback.accept(false);
9646 }
9647 } catch (RemoteException e) {
9648 // ignore
9649 }
9650 return;
9651 }
9652 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9653 Pair.create(specifiers, (x) -> {
9654 try {
9655 if (resultCallback != null) {
9656 resultCallback.accept(x);
9657 }
9658 } catch (RemoteException e) {
9659 // ignore
9660 }
9661 });
9662 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9663 } finally {
9664 Binder.restoreCallingIdentity(token);
9665 }
9666 }
9667
9668 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009669 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9670 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009671 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009672 mApp, subId, "getSystemSelectionChannels");
9673 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9674 final long identity = Binder.clearCallingIdentity();
9675 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009676 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9677 if (result instanceof IllegalStateException) {
9678 throw (IllegalStateException) result;
9679 }
9680 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009681 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9682 return specifiers;
9683 } finally {
9684 Binder.restoreCallingIdentity(identity);
9685 }
9686 }
9687
9688 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009689 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009690 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009691 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9692 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9693 if (iccRecords == null) {
9694 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9695 return false;
9696 }
9697 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9698 }
9699
9700 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009701 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9702 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009703 if (callingPackage == null) {
9704 callingPackage = getCurrentPackageName();
9705 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009706 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9707 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009708 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9709 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009710 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9711 }
9712 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9713 Intent intent = new Intent();
9714 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9715 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9716 // Bring up choose default SMS subscription dialog right now
9717 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9718 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9719 mApp.startActivity(intent);
9720 }
chen xud5ca2d52019-05-28 15:20:57 -07009721
9722 @Override
9723 public String getMmsUAProfUrl(int subId) {
9724 //TODO investigate if this API should require proper permission check in R b/133791609
9725 final long identity = Binder.clearCallingIdentity();
9726 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009727 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9728 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9729 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9730 return carrierUAProfUrl;
9731 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009732 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9733 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009734 } finally {
9735 Binder.restoreCallingIdentity(identity);
9736 }
9737 }
9738
9739 @Override
9740 public String getMmsUserAgent(int subId) {
9741 //TODO investigate if this API should require proper permission check in R b/133791609
9742 final long identity = Binder.clearCallingIdentity();
9743 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009744 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9745 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9746 if (!TextUtils.isEmpty(carrierUserAgent)) {
9747 return carrierUserAgent;
9748 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009749 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9750 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009751 } finally {
9752 Binder.restoreCallingIdentity(identity);
9753 }
9754 }
Jack Yub07d4972019-05-28 16:12:25 -07009755
9756 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009757 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9758 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009759
Jack Yub07d4972019-05-28 16:12:25 -07009760 final long identity = Binder.clearCallingIdentity();
9761 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009762 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009763 if (phone == null) return false;
9764
Hall Liua62f5da2020-09-25 10:42:19 -07009765 switch (policy) {
9766 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009767 if (phone.isUsingNewDataStack()) {
9768 return phone.getDataSettingsManager().isDataAllowedInVoiceCall();
9769 } else {
9770 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9771 }
Hall Liua62f5da2020-09-25 10:42:19 -07009772 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009773 if (phone.isUsingNewDataStack()) {
9774 return phone.getDataSettingsManager().isMmsAlwaysAllowed();
9775 } else {
9776 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9777 }
Hall Liua62f5da2020-09-25 10:42:19 -07009778 default:
9779 throw new IllegalArgumentException(policy + " is not a valid policy");
9780 }
Jack Yub07d4972019-05-28 16:12:25 -07009781 } finally {
9782 Binder.restoreCallingIdentity(identity);
9783 }
9784 }
9785
9786 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009787 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009788 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009789 enforceModifyPermission();
9790
changbettyd5c246e2019-12-24 15:40:37 +08009791 final long identity = Binder.clearCallingIdentity();
9792 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009793 Phone phone = getPhone(subscriptionId);
9794 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009795
Hall Liua62f5da2020-09-25 10:42:19 -07009796 switch (policy) {
9797 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009798 if (phone.isUsingNewDataStack()) {
9799 phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled);
9800 } else {
9801 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9802 }
Hall Liua62f5da2020-09-25 10:42:19 -07009803 break;
9804 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009805 if (phone.isUsingNewDataStack()) {
9806 phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled);
9807 } else {
9808 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9809 }
Hall Liua62f5da2020-09-25 10:42:19 -07009810 break;
9811 default:
9812 throw new IllegalArgumentException(policy + " is not a valid policy");
9813 }
changbettyd5c246e2019-12-24 15:40:37 +08009814 } finally {
9815 Binder.restoreCallingIdentity(identity);
9816 }
9817 }
9818
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009819 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009820 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009821 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9822 * otherwise.
9823 */
9824 @Override
9825 public void setCepEnabled(boolean isCepEnabled) {
9826 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9827
9828 final long identity = Binder.clearCallingIdentity();
9829 try {
9830 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9831 for (Phone phone : PhoneFactory.getPhones()) {
9832 Phone defaultPhone = phone.getImsPhone();
9833 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9834 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9835 ImsPhoneCallTracker imsPhoneCallTracker =
9836 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9837 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9838 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9839 + imsPhone.getMsisdn());
9840 }
9841 }
9842 } finally {
9843 Binder.restoreCallingIdentity(identity);
9844 }
9845 }
allenwtsu46dcc572020-01-08 18:24:03 +08009846
9847 /**
9848 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9849 *
9850 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9851 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9852 * before being read.
9853 */
9854 @Override
9855 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9856 isCompressed) {
9857 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9858 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009859 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9860 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9861 }
9862 if (!isImsAvailableOnDevice()) {
9863 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9864 "IMS not available on device.");
9865 }
9866
9867 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009868 try {
Hui Wang761a6682020-10-31 05:12:53 +00009869 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9870 } finally {
9871 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009872 }
9873 }
zoey chene02881a2019-12-30 16:11:23 +08009874
9875 @Override
9876 public boolean isIccLockEnabled(int subId) {
9877 enforceReadPrivilegedPermission("isIccLockEnabled");
9878
9879 // Now that all security checks passes, perform the operation as ourselves.
9880 final long identity = Binder.clearCallingIdentity();
9881 try {
9882 Phone phone = getPhone(subId);
9883 if (phone != null && phone.getIccCard() != null) {
9884 return phone.getIccCard().getIccLockEnabled();
9885 } else {
9886 return false;
9887 }
9888 } finally {
9889 Binder.restoreCallingIdentity(identity);
9890 }
9891 }
9892
9893 /**
9894 * Set the ICC pin lock enabled or disabled.
9895 *
9896 * @return an integer representing the status of IccLock enabled or disabled in the following
9897 * three cases:
9898 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9899 * successfully.
9900 * - Positive number and zero for remaining password attempts.
9901 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9902 *
9903 */
9904 @Override
9905 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9906 enforceModifyPermission();
9907
9908 Phone phone = getPhone(subId);
9909 if (phone == null) {
9910 return 0;
9911 }
9912 // Now that all security checks passes, perform the operation as ourselves.
9913 final long identity = Binder.clearCallingIdentity();
9914 try {
9915 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9916 new Pair<Boolean, String>(enabled, password), phone, null);
9917 return attemptsRemaining;
9918
9919 } catch (Exception e) {
9920 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9921 } finally {
9922 Binder.restoreCallingIdentity(identity);
9923 }
9924 return 0;
9925 }
9926
9927 /**
9928 * Change the ICC password used in ICC pin lock.
9929 *
9930 * @return an integer representing the status of IccLock changed in the following three cases:
9931 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9932 * - Positive number and zero for remaining password attempts.
9933 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9934 *
9935 */
9936 @Override
9937 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9938 enforceModifyPermission();
9939
9940 Phone phone = getPhone(subId);
9941 if (phone == null) {
9942 return 0;
9943 }
9944 // Now that all security checks passes, perform the operation as ourselves.
9945 final long identity = Binder.clearCallingIdentity();
9946 try {
9947 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9948 new Pair<String, String>(oldPassword, newPassword), phone, null);
9949 return attemptsRemaining;
9950
9951 } catch (Exception e) {
9952 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9953 } finally {
9954 Binder.restoreCallingIdentity(identity);
9955 }
9956 return 0;
9957 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009958
9959 /**
9960 * Request for receiving user activity notification
9961 */
9962 @Override
9963 public void requestUserActivityNotification() {
9964 if (!mNotifyUserActivity.get()
9965 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9966 mNotifyUserActivity.set(true);
9967 }
9968 }
9969
9970 /**
9971 * Called when userActivity is signalled in the power manager.
9972 * This is safe to call from any thread, with any window manager locks held or not.
9973 */
9974 @Override
9975 public void userActivity() {
9976 // ***************************************
9977 // * Inherited from PhoneWindowManager *
9978 // ***************************************
9979 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9980 // WITH ITS LOCKS HELD.
9981 //
9982 // This code must be VERY careful about the locks
9983 // it acquires.
9984 // In fact, the current code acquires way too many,
9985 // and probably has lurking deadlocks.
9986
9987 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9988 throw new SecurityException("Only the OS may call notifyUserActivity()");
9989 }
9990
9991 if (mNotifyUserActivity.getAndSet(false)) {
9992 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9993 USER_ACTIVITY_NOTIFICATION_DELAY);
9994 }
9995 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009996
9997 @Override
9998 public boolean canConnectTo5GInDsdsMode() {
9999 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10000 }
Jack Yud10cdd42020-09-28 20:28:01 -070010001
10002 @Override
10003 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10004 String callingFeatureId) {
10005 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10006 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10007 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10008 }
10009
10010 Phone phone = getPhone(subId);
10011 if (phone == null) {
10012 throw new RuntimeException("phone is not available");
10013 }
10014 // Now that all security checks passes, perform the operation as ourselves.
10015 final long identity = Binder.clearCallingIdentity();
10016 try {
10017 return phone.getEquivalentHomePlmns();
10018 } finally {
10019 Binder.restoreCallingIdentity(identity);
10020 }
10021 }
Daniel Bright59e67312020-11-13 11:49:37 -080010022
10023 @Override
10024 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010025 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10026 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010027 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010028 if (radioInterfaceCapabilities == null) {
10029 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010030 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010031 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010032 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010033
Hui Wang641e81c2020-10-12 12:14:23 -070010034 @Override
10035 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10036 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010037 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10038 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10039 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10040 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10041 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010042 if (DBG) {
10043 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10044 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10045 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10046 }
10047
10048 if (!SubscriptionManager.isValidSubscriptionId(subId)
10049 || appType < TelephonyManager.APPTYPE_UNKNOWN
10050 || appType > TelephonyManager.APPTYPE_ISIM
10051 || nafUrl == null || securityProtocol == null || callback == null) {
10052 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10053 if (callback != null) {
10054 try {
10055 callback.onAuthenticationFailure(
10056 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10057 } catch (RemoteException exception) {
10058 log("Fail to notify onAuthenticationFailure due to " + exception);
10059 }
10060 return;
10061 }
10062 }
10063
10064 final long token = Binder.clearCallingIdentity();
10065 try {
10066 getGbaManager(subId).bootstrapAuthenticationRequest(
10067 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10068 forceBootStrapping, callback));
10069 } finally {
10070 Binder.restoreCallingIdentity(token);
10071 }
10072 }
10073
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010074 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010075 * Attempts to set the radio power state for all phones for thermal reason.
10076 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010077 * requested radio power state will actually be set. See {@link
10078 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10079 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010080 * @param enable {@code true} if trying to turn radio on.
10081 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10082 * false}.
10083 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010084 private boolean setRadioPowerForThermal(boolean enable) {
10085 boolean isPhoneAvailable = false;
10086 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10087 Phone phone = PhoneFactory.getPhone(i);
10088 if (phone != null) {
10089 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10090 isPhoneAvailable = true;
10091 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010092 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010093
10094 // return true if successfully informed the phone object about the thermal radio power
10095 // request.
10096 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010097 }
10098
10099 private int handleDataThrottlingRequest(int subId,
10100 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010101 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10102 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10103 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10104 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10105 throw new IllegalArgumentException("modem does not support data throttling");
10106 }
10107
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010108 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10109 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010110 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010111 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10112 }
10113
10114 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10115
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010116 if (isDataThrottlingSupported) {
10117 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010118 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010119 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10120 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10121 } else if (thermalMitigationResult
10122 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010123 log("Modem likely does not support data throttling on secondary carrier. Data " +
10124 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10125 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010126 }
10127 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010128 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010129
10130 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010131 }
10132
Jack Nudelman644b91a2021-03-12 14:09:48 -080010133 private static List<String> getThermalMitigationAllowlist(Context context) {
10134 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10135 for (String pckg : context.getResources()
10136 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10137 sThermalMitigationAllowlistedPackages.add(pckg);
10138 }
10139 }
10140
10141 return sThermalMitigationAllowlistedPackages;
10142 }
10143
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010144 private boolean isAnyPhoneInEmergencyState() {
10145 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10146 if (tm.isInEmergencyCall()) {
10147 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10148 return true;
10149 }
10150 for (Phone phone : PhoneFactory.getPhones()) {
10151 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10152 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10153 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10154 + phone.isInEcm());
10155 return true;
10156 }
10157 }
10158
10159 return false;
10160 }
10161
Jack Nudelman644b91a2021-03-12 14:09:48 -080010162 /**
10163 * Used by shell commands to add an authorized package name for thermal mitigation.
10164 * @param packageName name of package to be allowlisted
10165 * @param context
10166 */
10167 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10168 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10169 sThermalMitigationAllowlistedPackages.add(packageName);
10170 }
10171
10172 /**
10173 * Used by shell commands to remove an authorized package name for thermal mitigation.
10174 * @param packageName name of package to remove from allowlist
10175 * @param context
10176 */
10177 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10178 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10179 sThermalMitigationAllowlistedPackages.remove(packageName);
10180 }
10181
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010182 /**
10183 * Thermal mitigation request to control functionalities at modem.
10184 *
10185 * @param subId the id of the subscription.
10186 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010187 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010188 *
10189 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10190 */
10191 @Override
10192 @ThermalMitigationResult
10193 public int sendThermalMitigationRequest(
10194 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010195 ThermalMitigationRequest thermalMitigationRequest,
10196 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010197 enforceModifyPermission();
10198
Jack Nudelman644b91a2021-03-12 14:09:48 -080010199 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10200 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10201 .contains(callingPackage)) {
10202 throw new SecurityException("Calling package must be configured in the device config. "
10203 + "calling package: " + callingPackage);
10204 }
10205
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010206 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10207 final long identity = Binder.clearCallingIdentity();
10208
10209 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10210 try {
10211 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10212 switch (thermalMitigationAction) {
10213 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10214 thermalMitigationResult =
10215 handleDataThrottlingRequest(subId,
10216 thermalMitigationRequest.getDataThrottlingRequest());
10217 break;
10218 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10219 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10220 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10221 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10222 }
10223
10224 // Ensure that radio is on. If not able to power on due to phone being
10225 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010226 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010227 thermalMitigationResult =
10228 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10229 break;
10230 }
10231
10232 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10233 false);
10234 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10235 break;
10236 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10237 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10238 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10239 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10240 }
10241
10242 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10243 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010244 Phone phone = getPhone(subId);
10245 if (phone == null) {
10246 thermalMitigationResult =
10247 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10248 break;
10249 }
10250
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010251 TelephonyConnectionService service =
10252 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010253 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010254 Log.e(LOG_TAG, "An emergency call is pending");
10255 thermalMitigationResult =
10256 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10257 break;
10258 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010259 thermalMitigationResult =
10260 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10261 break;
10262 }
10263 } else {
10264 thermalMitigationResult =
10265 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10266 break;
10267 }
10268
10269 // Turn radio off. If not able to power off due to phone being unavailable,
10270 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010271 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010272 thermalMitigationResult =
10273 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10274 break;
10275 }
10276 thermalMitigationResult =
10277 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10278 break;
10279 default:
10280 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10281 + "not exist. Requested action: " + thermalMitigationAction);
10282 }
10283 } catch (IllegalArgumentException e) {
10284 throw e;
10285 } catch (Exception e) {
10286 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10287 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10288 } finally {
10289 Binder.restoreCallingIdentity(identity);
10290 }
10291
10292 if (DBG) {
10293 log("thermalMitigationRequest returning with thermalMitigationResult: "
10294 + thermalMitigationResult);
10295 }
10296
10297 return thermalMitigationResult;
10298 }
Hui Wang641e81c2020-10-12 12:14:23 -070010299
10300 /**
10301 * Set the GbaService Package Name that Telephony will bind to.
10302 *
10303 * @param subId The sim that the GbaService is associated with.
10304 * @param packageName The name of the package to be replaced with.
10305 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10306 */
10307 @Override
10308 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10309 enforceModifyPermission();
10310
10311 final long identity = Binder.clearCallingIdentity();
10312 try {
10313 return getGbaManager(subId).overrideServicePackage(packageName);
10314 } finally {
10315 Binder.restoreCallingIdentity(identity);
10316 }
10317 }
10318
10319 /**
10320 * Return the package name of the currently bound GbaService.
10321 *
10322 * @param subId The sim that the GbaService is associated with.
10323 * @return the package name of the GbaService configuration, null if GBA is not supported.
10324 */
10325 @Override
10326 public String getBoundGbaService(int subId) {
10327 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10328
10329 final long identity = Binder.clearCallingIdentity();
10330 try {
10331 return getGbaManager(subId).getServicePackage();
10332 } finally {
10333 Binder.restoreCallingIdentity(identity);
10334 }
10335 }
10336
10337 /**
10338 * Set the release time for telephony to unbind GbaService.
10339 *
10340 * @param subId The sim that the GbaService is associated with.
10341 * @param interval The release time to unbind GbaService by millisecond.
10342 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10343 */
10344 @Override
10345 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10346 enforceModifyPermission();
10347
10348 final long identity = Binder.clearCallingIdentity();
10349 try {
10350 return getGbaManager(subId).overrideReleaseTime(interval);
10351 } finally {
10352 Binder.restoreCallingIdentity(identity);
10353 }
10354 }
10355
10356 /**
10357 * Return the release time for telephony to unbind GbaService.
10358 *
10359 * @param subId The sim that the GbaService is associated with.
10360 * @return The release time to unbind GbaService by millisecond.
10361 */
10362 @Override
10363 public int getGbaReleaseTime(int subId) {
10364 enforceReadPrivilegedPermission("getGbaReleaseTime");
10365
10366 final long identity = Binder.clearCallingIdentity();
10367 try {
10368 return getGbaManager(subId).getReleaseTime();
10369 } finally {
10370 Binder.restoreCallingIdentity(identity);
10371 }
10372 }
10373
10374 private GbaManager getGbaManager(int subId) {
10375 GbaManager instance = GbaManager.getInstance(subId);
10376 if (instance == null) {
10377 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10378 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10379 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10380 }
10381 return instance;
10382 }
Hui Wang761a6682020-10-31 05:12:53 +000010383
10384 /**
10385 * indicate whether the device and the carrier can support
10386 * RCS VoLTE single registration.
10387 */
10388 @Override
10389 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010390 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10391 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10392 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10393 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010394
10395 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10396 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10397 }
10398
10399 final long identity = Binder.clearCallingIdentity();
10400 try {
10401 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10402 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010403 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10404 if (isCapable != null) {
10405 return isCapable;
10406 }
Hui Wang761a6682020-10-31 05:12:53 +000010407 }
Hui Wang67af90e2021-06-04 16:57:15 -070010408 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10409 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010410 } finally {
10411 Binder.restoreCallingIdentity(identity);
10412 }
10413 }
10414
10415 /**
10416 * Register RCS provisioning callback.
10417 */
10418 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010419 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010420 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010421 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010422 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010423 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10424 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010425
10426 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10427 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10428 }
10429 if (!isImsAvailableOnDevice()) {
10430 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10431 "IMS not available on device.");
10432 }
10433
10434 final long identity = Binder.clearCallingIdentity();
10435 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010436 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010437 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010438 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10439 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010440 }
Hui Wang761a6682020-10-31 05:12:53 +000010441 } finally {
10442 Binder.restoreCallingIdentity(identity);
10443 }
10444 }
10445
10446 /**
10447 * Unregister RCS provisioning callback.
10448 */
10449 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010450 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010451 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010452 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010453 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010454 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10455 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010456
10457 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10458 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10459 }
10460 if (!isImsAvailableOnDevice()) {
10461 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10462 "IMS not available on device.");
10463 }
10464
10465 final long identity = Binder.clearCallingIdentity();
10466 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010467 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010468 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010469 } finally {
10470 Binder.restoreCallingIdentity(identity);
10471 }
10472 }
10473
10474 /**
10475 * trigger RCS reconfiguration.
10476 */
10477 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010478 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10479 "triggerRcsReconfiguration",
10480 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010481
10482 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10483 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10484 }
10485 if (!isImsAvailableOnDevice()) {
10486 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10487 "IMS not available on device.");
10488 }
10489
10490 final long identity = Binder.clearCallingIdentity();
10491 try {
10492 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10493 } finally {
10494 Binder.restoreCallingIdentity(identity);
10495 }
10496 }
10497
10498 /**
10499 * Provide the client configuration parameters of the RCS application.
10500 */
10501 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010502 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10503 "setRcsClientConfiguration",
10504 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010505
10506 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10507 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10508 }
10509 if (!isImsAvailableOnDevice()) {
10510 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10511 "IMS not available on device.");
10512 }
10513
10514 final long identity = Binder.clearCallingIdentity();
10515
10516 try {
10517 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10518 if (configBinder == null) {
10519 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010520 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10521 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010522 } else {
10523 configBinder.setRcsClientConfiguration(rcc);
10524 }
joonhunshinfa314642021-09-17 06:33:39 +000010525
10526 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10527 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010528 } catch (RemoteException e) {
10529 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010530 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10531 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010532 } finally {
10533 Binder.restoreCallingIdentity(identity);
10534 }
10535 }
10536
10537 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010538 * Enables or disables the test mode for RCS VoLTE single registration.
10539 */
10540 @Override
10541 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10542 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10543 "setRcsSingleRegistrationTestModeEnabled");
10544
10545 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10546 }
10547
10548 /**
10549 * Gets the test mode for RCS VoLTE single registration.
10550 */
10551 @Override
10552 public boolean getRcsSingleRegistrationTestModeEnabled() {
10553 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10554 "getRcsSingleRegistrationTestModeEnabled");
10555
10556 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10557 }
10558
10559 /**
Hui Wang761a6682020-10-31 05:12:53 +000010560 * Overrides the config of RCS VoLTE single registration enabled for the device.
10561 */
10562 @Override
10563 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10564 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10565 "setDeviceSingleRegistrationEnabledOverride");
10566 enforceModifyPermission();
10567
10568 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10569 : Boolean.parseBoolean(enabledStr);
10570 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010571 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010572 }
10573
10574 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010575 * Sends a device to device communication message. Only usable via shell.
10576 * @param message message to send.
10577 * @param value message value.
10578 */
10579 @Override
10580 public void sendDeviceToDeviceMessage(int message, int value) {
10581 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010582 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010583 enforceModifyPermission();
10584
10585 final long identity = Binder.clearCallingIdentity();
10586 try {
10587 TelephonyConnectionService service =
10588 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10589 if (service == null) {
10590 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10591 return;
10592 }
10593 service.sendTestDeviceToDeviceMessage(message, value);
10594 } finally {
10595 Binder.restoreCallingIdentity(identity);
10596 }
10597 }
10598
Tyler Gunnbabbda02021-02-10 11:05:02 -080010599 /**
10600 * Sets the specified device to device transport active.
10601 * @param transport The transport to set active.
10602 */
10603 @Override
10604 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10605 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10606 "setActiveDeviceToDeviceTransport");
10607 enforceModifyPermission();
10608
10609 final long identity = Binder.clearCallingIdentity();
10610 try {
10611 TelephonyConnectionService service =
10612 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10613 if (service == null) {
10614 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10615 return;
10616 }
10617 service.setActiveDeviceToDeviceTransport(transport);
10618 } finally {
10619 Binder.restoreCallingIdentity(identity);
10620 }
10621 }
Tyler Gunn92479152021-01-20 16:30:10 -080010622
Tyler Gunnd4575212021-05-03 14:46:49 -070010623 @Override
10624 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10625 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10626 "setDeviceToDeviceForceEnabled");
10627
10628 final long identity = Binder.clearCallingIdentity();
10629 try {
10630 Arrays.stream(PhoneFactory.getPhones()).forEach(
10631 p -> {
10632 Phone thePhone = p.getImsPhone();
10633 if (thePhone != null && thePhone instanceof ImsPhone) {
10634 ImsPhone imsPhone = (ImsPhone) thePhone;
10635 CallTracker tracker = imsPhone.getCallTracker();
10636 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10637 ImsPhoneCallTracker imsPhoneCallTracker =
10638 (ImsPhoneCallTracker) tracker;
10639 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10640 }
10641 }
10642 }
10643 );
10644 } finally {
10645 Binder.restoreCallingIdentity(identity);
10646 }
10647 }
10648
Tyler Gunn92479152021-01-20 16:30:10 -080010649 /**
Hui Wang761a6682020-10-31 05:12:53 +000010650 * Gets the config of RCS VoLTE single registration enabled for the device.
10651 */
10652 @Override
10653 public boolean getDeviceSingleRegistrationEnabled() {
10654 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10655 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10656 }
10657
10658 /**
10659 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10660 */
10661 @Override
10662 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10663 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10664 "setCarrierSingleRegistrationEnabledOverride");
10665 enforceModifyPermission();
10666
10667 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10668 : Boolean.parseBoolean(enabledStr);
10669 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10670 subId, enabled);
10671 }
10672
10673 /**
10674 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10675 */
10676 @Override
10677 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10678 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10679 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10680 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010681
10682 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010683 * Overrides the ims feature validation result
10684 */
10685 @Override
10686 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10687 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10688 "setImsFeatureValidationOverride");
10689
10690 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10691 : Boolean.parseBoolean(enabledStr);
10692 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10693 subId, enabled);
10694 }
10695
10696 /**
10697 * Gets the ims feature validation override value
10698 */
10699 @Override
10700 public boolean getImsFeatureValidationOverride(int subId) {
10701 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10702 "getImsFeatureValidationOverride");
10703 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10704 }
10705
10706 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010707 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10708 * their mobile plan.
10709 */
10710 @Override
10711 public String getMobileProvisioningUrl() {
10712 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10713 final long identity = Binder.clearCallingIdentity();
10714 try {
10715 return getDefaultPhone().getMobileProvisioningUrl();
10716 } finally {
10717 Binder.restoreCallingIdentity(identity);
10718 }
10719 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010720
James.cf Linbcdf8b32021-01-14 16:44:13 +080010721 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010722 * Get the EAB contact from the EAB database.
10723 */
10724 @Override
10725 public String getContactFromEab(String contact) {
10726 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10727 enforceModifyPermission();
10728 final long identity = Binder.clearCallingIdentity();
10729 try {
10730 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10731 } finally {
10732 Binder.restoreCallingIdentity(identity);
10733 }
10734 }
10735
10736 /**
Calvin Pana1434322021-07-01 19:27:01 +080010737 * Get the EAB capability from the EAB database.
10738 */
10739 @Override
10740 public String getCapabilityFromEab(String contact) {
10741 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10742 enforceModifyPermission();
10743 final long identity = Binder.clearCallingIdentity();
10744 try {
10745 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10746 } finally {
10747 Binder.restoreCallingIdentity(identity);
10748 }
10749 }
10750
10751 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010752 * Remove the EAB contacts from the EAB database.
10753 */
10754 @Override
10755 public int removeContactFromEab(int subId, String contacts) {
10756 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10757 enforceModifyPermission();
10758 final long identity = Binder.clearCallingIdentity();
10759 try {
10760 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10761 } finally {
10762 Binder.restoreCallingIdentity(identity);
10763 }
10764 }
10765
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010766 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010767 public boolean getDeviceUceEnabled() {
10768 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10769 final long identity = Binder.clearCallingIdentity();
10770 try {
10771 return mApp.getDeviceUceEnabled();
10772 } finally {
10773 Binder.restoreCallingIdentity(identity);
10774 }
10775 }
10776
10777 @Override
10778 public void setDeviceUceEnabled(boolean isEnabled) {
10779 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10780 final long identity = Binder.clearCallingIdentity();
10781 try {
10782 mApp.setDeviceUceEnabled(isEnabled);
10783 } finally {
10784 Binder.restoreCallingIdentity(identity);
10785 }
10786 }
10787
Brad Ebinger14d467f2021-02-12 06:18:28 +000010788 /**
10789 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10790 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10791 */
10792 // Used for SHELL command only right now.
10793 @Override
10794 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10795 List<String> featureTags) {
10796 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10797 "addUceRegistrationOverrideShell");
10798 final long identity = Binder.clearCallingIdentity();
10799 try {
10800 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10801 new ArraySet<>(featureTags));
10802 } catch (ImsException e) {
10803 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10804 } finally {
10805 Binder.restoreCallingIdentity(identity);
10806 }
10807 }
10808
10809 /**
10810 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10811 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10812 */
10813 // Used for SHELL command only right now.
10814 @Override
10815 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10816 List<String> featureTags) {
10817 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10818 "removeUceRegistrationOverrideShell");
10819 final long identity = Binder.clearCallingIdentity();
10820 try {
10821 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10822 new ArraySet<>(featureTags));
10823 } catch (ImsException e) {
10824 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10825 } finally {
10826 Binder.restoreCallingIdentity(identity);
10827 }
10828 }
10829
10830 /**
10831 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10832 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10833 */
10834 // Used for SHELL command only right now.
10835 @Override
10836 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10837 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10838 "clearUceRegistrationOverrideShell");
10839 final long identity = Binder.clearCallingIdentity();
10840 try {
10841 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10842 } catch (ImsException e) {
10843 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10844 } finally {
10845 Binder.restoreCallingIdentity(identity);
10846 }
10847 }
10848
10849 /**
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 getLatestRcsContactUceCapabilityShell(int subId) {
10855 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10856 "getLatestRcsContactUceCapabilityShell");
10857 final long identity = Binder.clearCallingIdentity();
10858 try {
10859 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10860 } catch (ImsException e) {
10861 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10862 } finally {
10863 Binder.restoreCallingIdentity(identity);
10864 }
10865 }
10866
10867 /**
10868 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10869 * device does not have an active PUBLISH.
10870 */
10871 // Used for SHELL command only right now.
10872 @Override
10873 public String getLastUcePidfXmlShell(int subId) {
10874 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10875 final long identity = Binder.clearCallingIdentity();
10876 try {
10877 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10878 } catch (ImsException e) {
10879 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10880 } finally {
10881 Binder.restoreCallingIdentity(identity);
10882 }
10883 }
10884
James.cf Line8713a42021-04-29 16:04:26 +080010885 /**
10886 * Remove UCE requests cannot be sent to the network status.
10887 */
10888 // Used for SHELL command only right now.
10889 @Override
10890 public boolean removeUceRequestDisallowedStatus(int subId) {
10891 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10892 final long identity = Binder.clearCallingIdentity();
10893 try {
10894 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10895 } catch (ImsException e) {
10896 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10897 } finally {
10898 Binder.restoreCallingIdentity(identity);
10899 }
10900 }
10901
James.cf Lin0fc71b02021-05-25 01:37:38 +080010902 /**
10903 * Remove UCE requests cannot be sent to the network status.
10904 */
10905 // Used for SHELL command only.
10906 @Override
10907 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10908 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10909 final long identity = Binder.clearCallingIdentity();
10910 try {
10911 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10912 } catch (ImsException e) {
10913 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10914 } finally {
10915 Binder.restoreCallingIdentity(identity);
10916 }
10917 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010918
James.cf Lin4b784aa2021-01-31 03:25:15 +080010919 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010920 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10921 String callingPackage) {
10922 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10923 mApp, subId, "setSignalStrengthUpdateRequest");
10924
10925 final int callingUid = Binder.getCallingUid();
10926 // Verify that tha callingPackage belongs to the calling UID
10927 mApp.getSystemService(AppOpsManager.class)
10928 .checkPackage(callingUid, callingPackage);
10929
Rambo Wang3607f502021-02-01 21:51:40 -080010930 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010931
10932 final long identity = Binder.clearCallingIdentity();
10933 try {
10934 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10935 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10936
10937 if (result instanceof IllegalStateException) {
10938 throw (IllegalStateException) result;
10939 }
10940 } finally {
10941 Binder.restoreCallingIdentity(identity);
10942 }
10943 }
10944
10945 @Override
10946 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10947 String callingPackage) {
10948 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10949 mApp, subId, "clearSignalStrengthUpdateRequest");
10950
10951 final int callingUid = Binder.getCallingUid();
10952 // Verify that tha callingPackage belongs to the calling UID
10953 mApp.getSystemService(AppOpsManager.class)
10954 .checkPackage(callingUid, callingPackage);
10955
10956 final long identity = Binder.clearCallingIdentity();
10957 try {
10958 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10959 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10960
10961 if (result instanceof IllegalStateException) {
10962 throw (IllegalStateException) result;
10963 }
10964 } finally {
10965 Binder.restoreCallingIdentity(identity);
10966 }
10967 }
10968
Rambo Wang3607f502021-02-01 21:51:40 -080010969 private static void validateSignalStrengthUpdateRequest(Context context,
10970 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010971 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10972 // phone/system process do not have further restriction on request
10973 return;
10974 }
10975
10976 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080010977 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010978 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080010979 context.enforceCallingOrSelfPermission(
10980 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
10981 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010982 }
10983
10984 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10985 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10986 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10987 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10988 || info.isEnabled()) {
10989 throw new IllegalArgumentException(
10990 "Only system can set hide fields in SignalThresholdInfo");
10991 }
10992
10993 // Thresholds length for each RAN need in range. This has been validated in
10994 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10995 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10996 final int[] thresholds = info.getThresholds();
10997 Objects.requireNonNull(thresholds);
10998 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10999 || thresholds.length
11000 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11001 throw new IllegalArgumentException(
11002 "thresholds length is out of range: " + thresholds.length);
11003 }
11004 }
11005 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011006
11007 /**
11008 * Gets the current phone capability.
11009 *
11010 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11011 * @return the PhoneCapability which describes the data connection capability of modem.
11012 * It's used to evaluate possible phone config change, for example from single
11013 * SIM device to multi-SIM device.
11014 */
11015 @Override
11016 public PhoneCapability getPhoneCapability() {
11017 enforceReadPrivilegedPermission("getPhoneCapability");
11018 final long identity = Binder.clearCallingIdentity();
11019 try {
11020 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11021 } finally {
11022 Binder.restoreCallingIdentity(identity);
11023 }
11024 }
Michele Berionne5e411512020-11-13 02:36:59 +000011025
11026 /**
11027 * Prepare TelephonyManager for an unattended reboot. The reboot is
11028 * required to be done shortly after the API is invoked.
11029 */
11030 @Override
11031 @TelephonyManager.PrepareUnattendedRebootResult
11032 public int prepareForUnattendedReboot() {
11033 enforceRebootPermission();
11034
11035 final long identity = Binder.clearCallingIdentity();
11036 try {
11037 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
11038 } finally {
11039 Binder.restoreCallingIdentity(identity);
11040 }
11041 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011042
11043 /**
11044 * Request to get the current slicing configuration including URSP rules and
11045 * NSSAIs (configured, allowed and rejected).
11046 *
11047 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11048 */
11049 @Override
11050 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011051 TelephonyPermissions
11052 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11053 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011054
11055 final long identity = Binder.clearCallingIdentity();
11056 try {
11057 Phone phone = getDefaultPhone();
11058 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11059 } finally {
11060 Binder.restoreCallingIdentity(identity);
11061 }
11062 }
Hunsuk Choic7ebc0f2021-11-15 23:46:41 +000011063
11064 /**
11065 * Register an IMS connection state callback
11066 */
11067 @Override
11068 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11069 String callingPackage) {
11070 if (feature == ImsFeature.FEATURE_MMTEL) {
11071 // ImsMmTelManager
11072 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11073 TelephonyPermissions
11074 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11075 mApp, subId, "registerImsStateCallback");
11076 } else if (feature == ImsFeature.FEATURE_RCS) {
11077 // ImsRcsManager or SipDelegateManager
11078 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11079 Binder.getCallingUid(), "registerImsStateCallback",
11080 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11081 Manifest.permission.READ_PRECISE_PHONE_STATE,
11082 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11083 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11084 }
11085
11086 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11087 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11088 "IMS not available on device.");
11089 }
11090
11091 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11092 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11093 }
11094
11095 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11096 if (controller == null) {
11097 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11098 "IMS not available on device.");
11099 }
11100
11101 if (callingPackage == null) {
11102 callingPackage = getCurrentPackageName();
11103 }
11104
11105 final long token = Binder.clearCallingIdentity();
11106 try {
11107 int slotId = getSlotIndexOrException(subId);
11108 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
11109 } catch (ImsException e) {
11110 throw new ServiceSpecificException(e.getCode());
11111 } finally {
11112 Binder.restoreCallingIdentity(token);
11113 }
11114 }
11115
11116 /**
11117 * Unregister an IMS connection state callback
11118 */
11119 @Override
11120 public void unregisterImsStateCallback(IImsStateCallback cb) {
11121 final long token = Binder.clearCallingIdentity();
11122 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11123 if (controller == null) {
11124 return;
11125 }
11126 try {
11127 controller.unregisterImsStateCallback(cb);
11128 } finally {
11129 Binder.restoreCallingIdentity(token);
11130 }
11131 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011132
11133 /**
11134 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11135 *
11136 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11137 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11138 * SecurityException.
11139 * If there is current registered network this value will be same as the registered cell
11140 * identity. If the device goes out of service the previous cell identity is cached and
11141 * will be returned. If the cache age of the Cell identity is more than 24 hours
11142 * it will be cleared and null will be returned.
11143 *
11144 */
11145 @Override
11146 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11147 String callingFeatureId) {
11148 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11149 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11150 LocationAccessPolicy.checkLocationPermission(mApp,
11151 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11152 .setCallingPackage(callingPackage)
11153 .setCallingFeatureId(callingFeatureId)
11154 .setCallingPid(Binder.getCallingPid())
11155 .setCallingUid(Binder.getCallingUid())
11156 .setMethod("getLastKnownCellIdentity")
11157 .setLogAsInfo(true)
11158 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11159 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11160 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11161 .build());
11162
11163 boolean hasFinePermission =
11164 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11165 if (!hasFinePermission
11166 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11167 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
11168 + "and BIND_CONNECTION_SERVICE permission.");
11169 }
11170
11171 final long identity = Binder.clearCallingIdentity();
11172 try {
11173 Phone phone = getPhone(subId);
11174 if (phone == null) return null;
11175 ServiceStateTracker sst = phone.getServiceStateTracker();
11176 if (sst == null) return null;
11177 return sst.getLastKnownCellIdentity();
11178 } finally {
11179 Binder.restoreCallingIdentity(identity);
11180 }
11181 }
jimsun38340bf2021-10-26 15:01:23 +080011182
11183 /**
11184 * Sets the modem service class Name that Telephony will bind to.
11185 *
11186 * @param serviceName The class name of the modem service.
11187 * @return true if the operation is succeed, otherwise false.
11188 */
11189 public boolean setModemService(String serviceName) {
11190 Log.d(LOG_TAG, "setModemService - " + serviceName);
11191 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11192 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11193 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11194 "setModemService");
11195 return mPhoneConfigurationManager.setModemService(serviceName);
11196 }
11197
11198 /**
11199 * Return the class name of the currently bounded modem service.
11200 *
11201 * @return the class name of the modem service.
11202 */
11203 public String getModemService() {
11204 String result;
11205 Log.d(LOG_TAG, "getModemService");
11206 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11207 TelephonyPermissions
11208 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11209 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11210 "getModemService");
11211 result = mPhoneConfigurationManager.getModemService();
11212 Log.d(LOG_TAG, "result = " + result);
11213 return result;
11214 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011215}