blob: a94efa808be490b29f69ff1832a2036252aa9d1d [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;
sandeepjs0a502c42021-09-27 15:34:44 +000036import android.compat.annotation.ChangeId;
37import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070038import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070039import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070040import android.content.Context;
41import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070042import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070043import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070044import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.net.Uri;
46import android.os.AsyncResult;
47import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080048import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049import android.os.Bundle;
50import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070051import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052import android.os.Looper;
53import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070054import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080055import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070056import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070057import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080058import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080059import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070060import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070061import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080062import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070063import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070064import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070065import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070066import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070067import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080068import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070069import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090070import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080071import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080072import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070073import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070074import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080075import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080076import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070077import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080078import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070079import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080080import android.telephony.CellIdentityCdma;
81import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070082import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070083import android.telephony.CellInfoGsm;
84import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070085import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080086import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070087import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070088import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070089import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080090import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070091import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080092import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070093import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080094import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080095import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070096import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080097import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070098import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080099import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800100import android.telephony.SignalStrengthUpdateRequest;
101import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800102import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800103import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800104import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700105import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700106import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800107import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800108import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800109import android.telephony.UiccCardInfo;
sandeepjs0a502c42021-09-27 15:34:44 +0000110import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000111import android.telephony.UiccSlotInfo;
sandeepjs0a502c42021-09-27 15:34:44 +0000112import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700113import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700114import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800115import android.telephony.data.ApnSetting;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800116import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800117import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700118import android.telephony.gba.GbaAuthRequest;
119import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700120import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800121import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000122import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000123import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700124import android.telephony.ims.RegistrationManager;
joonhunshin2c3e4232021-11-28 07:32:01 +0000125import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700126import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800127import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700128import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800129import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700130import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000131import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700132import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800133import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800134import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800135import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800136import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700137import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800138import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700139import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800141import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800142
Andrew Lee312e8172014-10-23 17:01:36 -0700143import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800144import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800145import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800146import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800147import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700148import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700149import com.android.internal.telephony.CallStateException;
Tyler Gunnd4575212021-05-03 14:46:49 -0700150import com.android.internal.telephony.CallTracker;
Rambo Wanga7436882022-01-13 21:51:44 -0800151import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800152import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700153import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700154import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800155import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700156import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700157import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800158import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800159import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800160import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700161import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choic7ebc0f2021-11-15 23:46:41 +0000162import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700163import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800164import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700165import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800166import com.android.internal.telephony.IccCard;
Rambo Wange162e302021-11-10 20:15:19 -0800167import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700168import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700169import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700170import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700171import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700172import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800173import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700174import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700175import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700176import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700177import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800178import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800179import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700180import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700181import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700182import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800183import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800184import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800185import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700186import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800187import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700188import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800189import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700190import com.android.internal.telephony.imsphone.ImsPhone;
191import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshinfa314642021-09-17 06:33:39 +0000192import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800193import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700194import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700195import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800196import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700197import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800198import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700199import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800200import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700201import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000202import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800203import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000204import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800205import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700206import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700207import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800208import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800209import com.android.phone.callcomposer.CallComposerPictureManager;
210import com.android.phone.callcomposer.CallComposerPictureTransfer;
211import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700212import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700213import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800214import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700215import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700216import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800217import com.android.services.telephony.TelecomAccountRegistry;
218import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800219import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800220
Hall Liu82694d52020-12-11 18:22:04 -0800221import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700222import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800223import java.io.IOException;
224import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700225import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700226import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800227import java.util.Arrays;
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +0000228import java.util.Collection;
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -0800229import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800230import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800231import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800232import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100233import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800234import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700235import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800236import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800237import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800238import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800239import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800240import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700241
242/**
243 * Implementation of the ITelephony interface.
244 */
Santos Cordon117fee72014-05-16 17:56:12 -0700245public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700246 private static final String LOG_TAG = "PhoneInterfaceManager";
247 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
248 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800249 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700250
251 // Message codes used with mMainThreadHandler
252 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700253 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
254 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700255 private static final int CMD_OPEN_CHANNEL = 9;
256 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
257 private static final int CMD_CLOSE_CHANNEL = 11;
258 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800259 private static final int CMD_NV_READ_ITEM = 13;
260 private static final int EVENT_NV_READ_ITEM_DONE = 14;
261 private static final int CMD_NV_WRITE_ITEM = 15;
262 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
263 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
264 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700265 private static final int CMD_RESET_MODEM_CONFIG = 19;
266 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800267 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
268 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800269 private static final int CMD_SEND_ENVELOPE = 25;
270 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000271 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
272 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700273 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
274 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
275 private static final int CMD_EXCHANGE_SIM_IO = 31;
276 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800277 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
278 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700279 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
280 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700281 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
282 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700283 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
284 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
285 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
286 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700287 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
288 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
289 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
290 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700291 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800292 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
293 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000294 private static final int CMD_SWITCH_SLOTS = 50;
295 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700296 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
297 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
298 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
299 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
300 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
301 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
302 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
303 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700304 private static final int CMD_GET_ALL_CELL_INFO = 60;
305 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
306 private static final int CMD_GET_CELL_LOCATION = 62;
307 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700308 private static final int CMD_MODEM_REBOOT = 64;
309 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700310 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
311 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800312 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
313 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700314 private static final int CMD_GET_MODEM_STATUS = 70;
315 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700316 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
317 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700318 private static final int CMD_ERASE_MODEM_CONFIG = 74;
319 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800320 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
321 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
322 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
323 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800324 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
325 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800326 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800327 private static final int CMD_GET_CALL_FORWARDING = 83;
328 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
329 private static final int CMD_SET_CALL_FORWARDING = 85;
330 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
331 private static final int CMD_GET_CALL_WAITING = 87;
332 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
333 private static final int CMD_SET_CALL_WAITING = 89;
334 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700335 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
336 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
337 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
338 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700339 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
340 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800341 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
342 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800343 private static final int CMD_SET_DATA_THROTTLING = 99;
344 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800345 private static final int CMD_SET_SIM_POWER = 101;
346 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800347 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
348 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
349 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
350 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800351 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
352 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000353 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800354 private static final int CMD_GET_SLICING_CONFIG = 110;
355 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800356 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700357 private static final int CMD_ENABLE_VONR = 113;
358 private static final int EVENT_ENABLE_VONR_DONE = 114;
359 private static final int CMD_IS_VONR_ENABLED = 115;
360 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700361
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800362 // Parameters of select command.
363 private static final int SELECT_COMMAND = 0xA4;
364 private static final int SELECT_P1 = 0x04;
365 private static final int SELECT_P2 = 0;
366 private static final int SELECT_P3 = 0x10;
367
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700368 /** The singleton instance. */
369 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800370 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371
Wink Saville3ab207e2014-11-20 13:07:20 -0800372 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800373 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800374 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700375 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800376 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700377 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800378 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800379 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800380 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700381 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800382 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700383
Peter Wangdafb9ac2020-01-15 14:13:38 -0800384 /** User Activity */
385 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800386 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
387
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700388 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
389
Derek Tan97ebb422014-09-05 16:55:38 -0700390 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
391 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800392 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800393 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700394
Michelecea4cf22018-12-21 15:00:11 -0800395 // String to store multi SIM allowed
396 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
397
Derek Tan740e1672017-06-27 14:56:27 -0700398 // The AID of ISD-R.
399 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
400
yinxub1bed742017-04-17 11:45:04 -0700401 private NetworkScanRequestTracker mNetworkScanRequestTracker;
402
David Kelly5e06a7f2018-03-12 14:10:59 +0000403 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
404 private static final int MANUFACTURER_CODE_LENGTH = 8;
405
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800406 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800407 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800408
Derek Tan89e89d42014-07-08 17:00:10 -0700409 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700410 * Experiment flag to enable erase modem config on reset network, default value is false
411 */
412 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
413 "reset_network_erase_modem_config_enabled";
414
Rambo Wang0f050d82021-02-12 11:43:36 -0800415 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
sandeepjs0a502c42021-09-27 15:34:44 +0000416 /**
417 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
418 * one ICCID active at the same time.
419 * Apps should use below API signatures if targeting SDK is T and beyond.
420 *
421 * @hide
422 */
423 @ChangeId
424 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
425 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800426
Naina Nallurid63128d2019-09-17 14:10:30 -0700427 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700428 * A request object to use for transmitting data to an ICC.
429 */
430 private static final class IccAPDUArgument {
431 public int channel, cla, command, p1, p2, p3;
432 public String data;
433
434 public IccAPDUArgument(int channel, int cla, int command,
435 int p1, int p2, int p3, String data) {
436 this.channel = channel;
437 this.cla = cla;
438 this.command = command;
439 this.p1 = p1;
440 this.p2 = p2;
441 this.p3 = p3;
442 this.data = data;
443 }
444 }
445
446 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700447 * A request object to use for transmitting data to an ICC.
448 */
449 private static final class ManualNetworkSelectionArgument {
450 public OperatorInfo operatorInfo;
451 public boolean persistSelection;
452
453 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
454 this.operatorInfo = operatorInfo;
455 this.persistSelection = persistSelection;
456 }
457 }
458
459 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700460 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
461 * request after sending. The main thread will notify the request when it is complete.
462 */
463 private static final class MainThreadRequest {
464 /** The argument to use for the request */
465 public Object argument;
466 /** The result of the request that is run on the main thread */
467 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800468 // The subscriber id that this request applies to. Defaults to
469 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
470 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700471
Nathan Harold92bed182018-10-12 18:16:49 -0700472 // In cases where subId is unavailable, the caller needs to specify the phone.
473 public Phone phone;
474
vagdeviaf9a5b92018-08-15 16:01:53 -0700475 public WorkSource workSource;
476
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700477 public MainThreadRequest(Object argument) {
478 this.argument = argument;
479 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800480
Nathan Harold92bed182018-10-12 18:16:49 -0700481 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
482 this.argument = argument;
483 if (phone != null) {
484 this.phone = phone;
485 }
486 this.workSource = workSource;
487 }
488
vagdeviaf9a5b92018-08-15 16:01:53 -0700489 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800490 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800491 if (subId != null) {
492 this.subId = subId;
493 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700494 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800495 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700496 }
497
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800498 private static final class IncomingThirdPartyCallArgs {
499 public final ComponentName component;
500 public final String callId;
501 public final String callerDisplayName;
502
503 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
504 String callerDisplayName) {
505 this.component = component;
506 this.callId = callId;
507 this.callerDisplayName = callerDisplayName;
508 }
509 }
510
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700511 /**
512 * A handler that processes messages on the main thread in the phone process. Since many
513 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
514 * inbound binder threads to the main thread in the phone process. The Binder thread
515 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
516 * on, which will be notified when the operation completes and will contain the result of the
517 * request.
518 *
519 * <p>If a MainThreadRequest object is provided in the msg.obj field,
520 * note that request.result must be set to something non-null for the calling thread to
521 * unblock.
522 */
523 private final class MainThreadHandler extends Handler {
524 @Override
525 public void handleMessage(Message msg) {
526 MainThreadRequest request;
527 Message onCompleted;
528 AsyncResult ar;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000529 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700530 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800531 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700532
533 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700534 case CMD_HANDLE_USSD_REQUEST: {
535 request = (MainThreadRequest) msg.obj;
536 final Phone phone = getPhoneFromRequest(request);
537 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
538 String ussdRequest = ussdObject.first;
539 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700540
Pengquan Menga1bb6272018-09-06 09:59:22 -0700541 if (!isUssdApiAllowed(request.subId)) {
542 // Carrier does not support use of this API, return failure.
543 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
544 UssdResponse response = new UssdResponse(ussdRequest, null);
545 Bundle returnData = new Bundle();
546 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
547 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700548
Pengquan Menga1bb6272018-09-06 09:59:22 -0700549 request.result = true;
550 notifyRequester(request);
551 return;
552 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700553
Pengquan Menga1bb6272018-09-06 09:59:22 -0700554 try {
555 request.result = phone != null
556 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
557 } catch (CallStateException cse) {
558 request.result = false;
559 }
560 // Wake up the requesting thread
561 notifyRequester(request);
562 break;
pkanwar32d516d2016-10-14 19:37:38 -0700563 }
564
Yorke Lee716f67e2015-06-17 15:39:16 -0700565 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700566 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700567 final Phone phone = getPhoneFromRequest(request);
568 request.result = phone != null ?
569 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
570 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700571 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700572 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700573 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700574 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700575
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700576 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700577 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700578 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000579 uiccPort = getUiccPortFromRequest(request);
580 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700581 loge("iccTransmitApduLogicalChannel: No UICC");
582 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700583 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700584 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700585 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
586 request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000587 uiccPort.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700588 iccArgument.channel, iccArgument.cla, iccArgument.command,
589 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700590 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700591 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700592 break;
593
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700594 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700595 ar = (AsyncResult) msg.obj;
596 request = (MainThreadRequest) ar.userObj;
597 if (ar.exception == null && ar.result != null) {
598 request.result = ar.result;
599 } else {
600 request.result = new IccIoResult(0x6F, 0, (byte[])null);
601 if (ar.result == null) {
602 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800603 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700604 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800605 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700606 } else {
607 loge("iccTransmitApduLogicalChannel: Unknown exception");
608 }
609 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700610 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700611 break;
612
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700613 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
614 request = (MainThreadRequest) msg.obj;
615 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000616 uiccPort = getUiccPortFromRequest(request);
617 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700618 loge("iccTransmitApduBasicChannel: No UICC");
619 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700620 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700621 } else {
622 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
623 request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000624 uiccPort.iccTransmitApduBasicChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700625 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
626 iccArgument.p3, iccArgument.data, onCompleted);
627 }
628 break;
629
630 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
631 ar = (AsyncResult) msg.obj;
632 request = (MainThreadRequest) ar.userObj;
633 if (ar.exception == null && ar.result != null) {
634 request.result = ar.result;
635 } else {
636 request.result = new IccIoResult(0x6F, 0, (byte[])null);
637 if (ar.result == null) {
638 loge("iccTransmitApduBasicChannel: Empty response");
639 } else if (ar.exception instanceof CommandException) {
640 loge("iccTransmitApduBasicChannel: CommandException: " +
641 ar.exception);
642 } else {
643 loge("iccTransmitApduBasicChannel: Unknown exception");
644 }
645 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700646 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700647 break;
648
649 case CMD_EXCHANGE_SIM_IO:
650 request = (MainThreadRequest) msg.obj;
651 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000652 uiccPort = getUiccPortFromRequest(request);
653 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700654 loge("iccExchangeSimIO: No UICC");
655 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700656 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700657 } else {
658 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
659 request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000660 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700661 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
662 iccArgument.data, onCompleted);
663 }
664 break;
665
666 case EVENT_EXCHANGE_SIM_IO_DONE:
667 ar = (AsyncResult) msg.obj;
668 request = (MainThreadRequest) ar.userObj;
669 if (ar.exception == null && ar.result != null) {
670 request.result = ar.result;
671 } else {
672 request.result = new IccIoResult(0x6f, 0, (byte[])null);
673 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700674 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700675 break;
676
Derek Tan4d5e5c12014-02-04 11:54:58 -0800677 case CMD_SEND_ENVELOPE:
678 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000679 uiccPort = getUiccPortFromRequest(request);
680 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700681 loge("sendEnvelopeWithStatus: No UICC");
682 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700683 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700684 } else {
685 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000686 uiccPort.sendEnvelopeWithStatus((String)request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700687 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800688 break;
689
690 case EVENT_SEND_ENVELOPE_DONE:
691 ar = (AsyncResult) msg.obj;
692 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700693 if (ar.exception == null && ar.result != null) {
694 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800695 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700696 request.result = new IccIoResult(0x6F, 0, (byte[])null);
697 if (ar.result == null) {
698 loge("sendEnvelopeWithStatus: Empty response");
699 } else if (ar.exception instanceof CommandException) {
700 loge("sendEnvelopeWithStatus: CommandException: " +
701 ar.exception);
702 } else {
703 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
704 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800705 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700706 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800707 break;
708
Shishir Agrawal566b7612013-10-28 14:41:00 -0700709 case CMD_OPEN_CHANNEL:
710 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000711 uiccPort = getUiccPortFromRequest(request);
Rambo Wange162e302021-11-10 20:15:19 -0800712 IccLogicalChannelRequest openChannelRequest =
713 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000714 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700715 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800716 request.result = new IccOpenLogicalChannelResponse(-1,
717 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700718 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700719 } else {
720 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wange162e302021-11-10 20:15:19 -0800721 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
722 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700723 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700724 break;
725
726 case EVENT_OPEN_CHANNEL_DONE:
727 ar = (AsyncResult) msg.obj;
728 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700729 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700730 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700731 int[] result = (int[]) ar.result;
732 int channelId = result[0];
733 byte[] selectResponse = null;
734 if (result.length > 1) {
735 selectResponse = new byte[result.length - 1];
736 for (int i = 1; i < result.length; ++i) {
737 selectResponse[i - 1] = (byte) result[i];
738 }
739 }
740 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700741 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700742 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700743 if (ar.result == null) {
744 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700745 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700746 if (ar.exception != null) {
747 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
748 }
749
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700750 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700751 if (ar.exception instanceof CommandException) {
752 CommandException.Error error =
753 ((CommandException) (ar.exception)).getCommandError();
754 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700755 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700756 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700757 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700758 }
759 }
760 openChannelResp = new IccOpenLogicalChannelResponse(
761 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700762 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700763 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700764 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700765 break;
766
767 case CMD_CLOSE_CHANNEL:
768 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000769 uiccPort = getUiccPortFromRequest(request);
770 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700771 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900772 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700773 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700774 } else {
775 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000776 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700777 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700778 break;
779
780 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800781 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
782 break;
783
784 case CMD_NV_READ_ITEM:
785 request = (MainThreadRequest) msg.obj;
786 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800787 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
788 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800789 break;
790
791 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700792 ar = (AsyncResult) msg.obj;
793 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800794 if (ar.exception == null && ar.result != null) {
795 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700796 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800797 request.result = "";
798 if (ar.result == null) {
799 loge("nvReadItem: Empty response");
800 } else if (ar.exception instanceof CommandException) {
801 loge("nvReadItem: CommandException: " +
802 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700803 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800804 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700805 }
806 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700807 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700808 break;
809
Jake Hambye994d462014-02-03 13:10:13 -0800810 case CMD_NV_WRITE_ITEM:
811 request = (MainThreadRequest) msg.obj;
812 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
813 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800814 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700815 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800816 break;
817
818 case EVENT_NV_WRITE_ITEM_DONE:
819 handleNullReturnEvent(msg, "nvWriteItem");
820 break;
821
822 case CMD_NV_WRITE_CDMA_PRL:
823 request = (MainThreadRequest) msg.obj;
824 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800825 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800826 break;
827
828 case EVENT_NV_WRITE_CDMA_PRL_DONE:
829 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
830 break;
831
chen xu6dac5ab2018-10-26 17:39:23 -0700832 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800833 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700834 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800835 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800836 break;
837
chen xu6dac5ab2018-10-26 17:39:23 -0700838 case EVENT_RESET_MODEM_CONFIG_DONE:
839 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800840 break;
841
Sooraj Sasindran37444802020-08-11 10:40:43 -0700842 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
843 request = (MainThreadRequest) msg.obj;
844 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
845 request);
846 Phone phone = getPhoneFromRequest(request);
847 if (phone != null) {
848 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
849 } else {
850 loge("isNRDualConnectivityEnabled: No phone object");
851 request.result = false;
852 notifyRequester(request);
853 }
854 break;
855 }
856
857 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
858 ar = (AsyncResult) msg.obj;
859 request = (MainThreadRequest) ar.userObj;
860 if (ar.exception == null && ar.result != null) {
861 request.result = ar.result;
862 } else {
863 // request.result must be set to something non-null
864 // for the calling thread to unblock
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700865 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700866 request.result = ar.result;
867 } else {
868 request.result = false;
869 }
870 if (ar.result == null) {
871 loge("isNRDualConnectivityEnabled: Empty response");
872 } else if (ar.exception instanceof CommandException) {
873 loge("isNRDualConnectivityEnabled: CommandException: "
874 + ar.exception);
875 } else {
876 loge("isNRDualConnectivityEnabled: Unknown exception");
877 }
878 }
879 notifyRequester(request);
880 break;
881
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700882 case CMD_IS_VONR_ENABLED: {
883 request = (MainThreadRequest) msg.obj;
884 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
885 request);
886 Phone phone = getPhoneFromRequest(request);
887 if (phone != null) {
888 phone.isVoNrEnabled(onCompleted, request.workSource);
889 } else {
890 loge("isVoNrEnabled: No phone object");
891 request.result = false;
892 notifyRequester(request);
893 }
894 break;
895 }
896
897 case EVENT_IS_VONR_ENABLED_DONE:
898 ar = (AsyncResult) msg.obj;
899 request = (MainThreadRequest) ar.userObj;
900 if (ar.exception == null && ar.result != null) {
901 request.result = ar.result;
902 } else {
903 // request.result must be set to something non-null
904 // for the calling thread to unblock
905 if (ar.result != null) {
906 request.result = ar.result;
907 } else {
908 request.result = false;
909 }
910 if (ar.result == null) {
911 loge("isVoNrEnabled: Empty response");
912 } else if (ar.exception instanceof CommandException) {
913 loge("isVoNrEnabled: CommandException: "
914 + ar.exception);
915 } else {
916 loge("isVoNrEnabled: Unknown exception");
917 }
918 }
919 notifyRequester(request);
920 break;
921
Sooraj Sasindran37444802020-08-11 10:40:43 -0700922 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
923 request = (MainThreadRequest) msg.obj;
924 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
925 Phone phone = getPhoneFromRequest(request);
926 if (phone != null) {
927 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
928 request.workSource);
929 } else {
930 loge("enableNrDualConnectivity: No phone object");
931 request.result =
932 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
933 notifyRequester(request);
934 }
935 break;
936 }
937
938 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
939 ar = (AsyncResult) msg.obj;
940 request = (MainThreadRequest) ar.userObj;
941 if (ar.exception == null) {
942 request.result =
943 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
944 } else {
945 request.result =
946 TelephonyManager
947 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
948 if (ar.exception instanceof CommandException) {
949 CommandException.Error error =
950 ((CommandException) (ar.exception)).getCommandError();
951 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
952 request.result =
953 TelephonyManager
954 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000955 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
956 request.result =
957 TelephonyManager
958 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700959 }
960 loge("enableNrDualConnectivity" + ": CommandException: "
961 + ar.exception);
962 } else {
963 loge("enableNrDualConnectivity" + ": Unknown exception");
964 }
965 }
966 notifyRequester(request);
967 break;
968 }
969
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700970 case CMD_ENABLE_VONR: {
971 request = (MainThreadRequest) msg.obj;
972 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
973 Phone phone = getPhoneFromRequest(request);
974 if (phone != null) {
975 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
976 request.workSource);
977 } else {
978 loge("setVoNrEnabled: No phone object");
979 request.result =
980 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
981 notifyRequester(request);
982 }
983 break;
984 }
985
986 case EVENT_ENABLE_VONR_DONE: {
987 ar = (AsyncResult) msg.obj;
988 request = (MainThreadRequest) ar.userObj;
989 if (ar.exception == null) {
990 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
991 } else {
992 request.result = TelephonyManager.ENABLE_VONR_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 = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
998 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
999 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1000 } else {
1001 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1002 }
1003 loge("setVoNrEnabled" + ": CommandException: "
1004 + ar.exception);
1005 } else {
1006 loge("setVoNrEnabled" + ": Unknown exception");
1007 }
1008 }
1009 notifyRequester(request);
1010 break;
1011 }
1012
SongFerngWang3ef3e072020-12-21 16:41:52 +08001013 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001014 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001015 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1016 request);
1017 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001018 break;
1019
SongFerngWang3ef3e072020-12-21 16:41:52 +08001020 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001021 ar = (AsyncResult) msg.obj;
1022 request = (MainThreadRequest) ar.userObj;
1023 if (ar.exception == null && ar.result != null) {
1024 request.result = ar.result; // Integer
1025 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301026 // request.result must be set to something non-null
1027 // for the calling thread to unblock
1028 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001029 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001030 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001031 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001032 loge("getAllowedNetworkTypesBitmask: CommandException: "
1033 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001034 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001035 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001036 }
1037 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001038 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001039 break;
1040
SongFerngWang3ef3e072020-12-21 16:41:52 +08001041 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001042 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001043 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1044 request);
1045 Pair<Integer, Long> reasonWithNetworkTypes =
1046 (Pair<Integer, Long>) request.argument;
1047 getPhoneFromRequest(request).setAllowedNetworkTypes(
1048 reasonWithNetworkTypes.first,
1049 reasonWithNetworkTypes.second,
1050 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001051 break;
1052
SongFerngWang3ef3e072020-12-21 16:41:52 +08001053 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1054 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001055 break;
1056
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001057 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1058 request = (MainThreadRequest)msg.obj;
1059 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001060 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001061 break;
1062
1063 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1064 ar = (AsyncResult)msg.obj;
1065 request = (MainThreadRequest)ar.userObj;
1066 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001067 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001068 break;
1069
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001070 case CMD_SET_VOICEMAIL_NUMBER:
1071 request = (MainThreadRequest) msg.obj;
1072 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1073 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001074 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1075 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001076 break;
1077
1078 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1079 handleNullReturnEvent(msg, "setVoicemailNumber");
1080 break;
1081
Stuart Scott54788802015-03-30 13:18:01 -07001082 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1083 request = (MainThreadRequest) msg.obj;
1084 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1085 request);
1086 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1087 break;
1088
1089 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1090 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1091 break;
1092
Shishir Agrawal302c8692015-06-19 13:49:39 -07001093 case CMD_PERFORM_NETWORK_SCAN:
1094 request = (MainThreadRequest) msg.obj;
1095 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1096 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1097 break;
1098
Hall Liu27d24262020-09-18 19:04:59 -07001099 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001100 request = (MainThreadRequest) msg.obj;
1101 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001102 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1103 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1104 request.argument;
1105 int callForwardingReason = args.first;
1106 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001107 break;
Hall Liu27d24262020-09-18 19:04:59 -07001108 }
1109 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001110 ar = (AsyncResult) msg.obj;
1111 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001112 TelephonyManager.CallForwardingInfoCallback callback =
1113 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1114 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001115 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001116 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001117 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1118 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1119 // Service Class is a bit mask per 3gpp 27.007. Search for
1120 // any service for voice call.
1121 if ((callForwardInfo.serviceClass
1122 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001123 callForwardingInfo = new CallForwardingInfo(
1124 callForwardInfo.status
1125 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001126 callForwardInfo.reason,
1127 callForwardInfo.number,
1128 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001129 break;
1130 }
1131 }
1132 // Didn't find a call forward info for voice call.
1133 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001134 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1135 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001136 }
Hall Liu27d24262020-09-18 19:04:59 -07001137 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001138 } else {
1139 if (ar.result == null) {
1140 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1141 }
1142 if (ar.exception != null) {
1143 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1144 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001145 int errorCode = TelephonyManager
1146 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001147 if (ar.exception instanceof CommandException) {
1148 CommandException.Error error =
1149 ((CommandException) (ar.exception)).getCommandError();
1150 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001151 errorCode = TelephonyManager
1152 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001153 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001154 errorCode = TelephonyManager
1155 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001156 }
1157 }
Hall Liu27d24262020-09-18 19:04:59 -07001158 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001159 }
Shuo Qian4a594052020-01-23 11:59:30 -08001160 break;
Hall Liu27d24262020-09-18 19:04:59 -07001161 }
Shuo Qian4a594052020-01-23 11:59:30 -08001162
Hall Liu27d24262020-09-18 19:04:59 -07001163 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001164 request = (MainThreadRequest) msg.obj;
1165 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001166 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001167 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001168 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1169 request.argument).first;
1170 request.phone.setCallForwardingOption(
1171 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001172 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001173 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001174 callForwardingInfoToSet.getReason(),
1175 callForwardingInfoToSet.getNumber(),
1176 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1177 break;
Hall Liu27d24262020-09-18 19:04:59 -07001178 }
Shuo Qian4a594052020-01-23 11:59:30 -08001179
Hall Liu27d24262020-09-18 19:04:59 -07001180 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001181 ar = (AsyncResult) msg.obj;
1182 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001183 Consumer<Integer> callback =
1184 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1185 request.argument).second;
1186 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001187 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001188 int errorCode = TelephonyManager.CallForwardingInfoCallback
1189 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001190 if (ar.exception instanceof CommandException) {
1191 CommandException.Error error =
1192 ((CommandException) (ar.exception)).getCommandError();
1193 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001194 errorCode = TelephonyManager.CallForwardingInfoCallback
1195 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001196 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001197 errorCode = TelephonyManager.CallForwardingInfoCallback
1198 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001199 }
1200 }
1201 callback.accept(errorCode);
1202 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001203 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
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_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001209 request = (MainThreadRequest) msg.obj;
1210 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1211 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1212 break;
Hall Liu27d24262020-09-18 19:04:59 -07001213 }
Shuo Qian4a594052020-01-23 11:59:30 -08001214
Hall Liu27d24262020-09-18 19:04:59 -07001215 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001216 ar = (AsyncResult) msg.obj;
1217 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001218 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001219 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1220 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001221 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001222 // Service Class is a bit mask per 3gpp 27.007.
1223 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001224 if (callForwardResults.length > 1
1225 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001226 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001227 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001228 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1229 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001230 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001231 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001232 }
1233 } else {
1234 if (ar.result == null) {
1235 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1236 }
1237 if (ar.exception != null) {
1238 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1239 }
1240 if (ar.exception instanceof CommandException) {
1241 CommandException.Error error =
1242 ((CommandException) (ar.exception)).getCommandError();
1243 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1244 callForwardingStatus =
1245 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1246 }
1247 }
1248 }
Hall Liu27d24262020-09-18 19:04:59 -07001249 callback.accept(callForwardingStatus);
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_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001254 request = (MainThreadRequest) msg.obj;
1255 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001256 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1257 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001258 break;
Hall Liu27d24262020-09-18 19:04:59 -07001259 }
Shuo Qian4a594052020-01-23 11:59:30 -08001260
Hall Liu27d24262020-09-18 19:04:59 -07001261 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001262 ar = (AsyncResult) msg.obj;
1263 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001264 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1265 Consumer<Integer> callback =
1266 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1267 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001268 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001269 if (ar.exception instanceof CommandException) {
1270 CommandException.Error error =
1271 ((CommandException) (ar.exception)).getCommandError();
1272 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1273 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1274 } else {
1275 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1276 }
1277 } else {
1278 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1279 }
1280 } else {
1281 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1282 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001283 }
Shuo Qian4a594052020-01-23 11:59:30 -08001284 break;
Hall Liu27d24262020-09-18 19:04:59 -07001285 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001286 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1287 ar = (AsyncResult) msg.obj;
1288 request = (MainThreadRequest) ar.userObj;
1289 CellNetworkScanResult cellScanResult;
1290 if (ar.exception == null && ar.result != null) {
1291 cellScanResult = new CellNetworkScanResult(
1292 CellNetworkScanResult.STATUS_SUCCESS,
1293 (List<OperatorInfo>) ar.result);
1294 } else {
1295 if (ar.result == null) {
1296 loge("getCellNetworkScanResults: Empty response");
1297 }
1298 if (ar.exception != null) {
1299 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1300 }
1301 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1302 if (ar.exception instanceof CommandException) {
1303 CommandException.Error error =
1304 ((CommandException) (ar.exception)).getCommandError();
1305 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1306 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1307 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1308 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1309 }
1310 }
1311 cellScanResult = new CellNetworkScanResult(errorCode, null);
1312 }
1313 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001314 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001315 break;
1316
1317 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1318 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001319 ManualNetworkSelectionArgument selArg =
1320 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001321 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1322 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001323 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1324 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001325 break;
1326
1327 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001328 ar = (AsyncResult) msg.obj;
1329 request = (MainThreadRequest) ar.userObj;
1330 if (ar.exception == null) {
1331 request.result = true;
1332 } else {
1333 request.result = false;
1334 loge("setNetworkSelectionModeManual " + ar.exception);
1335 }
1336 notifyRequester(request);
1337 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001338 break;
1339
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001340 case CMD_GET_MODEM_ACTIVITY_INFO:
1341 request = (MainThreadRequest) msg.obj;
1342 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001343 if (defaultPhone != null) {
1344 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001345 } else {
1346 ResultReceiver result = (ResultReceiver) request.argument;
1347 Bundle bundle = new Bundle();
1348 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001349 new ModemActivityInfo(0, 0, 0,
1350 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001351 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001352 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001353 break;
1354
Hall Liud0f208c2020-10-14 16:54:44 -07001355 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001356 ar = (AsyncResult) msg.obj;
1357 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001358 ResultReceiver result = (ResultReceiver) request.argument;
1359
Hall Liud0f208c2020-10-14 16:54:44 -07001360 ModemActivityInfo ret = null;
1361 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001362 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001363 // Update the last modem activity info and the result of the request.
1364 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1365 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001366 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001367 int[] txTimeMs = info.getTransmitTimeMillis();
1368 int[] lastModemTxTimeMs = mLastModemActivityInfo
1369 .getTransmitTimeMillis();
1370 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1371 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1372 }
Hall Liu49656c02020-10-09 19:00:11 -07001373 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001374 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1375 + mLastModemActivityInfo.getSleepTimeMillis());
1376 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1377 + mLastModemActivityInfo.getIdleTimeMillis());
1378 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1379 mLastModemActivityInfo.setReceiveTimeMillis(
1380 info.getReceiveTimeMillis()
1381 + mLastModemActivityInfo.getReceiveTimeMillis());
1382 }
Hall Liu49656c02020-10-09 19:00:11 -07001383 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001384 mLastModemActivityInfo.getSleepTimeMillis(),
1385 mLastModemActivityInfo.getIdleTimeMillis(),
1386 mLastModemActivityInfo.getTransmitTimeMillis(),
1387 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001388 } else {
1389 if (ar.result == null) {
1390 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001391 error = TelephonyManager.ModemActivityInfoException
1392 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001393 } else if (ar.exception instanceof CommandException) {
1394 loge("queryModemActivityInfo: CommandException: " +
1395 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001396 error = TelephonyManager.ModemActivityInfoException
1397 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001398 } else {
1399 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001400 error = TelephonyManager.ModemActivityInfoException
1401 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001402 }
1403 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001404 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001405 if (ret != null) {
1406 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1407 } else {
1408 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1409 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001410 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001411 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001412 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001413 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001414
Meng Wang1a7c35a2016-05-05 20:56:15 -07001415 case CMD_SET_ALLOWED_CARRIERS:
1416 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001417 CarrierRestrictionRules argument =
1418 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001419 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001420 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001421 break;
1422
1423 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1424 ar = (AsyncResult) msg.obj;
1425 request = (MainThreadRequest) ar.userObj;
1426 if (ar.exception == null && ar.result != null) {
1427 request.result = ar.result;
1428 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001429 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1430 if (ar.exception instanceof CommandException) {
1431 loge("setAllowedCarriers: CommandException: " + ar.exception);
1432 CommandException.Error error =
1433 ((CommandException) (ar.exception)).getCommandError();
1434 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1435 request.result =
1436 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1437 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001438 } else {
1439 loge("setAllowedCarriers: Unknown exception");
1440 }
1441 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001442 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001443 break;
1444
1445 case CMD_GET_ALLOWED_CARRIERS:
1446 request = (MainThreadRequest) msg.obj;
1447 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001448 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001449 break;
1450
1451 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1452 ar = (AsyncResult) msg.obj;
1453 request = (MainThreadRequest) ar.userObj;
1454 if (ar.exception == null && ar.result != null) {
1455 request.result = ar.result;
1456 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001457 request.result = new IllegalStateException(
1458 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001459 if (ar.result == null) {
1460 loge("getAllowedCarriers: Empty response");
1461 } else if (ar.exception instanceof CommandException) {
1462 loge("getAllowedCarriers: CommandException: " +
1463 ar.exception);
1464 } else {
1465 loge("getAllowedCarriers: Unknown exception");
1466 }
1467 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001468 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001469 break;
1470
Nathan Haroldb3014052017-01-25 15:57:32 -08001471 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1472 ar = (AsyncResult) msg.obj;
1473 request = (MainThreadRequest) ar.userObj;
1474 if (ar.exception == null && ar.result != null) {
1475 request.result = ar.result;
1476 } else {
1477 request.result = new IllegalArgumentException(
1478 "Failed to retrieve Forbidden Plmns");
1479 if (ar.result == null) {
1480 loge("getForbiddenPlmns: Empty response");
1481 } else {
1482 loge("getForbiddenPlmns: Unknown exception");
1483 }
1484 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001485 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001486 break;
1487
1488 case CMD_GET_FORBIDDEN_PLMNS:
1489 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001490 uiccPort = getUiccPortFromRequest(request);
1491 if (uiccPort == null) {
1492 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001493 request.result = new IllegalArgumentException(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001494 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001495 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001496 break;
1497 }
1498 Integer appType = (Integer) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001499 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001500 if (uiccApp == null) {
1501 loge("getForbiddenPlmns() no app with specified type -- "
1502 + appType);
1503 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001504 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001505 break;
1506 } else {
1507 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1508 + " specified type -- " + appType);
1509 }
1510 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1511 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1512 onCompleted);
1513 break;
1514
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001515 case CMD_SWITCH_SLOTS:
1516 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00001517 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001518 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00001519 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001520 break;
1521
1522 case EVENT_SWITCH_SLOTS_DONE:
1523 ar = (AsyncResult) msg.obj;
1524 request = (MainThreadRequest) ar.userObj;
1525 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001526 notifyRequester(request);
1527 break;
1528 case CMD_GET_NETWORK_SELECTION_MODE:
1529 request = (MainThreadRequest) msg.obj;
1530 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1531 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1532 break;
1533
1534 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1535 ar = (AsyncResult) msg.obj;
1536 request = (MainThreadRequest) ar.userObj;
1537 if (ar.exception != null) {
1538 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1539 } else {
1540 int mode = ((int[]) ar.result)[0];
1541 if (mode == 0) {
1542 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1543 } else {
1544 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1545 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001546 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001547 notifyRequester(request);
1548 break;
1549 case CMD_GET_CDMA_ROAMING_MODE:
1550 request = (MainThreadRequest) msg.obj;
1551 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1552 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1553 break;
1554 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1555 ar = (AsyncResult) msg.obj;
1556 request = (MainThreadRequest) ar.userObj;
1557 if (ar.exception != null) {
1558 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1559 } else {
1560 request.result = ((int[]) ar.result)[0];
1561 }
1562 notifyRequester(request);
1563 break;
1564 case CMD_SET_CDMA_ROAMING_MODE:
1565 request = (MainThreadRequest) msg.obj;
1566 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1567 int mode = (int) request.argument;
1568 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1569 break;
1570 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1571 ar = (AsyncResult) msg.obj;
1572 request = (MainThreadRequest) ar.userObj;
1573 request.result = ar.exception == null;
1574 notifyRequester(request);
1575 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001576 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1577 request = (MainThreadRequest) msg.obj;
1578 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1579 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1580 break;
1581 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1582 ar = (AsyncResult) msg.obj;
1583 request = (MainThreadRequest) ar.userObj;
1584 if (ar.exception != null) {
1585 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1586 } else {
1587 request.result = ((int[]) ar.result)[0];
1588 }
1589 notifyRequester(request);
1590 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001591 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1592 request = (MainThreadRequest) msg.obj;
1593 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1594 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001595 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1596 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001597 break;
1598 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1599 ar = (AsyncResult) msg.obj;
1600 request = (MainThreadRequest) ar.userObj;
1601 request.result = ar.exception == null;
1602 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001603 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001604 case CMD_GET_ALL_CELL_INFO:
1605 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001606 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001607 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001608 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001609 case EVENT_GET_ALL_CELL_INFO_DONE:
1610 ar = (AsyncResult) msg.obj;
1611 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001612 // If a timeout occurs, the response will be null
1613 request.result = (ar.exception == null && ar.result != null)
1614 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001615 synchronized (request) {
1616 request.notifyAll();
1617 }
1618 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001619 case CMD_REQUEST_CELL_INFO_UPDATE:
1620 request = (MainThreadRequest) msg.obj;
1621 request.phone.requestCellInfoUpdate(request.workSource,
1622 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1623 break;
1624 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1625 ar = (AsyncResult) msg.obj;
1626 request = (MainThreadRequest) ar.userObj;
1627 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1628 try {
1629 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001630 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001631 cb.onError(
1632 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1633 ar.exception.getClass().getName(),
1634 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001635 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001636 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001637 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001638 } else {
1639 // use the result as returned
1640 cb.onCellInfo((List<CellInfo>) ar.result);
1641 }
1642 } catch (RemoteException re) {
1643 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1644 }
1645 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001646 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001647 request = (MainThreadRequest) msg.obj;
1648 WorkSource ws = (WorkSource) request.argument;
1649 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001650 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001651 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001652 }
1653 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001654 ar = (AsyncResult) msg.obj;
1655 request = (MainThreadRequest) ar.userObj;
1656 if (ar.exception == null) {
1657 request.result = ar.result;
1658 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001659 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001660 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001661 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001662 }
1663
1664 synchronized (request) {
1665 request.notifyAll();
1666 }
1667 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001668 }
chen xu6dac5ab2018-10-26 17:39:23 -07001669 case CMD_MODEM_REBOOT:
1670 request = (MainThreadRequest) msg.obj;
1671 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001672 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001673 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001674 case EVENT_CMD_MODEM_REBOOT_DONE:
1675 handleNullReturnEvent(msg, "rebootModem");
1676 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001677 case CMD_REQUEST_ENABLE_MODEM:
1678 request = (MainThreadRequest) msg.obj;
1679 boolean enable = (boolean) request.argument;
1680 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001681 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001682 PhoneConfigurationManager.getInstance()
1683 .enablePhone(request.phone, enable, onCompleted);
1684 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001685 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001686 ar = (AsyncResult) msg.obj;
1687 request = (MainThreadRequest) ar.userObj;
1688 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001689 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001690 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001691 if ((boolean) request.result) {
1692 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1693 updateModemStateMetrics();
1694 } else {
1695 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1696 + ar.exception);
1697 }
1698 notifyRequester(request);
1699 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001700 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001701 case CMD_GET_MODEM_STATUS:
1702 request = (MainThreadRequest) msg.obj;
1703 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1704 PhoneConfigurationManager.getInstance()
1705 .getPhoneStatusFromModem(request.phone, onCompleted);
1706 break;
1707 case EVENT_GET_MODEM_STATUS_DONE:
1708 ar = (AsyncResult) msg.obj;
1709 request = (MainThreadRequest) ar.userObj;
1710 int id = request.phone.getPhoneId();
1711 if (ar.exception == null && ar.result != null) {
1712 request.result = ar.result;
1713 //update the cache as modem status has changed
1714 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1715 (boolean) request.result);
1716 } else {
1717 // Return true if modem status cannot be retrieved. For most cases,
1718 // modem status is on. And for older version modems, GET_MODEM_STATUS
1719 // and disable modem are not supported. Modem is always on.
1720 // TODO: this should be fixed in R to support a third
1721 // status UNKNOWN b/131631629
1722 request.result = true;
1723 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1724 + ar.exception);
1725 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001726 notifyRequester(request);
1727 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001728 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1729 request = (MainThreadRequest) msg.obj;
1730 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1731 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1732 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1733 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1734 break;
1735 }
1736 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1737 ar = (AsyncResult) msg.obj;
1738 request = (MainThreadRequest) ar.userObj;
1739 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1740 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1741 args.second.accept(ar.exception == null);
1742 notifyRequester(request);
1743 break;
1744 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001745 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1746 request = (MainThreadRequest) msg.obj;
1747 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1748 Phone phone = getPhoneFromRequest(request);
1749 if (phone != null) {
1750 phone.getSystemSelectionChannels(onCompleted);
1751 } else {
1752 loge("getSystemSelectionChannels: No phone object");
1753 request.result = new ArrayList<RadioAccessSpecifier>();
1754 notifyRequester(request);
1755 }
1756 break;
1757 }
1758 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1759 ar = (AsyncResult) msg.obj;
1760 request = (MainThreadRequest) ar.userObj;
1761 if (ar.exception == null && ar.result != null) {
1762 request.result = ar.result;
1763 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001764 request.result = new IllegalStateException(
1765 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001766 if (ar.result == null) {
1767 loge("getSystemSelectionChannels: Empty response");
1768 } else {
1769 loge("getSystemSelectionChannels: Unknown exception");
1770 }
1771 }
1772 notifyRequester(request);
1773 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001774 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1775 ar = (AsyncResult) msg.obj;
1776 request = (MainThreadRequest) ar.userObj;
1777 if (ar.exception == null && ar.result != null) {
1778 request.result = ar.result;
1779 } else {
1780 request.result = -1;
1781 loge("Failed to set Forbidden Plmns");
1782 if (ar.result == null) {
1783 loge("setForbidenPlmns: Empty response");
1784 } else if (ar.exception != null) {
1785 loge("setForbiddenPlmns: Exception: " + ar.exception);
1786 request.result = -1;
1787 } else {
1788 loge("setForbiddenPlmns: Unknown exception");
1789 }
1790 }
1791 notifyRequester(request);
1792 break;
1793 case CMD_SET_FORBIDDEN_PLMNS:
1794 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001795 uiccPort = getUiccPortFromRequest(request);
1796 if (uiccPort == null) {
1797 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001798 request.result = -1;
1799 notifyRequester(request);
1800 break;
1801 }
1802 Pair<Integer, List<String>> setFplmnsArgs =
1803 (Pair<Integer, List<String>>) request.argument;
1804 appType = setFplmnsArgs.first;
1805 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001806 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001807 if (uiccApp == null) {
1808 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1809 request.result = -1;
1810 loge("Failed to get UICC App");
1811 notifyRequester(request);
1812 } else {
1813 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1814 ((SIMRecords) uiccApp.getIccRecords())
1815 .setForbiddenPlmns(onCompleted, fplmns);
1816 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001817 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001818 case CMD_ERASE_MODEM_CONFIG:
1819 request = (MainThreadRequest) msg.obj;
1820 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1821 defaultPhone.eraseModemConfig(onCompleted);
1822 break;
1823 case EVENT_ERASE_MODEM_CONFIG_DONE:
1824 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001825 break;
zoey chene02881a2019-12-30 16:11:23 +08001826
Kai Shif70f46f2021-03-03 13:59:46 -08001827 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1828 request = (MainThreadRequest) msg.obj;
1829 request.result = defaultPhone.eraseDataInSharedPreferences();
1830 notifyRequester(request);
1831 break;
1832
zoey chene02881a2019-12-30 16:11:23 +08001833 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1834 request = (MainThreadRequest) msg.obj;
1835 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1836 Pair<String, String> changed = (Pair<String, String>) request.argument;
1837 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1838 changed.first, changed.second, onCompleted);
1839 break;
1840 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1841 ar = (AsyncResult) msg.obj;
1842 request = (MainThreadRequest) ar.userObj;
1843 if (ar.exception == null) {
1844 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001845 // If the operation is successful, update the PIN storage
1846 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1847 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivackbb777522021-10-06 20:53:09 +00001848 UiccController.getInstance().getPinStorage()
1849 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001850 } else {
1851 request.result = msg.arg1;
1852 }
1853 notifyRequester(request);
1854 break;
1855
Michele Berionne5e411512020-11-13 02:36:59 +00001856 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001857 request = (MainThreadRequest) msg.obj;
1858 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1859 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1860 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1861 enabled.first, enabled.second, onCompleted);
1862 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001863 }
zoey chene02881a2019-12-30 16:11:23 +08001864 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1865 ar = (AsyncResult) msg.obj;
1866 request = (MainThreadRequest) ar.userObj;
1867 if (ar.exception == null) {
1868 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001869 // If the operation is successful, update the PIN storage
1870 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1871 int phoneId = getPhoneFromRequest(request).getPhoneId();
1872 if (enabled.first) {
Jon Spivackbb777522021-10-06 20:53:09 +00001873 UiccController.getInstance().getPinStorage()
1874 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001875 } else {
1876 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1877 }
zoey chene02881a2019-12-30 16:11:23 +08001878 } else {
1879 request.result = msg.arg1;
1880 }
Michele Berionne5e411512020-11-13 02:36:59 +00001881
1882
zoey chene02881a2019-12-30 16:11:23 +08001883 notifyRequester(request);
1884 break;
1885
Peter Wangdafb9ac2020-01-15 14:13:38 -08001886 case MSG_NOTIFY_USER_ACTIVITY:
1887 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001888 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001889 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1890 getDefaultPhone().getContext().sendBroadcastAsUser(
1891 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1892 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001893
1894 case CMD_SET_DATA_THROTTLING: {
1895 request = (MainThreadRequest) msg.obj;
1896 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1897 DataThrottlingRequest dataThrottlingRequest =
1898 (DataThrottlingRequest) request.argument;
1899 Phone phone = getPhoneFromRequest(request);
1900 if (phone != null) {
1901 phone.setDataThrottling(onCompleted,
1902 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1903 dataThrottlingRequest.getCompletionDurationMillis());
1904 } else {
1905 loge("setDataThrottling: No phone object");
1906 request.result =
1907 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1908 notifyRequester(request);
1909 }
1910
1911 break;
1912 }
1913 case EVENT_SET_DATA_THROTTLING_DONE:
1914 ar = (AsyncResult) msg.obj;
1915 request = (MainThreadRequest) ar.userObj;
1916
1917 if (ar.exception == null) {
1918 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1919 } else if (ar.exception instanceof CommandException) {
1920 loge("setDataThrottling: CommandException: " + ar.exception);
1921 CommandException.Error error =
1922 ((CommandException) (ar.exception)).getCommandError();
1923
1924 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1925 request.result = TelephonyManager
1926 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1927 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1928 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001929 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1930 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001931 } else {
1932 request.result =
1933 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1934 }
1935 } else {
1936 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1937 }
1938 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1939 notifyRequester(request);
1940 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001941
1942 case CMD_SET_SIM_POWER: {
1943 request = (MainThreadRequest) msg.obj;
1944 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1945 request = (MainThreadRequest) msg.obj;
1946 int stateToSet =
1947 ((Pair<Integer, IIntegerConsumer>)
1948 request.argument).first;
1949 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1950 break;
1951 }
1952 case EVENT_SET_SIM_POWER_DONE: {
1953 ar = (AsyncResult) msg.obj;
1954 request = (MainThreadRequest) ar.userObj;
1955 IIntegerConsumer callback =
1956 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1957 if (ar.exception != null) {
1958 loge("setSimPower exception: " + ar.exception);
1959 int errorCode = TelephonyManager.CallForwardingInfoCallback
1960 .RESULT_ERROR_UNKNOWN;
1961 if (ar.exception instanceof CommandException) {
1962 CommandException.Error error =
1963 ((CommandException) (ar.exception)).getCommandError();
1964 if (error == CommandException.Error.SIM_ERR) {
1965 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1966 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1967 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1968 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1969 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1970 } else {
1971 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1972 }
1973 }
1974 try {
1975 callback.accept(errorCode);
1976 } catch (RemoteException e) {
1977 // Ignore if the remote process is no longer available to call back.
1978 Log.w(LOG_TAG, "setSimPower: callback not available.");
1979 }
1980 } else {
1981 try {
1982 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1983 } catch (RemoteException e) {
1984 // Ignore if the remote process is no longer available to call back.
1985 Log.w(LOG_TAG, "setSimPower: callback not available.");
1986 }
1987 }
1988 break;
1989 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001990 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1991 request = (MainThreadRequest) msg.obj;
1992
1993 final Phone phone = getPhoneFromRequest(request);
1994 if (phone == null || phone.getServiceStateTracker() == null) {
1995 request.result = new IllegalStateException("Phone or SST is null");
1996 notifyRequester(request);
1997 break;
1998 }
1999
2000 Pair<Integer, SignalStrengthUpdateRequest> pair =
2001 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2002 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2003 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002004 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002005 request.subId, pair.first /*callingUid*/,
2006 pair.second /*request*/, onCompleted);
2007 break;
2008 }
2009 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2010 ar = (AsyncResult) msg.obj;
2011 request = (MainThreadRequest) ar.userObj;
2012 // request.result will be the exception of ar if present, true otherwise.
2013 // Be cautious not to leave result null which will wait() forever
2014 request.result = ar.exception != null ? ar.exception : true;
2015 notifyRequester(request);
2016 break;
2017 }
2018 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2019 request = (MainThreadRequest) msg.obj;
2020
2021 Phone phone = getPhoneFromRequest(request);
2022 if (phone == null || phone.getServiceStateTracker() == null) {
2023 request.result = new IllegalStateException("Phone or SST is null");
2024 notifyRequester(request);
2025 break;
2026 }
2027
2028 Pair<Integer, SignalStrengthUpdateRequest> pair =
2029 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2030 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2031 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002032 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002033 request.subId, pair.first /*callingUid*/,
2034 pair.second /*request*/, onCompleted);
2035 break;
2036 }
2037 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2038 ar = (AsyncResult) msg.obj;
2039 request = (MainThreadRequest) ar.userObj;
2040 request.result = ar.exception != null ? ar.exception : true;
2041 notifyRequester(request);
2042 break;
2043 }
Jordan Liu109698e2020-11-24 14:50:34 -08002044
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002045 case CMD_GET_SLICING_CONFIG: {
2046 request = (MainThreadRequest) msg.obj;
2047 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2048 request.phone.getSlicingConfig(onCompleted);
2049 break;
2050 }
2051 case EVENT_GET_SLICING_CONFIG_DONE: {
2052 ar = (AsyncResult) msg.obj;
2053 request = (MainThreadRequest) ar.userObj;
2054 ResultReceiver result = (ResultReceiver) request.argument;
2055
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002056 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002057 Bundle bundle = new Bundle();
2058 int resultCode = 0;
2059 if (ar.exception != null) {
2060 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2061 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002062 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002063 } else if (ar.result == null) {
2064 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002065 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002066 } else {
2067 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002068 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2069 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002070 }
2071
2072 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002073 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002074 }
2075 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2076 result.send(resultCode, bundle);
2077 notifyRequester(request);
2078 break;
2079 }
2080
Michele Berionne5e411512020-11-13 02:36:59 +00002081 case CMD_PREPARE_UNATTENDED_REBOOT:
2082 request = (MainThreadRequest) msg.obj;
2083 request.result =
2084 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
2085 notifyRequester(request);
2086 break;
2087
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002088 default:
2089 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2090 break;
2091 }
2092 }
Jake Hambye994d462014-02-03 13:10:13 -08002093
Pengquan Menga1bb6272018-09-06 09:59:22 -07002094 private void notifyRequester(MainThreadRequest request) {
2095 synchronized (request) {
2096 request.notifyAll();
2097 }
2098 }
2099
Jake Hambye994d462014-02-03 13:10:13 -08002100 private void handleNullReturnEvent(Message msg, String command) {
2101 AsyncResult ar = (AsyncResult) msg.obj;
2102 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2103 if (ar.exception == null) {
2104 request.result = true;
2105 } else {
2106 request.result = false;
2107 if (ar.exception instanceof CommandException) {
2108 loge(command + ": CommandException: " + ar.exception);
2109 } else {
2110 loge(command + ": Unknown exception");
2111 }
2112 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002113 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002114 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002115 }
2116
2117 /**
2118 * Posts the specified command to be executed on the main thread,
2119 * waits for the request to complete, and returns the result.
2120 * @see #sendRequestAsync
2121 */
2122 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002123 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2124 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002125 }
2126
2127 /**
2128 * Posts the specified command to be executed on the main thread,
2129 * waits for the request to complete, and returns the result.
2130 * @see #sendRequestAsync
2131 */
2132 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2133 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002134 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002135 }
2136
2137 /**
2138 * Posts the specified command to be executed on the main thread,
2139 * waits for the request to complete, and returns the result.
2140 * @see #sendRequestAsync
2141 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002142 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002143 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2144 }
2145
2146 /**
2147 * Posts the specified command to be executed on the main thread,
2148 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2149 * if not timeout or null otherwise.
2150 * @see #sendRequestAsync
2151 */
2152 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2153 long timeoutInMs) {
2154 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002155 }
2156
2157 /**
2158 * Posts the specified command to be executed on the main thread,
2159 * waits for the request to complete, and returns the result.
2160 * @see #sendRequestAsync
2161 */
Nathan Harold92bed182018-10-12 18:16:49 -07002162 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002163 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002164 }
2165
2166 /**
2167 * Posts the specified command to be executed on the main thread,
2168 * waits for the request to complete, and returns the result.
2169 * @see #sendRequestAsync
2170 */
2171 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002172 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2173 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002174 }
2175
2176 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002177 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2178 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2179 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002180 * @see #sendRequestAsync
2181 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002182 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2183 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002184 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2185 throw new RuntimeException("This method will deadlock if called from the main thread.");
2186 }
2187
Nathan Harold92bed182018-10-12 18:16:49 -07002188 MainThreadRequest request = null;
2189 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2190 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2191 } else if (phone != null) {
2192 request = new MainThreadRequest(argument, phone, workSource);
2193 } else {
2194 request = new MainThreadRequest(argument, subId, workSource);
2195 }
2196
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002197 Message msg = mMainThreadHandler.obtainMessage(command, request);
2198 msg.sendToTarget();
2199
Rambo Wang0f050d82021-02-12 11:43:36 -08002200
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002201 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002202 if (timeoutInMs >= 0) {
2203 // Wait for at least timeoutInMs before returning null request result
2204 long now = SystemClock.elapsedRealtime();
2205 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002206 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002207 try {
2208 request.wait(deadline - now);
2209 } catch (InterruptedException e) {
2210 // Do nothing, go back and check if request is completed or timeout
2211 } finally {
2212 now = SystemClock.elapsedRealtime();
2213 }
2214 }
2215 } else {
2216 // Wait for the request to complete
2217 while (request.result == null) {
2218 try {
2219 request.wait();
2220 } catch (InterruptedException e) {
2221 // Do nothing, go back and wait until the request is complete
2222 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002223 }
2224 }
2225 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002226 if (request.result == null) {
2227 Log.wtf(LOG_TAG,
2228 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2229 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002230 return request.result;
2231 }
2232
2233 /**
2234 * Asynchronous ("fire and forget") version of sendRequest():
2235 * Posts the specified command to be executed on the main thread, and
2236 * returns immediately.
2237 * @see #sendRequest
2238 */
2239 private void sendRequestAsync(int command) {
2240 mMainThreadHandler.sendEmptyMessage(command);
2241 }
2242
2243 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002244 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002245 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002246 */
2247 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002248 sendRequestAsync(command, argument, null, null);
2249 }
2250
2251 /**
2252 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2253 * @see {@link #sendRequest(int,Object)}
2254 */
2255 private void sendRequestAsync(
2256 int command, Object argument, Phone phone, WorkSource workSource) {
2257 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002258 Message msg = mMainThreadHandler.obtainMessage(command, request);
2259 msg.sendToTarget();
2260 }
2261
2262 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002263 * Initialize the singleton PhoneInterfaceManager instance.
2264 * This is only done once, at startup, from PhoneApp.onCreate().
2265 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002266 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002267 synchronized (PhoneInterfaceManager.class) {
2268 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002269 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002270 } else {
2271 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2272 }
2273 return sInstance;
2274 }
2275 }
2276
2277 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002278 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002279 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002280 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002281 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002282 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002283 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002284 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002285 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002286 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002287 mTelephonySharedPreferences =
2288 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002289 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002290 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002291 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002292 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002293
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002294 publish();
2295 }
2296
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002297 private Phone getDefaultPhone() {
2298 Phone thePhone = getPhone(getDefaultSubscription());
2299 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2300 }
2301
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002302 private void publish() {
2303 if (DBG) log("publish: " + this);
2304
Peter Wangc035ce42020-01-08 21:00:22 -08002305 TelephonyFrameworkInitializer
2306 .getTelephonyServiceManager()
2307 .getTelephonyServiceRegisterer()
2308 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002309 }
2310
Stuart Scott584921c2015-01-15 17:10:34 -08002311 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002312 if (request.phone != null) {
2313 return request.phone;
2314 } else {
2315 return getPhoneFromSubId(request.subId);
2316 }
2317 }
2318
2319 private Phone getPhoneFromSubId(int subId) {
2320 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2321 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002322 }
2323
Muralidhar Reddy864fe982021-09-29 19:38:40 +00002324 private UiccPort getUiccPortFromRequest(MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002325 Phone phone = getPhoneFromRequest(request);
2326 return phone == null ? null :
Muralidhar Reddy864fe982021-09-29 19:38:40 +00002327 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002328 }
2329
Wink Saville36469e72014-06-11 15:17:00 -07002330 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002331 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002332 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002333 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002334
Kai Shif70f46f2021-03-03 13:59:46 -08002335 private void sendEraseModemConfig(@NonNull Phone phone) {
2336 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2337 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2338 }
2339
2340 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2341 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2342 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002343 }
2344
Peter Wang44b186e2020-01-13 23:33:09 -08002345 private boolean isImsAvailableOnDevice() {
2346 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2347 if (pm == null) {
2348 // For some reason package manger is not available.. This will fail internally anyway,
2349 // so do not throw error and allow.
2350 return true;
2351 }
2352 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2353 }
2354
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002355 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002356 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002357 }
2358
Wink Savilleb564aae2014-10-23 10:18:09 -07002359 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002360 if (DBG) log("dial: " + number);
2361 // No permission check needed here: This is just a wrapper around the
2362 // ACTION_DIAL intent, which is available to any app since it puts up
2363 // the UI before it does anything.
2364
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002365 final long identity = Binder.clearCallingIdentity();
2366 try {
2367 String url = createTelUrl(number);
2368 if (url == null) {
2369 return;
2370 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002371
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002372 // PENDING: should we just silently fail if phone is offhook or ringing?
2373 PhoneConstants.State state = mCM.getState(subId);
2374 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2375 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2376 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2377 mApp.startActivity(intent);
2378 }
2379 } finally {
2380 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002381 }
2382 }
2383
2384 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002385 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002386 }
2387
Wink Savilleb564aae2014-10-23 10:18:09 -07002388 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002389 if (DBG) log("call: " + number);
2390
2391 // This is just a wrapper around the ACTION_CALL intent, but we still
2392 // need to do a permission check since we're calling startActivity()
2393 // from the context of the phone app.
2394 enforceCallPermission();
2395
Jordan Liu1617b712019-07-10 15:06:26 -07002396 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002397 != AppOpsManager.MODE_ALLOWED) {
2398 return;
2399 }
2400
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002401 final long identity = Binder.clearCallingIdentity();
2402 try {
2403 String url = createTelUrl(number);
2404 if (url == null) {
2405 return;
2406 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002407
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002408 boolean isValid = false;
2409 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2410 if (slist != null) {
2411 for (SubscriptionInfo subInfoRecord : slist) {
2412 if (subInfoRecord.getSubscriptionId() == subId) {
2413 isValid = true;
2414 break;
2415 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002416 }
Wink Saville08874612014-08-31 19:19:58 -07002417 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002418 if (!isValid) {
2419 return;
2420 }
Wink Saville08874612014-08-31 19:19:58 -07002421
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002422 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2423 intent.putExtra(SUBSCRIPTION_KEY, subId);
2424 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2425 mApp.startActivity(intent);
2426 } finally {
2427 Binder.restoreCallingIdentity(identity);
2428 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002429 }
2430
Wink Savilleb564aae2014-10-23 10:18:09 -07002431 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002432 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002433 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2434 }
2435
Wink Savilleb564aae2014-10-23 10:18:09 -07002436 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002437 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002438 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2439 }
2440
Wink Savilleb564aae2014-10-23 10:18:09 -07002441 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002442 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002443
2444 final long identity = Binder.clearCallingIdentity();
2445 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002446 Phone phone = getPhone(subId);
2447 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002448 checkSimPin.start();
2449 return checkSimPin.unlockSim(null, pin);
2450 } finally {
2451 Binder.restoreCallingIdentity(identity);
2452 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002453 }
2454
Wink Savilleb564aae2014-10-23 10:18:09 -07002455 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002456 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002457
2458 final long identity = Binder.clearCallingIdentity();
2459 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002460 Phone phone = getPhone(subId);
2461 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002462 checkSimPuk.start();
2463 return checkSimPuk.unlockSim(puk, pin);
2464 } finally {
2465 Binder.restoreCallingIdentity(identity);
2466 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002467 }
2468
2469 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002470 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002471 * a synchronous one.
2472 */
2473 private static class UnlockSim extends Thread {
2474
2475 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002476 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002477
2478 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002479 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2480 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002481
2482 // For replies from SimCard interface
2483 private Handler mHandler;
2484
2485 // For async handler to identify request type
2486 private static final int SUPPLY_PIN_COMPLETE = 100;
2487
Michele Berionne5e411512020-11-13 02:36:59 +00002488 UnlockSim(int phoneId, IccCard simCard) {
2489 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002490 mSimCard = simCard;
2491 }
2492
2493 @Override
2494 public void run() {
2495 Looper.prepare();
2496 synchronized (UnlockSim.this) {
2497 mHandler = new Handler() {
2498 @Override
2499 public void handleMessage(Message msg) {
2500 AsyncResult ar = (AsyncResult) msg.obj;
2501 switch (msg.what) {
2502 case SUPPLY_PIN_COMPLETE:
2503 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2504 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002505 mRetryCount = msg.arg1;
2506 if (ar.exception != null) {
2507 if (ar.exception instanceof CommandException &&
2508 ((CommandException)(ar.exception)).getCommandError()
2509 == CommandException.Error.PASSWORD_INCORRECT) {
2510 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002511 } //When UiccCardApp dispose,handle message and return exception
2512 else if (ar.exception instanceof CommandException &&
2513 ((CommandException) (ar.exception)).getCommandError()
2514 == CommandException.Error.ABORTED) {
2515 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002516 } else {
2517 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2518 }
2519 } else {
2520 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2521 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002522 mDone = true;
2523 UnlockSim.this.notifyAll();
2524 }
2525 break;
2526 }
2527 }
2528 };
2529 UnlockSim.this.notifyAll();
2530 }
2531 Looper.loop();
2532 }
2533
2534 /*
2535 * Use PIN or PUK to unlock SIM card
2536 *
2537 * If PUK is null, unlock SIM card with PIN
2538 *
2539 * If PUK is not null, unlock SIM card with PUK and set PIN code
2540 */
Wink Saville9de0f752013-10-22 19:04:03 -07002541 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002542
2543 while (mHandler == null) {
2544 try {
2545 wait();
2546 } catch (InterruptedException e) {
2547 Thread.currentThread().interrupt();
2548 }
2549 }
2550 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2551
2552 if (puk == null) {
2553 mSimCard.supplyPin(pin, callback);
2554 } else {
2555 mSimCard.supplyPuk(puk, pin, callback);
2556 }
2557
2558 while (!mDone) {
2559 try {
2560 Log.d(LOG_TAG, "wait for done");
2561 wait();
2562 } catch (InterruptedException e) {
2563 // Restore the interrupted status
2564 Thread.currentThread().interrupt();
2565 }
2566 }
2567 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002568 int[] resultArray = new int[2];
2569 resultArray[0] = mResult;
2570 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002571
2572 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivackbb777522021-10-06 20:53:09 +00002573 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002574 }
2575
Wink Saville9de0f752013-10-22 19:04:03 -07002576 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002577 }
2578 }
2579
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002580 /**
2581 * This method has been removed due to privacy and stability concerns.
2582 */
2583 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002584 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002585 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2586 return;
Wink Saville36469e72014-06-11 15:17:00 -07002587 }
2588
Nathan Harold1f889d82020-06-04 17:05:26 -07002589 @Override
2590 public void updateServiceLocationWithPackageName(String callingPackage) {
2591 mApp.getSystemService(AppOpsManager.class)
2592 .checkPackage(Binder.getCallingUid(), callingPackage);
2593
Nathan Haroldf096d982020-11-18 17:18:06 -08002594 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002595 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2596 // Callers targeting S have no business invoking this method.
2597 return;
2598 }
2599
2600 LocationAccessPolicy.LocationPermissionResult locationResult =
2601 LocationAccessPolicy.checkLocationPermission(mApp,
2602 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2603 .setCallingPackage(callingPackage)
2604 .setCallingFeatureId(null)
2605 .setCallingPid(Binder.getCallingPid())
2606 .setCallingUid(Binder.getCallingUid())
2607 .setMethod("updateServiceLocation")
2608 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2609 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2610 .build());
2611 // Apps that lack location permission have no business calling this method;
2612 // however, because no permission was declared in the public API, denials must
2613 // all be "soft".
2614 switch (locationResult) {
2615 case DENIED_HARD: /* fall through */
2616 case DENIED_SOFT:
2617 return;
2618 }
2619
2620 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002621 final long identity = Binder.clearCallingIdentity();
2622 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002623 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002624 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002625 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002626 }
2627 } finally {
2628 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002629 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002630 }
2631
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002632 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002633 @Override
2634 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002635 return isRadioOnWithFeature(callingPackage, null);
2636 }
2637
2638
2639 @Override
2640 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2641 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2642 callingFeatureId);
2643 }
2644
2645 @Deprecated
2646 @Override
2647 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2648 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002649 }
2650
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002651 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002652 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2653 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002654 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002655 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002656 return false;
2657 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002658
2659 final long identity = Binder.clearCallingIdentity();
2660 try {
2661 return isRadioOnForSubscriber(subId);
2662 } finally {
2663 Binder.restoreCallingIdentity(identity);
2664 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002665 }
2666
2667 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002668 final long identity = Binder.clearCallingIdentity();
2669 try {
2670 final Phone phone = getPhone(subId);
2671 if (phone != null) {
2672 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2673 } else {
2674 return false;
2675 }
2676 } finally {
2677 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002678 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002679 }
2680
2681 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002682 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002683 }
Wink Saville36469e72014-06-11 15:17:00 -07002684
Wink Savilleb564aae2014-10-23 10:18:09 -07002685 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002686 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002687
2688 final long identity = Binder.clearCallingIdentity();
2689 try {
2690 final Phone phone = getPhone(subId);
2691 if (phone != null) {
2692 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2693 }
2694 } finally {
2695 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002696 }
Wink Saville36469e72014-06-11 15:17:00 -07002697 }
2698
2699 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002700 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002701 }
2702
Wink Savilleb564aae2014-10-23 10:18:09 -07002703 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002704 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002705
2706 final long identity = Binder.clearCallingIdentity();
2707 try {
2708 final Phone phone = getPhone(subId);
2709 if (phone == null) {
2710 return false;
2711 }
2712 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2713 toggleRadioOnOffForSubscriber(subId);
2714 }
2715 return true;
2716 } finally {
2717 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002718 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002719 }
Wink Saville36469e72014-06-11 15:17:00 -07002720
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002721 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002722 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002723 /*
2724 * If any of the Radios are available, it will need to be
2725 * shutdown. So return true if any Radio is available.
2726 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002727 final long identity = Binder.clearCallingIdentity();
2728 try {
2729 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2730 Phone phone = PhoneFactory.getPhone(i);
2731 if (phone != null && phone.isRadioAvailable()) return true;
2732 }
2733 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2734 return false;
2735 } finally {
2736 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002737 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002738 }
2739
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002740 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002741 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002742 enforceModifyPermission();
2743
2744 final long identity = Binder.clearCallingIdentity();
2745 try {
2746 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2747 logv("Shutting down Phone " + i);
2748 shutdownRadioUsingPhoneId(i);
2749 }
2750 } finally {
2751 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002752 }
2753 }
2754
2755 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002756 Phone phone = PhoneFactory.getPhone(phoneId);
2757 if (phone != null && phone.isRadioAvailable()) {
2758 phone.shutdownRadio();
2759 }
2760 }
2761
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002762 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002763 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002764
2765 final long identity = Binder.clearCallingIdentity();
2766 try {
2767 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2768 if (defaultPhone != null) {
2769 defaultPhone.setRadioPower(turnOn);
2770 return true;
2771 } else {
2772 loge("There's no default phone.");
2773 return false;
2774 }
2775 } finally {
2776 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002777 }
Wink Saville36469e72014-06-11 15:17:00 -07002778 }
2779
Wink Savilleb564aae2014-10-23 10:18:09 -07002780 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002781 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002782
2783 final long identity = Binder.clearCallingIdentity();
2784 try {
2785 final Phone phone = getPhone(subId);
2786 if (phone != null) {
2787 phone.setRadioPower(turnOn);
2788 return true;
2789 } else {
2790 return false;
2791 }
2792 } finally {
2793 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002794 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002795 }
2796
Wink Saville36469e72014-06-11 15:17:00 -07002797 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002798 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002799 public boolean enableDataConnectivity() {
2800 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002801
2802 final long identity = Binder.clearCallingIdentity();
2803 try {
2804 int subId = mSubscriptionController.getDefaultDataSubId();
2805 final Phone phone = getPhone(subId);
2806 if (phone != null) {
Jack Yu6bc9c8b2021-12-17 23:14:15 -08002807 if (phone.isUsingNewDataStack()) {
2808 phone.getDataSettingsManager().setDataEnabled(
2809 TelephonyManager.DATA_ENABLED_REASON_USER, true);
2810 } else {
2811 phone.getDataEnabledSettings().setDataEnabled(
2812 TelephonyManager.DATA_ENABLED_REASON_USER, true);
2813 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002814 return true;
2815 } else {
2816 return false;
2817 }
2818 } finally {
2819 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002820 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002821 }
2822
Wink Saville36469e72014-06-11 15:17:00 -07002823 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002824 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002825 public boolean disableDataConnectivity() {
2826 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002827
2828 final long identity = Binder.clearCallingIdentity();
2829 try {
2830 int subId = mSubscriptionController.getDefaultDataSubId();
2831 final Phone phone = getPhone(subId);
2832 if (phone != null) {
Jack Yu6bc9c8b2021-12-17 23:14:15 -08002833 if (phone.isUsingNewDataStack()) {
2834 phone.getDataSettingsManager().setDataEnabled(
2835 TelephonyManager.DATA_ENABLED_REASON_USER, false);
2836 } else {
2837 phone.getDataEnabledSettings().setDataEnabled(
2838 TelephonyManager.DATA_ENABLED_REASON_USER, false);
2839 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002840 return true;
2841 } else {
2842 return false;
2843 }
2844 } finally {
2845 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002846 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002847 }
2848
Sanket Padawe356d7632015-06-22 14:03:32 -07002849 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002850 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002851 final long identity = Binder.clearCallingIdentity();
2852 try {
2853 final Phone phone = getPhone(subId);
2854 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002855 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002856 } else {
2857 return false;
2858 }
2859 } finally {
2860 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002861 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002862 }
2863
2864 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002865 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002866 }
2867
pkanwarae03a6b2016-11-06 20:37:09 -08002868 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002869 enforceCallPermission();
2870
2871 final long identity = Binder.clearCallingIdentity();
2872 try {
2873 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2874 return;
2875 }
2876 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2877 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2878 } finally {
2879 Binder.restoreCallingIdentity(identity);
2880 }
pkanwar32d516d2016-10-14 19:37:38 -07002881 };
2882
Wink Savilleb564aae2014-10-23 10:18:09 -07002883 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002884 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002885
2886 final long identity = Binder.clearCallingIdentity();
2887 try {
2888 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2889 return false;
2890 }
2891 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2892 } finally {
2893 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002894 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002895 }
2896
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002897 /**
2898 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2899 * tag on getCallState Binder call.
2900 */
2901 @Deprecated
2902 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002903 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002904 if (CompatChanges.isChangeEnabled(
2905 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2906 Binder.getCallingUid())) {
2907 // Do not allow this API to be called on API version 31+, it should only be
2908 // called on old apps using this Binder call directly.
2909 throw new SecurityException("This method can only be used for applications "
2910 + "targeting API version 30 or less.");
2911 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002912 final long identity = Binder.clearCallingIdentity();
2913 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002914 Phone phone = getPhone(getDefaultSubscription());
2915 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2916 PhoneConstantConversions.convertCallState(phone.getState());
2917 } finally {
2918 Binder.restoreCallingIdentity(identity);
2919 }
2920 }
2921
2922 @Override
2923 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2924 if (CompatChanges.isChangeEnabled(
2925 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2926 Binder.getCallingUid())) {
2927 // Check READ_PHONE_STATE for API version 31+
2928 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2929 featureId, "getCallStateForSubscription")) {
2930 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2931 + "targeting API level 31+.");
2932 }
2933 }
2934 final long identity = Binder.clearCallingIdentity();
2935 try {
2936 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002937 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2938 PhoneConstantConversions.convertCallState(phone.getState());
2939 } finally {
2940 Binder.restoreCallingIdentity(identity);
2941 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002942 }
2943
Sanket Padawe356d7632015-06-22 14:03:32 -07002944 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002945 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002946 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2947 }
2948
2949 @Override
2950 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002951 final long identity = Binder.clearCallingIdentity();
2952 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002953 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002954 if (phone != null) {
Jack Yu4accbd92021-11-29 11:36:17 -08002955 if (phone.isUsingNewDataStack()) {
2956 return phone.getDataNetworkController().getInternetDataNetworkState();
2957 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002958 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2959 } else {
2960 return PhoneConstantConversions.convertDataState(
2961 PhoneConstants.DataState.DISCONNECTED);
2962 }
2963 } finally {
2964 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002965 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002966 }
2967
Sanket Padawe356d7632015-06-22 14:03:32 -07002968 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002969 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002970 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2971 }
2972
2973 @Override
2974 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002975 final long identity = Binder.clearCallingIdentity();
2976 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002977 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002978 if (phone != null) {
2979 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2980 } else {
2981 return TelephonyManager.DATA_ACTIVITY_NONE;
2982 }
2983 } finally {
2984 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002985 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002986 }
2987
2988 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002989 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002990 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002991 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002992
2993 LocationAccessPolicy.LocationPermissionResult locationResult =
2994 LocationAccessPolicy.checkLocationPermission(mApp,
2995 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2996 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002997 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002998 .setCallingPid(Binder.getCallingPid())
2999 .setCallingUid(Binder.getCallingUid())
3000 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003001 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003002 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3003 .build());
3004 switch (locationResult) {
3005 case DENIED_HARD:
3006 throw new SecurityException("Not allowed to access cell location");
3007 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003008 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3009 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003010 }
3011
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003012 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003013 final long identity = Binder.clearCallingIdentity();
3014 try {
3015 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003016 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003017 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003018 } finally {
3019 Binder.restoreCallingIdentity(identity);
3020 }
Svetoslav64fad262015-04-14 14:35:21 -07003021 }
3022
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003023 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003024 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003025 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3026 // registered cell info, so return a NULL country instead.
3027 final long identity = Binder.clearCallingIdentity();
3028 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003029 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3030 // Get default phone in this case.
3031 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3032 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003033 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003034 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003035 if (phone == null) return "";
3036 ServiceStateTracker sst = phone.getServiceStateTracker();
3037 if (sst == null) return "";
3038 LocaleTracker lt = sst.getLocaleTracker();
3039 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003040 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003041 } finally {
3042 Binder.restoreCallingIdentity(identity);
3043 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003044 }
3045
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003046 /**
3047 * This method was removed due to potential issues caused by performing partial
3048 * updates of service state, and lack of a credible use case.
3049 *
3050 * This has the ability to break the telephony implementation by disabling notification of
3051 * changes in device connectivity. DO NOT USE THIS!
3052 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003053 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003054 public void enableLocationUpdates() {
3055 mApp.enforceCallingOrSelfPermission(
3056 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003057 }
3058
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003059 /**
3060 * This method was removed due to potential issues caused by performing partial
3061 * updates of service state, and lack of a credible use case.
3062 *
3063 * This has the ability to break the telephony implementation by disabling notification of
3064 * changes in device connectivity. DO NOT USE THIS!
3065 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003066 @Override
3067 public void disableLocationUpdates() {
3068 mApp.enforceCallingOrSelfPermission(
3069 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003070 }
3071
3072 @Override
3073 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003074 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3075 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003076 try {
3077 mApp.getSystemService(AppOpsManager.class)
3078 .checkPackage(Binder.getCallingUid(), callingPackage);
3079 } catch (SecurityException e) {
3080 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3081 throw e;
3082 }
3083
Nathan Haroldf096d982020-11-18 17:18:06 -08003084 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003085 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3086 throw new SecurityException(
3087 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3088 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003089
Jordan Liu1617b712019-07-10 15:06:26 -07003090 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003091 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3092 return null;
3093 }
Svetoslav64fad262015-04-14 14:35:21 -07003094
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003095 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003096
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003097 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003098 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003099
Nathan Haroldf180aac2018-06-01 18:43:55 -07003100 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3101 for (CellInfo ci : info) {
3102 if (ci instanceof CellInfoGsm) {
3103 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3104 } else if (ci instanceof CellInfoWcdma) {
3105 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3106 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003107 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003108 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003109 }
3110
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003111 private List<CellInfo> getCachedCellInfo() {
3112 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3113 for (Phone phone : PhoneFactory.getPhones()) {
3114 List<CellInfo> info = phone.getAllCellInfo();
3115 if (info != null) cellInfos.addAll(info);
3116 }
3117 return cellInfos;
3118 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003119
3120 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003121 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003122 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003123 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003124
3125 LocationAccessPolicy.LocationPermissionResult locationResult =
3126 LocationAccessPolicy.checkLocationPermission(mApp,
3127 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3128 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003129 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003130 .setCallingPid(Binder.getCallingPid())
3131 .setCallingUid(Binder.getCallingUid())
3132 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003133 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003134 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3135 .build());
3136 switch (locationResult) {
3137 case DENIED_HARD:
3138 throw new SecurityException("Not allowed to access cell info");
3139 case DENIED_SOFT:
3140 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003141 }
3142
Nathan Haroldf096d982020-11-18 17:18:06 -08003143 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003144 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3145 return getCachedCellInfo();
3146 }
3147
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003148 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003149 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003150 final long identity = Binder.clearCallingIdentity();
3151 try {
3152 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3153 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003154 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003155 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003156 if (info != null) cellInfos.addAll(info);
3157 }
3158 return cellInfos;
3159 } finally {
3160 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003161 }
3162 }
3163
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003164 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003165 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3166 String callingFeatureId) {
3167 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3168 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003169 }
3170
3171 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003172 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3173 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003174 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003175 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003176 }
3177
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003178 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3179 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003180 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003181 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003182
3183 LocationAccessPolicy.LocationPermissionResult locationResult =
3184 LocationAccessPolicy.checkLocationPermission(mApp,
3185 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3186 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003187 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003188 .setCallingPid(Binder.getCallingPid())
3189 .setCallingUid(Binder.getCallingUid())
3190 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003191 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3192 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003193 .build());
3194 switch (locationResult) {
3195 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003196 if (TelephonyPermissions
3197 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003198 // Safetynet logging for b/154934934
3199 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3200 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003201 throw new SecurityException("Not allowed to access cell info");
3202 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003203 if (TelephonyPermissions
3204 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003205 // Safetynet logging for b/154934934
3206 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3207 }
Nathan Harold5320c422019-05-09 10:26:08 -07003208 try {
3209 cb.onCellInfo(new ArrayList<CellInfo>());
3210 } catch (RemoteException re) {
3211 // Drop without consequences
3212 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003213 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003214 }
3215
Nathan Harolda939a962019-05-09 10:13:47 -07003216
3217 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003218 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3219
3220 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3221 }
3222
3223 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003224 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003225 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003226 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003227
3228 final long identity = Binder.clearCallingIdentity();
3229 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003230 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003231 } finally {
3232 Binder.restoreCallingIdentity(identity);
3233 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003234 }
3235
Shishir Agrawala9f32182016-04-12 12:00:16 -07003236 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003237 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003238 Phone phone = PhoneFactory.getPhone(slotIndex);
3239 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003240 return null;
3241 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003242 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003243 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003244 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003245 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003246 return null;
3247 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003248
3249 final long identity = Binder.clearCallingIdentity();
3250 try {
3251 return phone.getImei();
3252 } finally {
3253 Binder.restoreCallingIdentity(identity);
3254 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003255 }
3256
3257 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003258 public String getTypeAllocationCodeForSlot(int slotIndex) {
3259 Phone phone = PhoneFactory.getPhone(slotIndex);
3260 String tac = null;
3261 if (phone != null) {
3262 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003263 try {
3264 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3265 } catch (IndexOutOfBoundsException e) {
3266 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3267 return null;
3268 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003269 }
3270 return tac;
3271 }
3272
3273 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003274 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003275 try {
3276 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3277 } catch (SecurityException se) {
3278 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3279 throw new SecurityException("Package " + callingPackage + " does not belong to "
3280 + Binder.getCallingUid());
3281 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003282 Phone phone = PhoneFactory.getPhone(slotIndex);
3283 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003284 return null;
3285 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003286
Jeff Davidson913390f2018-02-23 17:11:49 -08003287 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003288 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003289 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003290 return null;
3291 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003292
3293 final long identity = Binder.clearCallingIdentity();
3294 try {
3295 return phone.getMeid();
3296 } finally {
3297 Binder.restoreCallingIdentity(identity);
3298 }
Jack Yu2af8d712017-03-15 17:14:14 -07003299 }
3300
3301 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003302 public String getManufacturerCodeForSlot(int slotIndex) {
3303 Phone phone = PhoneFactory.getPhone(slotIndex);
3304 String manufacturerCode = null;
3305 if (phone != null) {
3306 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003307 try {
3308 manufacturerCode =
3309 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3310 } catch (IndexOutOfBoundsException e) {
3311 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3312 return null;
3313 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003314 }
3315 return manufacturerCode;
3316 }
3317
3318 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003319 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3320 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003321 Phone phone = PhoneFactory.getPhone(slotIndex);
3322 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003323 return null;
3324 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003325 int subId = phone.getSubId();
3326 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003327 mApp, subId, callingPackage, callingFeatureId,
3328 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003329 return null;
3330 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003331
3332 final long identity = Binder.clearCallingIdentity();
3333 try {
3334 return phone.getDeviceSvn();
3335 } finally {
3336 Binder.restoreCallingIdentity(identity);
3337 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003338 }
3339
fionaxu43304da2017-11-27 22:51:16 -08003340 @Override
3341 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003342 final long identity = Binder.clearCallingIdentity();
3343 try {
3344 final Phone phone = getPhone(subId);
3345 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3346 } finally {
3347 Binder.restoreCallingIdentity(identity);
3348 }
fionaxu43304da2017-11-27 22:51:16 -08003349 }
3350
3351 @Override
3352 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003353 final long identity = Binder.clearCallingIdentity();
3354 try {
3355 final Phone phone = getPhone(subId);
3356 return phone == null ? null : phone.getCarrierName();
3357 } finally {
3358 Binder.restoreCallingIdentity(identity);
3359 }
fionaxu43304da2017-11-27 22:51:16 -08003360 }
3361
calvinpanffe225e2018-11-01 19:43:06 +08003362 @Override
chen xu0026ca62019-03-06 15:28:50 -08003363 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003364 final long identity = Binder.clearCallingIdentity();
3365 try {
3366 final Phone phone = getPhone(subId);
3367 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003368 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003369 } finally {
3370 Binder.restoreCallingIdentity(identity);
3371 }
3372 }
3373
3374 @Override
chen xu0026ca62019-03-06 15:28:50 -08003375 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003376 final long identity = Binder.clearCallingIdentity();
3377 try {
3378 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003379 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003380 } finally {
3381 Binder.restoreCallingIdentity(identity);
3382 }
3383 }
3384
chen xu651eec72018-11-11 19:03:44 -08003385 @Override
chen xu864e11c2018-12-06 22:10:03 -08003386 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3387 if (!isSubscriptionMccMnc) {
3388 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3389 }
chen xu651eec72018-11-11 19:03:44 -08003390 final Phone phone = PhoneFactory.getPhone(slotIndex);
3391 if (phone == null) {
3392 return TelephonyManager.UNKNOWN_CARRIER_ID;
3393 }
3394 final long identity = Binder.clearCallingIdentity();
3395 try {
3396 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3397 } finally {
3398 Binder.restoreCallingIdentity(identity);
3399 }
3400 }
3401
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003402 //
3403 // Internal helper methods.
3404 //
3405
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003406 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003407 * Make sure the caller is the calling package itself
3408 *
3409 * @throws SecurityException if the caller is not the calling package
3410 */
3411 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3412 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003413 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3414 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003415 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003416 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003417 } catch (PackageManager.NameNotFoundException e) {
3418 // packageUid is -1
3419 }
3420 if (packageUid != callingUid) {
3421 throw new SecurityException(message + ": Package " + callingPackage
3422 + " does not belong to " + callingUid);
3423 }
3424 }
3425
3426 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003427 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3428 *
3429 * @throws SecurityException if the caller does not have the required permission
3430 */
3431 private void enforceModifyPermission() {
3432 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3433 }
3434
Shuo Qian3b6ee772019-11-13 17:43:31 -08003435 private void enforceActiveEmergencySessionPermission() {
3436 mApp.enforceCallingOrSelfPermission(
3437 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3438 }
3439
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003440 /**
3441 * Make sure the caller has the CALL_PHONE permission.
3442 *
3443 * @throws SecurityException if the caller does not have the required permission
3444 */
3445 private void enforceCallPermission() {
3446 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3447 }
3448
paulhu5a773602019-08-23 19:17:33 +08003449 private void enforceSettingsPermission() {
3450 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003451 }
3452
Michele Berionne5e411512020-11-13 02:36:59 +00003453 private void enforceRebootPermission() {
3454 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3455 }
3456
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003457 private String createTelUrl(String number) {
3458 if (TextUtils.isEmpty(number)) {
3459 return null;
3460 }
3461
Jake Hambye994d462014-02-03 13:10:13 -08003462 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003463 }
3464
Ihab Awadf9e92732013-12-05 18:02:52 -08003465 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003466 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3467 }
3468
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003469 private static void logv(String msg) {
3470 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3471 }
3472
Ihab Awadf9e92732013-12-05 18:02:52 -08003473 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003474 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3475 }
3476
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003477 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003478 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003479 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003480 }
3481
Sanket Padawe356d7632015-06-22 14:03:32 -07003482 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003483 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003484 final long identity = Binder.clearCallingIdentity();
3485 try {
3486 final Phone phone = PhoneFactory.getPhone(slotIndex);
3487 if (phone == null) {
3488 return PhoneConstants.PHONE_TYPE_NONE;
3489 } else {
3490 return phone.getPhoneType();
3491 }
3492 } finally {
3493 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003494 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003495 }
3496
3497 /**
3498 * Returns the CDMA ERI icon index to display
3499 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003500 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003501 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3502 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3503 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003504 }
3505
Sanket Padawe356d7632015-06-22 14:03:32 -07003506 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003507 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3508 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003509 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003510 mApp, subId, callingPackage, callingFeatureId,
3511 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003512 return -1;
3513 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003514
3515 final long identity = Binder.clearCallingIdentity();
3516 try {
3517 final Phone phone = getPhone(subId);
3518 if (phone != null) {
3519 return phone.getCdmaEriIconIndex();
3520 } else {
3521 return -1;
3522 }
3523 } finally {
3524 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003525 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003526 }
3527
3528 /**
3529 * Returns the CDMA ERI icon mode,
3530 * 0 - ON
3531 * 1 - FLASHING
3532 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003533 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003534 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3535 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3536 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003537 }
3538
Sanket Padawe356d7632015-06-22 14:03:32 -07003539 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003540 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3541 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003542 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003543 mApp, subId, callingPackage, callingFeatureId,
3544 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003545 return -1;
3546 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003547
3548 final long identity = Binder.clearCallingIdentity();
3549 try {
3550 final Phone phone = getPhone(subId);
3551 if (phone != null) {
3552 return phone.getCdmaEriIconMode();
3553 } else {
3554 return -1;
3555 }
3556 } finally {
3557 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003558 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003559 }
3560
3561 /**
3562 * Returns the CDMA ERI text,
3563 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003564 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003565 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3566 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3567 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003568 }
3569
Sanket Padawe356d7632015-06-22 14:03:32 -07003570 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003571 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3572 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003573 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003574 mApp, subId, callingPackage, callingFeatureId,
3575 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003576 return null;
3577 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003578
3579 final long identity = Binder.clearCallingIdentity();
3580 try {
3581 final Phone phone = getPhone(subId);
3582 if (phone != null) {
3583 return phone.getCdmaEriText();
3584 } else {
3585 return null;
3586 }
3587 } finally {
3588 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003589 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003590 }
3591
3592 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003593 * Returns the CDMA MDN.
3594 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003595 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003596 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003597 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3598 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003599
3600 final long identity = Binder.clearCallingIdentity();
3601 try {
3602 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003603 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003604 return phone.getLine1Number();
3605 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003606 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003607 return null;
3608 }
3609 } finally {
3610 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003611 }
3612 }
3613
3614 /**
3615 * Returns the CDMA MIN.
3616 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003617 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003618 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003619 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3620 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003621
3622 final long identity = Binder.clearCallingIdentity();
3623 try {
3624 final Phone phone = getPhone(subId);
3625 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3626 return phone.getCdmaMin();
3627 } else {
3628 return null;
3629 }
3630 } finally {
3631 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003632 }
3633 }
3634
Hall Liud892bec2018-11-30 14:51:45 -08003635 @Override
3636 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3637 INumberVerificationCallback callback, String callingPackage) {
3638 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3639 != PERMISSION_GRANTED) {
3640 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3641 }
3642 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3643
3644 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3645 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003646 throw new SecurityException("Calling package must be configured in the device config: "
3647 + "calling package: " + callingPackage
3648 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003649 }
3650
3651 if (range == null) {
3652 throw new NullPointerException("Range must be non-null");
3653 }
3654
3655 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003656 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003657
3658 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3659 }
3660
Junda Liuca05d5d2014-08-14 22:36:34 -07003661 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003662 * Returns true if CDMA provisioning needs to run.
3663 */
3664 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003665 final long identity = Binder.clearCallingIdentity();
3666 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003667 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003668 } finally {
3669 Binder.restoreCallingIdentity(identity);
3670 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003671 }
3672
3673 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003674 * Sets the voice mail number of a given subId.
3675 */
3676 @Override
3677 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003678 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3679 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003680
3681 final long identity = Binder.clearCallingIdentity();
3682 try {
3683 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3684 new Pair<String, String>(alphaTag, number), new Integer(subId));
3685 return success;
3686 } finally {
3687 Binder.restoreCallingIdentity(identity);
3688 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003689 }
3690
Ta-wei Yen87c49842016-05-13 21:19:52 -07003691 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003692 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3693 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003694 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3695 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003696 if (!TextUtils.equals(callingPackage, systemDialer)) {
3697 throw new SecurityException("caller must be system dialer");
3698 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003699
3700 final long identity = Binder.clearCallingIdentity();
3701 try {
3702 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3703 if (phoneAccountHandle == null) {
3704 return null;
3705 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003706 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003707 } finally {
3708 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003709 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003710 }
3711
3712 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003713 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3714 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003715 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003716 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003717 mApp, subId, callingPackage, callingFeatureId,
3718 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003719 return null;
3720 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003721
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003722 final long identity = Binder.clearCallingIdentity();
3723 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003724 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003725 } finally {
3726 Binder.restoreCallingIdentity(identity);
3727 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003728 }
3729
3730 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003731 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3732 VisualVoicemailSmsFilterSettings settings) {
3733 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003734
3735 final long identity = Binder.clearCallingIdentity();
3736 try {
3737 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003738 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003739 } finally {
3740 Binder.restoreCallingIdentity(identity);
3741 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003742 }
3743
3744 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003745 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3746 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003747
3748 final long identity = Binder.clearCallingIdentity();
3749 try {
3750 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003751 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003752 } finally {
3753 Binder.restoreCallingIdentity(identity);
3754 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003755 }
3756
3757 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003758 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3759 String callingPackage, int subId) {
3760 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003761
3762 final long identity = Binder.clearCallingIdentity();
3763 try {
3764 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003765 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003766 } finally {
3767 Binder.restoreCallingIdentity(identity);
3768 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003769 }
3770
3771 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003772 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003773 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003774
3775 final long identity = Binder.clearCallingIdentity();
3776 try {
3777 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003778 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003779 } finally {
3780 Binder.restoreCallingIdentity(identity);
3781 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003782 }
3783
3784 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003785 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3786 String callingAttributionTag, int subId, String number, int port, String text,
3787 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003788 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003789 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003790 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003791 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003792 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3793 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003794 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003795
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003796 /**
fionaxu0152e512016-11-14 13:36:14 -08003797 * Sets the voice activation state of a given subId.
3798 */
3799 @Override
3800 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003801 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3802 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003803
3804 final long identity = Binder.clearCallingIdentity();
3805 try {
3806 final Phone phone = getPhone(subId);
3807 if (phone != null) {
3808 phone.setVoiceActivationState(activationState);
3809 } else {
3810 loge("setVoiceActivationState fails with invalid subId: " + subId);
3811 }
3812 } finally {
3813 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003814 }
3815 }
3816
3817 /**
3818 * Sets the data activation state of a given subId.
3819 */
3820 @Override
3821 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003822 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3823 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003824
3825 final long identity = Binder.clearCallingIdentity();
3826 try {
3827 final Phone phone = getPhone(subId);
3828 if (phone != null) {
3829 phone.setDataActivationState(activationState);
3830 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003831 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003832 }
3833 } finally {
3834 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003835 }
3836 }
3837
3838 /**
3839 * Returns the voice activation state of a given subId.
3840 */
3841 @Override
3842 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003843 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003844
fionaxu0152e512016-11-14 13:36:14 -08003845 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003846 final long identity = Binder.clearCallingIdentity();
3847 try {
3848 if (phone != null) {
3849 return phone.getVoiceActivationState();
3850 } else {
3851 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3852 }
3853 } finally {
3854 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003855 }
3856 }
3857
3858 /**
3859 * Returns the data activation state of a given subId.
3860 */
3861 @Override
3862 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003863 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003864
fionaxu0152e512016-11-14 13:36:14 -08003865 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003866 final long identity = Binder.clearCallingIdentity();
3867 try {
3868 if (phone != null) {
3869 return phone.getDataActivationState();
3870 } else {
3871 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3872 }
3873 } finally {
3874 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003875 }
3876 }
3877
3878 /**
Wink Saville36469e72014-06-11 15:17:00 -07003879 * Returns the unread count of voicemails for a subId
3880 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003881 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003882 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3883 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003884 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003885 mApp, subId, callingPackage, callingFeatureId,
3886 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003887 return 0;
3888 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003889 final long identity = Binder.clearCallingIdentity();
3890 try {
3891 final Phone phone = getPhone(subId);
3892 if (phone != null) {
3893 return phone.getVoiceMessageCount();
3894 } else {
3895 return 0;
3896 }
3897 } finally {
3898 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003899 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003900 }
3901
3902 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003903 * returns true, if the device is in a state where both voice and data
3904 * are supported simultaneously. This can change based on location or network condition.
3905 */
3906 @Override
3907 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003908 final long identity = Binder.clearCallingIdentity();
3909 try {
3910 final Phone phone = getPhone(subId);
3911 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3912 } finally {
3913 Binder.restoreCallingIdentity(identity);
3914 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003915 }
3916
3917 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003918 * Send the dialer code if called from the current default dialer or the caller has
3919 * carrier privilege.
3920 * @param inputCode The dialer code to send
3921 */
3922 @Override
3923 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003924 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003925 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003926 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3927 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003928 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003929 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003930 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003931 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003932
3933 final long identity = Binder.clearCallingIdentity();
3934 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003935 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003936 } finally {
3937 Binder.restoreCallingIdentity(identity);
3938 }
fionaxu235cc5e2017-03-06 22:25:57 -08003939 }
3940
Pengquan Menga1bb6272018-09-06 09:59:22 -07003941 @Override
3942 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003943 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003944 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003945 mApp, subId, "getNetworkSelectionMode");
3946 final long identity = Binder.clearCallingIdentity();
3947 try {
3948 if (!isActiveSubscription(subId)) {
3949 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3950 }
3951 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3952 } finally {
3953 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003954 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003955 }
3956
Brad Ebinger35c841c2018-10-01 10:40:55 -07003957 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003958 public boolean isInEmergencySmsMode() {
3959 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3960 final long identity = Binder.clearCallingIdentity();
3961 try {
3962 for (Phone phone : PhoneFactory.getPhones()) {
3963 if (phone.isInEmergencySmsMode()) {
3964 return true;
3965 }
3966 }
3967 } finally {
3968 Binder.restoreCallingIdentity(identity);
3969 }
3970 return false;
3971 }
3972
shilu366312e2019-12-17 09:28:10 -08003973 /**
3974 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3975 * @param subId The subscription to use to check the configuration.
3976 * @param c The callback that will be used to send the result.
3977 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003978 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003979 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3980 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003981 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003982 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003983
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003984 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3985 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3986 "IMS not available on device.");
3987 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003988 final long token = Binder.clearCallingIdentity();
3989 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003990 int slotId = getSlotIndexOrException(subId);
3991 verifyImsMmTelConfiguredOrThrow(slotId);
3992 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003993 } catch (ImsException e) {
3994 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003995 } finally {
3996 Binder.restoreCallingIdentity(token);
3997 }
3998 }
3999
shilu366312e2019-12-17 09:28:10 -08004000 /**
4001 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4002 * @param subId The subscription to use to check the configuration.
4003 * @param c The callback that will be used to send the result.
4004 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004005 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004006 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004007 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004008 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004009 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4010 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4011 }
Meng Wangafbc5852019-09-19 17:37:13 -07004012 final long token = Binder.clearCallingIdentity();
4013 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004014 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4015 .removeRegistrationCallbackForSubscription(c, subId);
4016 } catch (ImsException e) {
4017 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4018 + "is inactive, ignoring unregister.");
4019 // If the subscription is no longer active, just return, since the callback
4020 // will already have been removed internally.
4021 } finally {
4022 Binder.restoreCallingIdentity(token);
4023 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004024 }
4025
Brad Ebingera34a6c22019-10-22 17:36:18 -07004026 /**
4027 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4028 */
4029 @Override
4030 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4031 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4032 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4033 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4034 "IMS not available on device.");
4035 }
4036 final long token = Binder.clearCallingIdentity();
4037 try {
4038 Phone phone = getPhone(subId);
4039 if (phone == null) {
4040 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4041 + subId + "'");
4042 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4043 }
4044 phone.getImsRegistrationState(regState -> {
4045 try {
4046 consumer.accept((regState == null)
4047 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4048 } catch (RemoteException e) {
4049 // Ignore if the remote process is no longer available to call back.
4050 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4051 }
4052 });
4053 } finally {
4054 Binder.restoreCallingIdentity(token);
4055 }
4056 }
4057
4058 /**
4059 * Get the transport type for the IMS service registration state.
4060 */
4061 @Override
4062 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004063 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004064 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004065 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4066 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4067 "IMS not available on device.");
4068 }
4069 final long token = Binder.clearCallingIdentity();
4070 try {
4071 Phone phone = getPhone(subId);
4072 if (phone == null) {
4073 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4074 + subId + "'");
4075 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4076 }
4077 phone.getImsRegistrationTech(regTech -> {
4078 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4079 int regTechConverted = (regTech == null)
4080 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4081 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4082 regTechConverted);
4083 try {
4084 consumer.accept(regTechConverted);
4085 } catch (RemoteException e) {
4086 // Ignore if the remote process is no longer available to call back.
4087 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4088 }
4089 });
4090 } finally {
4091 Binder.restoreCallingIdentity(token);
4092 }
4093 }
4094
shilu366312e2019-12-17 09:28:10 -08004095 /**
4096 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4097 * @param subId The subscription to use to check the configuration.
4098 * @param c The callback that will be used to send the result.
4099 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004100 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004101 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4102 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004103 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004104 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004105 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4106 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4107 "IMS not available on device.");
4108 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004109 final long token = Binder.clearCallingIdentity();
4110 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004111 int slotId = getSlotIndexOrException(subId);
4112 verifyImsMmTelConfiguredOrThrow(slotId);
4113 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004114 } catch (ImsException e) {
4115 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004116 } finally {
4117 Binder.restoreCallingIdentity(token);
4118 }
4119 }
4120
shilu366312e2019-12-17 09:28:10 -08004121 /**
4122 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4123 * @param subId The subscription to use to check the configuration.
4124 * @param c The callback that will be used to send the result.
4125 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004126 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004127 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004128 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004129 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004130 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4131 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4132 }
Meng Wangafbc5852019-09-19 17:37:13 -07004133
4134 final long token = Binder.clearCallingIdentity();
4135 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004136 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004137 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004138 } catch (ImsException e) {
4139 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4140 + "is inactive, ignoring unregister.");
4141 // If the subscription is no longer active, just return, since the callback
4142 // will already have been removed internally.
4143 } finally {
4144 Binder.restoreCallingIdentity(token);
4145 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004146 }
4147
4148 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004149 public boolean isCapable(int subId, int capability, int regTech) {
4150 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004151 final long token = Binder.clearCallingIdentity();
4152 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004153 int slotId = getSlotIndexOrException(subId);
4154 verifyImsMmTelConfiguredOrThrow(slotId);
4155 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004156 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004157 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4158 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004159 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004160 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4161 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004162 } finally {
4163 Binder.restoreCallingIdentity(token);
4164 }
4165 }
4166
4167 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004168 public boolean isAvailable(int subId, int capability, int regTech) {
4169 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004170 final long token = Binder.clearCallingIdentity();
4171 try {
4172 Phone phone = getPhone(subId);
4173 if (phone == null) return false;
4174 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004175 } catch (com.android.ims.ImsException e) {
4176 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4177 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004178 } finally {
4179 Binder.restoreCallingIdentity(token);
4180 }
4181 }
4182
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004183 /**
4184 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4185 * subscription.
4186 * @param subId The subscription to use to check the configuration.
4187 * @param callback The callback that will be used to send the result.
4188 * @param capability The MmTelFeature capability that will be used to send the result.
4189 * @param transportType The transport type of the MmTelFeature capability.
4190 */
4191 @Override
4192 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4193 int transportType) {
4194 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4195 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4196 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4197 "IMS not available on device.");
4198 }
4199 final long token = Binder.clearCallingIdentity();
4200 try {
4201 int slotId = getSlotIndex(subId);
4202 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4203 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4204 + subId + "'");
4205 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4206 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004207 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004208 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4209 transportType, aBoolean -> {
4210 try {
4211 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4212 } catch (RemoteException e) {
4213 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4214 + "running. Ignore");
4215 }
4216 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004217 } catch (ImsException e) {
4218 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004219 } finally {
4220 Binder.restoreCallingIdentity(token);
4221 }
4222 }
4223
shilu366312e2019-12-17 09:28:10 -08004224 /**
4225 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4226 * @param subId The subscription to use to check the configuration.
4227 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004228 @Override
4229 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004230 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004231 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004232
Brad Ebinger35c841c2018-10-01 10:40:55 -07004233 final long token = Binder.clearCallingIdentity();
4234 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004235 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004236 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004237 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004238 } catch (ImsException e) {
4239 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004240 } finally {
4241 Binder.restoreCallingIdentity(token);
4242 }
4243 }
4244
4245 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004246 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004247 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004248 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004249 final long identity = Binder.clearCallingIdentity();
4250 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004251 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004252 // This setting doesn't require an active ImsService connection, so do not verify. The
4253 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004254 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004255 } catch (ImsException e) {
4256 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004257 } finally {
4258 Binder.restoreCallingIdentity(identity);
4259 }
4260 }
4261
shilu366312e2019-12-17 09:28:10 -08004262 /**
4263 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4264 * @param subId The subscription to use to check the configuration.
4265 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004266 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004267 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004268 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004269 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004270 final long identity = Binder.clearCallingIdentity();
4271 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004272 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004273 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004274 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004275 } catch (ImsException e) {
4276 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004277 } finally {
4278 Binder.restoreCallingIdentity(identity);
4279 }
4280 }
4281
4282 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004283 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004284 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004285 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004286 final long identity = Binder.clearCallingIdentity();
4287 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004288 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004289 // This setting doesn't require an active ImsService connection, so do not verify. The
4290 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004291 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004292 } catch (ImsException e) {
4293 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004294 } finally {
4295 Binder.restoreCallingIdentity(identity);
4296 }
4297 }
4298
shilu366312e2019-12-17 09:28:10 -08004299 /**
4300 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4301 * @param subId The subscription to use to check the configuration.
4302 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004303 @Override
4304 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004305 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004306 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004307 final long identity = Binder.clearCallingIdentity();
4308 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004309 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004310 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004311 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004312 } catch (ImsException e) {
4313 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004314 } finally {
4315 Binder.restoreCallingIdentity(identity);
4316 }
4317 }
4318
4319 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004320 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004321 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004322 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004323 final long identity = Binder.clearCallingIdentity();
4324 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004325 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004326 // This setting doesn't require an active ImsService connection, so do not verify. The
4327 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004328 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004329 } catch (ImsException e) {
4330 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004331 } finally {
4332 Binder.restoreCallingIdentity(identity);
4333 }
4334 }
4335
shilu366312e2019-12-17 09:28:10 -08004336 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004337 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4338 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4339 * @param subId The subscription to use to check the configuration.
4340 */
4341 @Override
4342 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004343 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004344 mApp, subId, "isCrossSimCallingEnabledByUser");
4345 final long identity = Binder.clearCallingIdentity();
4346 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004347 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004348 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004349 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004350 } catch (ImsException e) {
4351 throw new ServiceSpecificException(e.getCode());
4352 } finally {
4353 Binder.restoreCallingIdentity(identity);
4354 }
4355 }
4356
4357 /**
4358 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4359 * Requires MODIFY_PHONE_STATE permission.
4360 * @param subId The subscription to use to check the configuration.
4361 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4362 * false otherwise
4363 */
4364 @Override
4365 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4366 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4367 "setCrossSimCallingEnabled");
4368 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).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004374 } catch (ImsException e) {
4375 throw new ServiceSpecificException(e.getCode());
4376 } finally {
4377 Binder.restoreCallingIdentity(identity);
4378 }
4379 }
4380
4381 /**
shilu366312e2019-12-17 09:28:10 -08004382 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4383 * @param subId The subscription to use to check the configuration.
4384 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004385 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004386
Brad Ebinger35c841c2018-10-01 10:40:55 -07004387 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004388 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004389 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004390 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).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004395 } catch (ImsException e) {
4396 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004397 } finally {
4398 Binder.restoreCallingIdentity(identity);
4399 }
4400 }
4401
4402 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004403 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004404 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004405 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004406 final long identity = Binder.clearCallingIdentity();
4407 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004408 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004409 // This setting doesn't require an active ImsService connection, so do not verify. The
4410 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004411 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004412 } catch (ImsException e) {
4413 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004414 } finally {
4415 Binder.restoreCallingIdentity(identity);
4416 }
4417 }
4418
4419 @Override
4420 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4421 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4422 "setVoWiFiNonPersistent");
4423 final long identity = Binder.clearCallingIdentity();
4424 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004425 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004426 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004427 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004428 } catch (ImsException e) {
4429 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004430 } finally {
4431 Binder.restoreCallingIdentity(identity);
4432 }
4433 }
4434
shilu366312e2019-12-17 09:28:10 -08004435 /**
4436 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4437 * @param subId The subscription to use to check the configuration.
4438 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004439 @Override
4440 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004441 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004442 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004443 final long identity = Binder.clearCallingIdentity();
4444 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004445 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004446 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004447 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004448 } catch (ImsException e) {
4449 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004450 } finally {
4451 Binder.restoreCallingIdentity(identity);
4452 }
4453 }
4454
4455 @Override
4456 public void setVoWiFiModeSetting(int subId, int mode) {
4457 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4458 "setVoWiFiModeSetting");
4459 final long identity = Binder.clearCallingIdentity();
4460 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004461 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004462 // This setting doesn't require an active ImsService connection, so do not verify. The
4463 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004464 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004465 } catch (ImsException e) {
4466 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004467 } finally {
4468 Binder.restoreCallingIdentity(identity);
4469 }
4470 }
4471
4472 @Override
4473 public int getVoWiFiRoamingModeSetting(int subId) {
4474 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4475 final long identity = Binder.clearCallingIdentity();
4476 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004477 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004478 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004479 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004480 } catch (ImsException e) {
4481 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004482 } finally {
4483 Binder.restoreCallingIdentity(identity);
4484 }
4485 }
4486
4487 @Override
4488 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4489 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4490 "setVoWiFiRoamingModeSetting");
4491 final long identity = Binder.clearCallingIdentity();
4492 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004493 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004494 // This setting doesn't require an active ImsService connection, so do not verify. The
4495 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004496 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004497 } catch (ImsException e) {
4498 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004499 } finally {
4500 Binder.restoreCallingIdentity(identity);
4501 }
4502 }
4503
4504 @Override
4505 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4506 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4507 "setRttCapabilityEnabled");
4508 final long identity = Binder.clearCallingIdentity();
4509 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004510 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004511 // This setting doesn't require an active ImsService connection, so do not verify. The
4512 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004513 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004514 } catch (ImsException e) {
4515 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004516 } finally {
4517 Binder.restoreCallingIdentity(identity);
4518 }
4519 }
4520
shilu366312e2019-12-17 09:28:10 -08004521 /**
4522 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4523 * @param subId The subscription to use to check the configuration.
4524 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004525 @Override
4526 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004527 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004528 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004529 final long identity = Binder.clearCallingIdentity();
4530 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004531 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004532 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004533 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004534 } catch (ImsException e) {
4535 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004536 } finally {
4537 Binder.restoreCallingIdentity(identity);
4538 }
4539 }
4540
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004541 @Override
4542 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4543 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshin2c3e4232021-11-28 07:32:01 +00004544
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004545 final long identity = Binder.clearCallingIdentity();
4546 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004547 if (!isImsAvailableOnDevice()) {
4548 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4549 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004550 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004551 int slotId = getSlotIndexOrException(subId);
4552 verifyImsMmTelConfiguredOrThrow(slotId);
4553 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004554 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004555 } catch (ImsException e) {
4556 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004557 } finally {
4558 Binder.restoreCallingIdentity(identity);
4559 }
4560 }
4561
4562 @Override
4563 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4564 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshin2c3e4232021-11-28 07:32:01 +00004565
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004566 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004567 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4568 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4569 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004570 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004571 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004572 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004573 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004574 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4575 + "is inactive, ignoring unregister.");
4576 // If the subscription is no longer active, just return, since the callback will already
4577 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004578 } finally {
4579 Binder.restoreCallingIdentity(identity);
4580 }
4581 }
4582
joonhunshin2c3e4232021-11-28 07:32:01 +00004583 @Override
4584 public void registerFeatureProvisioningChangedCallback(int subId,
4585 IFeatureProvisioningCallback callback) {
4586 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4587 mApp, subId, "registerFeatureProvisioningChangedCallback");
4588
4589 final long identity = Binder.clearCallingIdentity();
4590 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4591 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4592 }
4593
4594 ImsProvisioningController.getInstance()
4595 .addFeatureProvisioningChangedCallback(subId, callback);
4596
4597 Binder.restoreCallingIdentity(identity);
4598 }
4599
4600 @Override
4601 public void unregisterFeatureProvisioningChangedCallback(int subId,
4602 IFeatureProvisioningCallback callback) {
4603 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4604 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4605
4606 final long identity = Binder.clearCallingIdentity();
4607 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4608 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4609 }
4610
4611 ImsProvisioningController.getInstance()
4612 .removeFeatureProvisioningChangedCallback(subId, callback);
4613
4614 Binder.restoreCallingIdentity(identity);
4615 }
allenwtsu99c623b2020-01-03 18:24:23 +08004616
4617 private void checkModifyPhoneStatePermission(int subId, String message) {
4618 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4619 message);
4620 }
4621
4622 private boolean isImsProvisioningRequired(int subId, int capability,
4623 boolean isMmtelCapability) {
4624 Phone phone = getPhone(subId);
4625 if (phone == null) {
4626 loge("phone instance null for subid " + subId);
4627 return false;
4628 }
4629 if (isMmtelCapability) {
4630 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4631 return false;
4632 }
4633 } else {
4634 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4635 return false;
4636 }
4637 }
4638 return true;
4639 }
4640
4641 @Override
joonhunshin2c3e4232021-11-28 07:32:01 +00004642 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004643 boolean isProvisioned) {
4644 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4645
4646 final long identity = Binder.clearCallingIdentity();
4647 try {
joonhunshin2c3e4232021-11-28 07:32:01 +00004648 ImsProvisioningController.getInstance()
4649 .setRcsProvisioningStatusForCapability(subId, capability, tech, isProvisioned);
4650 return;
allenwtsu99c623b2020-01-03 18:24:23 +08004651 } finally {
4652 Binder.restoreCallingIdentity(identity);
4653 }
allenwtsu99c623b2020-01-03 18:24:23 +08004654 }
4655
4656
4657 @Override
joonhunshin2c3e4232021-11-28 07:32:01 +00004658 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4659 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4660 mApp, subId, "getRcsProvisioningStatusForCapability");
4661
allenwtsu99c623b2020-01-03 18:24:23 +08004662 final long identity = Binder.clearCallingIdentity();
4663 try {
joonhunshin2c3e4232021-11-28 07:32:01 +00004664 return ImsProvisioningController.getInstance()
4665 .getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004666 } finally {
4667 Binder.restoreCallingIdentity(identity);
4668 }
4669 }
4670
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004671 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004672 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4673 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004674 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshin2c3e4232021-11-28 07:32:01 +00004675
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004676 final long identity = Binder.clearCallingIdentity();
4677 try {
joonhunshin2c3e4232021-11-28 07:32:01 +00004678 ImsProvisioningController.getInstance()
4679 .setImsProvisioningStatusForCapability(subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004680 } finally {
4681 Binder.restoreCallingIdentity(identity);
4682 }
4683 }
4684
4685 @Override
4686 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshin2c3e4232021-11-28 07:32:01 +00004687 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4688 mApp, subId, "getProvisioningStatusForCapability");
4689
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004690 final long identity = Binder.clearCallingIdentity();
4691 try {
joonhunshin2c3e4232021-11-28 07:32:01 +00004692 return ImsProvisioningController.getInstance()
4693 .getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004694
4695 } finally {
4696 Binder.restoreCallingIdentity(identity);
4697 }
4698 }
4699
4700 @Override
joonhunshin2c3e4232021-11-28 07:32:01 +00004701 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4702 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4703 mApp, subId, "isProvisioningRequiredForCapability");
4704
4705 final long identity = Binder.clearCallingIdentity();
4706 try {
4707 return ImsProvisioningController.getInstance()
4708 .isImsProvisioningRequiredForCapability(subId, capability, tech);
4709 } finally {
4710 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004711 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004712 }
4713
4714 @Override
joonhunshin2c3e4232021-11-28 07:32:01 +00004715 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4716 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4717 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004718
joonhunshin2c3e4232021-11-28 07:32:01 +00004719 final long identity = Binder.clearCallingIdentity();
4720 try {
4721 return ImsProvisioningController.getInstance()
4722 .isRcsProvisioningRequiredForCapability(subId, capability, tech);
4723 } finally {
4724 Binder.restoreCallingIdentity(identity);
4725 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004726 }
4727
4728 private static String getMmTelProvisioningKey(int subId, int tech) {
4729 // resulting key is provision_ims_mmtel_{subId}_{tech}
4730 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4731 }
4732
4733 /**
4734 * Query CarrierConfig to see if the specified capability requires provisioning for the
4735 * carrier associated with the subscription id.
4736 */
4737 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4738 int capability) {
4739 CarrierConfigManager configManager = new CarrierConfigManager(context);
4740 PersistableBundle c = configManager.getConfigForSubId(subId);
4741 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004742 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004743 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4744 false);
4745 boolean requireVoiceVtProvisioning = c.getBoolean(
4746 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4747
4748 // First check to make sure that the capability requires provisioning.
4749 switch (capability) {
4750 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4751 // intentional fallthrough
4752 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4753 if (requireVoiceVtProvisioning) {
4754 // Voice and Video requires provisioning
4755 return true;
4756 }
4757 break;
4758 }
4759 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4760 if (requireUtProvisioning) {
4761 // UT requires provisioning
4762 return true;
4763 }
4764 break;
4765 }
4766 }
4767 return false;
4768 }
4769
allenwtsu99c623b2020-01-03 18:24:23 +08004770 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4771 int capability) {
4772 CarrierConfigManager configManager = new CarrierConfigManager(context);
4773 PersistableBundle c = configManager.getConfigForSubId(subId);
4774
4775 boolean requireRcsProvisioning = c.getBoolean(
4776 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4777
4778 // First check to make sure that the capability requires provisioning.
4779 switch (capability) {
4780 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4781 // intentional fallthrough
4782 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4783 if (requireRcsProvisioning) {
4784 // OPTION or PRESENCE requires provisioning
4785 return true;
4786 }
4787 break;
4788 }
4789 }
4790 return false;
4791 }
4792
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004793 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004794 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004795 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4796 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4797 }
joonhunshin2c3e4232021-11-28 07:32:01 +00004798 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4799 mApp, subId, "getImsProvisioningInt");
4800
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004801 final long identity = Binder.clearCallingIdentity();
4802 try {
4803 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004804 int slotId = getSlotIndex(subId);
4805 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4806 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4807 + subId + "' for key:" + key);
4808 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4809 }
joonhunshin2c3e4232021-11-28 07:32:01 +00004810
4811 int retVal = ImsProvisioningController.getInstance().getProvisioningValue(subId, key);
4812 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4813 return retVal;
4814 }
4815
calvinpanb5a34062021-02-08 19:59:36 +08004816 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004817 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004818 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4819 + subId + "' for key:" + key);
4820 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004821 } finally {
4822 Binder.restoreCallingIdentity(identity);
4823 }
4824 }
4825
4826 @Override
4827 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004828 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4829 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4830 }
joonhunshin2c3e4232021-11-28 07:32:01 +00004831 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4832 mApp, subId, "getImsProvisioningString");
4833
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004834 final long identity = Binder.clearCallingIdentity();
4835 try {
4836 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004837 int slotId = getSlotIndex(subId);
4838 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4839 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4840 + subId + "' for key:" + key);
4841 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4842 }
calvinpanb5a34062021-02-08 19:59:36 +08004843 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004844 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004845 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4846 + subId + "' for key:" + key);
4847 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004848 } finally {
4849 Binder.restoreCallingIdentity(identity);
4850 }
4851 }
4852
4853 @Override
4854 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004855 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4856 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4857 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004858 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4859 "setImsProvisioningInt");
joonhunshin2c3e4232021-11-28 07:32:01 +00004860
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004861 final long identity = Binder.clearCallingIdentity();
4862 try {
4863 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004864 int slotId = getSlotIndex(subId);
4865 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4866 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4867 + subId + "' for key:" + key);
4868 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4869 }
joonhunshin2c3e4232021-11-28 07:32:01 +00004870
4871 int retVal = ImsProvisioningController.getInstance()
4872 .setProvisioningValue(subId, key, value);
4873 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4874 return retVal;
4875 }
4876
calvinpanb5a34062021-02-08 19:59:36 +08004877 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4878 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004879 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004880 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004881 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004882 } finally {
4883 Binder.restoreCallingIdentity(identity);
4884 }
4885 }
4886
4887 @Override
4888 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004889 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4890 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4891 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004892 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4893 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004894 final long identity = Binder.clearCallingIdentity();
4895 try {
4896 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004897 int slotId = getSlotIndex(subId);
4898 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4899 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4900 + subId + "' for key:" + key);
4901 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4902 }
calvinpanb5a34062021-02-08 19:59:36 +08004903 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4904 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004905 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004906 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004907 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004908 } finally {
4909 Binder.restoreCallingIdentity(identity);
4910 }
4911 }
4912
Brad Ebinger919631e2021-06-02 17:46:35 -07004913 /**
4914 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4915 * for the given slot ID or no ImsResolver instance has been created.
4916 * @param slotId The slot ID that the IMS service is created for.
4917 * @throws ImsException If there is no ImsService configured for this slot.
4918 */
4919 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4920 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4921 ImsFeature.FEATURE_MMTEL)) {
4922 throw new ImsException("This subscription does not support MMTEL over IMS",
4923 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4924 }
4925 }
4926
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004927 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004928 int slotId = SubscriptionManager.getSlotIndex(subId);
4929 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004930 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4931 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004932 }
4933 return slotId;
4934 }
4935
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004936 private int getSlotIndex(int subId) {
4937 int slotId = SubscriptionManager.getSlotIndex(subId);
4938 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4939 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4940 }
4941 return slotId;
4942 }
4943
Wink Saville36469e72014-06-11 15:17:00 -07004944 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004945 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004946 */
4947 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004948 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4949 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07004950 try {
4951 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4952 } catch (SecurityException se) {
4953 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
4954 throw new SecurityException("Package " + callingPackage + " does not belong to "
4955 + Binder.getCallingUid());
4956 }
Nathan Haroldf096d982020-11-18 17:18:06 -08004957 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004958 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004959 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004960 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004961 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004962 mApp, subId, callingPackage, callingFeatureId,
4963 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004964 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4965 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004966
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004967 final long identity = Binder.clearCallingIdentity();
4968 try {
4969 final Phone phone = getPhone(subId);
4970 if (phone != null) {
4971 return phone.getServiceState().getDataNetworkType();
4972 } else {
4973 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4974 }
4975 } finally {
4976 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004977 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004978 }
4979
4980 /**
4981 * Returns the data network type
4982 */
4983 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004984 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08004985 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
4986 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004987 }
4988
4989 /**
4990 * Returns the data network type for a subId
4991 */
4992 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004993 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4994 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07004995 String functionName = "getDataNetworkTypeForSubscriber";
4996 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
4997 mApp, functionName)) {
4998 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4999 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5000 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5001 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005002 }
5003
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005004 final long identity = Binder.clearCallingIdentity();
5005 try {
5006 final Phone phone = getPhone(subId);
5007 if (phone != null) {
5008 return phone.getServiceState().getDataNetworkType();
5009 } else {
5010 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5011 }
5012 } finally {
5013 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005014 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005015 }
5016
5017 /**
Wink Saville36469e72014-06-11 15:17:00 -07005018 * Returns the Voice network type for a subId
5019 */
5020 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005021 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5022 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005023 String functionName = "getVoiceNetworkTypeForSubscriber";
5024 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5025 mApp, functionName)) {
5026 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5027 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5028 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5029 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005030 }
5031
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005032 final long identity = Binder.clearCallingIdentity();
5033 try {
5034 final Phone phone = getPhone(subId);
5035 if (phone != null) {
5036 return phone.getServiceState().getVoiceNetworkType();
5037 } else {
5038 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5039 }
5040 } finally {
5041 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005042 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005043 }
5044
5045 /**
5046 * @return true if a ICC card is present
5047 */
5048 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005049 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005050 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5051 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005052 }
5053
5054 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005055 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005056 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005057 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005058 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005059 final long identity = Binder.clearCallingIdentity();
5060 try {
5061 final Phone phone = PhoneFactory.getPhone(slotIndex);
5062 if (phone != null) {
5063 return phone.getIccCard().hasIccCard();
5064 } else {
5065 return false;
5066 }
5067 } finally {
5068 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005069 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005070 }
5071
5072 /**
5073 * Return if the current radio is LTE on CDMA. This
5074 * is a tri-state return value as for a period of time
5075 * the mode may be unknown.
5076 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005077 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005078 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005079 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005080 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005081 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005082 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5083 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5084 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005085 }
5086
Sanket Padawe356d7632015-06-22 14:03:32 -07005087 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005088 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5089 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005090 try {
5091 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5092 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005093 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5094 }
5095
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005096 final long identity = Binder.clearCallingIdentity();
5097 try {
5098 final Phone phone = getPhone(subId);
5099 if (phone == null) {
5100 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5101 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005102 return TelephonyProperties.lte_on_cdma_device()
5103 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005104 }
5105 } finally {
5106 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005107 }
Wink Saville36469e72014-06-11 15:17:00 -07005108 }
5109
Wink Saville36469e72014-06-11 15:17:00 -07005110 /**
5111 * {@hide}
5112 * Returns Default subId, 0 in the case of single standby.
5113 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005114 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005115 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005116 }
5117
Shishir Agrawala9f32182016-04-12 12:00:16 -07005118 private int getSlotForDefaultSubscription() {
5119 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5120 }
5121
Wink Savilleb564aae2014-10-23 10:18:09 -07005122 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005123 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005124 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005125
Pengquan Menge92a50d2018-09-21 15:54:48 -07005126 private boolean isActiveSubscription(int subId) {
5127 return mSubscriptionController.isActiveSubId(subId);
5128 }
5129
Ihab Awadf2177b72013-11-25 13:33:23 -08005130 /**
5131 * @see android.telephony.TelephonyManager.WifiCallingChoices
5132 */
5133 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005134 final long identity = Binder.clearCallingIdentity();
5135 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005136 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005137 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5138 getWhenToMakeWifiCallsDefaultPreference());
5139 } finally {
5140 Binder.restoreCallingIdentity(identity);
5141 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005142 }
5143
5144 /**
5145 * @see android.telephony.TelephonyManager.WifiCallingChoices
5146 */
5147 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005148 final long identity = Binder.clearCallingIdentity();
5149 try {
5150 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005151 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005152 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5153 } finally {
5154 Binder.restoreCallingIdentity(identity);
5155 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005156 }
5157
Sailesh Nepald1e68152013-12-12 19:08:02 -08005158 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005159 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005160 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005161 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005162
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005163 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5164 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5165 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005166 if (phoneId == -1) {
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005167 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5168 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005169 }
5170 return PhoneFactory.getPhone(phoneId);
5171 }
5172
Shishir Agrawal566b7612013-10-28 14:41:00 -07005173 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005174 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wange162e302021-11-10 20:15:19 -08005175 @NonNull IccLogicalChannelRequest request) {
5176 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5177 /*message=*/ "iccOpenLogicalChannel");
5178
5179 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5180 // Verify that the callingPackage in the request belongs to the calling UID
5181 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5182
5183 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005184 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005185
Rambo Wange162e302021-11-10 20:15:19 -08005186 private Phone getPhoneFromValidIccLogicalChannelRequest(
5187 @NonNull IccLogicalChannelRequest request, String message) {
5188 Phone phone;
5189 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5190 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5191 mApp, request.subId, message);
5192 phone = getPhoneFromSubId(request.subId);
5193 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5194 enforceModifyPermission();
5195 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5196 } else {
5197 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005198 }
Rambo Wange162e302021-11-10 20:15:19 -08005199 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005200 }
5201
5202 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wange162e302021-11-10 20:15:19 -08005203 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005204 final long identity = Binder.clearCallingIdentity();
5205 try {
Rambo Wange162e302021-11-10 20:15:19 -08005206 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005207 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005208 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5209 .getContext().getPackageManager());
Rambo Wange162e302021-11-10 20:15:19 -08005210 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5211 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005212 loge("The calling package is not allowed to access ISD-R.");
5213 throw new SecurityException(
5214 "The calling package is not allowed to access ISD-R.");
5215 }
Derek Tan740e1672017-06-27 14:56:27 -07005216 }
Derek Tan740e1672017-06-27 14:56:27 -07005217
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005218 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wange162e302021-11-10 20:15:19 -08005219 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5220 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005221 return response;
5222 } finally {
5223 Binder.restoreCallingIdentity(identity);
5224 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005225 }
5226
5227 @Override
Rambo Wange162e302021-11-10 20:15:19 -08005228 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5229 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5230 /*message=*/"iccCloseLogicalChannel");
5231
5232 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5233
5234 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005235 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005236
Rambo Wange162e302021-11-10 20:15:19 -08005237 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5238 IccLogicalChannelRequest request) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005239 final long identity = Binder.clearCallingIdentity();
5240 try {
Rambo Wange162e302021-11-10 20:15:19 -08005241 if (request.channel < 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005242 return false;
5243 }
Rambo Wange162e302021-11-10 20:15:19 -08005244 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005245 null /* workSource */);
Rambo Wange162e302021-11-10 20:15:19 -08005246 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005247 return success;
5248 } finally {
5249 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005250 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005251 }
5252
5253 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005254 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005255 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005256 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5257 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005258 if (DBG) {
5259 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5260 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5261 + p3 + " data=" + data);
5262 }
5263 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5264 command, p1, p2, p3, data);
5265 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005266
Jordan Liu4c733742019-02-28 12:03:40 -08005267 @Override
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005268 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5269 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005270 enforceModifyPermission();
5271 if (DBG) {
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005272 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5273 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5274 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005275 }
5276 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005277 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5278 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005279 }
5280
5281 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5282 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005283 final long identity = Binder.clearCallingIdentity();
5284 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005285 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005286 return "";
5287 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005288
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005289 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005290 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5291 null /* workSource */);
5292 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005293
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005294 // Append the returned status code to the end of the response payload.
5295 String s = Integer.toHexString(
5296 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5297 if (response.payload != null) {
5298 s = IccUtils.bytesToHexString(response.payload) + s;
5299 }
5300 return s;
5301 } finally {
5302 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005303 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005304 }
Jake Hambye994d462014-02-03 13:10:13 -08005305
Evan Charltonc66da362014-05-16 14:06:40 -07005306 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005307 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5308 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005309 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5310 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005311 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005312 if (DBG) {
5313 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5314 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5315 }
5316 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5317 cla, command, p1, p2, p3, data);
5318 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005319
Jordan Liu4c733742019-02-28 12:03:40 -08005320 @Override
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005321 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5322 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005323 enforceModifyPermission();
5324 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5325 if (DBG) {
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005326 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5327 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5328 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005329 }
5330
5331 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddyc4c6a692021-12-02 21:04:16 +00005332 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5333 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005334 }
5335
5336 // open APDU basic channel assuming the caller has sufficient permissions
5337 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5338 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005339 final long identity = Binder.clearCallingIdentity();
5340 try {
5341 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5342 && TextUtils.equals(ISDR_AID, data)) {
5343 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005344 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5345 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005346 if (bestComponent == null
5347 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5348 loge("The calling package is not allowed to select ISD-R.");
5349 throw new SecurityException(
5350 "The calling package is not allowed to select ISD-R.");
5351 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005352 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005353
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005354 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005355 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5356 null /* workSource */);
5357 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005358
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005359 // Append the returned status code to the end of the response payload.
5360 String s = Integer.toHexString(
5361 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5362 if (response.payload != null) {
5363 s = IccUtils.bytesToHexString(response.payload) + s;
5364 }
5365 return s;
5366 } finally {
5367 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005368 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005369 }
5370
5371 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005372 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005373 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005374 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5375 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005376
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005377 final long identity = Binder.clearCallingIdentity();
5378 try {
5379 if (DBG) {
5380 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5381 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5382 }
5383
5384 IccIoResult response =
5385 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5386 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5387 subId);
5388
5389 if (DBG) {
5390 log("Exchange SIM_IO [R]" + response);
5391 }
5392
5393 byte[] result = null;
5394 int length = 2;
5395 if (response.payload != null) {
5396 length = 2 + response.payload.length;
5397 result = new byte[length];
5398 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5399 } else {
5400 result = new byte[length];
5401 }
5402
5403 result[length - 1] = (byte) response.sw2;
5404 result[length - 2] = (byte) response.sw1;
5405 return result;
5406 } finally {
5407 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005408 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005409 }
5410
Nathan Haroldb3014052017-01-25 15:57:32 -08005411 /**
5412 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5413 * on a particular subscription
5414 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005415 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5416 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005417 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005418 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005419 return null;
5420 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005421
5422 final long identity = Binder.clearCallingIdentity();
5423 try {
5424 if (appType != TelephonyManager.APPTYPE_USIM
5425 && appType != TelephonyManager.APPTYPE_SIM) {
5426 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5427 return null;
5428 }
5429 Object response = sendRequest(
5430 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5431 if (response instanceof String[]) {
5432 return (String[]) response;
5433 }
yincheng zhao2737e882019-09-06 17:06:54 -07005434 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005435 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005436 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005437 } finally {
5438 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005439 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005440 }
5441
yincheng zhao2737e882019-09-06 17:06:54 -07005442 /**
5443 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5444 * subscription.
5445 *
5446 * @param subId the id of the subscription.
5447 * @param appType the uicc app type, must be USIM or SIM.
5448 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5449 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005450 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005451 * @return number of fplmns that is successfully written to the SIM.
5452 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005453 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5454 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005455 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5456 mApp, subId, "setForbiddenPlmns");
5457
yincheng zhao2737e882019-09-06 17:06:54 -07005458 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5459 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5460 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5461 }
5462 if (fplmns == null) {
5463 throw new IllegalArgumentException("Fplmn List provided is null");
5464 }
5465 for (String fplmn : fplmns) {
5466 if (!CellIdentity.isValidPlmn(fplmn)) {
5467 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5468 }
5469 }
5470 final long identity = Binder.clearCallingIdentity();
5471 try {
5472 Object response = sendRequest(
5473 CMD_SET_FORBIDDEN_PLMNS,
5474 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5475 subId);
5476 return (int) response;
5477 } finally {
5478 Binder.restoreCallingIdentity(identity);
5479 }
5480 }
5481
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005482 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005483 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005484 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5485 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005486
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005487 final long identity = Binder.clearCallingIdentity();
5488 try {
5489 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5490 if (response.payload == null) {
5491 return "";
5492 }
Evan Charltonc66da362014-05-16 14:06:40 -07005493
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005494 // Append the returned status code to the end of the response payload.
5495 String s = Integer.toHexString(
5496 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5497 s = IccUtils.bytesToHexString(response.payload) + s;
5498 return s;
5499 } finally {
5500 Binder.restoreCallingIdentity(identity);
5501 }
Evan Charltonc66da362014-05-16 14:06:40 -07005502 }
5503
Jake Hambye994d462014-02-03 13:10:13 -08005504 /**
5505 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5506 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5507 *
5508 * @param itemID the ID of the item to read
5509 * @return the NV item as a String, or null on error.
5510 */
5511 @Override
5512 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005513 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005514 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5515 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005516
5517 final long identity = Binder.clearCallingIdentity();
5518 try {
5519 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005520 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005521 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5522 return value;
5523 } finally {
5524 Binder.restoreCallingIdentity(identity);
5525 }
Jake Hambye994d462014-02-03 13:10:13 -08005526 }
5527
5528 /**
5529 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5530 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5531 *
5532 * @param itemID the ID of the item to read
5533 * @param itemValue the value to write, as a String
5534 * @return true on success; false on any failure
5535 */
5536 @Override
5537 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005538 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005539 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5540 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005541
5542 final long identity = Binder.clearCallingIdentity();
5543 try {
5544 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5545 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005546 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005547 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5548 return success;
5549 } finally {
5550 Binder.restoreCallingIdentity(identity);
5551 }
Jake Hambye994d462014-02-03 13:10:13 -08005552 }
5553
5554 /**
5555 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5556 * Used for device configuration by some CDMA operators.
5557 *
5558 * @param preferredRoamingList byte array containing the new PRL
5559 * @return true on success; false on any failure
5560 */
5561 @Override
5562 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005563 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5564 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005565
5566 final long identity = Binder.clearCallingIdentity();
5567 try {
5568 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5569 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5570 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5571 return success;
5572 } finally {
5573 Binder.restoreCallingIdentity(identity);
5574 }
Jake Hambye994d462014-02-03 13:10:13 -08005575 }
5576
5577 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005578 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005579 * Used for device configuration by some CDMA operators.
5580 *
chen xu6dac5ab2018-10-26 17:39:23 -07005581 * @param slotIndex - device slot.
5582 *
Jake Hambye994d462014-02-03 13:10:13 -08005583 * @return true on success; false on any failure
5584 */
5585 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005586 public boolean resetModemConfig(int slotIndex) {
5587 Phone phone = PhoneFactory.getPhone(slotIndex);
5588 if (phone != null) {
5589 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5590 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005591
chen xu6dac5ab2018-10-26 17:39:23 -07005592 final long identity = Binder.clearCallingIdentity();
5593 try {
5594 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5595 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5596 return success;
5597 } finally {
5598 Binder.restoreCallingIdentity(identity);
5599 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005600 }
chen xu6dac5ab2018-10-26 17:39:23 -07005601 return false;
5602 }
5603
5604 /**
5605 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5606 *
5607 * @param slotIndex - device slot.
5608 *
5609 * @return true on success; false on any failure
5610 */
5611 @Override
5612 public boolean rebootModem(int slotIndex) {
5613 Phone phone = PhoneFactory.getPhone(slotIndex);
5614 if (phone != null) {
5615 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5616 mApp, phone.getSubId(), "rebootModem");
5617
5618 final long identity = Binder.clearCallingIdentity();
5619 try {
5620 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5621 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5622 return success;
5623 } finally {
5624 Binder.restoreCallingIdentity(identity);
5625 }
5626 }
5627 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005628 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005629
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005630 public String[] getPcscfAddress(String apnType, String callingPackage,
5631 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005632 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005633 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5634 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005635 return new String[0];
5636 }
5637
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005638 final long identity = Binder.clearCallingIdentity();
5639 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005640 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005641 } finally {
5642 Binder.restoreCallingIdentity(identity);
5643 }
Wink Saville36469e72014-06-11 15:17:00 -07005644 }
5645
Brad Ebinger51f743a2017-01-23 13:50:20 -08005646 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005647 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5648 * {@link #disableIms(int)}.
5649 * @param slotIndex device slot.
5650 */
5651 public void resetIms(int slotIndex) {
5652 enforceModifyPermission();
5653
5654 final long identity = Binder.clearCallingIdentity();
5655 try {
5656 if (mImsResolver == null) {
5657 // may happen if the does not support IMS.
5658 return;
5659 }
5660 mImsResolver.disableIms(slotIndex);
5661 mImsResolver.enableIms(slotIndex);
5662 } finally {
5663 Binder.restoreCallingIdentity(identity);
5664 }
5665 }
5666
5667 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005668 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5669 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005670 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005671 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005672 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005673
5674 final long identity = Binder.clearCallingIdentity();
5675 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005676 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005677 // may happen if the device does not support IMS.
5678 return;
5679 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005680 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005681 } finally {
5682 Binder.restoreCallingIdentity(identity);
5683 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005684 }
5685
5686 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005687 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5688 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005689 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005690 public void disableIms(int slotId) {
5691 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005692
5693 final long identity = Binder.clearCallingIdentity();
5694 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005695 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005696 // may happen if the device does not support IMS.
5697 return;
5698 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005699 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005700 } finally {
5701 Binder.restoreCallingIdentity(identity);
5702 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005703 }
5704
5705 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005706 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5707 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005708 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005709 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005710 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005711 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005712
5713 final long identity = Binder.clearCallingIdentity();
5714 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005715 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005716 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5717 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005718 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005719 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005720 } finally {
5721 Binder.restoreCallingIdentity(identity);
5722 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005723 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005724 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005725 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5726 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005727 @Override
5728 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005729 enforceModifyPermission();
5730
5731 final long identity = Binder.clearCallingIdentity();
5732 try {
5733 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005734 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005735 } finally {
5736 Binder.restoreCallingIdentity(identity);
5737 }
5738 }
5739
5740 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005741 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005742 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005743 */
5744 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5745 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005746
5747 final long identity = Binder.clearCallingIdentity();
5748 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005749 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005750 // may happen if the device does not support IMS.
5751 return null;
5752 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005753 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005754 } finally {
5755 Binder.restoreCallingIdentity(identity);
5756 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005757 }
5758
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005759 /**
5760 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005761 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005762 */
5763 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5764 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005765
5766 final long identity = Binder.clearCallingIdentity();
5767 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005768 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005769 // may happen if the device does not support IMS.
5770 return null;
5771 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005772 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005773 } finally {
5774 Binder.restoreCallingIdentity(identity);
5775 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005776 }
5777
Brad Ebinger884c07b2018-02-15 16:17:40 -08005778 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005779 * Sets the ImsService Package Name that Telephony will bind to.
5780 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005781 * @param slotIndex the slot ID that the ImsService should bind for.
5782 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005783 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005784 * @param featureTypes An integer array of feature types associated with a packageName.
5785 * @param packageName The name of the package that the current configuration will be replaced
5786 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005787 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005788 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005789 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5790 int[] featureTypes, String packageName) {
5791 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5792 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005793 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5794 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005795 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005796
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005797 final long identity = Binder.clearCallingIdentity();
5798 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005799 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005800 // may happen if the device does not support IMS.
5801 return false;
5802 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005803 Map<Integer, String> featureConfig = new HashMap<>();
5804 for (int featureType : featureTypes) {
5805 featureConfig.put(featureType, packageName);
5806 }
5807 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5808 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005809 } finally {
5810 Binder.restoreCallingIdentity(identity);
5811 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005812 }
5813
5814 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005815 * Clears any carrier ImsService overrides for the slot index specified that were previously
5816 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5817 *
5818 * This should only be used for testing.
5819 *
5820 * @param slotIndex the slot ID that the ImsService should bind for.
5821 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5822 */
5823 @Override
5824 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5825 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5826 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5827 "clearCarrierImsServiceOverride");
5828 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5829 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5830 "clearCarrierImsServiceOverride");
5831
5832 final long identity = Binder.clearCallingIdentity();
5833 try {
5834 if (mImsResolver == null) {
5835 // may happen if the device does not support IMS.
5836 return false;
5837 }
5838 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5839 } finally {
5840 Binder.restoreCallingIdentity(identity);
5841 }
5842 }
5843
5844 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005845 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005846 *
5847 * @param slotId The slot that the ImsService is associated with.
5848 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5849 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005850 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005851 * @return the package name of the ImsService configuration.
5852 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005853 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5854 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005855 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005856 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005857 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005858 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5859 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005860
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005861 final long identity = Binder.clearCallingIdentity();
5862 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005863 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005864 // may happen if the device does not support IMS.
5865 return "";
5866 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005867 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005868 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5869 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005870 } finally {
5871 Binder.restoreCallingIdentity(identity);
5872 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005873 }
5874
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005875 /**
5876 * Get the MmTelFeature state associated with the requested subscription id.
5877 * @param subId The subscription that the MmTelFeature is associated with.
5878 * @param callback A callback with an integer containing the
5879 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5880 */
5881 @Override
5882 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5883 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5884 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5885 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5886 "IMS not available on device.");
5887 }
5888 final long token = Binder.clearCallingIdentity();
5889 try {
5890 int slotId = getSlotIndex(subId);
5891 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5892 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5893 + subId + "'");
5894 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5895 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005896 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005897 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5898 try {
5899 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5900 } catch (RemoteException e) {
5901 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5902 + "Ignore");
5903 }
5904 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005905 } catch (ImsException e) {
5906 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005907 } finally {
5908 Binder.restoreCallingIdentity(token);
5909 }
5910 }
5911
Daniel Brightbb5840b2021-01-12 15:48:18 -08005912 /**
5913 * Sets the ims registration state on all valid {@link Phone}s.
5914 */
5915 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005916 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005917
5918 final long identity = Binder.clearCallingIdentity();
5919 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005920 // NOTE: Before S, this method only set the default phone.
5921 for (final Phone phone : PhoneFactory.getPhones()) {
5922 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5923 phone.setImsRegistrationState(registered);
5924 }
5925 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005926 } finally {
5927 Binder.restoreCallingIdentity(identity);
5928 }
Wink Saville36469e72014-06-11 15:17:00 -07005929 }
5930
5931 /**
Stuart Scott54788802015-03-30 13:18:01 -07005932 * Set the network selection mode to automatic.
5933 *
5934 */
5935 @Override
5936 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005937 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5938 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005939
5940 final long identity = Binder.clearCallingIdentity();
5941 try {
shilufc958392020-01-20 11:36:01 -08005942 if (!isActiveSubscription(subId)) {
5943 return;
5944 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005945 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005946 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5947 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005948 } finally {
5949 Binder.restoreCallingIdentity(identity);
5950 }
Stuart Scott54788802015-03-30 13:18:01 -07005951 }
5952
Jack Yud10cdd42020-09-28 20:28:01 -07005953 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005954 * Ask the radio to connect to the input network and change selection mode to manual.
5955 *
5956 * @param subId the id of the subscription.
5957 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5958 * the operator to attach to.
5959 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5960 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5961 * normal network selection next time.
5962 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005963 */
5964 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005965 public boolean setNetworkSelectionModeManual(
5966 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005967 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5968 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005969
5970 if (!isActiveSubscription(subId)) {
5971 return false;
5972 }
5973
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005974 final long identity = Binder.clearCallingIdentity();
5975 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005976 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005977 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005978 if (DBG) {
5979 log("setNetworkSelectionModeManual: subId: " + subId
5980 + " operator: " + operatorInfo);
5981 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005982 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5983 } finally {
5984 Binder.restoreCallingIdentity(identity);
5985 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005986 }
shilu84f6e8b2019-12-19 13:58:01 -08005987 /**
5988 * Get the manual network selection
5989 *
5990 * @param subId the id of the subscription.
5991 *
5992 * @return the previously saved user selected PLMN
5993 */
5994 @Override
5995 public String getManualNetworkSelectionPlmn(int subId) {
5996 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005997 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08005998 mApp, subId, "getManualNetworkSelectionPlmn");
5999
6000 final long identity = Binder.clearCallingIdentity();
6001 try {
6002 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006003 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006004 }
6005
6006 final Phone phone = getPhone(subId);
6007 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006008 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006009 }
6010 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6011 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6012 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6013 } finally {
6014 Binder.restoreCallingIdentity(identity);
6015 }
6016 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006017
6018 /**
6019 * Scans for available networks.
6020 */
6021 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006022 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6023 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006024 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6025 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006026 LocationAccessPolicy.LocationPermissionResult locationResult =
6027 LocationAccessPolicy.checkLocationPermission(mApp,
6028 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6029 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006030 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006031 .setCallingPid(Binder.getCallingPid())
6032 .setCallingUid(Binder.getCallingUid())
6033 .setMethod("getCellNetworkScanResults")
6034 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006035 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6036 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006037 .build());
6038 switch (locationResult) {
6039 case DENIED_HARD:
6040 throw new SecurityException("Not allowed to access scan results -- location");
6041 case DENIED_SOFT:
6042 return null;
6043 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006044
Pengquan Menga1bb6272018-09-06 09:59:22 -07006045 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006046 try {
6047 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006048 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006049 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006050 } finally {
6051 Binder.restoreCallingIdentity(identity);
6052 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006053 }
6054
6055 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006056 * Get the call forwarding info, given the call forwarding reason.
6057 */
6058 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006059 public void getCallForwarding(int subId, int callForwardingReason,
6060 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006061 enforceReadPrivilegedPermission("getCallForwarding");
6062 long identity = Binder.clearCallingIdentity();
6063 try {
6064 if (DBG) {
6065 log("getCallForwarding: subId " + subId
6066 + " callForwardingReason" + callForwardingReason);
6067 }
Hall Liu27d24262020-09-18 19:04:59 -07006068
6069 Phone phone = getPhone(subId);
6070 if (phone == null) {
6071 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006072 callback.onError(
6073 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006074 } catch (RemoteException e) {
6075 // ignore
6076 }
6077 return;
6078 }
6079
6080 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6081 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6082 @Override
6083 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6084 try {
6085 callback.onCallForwardingInfoAvailable(info);
6086 } catch (RemoteException e) {
6087 // ignore
6088 }
6089 }
6090
6091 @Override
6092 public void onError(int error) {
6093 try {
6094 callback.onError(error);
6095 } catch (RemoteException e) {
6096 // ignore
6097 }
6098 }
6099 });
6100 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006101 } finally {
6102 Binder.restoreCallingIdentity(identity);
6103 }
6104 }
6105
6106 /**
6107 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6108 * reason, the number to forward, and the timeout before the forwarding is attempted.
6109 */
6110 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006111 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6112 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006113 enforceModifyPermission();
6114 long identity = Binder.clearCallingIdentity();
6115 try {
6116 if (DBG) {
6117 log("setCallForwarding: subId " + subId
6118 + " callForwardingInfo" + callForwardingInfo);
6119 }
Hall Liu27d24262020-09-18 19:04:59 -07006120
6121 Phone phone = getPhone(subId);
6122 if (phone == null) {
6123 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006124 callback.accept(
6125 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006126 } catch (RemoteException e) {
6127 // ignore
6128 }
6129 return;
6130 }
6131
6132 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6133 FunctionalUtils.ignoreRemoteException(callback::accept));
6134
6135 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006136 } finally {
6137 Binder.restoreCallingIdentity(identity);
6138 }
6139 }
6140
6141 /**
Hall Liu27d24262020-09-18 19:04:59 -07006142 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006143 */
6144 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006145 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006146 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006147 long identity = Binder.clearCallingIdentity();
6148 try {
Hall Liu27d24262020-09-18 19:04:59 -07006149 Phone phone = getPhone(subId);
6150 if (phone == null) {
6151 try {
6152 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6153 } catch (RemoteException e) {
6154 // ignore
6155 }
6156 return;
6157 }
SongFerngWang0e767992021-03-31 22:08:45 +08006158 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6159 PersistableBundle c = configManager.getConfigForSubId(subId);
6160 boolean requireUssd = c.getBoolean(
6161 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006162
Shuo Qian4a594052020-01-23 11:59:30 -08006163 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006164 if (requireUssd) {
6165 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6166 getSubscriptionCarrierId(subId));
6167 String newUssdCommand = "";
6168 try {
6169 newUssdCommand = carrierXmlParser.getFeature(
6170 CarrierXmlParser.FEATURE_CALL_WAITING)
6171 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6172 } catch (NullPointerException e) {
6173 loge("Failed to generate USSD number" + e);
6174 }
6175 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6176 mMainThreadHandler, callback, carrierXmlParser,
6177 CarrierXmlParser.SsEntry.SSAction.QUERY);
6178 final String ussdCommand = newUssdCommand;
6179 Executors.newSingleThreadExecutor().execute(() -> {
6180 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6181 });
6182 } else {
6183 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6184 callback::accept);
6185 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6186 }
Shuo Qian4a594052020-01-23 11:59:30 -08006187 } finally {
6188 Binder.restoreCallingIdentity(identity);
6189 }
6190 }
6191
6192 /**
Hall Liu27d24262020-09-18 19:04:59 -07006193 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006194 */
6195 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006196 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006197 enforceModifyPermission();
6198 long identity = Binder.clearCallingIdentity();
6199 try {
Hall Liu27d24262020-09-18 19:04:59 -07006200 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6201
6202 Phone phone = getPhone(subId);
6203 if (phone == null) {
6204 try {
6205 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6206 } catch (RemoteException e) {
6207 // ignore
6208 }
6209 return;
6210 }
6211
SongFerngWang0e767992021-03-31 22:08:45 +08006212 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6213 PersistableBundle c = configManager.getConfigForSubId(subId);
6214 boolean requireUssd = c.getBoolean(
6215 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006216
SongFerngWang0e767992021-03-31 22:08:45 +08006217 if (DBG) log("getCallWaitingStatus: subId " + subId);
6218 if (requireUssd) {
6219 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6220 getSubscriptionCarrierId(subId));
6221 CarrierXmlParser.SsEntry.SSAction ssAction =
6222 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6223 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6224 String newUssdCommand = "";
6225 try {
6226 newUssdCommand = carrierXmlParser.getFeature(
6227 CarrierXmlParser.FEATURE_CALL_WAITING)
6228 .makeCommand(ssAction, null);
6229 } catch (NullPointerException e) {
6230 loge("Failed to generate USSD number" + e);
6231 }
6232 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6233 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6234 final String ussdCommand = newUssdCommand;
6235 Executors.newSingleThreadExecutor().execute(() -> {
6236 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6237 });
6238 } else {
6239 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6240 FunctionalUtils.ignoreRemoteException(callback::accept));
6241
6242 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6243 }
Shuo Qian4a594052020-01-23 11:59:30 -08006244 } finally {
6245 Binder.restoreCallingIdentity(identity);
6246 }
6247 }
6248
6249 /**
yinxub1bed742017-04-17 11:45:04 -07006250 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006251 *
yinxub1bed742017-04-17 11:45:04 -07006252 * @param subId id of the subscription
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006253 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6254 * location related information which will be sent if the caller already possess
6255 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006256 * @param request contains the radio access networks with bands/channels to scan
6257 * @param messenger callback messenger for scan results or errors
6258 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006259 * @return the id of the requested scan which can be used to stop the scan.
6260 */
6261 @Override
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006262 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6263 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006264 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006265 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6266 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006267 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006268 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6269 if (!renounceFineLocationAccess) {
6270 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6271 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6272 .setCallingPackage(callingPackage)
6273 .setCallingFeatureId(callingFeatureId)
6274 .setCallingPid(Binder.getCallingPid())
6275 .setCallingUid(Binder.getCallingUid())
6276 .setMethod("requestNetworkScan")
6277 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6278 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6279 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6280 .build());
6281 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006282 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006283 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6284 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006285 if (e != null) {
6286 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6287 throw e;
6288 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006289 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006290 return TelephonyScanManager.INVALID_SCAN_ID;
6291 }
6292 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006293 }
Hall Liu912dfd32019-04-25 14:02:26 -07006294 int callingUid = Binder.getCallingUid();
6295 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006296 final long identity = Binder.clearCallingIdentity();
6297 try {
6298 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006299 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006300 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006301 } finally {
6302 Binder.restoreCallingIdentity(identity);
6303 }
yinxu504e1392017-04-12 16:03:22 -07006304 }
6305
Hall Liub2ac8ef2019-02-28 15:56:23 -08006306 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006307 NetworkScanRequest request, int subId, String callingPackage) {
6308 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006309 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6310 boolean hasNetworkScanPermission =
6311 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6312 == PERMISSION_GRANTED;
6313
6314 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6315 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6316 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006317 }
6318
6319 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6320 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006321 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6322 return new SecurityException("Specific channels must not be"
6323 + " scanned without location access.");
6324 }
6325 }
6326 }
6327
Hall Liub2ac8ef2019-02-28 15:56:23 -08006328 return null;
6329 }
6330
yinxu504e1392017-04-12 16:03:22 -07006331 /**
6332 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006333 *
6334 * @param subId id of the subscription
6335 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006336 */
6337 @Override
6338 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006339 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6340 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006341
Hall Liu912dfd32019-04-25 14:02:26 -07006342 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006343 final long identity = Binder.clearCallingIdentity();
6344 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006345 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006346 } finally {
6347 Binder.restoreCallingIdentity(identity);
6348 }
yinxu504e1392017-04-12 16:03:22 -07006349 }
6350
6351 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006352 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006353 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006354 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006355 */
6356 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006357 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006358 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006359 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006360 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006361
6362 final long identity = Binder.clearCallingIdentity();
6363 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006364 if (DBG) log("getAllowedNetworkTypesBitmask");
6365 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6366 int networkTypesBitmask = (result != null ? result[0] : -1);
6367 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6368 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006369 } finally {
6370 Binder.restoreCallingIdentity(identity);
6371 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006372 }
6373
6374 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006375 * Get the allowed network types for certain reason.
6376 *
6377 * @param subId the id of the subscription.
6378 * @param reason the reason the allowed network type change is taking place
6379 * @return the allowed network types.
6380 */
6381 @Override
6382 public long getAllowedNetworkTypesForReason(int subId,
6383 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006384 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006385 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006386 final long identity = Binder.clearCallingIdentity();
6387 try {
6388 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6389 } finally {
6390 Binder.restoreCallingIdentity(identity);
6391 }
6392 }
6393
6394 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006395 * Enable/Disable E-UTRA-NR Dual Connectivity
6396 * @param subId subscription id of the sim card
6397 * @param nrDualConnectivityState expected NR dual connectivity state
6398 * This can be passed following states
6399 * <ol>
6400 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6401 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6402 * <li>Disable NR dual connectivity and force secondary cell to be released
6403 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6404 * </ol>
6405 * @return operation result.
6406 */
6407 @Override
6408 public int setNrDualConnectivityState(int subId,
6409 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6410 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6411 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006412 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006413 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6414 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6415 }
6416
Sooraj Sasindran37444802020-08-11 10:40:43 -07006417 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6418 final long identity = Binder.clearCallingIdentity();
6419 try {
6420 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6421 nrDualConnectivityState, subId,
6422 workSource);
6423 if (DBG) log("enableNRDualConnectivity result: " + result);
6424 return result;
6425 } finally {
6426 Binder.restoreCallingIdentity(identity);
6427 }
6428 }
6429
6430 /**
6431 * Is E-UTRA-NR Dual Connectivity enabled
6432 * @return true if dual connectivity is enabled else false
6433 */
6434 @Override
6435 public boolean isNrDualConnectivityEnabled(int subId) {
6436 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006437 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006438 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006439 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006440 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6441 return false;
6442 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006443 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6444 final long identity = Binder.clearCallingIdentity();
6445 try {
6446 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6447 null, subId, workSource);
6448 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6449 return isEnabled;
6450 } finally {
6451 Binder.restoreCallingIdentity(identity);
6452 }
6453 }
6454
6455 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006456 * Set the allowed network types of the device and
6457 * provide the reason triggering the allowed network change.
6458 *
6459 * @param subId the id of the subscription.
6460 * @param reason the reason the allowed network type change is taking place
6461 * @param allowedNetworkTypes the allowed network types.
6462 * @return true on success; false on any failure.
6463 */
6464 @Override
6465 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006466 @TelephonyManager.AllowedNetworkTypesReason int reason,
6467 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006468 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6469 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006470 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006471 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6472 return false;
6473 }
6474 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6475 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006476 return false;
6477 }
6478
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006479 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6480 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6481
6482
6483 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6484 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6485 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006486 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006487
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006488 final long identity = Binder.clearCallingIdentity();
6489 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006490 Boolean success = (Boolean) sendRequest(
6491 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6492 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6493
6494 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6495 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006496 } finally {
6497 Binder.restoreCallingIdentity(identity);
6498 }
6499 }
6500
6501 /**
Miaoa84611c2019-03-15 09:21:10 +08006502 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006503 *
Miaoa84611c2019-03-15 09:21:10 +08006504 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006505 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006506 * @hide
6507 */
6508 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006509 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006510 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006511 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006512 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006513 try {
Miaoa84611c2019-03-15 09:21:10 +08006514 if (phone != null) {
6515 return phone.hasMatchedTetherApnSetting();
6516 } else {
6517 return false;
6518 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006519 } finally {
6520 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006521 }
Junda Liu475951f2014-11-07 16:45:03 -08006522 }
6523
6524 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006525 * Get the user enabled state of Mobile Data.
6526 *
6527 * TODO: remove and use isUserDataEnabled.
6528 * This can't be removed now because some vendor codes
6529 * calls through ITelephony directly while they should
6530 * use TelephonyManager.
6531 *
6532 * @return true on enabled
6533 */
6534 @Override
6535 public boolean getDataEnabled(int subId) {
6536 return isUserDataEnabled(subId);
6537 }
6538
6539 /**
6540 * Get whether mobile data is enabled per user setting.
6541 *
6542 * There are other factors deciding whether mobile data is actually enabled, but they are
6543 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006544 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006545 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6546 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006547 *
6548 * @return {@code true} if data is enabled else {@code false}
6549 */
6550 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006551 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006552 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006553 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006554 try {
6555 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6556 functionName);
6557 } catch (Exception e) {
6558 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6559 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006560 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006561 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006562 mApp, subId, functionName);
6563
Robert Greenwalt646120a2014-05-23 11:54:03 -07006564 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006565
6566 final long identity = Binder.clearCallingIdentity();
6567 try {
6568 int phoneId = mSubscriptionController.getPhoneId(subId);
6569 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6570 Phone phone = PhoneFactory.getPhone(phoneId);
6571 if (phone != null) {
6572 boolean retVal = phone.isUserDataEnabled();
6573 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6574 return retVal;
6575 } else {
6576 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6577 return false;
6578 }
6579 } finally {
6580 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006581 }
6582 }
6583
6584 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006585 * Checks if the device is capable of mobile data by considering whether whether the
6586 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6587 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006588 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006589 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006590 */
6591 @Override
6592 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006593 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006594 try {
6595 try {
6596 mApp.enforceCallingOrSelfPermission(
6597 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006598 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006599 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006600 try {
6601 mApp.enforceCallingOrSelfPermission(
6602 android.Manifest.permission.READ_PHONE_STATE,
6603 functionName);
6604 } catch (Exception e2) {
6605 mApp.enforceCallingOrSelfPermission(
6606 permission.READ_BASIC_PHONE_STATE, functionName);
6607 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006608 }
6609 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006610 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006611 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006612
6613 final long identity = Binder.clearCallingIdentity();
6614 try {
6615 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006616 Phone phone = PhoneFactory.getPhone(phoneId);
6617 if (phone != null) {
Jack Yu3fb3a6b2021-12-03 14:23:53 -08006618 boolean retVal;
6619 if (phone.isUsingNewDataStack()) {
Sarah Chin8619e162022-03-09 13:57:52 -08006620 retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu3fb3a6b2021-12-03 14:23:53 -08006621 } else {
6622 retVal = phone.getDataEnabledSettings().isDataEnabled();
6623 }
6624 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006625 return retVal;
6626 } else {
6627 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6628 return false;
6629 }
6630 } finally {
6631 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006632 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006633 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006634
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006635 /**
6636 * Check if data is enabled for a specific reason
6637 * @param subId Subscription index
6638 * @param reason the reason the data enable change is taking place
6639 * @return {@code true} if the overall data is enabled; {@code false} if not.
6640 */
6641 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006642 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006643 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006644 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006645 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006646 try {
6647 mApp.enforceCallingOrSelfPermission(
6648 android.Manifest.permission.ACCESS_NETWORK_STATE,
6649 functionName);
6650 } catch (Exception e) {
6651 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6652 functionName);
6653 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006654 } catch (Exception e) {
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006655 try {
6656 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006657 functionName);
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006658 } catch (Exception e2) {
6659 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006660 mApp, subId, functionName);
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006661 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006662 }
6663
6664
6665 final long identity = Binder.clearCallingIdentity();
6666 try {
6667 int phoneId = mSubscriptionController.getPhoneId(subId);
6668 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006669 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006670 + " reason=" + reason);
6671 }
6672 Phone phone = PhoneFactory.getPhone(phoneId);
6673 if (phone != null) {
6674 boolean retVal;
Jack Yu6bc9c8b2021-12-17 23:14:15 -08006675 if (phone.isUsingNewDataStack()) {
6676 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006677 } else {
Jack Yu6bc9c8b2021-12-17 23:14:15 -08006678 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6679 retVal = phone.isUserDataEnabled();
6680 } else {
6681 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
6682 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006683 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006684 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006685 return retVal;
6686 } else {
6687 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006688 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006689 + subId + " retVal=false");
6690 }
6691 return false;
6692 }
6693 } finally {
6694 Binder.restoreCallingIdentity(identity);
6695 }
6696 }
6697
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006698 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006699 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006700 // No permission needed; this only lets the caller inspect their own status.
6701 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006702 }
Junda Liu29340342014-07-10 15:23:27 -07006703
6704 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006705 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006706 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006707 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6708 }
6709
6710 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6711 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006712 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006713 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006714 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6715 }
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006716 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6717 if (cpt == null) {
6718 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006719 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6720 }
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006721 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006722 }
6723
6724 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006725 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006726 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006727 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006728 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006729 }
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006730 Phone phone = getPhone(subId);
6731 if (phone == null) {
6732 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6733 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6734 }
6735 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6736 if (cpt == null) {
6737 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006738 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6739 }
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006740 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006741 }
6742
6743 @Override
6744 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006745 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
6746 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006747 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006748 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006749 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006750 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6751 Phone phone = PhoneFactory.getPhone(phoneId);
6752 if (phone == null) {
6753 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006754 }
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006755 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6756 if (cpt == null) {
6757 continue;
6758 }
6759 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006760 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6761 break;
6762 }
6763 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006764 return result;
Junda Liu29340342014-07-10 15:23:27 -07006765 }
Derek Tan89e89d42014-07-08 17:00:10 -07006766
6767 @Override
Junda Liue64de782015-04-16 17:19:16 -07006768 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006769 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Hunter Knepshieldb0eb4792021-12-14 18:49:15 -08006770 Phone phone = PhoneFactory.getPhone(phoneId);
6771 if (phone == null) {
6772 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006773 }
Hunter Knepshieldb0eb4792021-12-14 18:49:15 -08006774 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6775 if (cpt == null) {
6776 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006777 }
Hunter Knepshieldb0eb4792021-12-14 18:49:15 -08006778 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006779 }
6780
Amith Yamasani6e118872016-02-19 12:53:51 -08006781 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006782 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006783 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006784 Phone phone = PhoneFactory.getPhone(phoneId);
6785 if (phone == null) {
6786 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006787 }
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006788 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6789 if (cpt == null) {
6790 return Collections.emptyList();
6791 }
6792 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006793 }
6794
chen xuf7e9fe82019-05-09 19:31:02 -07006795 @Override
6796 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006797 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006798 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006799 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00006800 try {
6801 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6802 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6803 }
6804 } finally {
6805 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006806 }
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08006807 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07006808 }
6809
Rambo Wang9b91ffd2022-03-15 16:54:17 -07006810 @Override
6811 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
6812 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
6813
6814 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
6815 if (phone == null) {
6816 return null;
6817 }
6818 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6819 if (cpt == null) {
6820 return null;
6821 }
6822 return cpt.getCarrierServicePackageName();
6823 }
6824
Wink Savilleb564aae2014-10-23 10:18:09 -07006825 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006826 final Phone phone = getPhone(subId);
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006827 UiccPort port = phone == null ? null : phone.getUiccPort();
6828 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006829 return null;
6830 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006831 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006832 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006833 return null;
6834 }
6835 return iccId;
6836 }
6837
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006838 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006839 public void setCallComposerStatus(int subId, int status) {
6840 enforceModifyPermission();
6841
6842 final long identity = Binder.clearCallingIdentity();
6843 try {
6844 Phone phone = getPhone(subId);
6845 if (phone != null) {
6846 Phone defaultPhone = phone.getImsPhone();
6847 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6848 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6849 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006850 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6851 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006852 }
6853 }
Shuo Qian284ae752020-12-22 19:10:14 -08006854 } catch (ImsException e) {
6855 throw new ServiceSpecificException(e.getCode());
6856 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006857 Binder.restoreCallingIdentity(identity);
6858 }
6859 }
6860
6861 @Override
6862 public int getCallComposerStatus(int subId) {
6863 enforceReadPrivilegedPermission("getCallComposerStatus");
6864
6865 final long identity = Binder.clearCallingIdentity();
6866 try {
6867 Phone phone = getPhone(subId);
6868 if (phone != null) {
6869 Phone defaultPhone = phone.getImsPhone();
6870 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6871 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6872 return imsPhone.getCallComposerStatus();
6873 }
6874 }
6875 } finally {
6876 Binder.restoreCallingIdentity(identity);
6877 }
6878 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6879 }
6880
6881 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006882 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6883 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006884 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006885 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006886
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006887 final long identity = Binder.clearCallingIdentity();
6888 try {
6889 final String iccId = getIccId(subId);
6890 final Phone phone = getPhone(subId);
6891 if (phone == null) {
6892 return false;
6893 }
6894 final String subscriberId = phone.getSubscriberId();
6895
6896 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006897 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006898 + subscriberId + " to " + number);
6899 }
6900
6901 if (TextUtils.isEmpty(iccId)) {
6902 return false;
6903 }
6904
6905 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6906
6907 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6908 if (alphaTag == null) {
6909 editor.remove(alphaTagPrefKey);
6910 } else {
6911 editor.putString(alphaTagPrefKey, alphaTag);
6912 }
6913
6914 // Record both the line number and IMSI for this ICCID, since we need to
6915 // track all merged IMSIs based on line number
6916 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6917 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6918 if (number == null) {
6919 editor.remove(numberPrefKey);
6920 editor.remove(subscriberPrefKey);
6921 } else {
6922 editor.putString(numberPrefKey, number);
6923 editor.putString(subscriberPrefKey, subscriberId);
6924 }
6925
6926 editor.commit();
6927 return true;
6928 } finally {
6929 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006930 }
Derek Tan7226c842014-07-02 17:42:23 -07006931 }
6932
6933 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006934 public String getLine1NumberForDisplay(int subId, String callingPackage,
6935 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006936 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006937 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006938 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006939 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006940 return null;
6941 }
Derek Tan97ebb422014-09-05 16:55:38 -07006942
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006943 final long identity = Binder.clearCallingIdentity();
6944 try {
6945 String iccId = getIccId(subId);
6946 if (iccId != null) {
6947 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6948 if (DBG_MERGE) {
6949 log("getLine1NumberForDisplay returning "
6950 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6951 }
6952 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006953 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006954 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6955 return null;
6956 } finally {
6957 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006958 }
Derek Tan7226c842014-07-02 17:42:23 -07006959 }
6960
6961 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006962 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6963 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006964 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006965 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006966 return null;
6967 }
Derek Tan97ebb422014-09-05 16:55:38 -07006968
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006969 final long identity = Binder.clearCallingIdentity();
6970 try {
6971 String iccId = getIccId(subId);
6972 if (iccId != null) {
6973 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6974 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6975 }
6976 return null;
6977 } finally {
6978 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006979 }
Derek Tan7226c842014-07-02 17:42:23 -07006980 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006981
6982 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006983 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6984 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006985 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6986 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006987 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006988 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006989 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006990 return null;
6991 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006992
Jordan Liub49b04b2019-05-06 14:45:15 -07006993 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6994 // the process, where TelephonyManager was instantiated.
6995 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006996 final long identity = Binder.clearCallingIdentity();
6997 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006998 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006999 final TelephonyManager tele = TelephonyManager.from(context);
7000 final SubscriptionManager sub = SubscriptionManager.from(context);
7001
7002 // Figure out what subscribers are currently active
7003 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007004
Jordan Liub49b04b2019-05-06 14:45:15 -07007005 // Only consider subs which match the current subId
7006 // This logic can be simplified. See b/131189269 for progress.
7007 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007008 activeSubscriberIds.add(tele.getSubscriberId(subId));
7009 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007010
7011 // First pass, find a number override for an active subscriber
7012 String mergeNumber = null;
7013 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7014 for (String key : prefs.keySet()) {
7015 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7016 final String subscriberId = (String) prefs.get(key);
7017 if (activeSubscriberIds.contains(subscriberId)) {
7018 final String iccId = key.substring(
7019 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7020 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7021 mergeNumber = (String) prefs.get(numberKey);
7022 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007023 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007024 + " for active subscriber " + subscriberId);
7025 }
7026 if (!TextUtils.isEmpty(mergeNumber)) {
7027 break;
7028 }
7029 }
7030 }
7031 }
7032
7033 // Shortcut when no active merged subscribers
7034 if (TextUtils.isEmpty(mergeNumber)) {
7035 return null;
7036 }
7037
7038 // Second pass, find all subscribers under that line override
7039 final ArraySet<String> result = new ArraySet<>();
7040 for (String key : prefs.keySet()) {
7041 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7042 final String number = (String) prefs.get(key);
7043 if (mergeNumber.equals(number)) {
7044 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7045 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7046 final String subscriberId = (String) prefs.get(subscriberKey);
7047 if (!TextUtils.isEmpty(subscriberId)) {
7048 result.add(subscriberId);
7049 }
7050 }
7051 }
7052 }
7053
7054 final String[] resultArray = result.toArray(new String[result.size()]);
7055 Arrays.sort(resultArray);
7056 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007057 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007058 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7059 }
7060 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007061 } finally {
7062 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007063 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007064 }
7065
7066 @Override
zoey chen38003472019-12-13 17:16:31 +08007067 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7068 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007069
7070 final long identity = Binder.clearCallingIdentity();
7071 try {
7072 final TelephonyManager telephonyManager = mApp.getSystemService(
7073 TelephonyManager.class);
7074 String subscriberId = telephonyManager.getSubscriberId(subId);
7075 if (subscriberId == null) {
7076 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007077 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007078 + subId);
7079 }
7080 return null;
7081 }
7082
7083 final SubscriptionInfo info = SubscriptionController.getInstance()
7084 .getSubscriptionInfo(subId);
7085 final ParcelUuid groupUuid = info.getGroupUuid();
7086 // If it doesn't belong to any group, return just subscriberId of itself.
7087 if (groupUuid == null) {
7088 return new String[]{subscriberId};
7089 }
7090
7091 // Get all subscriberIds from the group.
7092 final List<String> mergedSubscriberIds = new ArrayList<>();
7093 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007094 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007095 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007096 for (SubscriptionInfo subInfo : groupInfos) {
7097 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7098 if (subscriberId != null) {
7099 mergedSubscriberIds.add(subscriberId);
7100 }
7101 }
7102
7103 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7104 } finally {
7105 Binder.restoreCallingIdentity(identity);
7106
7107 }
7108 }
7109
7110 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007111 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007112 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007113 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007114
7115 final long identity = Binder.clearCallingIdentity();
7116 try {
7117 final Phone phone = getPhone(subId);
7118 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7119 } finally {
7120 Binder.restoreCallingIdentity(identity);
7121 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007122 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007123
7124 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007125 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007126 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7127 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007128 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7129 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007130
7131 final long identity = Binder.clearCallingIdentity();
7132 try {
7133 final Phone phone = getPhone(subId);
7134 if (phone == null) {
7135 return false;
7136 }
7137 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7138 cdmaNonRoamingList);
7139 } finally {
7140 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007141 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007142 }
7143
7144 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007145 @Deprecated
7146 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7147 enforceModifyPermission();
7148
7149 int returnValue = 0;
7150 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007151 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007152 if(result.exception == null) {
7153 if (result.result != null) {
7154 byte[] responseData = (byte[])(result.result);
7155 if(responseData.length > oemResp.length) {
7156 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7157 responseData.length + "bytes. Buffer Size is " +
7158 oemResp.length + "bytes.");
7159 }
7160 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7161 returnValue = responseData.length;
7162 }
7163 } else {
7164 CommandException ex = (CommandException) result.exception;
7165 returnValue = ex.getCommandError().ordinal();
7166 if(returnValue > 0) returnValue *= -1;
7167 }
7168 } catch (RuntimeException e) {
7169 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7170 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7171 if(returnValue > 0) returnValue *= -1;
7172 }
7173
7174 return returnValue;
7175 }
7176
7177 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007178 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007179 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007180 try {
7181 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007182 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007183 mApp, phone.getSubId(), "getRadioAccessFamily");
7184 } catch (SecurityException e) {
7185 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7186 throw e;
7187 }
chen xub97461a2018-10-26 14:17:57 -07007188 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007189 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007190 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007191 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007192 final long identity = Binder.clearCallingIdentity();
7193 try {
chen xub97461a2018-10-26 14:17:57 -07007194 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007195 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007196 mApp, phone.getSubId(), "getRadioAccessFamily");
7197 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007198 } finally {
7199 Binder.restoreCallingIdentity(identity);
7200 }
chen xub97461a2018-10-26 14:17:57 -07007201 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007202 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007203
7204 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007205 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007206 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007207 try {
7208 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7209 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007210 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007211 }
7212 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007213 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007214 }
7215 RoleManager rm = mApp.getSystemService(RoleManager.class);
7216 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7217 if (!dialerRoleHolders.contains(callingPackage)) {
7218 throw new SecurityException("App must be the dialer role holder to"
7219 + " upload a call composer pic");
7220 }
7221
7222 Executors.newSingleThreadExecutor().execute(() -> {
7223 ByteArrayOutputStream output = new ByteArrayOutputStream(
7224 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7225 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7226 boolean readUntilEnd = false;
7227 int totalBytesRead = 0;
7228 byte[] buffer = new byte[16 * 1024];
7229 while (true) {
7230 int numRead;
7231 try {
7232 numRead = input.read(buffer);
7233 } catch (IOException e) {
7234 try {
7235 fd.checkError();
7236 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7237 null);
7238 } catch (IOException e1) {
7239 // This means that the other side closed explicitly with an error. If this
7240 // happens, log and ignore.
7241 loge("Remote end of call composer picture pipe closed: " + e1);
7242 }
7243 break;
7244 }
7245 if (numRead == -1) {
7246 readUntilEnd = true;
7247 break;
7248 }
7249 totalBytesRead += numRead;
7250 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7251 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7252 try {
7253 input.close();
7254 } catch (IOException e) {
7255 // ignore
7256 }
7257 break;
7258 }
7259 output.write(buffer, 0, numRead);
7260 }
7261 // Generally, the remote end will close the file descriptors. The only case where we
7262 // close is above, where the picture size is too big.
7263
7264 try {
7265 fd.checkError();
7266 } catch (IOException e) {
7267 loge("Remote end for call composer closed with an error: " + e);
7268 return;
7269 }
7270
Hall Liuaa4211e2021-01-20 15:43:39 -08007271 if (!readUntilEnd) {
7272 loge("Did not finish reading entire image; aborting");
7273 return;
7274 }
Hall Liu82694d52020-12-11 18:22:04 -08007275
Hall Liuaa4211e2021-01-20 15:43:39 -08007276 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7277 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7278 new CallComposerPictureTransfer.Factory() {},
7279 imageData,
7280 (result) -> {
7281 if (result.first != null) {
7282 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7283 Bundle outputResult = new Bundle();
7284 outputResult.putParcelable(
7285 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7286 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7287 outputResult);
7288 } else {
7289 callback.send(result.second, null);
7290 }
7291 }
7292 );
Hall Liu82694d52020-12-11 18:22:04 -08007293 });
7294 }
7295
7296 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007297 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007298 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007299 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007300
7301 final long identity = Binder.clearCallingIdentity();
7302 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007303 ImsManager.getInstance(defaultPhone.getContext(),
7304 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007305 } finally {
7306 Binder.restoreCallingIdentity(identity);
7307 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007308 }
7309
7310 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007311 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007312 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007313 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7314 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007315 return false;
7316 }
Svet Ganovb320e182015-04-16 12:30:10 -07007317
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007318 final long identity = Binder.clearCallingIdentity();
7319 try {
7320 // Check the user preference and the system-level IMS setting. Even if the user has
7321 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7322 // In the long run, we may instead need to check if there exists a connection service
7323 // which can support video calling.
7324 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007325 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007326 return imsManager.isVtEnabledByPlatform()
7327 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7328 && imsManager.isVtEnabledByUser();
7329 } finally {
7330 Binder.restoreCallingIdentity(identity);
7331 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007332 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007333
Andrew Leea1239f22015-03-02 17:44:07 -08007334 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007335 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7336 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007337 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007338 mApp, subId, callingPackage, callingFeatureId,
7339 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007340 return false;
7341 }
7342
7343 final long identity = Binder.clearCallingIdentity();
7344 try {
7345 CarrierConfigManager configManager =
7346 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007347 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007348 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7349 } finally {
7350 Binder.restoreCallingIdentity(identity);
7351 }
Andrew Leea1239f22015-03-02 17:44:07 -08007352 }
7353
7354 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007355 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007356 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007357 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007358 return false;
7359 }
7360
7361 final long identity = Binder.clearCallingIdentity();
7362 try {
7363 CarrierConfigManager configManager =
7364 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007365 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007366 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7367 } finally {
7368 Binder.restoreCallingIdentity(identity);
7369 }
Andrew Leea1239f22015-03-02 17:44:07 -08007370 }
7371
Andrew Lee9431b832015-03-09 18:46:45 -07007372 @Override
7373 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007374 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007375 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007376 }
7377
7378 @Override
7379 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007380 final long identity = Binder.clearCallingIdentity();
7381 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007382 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007383 } finally {
7384 Binder.restoreCallingIdentity(identity);
7385 }
Andrew Lee9431b832015-03-09 18:46:45 -07007386 }
7387
Hall Liuf6668912018-10-31 17:05:23 -07007388 /**
7389 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7390 * support for the feature and device firmware support.
7391 *
7392 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7393 */
7394 @Override
7395 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007396 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007397 final Phone phone = getPhone(subscriptionId);
7398 if (phone == null) {
7399 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7400 return false;
7401 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007402 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007403 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007404 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7405 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007406 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007407 return isCarrierSupported && isDeviceSupported;
7408 } finally {
7409 Binder.restoreCallingIdentity(identity);
7410 }
Hall Liu98187582018-01-22 19:15:32 -08007411 }
7412
Hall Liuf6668912018-10-31 17:05:23 -07007413 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007414 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7415 * RTT setting, will return true if the device and carrier both support RTT.
7416 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007417 */
7418 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007419 final long identity = Binder.clearCallingIdentity();
7420 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007421 boolean isRttSupported = isRttSupported(subscriptionId);
7422 boolean isUserRttSettingOn = Settings.Secure.getInt(
7423 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7424 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7425 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7426 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007427 } finally {
7428 Binder.restoreCallingIdentity(identity);
7429 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007430 }
7431
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007432 @Deprecated
7433 @Override
7434 public String getDeviceId(String callingPackage) {
7435 return getDeviceIdWithFeature(callingPackage, null);
7436 }
7437
Sanket Padawe7310cc72015-01-14 09:53:20 -08007438 /**
7439 * Returns the unique device ID of phone, for example, the IMEI for
7440 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7441 *
7442 * <p>Requires Permission:
7443 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7444 */
7445 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007446 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007447 try {
7448 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7449 } catch (SecurityException se) {
7450 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7451 throw new SecurityException("Package " + callingPackage + " does not belong to "
7452 + Binder.getCallingUid());
7453 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007454 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007455 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007456 return null;
7457 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007458 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007459 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007460 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007461 return null;
7462 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007463
7464 final long identity = Binder.clearCallingIdentity();
7465 try {
7466 return phone.getDeviceId();
7467 } finally {
7468 Binder.restoreCallingIdentity(identity);
7469 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007470 }
7471
Ping Sunc67b7c22016-03-02 19:16:45 +08007472 /**
7473 * {@hide}
7474 * Returns the IMS Registration Status on a particular subid
7475 *
7476 * @param subId
7477 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007478 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007479 Phone phone = getPhone(subId);
7480 if (phone != null) {
7481 return phone.isImsRegistered();
7482 } else {
7483 return false;
7484 }
7485 }
7486
Santos Cordon7a1885b2015-02-03 11:15:19 -08007487 @Override
7488 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007489 final long identity = Binder.clearCallingIdentity();
7490 try {
7491 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7492 } finally {
7493 Binder.restoreCallingIdentity(identity);
7494 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007495 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007496
Tyler Gunnf70ed162019-04-03 15:28:53 -07007497 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007498 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007499 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007500 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007501 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007502 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7503 }
7504 final long identity = Binder.clearCallingIdentity();
7505 try {
7506 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7507 } finally {
7508 Binder.restoreCallingIdentity(identity);
7509 }
7510 }
7511
7512 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007513 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007514 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007515 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007516 mApp,
7517 subscriptionId,
7518 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007519 final long identity = Binder.clearCallingIdentity();
7520 try {
7521 Phone phone = getPhone(subscriptionId);
7522 if (phone == null) {
7523 return null;
7524 }
7525 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7526 } finally {
7527 Binder.restoreCallingIdentity(identity);
7528 }
7529 }
7530
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007531 /**
7532 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007533 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007534 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007535 final long identity = Binder.clearCallingIdentity();
7536 try {
7537 Phone phone = getPhone(subId);
7538 if (phone != null) {
7539 return phone.isWifiCallingEnabled();
7540 } else {
7541 return false;
7542 }
7543 } finally {
7544 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007545 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007546 }
7547
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007548 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007549 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007550 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007551 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007552 final long identity = Binder.clearCallingIdentity();
7553 try {
7554 Phone phone = getPhone(subId);
7555 if (phone != null) {
7556 return phone.isVideoEnabled();
7557 } else {
7558 return false;
7559 }
7560 } finally {
7561 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007562 }
7563 }
7564
7565 /**
7566 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7567 * defined in {@link ImsRegistrationImplBase}.
7568 */
7569 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007570 final long identity = Binder.clearCallingIdentity();
7571 try {
7572 Phone phone = getPhone(subId);
7573 if (phone != null) {
7574 return phone.getImsRegistrationTech();
7575 } else {
7576 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7577 }
7578 } finally {
7579 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007580 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007581 }
7582
Stuart Scott8eef64f2015-04-08 15:13:54 -07007583 @Override
7584 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007585 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007586 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7587 return;
7588 }
Kai Shif70f46f2021-03-03 13:59:46 -08007589 Phone defaultPhone = getDefaultPhone();
7590 if (defaultPhone != null) {
7591 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7592 mApp, getDefaultPhone().getSubId(), "factoryReset");
7593 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007594 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007595
Svet Ganovcc087f82015-05-12 20:35:54 -07007596 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007597 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7598 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007599 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007600 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007601 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007602 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007603 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007604 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007605 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007606 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007607 // There has been issues when Sms raw table somehow stores orphan
7608 // fragments. They lead to garbled message when new fragments come
7609 // in and combined with those stale ones. In case this happens again,
7610 // user can reset all network settings which will clean up this table.
7611 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007612 // Clean up IMS settings as well here.
7613 int slotId = getSlotIndex(subId);
7614 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7615 ImsManager.getInstance(mApp, slotId).factoryReset();
7616 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007617
Kai Shif70f46f2021-03-03 13:59:46 -08007618 if (defaultPhone == null) {
7619 return;
7620 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007621 // Erase modem config if erase modem on network setting is enabled.
7622 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7623 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7624 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007625 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007626 }
Kai Shif70f46f2021-03-03 13:59:46 -08007627
7628 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007629 } finally {
7630 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007631 }
7632 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007633
SongFerngWangfd89b102021-05-27 22:44:54 +08007634 @VisibleForTesting
7635 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7636 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7637 return;
7638 }
7639 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7640 RILConstants.PREFERRED_NETWORK_MODE);
7641 SubscriptionManager.setSubscriptionProperty(subId,
7642 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7643 "user=" + defaultNetworkType);
7644 phone.loadAllowedNetworksFromSubscriptionDatabase();
7645 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7646 defaultNetworkType, null);
7647 }
7648
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007649 private void cleanUpSmsRawTable(Context context) {
7650 ContentResolver resolver = context.getContentResolver();
7651 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7652 resolver.delete(uri, null, null);
7653 }
7654
Narayan Kamath1c496c22015-04-16 14:40:19 +01007655 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007656 public String getSimLocaleForSubscriber(int subId) {
7657 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7658 final Phone phone = getPhone(subId);
7659 if (phone == null) {
7660 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007661 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007662 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007663 final long identity = Binder.clearCallingIdentity();
7664 try {
chen xu5d3637b2019-01-21 23:31:38 -08007665 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007666 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007667 if (info == null) {
7668 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7669 return null;
7670 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007671 // Try and fetch the locale from the carrier properties or from the SIM language
7672 // preferences (EF-PL and EF-LI)...
7673 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007674 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007675 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7676 if (localeFromDefaultSim != null) {
7677 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7678 if (DBG) log("Using locale from subId: " + subId + " locale: "
7679 + localeFromDefaultSim);
7680 return localeFromDefaultSim.toLanguageTag();
7681 } else {
7682 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007683 }
7684 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007685
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007686 // The SIM language preferences only store a language (e.g. fr = French), not an
7687 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7688 // the SIM and carrier preferences does not include a country we add the country
7689 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007690 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007691 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007692 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007693 return mccLocale.toLanguageTag();
7694 }
7695
7696 if (DBG) log("No locale found - returning null");
7697 return null;
7698 } finally {
7699 Binder.restoreCallingIdentity(identity);
7700 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007701 }
7702
7703 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007704 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007705 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007706 }
7707
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007708 /**
7709 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7710 */
7711 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007712 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007713 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007714 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007715
Chenjie Yu1ba97252018-01-11 18:16:20 -08007716 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007717 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007718
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007719 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007720 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7721 * representing the state of the modem.
7722 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007723 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7724 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007725 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007726 */
7727 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007728 public void requestModemActivityInfo(ResultReceiver result) {
7729 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007730 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007731
7732 final long identity = Binder.clearCallingIdentity();
7733 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007734 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007735 } finally {
7736 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007737 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007738 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007739
Siddharth Rayb8114062018-06-17 15:02:38 -07007740 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7741 // less than total activity duration.
7742 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7743 if (info == null) {
7744 return false;
7745 }
7746 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007747 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7748 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7749
Siddharth Rayb8114062018-06-17 15:02:38 -07007750 return (info.isValid()
7751 && (info.getSleepTimeMillis() <= activityDurationMs)
7752 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007753 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007754 && (totalTxTimeMs <= activityDurationMs));
7755 }
7756
Jack Yu85bd38a2015-11-09 11:34:32 -08007757 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007758 * Returns the service state information on specified subscription.
7759 */
7760 @Override
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007761 public ServiceState getServiceStateForSubscriber(int subId,
7762 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7763 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007764 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007765 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007766 return null;
7767 }
7768
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007769 boolean hasFinePermission = false;
7770 boolean hasCoarsePermission = false;
7771 if (!renounceFineLocationAccess) {
7772 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7773 LocationAccessPolicy.checkLocationPermission(mApp,
7774 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7775 .setCallingPackage(callingPackage)
7776 .setCallingFeatureId(callingFeatureId)
7777 .setCallingPid(Binder.getCallingPid())
7778 .setCallingUid(Binder.getCallingUid())
7779 .setMethod("getServiceStateForSubscriber")
7780 .setLogAsInfo(true)
7781 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7782 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7783 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7784 .build());
7785 hasFinePermission =
7786 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7787 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007788
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007789 if (!renounceCoarseLocationAccess) {
7790 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7791 LocationAccessPolicy.checkLocationPermission(mApp,
7792 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7793 .setCallingPackage(callingPackage)
7794 .setCallingFeatureId(callingFeatureId)
7795 .setCallingPid(Binder.getCallingPid())
7796 .setCallingUid(Binder.getCallingUid())
7797 .setMethod("getServiceStateForSubscriber")
7798 .setLogAsInfo(true)
7799 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7800 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7801 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7802 .build());
7803 hasCoarsePermission =
7804 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7805 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007806
Jack Yu479f40e2020-10-27 21:29:25 -07007807 final Phone phone = getPhone(subId);
7808 if (phone == null) {
7809 return null;
7810 }
7811
Jordan Liu0f2bc442020-11-18 16:47:37 -08007812 final long identity = Binder.clearCallingIdentity();
7813
Jack Yu479f40e2020-10-27 21:29:25 -07007814 boolean isCallingPackageDataService = phone.getDataServicePackages()
7815 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007816 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007817 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7818 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7819 Rlog.d(LOG_TAG,
7820 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7821 return null;
7822 }
7823
Hall Liuf19c44f2018-11-27 14:38:17 -08007824 ServiceState ss = phone.getServiceState();
7825
7826 // Scrub out the location info in ServiceState depending on what level of access
7827 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007828 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007829 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7830 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007831 } finally {
7832 Binder.restoreCallingIdentity(identity);
7833 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007834 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007835
7836 /**
7837 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7838 *
7839 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7840 * voicemail ringtone.
7841 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7842 * PhoneAccount.
7843 */
7844 @Override
7845 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007846 final long identity = Binder.clearCallingIdentity();
7847 try {
7848 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7849 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007850 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007851 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007852
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007853 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7854 } finally {
7855 Binder.restoreCallingIdentity(identity);
7856 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007857 }
7858
7859 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007860 * Sets the per-account voicemail ringtone.
7861 *
7862 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7863 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7864 *
7865 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7866 * voicemail ringtone.
7867 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7868 * PhoneAccount.
7869 */
7870 @Override
7871 public void setVoicemailRingtoneUri(String callingPackage,
7872 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007873 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007874 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007875 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7876 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007877 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7878 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7879 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007880 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007881
7882 final long identity = Binder.clearCallingIdentity();
7883 try {
7884 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7885 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007886 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007887 }
7888 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7889 } finally {
7890 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007891 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007892 }
7893
7894 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007895 * Returns whether vibration is set for voicemail notification in Phone settings.
7896 *
7897 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7898 * voicemail vibration setting.
7899 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7900 */
7901 @Override
7902 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007903 final long identity = Binder.clearCallingIdentity();
7904 try {
7905 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7906 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007907 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007908 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007909
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007910 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7911 } finally {
7912 Binder.restoreCallingIdentity(identity);
7913 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007914 }
7915
Youhan Wange64578a2016-05-02 15:32:42 -07007916 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007917 * Sets the per-account voicemail vibration.
7918 *
7919 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7920 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7921 *
7922 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7923 * voicemail vibration setting.
7924 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7925 * specific PhoneAccount.
7926 */
7927 @Override
7928 public void setVoicemailVibrationEnabled(String callingPackage,
7929 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007930 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007931 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007932 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7933 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007934 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7935 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7936 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007937 }
7938
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007939 final long identity = Binder.clearCallingIdentity();
7940 try {
7941 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7942 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007943 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007944 }
7945 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7946 } finally {
7947 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007948 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007949 }
7950
7951 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007952 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7953 *
7954 * @throws SecurityException if the caller does not have the required permission
7955 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007956 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007957 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007958 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007959 }
7960
7961 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007962 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7963 * permission.
7964 *
7965 * @throws SecurityException if the caller does not have the required permission
7966 */
7967 private void enforceSendSmsPermission() {
7968 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7969 }
7970
7971 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007972 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007973 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007974 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007975 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007976 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007977 final long identity = Binder.clearCallingIdentity();
7978 try {
7979 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007980 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007981 if (componentName == null) {
7982 throw new SecurityException(
7983 "Caller not current active visual voicemail package[null]");
7984 }
7985 String vvmPackage = componentName.getPackageName();
7986 if (!callingPackage.equals(vvmPackage)) {
7987 throw new SecurityException("Caller not current active visual voicemail package["
7988 + vvmPackage + "]");
7989 }
7990 } finally {
7991 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007992 }
7993 }
7994
7995 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007996 * Return the application ID for the app type.
7997 *
7998 * @param subId the subscription ID that this request applies to.
7999 * @param appType the uicc app type.
8000 * @return Application ID for specificied app type, or null if no uicc.
8001 */
8002 @Override
8003 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008004 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008005 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008006
8007 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008008 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008009 if (phone == null) {
8010 return null;
8011 }
8012 String aid = null;
8013 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008014 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008015 .getApplicationByType(appType).getAid();
8016 } catch (Exception e) {
8017 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8018 }
8019 return aid;
8020 } finally {
8021 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008022 }
Youhan Wange64578a2016-05-02 15:32:42 -07008023 }
8024
Youhan Wang4001d252016-05-11 10:29:41 -07008025 /**
8026 * Return the Electronic Serial Number.
8027 *
8028 * @param subId the subscription ID that this request applies to.
8029 * @return ESN or null if error.
8030 */
8031 @Override
8032 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008033 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008034 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008035
8036 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008037 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008038 if (phone == null) {
8039 return null;
8040 }
8041 String esn = null;
8042 try {
8043 esn = phone.getEsn();
8044 } catch (Exception e) {
8045 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8046 }
8047 return esn;
8048 } finally {
8049 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008050 }
Youhan Wang4001d252016-05-11 10:29:41 -07008051 }
8052
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008053 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008054 * Return the Preferred Roaming List Version.
8055 *
8056 * @param subId the subscription ID that this request applies to.
8057 * @return PRLVersion or null if error.
8058 */
8059 @Override
8060 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008061 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008062 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008063
8064 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008065 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008066 if (phone == null) {
8067 return null;
8068 }
8069 String cdmaPrlVersion = null;
8070 try {
8071 cdmaPrlVersion = phone.getCdmaPrlVersion();
8072 } catch (Exception e) {
8073 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8074 }
8075 return cdmaPrlVersion;
8076 } finally {
8077 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008078 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008079 }
8080
8081 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008082 * Get snapshot of Telephony histograms
8083 * @return List of Telephony histograms
8084 * @hide
8085 */
8086 @Override
8087 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008088 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8089 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008090
8091 final long identity = Binder.clearCallingIdentity();
8092 try {
8093 return RIL.getTelephonyRILTimingHistograms();
8094 } finally {
8095 Binder.restoreCallingIdentity(identity);
8096 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008097 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008098
8099 /**
8100 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008101 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8102 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008103 * Require system privileges. In the future we may add this to carrier APIs.
8104 *
Michele Berionne482f8202018-11-27 18:57:59 -08008105 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008106 */
8107 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008108 @TelephonyManager.SetCarrierRestrictionResult
8109 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008110 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008111 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008112
Michele Berionne482f8202018-11-27 18:57:59 -08008113 if (carrierRestrictionRules == null) {
8114 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008115 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008116
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008117 final long identity = Binder.clearCallingIdentity();
8118 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008119 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008120 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008121 } finally {
8122 Binder.restoreCallingIdentity(identity);
8123 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008124 }
8125
8126 /**
8127 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008128 * Get the allowed carrier list and the excluded carrier list, including the priority between
8129 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008130 * Require system privileges. In the future we may add this to carrier APIs.
8131 *
Michele Berionne482f8202018-11-27 18:57:59 -08008132 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008133 */
8134 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008135 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008136 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008137 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008138
8139 final long identity = Binder.clearCallingIdentity();
8140 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008141 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8142 if (response instanceof CarrierRestrictionRules) {
8143 return (CarrierRestrictionRules) response;
8144 }
8145 // Response is an Exception of some kind,
8146 // which is signalled to the user as a NULL retval
8147 return null;
8148 } catch (Exception e) {
8149 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8150 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008151 } finally {
8152 Binder.restoreCallingIdentity(identity);
8153 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008154 }
8155
fionaxu59545b42016-05-25 15:53:37 -07008156 /**
fionaxu59545b42016-05-25 15:53:37 -07008157 * Action set from carrier signalling broadcast receivers to enable/disable radio
8158 * @param subId the subscription ID that this action applies to.
8159 * @param enabled control enable or disable radio.
8160 * {@hide}
8161 */
8162 @Override
8163 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8164 enforceModifyPermission();
8165 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008166
8167 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008168 if (phone == null) {
8169 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8170 return;
8171 }
8172 try {
8173 phone.carrierActionSetRadioEnabled(enabled);
8174 } catch (Exception e) {
8175 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008176 } finally {
8177 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008178 }
8179 }
8180
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008181 /**
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -07008182 * Enable or disable Voice over NR (VoNR)
8183 * @param subId the subscription ID that this action applies to.
8184 * @param enabled enable or disable VoNR.
8185 * @return operation result.
8186 */
8187 @Override
8188 public int setVoNrEnabled(int subId, boolean enabled) {
8189 enforceModifyPermission();
8190 final Phone phone = getPhone(subId);
8191
8192 final long identity = Binder.clearCallingIdentity();
8193 if (phone == null) {
8194 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8195 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8196 }
8197
8198 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8199 try {
8200 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8201 workSource);
8202 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008203
8204 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8205 if (DBG) {
8206 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8207 }
8208 SubscriptionManager.setSubscriptionProperty(
8209 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8210 (enabled ? "1" : "0"));
8211 }
8212
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -07008213 return result;
8214 } finally {
8215 Binder.restoreCallingIdentity(identity);
8216 }
8217 }
8218
8219 /**
8220 * Is voice over NR enabled
8221 * @return true if VoNR is enabled else false
8222 */
8223 @Override
8224 public boolean isVoNrEnabled(int subId) {
8225 enforceReadPrivilegedPermission("isVoNrEnabled");
8226 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8227 final long identity = Binder.clearCallingIdentity();
8228 try {
8229 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8230 null, subId, workSource);
8231 if (DBG) log("isVoNrEnabled: " + isEnabled);
8232 return isEnabled;
8233 } finally {
8234 Binder.restoreCallingIdentity(identity);
8235 }
8236 }
8237
8238 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008239 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8240 * network status based on which carrier apps could apply actions accordingly,
8241 * enable/disable default url handler for example.
8242 *
8243 * @param subId the subscription ID that this action applies to.
8244 * @param report control start/stop reporting the default network status.
8245 * {@hide}
8246 */
8247 @Override
8248 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8249 enforceModifyPermission();
8250 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008251
8252 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008253 if (phone == null) {
8254 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8255 return;
8256 }
8257 try {
8258 phone.carrierActionReportDefaultNetworkStatus(report);
8259 } catch (Exception e) {
8260 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008261 } finally {
8262 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008263 }
8264 }
8265
8266 /**
fionaxud9622282017-07-17 17:51:30 -07008267 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8268 * @param subId the subscription ID that this action applies to.
8269 * {@hide}
8270 */
8271 @Override
8272 public void carrierActionResetAll(int subId) {
8273 enforceModifyPermission();
8274 final Phone phone = getPhone(subId);
8275 if (phone == null) {
8276 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8277 return;
8278 }
8279 try {
8280 phone.carrierActionResetAll();
8281 } catch (Exception e) {
8282 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8283 }
8284 }
8285
8286 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008287 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8288 * bug report is being generated.
8289 */
8290 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008291 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008292 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8293 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008294 writer.println("Permission Denial: can't dump Phone from pid="
8295 + Binder.getCallingPid()
8296 + ", uid=" + Binder.getCallingUid()
8297 + "without permission "
8298 + android.Manifest.permission.DUMP);
8299 return;
8300 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008301 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008302 }
Jack Yueb89b242016-06-22 13:27:47 -07008303
Brad Ebingerdac2f002018-04-03 15:17:52 -07008304 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008305 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8306 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8307 @NonNull String[] args) {
8308 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8309 this, in.getFileDescriptor(), out.getFileDescriptor(),
8310 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008311 }
8312
Jack Yueb89b242016-06-22 13:27:47 -07008313 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008314 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008315 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008316 * @param reason the reason the data enable change is taking place
8317 * @param enabled True if enabling the data, otherwise disabling.
8318 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008319 */
8320 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008321 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008322 boolean enabled) {
8323 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8324 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8325 try {
8326 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008327 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008328 } catch (SecurityException se) {
8329 enforceModifyPermission();
8330 }
8331 } else {
8332 enforceModifyPermission();
8333 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008334
8335 final long identity = Binder.clearCallingIdentity();
8336 try {
8337 Phone phone = getPhone(subId);
8338 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008339 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8340 phone.carrierActionSetMeteredApnsEnabled(enabled);
8341 } else {
Jack Yu6bc9c8b2021-12-17 23:14:15 -08008342 if (phone.isUsingNewDataStack()) {
8343 phone.getDataSettingsManager().setDataEnabled(reason, enabled);
8344 } else {
8345 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8346 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008347 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008348 }
8349 } finally {
8350 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008351 }
8352 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008353
8354 /**
8355 * Get Client request stats
8356 * @return List of Client Request Stats
8357 * @hide
8358 */
8359 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008360 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8361 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008362 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008363 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008364 return null;
8365 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008366 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008367
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008368 final long identity = Binder.clearCallingIdentity();
8369 try {
8370 if (phone != null) {
8371 return phone.getClientRequestStats();
8372 }
8373
8374 return null;
8375 } finally {
8376 Binder.restoreCallingIdentity(identity);
8377 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008378 }
8379
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008380 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008381 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008382 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008383 }
Jack Yueb4124c2017-02-16 15:32:43 -08008384
8385 /**
Grace Chen70990072017-03-24 17:21:30 -07008386 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008387 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008388 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008389 * @param state State of SIM (power down, power up, pass through)
8390 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8391 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8392 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008393 *
8394 **/
8395 @Override
Grace Chen70990072017-03-24 17:21:30 -07008396 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008397 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008398 Phone phone = PhoneFactory.getPhone(slotIndex);
8399
vagdeviaf9a5b92018-08-15 16:01:53 -07008400 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8401
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008402 final long identity = Binder.clearCallingIdentity();
8403 try {
8404 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008405 phone.setSimPowerState(state, null, workSource);
8406 }
8407 } finally {
8408 Binder.restoreCallingIdentity(identity);
8409 }
8410 }
8411
8412 /**
8413 * Set SIM card power state.
8414 *
8415 * @param slotIndex SIM slot id.
8416 * @param state State of SIM (power down, power up, pass through)
8417 * @param callback callback to trigger after success or failure
8418 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8419 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8420 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8421 *
8422 **/
8423 @Override
8424 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8425 IIntegerConsumer callback) {
8426 enforceModifyPermission();
8427 Phone phone = PhoneFactory.getPhone(slotIndex);
8428
8429 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8430
8431 final long identity = Binder.clearCallingIdentity();
8432 try {
8433 if (phone != null) {
8434 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8435 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008436 }
8437 } finally {
8438 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008439 }
8440 }
Shuo Qiandd210312017-04-12 22:11:33 +00008441
Tyler Gunn65d45c22017-06-05 11:22:26 -07008442 private boolean isUssdApiAllowed(int subId) {
8443 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008444 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008445 if (configManager == null) {
8446 return false;
8447 }
8448 PersistableBundle pb = configManager.getConfigForSubId(subId);
8449 if (pb == null) {
8450 return false;
8451 }
8452 return pb.getBoolean(
8453 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8454 }
8455
Shuo Qiandd210312017-04-12 22:11:33 +00008456 /**
8457 * Check if phone is in emergency callback mode
8458 * @return true if phone is in emergency callback mode
8459 * @param subId sub id
8460 */
goneil9c5f4872017-12-05 14:07:56 -08008461 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008462 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008463 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008464 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008465
8466 final long identity = Binder.clearCallingIdentity();
8467 try {
8468 if (phone != null) {
8469 return phone.isInEcm();
8470 } else {
8471 return false;
8472 }
8473 } finally {
8474 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008475 }
8476 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008477
8478 /**
8479 * Get the current signal strength information for the given subscription.
8480 * Because this information is not updated when the device is in a low power state
8481 * it should not be relied-upon to be current.
8482 * @param subId Subscription index
8483 * @return the most recent cached signal strength info from the modem
8484 */
8485 @Override
8486 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008487 final long identity = Binder.clearCallingIdentity();
8488 try {
8489 Phone p = getPhone(subId);
8490 if (p == null) {
8491 return null;
8492 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008493
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008494 return p.getSignalStrength();
8495 } finally {
8496 Binder.restoreCallingIdentity(identity);
8497 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008498 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008499
Pengquan Meng77b7f132018-08-22 14:49:57 -07008500 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008501 * Get the current modem radio state for the given slot.
8502 * @param slotIndex slot index.
8503 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008504 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008505 * @return the current radio power state from the modem
8506 */
8507 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008508 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008509 Phone phone = PhoneFactory.getPhone(slotIndex);
8510 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008511 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8512 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008513 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8514 }
8515
8516 final long identity = Binder.clearCallingIdentity();
8517 try {
8518 return phone.getRadioPowerState();
8519 } finally {
8520 Binder.restoreCallingIdentity(identity);
8521 }
8522 }
8523 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8524 }
8525
8526 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008527 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8528 *
8529 * <p>Requires one of the following permissions:
8530 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008531 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008532 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8533 * privileges.
8534 *
8535 * @param subId subscription id
8536 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8537 * {@code false}.
8538 */
8539 @Override
8540 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008541 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008542 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008543 try {
8544 mApp.enforceCallingOrSelfPermission(
8545 android.Manifest.permission.ACCESS_NETWORK_STATE,
8546 functionName);
8547 } catch (Exception e) {
8548 mApp.enforceCallingOrSelfPermission(
8549 permission.READ_BASIC_PHONE_STATE, functionName);
8550 }
Shuo Qian093013d2020-08-13 15:42:55 -07008551 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008552 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008553 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008554 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008555
Pengquan Menga1bb6272018-09-06 09:59:22 -07008556 boolean isEnabled = false;
8557 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008558 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008559 Phone phone = getPhone(subId);
8560 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008561 } finally {
8562 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008563 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008564 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008565 }
8566
8567
8568 /**
8569 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8570 *
8571 * <p> Requires permission:
8572 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8573 * privileges.
8574 *
8575 * @param subId subscription id
8576 * @param isEnabled {@code true} means enable, {@code false} means disable.
8577 */
8578 @Override
8579 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008580 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8581 mApp, subId, "setDataRoamingEnabled");
8582
Pengquan Menga1bb6272018-09-06 09:59:22 -07008583 final long identity = Binder.clearCallingIdentity();
8584 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008585 Phone phone = getPhone(subId);
8586 if (phone != null) {
8587 phone.setDataRoamingEnabled(isEnabled);
8588 }
8589 } finally {
8590 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008591 }
8592 }
8593
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008594 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008595 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008596 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008597 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008598 mApp, subId, "isManualNetworkSelectionAllowed");
8599
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008600 boolean isAllowed = true;
8601 final long identity = Binder.clearCallingIdentity();
8602 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008603 Phone phone = getPhone(subId);
8604 if (phone != null) {
8605 isAllowed = phone.isCspPlmnEnabled();
8606 }
8607 } finally {
8608 Binder.restoreCallingIdentity(identity);
8609 }
8610 return isAllowed;
8611 }
8612
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008613 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8614 UiccProfile profile = port.getUiccProfile();
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08008615 if (profile == null) {
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008616 return false;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008617 }
Hunter Knepshield25ee6fc2021-12-13 15:08:35 -08008618 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8619 if (phone == null) {
8620 return false;
8621 }
8622 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8623 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8624 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008625 }
8626
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008627 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008628 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjs29b7e8e2021-11-17 04:05:58 +00008629 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008630 mApp.getSystemService(AppOpsManager.class)
8631 .checkPackage(Binder.getCallingUid(), callingPackage);
8632
Jordan Liu1e142fc2019-04-22 15:10:43 -07008633 boolean hasReadPermission = false;
sandeepjs0a502c42021-09-27 15:34:44 +00008634 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008635 try {
8636 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008637 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008638 } catch (SecurityException e) {
8639 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8640 // has carrier privileges on an active UICC
8641 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8642 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008643 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008644 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008645 }
sandeepjs0a502c42021-09-27 15:34:44 +00008646 // checking compatibility, if calling app's target SDK is T and beyond.
8647 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8648 Binder.getCallingUid())) {
8649 isIccIdAccessRestricted = true;
8650 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008651 final long identity = Binder.clearCallingIdentity();
8652 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008653 UiccController uiccController = UiccController.getInstance();
8654 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008655 if (hasReadPermission) {
8656 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008657 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008658
8659 // Remove private info if the caller doesn't have access
8660 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8661 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjs0a502c42021-09-27 15:34:44 +00008662 //setting the value after compatibility check
8663 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008664 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8665 // is available
sandeepjs0a502c42021-09-27 15:34:44 +00008666 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008667 if (card == null) {
8668 // assume no access if the card is unavailable
sandeepjs0a502c42021-09-27 15:34:44 +00008669 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008670 continue;
8671 }
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008672 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8673 if (portInfos.isEmpty()) {
sandeepjs0a502c42021-09-27 15:34:44 +00008674 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008675 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008676 }
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008677 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8678 for (UiccPortInfo portInfo : portInfos) {
8679 UiccPort port = uiccController.getUiccPortForSlot(
8680 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8681 if (port == null) {
8682 // assume no access if port is null
8683 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8684 continue;
8685 }
8686 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8687 uiccPortInfos.add(portInfo);
8688 } else {
8689 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8690 }
8691 }
8692 filteredInfos.add(new UiccCardInfo(
8693 cardInfo.isEuicc(),
8694 cardInfo.getCardId(),
8695 null,
8696 cardInfo.getPhysicalSlotIndex(),
8697 cardInfo.isRemovable(),
8698 cardInfo.isMultipleEnabledProfilesSupported(),
8699 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008700 }
8701 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008702 } finally {
8703 Binder.restoreCallingIdentity(identity);
8704 }
8705 }
8706
sandeepjs0a502c42021-09-27 15:34:44 +00008707 /**
8708 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8709 * generally private and require carrier privileges to view.
8710 *
8711 * @hide
8712 */
8713 @NonNull
8714 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8715 List<UiccPortInfo> portinfo = new ArrayList<>();
8716 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8717 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8718 }
8719 return new UiccCardInfo(
8720 cardInfo.isEuicc(),
8721 cardInfo.getCardId(),
8722 null,
8723 cardInfo.getPhysicalSlotIndex(),
8724 cardInfo.isRemovable(),
8725 cardInfo.isMultipleEnabledProfilesSupported(),
8726 portinfo
8727 );
8728 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008729
sandeepjs0a502c42021-09-27 15:34:44 +00008730 /**
8731 * @hide
8732 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8733 * These values are generally private and require carrier privileges to view.
8734 */
8735 @NonNull
8736 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8737 return new UiccPortInfo(
8738 UiccPortInfo.ICCID_REDACTED,
8739 portInfo.getPortIndex(),
8740 portInfo.getLogicalSlotIndex(),
8741 portInfo.isActive()
8742 );
8743 }
8744 @Override
8745 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjs29b7e8e2021-11-17 04:05:58 +00008746 // Verify that the callingPackage belongs to the calling UID
sandeepjs0a502c42021-09-27 15:34:44 +00008747 mApp.getSystemService(AppOpsManager.class)
8748 .checkPackage(Binder.getCallingUid(), callingPackage);
8749
8750 boolean hasReadPermission = false;
8751 boolean isLogicalSlotAccessRestricted = false;
sandeepjs0a502c42021-09-27 15:34:44 +00008752
8753 try {
8754 enforceReadPrivilegedPermission("getUiccSlotsInfo");
8755 hasReadPermission = true;
8756 } catch (SecurityException e) {
8757 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8758 // has carrier privileges on an active UICC
8759 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8760 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8761 hasReadPermission = true;
8762 }
8763 }
8764
8765 // checking compatibility, if calling app's target SDK is T and beyond.
8766 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8767 Binder.getCallingUid())) {
8768 isLogicalSlotAccessRestricted = true;
8769 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008770 final long identity = Binder.clearCallingIdentity();
8771 try {
8772 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8773 if (slots == null) {
8774 Rlog.i(LOG_TAG, "slots is null.");
8775 return null;
8776 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008777 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8778 for (int i = 0; i < slots.length; i++) {
8779 UiccSlot slot = slots[i];
8780 if (slot == null) {
8781 continue;
8782 }
8783
Jordan Liu7be7e652019-05-06 18:55:02 +00008784 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008785 UiccCard card = slot.getUiccCard();
8786 if (card != null) {
8787 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008788 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008789 cardId = slot.getEid();
8790 if (TextUtils.isEmpty(cardId)) {
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008791 // If cardId is null, use iccId of default port as cardId. Check if has
8792 // read permission otherwise set to null.(card is null which means no
8793 // carrier permission)
8794 cardId = hasReadPermission ? slot.getIccId(
8795 TelephonyManager.DEFAULT_PORT_INDEX) : null;
Jordan Liu01bd00d2019-09-12 16:19:43 -07008796 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008797 }
8798
Jordan Liu857451f2019-05-09 16:35:35 -07008799 if (cardId != null) {
8800 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8801 // if cardId is an EID, it's all digits so this is fine
8802 cardId = IccUtils.stripTrailingFs(cardId);
8803 }
8804
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008805 int cardState = 0;
8806 switch (slot.getCardState()) {
8807 case CARDSTATE_ABSENT:
8808 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8809 break;
8810 case CARDSTATE_PRESENT:
8811 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8812 break;
8813 case CARDSTATE_ERROR:
8814 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8815 break;
8816 case CARDSTATE_RESTRICTED:
8817 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8818 break;
8819 default:
8820 break;
8821
8822 }
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008823 List<UiccPortInfo> portInfos = new ArrayList<>();
8824 int[] portIndexes = slot.getPortList();
8825 for (int portIdx : portIndexes) {
8826 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
8827 callingPackage, hasReadPermission));
8828 if (slot.isPortActive(portIdx)) {
8829 UiccPort port = slot.getUiccCard().getUiccPort(portIdx);
8830 portInfos.add(new UiccPortInfo(iccId, port.getPortIdx(),
8831 port.getPhoneId(), true));
8832 } else {
8833 portInfos.add(new UiccPortInfo(iccId, portIdx, -1, false));
8834 }
8835 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008836 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008837 slot.isEuicc(),
8838 cardId,
8839 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08008840 slot.isExtendedApduSupported(),
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008841 slot.isRemovable(), portInfos);
sandeepjs0a502c42021-09-27 15:34:44 +00008842 //setting the value after compatibility check
8843 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008844 }
8845 return infos;
8846 } finally {
8847 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008848 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008849 }
8850
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008851 /* Returns null if doesn't have read permission or carrier privilege access. */
8852 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
8853 boolean hasReadPermission) {
8854 String iccId = slot.getIccId(portIndex);
8855 if (hasReadPermission) { // if has read permission
8856 return iccId;
8857 } else {
8858 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
8859 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
8860 // if no read permission, checking carrier privilege access
8861 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8862 return iccId;
8863 }
8864 }
8865 }
8866 // No read permission or carrier privilege access.
8867 return UiccPortInfo.ICCID_REDACTED;
8868 }
8869
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008870 @Override
sandeepjs0a502c42021-09-27 15:34:44 +00008871 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008872 public boolean switchSlots(int[] physicalSlots) {
8873 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008874
8875 final long identity = Binder.clearCallingIdentity();
8876 try {
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008877 List<UiccSlotMapping> slotMappings = new ArrayList<>();
8878 for (int i = 0; i < physicalSlots.length; i++) {
8879 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
8880 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
8881 physicalSlots[i], i));
8882 }
8883 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008884 } finally {
8885 Binder.restoreCallingIdentity(identity);
8886 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008887 }
Jack Yu4c988042018-02-27 15:30:01 -08008888
8889 @Override
sandeepjs0a502c42021-09-27 15:34:44 +00008890 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
8891 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
8892 enforceModifyPermission();
8893
8894 final long identity = Binder.clearCallingIdentity();
8895 try {
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008896 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjs0a502c42021-09-27 15:34:44 +00008897 } finally {
8898 Binder.restoreCallingIdentity(identity);
8899 }
8900 }
8901
8902 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008903 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008904 final long identity = Binder.clearCallingIdentity();
8905 try {
8906 return UiccController.getInstance().getCardIdForDefaultEuicc();
8907 } finally {
8908 Binder.restoreCallingIdentity(identity);
8909 }
8910 }
8911
Pengquan Meng85728fb2018-03-12 16:31:21 -07008912 /**
goneil47ffb6e2018-04-06 15:40:58 -07008913 * A test API to reload the UICC profile.
8914 *
8915 * <p>Requires that the calling app has permission
8916 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8917 * @hide
8918 */
8919 @Override
8920 public void refreshUiccProfile(int subId) {
8921 enforceModifyPermission();
8922
8923 final long identity = Binder.clearCallingIdentity();
8924 try {
8925 Phone phone = getPhone(subId);
8926 if (phone == null) {
8927 return;
8928 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008929 UiccPort uiccPort = phone.getUiccPort();
8930 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07008931 return;
8932 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008933 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07008934 if (uiccProfile == null) {
8935 return;
8936 }
8937 uiccProfile.refresh();
8938 } finally {
8939 Binder.restoreCallingIdentity(identity);
8940 }
8941 }
8942
8943 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008944 * Returns false if the mobile data is disabled by default, otherwise return true.
8945 */
8946 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008947 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008948 }
8949
8950 /**
8951 * Returns true if the data roaming is enabled by default, i.e the system property
8952 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8953 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8954 */
8955 private boolean getDefaultDataRoamingEnabled(int subId) {
8956 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008957 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008958 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008959 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8960 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8961 return isDataRoamingEnabled;
8962 }
8963
8964 /**
8965 * Returns the default network type for the given {@code subId}, if the default network type is
8966 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8967 */
8968 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008969 List<Integer> list = TelephonyProperties.default_network();
8970 int phoneId = mSubscriptionController.getPhoneId(subId);
8971 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8972 return list.get(phoneId);
8973 }
8974 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008975 }
fionaxua13278b2018-03-21 00:08:13 -07008976
8977 @Override
8978 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008979 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008980 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008981
8982 final long identity = Binder.clearCallingIdentity();
8983 try {
8984 final Phone phone = getPhone(subId);
8985 if (phone == null) {
8986 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8987 return;
8988 }
Rambo Wanga7436882022-01-13 21:51:44 -08008989 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8990 if (cpt != null) {
8991 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
8992 }
8993 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07008994 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8995 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008996 if (carrierPrivilegeRules == null) {
8997 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8998 } else {
8999 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9000 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009001 } finally {
9002 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009003 }
fionaxua13278b2018-03-21 00:08:13 -07009004 }
9005
9006 @Override
9007 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009008 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009009
9010 final long identity = Binder.clearCallingIdentity();
9011 try {
9012 final Phone phone = getPhone(subId);
9013 if (phone == null) {
9014 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9015 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9016 }
9017 return phone.getCarrierIdListVersion();
9018 } finally {
9019 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009020 }
fionaxua13278b2018-03-21 00:08:13 -07009021 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009022
9023 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009024 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9025 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009026 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009027 mApp, subId, callingPackage, callingFeatureId,
9028 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009029 return -1;
9030 }
9031
9032 final long identity = Binder.clearCallingIdentity();
9033 try {
9034 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9035 } finally {
9036 Binder.restoreCallingIdentity(identity);
9037 }
9038 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009039
9040 @Override
9041 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009042 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009043 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009044 mApp, subId, "getCdmaRoamingMode");
9045
9046 final long identity = Binder.clearCallingIdentity();
9047 try {
9048 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9049 } finally {
9050 Binder.restoreCallingIdentity(identity);
9051 }
9052 }
9053
9054 @Override
9055 public boolean setCdmaRoamingMode(int subId, int mode) {
9056 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9057 mApp, subId, "setCdmaRoamingMode");
9058
9059 final long identity = Binder.clearCallingIdentity();
9060 try {
9061 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9062 } finally {
9063 Binder.restoreCallingIdentity(identity);
9064 }
9065 }
9066
9067 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009068 public int getCdmaSubscriptionMode(int subId) {
9069 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009070 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009071 mApp, subId, "getCdmaSubscriptionMode");
9072
9073 final long identity = Binder.clearCallingIdentity();
9074 try {
9075 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9076 } finally {
9077 Binder.restoreCallingIdentity(identity);
9078 }
9079 }
9080
9081 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009082 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9083 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9084 mApp, subId, "setCdmaSubscriptionMode");
9085
9086 final long identity = Binder.clearCallingIdentity();
9087 try {
9088 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9089 } finally {
9090 Binder.restoreCallingIdentity(identity);
9091 }
9092 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009093
sqianc5eccab2018-10-19 18:46:41 -07009094 @Override
sqian8c685422019-02-22 15:55:18 -08009095 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009096 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009097 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009098 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9099 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009100 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9101 }
9102 final long identity = Binder.clearCallingIdentity();
9103 try {
sqian854d44b2018-12-12 16:48:18 -08009104 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9105 for (Phone phone: PhoneFactory.getPhones()) {
9106 if (phone.getEmergencyNumberTracker() != null
9107 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9108 emergencyNumberListInternal.put(
9109 phone.getSubId(),
9110 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9111 }
sqian11b7a0e2018-12-05 18:48:28 -08009112 }
sqian854d44b2018-12-12 16:48:18 -08009113 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009114 } finally {
9115 Binder.restoreCallingIdentity(identity);
9116 }
sqianc5eccab2018-10-19 18:46:41 -07009117 }
9118
9119 @Override
sqian8c685422019-02-22 15:55:18 -08009120 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009121 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009122 if (!exactMatch) {
9123 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009124 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009125 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009126 }
9127 final long identity = Binder.clearCallingIdentity();
9128 try {
sqian854d44b2018-12-12 16:48:18 -08009129 for (Phone phone: PhoneFactory.getPhones()) {
9130 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009131 && phone.getEmergencyNumberTracker()
9132 .isEmergencyNumber(number, exactMatch)) {
9133 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009134 }
sqian11b7a0e2018-12-05 18:48:28 -08009135 }
9136 return false;
9137 } finally {
9138 Binder.restoreCallingIdentity(identity);
9139 }
9140 }
9141
sqianf4ca7ed2019-01-15 18:32:07 -08009142 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009143 * Start emergency callback mode for GsmCdmaPhone for testing.
9144 */
9145 @Override
9146 public void startEmergencyCallbackMode() {
9147 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9148 "startEmergencyCallbackMode");
9149 enforceModifyPermission();
9150 final long identity = Binder.clearCallingIdentity();
9151 try {
9152 for (Phone phone : PhoneFactory.getPhones()) {
9153 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9154 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9155 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9156 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9157 gsmCdmaPhone.obtainMessage(
9158 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9159 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9160 }
9161 }
9162 } finally {
9163 Binder.restoreCallingIdentity(identity);
9164 }
9165 }
9166
9167 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009168 * Update emergency number list for test mode.
9169 */
9170 @Override
9171 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9172 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9173 "updateEmergencyNumberListTestMode");
9174
9175 final long identity = Binder.clearCallingIdentity();
9176 try {
9177 for (Phone phone: PhoneFactory.getPhones()) {
9178 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9179 if (tracker != null) {
9180 tracker.executeEmergencyNumberTestModeCommand(action, num);
9181 }
9182 }
9183 } finally {
9184 Binder.restoreCallingIdentity(identity);
9185 }
9186 }
9187
9188 /**
9189 * Get the full emergency number list for test mode.
9190 */
9191 @Override
9192 public List<String> getEmergencyNumberListTestMode() {
9193 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9194 "getEmergencyNumberListTestMode");
9195
9196 final long identity = Binder.clearCallingIdentity();
9197 try {
9198 Set<String> emergencyNumbers = new HashSet<>();
9199 for (Phone phone: PhoneFactory.getPhones()) {
9200 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9201 if (tracker != null) {
9202 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9203 emergencyNumbers.add(num.getNumber());
9204 }
9205 }
9206 }
9207 return new ArrayList<>(emergencyNumbers);
9208 } finally {
9209 Binder.restoreCallingIdentity(identity);
9210 }
9211 }
9212
chen xud6b45bd2018-10-30 22:27:10 -07009213 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009214 public int getEmergencyNumberDbVersion(int subId) {
9215 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9216
9217 final long identity = Binder.clearCallingIdentity();
9218 try {
9219 final Phone phone = getPhone(subId);
9220 if (phone == null) {
9221 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9222 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9223 }
9224 return phone.getEmergencyNumberDbVersion();
9225 } finally {
9226 Binder.restoreCallingIdentity(identity);
9227 }
9228 }
9229
9230 @Override
9231 public void notifyOtaEmergencyNumberDbInstalled() {
9232 enforceModifyPermission();
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.updateOtaEmergencyNumberDatabase();
9240 }
9241 }
9242 } finally {
9243 Binder.restoreCallingIdentity(identity);
9244 }
9245 }
9246
9247 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009248 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009249 enforceActiveEmergencySessionPermission();
9250
9251 final long identity = Binder.clearCallingIdentity();
9252 try {
9253 for (Phone phone: PhoneFactory.getPhones()) {
9254 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9255 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009256 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9257 }
9258 }
9259 } finally {
9260 Binder.restoreCallingIdentity(identity);
9261 }
9262 }
9263
9264 @Override
9265 public void resetOtaEmergencyNumberDbFilePath() {
9266 enforceActiveEmergencySessionPermission();
9267
9268 final long identity = Binder.clearCallingIdentity();
9269 try {
9270 for (Phone phone: PhoneFactory.getPhones()) {
9271 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9272 if (tracker != null) {
9273 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009274 }
9275 }
9276 } finally {
9277 Binder.restoreCallingIdentity(identity);
9278 }
9279 }
9280
9281 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009282 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9283 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9284 Phone phone = getPhone(subId);
9285 if (phone == null) {
9286 return null;
9287 }
9288 final long identity = Binder.clearCallingIdentity();
9289 try {
9290 UiccProfile profile = UiccController.getInstance()
9291 .getUiccProfileForPhone(phone.getPhoneId());
9292 if (profile != null) {
9293 return profile.getCertsFromCarrierPrivilegeAccessRules();
9294 }
9295 } finally {
9296 Binder.restoreCallingIdentity(identity);
9297 }
9298 return null;
9299 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009300
9301 /**
9302 * Enable or disable a modem stack.
9303 */
9304 @Override
9305 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9306 enforceModifyPermission();
9307
9308 final long identity = Binder.clearCallingIdentity();
9309 try {
9310 Phone phone = PhoneFactory.getPhone(slotIndex);
9311 if (phone == null) {
9312 return false;
9313 } else {
9314 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9315 }
9316 } finally {
9317 Binder.restoreCallingIdentity(identity);
9318 }
9319 }
Michelecea4cf22018-12-21 15:00:11 -08009320
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009321 /**
9322 * Whether a modem stack is enabled or not.
9323 */
9324 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009325 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9326 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009327 Phone phone = PhoneFactory.getPhone(slotIndex);
9328 if (phone == null) return false;
9329
9330 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009331 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9332 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009333 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9334 }
9335
9336 final long identity = Binder.clearCallingIdentity();
9337 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009338 try {
9339 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9340 } catch (NoSuchElementException ex) {
9341 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9342 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009343 } finally {
9344 Binder.restoreCallingIdentity(identity);
9345 }
9346 }
9347
Michelecea4cf22018-12-21 15:00:11 -08009348 @Override
Michele0ea7d782019-03-19 14:58:42 -07009349 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009350 enforceModifyPermission();
9351
9352 final long identity = Binder.clearCallingIdentity();
9353 try {
9354 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009355 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009356 .commit();
9357 } finally {
9358 Binder.restoreCallingIdentity(identity);
9359 }
9360 }
9361
9362 @Override
Michele0ea7d782019-03-19 14:58:42 -07009363 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009364 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009365 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009366 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9367 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009368 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009369 }
Michelecea4cf22018-12-21 15:00:11 -08009370
9371 final long identity = Binder.clearCallingIdentity();
9372 try {
Michele0ea7d782019-03-19 14:58:42 -07009373 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009374 } finally {
9375 Binder.restoreCallingIdentity(identity);
9376 }
9377 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009378
Michele0ea7d782019-03-19 14:58:42 -07009379 @TelephonyManager.IsMultiSimSupportedResult
9380 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009381 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9382 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9383 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009384 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9385 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009386 }
9387 // Check if the hardware supports multisim functionality. If usage of multisim is not
9388 // supported by the modem, indicate that it is restricted.
9389 PhoneCapability staticCapability =
9390 mPhoneConfigurationManager.getStaticPhoneCapability();
9391 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009392 loge("isMultiSimSupportedInternal: no static configuration available");
9393 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009394 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009395 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009396 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9397 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009398 }
9399 // Check if support of multiple SIMs is restricted by carrier
9400 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009401 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009402 }
9403
Michele0ea7d782019-03-19 14:58:42 -07009404 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009405 }
9406
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009407 /**
9408 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009409 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9410 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9411 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009412 * @param numOfSims number of active sims we want to switch to
9413 */
9414 @Override
9415 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009416 if (numOfSims == 1) {
9417 enforceModifyPermission();
9418 } else {
9419 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9420 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9421 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009422 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009423
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009424 try {
Michele30b57b22019-03-01 12:01:14 -08009425 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009426 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009427 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9428 return;
9429 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009430 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9431 } finally {
9432 Binder.restoreCallingIdentity(identity);
9433 }
9434 }
9435
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009436 @Override
9437 public boolean isApplicationOnUicc(int subId, int appType) {
9438 enforceReadPrivilegedPermission("isApplicationOnUicc");
9439 Phone phone = getPhone(subId);
9440 if (phone == null) {
9441 return false;
9442 }
9443 final long identity = Binder.clearCallingIdentity();
9444 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009445 UiccPort uiccPort = phone.getUiccPort();
9446 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009447 return false;
9448 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009449 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009450 if (uiccProfile == null) {
9451 return false;
9452 }
9453 if (TelephonyManager.APPTYPE_SIM <= appType
9454 && appType <= TelephonyManager.APPTYPE_ISIM) {
9455 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9456 }
9457 return false;
9458 } finally {
9459 Binder.restoreCallingIdentity(identity);
9460 }
9461 }
9462
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009463 /**
chen xub4baa772019-04-03 10:23:41 -07009464 * Get whether making changes to modem configurations will trigger reboot.
9465 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009466 */
9467 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009468 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9469 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009470 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009471 mApp, subId, callingPackage, callingFeatureId,
9472 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009473 return false;
9474 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009475 final long identity = Binder.clearCallingIdentity();
9476 try {
9477 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9478 } finally {
9479 Binder.restoreCallingIdentity(identity);
9480 }
9481 }
9482
Nathan Harold29f5f052019-02-15 13:41:57 -08009483 private void updateModemStateMetrics() {
9484 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9485 // TODO: check the state for each modem if the api is ready.
9486 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9487 }
9488
Pengquan Meng3889a572019-01-23 11:16:29 -08009489 @Override
sandeepjs29b7e8e2021-11-17 04:05:58 +00009490 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009491 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjs29b7e8e2021-11-17 04:05:58 +00009492 // Verify that the callingPackage belongs to the calling UID
9493 mApp.getSystemService(AppOpsManager.class)
9494 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009495 final long identity = Binder.clearCallingIdentity();
sandeepjs29b7e8e2021-11-17 04:05:58 +00009496 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009497 try {
sandeepjs29b7e8e2021-11-17 04:05:58 +00009498 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9499 if (slotInfos != null) {
9500 for (int i = 0; i < slotInfos.length; i++) {
9501 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9502 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9503 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9504 portInfo.getLogicalSlotIndex()));
9505 }
9506 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009507 }
9508 }
sandeepjs29b7e8e2021-11-17 04:05:58 +00009509 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009510 } finally {
9511 Binder.restoreCallingIdentity(identity);
9512 }
9513 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009514
9515 /**
9516 * Get the IRadio HAL Version
9517 */
9518 @Override
9519 public int getRadioHalVersion() {
9520 Phone phone = getDefaultPhone();
9521 if (phone == null) return -1;
9522 HalVersion hv = phone.getHalVersion();
9523 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9524 return hv.major * 100 + hv.minor;
9525 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009526
9527 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009528 * Get the current calling package name.
9529 * @return the current calling package name
9530 */
9531 @Override
9532 public String getCurrentPackageName() {
9533 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9534 }
9535
9536 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009537 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9538 * corresponding network requests on a subId.
9539 *
9540 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009541 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009542 * 2) APN is un-metered for this subscription, or
9543 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009544 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009545 *
9546 * @return whether data is allowed for a apn type.
9547 *
9548 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009549 */
9550 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009551 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009552 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9553 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009554
9555 // Now that all security checks passes, perform the operation as ourselves.
9556 final long identity = Binder.clearCallingIdentity();
9557 try {
9558 Phone phone = getPhone(subId);
9559 if (phone == null) return false;
9560
Jack Yu41407ee2019-05-13 16:54:09 -07009561 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009562 boolean isDataEnabled;
9563 if (phone.isUsingNewDataStack()) {
9564 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
9565 } else {
9566 isDataEnabled = phone.getDataEnabledSettings().isDataEnabled(apnType);
9567 }
9568 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009569 } finally {
9570 Binder.restoreCallingIdentity(identity);
9571 }
9572 }
9573
9574 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009575 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009576 enforceReadPrivilegedPermission("isApnMetered");
9577
9578 // Now that all security checks passes, perform the operation as ourselves.
9579 final long identity = Binder.clearCallingIdentity();
9580 try {
9581 Phone phone = getPhone(subId);
9582 if (phone == null) return true; // By default return true.
9583
Jack Yu41407ee2019-05-13 16:54:09 -07009584 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009585 } finally {
9586 Binder.restoreCallingIdentity(identity);
9587 }
9588 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009589
9590 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009591 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9592 int subscriptionId, IBooleanConsumer resultCallback) {
9593 enforceModifyPermission();
9594 long token = Binder.clearCallingIdentity();
9595 try {
9596 Phone phone = getPhone(subscriptionId);
9597 if (phone == null) {
9598 try {
9599 if (resultCallback != null) {
9600 resultCallback.accept(false);
9601 }
9602 } catch (RemoteException e) {
9603 // ignore
9604 }
9605 return;
9606 }
9607 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9608 Pair.create(specifiers, (x) -> {
9609 try {
9610 if (resultCallback != null) {
9611 resultCallback.accept(x);
9612 }
9613 } catch (RemoteException e) {
9614 // ignore
9615 }
9616 });
9617 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9618 } finally {
9619 Binder.restoreCallingIdentity(token);
9620 }
9621 }
9622
9623 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009624 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9625 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009626 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009627 mApp, subId, "getSystemSelectionChannels");
9628 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9629 final long identity = Binder.clearCallingIdentity();
9630 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009631 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9632 if (result instanceof IllegalStateException) {
9633 throw (IllegalStateException) result;
9634 }
9635 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009636 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9637 return specifiers;
9638 } finally {
9639 Binder.restoreCallingIdentity(identity);
9640 }
9641 }
9642
9643 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009644 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009645 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009646 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9647 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9648 if (iccRecords == null) {
9649 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9650 return false;
9651 }
9652 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9653 }
9654
9655 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009656 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9657 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009658 if (callingPackage == null) {
9659 callingPackage = getCurrentPackageName();
9660 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009661 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9662 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009663 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9664 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009665 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9666 }
9667 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9668 Intent intent = new Intent();
9669 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9670 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9671 // Bring up choose default SMS subscription dialog right now
9672 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9673 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9674 mApp.startActivity(intent);
9675 }
chen xud5ca2d52019-05-28 15:20:57 -07009676
9677 @Override
9678 public String getMmsUAProfUrl(int subId) {
9679 //TODO investigate if this API should require proper permission check in R b/133791609
9680 final long identity = Binder.clearCallingIdentity();
9681 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009682 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9683 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9684 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9685 return carrierUAProfUrl;
9686 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009687 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9688 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009689 } finally {
9690 Binder.restoreCallingIdentity(identity);
9691 }
9692 }
9693
9694 @Override
9695 public String getMmsUserAgent(int subId) {
9696 //TODO investigate if this API should require proper permission check in R b/133791609
9697 final long identity = Binder.clearCallingIdentity();
9698 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009699 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9700 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9701 if (!TextUtils.isEmpty(carrierUserAgent)) {
9702 return carrierUserAgent;
9703 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009704 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9705 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009706 } finally {
9707 Binder.restoreCallingIdentity(identity);
9708 }
9709 }
Jack Yub07d4972019-05-28 16:12:25 -07009710
9711 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009712 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9713 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009714
Jack Yub07d4972019-05-28 16:12:25 -07009715 final long identity = Binder.clearCallingIdentity();
9716 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009717 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009718 if (phone == null) return false;
9719
Hall Liua62f5da2020-09-25 10:42:19 -07009720 switch (policy) {
9721 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009722 if (phone.isUsingNewDataStack()) {
9723 return phone.getDataSettingsManager().isDataAllowedInVoiceCall();
9724 } else {
9725 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9726 }
Hall Liua62f5da2020-09-25 10:42:19 -07009727 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009728 if (phone.isUsingNewDataStack()) {
9729 return phone.getDataSettingsManager().isMmsAlwaysAllowed();
9730 } else {
9731 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9732 }
Hall Liua62f5da2020-09-25 10:42:19 -07009733 default:
9734 throw new IllegalArgumentException(policy + " is not a valid policy");
9735 }
Jack Yub07d4972019-05-28 16:12:25 -07009736 } finally {
9737 Binder.restoreCallingIdentity(identity);
9738 }
9739 }
9740
9741 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009742 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009743 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009744 enforceModifyPermission();
9745
changbettyd5c246e2019-12-24 15:40:37 +08009746 final long identity = Binder.clearCallingIdentity();
9747 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009748 Phone phone = getPhone(subscriptionId);
9749 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009750
Hall Liua62f5da2020-09-25 10:42:19 -07009751 switch (policy) {
9752 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009753 if (phone.isUsingNewDataStack()) {
9754 phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled);
9755 } else {
9756 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9757 }
Hall Liua62f5da2020-09-25 10:42:19 -07009758 break;
9759 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu6bc9c8b2021-12-17 23:14:15 -08009760 if (phone.isUsingNewDataStack()) {
9761 phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled);
9762 } else {
9763 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9764 }
Hall Liua62f5da2020-09-25 10:42:19 -07009765 break;
9766 default:
9767 throw new IllegalArgumentException(policy + " is not a valid policy");
9768 }
changbettyd5c246e2019-12-24 15:40:37 +08009769 } finally {
9770 Binder.restoreCallingIdentity(identity);
9771 }
9772 }
9773
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009774 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009775 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009776 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9777 * otherwise.
9778 */
9779 @Override
9780 public void setCepEnabled(boolean isCepEnabled) {
9781 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9782
9783 final long identity = Binder.clearCallingIdentity();
9784 try {
9785 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9786 for (Phone phone : PhoneFactory.getPhones()) {
9787 Phone defaultPhone = phone.getImsPhone();
9788 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9789 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9790 ImsPhoneCallTracker imsPhoneCallTracker =
9791 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9792 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9793 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9794 + imsPhone.getMsisdn());
9795 }
9796 }
9797 } finally {
9798 Binder.restoreCallingIdentity(identity);
9799 }
9800 }
allenwtsu46dcc572020-01-08 18:24:03 +08009801
9802 /**
9803 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9804 *
9805 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9806 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9807 * before being read.
9808 */
9809 @Override
9810 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9811 isCompressed) {
9812 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9813 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009814 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9815 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9816 }
9817 if (!isImsAvailableOnDevice()) {
9818 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9819 "IMS not available on device.");
9820 }
9821
9822 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009823 try {
Hui Wang761a6682020-10-31 05:12:53 +00009824 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9825 } finally {
9826 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009827 }
9828 }
zoey chene02881a2019-12-30 16:11:23 +08009829
9830 @Override
9831 public boolean isIccLockEnabled(int subId) {
9832 enforceReadPrivilegedPermission("isIccLockEnabled");
9833
9834 // Now that all security checks passes, perform the operation as ourselves.
9835 final long identity = Binder.clearCallingIdentity();
9836 try {
9837 Phone phone = getPhone(subId);
9838 if (phone != null && phone.getIccCard() != null) {
9839 return phone.getIccCard().getIccLockEnabled();
9840 } else {
9841 return false;
9842 }
9843 } finally {
9844 Binder.restoreCallingIdentity(identity);
9845 }
9846 }
9847
9848 /**
9849 * Set the ICC pin lock enabled or disabled.
9850 *
9851 * @return an integer representing the status of IccLock enabled or disabled in the following
9852 * three cases:
9853 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9854 * successfully.
9855 * - Positive number and zero for remaining password attempts.
9856 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9857 *
9858 */
9859 @Override
9860 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9861 enforceModifyPermission();
9862
9863 Phone phone = getPhone(subId);
9864 if (phone == null) {
9865 return 0;
9866 }
9867 // Now that all security checks passes, perform the operation as ourselves.
9868 final long identity = Binder.clearCallingIdentity();
9869 try {
9870 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9871 new Pair<Boolean, String>(enabled, password), phone, null);
9872 return attemptsRemaining;
9873
9874 } catch (Exception e) {
9875 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9876 } finally {
9877 Binder.restoreCallingIdentity(identity);
9878 }
9879 return 0;
9880 }
9881
9882 /**
9883 * Change the ICC password used in ICC pin lock.
9884 *
9885 * @return an integer representing the status of IccLock changed in the following three cases:
9886 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9887 * - Positive number and zero for remaining password attempts.
9888 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9889 *
9890 */
9891 @Override
9892 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9893 enforceModifyPermission();
9894
9895 Phone phone = getPhone(subId);
9896 if (phone == null) {
9897 return 0;
9898 }
9899 // Now that all security checks passes, perform the operation as ourselves.
9900 final long identity = Binder.clearCallingIdentity();
9901 try {
9902 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9903 new Pair<String, String>(oldPassword, newPassword), phone, null);
9904 return attemptsRemaining;
9905
9906 } catch (Exception e) {
9907 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9908 } finally {
9909 Binder.restoreCallingIdentity(identity);
9910 }
9911 return 0;
9912 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009913
9914 /**
9915 * Request for receiving user activity notification
9916 */
9917 @Override
9918 public void requestUserActivityNotification() {
9919 if (!mNotifyUserActivity.get()
9920 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9921 mNotifyUserActivity.set(true);
9922 }
9923 }
9924
9925 /**
9926 * Called when userActivity is signalled in the power manager.
9927 * This is safe to call from any thread, with any window manager locks held or not.
9928 */
9929 @Override
9930 public void userActivity() {
9931 // ***************************************
9932 // * Inherited from PhoneWindowManager *
9933 // ***************************************
9934 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9935 // WITH ITS LOCKS HELD.
9936 //
9937 // This code must be VERY careful about the locks
9938 // it acquires.
9939 // In fact, the current code acquires way too many,
9940 // and probably has lurking deadlocks.
9941
9942 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9943 throw new SecurityException("Only the OS may call notifyUserActivity()");
9944 }
9945
9946 if (mNotifyUserActivity.getAndSet(false)) {
9947 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9948 USER_ACTIVITY_NOTIFICATION_DELAY);
9949 }
9950 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009951
9952 @Override
9953 public boolean canConnectTo5GInDsdsMode() {
9954 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9955 }
Jack Yud10cdd42020-09-28 20:28:01 -07009956
9957 @Override
9958 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9959 String callingFeatureId) {
9960 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9961 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9962 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9963 }
9964
9965 Phone phone = getPhone(subId);
9966 if (phone == null) {
9967 throw new RuntimeException("phone is not available");
9968 }
9969 // Now that all security checks passes, perform the operation as ourselves.
9970 final long identity = Binder.clearCallingIdentity();
9971 try {
9972 return phone.getEquivalentHomePlmns();
9973 } finally {
9974 Binder.restoreCallingIdentity(identity);
9975 }
9976 }
Daniel Bright59e67312020-11-13 11:49:37 -08009977
9978 @Override
9979 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009980 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9981 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009982 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009983 if (radioInterfaceCapabilities == null) {
9984 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009985 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009986 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009987 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009988
Hui Wang641e81c2020-10-12 12:14:23 -07009989 @Override
9990 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9991 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009992 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9993 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9994 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9995 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9996 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009997 if (DBG) {
9998 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9999 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10000 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10001 }
10002
10003 if (!SubscriptionManager.isValidSubscriptionId(subId)
10004 || appType < TelephonyManager.APPTYPE_UNKNOWN
10005 || appType > TelephonyManager.APPTYPE_ISIM
10006 || nafUrl == null || securityProtocol == null || callback == null) {
10007 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10008 if (callback != null) {
10009 try {
10010 callback.onAuthenticationFailure(
10011 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10012 } catch (RemoteException exception) {
10013 log("Fail to notify onAuthenticationFailure due to " + exception);
10014 }
10015 return;
10016 }
10017 }
10018
10019 final long token = Binder.clearCallingIdentity();
10020 try {
10021 getGbaManager(subId).bootstrapAuthenticationRequest(
10022 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10023 forceBootStrapping, callback));
10024 } finally {
10025 Binder.restoreCallingIdentity(token);
10026 }
10027 }
10028
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010029 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010030 * Attempts to set the radio power state for all phones for thermal reason.
10031 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010032 * requested radio power state will actually be set. See {@link
10033 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10034 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010035 * @param enable {@code true} if trying to turn radio on.
10036 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10037 * false}.
10038 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010039 private boolean setRadioPowerForThermal(boolean enable) {
10040 boolean isPhoneAvailable = false;
10041 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10042 Phone phone = PhoneFactory.getPhone(i);
10043 if (phone != null) {
10044 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10045 isPhoneAvailable = true;
10046 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010047 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010048
10049 // return true if successfully informed the phone object about the thermal radio power
10050 // request.
10051 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010052 }
10053
10054 private int handleDataThrottlingRequest(int subId,
10055 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010056 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10057 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10058 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10059 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10060 throw new IllegalArgumentException("modem does not support data throttling");
10061 }
10062
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010063 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10064 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010065 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010066 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10067 }
10068
10069 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10070
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010071 if (isDataThrottlingSupported) {
10072 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010073 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010074 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10075 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10076 } else if (thermalMitigationResult
10077 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010078 log("Modem likely does not support data throttling on secondary carrier. Data " +
10079 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10080 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010081 }
10082 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010083 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010084
10085 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010086 }
10087
Jack Nudelman644b91a2021-03-12 14:09:48 -080010088 private static List<String> getThermalMitigationAllowlist(Context context) {
10089 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10090 for (String pckg : context.getResources()
10091 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10092 sThermalMitigationAllowlistedPackages.add(pckg);
10093 }
10094 }
10095
10096 return sThermalMitigationAllowlistedPackages;
10097 }
10098
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010099 private boolean isAnyPhoneInEmergencyState() {
10100 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10101 if (tm.isInEmergencyCall()) {
10102 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10103 return true;
10104 }
10105 for (Phone phone : PhoneFactory.getPhones()) {
10106 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10107 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10108 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10109 + phone.isInEcm());
10110 return true;
10111 }
10112 }
10113
10114 return false;
10115 }
10116
Jack Nudelman644b91a2021-03-12 14:09:48 -080010117 /**
10118 * Used by shell commands to add an authorized package name for thermal mitigation.
10119 * @param packageName name of package to be allowlisted
10120 * @param context
10121 */
10122 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10123 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10124 sThermalMitigationAllowlistedPackages.add(packageName);
10125 }
10126
10127 /**
10128 * Used by shell commands to remove an authorized package name for thermal mitigation.
10129 * @param packageName name of package to remove from allowlist
10130 * @param context
10131 */
10132 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10133 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10134 sThermalMitigationAllowlistedPackages.remove(packageName);
10135 }
10136
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010137 /**
10138 * Thermal mitigation request to control functionalities at modem.
10139 *
10140 * @param subId the id of the subscription.
10141 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010142 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010143 *
10144 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10145 */
10146 @Override
10147 @ThermalMitigationResult
10148 public int sendThermalMitigationRequest(
10149 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010150 ThermalMitigationRequest thermalMitigationRequest,
10151 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010152 enforceModifyPermission();
10153
Jack Nudelman644b91a2021-03-12 14:09:48 -080010154 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10155 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10156 .contains(callingPackage)) {
10157 throw new SecurityException("Calling package must be configured in the device config. "
10158 + "calling package: " + callingPackage);
10159 }
10160
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010161 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10162 final long identity = Binder.clearCallingIdentity();
10163
10164 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10165 try {
10166 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10167 switch (thermalMitigationAction) {
10168 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10169 thermalMitigationResult =
10170 handleDataThrottlingRequest(subId,
10171 thermalMitigationRequest.getDataThrottlingRequest());
10172 break;
10173 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10174 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10175 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10176 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10177 }
10178
10179 // Ensure that radio is on. If not able to power on due to phone being
10180 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010181 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010182 thermalMitigationResult =
10183 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10184 break;
10185 }
10186
10187 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10188 false);
10189 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10190 break;
10191 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10192 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10193 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10194 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10195 }
10196
10197 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10198 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010199 Phone phone = getPhone(subId);
10200 if (phone == null) {
10201 thermalMitigationResult =
10202 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10203 break;
10204 }
10205
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010206 TelephonyConnectionService service =
10207 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010208 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010209 Log.e(LOG_TAG, "An emergency call is pending");
10210 thermalMitigationResult =
10211 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10212 break;
10213 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010214 thermalMitigationResult =
10215 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10216 break;
10217 }
10218 } else {
10219 thermalMitigationResult =
10220 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10221 break;
10222 }
10223
10224 // Turn radio off. If not able to power off due to phone being unavailable,
10225 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010226 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010227 thermalMitigationResult =
10228 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10229 break;
10230 }
10231 thermalMitigationResult =
10232 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10233 break;
10234 default:
10235 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10236 + "not exist. Requested action: " + thermalMitigationAction);
10237 }
10238 } catch (IllegalArgumentException e) {
10239 throw e;
10240 } catch (Exception e) {
10241 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10242 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10243 } finally {
10244 Binder.restoreCallingIdentity(identity);
10245 }
10246
10247 if (DBG) {
10248 log("thermalMitigationRequest returning with thermalMitigationResult: "
10249 + thermalMitigationResult);
10250 }
10251
10252 return thermalMitigationResult;
10253 }
Hui Wang641e81c2020-10-12 12:14:23 -070010254
10255 /**
10256 * Set the GbaService Package Name that Telephony will bind to.
10257 *
10258 * @param subId The sim that the GbaService is associated with.
10259 * @param packageName The name of the package to be replaced with.
10260 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10261 */
10262 @Override
10263 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10264 enforceModifyPermission();
10265
10266 final long identity = Binder.clearCallingIdentity();
10267 try {
10268 return getGbaManager(subId).overrideServicePackage(packageName);
10269 } finally {
10270 Binder.restoreCallingIdentity(identity);
10271 }
10272 }
10273
10274 /**
10275 * Return the package name of the currently bound GbaService.
10276 *
10277 * @param subId The sim that the GbaService is associated with.
10278 * @return the package name of the GbaService configuration, null if GBA is not supported.
10279 */
10280 @Override
10281 public String getBoundGbaService(int subId) {
10282 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10283
10284 final long identity = Binder.clearCallingIdentity();
10285 try {
10286 return getGbaManager(subId).getServicePackage();
10287 } finally {
10288 Binder.restoreCallingIdentity(identity);
10289 }
10290 }
10291
10292 /**
10293 * Set the release time for telephony to unbind GbaService.
10294 *
10295 * @param subId The sim that the GbaService is associated with.
10296 * @param interval The release time to unbind GbaService by millisecond.
10297 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10298 */
10299 @Override
10300 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10301 enforceModifyPermission();
10302
10303 final long identity = Binder.clearCallingIdentity();
10304 try {
10305 return getGbaManager(subId).overrideReleaseTime(interval);
10306 } finally {
10307 Binder.restoreCallingIdentity(identity);
10308 }
10309 }
10310
10311 /**
10312 * Return the release time for telephony to unbind GbaService.
10313 *
10314 * @param subId The sim that the GbaService is associated with.
10315 * @return The release time to unbind GbaService by millisecond.
10316 */
10317 @Override
10318 public int getGbaReleaseTime(int subId) {
10319 enforceReadPrivilegedPermission("getGbaReleaseTime");
10320
10321 final long identity = Binder.clearCallingIdentity();
10322 try {
10323 return getGbaManager(subId).getReleaseTime();
10324 } finally {
10325 Binder.restoreCallingIdentity(identity);
10326 }
10327 }
10328
10329 private GbaManager getGbaManager(int subId) {
10330 GbaManager instance = GbaManager.getInstance(subId);
10331 if (instance == null) {
10332 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10333 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10334 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10335 }
10336 return instance;
10337 }
Hui Wang761a6682020-10-31 05:12:53 +000010338
10339 /**
10340 * indicate whether the device and the carrier can support
10341 * RCS VoLTE single registration.
10342 */
10343 @Override
10344 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010345 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10346 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10347 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10348 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010349
10350 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10351 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10352 }
10353
10354 final long identity = Binder.clearCallingIdentity();
10355 try {
10356 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10357 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010358 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10359 if (isCapable != null) {
10360 return isCapable;
10361 }
Hui Wang761a6682020-10-31 05:12:53 +000010362 }
Hui Wang67af90e2021-06-04 16:57:15 -070010363 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10364 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010365 } finally {
10366 Binder.restoreCallingIdentity(identity);
10367 }
10368 }
10369
10370 /**
10371 * Register RCS provisioning callback.
10372 */
10373 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010374 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010375 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010376 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010377 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010378 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10379 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010380
10381 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10382 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10383 }
10384 if (!isImsAvailableOnDevice()) {
10385 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10386 "IMS not available on device.");
10387 }
10388
10389 final long identity = Binder.clearCallingIdentity();
10390 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010391 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010392 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010393 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10394 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010395 }
Hui Wang761a6682020-10-31 05:12:53 +000010396 } finally {
10397 Binder.restoreCallingIdentity(identity);
10398 }
10399 }
10400
10401 /**
10402 * Unregister RCS provisioning callback.
10403 */
10404 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010405 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010406 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010407 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010408 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010409 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10410 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010411
10412 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10413 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10414 }
10415 if (!isImsAvailableOnDevice()) {
10416 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10417 "IMS not available on device.");
10418 }
10419
10420 final long identity = Binder.clearCallingIdentity();
10421 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010422 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010423 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010424 } finally {
10425 Binder.restoreCallingIdentity(identity);
10426 }
10427 }
10428
10429 /**
10430 * trigger RCS reconfiguration.
10431 */
10432 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010433 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10434 "triggerRcsReconfiguration",
10435 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010436
10437 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10438 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10439 }
10440 if (!isImsAvailableOnDevice()) {
10441 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10442 "IMS not available on device.");
10443 }
10444
10445 final long identity = Binder.clearCallingIdentity();
10446 try {
10447 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10448 } finally {
10449 Binder.restoreCallingIdentity(identity);
10450 }
10451 }
10452
10453 /**
10454 * Provide the client configuration parameters of the RCS application.
10455 */
10456 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010457 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10458 "setRcsClientConfiguration",
10459 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010460
10461 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10462 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10463 }
10464 if (!isImsAvailableOnDevice()) {
10465 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10466 "IMS not available on device.");
10467 }
10468
10469 final long identity = Binder.clearCallingIdentity();
10470
10471 try {
10472 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10473 if (configBinder == null) {
10474 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010475 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10476 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010477 } else {
10478 configBinder.setRcsClientConfiguration(rcc);
10479 }
joonhunshinfa314642021-09-17 06:33:39 +000010480
10481 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10482 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010483 } catch (RemoteException e) {
10484 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010485 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10486 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010487 } finally {
10488 Binder.restoreCallingIdentity(identity);
10489 }
10490 }
10491
10492 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010493 * Enables or disables the test mode for RCS VoLTE single registration.
10494 */
10495 @Override
10496 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10497 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10498 "setRcsSingleRegistrationTestModeEnabled");
10499
10500 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10501 }
10502
10503 /**
10504 * Gets the test mode for RCS VoLTE single registration.
10505 */
10506 @Override
10507 public boolean getRcsSingleRegistrationTestModeEnabled() {
10508 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10509 "getRcsSingleRegistrationTestModeEnabled");
10510
10511 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10512 }
10513
10514 /**
Hui Wang761a6682020-10-31 05:12:53 +000010515 * Overrides the config of RCS VoLTE single registration enabled for the device.
10516 */
10517 @Override
10518 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10519 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10520 "setDeviceSingleRegistrationEnabledOverride");
10521 enforceModifyPermission();
10522
10523 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10524 : Boolean.parseBoolean(enabledStr);
10525 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010526 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010527 }
10528
10529 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010530 * Sends a device to device communication message. Only usable via shell.
10531 * @param message message to send.
10532 * @param value message value.
10533 */
10534 @Override
10535 public void sendDeviceToDeviceMessage(int message, int value) {
10536 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010537 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010538 enforceModifyPermission();
10539
10540 final long identity = Binder.clearCallingIdentity();
10541 try {
10542 TelephonyConnectionService service =
10543 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10544 if (service == null) {
10545 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10546 return;
10547 }
10548 service.sendTestDeviceToDeviceMessage(message, value);
10549 } finally {
10550 Binder.restoreCallingIdentity(identity);
10551 }
10552 }
10553
Tyler Gunnbabbda02021-02-10 11:05:02 -080010554 /**
10555 * Sets the specified device to device transport active.
10556 * @param transport The transport to set active.
10557 */
10558 @Override
10559 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10560 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10561 "setActiveDeviceToDeviceTransport");
10562 enforceModifyPermission();
10563
10564 final long identity = Binder.clearCallingIdentity();
10565 try {
10566 TelephonyConnectionService service =
10567 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10568 if (service == null) {
10569 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10570 return;
10571 }
10572 service.setActiveDeviceToDeviceTransport(transport);
10573 } finally {
10574 Binder.restoreCallingIdentity(identity);
10575 }
10576 }
Tyler Gunn92479152021-01-20 16:30:10 -080010577
Tyler Gunnd4575212021-05-03 14:46:49 -070010578 @Override
10579 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10580 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10581 "setDeviceToDeviceForceEnabled");
10582
10583 final long identity = Binder.clearCallingIdentity();
10584 try {
10585 Arrays.stream(PhoneFactory.getPhones()).forEach(
10586 p -> {
10587 Phone thePhone = p.getImsPhone();
10588 if (thePhone != null && thePhone instanceof ImsPhone) {
10589 ImsPhone imsPhone = (ImsPhone) thePhone;
10590 CallTracker tracker = imsPhone.getCallTracker();
10591 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10592 ImsPhoneCallTracker imsPhoneCallTracker =
10593 (ImsPhoneCallTracker) tracker;
10594 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10595 }
10596 }
10597 }
10598 );
10599 } finally {
10600 Binder.restoreCallingIdentity(identity);
10601 }
10602 }
10603
Tyler Gunn92479152021-01-20 16:30:10 -080010604 /**
Hui Wang761a6682020-10-31 05:12:53 +000010605 * Gets the config of RCS VoLTE single registration enabled for the device.
10606 */
10607 @Override
10608 public boolean getDeviceSingleRegistrationEnabled() {
10609 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10610 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10611 }
10612
10613 /**
10614 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10615 */
10616 @Override
10617 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10618 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10619 "setCarrierSingleRegistrationEnabledOverride");
10620 enforceModifyPermission();
10621
10622 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10623 : Boolean.parseBoolean(enabledStr);
10624 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10625 subId, enabled);
10626 }
10627
10628 /**
10629 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10630 */
10631 @Override
10632 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10633 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10634 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10635 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010636
10637 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010638 * Overrides the ims feature validation result
10639 */
10640 @Override
10641 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10642 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10643 "setImsFeatureValidationOverride");
10644
10645 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10646 : Boolean.parseBoolean(enabledStr);
10647 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10648 subId, enabled);
10649 }
10650
10651 /**
10652 * Gets the ims feature validation override value
10653 */
10654 @Override
10655 public boolean getImsFeatureValidationOverride(int subId) {
10656 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10657 "getImsFeatureValidationOverride");
10658 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10659 }
10660
10661 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010662 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10663 * their mobile plan.
10664 */
10665 @Override
10666 public String getMobileProvisioningUrl() {
10667 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10668 final long identity = Binder.clearCallingIdentity();
10669 try {
10670 return getDefaultPhone().getMobileProvisioningUrl();
10671 } finally {
10672 Binder.restoreCallingIdentity(identity);
10673 }
10674 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010675
James.cf Linbcdf8b32021-01-14 16:44:13 +080010676 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010677 * Get the EAB contact from the EAB database.
10678 */
10679 @Override
10680 public String getContactFromEab(String contact) {
10681 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10682 enforceModifyPermission();
10683 final long identity = Binder.clearCallingIdentity();
10684 try {
10685 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10686 } finally {
10687 Binder.restoreCallingIdentity(identity);
10688 }
10689 }
10690
10691 /**
Calvin Pana1434322021-07-01 19:27:01 +080010692 * Get the EAB capability from the EAB database.
10693 */
10694 @Override
10695 public String getCapabilityFromEab(String contact) {
10696 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10697 enforceModifyPermission();
10698 final long identity = Binder.clearCallingIdentity();
10699 try {
10700 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10701 } finally {
10702 Binder.restoreCallingIdentity(identity);
10703 }
10704 }
10705
10706 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010707 * Remove the EAB contacts from the EAB database.
10708 */
10709 @Override
10710 public int removeContactFromEab(int subId, String contacts) {
10711 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10712 enforceModifyPermission();
10713 final long identity = Binder.clearCallingIdentity();
10714 try {
10715 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10716 } finally {
10717 Binder.restoreCallingIdentity(identity);
10718 }
10719 }
10720
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010721 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010722 public boolean getDeviceUceEnabled() {
10723 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10724 final long identity = Binder.clearCallingIdentity();
10725 try {
10726 return mApp.getDeviceUceEnabled();
10727 } finally {
10728 Binder.restoreCallingIdentity(identity);
10729 }
10730 }
10731
10732 @Override
10733 public void setDeviceUceEnabled(boolean isEnabled) {
10734 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10735 final long identity = Binder.clearCallingIdentity();
10736 try {
10737 mApp.setDeviceUceEnabled(isEnabled);
10738 } finally {
10739 Binder.restoreCallingIdentity(identity);
10740 }
10741 }
10742
Brad Ebinger14d467f2021-02-12 06:18:28 +000010743 /**
10744 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10745 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10746 */
10747 // Used for SHELL command only right now.
10748 @Override
10749 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10750 List<String> featureTags) {
10751 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10752 "addUceRegistrationOverrideShell");
10753 final long identity = Binder.clearCallingIdentity();
10754 try {
10755 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10756 new ArraySet<>(featureTags));
10757 } catch (ImsException e) {
10758 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10759 } finally {
10760 Binder.restoreCallingIdentity(identity);
10761 }
10762 }
10763
10764 /**
10765 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10766 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10767 */
10768 // Used for SHELL command only right now.
10769 @Override
10770 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10771 List<String> featureTags) {
10772 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10773 "removeUceRegistrationOverrideShell");
10774 final long identity = Binder.clearCallingIdentity();
10775 try {
10776 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10777 new ArraySet<>(featureTags));
10778 } catch (ImsException e) {
10779 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10780 } finally {
10781 Binder.restoreCallingIdentity(identity);
10782 }
10783 }
10784
10785 /**
10786 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10787 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10788 */
10789 // Used for SHELL command only right now.
10790 @Override
10791 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10792 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10793 "clearUceRegistrationOverrideShell");
10794 final long identity = Binder.clearCallingIdentity();
10795 try {
10796 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10797 } catch (ImsException e) {
10798 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10799 } finally {
10800 Binder.restoreCallingIdentity(identity);
10801 }
10802 }
10803
10804 /**
10805 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10806 */
10807 // Used for SHELL command only right now.
10808 @Override
10809 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10810 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10811 "getLatestRcsContactUceCapabilityShell");
10812 final long identity = Binder.clearCallingIdentity();
10813 try {
10814 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10815 } catch (ImsException e) {
10816 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10817 } finally {
10818 Binder.restoreCallingIdentity(identity);
10819 }
10820 }
10821
10822 /**
10823 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10824 * device does not have an active PUBLISH.
10825 */
10826 // Used for SHELL command only right now.
10827 @Override
10828 public String getLastUcePidfXmlShell(int subId) {
10829 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10830 final long identity = Binder.clearCallingIdentity();
10831 try {
10832 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10833 } catch (ImsException e) {
10834 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10835 } finally {
10836 Binder.restoreCallingIdentity(identity);
10837 }
10838 }
10839
James.cf Line8713a42021-04-29 16:04:26 +080010840 /**
10841 * Remove UCE requests cannot be sent to the network status.
10842 */
10843 // Used for SHELL command only right now.
10844 @Override
10845 public boolean removeUceRequestDisallowedStatus(int subId) {
10846 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10847 final long identity = Binder.clearCallingIdentity();
10848 try {
10849 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10850 } catch (ImsException e) {
10851 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10852 } finally {
10853 Binder.restoreCallingIdentity(identity);
10854 }
10855 }
10856
James.cf Lin0fc71b02021-05-25 01:37:38 +080010857 /**
10858 * Remove UCE requests cannot be sent to the network status.
10859 */
10860 // Used for SHELL command only.
10861 @Override
10862 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10863 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10864 final long identity = Binder.clearCallingIdentity();
10865 try {
10866 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10867 } catch (ImsException e) {
10868 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10869 } finally {
10870 Binder.restoreCallingIdentity(identity);
10871 }
10872 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010873
James.cf Lin4b784aa2021-01-31 03:25:15 +080010874 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010875 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10876 String callingPackage) {
10877 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10878 mApp, subId, "setSignalStrengthUpdateRequest");
10879
10880 final int callingUid = Binder.getCallingUid();
10881 // Verify that tha callingPackage belongs to the calling UID
10882 mApp.getSystemService(AppOpsManager.class)
10883 .checkPackage(callingUid, callingPackage);
10884
Rambo Wang3607f502021-02-01 21:51:40 -080010885 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010886
10887 final long identity = Binder.clearCallingIdentity();
10888 try {
10889 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10890 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10891
10892 if (result instanceof IllegalStateException) {
10893 throw (IllegalStateException) result;
10894 }
10895 } finally {
10896 Binder.restoreCallingIdentity(identity);
10897 }
10898 }
10899
10900 @Override
10901 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10902 String callingPackage) {
10903 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10904 mApp, subId, "clearSignalStrengthUpdateRequest");
10905
10906 final int callingUid = Binder.getCallingUid();
10907 // Verify that tha callingPackage belongs to the calling UID
10908 mApp.getSystemService(AppOpsManager.class)
10909 .checkPackage(callingUid, callingPackage);
10910
10911 final long identity = Binder.clearCallingIdentity();
10912 try {
10913 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10914 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10915
10916 if (result instanceof IllegalStateException) {
10917 throw (IllegalStateException) result;
10918 }
10919 } finally {
10920 Binder.restoreCallingIdentity(identity);
10921 }
10922 }
10923
Rambo Wang3607f502021-02-01 21:51:40 -080010924 private static void validateSignalStrengthUpdateRequest(Context context,
10925 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010926 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10927 // phone/system process do not have further restriction on request
10928 return;
10929 }
10930
10931 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080010932 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010933 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080010934 context.enforceCallingOrSelfPermission(
10935 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
10936 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010937 }
10938
10939 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10940 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10941 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10942 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10943 || info.isEnabled()) {
10944 throw new IllegalArgumentException(
10945 "Only system can set hide fields in SignalThresholdInfo");
10946 }
10947
10948 // Thresholds length for each RAN need in range. This has been validated in
10949 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10950 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10951 final int[] thresholds = info.getThresholds();
10952 Objects.requireNonNull(thresholds);
10953 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10954 || thresholds.length
10955 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10956 throw new IllegalArgumentException(
10957 "thresholds length is out of range: " + thresholds.length);
10958 }
10959 }
10960 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010961
10962 /**
10963 * Gets the current phone capability.
10964 *
10965 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10966 * @return the PhoneCapability which describes the data connection capability of modem.
10967 * It's used to evaluate possible phone config change, for example from single
10968 * SIM device to multi-SIM device.
10969 */
10970 @Override
10971 public PhoneCapability getPhoneCapability() {
10972 enforceReadPrivilegedPermission("getPhoneCapability");
10973 final long identity = Binder.clearCallingIdentity();
10974 try {
10975 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10976 } finally {
10977 Binder.restoreCallingIdentity(identity);
10978 }
10979 }
Michele Berionne5e411512020-11-13 02:36:59 +000010980
10981 /**
10982 * Prepare TelephonyManager for an unattended reboot. The reboot is
10983 * required to be done shortly after the API is invoked.
10984 */
10985 @Override
10986 @TelephonyManager.PrepareUnattendedRebootResult
10987 public int prepareForUnattendedReboot() {
10988 enforceRebootPermission();
10989
10990 final long identity = Binder.clearCallingIdentity();
10991 try {
10992 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10993 } finally {
10994 Binder.restoreCallingIdentity(identity);
10995 }
10996 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010997
10998 /**
10999 * Request to get the current slicing configuration including URSP rules and
11000 * NSSAIs (configured, allowed and rejected).
11001 *
11002 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11003 */
11004 @Override
11005 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011006 TelephonyPermissions
11007 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11008 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011009
11010 final long identity = Binder.clearCallingIdentity();
11011 try {
11012 Phone phone = getDefaultPhone();
11013 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11014 } finally {
11015 Binder.restoreCallingIdentity(identity);
11016 }
11017 }
Hunsuk Choic7ebc0f2021-11-15 23:46:41 +000011018
11019 /**
11020 * Register an IMS connection state callback
11021 */
11022 @Override
11023 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11024 String callingPackage) {
11025 if (feature == ImsFeature.FEATURE_MMTEL) {
11026 // ImsMmTelManager
11027 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11028 TelephonyPermissions
11029 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11030 mApp, subId, "registerImsStateCallback");
11031 } else if (feature == ImsFeature.FEATURE_RCS) {
11032 // ImsRcsManager or SipDelegateManager
11033 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11034 Binder.getCallingUid(), "registerImsStateCallback",
11035 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11036 Manifest.permission.READ_PRECISE_PHONE_STATE,
11037 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11038 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11039 }
11040
11041 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11042 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11043 "IMS not available on device.");
11044 }
11045
11046 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11047 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11048 }
11049
11050 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11051 if (controller == null) {
11052 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11053 "IMS not available on device.");
11054 }
11055
11056 if (callingPackage == null) {
11057 callingPackage = getCurrentPackageName();
11058 }
11059
11060 final long token = Binder.clearCallingIdentity();
11061 try {
11062 int slotId = getSlotIndexOrException(subId);
11063 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
11064 } catch (ImsException e) {
11065 throw new ServiceSpecificException(e.getCode());
11066 } finally {
11067 Binder.restoreCallingIdentity(token);
11068 }
11069 }
11070
11071 /**
11072 * Unregister an IMS connection state callback
11073 */
11074 @Override
11075 public void unregisterImsStateCallback(IImsStateCallback cb) {
11076 final long token = Binder.clearCallingIdentity();
11077 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11078 if (controller == null) {
11079 return;
11080 }
11081 try {
11082 controller.unregisterImsStateCallback(cb);
11083 } finally {
11084 Binder.restoreCallingIdentity(token);
11085 }
11086 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011087
11088 /**
11089 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11090 *
11091 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11092 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11093 * SecurityException.
11094 * If there is current registered network this value will be same as the registered cell
11095 * identity. If the device goes out of service the previous cell identity is cached and
11096 * will be returned. If the cache age of the Cell identity is more than 24 hours
11097 * it will be cleared and null will be returned.
11098 *
11099 */
11100 @Override
11101 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11102 String callingFeatureId) {
11103 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11104 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11105 LocationAccessPolicy.checkLocationPermission(mApp,
11106 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11107 .setCallingPackage(callingPackage)
11108 .setCallingFeatureId(callingFeatureId)
11109 .setCallingPid(Binder.getCallingPid())
11110 .setCallingUid(Binder.getCallingUid())
11111 .setMethod("getLastKnownCellIdentity")
11112 .setLogAsInfo(true)
11113 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11114 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11115 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11116 .build());
11117
11118 boolean hasFinePermission =
11119 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11120 if (!hasFinePermission
11121 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11122 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
11123 + "and BIND_CONNECTION_SERVICE permission.");
11124 }
11125
11126 final long identity = Binder.clearCallingIdentity();
11127 try {
11128 Phone phone = getPhone(subId);
11129 if (phone == null) return null;
11130 ServiceStateTracker sst = phone.getServiceStateTracker();
11131 if (sst == null) return null;
11132 return sst.getLastKnownCellIdentity();
11133 } finally {
11134 Binder.restoreCallingIdentity(identity);
11135 }
11136 }
jimsun38340bf2021-10-26 15:01:23 +080011137
11138 /**
11139 * Sets the modem service class Name that Telephony will bind to.
11140 *
11141 * @param serviceName The class name of the modem service.
11142 * @return true if the operation is succeed, otherwise false.
11143 */
11144 public boolean setModemService(String serviceName) {
11145 Log.d(LOG_TAG, "setModemService - " + serviceName);
11146 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11147 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11148 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11149 "setModemService");
11150 return mPhoneConfigurationManager.setModemService(serviceName);
11151 }
11152
11153 /**
11154 * Return the class name of the currently bounded modem service.
11155 *
11156 * @return the class name of the modem service.
11157 */
11158 public String getModemService() {
11159 String result;
11160 Log.d(LOG_TAG, "getModemService");
11161 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11162 TelephonyPermissions
11163 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11164 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11165 "getModemService");
11166 result = mPhoneConfigurationManager.getModemService();
11167 Log.d(LOG_TAG, "result = " + result);
11168 return result;
11169 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011170}