blob: eb1cf7755ce04dc40bbca1bd52d46952195dfdca [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");
Rambo Wang04d1ace2022-02-23 13:41:02 -08006791 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
6792 }
6793
6794 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006795 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006796 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006797 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006798 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006799 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6800 Phone phone = PhoneFactory.getPhone(phoneId);
6801 if (phone == null) {
6802 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006803 }
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006804 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6805 if (cpt == null) {
6806 continue;
6807 }
6808 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006809 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6810 break;
6811 }
6812 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006813 return result;
Junda Liu29340342014-07-10 15:23:27 -07006814 }
Derek Tan89e89d42014-07-08 17:00:10 -07006815
6816 @Override
Junda Liue64de782015-04-16 17:19:16 -07006817 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006818 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Hunter Knepshieldb0eb4792021-12-14 18:49:15 -08006819 Phone phone = PhoneFactory.getPhone(phoneId);
6820 if (phone == null) {
6821 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006822 }
Hunter Knepshieldb0eb4792021-12-14 18:49:15 -08006823 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6824 if (cpt == null) {
6825 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006826 }
Hunter Knepshieldb0eb4792021-12-14 18:49:15 -08006827 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006828 }
6829
Amith Yamasani6e118872016-02-19 12:53:51 -08006830 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006831 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006832 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006833 Phone phone = PhoneFactory.getPhone(phoneId);
6834 if (phone == null) {
6835 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006836 }
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006837 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6838 if (cpt == null) {
6839 return Collections.emptyList();
6840 }
6841 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006842 }
6843
chen xuf7e9fe82019-05-09 19:31:02 -07006844 @Override
6845 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006846 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006847 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006848 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00006849 try {
6850 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6851 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6852 }
6853 } finally {
6854 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006855 }
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006856 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07006857 }
6858
Rambo Wang9b91ffd2022-03-15 16:54:17 -07006859 @Override
6860 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
6861 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
6862
6863 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
6864 if (phone == null) {
6865 return null;
6866 }
6867 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6868 if (cpt == null) {
6869 return null;
6870 }
6871 return cpt.getCarrierServicePackageName();
6872 }
6873
Wink Savilleb564aae2014-10-23 10:18:09 -07006874 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006875 final Phone phone = getPhone(subId);
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006876 UiccPort port = phone == null ? null : phone.getUiccPort();
6877 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006878 return null;
6879 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006880 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006881 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006882 return null;
6883 }
6884 return iccId;
6885 }
6886
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006887 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006888 public void setCallComposerStatus(int subId, int status) {
6889 enforceModifyPermission();
6890
6891 final long identity = Binder.clearCallingIdentity();
6892 try {
6893 Phone phone = getPhone(subId);
6894 if (phone != null) {
6895 Phone defaultPhone = phone.getImsPhone();
6896 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6897 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6898 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006899 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6900 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006901 }
6902 }
Shuo Qian284ae752020-12-22 19:10:14 -08006903 } catch (ImsException e) {
6904 throw new ServiceSpecificException(e.getCode());
6905 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006906 Binder.restoreCallingIdentity(identity);
6907 }
6908 }
6909
6910 @Override
6911 public int getCallComposerStatus(int subId) {
6912 enforceReadPrivilegedPermission("getCallComposerStatus");
6913
6914 final long identity = Binder.clearCallingIdentity();
6915 try {
6916 Phone phone = getPhone(subId);
6917 if (phone != null) {
6918 Phone defaultPhone = phone.getImsPhone();
6919 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6920 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6921 return imsPhone.getCallComposerStatus();
6922 }
6923 }
6924 } finally {
6925 Binder.restoreCallingIdentity(identity);
6926 }
6927 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6928 }
6929
6930 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006931 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6932 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006933 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006934 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006935
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006936 final long identity = Binder.clearCallingIdentity();
6937 try {
6938 final String iccId = getIccId(subId);
6939 final Phone phone = getPhone(subId);
6940 if (phone == null) {
6941 return false;
6942 }
6943 final String subscriberId = phone.getSubscriberId();
6944
6945 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006946 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006947 + subscriberId + " to " + number);
6948 }
6949
6950 if (TextUtils.isEmpty(iccId)) {
6951 return false;
6952 }
6953
6954 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6955
6956 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6957 if (alphaTag == null) {
6958 editor.remove(alphaTagPrefKey);
6959 } else {
6960 editor.putString(alphaTagPrefKey, alphaTag);
6961 }
6962
6963 // Record both the line number and IMSI for this ICCID, since we need to
6964 // track all merged IMSIs based on line number
6965 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6966 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6967 if (number == null) {
6968 editor.remove(numberPrefKey);
6969 editor.remove(subscriberPrefKey);
6970 } else {
6971 editor.putString(numberPrefKey, number);
6972 editor.putString(subscriberPrefKey, subscriberId);
6973 }
6974
6975 editor.commit();
6976 return true;
6977 } finally {
6978 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006979 }
Derek Tan7226c842014-07-02 17:42:23 -07006980 }
6981
6982 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006983 public String getLine1NumberForDisplay(int subId, String callingPackage,
6984 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006985 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006986 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006987 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006988 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006989 return null;
6990 }
Derek Tan97ebb422014-09-05 16:55:38 -07006991
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006992 final long identity = Binder.clearCallingIdentity();
6993 try {
6994 String iccId = getIccId(subId);
6995 if (iccId != null) {
6996 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6997 if (DBG_MERGE) {
6998 log("getLine1NumberForDisplay returning "
6999 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7000 }
7001 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007002 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007003 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7004 return null;
7005 } finally {
7006 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007007 }
Derek Tan7226c842014-07-02 17:42:23 -07007008 }
7009
7010 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007011 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7012 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007013 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007014 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007015 return null;
7016 }
Derek Tan97ebb422014-09-05 16:55:38 -07007017
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007018 final long identity = Binder.clearCallingIdentity();
7019 try {
7020 String iccId = getIccId(subId);
7021 if (iccId != null) {
7022 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7023 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7024 }
7025 return null;
7026 } finally {
7027 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007028 }
Derek Tan7226c842014-07-02 17:42:23 -07007029 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007030
7031 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007032 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7033 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007034 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7035 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007036 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007037 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007038 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007039 return null;
7040 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007041
Jordan Liub49b04b2019-05-06 14:45:15 -07007042 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7043 // the process, where TelephonyManager was instantiated.
7044 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007045 final long identity = Binder.clearCallingIdentity();
7046 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007047 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007048 final TelephonyManager tele = TelephonyManager.from(context);
7049 final SubscriptionManager sub = SubscriptionManager.from(context);
7050
7051 // Figure out what subscribers are currently active
7052 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007053
Jordan Liub49b04b2019-05-06 14:45:15 -07007054 // Only consider subs which match the current subId
7055 // This logic can be simplified. See b/131189269 for progress.
7056 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007057 activeSubscriberIds.add(tele.getSubscriberId(subId));
7058 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007059
7060 // First pass, find a number override for an active subscriber
7061 String mergeNumber = null;
7062 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7063 for (String key : prefs.keySet()) {
7064 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7065 final String subscriberId = (String) prefs.get(key);
7066 if (activeSubscriberIds.contains(subscriberId)) {
7067 final String iccId = key.substring(
7068 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7069 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7070 mergeNumber = (String) prefs.get(numberKey);
7071 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007072 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007073 + " for active subscriber " + subscriberId);
7074 }
7075 if (!TextUtils.isEmpty(mergeNumber)) {
7076 break;
7077 }
7078 }
7079 }
7080 }
7081
7082 // Shortcut when no active merged subscribers
7083 if (TextUtils.isEmpty(mergeNumber)) {
7084 return null;
7085 }
7086
7087 // Second pass, find all subscribers under that line override
7088 final ArraySet<String> result = new ArraySet<>();
7089 for (String key : prefs.keySet()) {
7090 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7091 final String number = (String) prefs.get(key);
7092 if (mergeNumber.equals(number)) {
7093 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7094 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7095 final String subscriberId = (String) prefs.get(subscriberKey);
7096 if (!TextUtils.isEmpty(subscriberId)) {
7097 result.add(subscriberId);
7098 }
7099 }
7100 }
7101 }
7102
7103 final String[] resultArray = result.toArray(new String[result.size()]);
7104 Arrays.sort(resultArray);
7105 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007106 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007107 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7108 }
7109 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007110 } finally {
7111 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007112 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007113 }
7114
7115 @Override
zoey chen38003472019-12-13 17:16:31 +08007116 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7117 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007118
7119 final long identity = Binder.clearCallingIdentity();
7120 try {
7121 final TelephonyManager telephonyManager = mApp.getSystemService(
7122 TelephonyManager.class);
7123 String subscriberId = telephonyManager.getSubscriberId(subId);
7124 if (subscriberId == null) {
7125 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007126 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007127 + subId);
7128 }
7129 return null;
7130 }
7131
7132 final SubscriptionInfo info = SubscriptionController.getInstance()
7133 .getSubscriptionInfo(subId);
7134 final ParcelUuid groupUuid = info.getGroupUuid();
7135 // If it doesn't belong to any group, return just subscriberId of itself.
7136 if (groupUuid == null) {
7137 return new String[]{subscriberId};
7138 }
7139
7140 // Get all subscriberIds from the group.
7141 final List<String> mergedSubscriberIds = new ArrayList<>();
7142 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007143 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007144 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007145 for (SubscriptionInfo subInfo : groupInfos) {
7146 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7147 if (subscriberId != null) {
7148 mergedSubscriberIds.add(subscriberId);
7149 }
7150 }
7151
7152 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7153 } finally {
7154 Binder.restoreCallingIdentity(identity);
7155
7156 }
7157 }
7158
7159 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007160 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007161 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007162 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007163
7164 final long identity = Binder.clearCallingIdentity();
7165 try {
7166 final Phone phone = getPhone(subId);
7167 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7168 } finally {
7169 Binder.restoreCallingIdentity(identity);
7170 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007171 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007172
7173 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007174 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007175 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7176 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007177 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7178 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007179
7180 final long identity = Binder.clearCallingIdentity();
7181 try {
7182 final Phone phone = getPhone(subId);
7183 if (phone == null) {
7184 return false;
7185 }
7186 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7187 cdmaNonRoamingList);
7188 } finally {
7189 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007190 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007191 }
7192
7193 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007194 @Deprecated
7195 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7196 enforceModifyPermission();
7197
7198 int returnValue = 0;
7199 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007200 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007201 if(result.exception == null) {
7202 if (result.result != null) {
7203 byte[] responseData = (byte[])(result.result);
7204 if(responseData.length > oemResp.length) {
7205 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7206 responseData.length + "bytes. Buffer Size is " +
7207 oemResp.length + "bytes.");
7208 }
7209 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7210 returnValue = responseData.length;
7211 }
7212 } else {
7213 CommandException ex = (CommandException) result.exception;
7214 returnValue = ex.getCommandError().ordinal();
7215 if(returnValue > 0) returnValue *= -1;
7216 }
7217 } catch (RuntimeException e) {
7218 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7219 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7220 if(returnValue > 0) returnValue *= -1;
7221 }
7222
7223 return returnValue;
7224 }
7225
7226 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007227 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007228 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007229 try {
7230 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007231 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007232 mApp, phone.getSubId(), "getRadioAccessFamily");
7233 } catch (SecurityException e) {
7234 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7235 throw e;
7236 }
chen xub97461a2018-10-26 14:17:57 -07007237 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007238 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007239 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007240 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007241 final long identity = Binder.clearCallingIdentity();
7242 try {
chen xub97461a2018-10-26 14:17:57 -07007243 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007244 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007245 mApp, phone.getSubId(), "getRadioAccessFamily");
7246 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007247 } finally {
7248 Binder.restoreCallingIdentity(identity);
7249 }
chen xub97461a2018-10-26 14:17:57 -07007250 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007251 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007252
7253 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007254 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007255 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007256 try {
7257 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7258 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007259 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007260 }
7261 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007262 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007263 }
7264 RoleManager rm = mApp.getSystemService(RoleManager.class);
7265 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7266 if (!dialerRoleHolders.contains(callingPackage)) {
7267 throw new SecurityException("App must be the dialer role holder to"
7268 + " upload a call composer pic");
7269 }
7270
7271 Executors.newSingleThreadExecutor().execute(() -> {
7272 ByteArrayOutputStream output = new ByteArrayOutputStream(
7273 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7274 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7275 boolean readUntilEnd = false;
7276 int totalBytesRead = 0;
7277 byte[] buffer = new byte[16 * 1024];
7278 while (true) {
7279 int numRead;
7280 try {
7281 numRead = input.read(buffer);
7282 } catch (IOException e) {
7283 try {
7284 fd.checkError();
7285 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7286 null);
7287 } catch (IOException e1) {
7288 // This means that the other side closed explicitly with an error. If this
7289 // happens, log and ignore.
7290 loge("Remote end of call composer picture pipe closed: " + e1);
7291 }
7292 break;
7293 }
7294 if (numRead == -1) {
7295 readUntilEnd = true;
7296 break;
7297 }
7298 totalBytesRead += numRead;
7299 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7300 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7301 try {
7302 input.close();
7303 } catch (IOException e) {
7304 // ignore
7305 }
7306 break;
7307 }
7308 output.write(buffer, 0, numRead);
7309 }
7310 // Generally, the remote end will close the file descriptors. The only case where we
7311 // close is above, where the picture size is too big.
7312
7313 try {
7314 fd.checkError();
7315 } catch (IOException e) {
7316 loge("Remote end for call composer closed with an error: " + e);
7317 return;
7318 }
7319
Hall Liuaa4211e2021-01-20 15:43:39 -08007320 if (!readUntilEnd) {
7321 loge("Did not finish reading entire image; aborting");
7322 return;
7323 }
Hall Liu82694d52020-12-11 18:22:04 -08007324
Hall Liuaa4211e2021-01-20 15:43:39 -08007325 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7326 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7327 new CallComposerPictureTransfer.Factory() {},
7328 imageData,
7329 (result) -> {
7330 if (result.first != null) {
7331 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7332 Bundle outputResult = new Bundle();
7333 outputResult.putParcelable(
7334 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7335 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7336 outputResult);
7337 } else {
7338 callback.send(result.second, null);
7339 }
7340 }
7341 );
Hall Liu82694d52020-12-11 18:22:04 -08007342 });
7343 }
7344
7345 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007346 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007347 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007348 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007349
7350 final long identity = Binder.clearCallingIdentity();
7351 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007352 ImsManager.getInstance(defaultPhone.getContext(),
7353 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007354 } finally {
7355 Binder.restoreCallingIdentity(identity);
7356 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007357 }
7358
7359 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007360 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007361 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007362 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7363 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007364 return false;
7365 }
Svet Ganovb320e182015-04-16 12:30:10 -07007366
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007367 final long identity = Binder.clearCallingIdentity();
7368 try {
7369 // Check the user preference and the system-level IMS setting. Even if the user has
7370 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7371 // In the long run, we may instead need to check if there exists a connection service
7372 // which can support video calling.
7373 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007374 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007375 return imsManager.isVtEnabledByPlatform()
7376 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7377 && imsManager.isVtEnabledByUser();
7378 } finally {
7379 Binder.restoreCallingIdentity(identity);
7380 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007381 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007382
Andrew Leea1239f22015-03-02 17:44:07 -08007383 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007384 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7385 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007386 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007387 mApp, subId, callingPackage, callingFeatureId,
7388 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007389 return false;
7390 }
7391
7392 final long identity = Binder.clearCallingIdentity();
7393 try {
7394 CarrierConfigManager configManager =
7395 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007396 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007397 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7398 } finally {
7399 Binder.restoreCallingIdentity(identity);
7400 }
Andrew Leea1239f22015-03-02 17:44:07 -08007401 }
7402
7403 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007404 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007405 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007406 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007407 return false;
7408 }
7409
7410 final long identity = Binder.clearCallingIdentity();
7411 try {
7412 CarrierConfigManager configManager =
7413 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007414 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007415 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7416 } finally {
7417 Binder.restoreCallingIdentity(identity);
7418 }
Andrew Leea1239f22015-03-02 17:44:07 -08007419 }
7420
Andrew Lee9431b832015-03-09 18:46:45 -07007421 @Override
7422 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007423 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007424 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007425 }
7426
7427 @Override
7428 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007429 final long identity = Binder.clearCallingIdentity();
7430 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007431 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007432 } finally {
7433 Binder.restoreCallingIdentity(identity);
7434 }
Andrew Lee9431b832015-03-09 18:46:45 -07007435 }
7436
Hall Liuf6668912018-10-31 17:05:23 -07007437 /**
7438 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7439 * support for the feature and device firmware support.
7440 *
7441 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7442 */
7443 @Override
7444 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007445 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007446 final Phone phone = getPhone(subscriptionId);
7447 if (phone == null) {
7448 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7449 return false;
7450 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007451 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007452 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007453 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7454 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007455 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007456 return isCarrierSupported && isDeviceSupported;
7457 } finally {
7458 Binder.restoreCallingIdentity(identity);
7459 }
Hall Liu98187582018-01-22 19:15:32 -08007460 }
7461
Hall Liuf6668912018-10-31 17:05:23 -07007462 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007463 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7464 * RTT setting, will return true if the device and carrier both support RTT.
7465 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007466 */
7467 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007468 final long identity = Binder.clearCallingIdentity();
7469 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007470 boolean isRttSupported = isRttSupported(subscriptionId);
7471 boolean isUserRttSettingOn = Settings.Secure.getInt(
7472 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7473 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7474 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7475 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007476 } finally {
7477 Binder.restoreCallingIdentity(identity);
7478 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007479 }
7480
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007481 @Deprecated
7482 @Override
7483 public String getDeviceId(String callingPackage) {
7484 return getDeviceIdWithFeature(callingPackage, null);
7485 }
7486
Sanket Padawe7310cc72015-01-14 09:53:20 -08007487 /**
7488 * Returns the unique device ID of phone, for example, the IMEI for
7489 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7490 *
7491 * <p>Requires Permission:
7492 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7493 */
7494 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007495 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007496 try {
7497 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7498 } catch (SecurityException se) {
7499 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7500 throw new SecurityException("Package " + callingPackage + " does not belong to "
7501 + Binder.getCallingUid());
7502 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007503 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007504 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007505 return null;
7506 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007507 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007508 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007509 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007510 return null;
7511 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007512
7513 final long identity = Binder.clearCallingIdentity();
7514 try {
7515 return phone.getDeviceId();
7516 } finally {
7517 Binder.restoreCallingIdentity(identity);
7518 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007519 }
7520
Ping Sunc67b7c22016-03-02 19:16:45 +08007521 /**
7522 * {@hide}
7523 * Returns the IMS Registration Status on a particular subid
7524 *
7525 * @param subId
7526 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007527 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007528 Phone phone = getPhone(subId);
7529 if (phone != null) {
7530 return phone.isImsRegistered();
7531 } else {
7532 return false;
7533 }
7534 }
7535
Santos Cordon7a1885b2015-02-03 11:15:19 -08007536 @Override
7537 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007538 final long identity = Binder.clearCallingIdentity();
7539 try {
7540 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7541 } finally {
7542 Binder.restoreCallingIdentity(identity);
7543 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007544 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007545
Tyler Gunnf70ed162019-04-03 15:28:53 -07007546 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007547 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007548 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007549 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007550 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007551 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7552 }
7553 final long identity = Binder.clearCallingIdentity();
7554 try {
7555 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7556 } finally {
7557 Binder.restoreCallingIdentity(identity);
7558 }
7559 }
7560
7561 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007562 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007563 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007564 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007565 mApp,
7566 subscriptionId,
7567 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007568 final long identity = Binder.clearCallingIdentity();
7569 try {
7570 Phone phone = getPhone(subscriptionId);
7571 if (phone == null) {
7572 return null;
7573 }
7574 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7575 } finally {
7576 Binder.restoreCallingIdentity(identity);
7577 }
7578 }
7579
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007580 /**
7581 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007582 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007583 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007584 final long identity = Binder.clearCallingIdentity();
7585 try {
7586 Phone phone = getPhone(subId);
7587 if (phone != null) {
7588 return phone.isWifiCallingEnabled();
7589 } else {
7590 return false;
7591 }
7592 } finally {
7593 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007594 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007595 }
7596
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007597 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007598 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007599 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007600 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007601 final long identity = Binder.clearCallingIdentity();
7602 try {
7603 Phone phone = getPhone(subId);
7604 if (phone != null) {
7605 return phone.isVideoEnabled();
7606 } else {
7607 return false;
7608 }
7609 } finally {
7610 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007611 }
7612 }
7613
7614 /**
7615 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7616 * defined in {@link ImsRegistrationImplBase}.
7617 */
7618 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007619 final long identity = Binder.clearCallingIdentity();
7620 try {
7621 Phone phone = getPhone(subId);
7622 if (phone != null) {
7623 return phone.getImsRegistrationTech();
7624 } else {
7625 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7626 }
7627 } finally {
7628 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007629 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007630 }
7631
Stuart Scott8eef64f2015-04-08 15:13:54 -07007632 @Override
7633 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007634 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007635 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7636 return;
7637 }
Kai Shif70f46f2021-03-03 13:59:46 -08007638 Phone defaultPhone = getDefaultPhone();
7639 if (defaultPhone != null) {
7640 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7641 mApp, getDefaultPhone().getSubId(), "factoryReset");
7642 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007643 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007644
Svet Ganovcc087f82015-05-12 20:35:54 -07007645 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007646 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7647 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007648 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007649 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007650 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007651 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007652 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007653 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007654 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007655 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007656 // There has been issues when Sms raw table somehow stores orphan
7657 // fragments. They lead to garbled message when new fragments come
7658 // in and combined with those stale ones. In case this happens again,
7659 // user can reset all network settings which will clean up this table.
7660 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007661 // Clean up IMS settings as well here.
7662 int slotId = getSlotIndex(subId);
7663 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7664 ImsManager.getInstance(mApp, slotId).factoryReset();
7665 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007666
Kai Shif70f46f2021-03-03 13:59:46 -08007667 if (defaultPhone == null) {
7668 return;
7669 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007670 // Erase modem config if erase modem on network setting is enabled.
7671 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7672 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7673 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007674 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007675 }
Kai Shif70f46f2021-03-03 13:59:46 -08007676
7677 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007678 } finally {
7679 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007680 }
7681 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007682
SongFerngWangfd89b102021-05-27 22:44:54 +08007683 @VisibleForTesting
7684 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7685 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7686 return;
7687 }
7688 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7689 RILConstants.PREFERRED_NETWORK_MODE);
7690 SubscriptionManager.setSubscriptionProperty(subId,
7691 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7692 "user=" + defaultNetworkType);
7693 phone.loadAllowedNetworksFromSubscriptionDatabase();
7694 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7695 defaultNetworkType, null);
7696 }
7697
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007698 private void cleanUpSmsRawTable(Context context) {
7699 ContentResolver resolver = context.getContentResolver();
7700 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7701 resolver.delete(uri, null, null);
7702 }
7703
Narayan Kamath1c496c22015-04-16 14:40:19 +01007704 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007705 public String getSimLocaleForSubscriber(int subId) {
7706 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7707 final Phone phone = getPhone(subId);
7708 if (phone == null) {
7709 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007710 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007711 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007712 final long identity = Binder.clearCallingIdentity();
7713 try {
chen xu5d3637b2019-01-21 23:31:38 -08007714 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007715 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007716 if (info == null) {
7717 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7718 return null;
7719 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007720 // Try and fetch the locale from the carrier properties or from the SIM language
7721 // preferences (EF-PL and EF-LI)...
7722 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007723 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007724 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7725 if (localeFromDefaultSim != null) {
7726 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7727 if (DBG) log("Using locale from subId: " + subId + " locale: "
7728 + localeFromDefaultSim);
7729 return localeFromDefaultSim.toLanguageTag();
7730 } else {
7731 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007732 }
7733 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007734
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007735 // The SIM language preferences only store a language (e.g. fr = French), not an
7736 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7737 // the SIM and carrier preferences does not include a country we add the country
7738 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007739 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007740 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007741 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007742 return mccLocale.toLanguageTag();
7743 }
7744
7745 if (DBG) log("No locale found - returning null");
7746 return null;
7747 } finally {
7748 Binder.restoreCallingIdentity(identity);
7749 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007750 }
7751
7752 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007753 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007754 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007755 }
7756
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007757 /**
7758 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7759 */
7760 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007761 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007762 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007763 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007764
Chenjie Yu1ba97252018-01-11 18:16:20 -08007765 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007766 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007767
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007768 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007769 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7770 * representing the state of the modem.
7771 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007772 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7773 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007774 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007775 */
7776 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007777 public void requestModemActivityInfo(ResultReceiver result) {
7778 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007779 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007780
7781 final long identity = Binder.clearCallingIdentity();
7782 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007783 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007784 } finally {
7785 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007786 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007787 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007788
Siddharth Rayb8114062018-06-17 15:02:38 -07007789 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7790 // less than total activity duration.
7791 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7792 if (info == null) {
7793 return false;
7794 }
7795 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007796 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7797 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7798
Siddharth Rayb8114062018-06-17 15:02:38 -07007799 return (info.isValid()
7800 && (info.getSleepTimeMillis() <= activityDurationMs)
7801 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007802 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007803 && (totalTxTimeMs <= activityDurationMs));
7804 }
7805
Jack Yu85bd38a2015-11-09 11:34:32 -08007806 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007807 * Returns the service state information on specified subscription.
7808 */
7809 @Override
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007810 public ServiceState getServiceStateForSubscriber(int subId,
7811 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7812 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007813 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007814 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007815 return null;
7816 }
7817
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007818 boolean hasFinePermission = false;
7819 boolean hasCoarsePermission = false;
7820 if (!renounceFineLocationAccess) {
7821 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7822 LocationAccessPolicy.checkLocationPermission(mApp,
7823 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7824 .setCallingPackage(callingPackage)
7825 .setCallingFeatureId(callingFeatureId)
7826 .setCallingPid(Binder.getCallingPid())
7827 .setCallingUid(Binder.getCallingUid())
7828 .setMethod("getServiceStateForSubscriber")
7829 .setLogAsInfo(true)
7830 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7831 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7832 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7833 .build());
7834 hasFinePermission =
7835 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7836 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007837
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007838 if (!renounceCoarseLocationAccess) {
7839 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7840 LocationAccessPolicy.checkLocationPermission(mApp,
7841 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7842 .setCallingPackage(callingPackage)
7843 .setCallingFeatureId(callingFeatureId)
7844 .setCallingPid(Binder.getCallingPid())
7845 .setCallingUid(Binder.getCallingUid())
7846 .setMethod("getServiceStateForSubscriber")
7847 .setLogAsInfo(true)
7848 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7849 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7850 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7851 .build());
7852 hasCoarsePermission =
7853 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7854 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007855
Jack Yu479f40e2020-10-27 21:29:25 -07007856 final Phone phone = getPhone(subId);
7857 if (phone == null) {
7858 return null;
7859 }
7860
Jordan Liu0f2bc442020-11-18 16:47:37 -08007861 final long identity = Binder.clearCallingIdentity();
7862
Jack Yu479f40e2020-10-27 21:29:25 -07007863 boolean isCallingPackageDataService = phone.getDataServicePackages()
7864 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007865 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007866 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7867 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7868 Rlog.d(LOG_TAG,
7869 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7870 return null;
7871 }
7872
Hall Liuf19c44f2018-11-27 14:38:17 -08007873 ServiceState ss = phone.getServiceState();
7874
7875 // Scrub out the location info in ServiceState depending on what level of access
7876 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007877 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007878 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7879 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007880 } finally {
7881 Binder.restoreCallingIdentity(identity);
7882 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007883 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007884
7885 /**
7886 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7887 *
7888 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7889 * voicemail ringtone.
7890 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7891 * PhoneAccount.
7892 */
7893 @Override
7894 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007895 final long identity = Binder.clearCallingIdentity();
7896 try {
7897 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7898 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007899 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007900 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007901
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007902 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7903 } finally {
7904 Binder.restoreCallingIdentity(identity);
7905 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007906 }
7907
7908 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007909 * Sets the per-account voicemail ringtone.
7910 *
7911 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7912 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7913 *
7914 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7915 * voicemail ringtone.
7916 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7917 * PhoneAccount.
7918 */
7919 @Override
7920 public void setVoicemailRingtoneUri(String callingPackage,
7921 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007922 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007923 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007924 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7925 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007926 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7927 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7928 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007929 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007930
7931 final long identity = Binder.clearCallingIdentity();
7932 try {
7933 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7934 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007935 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007936 }
7937 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7938 } finally {
7939 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007940 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007941 }
7942
7943 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007944 * Returns whether vibration is set for voicemail notification in Phone settings.
7945 *
7946 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7947 * voicemail vibration setting.
7948 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7949 */
7950 @Override
7951 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007952 final long identity = Binder.clearCallingIdentity();
7953 try {
7954 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7955 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007956 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007957 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007958
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007959 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7960 } finally {
7961 Binder.restoreCallingIdentity(identity);
7962 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007963 }
7964
Youhan Wange64578a2016-05-02 15:32:42 -07007965 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007966 * Sets the per-account voicemail vibration.
7967 *
7968 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7969 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7970 *
7971 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7972 * voicemail vibration setting.
7973 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7974 * specific PhoneAccount.
7975 */
7976 @Override
7977 public void setVoicemailVibrationEnabled(String callingPackage,
7978 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007979 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007980 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007981 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7982 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007983 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7984 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7985 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007986 }
7987
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007988 final long identity = Binder.clearCallingIdentity();
7989 try {
7990 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7991 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007992 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007993 }
7994 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7995 } finally {
7996 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007997 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007998 }
7999
8000 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008001 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8002 *
8003 * @throws SecurityException if the caller does not have the required permission
8004 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008005 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008006 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008007 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008008 }
8009
8010 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008011 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8012 * permission.
8013 *
8014 * @throws SecurityException if the caller does not have the required permission
8015 */
8016 private void enforceSendSmsPermission() {
8017 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8018 }
8019
8020 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008021 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008022 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008023 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008024 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008025 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008026 final long identity = Binder.clearCallingIdentity();
8027 try {
8028 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008029 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008030 if (componentName == null) {
8031 throw new SecurityException(
8032 "Caller not current active visual voicemail package[null]");
8033 }
8034 String vvmPackage = componentName.getPackageName();
8035 if (!callingPackage.equals(vvmPackage)) {
8036 throw new SecurityException("Caller not current active visual voicemail package["
8037 + vvmPackage + "]");
8038 }
8039 } finally {
8040 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008041 }
8042 }
8043
8044 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008045 * Return the application ID for the app type.
8046 *
8047 * @param subId the subscription ID that this request applies to.
8048 * @param appType the uicc app type.
8049 * @return Application ID for specificied app type, or null if no uicc.
8050 */
8051 @Override
8052 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008053 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008054 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008055
8056 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008057 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008058 if (phone == null) {
8059 return null;
8060 }
8061 String aid = null;
8062 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008063 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008064 .getApplicationByType(appType).getAid();
8065 } catch (Exception e) {
8066 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8067 }
8068 return aid;
8069 } finally {
8070 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008071 }
Youhan Wange64578a2016-05-02 15:32:42 -07008072 }
8073
Youhan Wang4001d252016-05-11 10:29:41 -07008074 /**
8075 * Return the Electronic Serial Number.
8076 *
8077 * @param subId the subscription ID that this request applies to.
8078 * @return ESN or null if error.
8079 */
8080 @Override
8081 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008082 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008083 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008084
8085 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008086 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008087 if (phone == null) {
8088 return null;
8089 }
8090 String esn = null;
8091 try {
8092 esn = phone.getEsn();
8093 } catch (Exception e) {
8094 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8095 }
8096 return esn;
8097 } finally {
8098 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008099 }
Youhan Wang4001d252016-05-11 10:29:41 -07008100 }
8101
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008102 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008103 * Return the Preferred Roaming List Version.
8104 *
8105 * @param subId the subscription ID that this request applies to.
8106 * @return PRLVersion or null if error.
8107 */
8108 @Override
8109 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008110 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008111 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008112
8113 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008114 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008115 if (phone == null) {
8116 return null;
8117 }
8118 String cdmaPrlVersion = null;
8119 try {
8120 cdmaPrlVersion = phone.getCdmaPrlVersion();
8121 } catch (Exception e) {
8122 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8123 }
8124 return cdmaPrlVersion;
8125 } finally {
8126 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008127 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008128 }
8129
8130 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008131 * Get snapshot of Telephony histograms
8132 * @return List of Telephony histograms
8133 * @hide
8134 */
8135 @Override
8136 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008137 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8138 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008139
8140 final long identity = Binder.clearCallingIdentity();
8141 try {
8142 return RIL.getTelephonyRILTimingHistograms();
8143 } finally {
8144 Binder.restoreCallingIdentity(identity);
8145 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008146 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008147
8148 /**
8149 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008150 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8151 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008152 * Require system privileges. In the future we may add this to carrier APIs.
8153 *
Michele Berionne482f8202018-11-27 18:57:59 -08008154 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008155 */
8156 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008157 @TelephonyManager.SetCarrierRestrictionResult
8158 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008159 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008160 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008161
Michele Berionne482f8202018-11-27 18:57:59 -08008162 if (carrierRestrictionRules == null) {
8163 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008164 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008165
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008166 final long identity = Binder.clearCallingIdentity();
8167 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008168 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008169 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008170 } finally {
8171 Binder.restoreCallingIdentity(identity);
8172 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008173 }
8174
8175 /**
8176 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008177 * Get the allowed carrier list and the excluded carrier list, including the priority between
8178 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008179 * Require system privileges. In the future we may add this to carrier APIs.
8180 *
Michele Berionne482f8202018-11-27 18:57:59 -08008181 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008182 */
8183 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008184 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008185 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008186 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008187
8188 final long identity = Binder.clearCallingIdentity();
8189 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008190 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8191 if (response instanceof CarrierRestrictionRules) {
8192 return (CarrierRestrictionRules) response;
8193 }
8194 // Response is an Exception of some kind,
8195 // which is signalled to the user as a NULL retval
8196 return null;
8197 } catch (Exception e) {
8198 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8199 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008200 } finally {
8201 Binder.restoreCallingIdentity(identity);
8202 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008203 }
8204
fionaxu59545b42016-05-25 15:53:37 -07008205 /**
fionaxu59545b42016-05-25 15:53:37 -07008206 * Action set from carrier signalling broadcast receivers to enable/disable radio
8207 * @param subId the subscription ID that this action applies to.
8208 * @param enabled control enable or disable radio.
8209 * {@hide}
8210 */
8211 @Override
8212 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8213 enforceModifyPermission();
8214 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008215
8216 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008217 if (phone == null) {
8218 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8219 return;
8220 }
8221 try {
8222 phone.carrierActionSetRadioEnabled(enabled);
8223 } catch (Exception e) {
8224 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008225 } finally {
8226 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008227 }
8228 }
8229
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008230 /**
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -07008231 * Enable or disable Voice over NR (VoNR)
8232 * @param subId the subscription ID that this action applies to.
8233 * @param enabled enable or disable VoNR.
8234 * @return operation result.
8235 */
8236 @Override
8237 public int setVoNrEnabled(int subId, boolean enabled) {
8238 enforceModifyPermission();
8239 final Phone phone = getPhone(subId);
8240
8241 final long identity = Binder.clearCallingIdentity();
8242 if (phone == null) {
8243 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8244 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8245 }
8246
8247 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8248 try {
8249 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8250 workSource);
8251 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008252
8253 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8254 if (DBG) {
8255 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8256 }
8257 SubscriptionManager.setSubscriptionProperty(
8258 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8259 (enabled ? "1" : "0"));
8260 }
8261
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -07008262 return result;
8263 } finally {
8264 Binder.restoreCallingIdentity(identity);
8265 }
8266 }
8267
8268 /**
8269 * Is voice over NR enabled
8270 * @return true if VoNR is enabled else false
8271 */
8272 @Override
8273 public boolean isVoNrEnabled(int subId) {
8274 enforceReadPrivilegedPermission("isVoNrEnabled");
8275 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8276 final long identity = Binder.clearCallingIdentity();
8277 try {
8278 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8279 null, subId, workSource);
8280 if (DBG) log("isVoNrEnabled: " + isEnabled);
8281 return isEnabled;
8282 } finally {
8283 Binder.restoreCallingIdentity(identity);
8284 }
8285 }
8286
8287 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008288 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8289 * network status based on which carrier apps could apply actions accordingly,
8290 * enable/disable default url handler for example.
8291 *
8292 * @param subId the subscription ID that this action applies to.
8293 * @param report control start/stop reporting the default network status.
8294 * {@hide}
8295 */
8296 @Override
8297 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8298 enforceModifyPermission();
8299 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008300
8301 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008302 if (phone == null) {
8303 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8304 return;
8305 }
8306 try {
8307 phone.carrierActionReportDefaultNetworkStatus(report);
8308 } catch (Exception e) {
8309 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008310 } finally {
8311 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008312 }
8313 }
8314
8315 /**
fionaxud9622282017-07-17 17:51:30 -07008316 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8317 * @param subId the subscription ID that this action applies to.
8318 * {@hide}
8319 */
8320 @Override
8321 public void carrierActionResetAll(int subId) {
8322 enforceModifyPermission();
8323 final Phone phone = getPhone(subId);
8324 if (phone == null) {
8325 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8326 return;
8327 }
8328 try {
8329 phone.carrierActionResetAll();
8330 } catch (Exception e) {
8331 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8332 }
8333 }
8334
8335 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008336 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8337 * bug report is being generated.
8338 */
8339 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008340 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008341 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8342 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008343 writer.println("Permission Denial: can't dump Phone from pid="
8344 + Binder.getCallingPid()
8345 + ", uid=" + Binder.getCallingUid()
8346 + "without permission "
8347 + android.Manifest.permission.DUMP);
8348 return;
8349 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008350 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008351 }
Jack Yueb89b242016-06-22 13:27:47 -07008352
Brad Ebingerdac2f002018-04-03 15:17:52 -07008353 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008354 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8355 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8356 @NonNull String[] args) {
8357 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8358 this, in.getFileDescriptor(), out.getFileDescriptor(),
8359 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008360 }
8361
Jack Yueb89b242016-06-22 13:27:47 -07008362 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008363 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008364 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008365 * @param reason the reason the data enable change is taking place
8366 * @param enabled True if enabling the data, otherwise disabling.
8367 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008368 */
8369 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008370 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008371 boolean enabled) {
8372 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8373 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8374 try {
8375 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008376 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008377 } catch (SecurityException se) {
8378 enforceModifyPermission();
8379 }
8380 } else {
8381 enforceModifyPermission();
8382 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008383
8384 final long identity = Binder.clearCallingIdentity();
8385 try {
8386 Phone phone = getPhone(subId);
8387 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008388 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8389 phone.carrierActionSetMeteredApnsEnabled(enabled);
8390 } else {
Jack Yu6bc9c8b2021-12-17 23:14:15 -08008391 if (phone.isUsingNewDataStack()) {
8392 phone.getDataSettingsManager().setDataEnabled(reason, enabled);
8393 } else {
8394 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8395 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008396 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008397 }
8398 } finally {
8399 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008400 }
8401 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008402
8403 /**
8404 * Get Client request stats
8405 * @return List of Client Request Stats
8406 * @hide
8407 */
8408 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008409 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8410 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008411 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008412 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008413 return null;
8414 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008415 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008416
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008417 final long identity = Binder.clearCallingIdentity();
8418 try {
8419 if (phone != null) {
8420 return phone.getClientRequestStats();
8421 }
8422
8423 return null;
8424 } finally {
8425 Binder.restoreCallingIdentity(identity);
8426 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008427 }
8428
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008429 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008430 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008431 if (uid == Process.ROOT_UID && packageName == null) {
8432 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8433 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8434 // exception. ROOT_UID seems not to have a valid package name returned by
8435 // PackageManager, so just fake it here to avoid issues when running telephony shell
8436 // commands that plumb through the RIL as root, like so:
8437 // $ adb root
8438 // $ adb shell cmd phone ...
8439 packageName = "root";
8440 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008441 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008442 }
Jack Yueb4124c2017-02-16 15:32:43 -08008443
8444 /**
Grace Chen70990072017-03-24 17:21:30 -07008445 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008446 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008447 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008448 * @param state State of SIM (power down, power up, pass through)
8449 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8450 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8451 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008452 *
8453 **/
8454 @Override
Grace Chen70990072017-03-24 17:21:30 -07008455 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008456 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008457 Phone phone = PhoneFactory.getPhone(slotIndex);
8458
vagdeviaf9a5b92018-08-15 16:01:53 -07008459 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8460
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008461 final long identity = Binder.clearCallingIdentity();
8462 try {
8463 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008464 phone.setSimPowerState(state, null, workSource);
8465 }
8466 } finally {
8467 Binder.restoreCallingIdentity(identity);
8468 }
8469 }
8470
8471 /**
8472 * Set SIM card power state.
8473 *
8474 * @param slotIndex SIM slot id.
8475 * @param state State of SIM (power down, power up, pass through)
8476 * @param callback callback to trigger after success or failure
8477 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8478 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8479 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8480 *
8481 **/
8482 @Override
8483 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8484 IIntegerConsumer callback) {
8485 enforceModifyPermission();
8486 Phone phone = PhoneFactory.getPhone(slotIndex);
8487
8488 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8489
8490 final long identity = Binder.clearCallingIdentity();
8491 try {
8492 if (phone != null) {
8493 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8494 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008495 }
8496 } finally {
8497 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008498 }
8499 }
Shuo Qiandd210312017-04-12 22:11:33 +00008500
Tyler Gunn65d45c22017-06-05 11:22:26 -07008501 private boolean isUssdApiAllowed(int subId) {
8502 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008503 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008504 if (configManager == null) {
8505 return false;
8506 }
8507 PersistableBundle pb = configManager.getConfigForSubId(subId);
8508 if (pb == null) {
8509 return false;
8510 }
8511 return pb.getBoolean(
8512 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8513 }
8514
Shuo Qiandd210312017-04-12 22:11:33 +00008515 /**
8516 * Check if phone is in emergency callback mode
8517 * @return true if phone is in emergency callback mode
8518 * @param subId sub id
8519 */
goneil9c5f4872017-12-05 14:07:56 -08008520 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008521 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008522 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008523 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008524
8525 final long identity = Binder.clearCallingIdentity();
8526 try {
8527 if (phone != null) {
8528 return phone.isInEcm();
8529 } else {
8530 return false;
8531 }
8532 } finally {
8533 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008534 }
8535 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008536
8537 /**
8538 * Get the current signal strength information for the given subscription.
8539 * Because this information is not updated when the device is in a low power state
8540 * it should not be relied-upon to be current.
8541 * @param subId Subscription index
8542 * @return the most recent cached signal strength info from the modem
8543 */
8544 @Override
8545 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008546 final long identity = Binder.clearCallingIdentity();
8547 try {
8548 Phone p = getPhone(subId);
8549 if (p == null) {
8550 return null;
8551 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008552
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008553 return p.getSignalStrength();
8554 } finally {
8555 Binder.restoreCallingIdentity(identity);
8556 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008557 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008558
Pengquan Meng77b7f132018-08-22 14:49:57 -07008559 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008560 * Get the current modem radio state for the given slot.
8561 * @param slotIndex slot index.
8562 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008563 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008564 * @return the current radio power state from the modem
8565 */
8566 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008567 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008568 Phone phone = PhoneFactory.getPhone(slotIndex);
8569 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008570 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8571 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008572 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8573 }
8574
8575 final long identity = Binder.clearCallingIdentity();
8576 try {
8577 return phone.getRadioPowerState();
8578 } finally {
8579 Binder.restoreCallingIdentity(identity);
8580 }
8581 }
8582 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8583 }
8584
8585 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008586 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8587 *
8588 * <p>Requires one of the following permissions:
8589 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008590 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008591 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8592 * privileges.
8593 *
8594 * @param subId subscription id
8595 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8596 * {@code false}.
8597 */
8598 @Override
8599 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008600 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008601 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008602 try {
8603 mApp.enforceCallingOrSelfPermission(
8604 android.Manifest.permission.ACCESS_NETWORK_STATE,
8605 functionName);
8606 } catch (Exception e) {
8607 mApp.enforceCallingOrSelfPermission(
8608 permission.READ_BASIC_PHONE_STATE, functionName);
8609 }
Shuo Qian093013d2020-08-13 15:42:55 -07008610 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008611 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008612 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008613 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008614
Pengquan Menga1bb6272018-09-06 09:59:22 -07008615 boolean isEnabled = false;
8616 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008617 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008618 Phone phone = getPhone(subId);
8619 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008620 } finally {
8621 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008622 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008623 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008624 }
8625
8626
8627 /**
8628 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8629 *
8630 * <p> Requires permission:
8631 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8632 * privileges.
8633 *
8634 * @param subId subscription id
8635 * @param isEnabled {@code true} means enable, {@code false} means disable.
8636 */
8637 @Override
8638 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008639 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8640 mApp, subId, "setDataRoamingEnabled");
8641
Pengquan Menga1bb6272018-09-06 09:59:22 -07008642 final long identity = Binder.clearCallingIdentity();
8643 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008644 Phone phone = getPhone(subId);
8645 if (phone != null) {
8646 phone.setDataRoamingEnabled(isEnabled);
8647 }
8648 } finally {
8649 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008650 }
8651 }
8652
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008653 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008654 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008655 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008656 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008657 mApp, subId, "isManualNetworkSelectionAllowed");
8658
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008659 boolean isAllowed = true;
8660 final long identity = Binder.clearCallingIdentity();
8661 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008662 Phone phone = getPhone(subId);
8663 if (phone != null) {
8664 isAllowed = phone.isCspPlmnEnabled();
8665 }
8666 } finally {
8667 Binder.restoreCallingIdentity(identity);
8668 }
8669 return isAllowed;
8670 }
8671
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008672 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8673 UiccProfile profile = port.getUiccProfile();
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08008674 if (profile == null) {
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008675 return false;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008676 }
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08008677 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8678 if (phone == null) {
8679 return false;
8680 }
8681 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8682 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8683 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008684 }
8685
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008686 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008687 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjs29b7e8e2021-11-17 04:05:58 +00008688 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008689 mApp.getSystemService(AppOpsManager.class)
8690 .checkPackage(Binder.getCallingUid(), callingPackage);
8691
Jordan Liu1e142fc2019-04-22 15:10:43 -07008692 boolean hasReadPermission = false;
sandeepjs0a502c42021-09-27 15:34:44 +00008693 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008694 try {
8695 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008696 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008697 } catch (SecurityException e) {
8698 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8699 // has carrier privileges on an active UICC
Rambo Wang04d1ace2022-02-23 13:41:02 -08008700 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08008701 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008702 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008703 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008704 }
sandeepjs0a502c42021-09-27 15:34:44 +00008705 // checking compatibility, if calling app's target SDK is T and beyond.
8706 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8707 Binder.getCallingUid())) {
8708 isIccIdAccessRestricted = true;
8709 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008710 final long identity = Binder.clearCallingIdentity();
8711 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008712 UiccController uiccController = UiccController.getInstance();
8713 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008714 if (hasReadPermission) {
8715 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008716 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008717
8718 // Remove private info if the caller doesn't have access
8719 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8720 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjs0a502c42021-09-27 15:34:44 +00008721 //setting the value after compatibility check
8722 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008723 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8724 // is available
sandeepjs0a502c42021-09-27 15:34:44 +00008725 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008726 if (card == null) {
8727 // assume no access if the card is unavailable
sandeepjs0a502c42021-09-27 15:34:44 +00008728 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008729 continue;
8730 }
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008731 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8732 if (portInfos.isEmpty()) {
sandeepjs0a502c42021-09-27 15:34:44 +00008733 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008734 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008735 }
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008736 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8737 for (UiccPortInfo portInfo : portInfos) {
8738 UiccPort port = uiccController.getUiccPortForSlot(
8739 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8740 if (port == null) {
8741 // assume no access if port is null
8742 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8743 continue;
8744 }
8745 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8746 uiccPortInfos.add(portInfo);
8747 } else {
8748 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8749 }
8750 }
8751 filteredInfos.add(new UiccCardInfo(
8752 cardInfo.isEuicc(),
8753 cardInfo.getCardId(),
8754 null,
8755 cardInfo.getPhysicalSlotIndex(),
8756 cardInfo.isRemovable(),
8757 cardInfo.isMultipleEnabledProfilesSupported(),
8758 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008759 }
8760 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008761 } finally {
8762 Binder.restoreCallingIdentity(identity);
8763 }
8764 }
8765
sandeepjs0a502c42021-09-27 15:34:44 +00008766 /**
8767 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8768 * generally private and require carrier privileges to view.
8769 *
8770 * @hide
8771 */
8772 @NonNull
8773 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8774 List<UiccPortInfo> portinfo = new ArrayList<>();
8775 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8776 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8777 }
8778 return new UiccCardInfo(
8779 cardInfo.isEuicc(),
8780 cardInfo.getCardId(),
8781 null,
8782 cardInfo.getPhysicalSlotIndex(),
8783 cardInfo.isRemovable(),
8784 cardInfo.isMultipleEnabledProfilesSupported(),
8785 portinfo
8786 );
8787 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008788
sandeepjs0a502c42021-09-27 15:34:44 +00008789 /**
8790 * @hide
8791 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8792 * These values are generally private and require carrier privileges to view.
8793 */
8794 @NonNull
8795 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8796 return new UiccPortInfo(
8797 UiccPortInfo.ICCID_REDACTED,
8798 portInfo.getPortIndex(),
8799 portInfo.getLogicalSlotIndex(),
8800 portInfo.isActive()
8801 );
8802 }
8803 @Override
8804 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjs29b7e8e2021-11-17 04:05:58 +00008805 // Verify that the callingPackage belongs to the calling UID
sandeepjs0a502c42021-09-27 15:34:44 +00008806 mApp.getSystemService(AppOpsManager.class)
8807 .checkPackage(Binder.getCallingUid(), callingPackage);
8808
8809 boolean hasReadPermission = false;
8810 boolean isLogicalSlotAccessRestricted = false;
sandeepjs0a502c42021-09-27 15:34:44 +00008811
8812 try {
8813 enforceReadPrivilegedPermission("getUiccSlotsInfo");
8814 hasReadPermission = true;
8815 } catch (SecurityException e) {
8816 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8817 // has carrier privileges on an active UICC
Rambo Wang04d1ace2022-02-23 13:41:02 -08008818 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
sandeepjs0a502c42021-09-27 15:34:44 +00008819 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8820 hasReadPermission = true;
8821 }
8822 }
8823
8824 // checking compatibility, if calling app's target SDK is T and beyond.
8825 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8826 Binder.getCallingUid())) {
8827 isLogicalSlotAccessRestricted = true;
8828 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008829 final long identity = Binder.clearCallingIdentity();
8830 try {
8831 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8832 if (slots == null) {
8833 Rlog.i(LOG_TAG, "slots is null.");
8834 return null;
8835 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008836 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8837 for (int i = 0; i < slots.length; i++) {
8838 UiccSlot slot = slots[i];
8839 if (slot == null) {
8840 continue;
8841 }
8842
Jordan Liu7be7e652019-05-06 18:55:02 +00008843 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008844 UiccCard card = slot.getUiccCard();
8845 if (card != null) {
8846 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008847 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008848 cardId = slot.getEid();
8849 if (TextUtils.isEmpty(cardId)) {
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008850 // If cardId is null, use iccId of default port as cardId. Check if has
8851 // read permission otherwise set to null.(card is null which means no
8852 // carrier permission)
8853 cardId = hasReadPermission ? slot.getIccId(
8854 TelephonyManager.DEFAULT_PORT_INDEX) : null;
Jordan Liu01bd00d2019-09-12 16:19:43 -07008855 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008856 }
8857
Jordan Liu857451f2019-05-09 16:35:35 -07008858 if (cardId != null) {
8859 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8860 // if cardId is an EID, it's all digits so this is fine
8861 cardId = IccUtils.stripTrailingFs(cardId);
8862 }
8863
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008864 int cardState = 0;
8865 switch (slot.getCardState()) {
8866 case CARDSTATE_ABSENT:
8867 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8868 break;
8869 case CARDSTATE_PRESENT:
8870 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8871 break;
8872 case CARDSTATE_ERROR:
8873 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8874 break;
8875 case CARDSTATE_RESTRICTED:
8876 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8877 break;
8878 default:
8879 break;
8880
8881 }
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008882 List<UiccPortInfo> portInfos = new ArrayList<>();
8883 int[] portIndexes = slot.getPortList();
8884 for (int portIdx : portIndexes) {
8885 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
8886 callingPackage, hasReadPermission));
8887 if (slot.isPortActive(portIdx)) {
8888 UiccPort port = slot.getUiccCard().getUiccPort(portIdx);
8889 portInfos.add(new UiccPortInfo(iccId, port.getPortIdx(),
8890 port.getPhoneId(), true));
8891 } else {
8892 portInfos.add(new UiccPortInfo(iccId, portIdx, -1, false));
8893 }
8894 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008895 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008896 slot.isEuicc(),
8897 cardId,
8898 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08008899 slot.isExtendedApduSupported(),
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008900 slot.isRemovable(), portInfos);
sandeepjs0a502c42021-09-27 15:34:44 +00008901 //setting the value after compatibility check
8902 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008903 }
8904 return infos;
8905 } finally {
8906 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008907 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008908 }
8909
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008910 /* Returns null if doesn't have read permission or carrier privilege access. */
8911 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
8912 boolean hasReadPermission) {
8913 String iccId = slot.getIccId(portIndex);
8914 if (hasReadPermission) { // if has read permission
8915 return iccId;
8916 } else {
8917 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
8918 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
8919 // if no read permission, checking carrier privilege access
8920 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8921 return iccId;
8922 }
8923 }
8924 }
8925 // No read permission or carrier privilege access.
8926 return UiccPortInfo.ICCID_REDACTED;
8927 }
8928
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008929 @Override
sandeepjs0a502c42021-09-27 15:34:44 +00008930 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008931 public boolean switchSlots(int[] physicalSlots) {
8932 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008933
8934 final long identity = Binder.clearCallingIdentity();
8935 try {
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008936 List<UiccSlotMapping> slotMappings = new ArrayList<>();
8937 for (int i = 0; i < physicalSlots.length; i++) {
8938 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
8939 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
8940 physicalSlots[i], i));
8941 }
8942 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008943 } finally {
8944 Binder.restoreCallingIdentity(identity);
8945 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008946 }
Jack Yu4c988042018-02-27 15:30:01 -08008947
8948 @Override
sandeepjs0a502c42021-09-27 15:34:44 +00008949 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
8950 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
8951 enforceModifyPermission();
8952
8953 final long identity = Binder.clearCallingIdentity();
8954 try {
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008955 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjs0a502c42021-09-27 15:34:44 +00008956 } finally {
8957 Binder.restoreCallingIdentity(identity);
8958 }
8959 }
8960
8961 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008962 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008963 final long identity = Binder.clearCallingIdentity();
8964 try {
8965 return UiccController.getInstance().getCardIdForDefaultEuicc();
8966 } finally {
8967 Binder.restoreCallingIdentity(identity);
8968 }
8969 }
8970
Pengquan Meng85728fb2018-03-12 16:31:21 -07008971 /**
goneil47ffb6e2018-04-06 15:40:58 -07008972 * A test API to reload the UICC profile.
8973 *
8974 * <p>Requires that the calling app has permission
8975 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8976 * @hide
8977 */
8978 @Override
8979 public void refreshUiccProfile(int subId) {
8980 enforceModifyPermission();
8981
8982 final long identity = Binder.clearCallingIdentity();
8983 try {
8984 Phone phone = getPhone(subId);
8985 if (phone == null) {
8986 return;
8987 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008988 UiccPort uiccPort = phone.getUiccPort();
8989 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07008990 return;
8991 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008992 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07008993 if (uiccProfile == null) {
8994 return;
8995 }
8996 uiccProfile.refresh();
8997 } finally {
8998 Binder.restoreCallingIdentity(identity);
8999 }
9000 }
9001
9002 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009003 * Returns false if the mobile data is disabled by default, otherwise return true.
9004 */
9005 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009006 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009007 }
9008
9009 /**
9010 * Returns true if the data roaming is enabled by default, i.e the system property
9011 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9012 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9013 */
9014 private boolean getDefaultDataRoamingEnabled(int subId) {
9015 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009016 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009017 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009018 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9019 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9020 return isDataRoamingEnabled;
9021 }
9022
9023 /**
9024 * Returns the default network type for the given {@code subId}, if the default network type is
9025 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9026 */
9027 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009028 List<Integer> list = TelephonyProperties.default_network();
9029 int phoneId = mSubscriptionController.getPhoneId(subId);
9030 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9031 return list.get(phoneId);
9032 }
9033 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009034 }
fionaxua13278b2018-03-21 00:08:13 -07009035
9036 @Override
9037 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009038 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009039 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009040
9041 final long identity = Binder.clearCallingIdentity();
9042 try {
9043 final Phone phone = getPhone(subId);
9044 if (phone == null) {
9045 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9046 return;
9047 }
Rambo Wanga7436882022-01-13 21:51:44 -08009048 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9049 if (cpt != null) {
9050 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9051 }
9052 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009053 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9054 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009055 if (carrierPrivilegeRules == null) {
9056 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9057 } else {
9058 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9059 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009060 } finally {
9061 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009062 }
fionaxua13278b2018-03-21 00:08:13 -07009063 }
9064
9065 @Override
9066 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009067 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009068
9069 final long identity = Binder.clearCallingIdentity();
9070 try {
9071 final Phone phone = getPhone(subId);
9072 if (phone == null) {
9073 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9074 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9075 }
9076 return phone.getCarrierIdListVersion();
9077 } finally {
9078 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009079 }
fionaxua13278b2018-03-21 00:08:13 -07009080 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009081
9082 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009083 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9084 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009085 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009086 mApp, subId, callingPackage, callingFeatureId,
9087 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009088 return -1;
9089 }
9090
9091 final long identity = Binder.clearCallingIdentity();
9092 try {
9093 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9094 } finally {
9095 Binder.restoreCallingIdentity(identity);
9096 }
9097 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009098
9099 @Override
9100 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009101 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009102 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009103 mApp, subId, "getCdmaRoamingMode");
9104
9105 final long identity = Binder.clearCallingIdentity();
9106 try {
9107 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9108 } finally {
9109 Binder.restoreCallingIdentity(identity);
9110 }
9111 }
9112
9113 @Override
9114 public boolean setCdmaRoamingMode(int subId, int mode) {
9115 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9116 mApp, subId, "setCdmaRoamingMode");
9117
9118 final long identity = Binder.clearCallingIdentity();
9119 try {
9120 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9121 } finally {
9122 Binder.restoreCallingIdentity(identity);
9123 }
9124 }
9125
9126 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009127 public int getCdmaSubscriptionMode(int subId) {
9128 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009129 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009130 mApp, subId, "getCdmaSubscriptionMode");
9131
9132 final long identity = Binder.clearCallingIdentity();
9133 try {
9134 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9135 } finally {
9136 Binder.restoreCallingIdentity(identity);
9137 }
9138 }
9139
9140 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009141 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9142 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9143 mApp, subId, "setCdmaSubscriptionMode");
9144
9145 final long identity = Binder.clearCallingIdentity();
9146 try {
9147 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9148 } finally {
9149 Binder.restoreCallingIdentity(identity);
9150 }
9151 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009152
sqianc5eccab2018-10-19 18:46:41 -07009153 @Override
sqian8c685422019-02-22 15:55:18 -08009154 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009155 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009156 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009157 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9158 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009159 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9160 }
9161 final long identity = Binder.clearCallingIdentity();
9162 try {
sqian854d44b2018-12-12 16:48:18 -08009163 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9164 for (Phone phone: PhoneFactory.getPhones()) {
9165 if (phone.getEmergencyNumberTracker() != null
9166 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9167 emergencyNumberListInternal.put(
9168 phone.getSubId(),
9169 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9170 }
sqian11b7a0e2018-12-05 18:48:28 -08009171 }
sqian854d44b2018-12-12 16:48:18 -08009172 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009173 } finally {
9174 Binder.restoreCallingIdentity(identity);
9175 }
sqianc5eccab2018-10-19 18:46:41 -07009176 }
9177
9178 @Override
sqian8c685422019-02-22 15:55:18 -08009179 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009180 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009181 if (!exactMatch) {
9182 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009183 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009184 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009185 }
9186 final long identity = Binder.clearCallingIdentity();
9187 try {
sqian854d44b2018-12-12 16:48:18 -08009188 for (Phone phone: PhoneFactory.getPhones()) {
9189 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009190 && phone.getEmergencyNumberTracker()
9191 .isEmergencyNumber(number, exactMatch)) {
9192 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009193 }
sqian11b7a0e2018-12-05 18:48:28 -08009194 }
9195 return false;
9196 } finally {
9197 Binder.restoreCallingIdentity(identity);
9198 }
9199 }
9200
sqianf4ca7ed2019-01-15 18:32:07 -08009201 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009202 * Start emergency callback mode for GsmCdmaPhone for testing.
9203 */
9204 @Override
9205 public void startEmergencyCallbackMode() {
9206 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9207 "startEmergencyCallbackMode");
9208 enforceModifyPermission();
9209 final long identity = Binder.clearCallingIdentity();
9210 try {
9211 for (Phone phone : PhoneFactory.getPhones()) {
9212 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9213 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9214 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9215 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9216 gsmCdmaPhone.obtainMessage(
9217 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9218 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9219 }
9220 }
9221 } finally {
9222 Binder.restoreCallingIdentity(identity);
9223 }
9224 }
9225
9226 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009227 * Update emergency number list for test mode.
9228 */
9229 @Override
9230 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9231 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9232 "updateEmergencyNumberListTestMode");
9233
9234 final long identity = Binder.clearCallingIdentity();
9235 try {
9236 for (Phone phone: PhoneFactory.getPhones()) {
9237 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9238 if (tracker != null) {
9239 tracker.executeEmergencyNumberTestModeCommand(action, num);
9240 }
9241 }
9242 } finally {
9243 Binder.restoreCallingIdentity(identity);
9244 }
9245 }
9246
9247 /**
9248 * Get the full emergency number list for test mode.
9249 */
9250 @Override
9251 public List<String> getEmergencyNumberListTestMode() {
9252 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9253 "getEmergencyNumberListTestMode");
9254
9255 final long identity = Binder.clearCallingIdentity();
9256 try {
9257 Set<String> emergencyNumbers = new HashSet<>();
9258 for (Phone phone: PhoneFactory.getPhones()) {
9259 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9260 if (tracker != null) {
9261 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9262 emergencyNumbers.add(num.getNumber());
9263 }
9264 }
9265 }
9266 return new ArrayList<>(emergencyNumbers);
9267 } finally {
9268 Binder.restoreCallingIdentity(identity);
9269 }
9270 }
9271
chen xud6b45bd2018-10-30 22:27:10 -07009272 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009273 public int getEmergencyNumberDbVersion(int subId) {
9274 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9275
9276 final long identity = Binder.clearCallingIdentity();
9277 try {
9278 final Phone phone = getPhone(subId);
9279 if (phone == null) {
9280 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9281 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9282 }
9283 return phone.getEmergencyNumberDbVersion();
9284 } finally {
9285 Binder.restoreCallingIdentity(identity);
9286 }
9287 }
9288
9289 @Override
9290 public void notifyOtaEmergencyNumberDbInstalled() {
9291 enforceModifyPermission();
9292
9293 final long identity = Binder.clearCallingIdentity();
9294 try {
9295 for (Phone phone: PhoneFactory.getPhones()) {
9296 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9297 if (tracker != null) {
9298 tracker.updateOtaEmergencyNumberDatabase();
9299 }
9300 }
9301 } finally {
9302 Binder.restoreCallingIdentity(identity);
9303 }
9304 }
9305
9306 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009307 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009308 enforceActiveEmergencySessionPermission();
9309
9310 final long identity = Binder.clearCallingIdentity();
9311 try {
9312 for (Phone phone: PhoneFactory.getPhones()) {
9313 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9314 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009315 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9316 }
9317 }
9318 } finally {
9319 Binder.restoreCallingIdentity(identity);
9320 }
9321 }
9322
9323 @Override
9324 public void resetOtaEmergencyNumberDbFilePath() {
9325 enforceActiveEmergencySessionPermission();
9326
9327 final long identity = Binder.clearCallingIdentity();
9328 try {
9329 for (Phone phone: PhoneFactory.getPhones()) {
9330 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9331 if (tracker != null) {
9332 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009333 }
9334 }
9335 } finally {
9336 Binder.restoreCallingIdentity(identity);
9337 }
9338 }
9339
9340 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009341 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9342 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9343 Phone phone = getPhone(subId);
9344 if (phone == null) {
9345 return null;
9346 }
9347 final long identity = Binder.clearCallingIdentity();
9348 try {
9349 UiccProfile profile = UiccController.getInstance()
9350 .getUiccProfileForPhone(phone.getPhoneId());
9351 if (profile != null) {
9352 return profile.getCertsFromCarrierPrivilegeAccessRules();
9353 }
9354 } finally {
9355 Binder.restoreCallingIdentity(identity);
9356 }
9357 return null;
9358 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009359
9360 /**
9361 * Enable or disable a modem stack.
9362 */
9363 @Override
9364 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9365 enforceModifyPermission();
9366
9367 final long identity = Binder.clearCallingIdentity();
9368 try {
9369 Phone phone = PhoneFactory.getPhone(slotIndex);
9370 if (phone == null) {
9371 return false;
9372 } else {
9373 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9374 }
9375 } finally {
9376 Binder.restoreCallingIdentity(identity);
9377 }
9378 }
Michelecea4cf22018-12-21 15:00:11 -08009379
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009380 /**
9381 * Whether a modem stack is enabled or not.
9382 */
9383 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009384 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9385 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009386 Phone phone = PhoneFactory.getPhone(slotIndex);
9387 if (phone == null) return false;
9388
9389 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009390 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9391 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009392 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9393 }
9394
9395 final long identity = Binder.clearCallingIdentity();
9396 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009397 try {
9398 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9399 } catch (NoSuchElementException ex) {
9400 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9401 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009402 } finally {
9403 Binder.restoreCallingIdentity(identity);
9404 }
9405 }
9406
Michelecea4cf22018-12-21 15:00:11 -08009407 @Override
Michele0ea7d782019-03-19 14:58:42 -07009408 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009409 enforceModifyPermission();
9410
9411 final long identity = Binder.clearCallingIdentity();
9412 try {
9413 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009414 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009415 .commit();
9416 } finally {
9417 Binder.restoreCallingIdentity(identity);
9418 }
9419 }
9420
9421 @Override
Michele0ea7d782019-03-19 14:58:42 -07009422 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009423 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009424 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009425 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9426 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009427 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009428 }
Michelecea4cf22018-12-21 15:00:11 -08009429
9430 final long identity = Binder.clearCallingIdentity();
9431 try {
Michele0ea7d782019-03-19 14:58:42 -07009432 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009433 } finally {
9434 Binder.restoreCallingIdentity(identity);
9435 }
9436 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009437
Michele0ea7d782019-03-19 14:58:42 -07009438 @TelephonyManager.IsMultiSimSupportedResult
9439 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009440 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9441 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9442 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009443 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9444 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009445 }
9446 // Check if the hardware supports multisim functionality. If usage of multisim is not
9447 // supported by the modem, indicate that it is restricted.
9448 PhoneCapability staticCapability =
9449 mPhoneConfigurationManager.getStaticPhoneCapability();
9450 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009451 loge("isMultiSimSupportedInternal: no static configuration available");
9452 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009453 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009454 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009455 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9456 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009457 }
9458 // Check if support of multiple SIMs is restricted by carrier
9459 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009460 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009461 }
9462
Michele0ea7d782019-03-19 14:58:42 -07009463 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009464 }
9465
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009466 /**
9467 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009468 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9469 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9470 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009471 * @param numOfSims number of active sims we want to switch to
9472 */
9473 @Override
9474 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009475 if (numOfSims == 1) {
9476 enforceModifyPermission();
9477 } else {
9478 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9479 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9480 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009481 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009482
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009483 try {
Michele30b57b22019-03-01 12:01:14 -08009484 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009485 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009486 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9487 return;
9488 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009489 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9490 } finally {
9491 Binder.restoreCallingIdentity(identity);
9492 }
9493 }
9494
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009495 @Override
9496 public boolean isApplicationOnUicc(int subId, int appType) {
9497 enforceReadPrivilegedPermission("isApplicationOnUicc");
9498 Phone phone = getPhone(subId);
9499 if (phone == null) {
9500 return false;
9501 }
9502 final long identity = Binder.clearCallingIdentity();
9503 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009504 UiccPort uiccPort = phone.getUiccPort();
9505 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009506 return false;
9507 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009508 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009509 if (uiccProfile == null) {
9510 return false;
9511 }
9512 if (TelephonyManager.APPTYPE_SIM <= appType
9513 && appType <= TelephonyManager.APPTYPE_ISIM) {
9514 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9515 }
9516 return false;
9517 } finally {
9518 Binder.restoreCallingIdentity(identity);
9519 }
9520 }
9521
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009522 /**
chen xub4baa772019-04-03 10:23:41 -07009523 * Get whether making changes to modem configurations will trigger reboot.
9524 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009525 */
9526 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009527 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9528 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009529 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009530 mApp, subId, callingPackage, callingFeatureId,
9531 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009532 return false;
9533 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009534 final long identity = Binder.clearCallingIdentity();
9535 try {
9536 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9537 } finally {
9538 Binder.restoreCallingIdentity(identity);
9539 }
9540 }
9541
Nathan Harold29f5f052019-02-15 13:41:57 -08009542 private void updateModemStateMetrics() {
9543 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9544 // TODO: check the state for each modem if the api is ready.
9545 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9546 }
9547
Pengquan Meng3889a572019-01-23 11:16:29 -08009548 @Override
sandeepjs29b7e8e2021-11-17 04:05:58 +00009549 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009550 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjs29b7e8e2021-11-17 04:05:58 +00009551 // Verify that the callingPackage belongs to the calling UID
9552 mApp.getSystemService(AppOpsManager.class)
9553 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009554 final long identity = Binder.clearCallingIdentity();
sandeepjs29b7e8e2021-11-17 04:05:58 +00009555 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009556 try {
sandeepjs29b7e8e2021-11-17 04:05:58 +00009557 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9558 if (slotInfos != null) {
9559 for (int i = 0; i < slotInfos.length; i++) {
9560 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9561 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9562 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9563 portInfo.getLogicalSlotIndex()));
9564 }
9565 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009566 }
9567 }
sandeepjs29b7e8e2021-11-17 04:05:58 +00009568 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009569 } finally {
9570 Binder.restoreCallingIdentity(identity);
9571 }
9572 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009573
9574 /**
9575 * Get the IRadio HAL Version
9576 */
9577 @Override
9578 public int getRadioHalVersion() {
9579 Phone phone = getDefaultPhone();
9580 if (phone == null) return -1;
9581 HalVersion hv = phone.getHalVersion();
9582 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9583 return hv.major * 100 + hv.minor;
9584 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009585
9586 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009587 * Get the current calling package name.
9588 * @return the current calling package name
9589 */
9590 @Override
9591 public String getCurrentPackageName() {
9592 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9593 }
9594
9595 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009596 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9597 * corresponding network requests on a subId.
9598 *
9599 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009600 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009601 * 2) APN is un-metered for this subscription, or
9602 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009603 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009604 *
9605 * @return whether data is allowed for a apn type.
9606 *
9607 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009608 */
9609 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009610 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009611 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9612 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009613
9614 // Now that all security checks passes, perform the operation as ourselves.
9615 final long identity = Binder.clearCallingIdentity();
9616 try {
9617 Phone phone = getPhone(subId);
9618 if (phone == null) return false;
9619
Jack Yu41407ee2019-05-13 16:54:09 -07009620 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009621 boolean isDataEnabled;
9622 if (phone.isUsingNewDataStack()) {
9623 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
9624 } else {
9625 isDataEnabled = phone.getDataEnabledSettings().isDataEnabled(apnType);
9626 }
9627 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009628 } finally {
9629 Binder.restoreCallingIdentity(identity);
9630 }
9631 }
9632
9633 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009634 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009635 enforceReadPrivilegedPermission("isApnMetered");
9636
9637 // Now that all security checks passes, perform the operation as ourselves.
9638 final long identity = Binder.clearCallingIdentity();
9639 try {
9640 Phone phone = getPhone(subId);
9641 if (phone == null) return true; // By default return true.
9642
Jack Yu41407ee2019-05-13 16:54:09 -07009643 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009644 } finally {
9645 Binder.restoreCallingIdentity(identity);
9646 }
9647 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009648
9649 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009650 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9651 int subscriptionId, IBooleanConsumer resultCallback) {
9652 enforceModifyPermission();
9653 long token = Binder.clearCallingIdentity();
9654 try {
9655 Phone phone = getPhone(subscriptionId);
9656 if (phone == null) {
9657 try {
9658 if (resultCallback != null) {
9659 resultCallback.accept(false);
9660 }
9661 } catch (RemoteException e) {
9662 // ignore
9663 }
9664 return;
9665 }
9666 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9667 Pair.create(specifiers, (x) -> {
9668 try {
9669 if (resultCallback != null) {
9670 resultCallback.accept(x);
9671 }
9672 } catch (RemoteException e) {
9673 // ignore
9674 }
9675 });
9676 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9677 } finally {
9678 Binder.restoreCallingIdentity(token);
9679 }
9680 }
9681
9682 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009683 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9684 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009685 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009686 mApp, subId, "getSystemSelectionChannels");
9687 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9688 final long identity = Binder.clearCallingIdentity();
9689 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009690 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9691 if (result instanceof IllegalStateException) {
9692 throw (IllegalStateException) result;
9693 }
9694 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009695 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9696 return specifiers;
9697 } finally {
9698 Binder.restoreCallingIdentity(identity);
9699 }
9700 }
9701
9702 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009703 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009704 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009705 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9706 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9707 if (iccRecords == null) {
9708 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9709 return false;
9710 }
9711 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9712 }
9713
9714 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009715 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9716 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009717 if (callingPackage == null) {
9718 callingPackage = getCurrentPackageName();
9719 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009720 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9721 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009722 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9723 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009724 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9725 }
9726 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9727 Intent intent = new Intent();
9728 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9729 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9730 // Bring up choose default SMS subscription dialog right now
9731 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9732 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9733 mApp.startActivity(intent);
9734 }
chen xud5ca2d52019-05-28 15:20:57 -07009735
9736 @Override
9737 public String getMmsUAProfUrl(int subId) {
9738 //TODO investigate if this API should require proper permission check in R b/133791609
9739 final long identity = Binder.clearCallingIdentity();
9740 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009741 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9742 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9743 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9744 return carrierUAProfUrl;
9745 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009746 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9747 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009748 } finally {
9749 Binder.restoreCallingIdentity(identity);
9750 }
9751 }
9752
9753 @Override
9754 public String getMmsUserAgent(int subId) {
9755 //TODO investigate if this API should require proper permission check in R b/133791609
9756 final long identity = Binder.clearCallingIdentity();
9757 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009758 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9759 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9760 if (!TextUtils.isEmpty(carrierUserAgent)) {
9761 return carrierUserAgent;
9762 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009763 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9764 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009765 } finally {
9766 Binder.restoreCallingIdentity(identity);
9767 }
9768 }
Jack Yub07d4972019-05-28 16:12:25 -07009769
9770 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009771 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9772 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009773
Jack Yub07d4972019-05-28 16:12:25 -07009774 final long identity = Binder.clearCallingIdentity();
9775 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009776 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009777 if (phone == null) return false;
9778
Hall Liua62f5da2020-09-25 10:42:19 -07009779 switch (policy) {
9780 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009781 if (phone.isUsingNewDataStack()) {
9782 return phone.getDataSettingsManager().isDataAllowedInVoiceCall();
9783 } else {
9784 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9785 }
Hall Liua62f5da2020-09-25 10:42:19 -07009786 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009787 if (phone.isUsingNewDataStack()) {
9788 return phone.getDataSettingsManager().isMmsAlwaysAllowed();
9789 } else {
9790 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9791 }
Hall Liua62f5da2020-09-25 10:42:19 -07009792 default:
9793 throw new IllegalArgumentException(policy + " is not a valid policy");
9794 }
Jack Yub07d4972019-05-28 16:12:25 -07009795 } finally {
9796 Binder.restoreCallingIdentity(identity);
9797 }
9798 }
9799
9800 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009801 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009802 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009803 enforceModifyPermission();
9804
changbettyd5c246e2019-12-24 15:40:37 +08009805 final long identity = Binder.clearCallingIdentity();
9806 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009807 Phone phone = getPhone(subscriptionId);
9808 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009809
Hall Liua62f5da2020-09-25 10:42:19 -07009810 switch (policy) {
9811 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009812 if (phone.isUsingNewDataStack()) {
9813 phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled);
9814 } else {
9815 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9816 }
Hall Liua62f5da2020-09-25 10:42:19 -07009817 break;
9818 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009819 if (phone.isUsingNewDataStack()) {
9820 phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled);
9821 } else {
9822 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9823 }
Hall Liua62f5da2020-09-25 10:42:19 -07009824 break;
9825 default:
9826 throw new IllegalArgumentException(policy + " is not a valid policy");
9827 }
changbettyd5c246e2019-12-24 15:40:37 +08009828 } finally {
9829 Binder.restoreCallingIdentity(identity);
9830 }
9831 }
9832
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009833 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009834 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009835 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9836 * otherwise.
9837 */
9838 @Override
9839 public void setCepEnabled(boolean isCepEnabled) {
9840 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9841
9842 final long identity = Binder.clearCallingIdentity();
9843 try {
9844 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9845 for (Phone phone : PhoneFactory.getPhones()) {
9846 Phone defaultPhone = phone.getImsPhone();
9847 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9848 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9849 ImsPhoneCallTracker imsPhoneCallTracker =
9850 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9851 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9852 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9853 + imsPhone.getMsisdn());
9854 }
9855 }
9856 } finally {
9857 Binder.restoreCallingIdentity(identity);
9858 }
9859 }
allenwtsu46dcc572020-01-08 18:24:03 +08009860
9861 /**
9862 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9863 *
9864 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9865 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9866 * before being read.
9867 */
9868 @Override
9869 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9870 isCompressed) {
9871 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9872 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009873 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9874 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9875 }
9876 if (!isImsAvailableOnDevice()) {
9877 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9878 "IMS not available on device.");
9879 }
9880
9881 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009882 try {
Hui Wang761a6682020-10-31 05:12:53 +00009883 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9884 } finally {
9885 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009886 }
9887 }
zoey chene02881a2019-12-30 16:11:23 +08009888
9889 @Override
9890 public boolean isIccLockEnabled(int subId) {
9891 enforceReadPrivilegedPermission("isIccLockEnabled");
9892
9893 // Now that all security checks passes, perform the operation as ourselves.
9894 final long identity = Binder.clearCallingIdentity();
9895 try {
9896 Phone phone = getPhone(subId);
9897 if (phone != null && phone.getIccCard() != null) {
9898 return phone.getIccCard().getIccLockEnabled();
9899 } else {
9900 return false;
9901 }
9902 } finally {
9903 Binder.restoreCallingIdentity(identity);
9904 }
9905 }
9906
9907 /**
9908 * Set the ICC pin lock enabled or disabled.
9909 *
9910 * @return an integer representing the status of IccLock enabled or disabled in the following
9911 * three cases:
9912 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9913 * successfully.
9914 * - Positive number and zero for remaining password attempts.
9915 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9916 *
9917 */
9918 @Override
9919 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9920 enforceModifyPermission();
9921
9922 Phone phone = getPhone(subId);
9923 if (phone == null) {
9924 return 0;
9925 }
9926 // Now that all security checks passes, perform the operation as ourselves.
9927 final long identity = Binder.clearCallingIdentity();
9928 try {
9929 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9930 new Pair<Boolean, String>(enabled, password), phone, null);
9931 return attemptsRemaining;
9932
9933 } catch (Exception e) {
9934 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9935 } finally {
9936 Binder.restoreCallingIdentity(identity);
9937 }
9938 return 0;
9939 }
9940
9941 /**
9942 * Change the ICC password used in ICC pin lock.
9943 *
9944 * @return an integer representing the status of IccLock changed in the following three cases:
9945 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9946 * - Positive number and zero for remaining password attempts.
9947 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9948 *
9949 */
9950 @Override
9951 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9952 enforceModifyPermission();
9953
9954 Phone phone = getPhone(subId);
9955 if (phone == null) {
9956 return 0;
9957 }
9958 // Now that all security checks passes, perform the operation as ourselves.
9959 final long identity = Binder.clearCallingIdentity();
9960 try {
9961 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9962 new Pair<String, String>(oldPassword, newPassword), phone, null);
9963 return attemptsRemaining;
9964
9965 } catch (Exception e) {
9966 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9967 } finally {
9968 Binder.restoreCallingIdentity(identity);
9969 }
9970 return 0;
9971 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009972
9973 /**
9974 * Request for receiving user activity notification
9975 */
9976 @Override
9977 public void requestUserActivityNotification() {
9978 if (!mNotifyUserActivity.get()
9979 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9980 mNotifyUserActivity.set(true);
9981 }
9982 }
9983
9984 /**
9985 * Called when userActivity is signalled in the power manager.
9986 * This is safe to call from any thread, with any window manager locks held or not.
9987 */
9988 @Override
9989 public void userActivity() {
9990 // ***************************************
9991 // * Inherited from PhoneWindowManager *
9992 // ***************************************
9993 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9994 // WITH ITS LOCKS HELD.
9995 //
9996 // This code must be VERY careful about the locks
9997 // it acquires.
9998 // In fact, the current code acquires way too many,
9999 // and probably has lurking deadlocks.
10000
10001 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10002 throw new SecurityException("Only the OS may call notifyUserActivity()");
10003 }
10004
10005 if (mNotifyUserActivity.getAndSet(false)) {
10006 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10007 USER_ACTIVITY_NOTIFICATION_DELAY);
10008 }
10009 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010010
10011 @Override
10012 public boolean canConnectTo5GInDsdsMode() {
10013 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10014 }
Jack Yud10cdd42020-09-28 20:28:01 -070010015
10016 @Override
10017 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10018 String callingFeatureId) {
10019 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10020 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10021 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10022 }
10023
10024 Phone phone = getPhone(subId);
10025 if (phone == null) {
10026 throw new RuntimeException("phone is not available");
10027 }
10028 // Now that all security checks passes, perform the operation as ourselves.
10029 final long identity = Binder.clearCallingIdentity();
10030 try {
10031 return phone.getEquivalentHomePlmns();
10032 } finally {
10033 Binder.restoreCallingIdentity(identity);
10034 }
10035 }
Daniel Bright59e67312020-11-13 11:49:37 -080010036
10037 @Override
10038 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010039 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10040 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010041 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010042 if (radioInterfaceCapabilities == null) {
10043 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010044 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010045 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010046 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010047
Hui Wang641e81c2020-10-12 12:14:23 -070010048 @Override
10049 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10050 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010051 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10052 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10053 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10054 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10055 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010056 if (DBG) {
10057 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10058 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10059 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10060 }
10061
10062 if (!SubscriptionManager.isValidSubscriptionId(subId)
10063 || appType < TelephonyManager.APPTYPE_UNKNOWN
10064 || appType > TelephonyManager.APPTYPE_ISIM
10065 || nafUrl == null || securityProtocol == null || callback == null) {
10066 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10067 if (callback != null) {
10068 try {
10069 callback.onAuthenticationFailure(
10070 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10071 } catch (RemoteException exception) {
10072 log("Fail to notify onAuthenticationFailure due to " + exception);
10073 }
10074 return;
10075 }
10076 }
10077
10078 final long token = Binder.clearCallingIdentity();
10079 try {
10080 getGbaManager(subId).bootstrapAuthenticationRequest(
10081 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10082 forceBootStrapping, callback));
10083 } finally {
10084 Binder.restoreCallingIdentity(token);
10085 }
10086 }
10087
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010088 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010089 * Attempts to set the radio power state for all phones for thermal reason.
10090 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010091 * requested radio power state will actually be set. See {@link
10092 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10093 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010094 * @param enable {@code true} if trying to turn radio on.
10095 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10096 * false}.
10097 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010098 private boolean setRadioPowerForThermal(boolean enable) {
10099 boolean isPhoneAvailable = false;
10100 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10101 Phone phone = PhoneFactory.getPhone(i);
10102 if (phone != null) {
10103 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10104 isPhoneAvailable = true;
10105 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010106 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010107
10108 // return true if successfully informed the phone object about the thermal radio power
10109 // request.
10110 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010111 }
10112
10113 private int handleDataThrottlingRequest(int subId,
10114 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010115 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10116 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10117 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10118 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10119 throw new IllegalArgumentException("modem does not support data throttling");
10120 }
10121
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010122 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10123 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010124 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010125 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10126 }
10127
10128 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10129
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010130 if (isDataThrottlingSupported) {
10131 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010132 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010133 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10134 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10135 } else if (thermalMitigationResult
10136 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010137 log("Modem likely does not support data throttling on secondary carrier. Data " +
10138 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10139 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010140 }
10141 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010142 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010143
10144 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010145 }
10146
Jack Nudelman644b91a2021-03-12 14:09:48 -080010147 private static List<String> getThermalMitigationAllowlist(Context context) {
10148 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10149 for (String pckg : context.getResources()
10150 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10151 sThermalMitigationAllowlistedPackages.add(pckg);
10152 }
10153 }
10154
10155 return sThermalMitigationAllowlistedPackages;
10156 }
10157
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010158 private boolean isAnyPhoneInEmergencyState() {
10159 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10160 if (tm.isInEmergencyCall()) {
10161 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10162 return true;
10163 }
10164 for (Phone phone : PhoneFactory.getPhones()) {
10165 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10166 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10167 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10168 + phone.isInEcm());
10169 return true;
10170 }
10171 }
10172
10173 return false;
10174 }
10175
Jack Nudelman644b91a2021-03-12 14:09:48 -080010176 /**
10177 * Used by shell commands to add an authorized package name for thermal mitigation.
10178 * @param packageName name of package to be allowlisted
10179 * @param context
10180 */
10181 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10182 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10183 sThermalMitigationAllowlistedPackages.add(packageName);
10184 }
10185
10186 /**
10187 * Used by shell commands to remove an authorized package name for thermal mitigation.
10188 * @param packageName name of package to remove from allowlist
10189 * @param context
10190 */
10191 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10192 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10193 sThermalMitigationAllowlistedPackages.remove(packageName);
10194 }
10195
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010196 /**
10197 * Thermal mitigation request to control functionalities at modem.
10198 *
10199 * @param subId the id of the subscription.
10200 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010201 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010202 *
10203 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10204 */
10205 @Override
10206 @ThermalMitigationResult
10207 public int sendThermalMitigationRequest(
10208 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010209 ThermalMitigationRequest thermalMitigationRequest,
10210 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010211 enforceModifyPermission();
10212
Jack Nudelman644b91a2021-03-12 14:09:48 -080010213 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10214 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10215 .contains(callingPackage)) {
10216 throw new SecurityException("Calling package must be configured in the device config. "
10217 + "calling package: " + callingPackage);
10218 }
10219
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010220 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10221 final long identity = Binder.clearCallingIdentity();
10222
10223 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10224 try {
10225 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10226 switch (thermalMitigationAction) {
10227 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10228 thermalMitigationResult =
10229 handleDataThrottlingRequest(subId,
10230 thermalMitigationRequest.getDataThrottlingRequest());
10231 break;
10232 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10233 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10234 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10235 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10236 }
10237
10238 // Ensure that radio is on. If not able to power on due to phone being
10239 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010240 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010241 thermalMitigationResult =
10242 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10243 break;
10244 }
10245
10246 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10247 false);
10248 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10249 break;
10250 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10251 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10252 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10253 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10254 }
10255
10256 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10257 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010258 Phone phone = getPhone(subId);
10259 if (phone == null) {
10260 thermalMitigationResult =
10261 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10262 break;
10263 }
10264
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010265 TelephonyConnectionService service =
10266 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010267 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010268 Log.e(LOG_TAG, "An emergency call is pending");
10269 thermalMitigationResult =
10270 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10271 break;
10272 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010273 thermalMitigationResult =
10274 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10275 break;
10276 }
10277 } else {
10278 thermalMitigationResult =
10279 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10280 break;
10281 }
10282
10283 // Turn radio off. If not able to power off due to phone being unavailable,
10284 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010285 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010286 thermalMitigationResult =
10287 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10288 break;
10289 }
10290 thermalMitigationResult =
10291 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10292 break;
10293 default:
10294 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10295 + "not exist. Requested action: " + thermalMitigationAction);
10296 }
10297 } catch (IllegalArgumentException e) {
10298 throw e;
10299 } catch (Exception e) {
10300 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10301 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10302 } finally {
10303 Binder.restoreCallingIdentity(identity);
10304 }
10305
10306 if (DBG) {
10307 log("thermalMitigationRequest returning with thermalMitigationResult: "
10308 + thermalMitigationResult);
10309 }
10310
10311 return thermalMitigationResult;
10312 }
Hui Wang641e81c2020-10-12 12:14:23 -070010313
10314 /**
10315 * Set the GbaService Package Name that Telephony will bind to.
10316 *
10317 * @param subId The sim that the GbaService is associated with.
10318 * @param packageName The name of the package to be replaced with.
10319 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10320 */
10321 @Override
10322 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10323 enforceModifyPermission();
10324
10325 final long identity = Binder.clearCallingIdentity();
10326 try {
10327 return getGbaManager(subId).overrideServicePackage(packageName);
10328 } finally {
10329 Binder.restoreCallingIdentity(identity);
10330 }
10331 }
10332
10333 /**
10334 * Return the package name of the currently bound GbaService.
10335 *
10336 * @param subId The sim that the GbaService is associated with.
10337 * @return the package name of the GbaService configuration, null if GBA is not supported.
10338 */
10339 @Override
10340 public String getBoundGbaService(int subId) {
10341 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10342
10343 final long identity = Binder.clearCallingIdentity();
10344 try {
10345 return getGbaManager(subId).getServicePackage();
10346 } finally {
10347 Binder.restoreCallingIdentity(identity);
10348 }
10349 }
10350
10351 /**
10352 * Set the release time for telephony to unbind GbaService.
10353 *
10354 * @param subId The sim that the GbaService is associated with.
10355 * @param interval The release time to unbind GbaService by millisecond.
10356 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10357 */
10358 @Override
10359 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10360 enforceModifyPermission();
10361
10362 final long identity = Binder.clearCallingIdentity();
10363 try {
10364 return getGbaManager(subId).overrideReleaseTime(interval);
10365 } finally {
10366 Binder.restoreCallingIdentity(identity);
10367 }
10368 }
10369
10370 /**
10371 * Return the release time for telephony to unbind GbaService.
10372 *
10373 * @param subId The sim that the GbaService is associated with.
10374 * @return The release time to unbind GbaService by millisecond.
10375 */
10376 @Override
10377 public int getGbaReleaseTime(int subId) {
10378 enforceReadPrivilegedPermission("getGbaReleaseTime");
10379
10380 final long identity = Binder.clearCallingIdentity();
10381 try {
10382 return getGbaManager(subId).getReleaseTime();
10383 } finally {
10384 Binder.restoreCallingIdentity(identity);
10385 }
10386 }
10387
10388 private GbaManager getGbaManager(int subId) {
10389 GbaManager instance = GbaManager.getInstance(subId);
10390 if (instance == null) {
10391 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10392 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10393 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10394 }
10395 return instance;
10396 }
Hui Wang761a6682020-10-31 05:12:53 +000010397
10398 /**
10399 * indicate whether the device and the carrier can support
10400 * RCS VoLTE single registration.
10401 */
10402 @Override
10403 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010404 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10405 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10406 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10407 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010408
10409 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10410 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10411 }
10412
10413 final long identity = Binder.clearCallingIdentity();
10414 try {
10415 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10416 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010417 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10418 if (isCapable != null) {
10419 return isCapable;
10420 }
Hui Wang761a6682020-10-31 05:12:53 +000010421 }
Hui Wang67af90e2021-06-04 16:57:15 -070010422 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10423 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010424 } finally {
10425 Binder.restoreCallingIdentity(identity);
10426 }
10427 }
10428
10429 /**
10430 * Register RCS provisioning callback.
10431 */
10432 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010433 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010434 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010435 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010436 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010437 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10438 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010439
10440 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10441 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10442 }
10443 if (!isImsAvailableOnDevice()) {
10444 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10445 "IMS not available on device.");
10446 }
10447
10448 final long identity = Binder.clearCallingIdentity();
10449 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010450 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010451 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010452 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10453 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010454 }
Hui Wang761a6682020-10-31 05:12:53 +000010455 } finally {
10456 Binder.restoreCallingIdentity(identity);
10457 }
10458 }
10459
10460 /**
10461 * Unregister RCS provisioning callback.
10462 */
10463 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010464 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010465 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010466 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010467 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010468 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10469 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010470
10471 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10472 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10473 }
10474 if (!isImsAvailableOnDevice()) {
10475 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10476 "IMS not available on device.");
10477 }
10478
10479 final long identity = Binder.clearCallingIdentity();
10480 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010481 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010482 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010483 } finally {
10484 Binder.restoreCallingIdentity(identity);
10485 }
10486 }
10487
10488 /**
10489 * trigger RCS reconfiguration.
10490 */
10491 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010492 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10493 "triggerRcsReconfiguration",
10494 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010495
10496 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10497 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10498 }
10499 if (!isImsAvailableOnDevice()) {
10500 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10501 "IMS not available on device.");
10502 }
10503
10504 final long identity = Binder.clearCallingIdentity();
10505 try {
10506 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10507 } finally {
10508 Binder.restoreCallingIdentity(identity);
10509 }
10510 }
10511
10512 /**
10513 * Provide the client configuration parameters of the RCS application.
10514 */
10515 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010516 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10517 "setRcsClientConfiguration",
10518 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010519
10520 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10521 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10522 }
10523 if (!isImsAvailableOnDevice()) {
10524 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10525 "IMS not available on device.");
10526 }
10527
10528 final long identity = Binder.clearCallingIdentity();
10529
10530 try {
10531 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10532 if (configBinder == null) {
10533 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010534 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10535 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010536 } else {
10537 configBinder.setRcsClientConfiguration(rcc);
10538 }
joonhunshinfa314642021-09-17 06:33:39 +000010539
10540 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10541 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010542 } catch (RemoteException e) {
10543 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010544 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10545 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010546 } finally {
10547 Binder.restoreCallingIdentity(identity);
10548 }
10549 }
10550
10551 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010552 * Enables or disables the test mode for RCS VoLTE single registration.
10553 */
10554 @Override
10555 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10556 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10557 "setRcsSingleRegistrationTestModeEnabled");
10558
10559 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10560 }
10561
10562 /**
10563 * Gets the test mode for RCS VoLTE single registration.
10564 */
10565 @Override
10566 public boolean getRcsSingleRegistrationTestModeEnabled() {
10567 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10568 "getRcsSingleRegistrationTestModeEnabled");
10569
10570 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10571 }
10572
10573 /**
Hui Wang761a6682020-10-31 05:12:53 +000010574 * Overrides the config of RCS VoLTE single registration enabled for the device.
10575 */
10576 @Override
10577 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10578 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10579 "setDeviceSingleRegistrationEnabledOverride");
10580 enforceModifyPermission();
10581
10582 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10583 : Boolean.parseBoolean(enabledStr);
10584 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010585 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010586 }
10587
10588 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010589 * Sends a device to device communication message. Only usable via shell.
10590 * @param message message to send.
10591 * @param value message value.
10592 */
10593 @Override
10594 public void sendDeviceToDeviceMessage(int message, int value) {
10595 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010596 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010597 enforceModifyPermission();
10598
10599 final long identity = Binder.clearCallingIdentity();
10600 try {
10601 TelephonyConnectionService service =
10602 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10603 if (service == null) {
10604 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10605 return;
10606 }
10607 service.sendTestDeviceToDeviceMessage(message, value);
10608 } finally {
10609 Binder.restoreCallingIdentity(identity);
10610 }
10611 }
10612
Tyler Gunnbabbda02021-02-10 11:05:02 -080010613 /**
10614 * Sets the specified device to device transport active.
10615 * @param transport The transport to set active.
10616 */
10617 @Override
10618 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10619 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10620 "setActiveDeviceToDeviceTransport");
10621 enforceModifyPermission();
10622
10623 final long identity = Binder.clearCallingIdentity();
10624 try {
10625 TelephonyConnectionService service =
10626 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10627 if (service == null) {
10628 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10629 return;
10630 }
10631 service.setActiveDeviceToDeviceTransport(transport);
10632 } finally {
10633 Binder.restoreCallingIdentity(identity);
10634 }
10635 }
Tyler Gunn92479152021-01-20 16:30:10 -080010636
Tyler Gunnd4575212021-05-03 14:46:49 -070010637 @Override
10638 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10639 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10640 "setDeviceToDeviceForceEnabled");
10641
10642 final long identity = Binder.clearCallingIdentity();
10643 try {
10644 Arrays.stream(PhoneFactory.getPhones()).forEach(
10645 p -> {
10646 Phone thePhone = p.getImsPhone();
10647 if (thePhone != null && thePhone instanceof ImsPhone) {
10648 ImsPhone imsPhone = (ImsPhone) thePhone;
10649 CallTracker tracker = imsPhone.getCallTracker();
10650 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10651 ImsPhoneCallTracker imsPhoneCallTracker =
10652 (ImsPhoneCallTracker) tracker;
10653 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10654 }
10655 }
10656 }
10657 );
10658 } finally {
10659 Binder.restoreCallingIdentity(identity);
10660 }
10661 }
10662
Tyler Gunn92479152021-01-20 16:30:10 -080010663 /**
Hui Wang761a6682020-10-31 05:12:53 +000010664 * Gets the config of RCS VoLTE single registration enabled for the device.
10665 */
10666 @Override
10667 public boolean getDeviceSingleRegistrationEnabled() {
10668 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10669 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10670 }
10671
10672 /**
10673 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10674 */
10675 @Override
10676 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10677 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10678 "setCarrierSingleRegistrationEnabledOverride");
10679 enforceModifyPermission();
10680
10681 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10682 : Boolean.parseBoolean(enabledStr);
10683 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10684 subId, enabled);
10685 }
10686
10687 /**
10688 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10689 */
10690 @Override
10691 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10692 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10693 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10694 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010695
10696 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010697 * Overrides the ims feature validation result
10698 */
10699 @Override
10700 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10701 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10702 "setImsFeatureValidationOverride");
10703
10704 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10705 : Boolean.parseBoolean(enabledStr);
10706 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10707 subId, enabled);
10708 }
10709
10710 /**
10711 * Gets the ims feature validation override value
10712 */
10713 @Override
10714 public boolean getImsFeatureValidationOverride(int subId) {
10715 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10716 "getImsFeatureValidationOverride");
10717 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10718 }
10719
10720 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010721 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10722 * their mobile plan.
10723 */
10724 @Override
10725 public String getMobileProvisioningUrl() {
10726 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10727 final long identity = Binder.clearCallingIdentity();
10728 try {
10729 return getDefaultPhone().getMobileProvisioningUrl();
10730 } finally {
10731 Binder.restoreCallingIdentity(identity);
10732 }
10733 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010734
James.cf Linbcdf8b32021-01-14 16:44:13 +080010735 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010736 * Get the EAB contact from the EAB database.
10737 */
10738 @Override
10739 public String getContactFromEab(String contact) {
10740 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10741 enforceModifyPermission();
10742 final long identity = Binder.clearCallingIdentity();
10743 try {
10744 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10745 } finally {
10746 Binder.restoreCallingIdentity(identity);
10747 }
10748 }
10749
10750 /**
Calvin Pana1434322021-07-01 19:27:01 +080010751 * Get the EAB capability from the EAB database.
10752 */
10753 @Override
10754 public String getCapabilityFromEab(String contact) {
10755 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10756 enforceModifyPermission();
10757 final long identity = Binder.clearCallingIdentity();
10758 try {
10759 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10760 } finally {
10761 Binder.restoreCallingIdentity(identity);
10762 }
10763 }
10764
10765 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010766 * Remove the EAB contacts from the EAB database.
10767 */
10768 @Override
10769 public int removeContactFromEab(int subId, String contacts) {
10770 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10771 enforceModifyPermission();
10772 final long identity = Binder.clearCallingIdentity();
10773 try {
10774 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10775 } finally {
10776 Binder.restoreCallingIdentity(identity);
10777 }
10778 }
10779
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010780 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010781 public boolean getDeviceUceEnabled() {
10782 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10783 final long identity = Binder.clearCallingIdentity();
10784 try {
10785 return mApp.getDeviceUceEnabled();
10786 } finally {
10787 Binder.restoreCallingIdentity(identity);
10788 }
10789 }
10790
10791 @Override
10792 public void setDeviceUceEnabled(boolean isEnabled) {
10793 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10794 final long identity = Binder.clearCallingIdentity();
10795 try {
10796 mApp.setDeviceUceEnabled(isEnabled);
10797 } finally {
10798 Binder.restoreCallingIdentity(identity);
10799 }
10800 }
10801
Brad Ebinger14d467f2021-02-12 06:18:28 +000010802 /**
10803 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10804 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10805 */
10806 // Used for SHELL command only right now.
10807 @Override
10808 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10809 List<String> featureTags) {
10810 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10811 "addUceRegistrationOverrideShell");
10812 final long identity = Binder.clearCallingIdentity();
10813 try {
10814 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10815 new ArraySet<>(featureTags));
10816 } catch (ImsException e) {
10817 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10818 } finally {
10819 Binder.restoreCallingIdentity(identity);
10820 }
10821 }
10822
10823 /**
10824 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10825 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10826 */
10827 // Used for SHELL command only right now.
10828 @Override
10829 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10830 List<String> featureTags) {
10831 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10832 "removeUceRegistrationOverrideShell");
10833 final long identity = Binder.clearCallingIdentity();
10834 try {
10835 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10836 new ArraySet<>(featureTags));
10837 } catch (ImsException e) {
10838 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10839 } finally {
10840 Binder.restoreCallingIdentity(identity);
10841 }
10842 }
10843
10844 /**
10845 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10846 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10847 */
10848 // Used for SHELL command only right now.
10849 @Override
10850 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10851 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10852 "clearUceRegistrationOverrideShell");
10853 final long identity = Binder.clearCallingIdentity();
10854 try {
10855 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10856 } catch (ImsException e) {
10857 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10858 } finally {
10859 Binder.restoreCallingIdentity(identity);
10860 }
10861 }
10862
10863 /**
10864 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10865 */
10866 // Used for SHELL command only right now.
10867 @Override
10868 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10869 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10870 "getLatestRcsContactUceCapabilityShell");
10871 final long identity = Binder.clearCallingIdentity();
10872 try {
10873 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10874 } catch (ImsException e) {
10875 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10876 } finally {
10877 Binder.restoreCallingIdentity(identity);
10878 }
10879 }
10880
10881 /**
10882 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10883 * device does not have an active PUBLISH.
10884 */
10885 // Used for SHELL command only right now.
10886 @Override
10887 public String getLastUcePidfXmlShell(int subId) {
10888 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10889 final long identity = Binder.clearCallingIdentity();
10890 try {
10891 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10892 } catch (ImsException e) {
10893 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10894 } finally {
10895 Binder.restoreCallingIdentity(identity);
10896 }
10897 }
10898
James.cf Line8713a42021-04-29 16:04:26 +080010899 /**
10900 * Remove UCE requests cannot be sent to the network status.
10901 */
10902 // Used for SHELL command only right now.
10903 @Override
10904 public boolean removeUceRequestDisallowedStatus(int subId) {
10905 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10906 final long identity = Binder.clearCallingIdentity();
10907 try {
10908 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10909 } catch (ImsException e) {
10910 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10911 } finally {
10912 Binder.restoreCallingIdentity(identity);
10913 }
10914 }
10915
James.cf Lin0fc71b02021-05-25 01:37:38 +080010916 /**
10917 * Remove UCE requests cannot be sent to the network status.
10918 */
10919 // Used for SHELL command only.
10920 @Override
10921 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10922 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10923 final long identity = Binder.clearCallingIdentity();
10924 try {
10925 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10926 } catch (ImsException e) {
10927 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10928 } finally {
10929 Binder.restoreCallingIdentity(identity);
10930 }
10931 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010932
James.cf Lin4b784aa2021-01-31 03:25:15 +080010933 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010934 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10935 String callingPackage) {
10936 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10937 mApp, subId, "setSignalStrengthUpdateRequest");
10938
10939 final int callingUid = Binder.getCallingUid();
10940 // Verify that tha callingPackage belongs to the calling UID
10941 mApp.getSystemService(AppOpsManager.class)
10942 .checkPackage(callingUid, callingPackage);
10943
Rambo Wang3607f502021-02-01 21:51:40 -080010944 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010945
10946 final long identity = Binder.clearCallingIdentity();
10947 try {
10948 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10949 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10950
10951 if (result instanceof IllegalStateException) {
10952 throw (IllegalStateException) result;
10953 }
10954 } finally {
10955 Binder.restoreCallingIdentity(identity);
10956 }
10957 }
10958
10959 @Override
10960 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10961 String callingPackage) {
10962 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10963 mApp, subId, "clearSignalStrengthUpdateRequest");
10964
10965 final int callingUid = Binder.getCallingUid();
10966 // Verify that tha callingPackage belongs to the calling UID
10967 mApp.getSystemService(AppOpsManager.class)
10968 .checkPackage(callingUid, callingPackage);
10969
10970 final long identity = Binder.clearCallingIdentity();
10971 try {
10972 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10973 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10974
10975 if (result instanceof IllegalStateException) {
10976 throw (IllegalStateException) result;
10977 }
10978 } finally {
10979 Binder.restoreCallingIdentity(identity);
10980 }
10981 }
10982
Rambo Wang3607f502021-02-01 21:51:40 -080010983 private static void validateSignalStrengthUpdateRequest(Context context,
10984 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010985 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10986 // phone/system process do not have further restriction on request
10987 return;
10988 }
10989
10990 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080010991 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010992 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080010993 context.enforceCallingOrSelfPermission(
10994 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
10995 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010996 }
10997
10998 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10999 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11000 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11001 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11002 || info.isEnabled()) {
11003 throw new IllegalArgumentException(
11004 "Only system can set hide fields in SignalThresholdInfo");
11005 }
11006
11007 // Thresholds length for each RAN need in range. This has been validated in
11008 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11009 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11010 final int[] thresholds = info.getThresholds();
11011 Objects.requireNonNull(thresholds);
11012 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11013 || thresholds.length
11014 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11015 throw new IllegalArgumentException(
11016 "thresholds length is out of range: " + thresholds.length);
11017 }
11018 }
11019 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011020
11021 /**
11022 * Gets the current phone capability.
11023 *
11024 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11025 * @return the PhoneCapability which describes the data connection capability of modem.
11026 * It's used to evaluate possible phone config change, for example from single
11027 * SIM device to multi-SIM device.
11028 */
11029 @Override
11030 public PhoneCapability getPhoneCapability() {
11031 enforceReadPrivilegedPermission("getPhoneCapability");
11032 final long identity = Binder.clearCallingIdentity();
11033 try {
11034 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11035 } finally {
11036 Binder.restoreCallingIdentity(identity);
11037 }
11038 }
Michele Berionne5e411512020-11-13 02:36:59 +000011039
11040 /**
11041 * Prepare TelephonyManager for an unattended reboot. The reboot is
11042 * required to be done shortly after the API is invoked.
11043 */
11044 @Override
11045 @TelephonyManager.PrepareUnattendedRebootResult
11046 public int prepareForUnattendedReboot() {
11047 enforceRebootPermission();
11048
11049 final long identity = Binder.clearCallingIdentity();
11050 try {
11051 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
11052 } finally {
11053 Binder.restoreCallingIdentity(identity);
11054 }
11055 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011056
11057 /**
11058 * Request to get the current slicing configuration including URSP rules and
11059 * NSSAIs (configured, allowed and rejected).
11060 *
11061 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11062 */
11063 @Override
11064 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011065 TelephonyPermissions
11066 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11067 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011068
11069 final long identity = Binder.clearCallingIdentity();
11070 try {
11071 Phone phone = getDefaultPhone();
11072 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11073 } finally {
11074 Binder.restoreCallingIdentity(identity);
11075 }
11076 }
Hunsuk Choic7ebc0f2021-11-15 23:46:41 +000011077
11078 /**
11079 * Register an IMS connection state callback
11080 */
11081 @Override
11082 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11083 String callingPackage) {
11084 if (feature == ImsFeature.FEATURE_MMTEL) {
11085 // ImsMmTelManager
11086 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11087 TelephonyPermissions
11088 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11089 mApp, subId, "registerImsStateCallback");
11090 } else if (feature == ImsFeature.FEATURE_RCS) {
11091 // ImsRcsManager or SipDelegateManager
11092 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11093 Binder.getCallingUid(), "registerImsStateCallback",
11094 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11095 Manifest.permission.READ_PRECISE_PHONE_STATE,
11096 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11097 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11098 }
11099
11100 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11101 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11102 "IMS not available on device.");
11103 }
11104
11105 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11106 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11107 }
11108
11109 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11110 if (controller == null) {
11111 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11112 "IMS not available on device.");
11113 }
11114
11115 if (callingPackage == null) {
11116 callingPackage = getCurrentPackageName();
11117 }
11118
11119 final long token = Binder.clearCallingIdentity();
11120 try {
11121 int slotId = getSlotIndexOrException(subId);
11122 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
11123 } catch (ImsException e) {
11124 throw new ServiceSpecificException(e.getCode());
11125 } finally {
11126 Binder.restoreCallingIdentity(token);
11127 }
11128 }
11129
11130 /**
11131 * Unregister an IMS connection state callback
11132 */
11133 @Override
11134 public void unregisterImsStateCallback(IImsStateCallback cb) {
11135 final long token = Binder.clearCallingIdentity();
11136 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11137 if (controller == null) {
11138 return;
11139 }
11140 try {
11141 controller.unregisterImsStateCallback(cb);
11142 } finally {
11143 Binder.restoreCallingIdentity(token);
11144 }
11145 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011146
11147 /**
11148 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11149 *
11150 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11151 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11152 * SecurityException.
11153 * If there is current registered network this value will be same as the registered cell
11154 * identity. If the device goes out of service the previous cell identity is cached and
11155 * will be returned. If the cache age of the Cell identity is more than 24 hours
11156 * it will be cleared and null will be returned.
11157 *
11158 */
11159 @Override
11160 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11161 String callingFeatureId) {
11162 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11163 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11164 LocationAccessPolicy.checkLocationPermission(mApp,
11165 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11166 .setCallingPackage(callingPackage)
11167 .setCallingFeatureId(callingFeatureId)
11168 .setCallingPid(Binder.getCallingPid())
11169 .setCallingUid(Binder.getCallingUid())
11170 .setMethod("getLastKnownCellIdentity")
11171 .setLogAsInfo(true)
11172 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11173 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11174 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11175 .build());
11176
11177 boolean hasFinePermission =
11178 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11179 if (!hasFinePermission
11180 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11181 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
11182 + "and BIND_CONNECTION_SERVICE permission.");
11183 }
11184
11185 final long identity = Binder.clearCallingIdentity();
11186 try {
11187 Phone phone = getPhone(subId);
11188 if (phone == null) return null;
11189 ServiceStateTracker sst = phone.getServiceStateTracker();
11190 if (sst == null) return null;
11191 return sst.getLastKnownCellIdentity();
11192 } finally {
11193 Binder.restoreCallingIdentity(identity);
11194 }
11195 }
jimsun38340bf2021-10-26 15:01:23 +080011196
11197 /**
11198 * Sets the modem service class Name that Telephony will bind to.
11199 *
11200 * @param serviceName The class name of the modem service.
11201 * @return true if the operation is succeed, otherwise false.
11202 */
11203 public boolean setModemService(String serviceName) {
11204 Log.d(LOG_TAG, "setModemService - " + serviceName);
11205 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11206 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11207 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11208 "setModemService");
11209 return mPhoneConfigurationManager.setModemService(serviceName);
11210 }
11211
11212 /**
11213 * Return the class name of the currently bounded modem service.
11214 *
11215 * @return the class name of the modem service.
11216 */
11217 public String getModemService() {
11218 String result;
11219 Log.d(LOG_TAG, "getModemService");
11220 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11221 TelephonyPermissions
11222 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11223 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11224 "getModemService");
11225 result = mPhoneConfigurationManager.getModemService();
11226 Log.d(LOG_TAG, "result = " + result);
11227 return result;
11228 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011229}